-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add supports of task display for node upgrade
- Loading branch information
Showing
28 changed files
with
768 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dto | ||
|
||
import "github.com/1Panel-dev/1Panel/core/app/model" | ||
|
||
type SearchTaskLogReq struct { | ||
Status string `json:"status"` | ||
Type string `json:"type"` | ||
PageInfo | ||
} | ||
|
||
type TaskDTO struct { | ||
model.Task | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
type Task struct { | ||
ID string `gorm:"primarykey;" json:"id"` | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
Operate string `json:"operate"` | ||
LogFile string `json:"logFile"` | ||
Status string `json:"status"` | ||
ErrorMsg string `json:"errorMsg"` | ||
OperationLogID uint `json:"operationLogID"` | ||
ResourceID uint `json:"resourceID"` | ||
CurrentStep string `json:"currentStep"` | ||
EndAt time.Time `json:"endAt"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package model | ||
|
||
type UpgradeLog struct { | ||
BaseModel | ||
NodeID uint `json:"nodeID"` | ||
OldVersion string `json:"oldVersion"` | ||
NewVersion string `json:"newVersion"` | ||
BackupFile string `json:"backupFile"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package repo | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/1Panel-dev/1Panel/core/app/model" | ||
"github.com/1Panel-dev/1Panel/core/global" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type TaskRepo struct { | ||
} | ||
|
||
type ITaskRepo interface { | ||
Save(ctx context.Context, task *model.Task) error | ||
GetFirst(opts ...DBOption) (model.Task, error) | ||
Page(page, size int, opts ...DBOption) (int64, []model.Task, error) | ||
Update(ctx context.Context, task *model.Task) error | ||
|
||
WithByID(id string) DBOption | ||
WithResourceID(id uint) DBOption | ||
WithOperate(taskOperate string) DBOption | ||
} | ||
|
||
func NewITaskRepo() ITaskRepo { | ||
return &TaskRepo{} | ||
} | ||
|
||
func getTaskDb(opts ...DBOption) *gorm.DB { | ||
db := global.TaskDB | ||
for _, opt := range opts { | ||
db = opt(db) | ||
} | ||
return db | ||
} | ||
|
||
func getTaskTx(ctx context.Context, opts ...DBOption) *gorm.DB { | ||
tx, ok := ctx.Value("db").(*gorm.DB) | ||
if ok { | ||
for _, opt := range opts { | ||
tx = opt(tx) | ||
} | ||
return tx | ||
} | ||
return getTaskDb(opts...) | ||
} | ||
|
||
func (t TaskRepo) WithByID(id string) DBOption { | ||
return func(g *gorm.DB) *gorm.DB { | ||
return g.Where("id = ?", id) | ||
} | ||
} | ||
|
||
func (t TaskRepo) WithOperate(taskOperate string) DBOption { | ||
return func(g *gorm.DB) *gorm.DB { | ||
return g.Where("operate = ?", taskOperate) | ||
} | ||
} | ||
|
||
func (t TaskRepo) WithResourceID(id uint) DBOption { | ||
return func(g *gorm.DB) *gorm.DB { | ||
return g.Where("resource_id = ?", id) | ||
} | ||
} | ||
|
||
func (t TaskRepo) Save(ctx context.Context, task *model.Task) error { | ||
return getTaskTx(ctx).Save(&task).Error | ||
} | ||
|
||
func (t TaskRepo) GetFirst(opts ...DBOption) (model.Task, error) { | ||
var task model.Task | ||
db := getTaskDb(opts...).Model(&model.Task{}) | ||
if err := db.First(&task).Error; err != nil { | ||
return task, err | ||
} | ||
return task, nil | ||
} | ||
|
||
func (t TaskRepo) Page(page, size int, opts ...DBOption) (int64, []model.Task, error) { | ||
var tasks []model.Task | ||
db := getTaskDb(opts...).Model(&model.Task{}) | ||
count := int64(0) | ||
db = db.Count(&count) | ||
err := db.Limit(size).Offset(size * (page - 1)).Find(&tasks).Error | ||
return count, tasks, err | ||
} | ||
|
||
func (t TaskRepo) Update(ctx context.Context, task *model.Task) error { | ||
return getTaskTx(ctx).Save(&task).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package repo | ||
|
||
import ( | ||
"github.com/1Panel-dev/1Panel/core/app/model" | ||
"github.com/1Panel-dev/1Panel/core/global" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type UpgradeLogRepo struct{} | ||
|
||
type IUpgradeLogRepo interface { | ||
Get(opts ...DBOption) (model.UpgradeLog, error) | ||
List(opts ...DBOption) ([]model.UpgradeLog, error) | ||
Create(log *model.UpgradeLog) error | ||
Page(limit, offset int, opts ...DBOption) (int64, []model.UpgradeLog, error) | ||
Delete(opts ...DBOption) error | ||
|
||
WithByNodeID(nodeID uint) DBOption | ||
WithByIDs(ids []uint) DBOption | ||
WithByID(id uint) DBOption | ||
} | ||
|
||
func NewIUpgradeLogRepo() IUpgradeLogRepo { | ||
return &UpgradeLogRepo{} | ||
} | ||
|
||
func (u *UpgradeLogRepo) Get(opts ...DBOption) (model.UpgradeLog, error) { | ||
var log model.UpgradeLog | ||
db := global.DB | ||
for _, opt := range opts { | ||
db = opt(db) | ||
} | ||
err := db.First(&log).Error | ||
return log, err | ||
} | ||
|
||
func (u *UpgradeLogRepo) List(opts ...DBOption) ([]model.UpgradeLog, error) { | ||
var logs []model.UpgradeLog | ||
db := global.DB | ||
for _, opt := range opts { | ||
db = opt(db) | ||
} | ||
err := db.Find(&logs).Error | ||
return logs, err | ||
} | ||
|
||
func (u *UpgradeLogRepo) Clean() error { | ||
return global.DB.Exec("delete from upgrade_logs;").Error | ||
} | ||
|
||
func (u *UpgradeLogRepo) Create(log *model.UpgradeLog) error { | ||
return global.DB.Create(log).Error | ||
} | ||
|
||
func (u *UpgradeLogRepo) Save(log *model.UpgradeLog) error { | ||
return global.DB.Save(log).Error | ||
} | ||
|
||
func (u *UpgradeLogRepo) Delete(opts ...DBOption) error { | ||
db := global.DB | ||
for _, opt := range opts { | ||
db = opt(db) | ||
} | ||
return db.Delete(&model.UpgradeLog{}).Error | ||
} | ||
|
||
func (u *UpgradeLogRepo) Page(page, size int, opts ...DBOption) (int64, []model.UpgradeLog, error) { | ||
var ops []model.UpgradeLog | ||
db := global.DB.Model(&model.UpgradeLog{}) | ||
for _, opt := range opts { | ||
db = opt(db) | ||
} | ||
count := int64(0) | ||
db = db.Count(&count) | ||
err := db.Limit(size).Offset(size * (page - 1)).Find(&ops).Error | ||
return count, ops, err | ||
} | ||
|
||
func (c *UpgradeLogRepo) WithByNodeID(nodeID uint) DBOption { | ||
return func(g *gorm.DB) *gorm.DB { | ||
return g.Where("node_id = ?", nodeID) | ||
} | ||
} | ||
func (c *UpgradeLogRepo) WithByID(id uint) DBOption { | ||
return func(g *gorm.DB) *gorm.DB { | ||
return g.Where("id = ?", id) | ||
} | ||
} | ||
func (c *UpgradeLogRepo) WithByIDs(ids []uint) DBOption { | ||
return func(g *gorm.DB) *gorm.DB { | ||
return g.Where("id in (?)", ids) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.