diff --git a/server/controller/task.go b/server/controller/task.go index 5707e2d57a8b417d0528c4f228a096f6e99561cc..73a082c6817a55bd7b7b29e3be8f6617eb020e2c 100644 --- a/server/controller/task.go +++ b/server/controller/task.go @@ -41,13 +41,14 @@ func CreatTask(c *gin.Context) { MachineUUIDs []string `json:"machine_uuids"` TuneID int `json:"tune_id"` TaskName string `json:"task_name"` + Description string `json:"description"` }{} if err := c.ShouldBind(d); err != nil { logger.Debug("绑定批次参数失败:%s", err) response.Fail(c, nil, "parameter error") return } - err := service.SaveTask(d.TaskName, d.MachineUUIDs, d.TuneID) + err := service.SaveTask(d.TaskName, d.Description, d.MachineUUIDs, d.TuneID) if err != nil { response.Fail(c, nil, err.Error()) return diff --git a/server/controller/tune.go b/server/controller/tune.go index b2400bcae561e9e0e09ea25ac1a47a04ab6ec78e..4b4572d911d7402854f2b037a973e0c2dc565f12 100644 --- a/server/controller/tune.go +++ b/server/controller/tune.go @@ -43,6 +43,15 @@ func GetAtuneInfo(c *gin.Context) { response.Success(c, tune, "获取到调优步骤信息") } +func QueryTunesNoPaged(c *gin.Context) { + data, err := service.QueryTunesNoPaged() + if err != nil { + response.Fail(c, nil, err.Error()) + return + } + response.Success(c, data, "获取到结果详情") +} + func QueryTunes(c *gin.Context) { query := &response.PaginationQ{} err := c.ShouldBindQuery(query) diff --git a/server/dao/tunedao.go b/server/dao/tunedao.go index 4d3431e628458f9a35582e885fd3d86082b0d4d9..8ed04f6061e909d74cf7158fb925fe9346c11b95 100644 --- a/server/dao/tunedao.go +++ b/server/dao/tunedao.go @@ -21,6 +21,14 @@ func GetTuneComandById(tune_id int) (map[int]model.TaskCommand, error) { return tuneCommand, nil } +func QueryTunesNoPaged() ([]*model.Tunes, error) { + var tunes []*model.Tunes + if err := db.MySQL().Find(&tunes).Error; err != nil { + return []*model.Tunes{}, err + } + return tunes, nil +} + func QueryTunes(query *response.PaginationQ) ([]*model.Tunes, int64, error) { var tunes []*model.Tunes if err := db.MySQL().Limit(query.PageSize).Offset((query.Page - 1) * query.PageSize).Find(&tunes).Error; err != nil { diff --git a/server/go.mod b/server/go.mod index c25a5c6a3cbdb7a9bccc6b8b6a6c059257ecb424..351d0caef03400fd39ba55be51157c519c6dc4b6 100644 --- a/server/go.mod +++ b/server/go.mod @@ -3,7 +3,7 @@ module openeuler.org/PilotGo/atune-plugin go 1.18 require ( - gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f + gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119031301-10921c4f0434 github.com/gin-gonic/gin v1.9.1 gopkg.in/yaml.v2 v2.4.0 gorm.io/driver/mysql v1.5.1 diff --git a/server/go.sum b/server/go.sum index 98e89cb3f67fc5b4d0e0feca690a4b46cf4ad295..20a5ab998e58181ff5b71dd9bce4114f85b10028 100644 --- a/server/go.sum +++ b/server/go.sum @@ -1,19 +1,5 @@ -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231218035738-e5355d2a2d29 h1:8BkdZwuBvt8u+iFClylVWahrDox6n+q1+pf27jd5JNA= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231218035738-e5355d2a2d29/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231220075944-c00326991801 h1:D7DF8kmhHZoesTGJsbeL9qhIZzQdmnUGOnPhbpo5P70= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231220075944-c00326991801/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231225071221-260195e4ee3e h1:UKsQvDsAqPY/Zsgi58wzsLwPikS66e+wH6oeEGGMx80= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231225071221-260195e4ee3e/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231226100554-760a57ca0a35 h1:fkTHiDG25bsB9Kt6ruZkFjteA4Ppekk+TJz8xgXD7uI= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231226100554-760a57ca0a35/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231227031908-2bcdb8153727 h1:WhtjNRVlIts1sNAP3FPQ+LhD6UPqt2jYGaCBbtQdOeA= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231227031908-2bcdb8153727/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231227070920-c289614a2e10 h1:RUbvPYH43bj1Ebu3w32oWdoQLOvlJRfQVzRE319uu/Q= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231227070920-c289614a2e10/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231227075111-fc150174f73a h1:vCMqSAe5nX8dX1tGH1MwTlMWljcziEV6Gw83Gu6KYqE= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231227075111-fc150174f73a/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f h1:DGwrH8ikENblWnxpTdF21OuQKcN3I4uLkp4oKi2nbuw= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119031301-10921c4f0434 h1:owh3m67r7EMCiktmIXjgLJ/dI/wZVYDpurKpXBDGfXE= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119031301-10921c4f0434/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= diff --git a/server/model/common.go b/server/model/common.go index c4d745826fb402d42eef97643daf21fbfc3e47fe..5a2500f039c9ed56d2e4985813b88d48cc9848a3 100644 --- a/server/model/common.go +++ b/server/model/common.go @@ -27,12 +27,13 @@ type RunResult struct { } type Tasks struct { - ID int `gorm:"primary_key;AUTO_INCREMENT" json:"id"` - TuneID int `json:"tune_id"` - TaskName string `json:"task_name"` - TaskStatus string `json:"task_status"` - CreateTime string `json:"create_time"` - UpdateTime string `json:"update_time"` + ID int `gorm:"primary_key;AUTO_INCREMENT" json:"id"` + TuneID int `json:"tune_id"` + TaskName string `json:"task_name"` + Description string `json:"description"` + TaskStatus string `json:"task_status"` + CreateTime string `json:"create_time"` + UpdateTime string `json:"update_time"` // RunResults []RunResult `gorm:"foreignKey:TaskID;constraint:OnDelete:CASCADE;" json:"results"` Tune Tunes `gorm:"foreignKey:TuneID;constraint:OnUpdate:CASCADE,OnDelete:RESTRICT;" json:"tune"` SuccessCount int `json:"success_count"` diff --git a/server/router/router.go b/server/router/router.go index 03bc3fd81deb7a3db9a78afd8686f33e96513f39..bf7f9c22a4b9982dc4f0ebd5e7b8a82572608c54 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -51,6 +51,7 @@ func registerAPIs(router *gin.Engine) { dbtune := router.Group("/plugin/" + plugin.GlobalClient.PluginInfo.Name) { dbtune.GET("tunes", controller.QueryTunes) + dbtune.GET("tunes_noPaged", controller.QueryTunesNoPaged) dbtune.POST("save_tune", controller.SaveTune) dbtune.POST("update_tune", controller.UpdateTune) dbtune.DELETE("delete_tune", controller.DeleteTune) diff --git a/server/service/taskservice.go b/server/service/taskservice.go index 0a03f99aa0cd48cbcbd5e6f817426c5eba9ba3f4..0c63faf6f020622ee835125e5e440ad7a0840c68 100644 --- a/server/service/taskservice.go +++ b/server/service/taskservice.go @@ -114,13 +114,14 @@ func UpdateTaskStatus(taskId int, taskStatus string) error { } return nil } -func SaveTask(task_name string, uuids []string, tuneId int) error { +func SaveTask(task_name string, desc string, uuids []string, tuneId int) error { task := &model.Tasks{ - TaskName: task_name, - TuneID: tuneId, - TaskStatus: TaskWaiting, - CreateTime: time.Now().Format("2006-01-02 15:04:05"), - UUIDCount: len(uuids), + TaskName: task_name, + Description: desc, + TuneID: tuneId, + TaskStatus: TaskWaiting, + CreateTime: time.Now().Format("2006-01-02 15:04:05"), + UUIDCount: len(uuids), } taskid, err := dao.SaveTask(task) diff --git a/server/service/tuneservice.go b/server/service/tuneservice.go index 3a596496b0c65d3483338ace160ef824e89d515a..cf79cbeea9fa56234a206d0df4b53cd426eb37c1 100644 --- a/server/service/tuneservice.go +++ b/server/service/tuneservice.go @@ -13,6 +13,14 @@ func GetCommandByID(tune_id int) (map[int]model.TaskCommand, error) { command, err := dao.GetTuneComandById(tune_id) return command, err } +func QueryTunesNoPaged() ([]*model.Tunes, error) { + if data, err := dao.QueryTunesNoPaged(); err != nil { + return nil, err + } else { + return data, nil + } +} + func QueryTunes(query *response.PaginationQ) ([]*model.Tunes, int, error) { if data, total, err := dao.QueryTunes(query); err != nil { return nil, 0, err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go index fa182cacfb5678aa7e68818b026985986932094e..90fe3522fc91dabc4d6eedf69e0b1bca027cd62c 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go @@ -30,7 +30,6 @@ type BatchExtention struct { type PageExtention struct { Type string `json:"type"` Name string `json:"name"` - IsIndex bool `json:"is_index"` URL string `json:"url"` Permission string `json:"permission"` } @@ -52,7 +51,7 @@ func (pe *PageExtention) Clone() Extention { // 解析extentions参数 func ParseParameters(data []map[string]interface{}) []Extention { - var extentions []Extention + extentions := []Extention{} for _, v := range data { switch v["type"] { case ExtentionMachine: @@ -79,7 +78,6 @@ func ParseParameters(data []map[string]interface{}) []Extention { URL: v["url"].(string), Permission: v["permission"].(string), Type: v["type"].(string), - IsIndex: v["is_index"].(bool), } extentions = append(extentions, pe) } diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go index 33ef06057611f73883b1d6b3a94c316664b357b0..23241fbd83a4f75c24becd8cdb6054cf809e4212 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go @@ -10,6 +10,13 @@ type MachineNode struct { MaintStatus string `json:"maintatatus"` } +type BatchList struct { + ID int `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Manager string `json:"manager"` +} + type Batch struct { BatchId int `json:"batch_id"` DepartmentIDs []string `json:"department_ids"` diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go new file mode 100644 index 0000000000000000000000000000000000000000..ebbc060b5e485364ea1acf2dc981db3014233f8f --- /dev/null +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go @@ -0,0 +1,6 @@ +package common + +type Permission struct { + Resource string `json:"resource"` //字符串中不允许包含"/" + Operate string `json:"operate"` +} diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go new file mode 100644 index 0000000000000000000000000000000000000000..9057d48ef7109953012382471ea896ae9753e5e8 --- /dev/null +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go @@ -0,0 +1,49 @@ +package client + +import ( + "encoding/json" + "errors" + + "gitee.com/openeuler/PilotGo/sdk/common" + "gitee.com/openeuler/PilotGo/sdk/utils/httputils" +) + +func (c *Client) BatchList() ([]*common.BatchList, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } + url := "http://" + c.Server() + "/api/v1/pluginapi/batch_list" + r, err := httputils.Get(url, nil) + if err != nil { + return nil, err + } + + result := struct { + Code int `json:"code"` + Data []*common.BatchList `json:"data"` + }{} + if err := json.Unmarshal(r.Body, &result); err != nil { + return nil, err + } + return result.Data, nil +} + +func (c *Client) BatchUUIDList(batchId string) ([]string, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } + url := "http://" + c.Server() + "/api/v1/pluginapi/batch_uuid?batchId=" + batchId + r, err := httputils.Get(url, nil) + if err != nil { + return nil, err + } + + result := struct { + Code int `json:"code"` + Data []string `json:"data"` + }{} + if err := json.Unmarshal(r.Body, &result); err != nil { + return nil, err + } + return result.Data, nil +} diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go index fb028757e39034efe31fc19f23213ae0249500b1..ef1d239c65d05dc7de3bdedc6459f83a591e47ff 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go @@ -31,6 +31,9 @@ type Client struct { // 用于平台扩展点功能 extentions []common.Extention + //用于权限校验 + permissions []common.Permission + //bind阻塞功能支持 mu sync.Mutex cond *sync.Cond @@ -47,6 +50,8 @@ func DefaultClient(desc *PluginInfo) *Client { asyncCmdResultChan: make(chan *common.AsyncCmdResult, 20), cmdProcessorCallbackMap: make(map[string]CallbackHandler), + extentions: []common.Extention{}, + permissions: []common.Permission{}, } global_client.cond = sync.NewCond(&global_client.mu) @@ -76,10 +81,6 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { api := router.Group("/plugin_manage/api/v1/") { - api.GET("/extentions", func(c *gin.Context) { - c.Set("__internal__client_instance", client) - }, extentionsHandler) - api.GET("/gettags", func(c *gin.Context) { c.Set("__internal__client_instance", client) }, tagsHandler) diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go index 1438deff2f444385baf73d2da24383fa21246243..65d977888df4a6ca37d9dd9f4459f3d79e00a9fc 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go @@ -46,8 +46,9 @@ func infoHandler(c *gin.Context) { } info := &PluginFullInfo{ - PluginInfo: *client.PluginInfo, - Extentions: client.extentions, + PluginInfo: *client.PluginInfo, + Extentions: client.extentions, + Permissions: client.permissions, } c.JSON(http.StatusOK, info) @@ -101,21 +102,6 @@ func eventHandler(c *gin.Context) { client.ProcessEvent(&msg) } -func extentionsHandler(c *gin.Context) { - v, ok := c.Get("__internal__client_instance") - if !ok { - response.Fail(c, gin.H{"status": false}, "未获取到client值信息") - return - } - client, ok := v.(*Client) - if !ok { - response.Fail(c, gin.H{"status": false}, "client信息错误") - return - } - - response.Success(c, client.extentions, "") -} - func commandResultHandler(c *gin.Context) { j, err := io.ReadAll(c.Request.Body) // 接收数据 if err != nil { diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go new file mode 100644 index 0000000000000000000000000000000000000000..2e208bb9c7576b4e5cf5d0ac278571cd961ff5fe --- /dev/null +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go @@ -0,0 +1,54 @@ +package client + +import ( + "encoding/json" + "errors" + "net/http" + "strings" + + "gitee.com/openeuler/PilotGo/sdk/common" + "gitee.com/openeuler/PilotGo/sdk/utils/httputils" +) + +func (c *Client) RegisterPermission(pers []common.Permission) error { + for _, v := range pers { + if strings.Contains(v.Resource, "/") { + return errors.New("permission-resource string contains /") + } else { + c.permissions = append(c.permissions, v) + } + } + return nil +} + +func (c *Client) HasPermission(resource, operate string) (bool, error) { + if !c.IsBind() { + return false, errors.New("unbind PilotGo-server platform") + } + + url := "http://" + c.Server() + "/api/v1/pluginapi/permission" + p := &common.Permission{ + Resource: resource, + Operate: operate, + } + + r, err := httputils.Post(url, &httputils.Params{ + Body: p, + }) + if err != nil { + return false, err + } + + res := &struct { + Code int `json:"code"` + Message string `json:"msg"` + Data bool `json:"data"` + }{} + if err := json.Unmarshal(r.Body, res); err != nil { + return false, err + } + if res.Code != http.StatusOK { + return false, errors.New(res.Message) + } + return res.Data, nil +} diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go index c009d55213537167c3ac8da5997aa011e67fe3b4..fcde30184f5fd7d499d176bf20860f2ed93d29bf 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go @@ -23,7 +23,8 @@ type PluginInfo struct { // 用于插件与PilotGo server通讯 type PluginFullInfo struct { PluginInfo - Extentions []common.Extention + Extentions []common.Extention + Permissions []common.Permission } func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { diff --git a/server/vendor/modules.txt b/server/vendor/modules.txt index 45cc5ee3e94e2a14482ea00dd72872eec49af11a..8ccc13a0f13d823c9ef7bc63d3e192f567574440 100644 --- a/server/vendor/modules.txt +++ b/server/vendor/modules.txt @@ -1,4 +1,4 @@ -# gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f +# gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119031301-10921c4f0434 ## explicit; go 1.17 gitee.com/openeuler/PilotGo/sdk/common gitee.com/openeuler/PilotGo/sdk/logger