From 6f181c313a76fa047c9e4f9a566819442579b37d Mon Sep 17 00:00:00 2001 From: tzwang Date: Thu, 7 Mar 2024 17:28:43 +0800 Subject: [PATCH 01/12] modified octopus functions generateAlgorithmId Former-commit-id: 0440af0e370819df4d58399d89574ac29c62c44f --- api/internal/storeLink/octopus.go | 39 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/api/internal/storeLink/octopus.go b/api/internal/storeLink/octopus.go index 5851f0d1..8060ca05 100644 --- a/api/internal/storeLink/octopus.go +++ b/api/internal/storeLink/octopus.go @@ -341,11 +341,10 @@ func (o *OctopusLink) generateResourceId(option *option.AiOption) error { return nil } } - } if option.ResourceType == CARD { - err = setResourceIdByCard(option, specResp, MLU) + err = setResourceIdByCard(option, specResp, GCU) if err != nil { return err } @@ -418,16 +417,23 @@ func (o *OctopusLink) generateImageId(option *option.AiOption) error { if !preImgResp.Success { return errors.New("failed to get PresetImages") } - for _, image := range preImgResp.Payload.Images { - if strings.Contains(image.ImageName, option.TaskType) && strings.Contains(image.ImageName, cardAliasMap[option.ComputeCard]) { - option.ImageId = image.Id - return nil + + if option.ResourceType == CARD { + for _, image := range preImgResp.Payload.Images { + if strings.Contains(image.ImageName, cardAliasMap[option.ComputeCard]) { + option.ImageId = image.Id + return nil + } } } + return errors.New("failed to get ImageId") } func (o *OctopusLink) generateAlgorithmId(option *option.AiOption) error { + // temporarily set algorithm to cnn + option.AlgorithmName = "cnn" + req := &octopus.GetMyAlgorithmListReq{ Platform: o.platform, PageIndex: o.pageIndex, @@ -442,18 +448,33 @@ func (o *OctopusLink) generateAlgorithmId(option *option.AiOption) error { } for _, algorithm := range resp.Payload.Algorithms { - if algorithm.FrameworkName == strings.Title(option.TaskType) && strings.Contains(algorithm.AlgorithmName, option.DatasetsName) { + if algorithm.FrameworkName == strings.Title(option.TaskType) { + ns := strings.Split(algorithm.AlgorithmName, DASH) + if ns[0] != option.DatasetsName { + continue + } + if ns[1] != option.AlgorithmName { + continue + } + if ns[2] != option.ResourceType { + continue + } option.AlgorithmId = algorithm.AlgorithmId return nil } } - return nil + return errors.New("failed to get AlgorithmId") } func (o *OctopusLink) generateCmd(option *option.AiOption) error { if option.Cmd == "" { - option.Cmd = TRAIN_CMD + switch option.ComputeCard { + case GCU: + option.Cmd = "cd /code; python3 train.py" + default: + option.Cmd = TRAIN_CMD + } } return nil From bda5f58086c87817fbe8252155535cb8369d5e4f Mon Sep 17 00:00:00 2001 From: qiwang <1364512070@qq.com> Date: Tue, 12 Mar 2024 16:50:22 +0800 Subject: [PATCH 02/12] fix:modify virtual machine interfaces Former-commit-id: 36de12f7eabd1df67329d8b8c22a1c25430d5a3e --- api/desc/vm/pcm-vm.api | 4 ---- api/etc/pcm.yaml | 17 +++++++++++------ api/internal/types/types.go | 4 ---- rpc/etc/pcmcore.yaml | 3 ++- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/api/desc/vm/pcm-vm.api b/api/desc/vm/pcm-vm.api index 724d0d45..ea709651 100644 --- a/api/desc/vm/pcm-vm.api +++ b/api/desc/vm/pcm-vm.api @@ -36,8 +36,6 @@ type ( absolute Absolute `json:"absolute,optional"` } GetComputeLimitsReq { - Limit int32 `json:"limit,optional"` - OffSet int32 `json:"offSet,optional"` Platform string `json:"platform,optional"` } @@ -68,8 +66,6 @@ type ( absolute VolumeAbsolute `json:"absolute,optional"` } GetVolumeLimitsReq { - Limit int32 `json:"limit,optional"` - OffSet int32 `json:"offSet,optional"` Platform string `json:"platform,optional"` } diff --git a/api/etc/pcm.yaml b/api/etc/pcm.yaml index 11d07339..c62b6a3d 100644 --- a/api/etc/pcm.yaml +++ b/api/etc/pcm.yaml @@ -5,14 +5,17 @@ Port: 8999 Timeout: 50000 DB: - DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true&loc=Local + #DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true&loc=Local + DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true&loc=Local Redis: - Host: 10.206.0.12:6379 + Host: 47.92.88.143:6379 + #Host: 10.206.0.12:6379 Pass: redisPW123 Cache: - Host: 10.206.0.12:6379 + # - Host: 10.206.0.12:6379 Pass: redisPW123 # k8s rpc @@ -67,15 +70,17 @@ OctopusRpcConf: Timeout: 20000 OpenstackRpcConf: - target: nacos://10.206.0.12:8848/pcm.openstack.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api - # Endpoints: - # - 127.0.0.1:8888 + # target: nacos://10.206.0.12:8848/pcm.openstack.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api + # target: nacos://127.0.0.1:8848/pcm.openstack.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api + Endpoints: + - 127.0.0.1:2010 NonBlock: true Timeout: 20000 # core rpc PcmCoreRpcConf: - target: nacos://10.206.0.12:8848/pcm.core.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api + # target: nacos://10.206.0.12:8848/pcm.core.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api + target: nacos://47.92.88.143:8848/pcm.core.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api # Endpoints: # - 127.0.0.1:8888 NonBlock: true diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 7073c61b..b0b966e8 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -2507,8 +2507,6 @@ type Limits struct { } type GetComputeLimitsReq struct { - Limit int32 `json:"limit,optional"` - OffSet int32 `json:"offSet,optional"` Platform string `json:"platform,optional"` } @@ -2541,8 +2539,6 @@ type VolumeLimits struct { } type GetVolumeLimitsReq struct { - Limit int32 `json:"limit,optional"` - OffSet int32 `json:"offSet,optional"` Platform string `json:"platform,optional"` } diff --git a/rpc/etc/pcmcore.yaml b/rpc/etc/pcmcore.yaml index 7be42380..70902acf 100644 --- a/rpc/etc/pcmcore.yaml +++ b/rpc/etc/pcmcore.yaml @@ -4,7 +4,8 @@ ListenOn: 0.0.0.0:2004 Timeout: 15000 # 15s,设置rpc服务的响应的超时时间,若超过15s还未返回则结束请求 DB: - DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true + # DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true + DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true #链路追踪 # Telemetry: From dff5870e3e8dcc4701d16f5953bf7a23547437aa Mon Sep 17 00:00:00 2001 From: qiwang <1364512070@qq.com> Date: Tue, 12 Mar 2024 16:58:11 +0800 Subject: [PATCH 03/12] fix:modify virtual machine interfaces Former-commit-id: 565a4a6b574a8515cd33becd8e06d7f0980289e9 --- api/etc/pcm.yaml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/api/etc/pcm.yaml b/api/etc/pcm.yaml index c62b6a3d..41fb111f 100644 --- a/api/etc/pcm.yaml +++ b/api/etc/pcm.yaml @@ -5,17 +5,17 @@ Port: 8999 Timeout: 50000 DB: - #DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true&loc=Local - DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true&loc=Local + DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true&loc=Local + #DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true&loc=Local Redis: - Host: 47.92.88.143:6379 - #Host: 10.206.0.12:6379 + #Host: 47.92.88.143:6379 + Host: 10.206.0.12:6379 Pass: redisPW123 Cache: + #- Host: 10.206.0.12:6379 - Host: 10.206.0.12:6379 - # - Host: 10.206.0.12:6379 Pass: redisPW123 # k8s rpc @@ -72,6 +72,8 @@ OctopusRpcConf: OpenstackRpcConf: # target: nacos://10.206.0.12:8848/pcm.openstack.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api # target: nacos://127.0.0.1:8848/pcm.openstack.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api + #Endpoints: + #- 127.0.0.1:2010 Endpoints: - 127.0.0.1:2010 NonBlock: true @@ -79,8 +81,8 @@ OpenstackRpcConf: # core rpc PcmCoreRpcConf: - # target: nacos://10.206.0.12:8848/pcm.core.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api - target: nacos://47.92.88.143:8848/pcm.core.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api + target: nacos://10.206.0.12:8848/pcm.core.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api + # target: nacos://47.92.88.143:8848/pcm.core.rpc?timeout=30s&namespaceid=test&groupname=DEFAULT_GROUP&appName=pcm.core.api # Endpoints: # - 127.0.0.1:8888 NonBlock: true From 2f9462965ebcca7695b8952eb801d8b9291b108b Mon Sep 17 00:00:00 2001 From: tzwang Date: Tue, 12 Mar 2024 17:47:00 +0800 Subject: [PATCH 04/12] modified submit shuguangai implementation Former-commit-id: 840111b6bb589bec04417f70e3d943f2fa999025 --- api/internal/storeLink/shuguangai.go | 30 ++++++++++++++++++++++++++-- api/internal/storeLink/storeLink.go | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/api/internal/storeLink/shuguangai.go b/api/internal/storeLink/shuguangai.go index 242d07ec..36c9311b 100644 --- a/api/internal/storeLink/shuguangai.go +++ b/api/internal/storeLink/shuguangai.go @@ -352,15 +352,18 @@ func (s *ShuguangAi) generateResourceId(option *option.AiOption) error { if option.ResourceType == CPU { option.ResourceId = "WodTB2rJ8SobMgQ1nrtR245jxOrsovFi" + return nil } if option.ResourceType == CARD { if option.Tops == 0 { option.ResourceId = "WodTB2rJ8SobMgQ1nrtR245jxOrsovFi" + return nil } if option.Tops > DCU_TOPS { option.ResourceId = "jeYBVPwyIALjVYNzHvysh2o5CsBpBLp2" + return nil } //Todo add more dcu specs @@ -386,7 +389,12 @@ func (s *ShuguangAi) generateImageId(option *option.AiOption) error { return errors.New("failed to get imageId") } - if option.ResourceType == CPU { + for _, datum := range resp.Data { + ns := strings.Split(datum.Version, COLON) + if ns[0] == "jupyterlab-pytorch" { + option.ImageId = datum.ImageId + return nil + } } @@ -412,6 +420,7 @@ func (s *ShuguangAi) generateAlgorithmId(option *option.AiOption) error { if ns[0] == option.DatasetsName { algorithmId = option.TaskType + DASH + file.Name option.AlgorithmId = algorithmId + option.AlgorithmName = ns[1] return nil } } @@ -430,6 +439,23 @@ func (s *ShuguangAi) generateEnv(option *option.AiOption) error { } func (s *ShuguangAi) generateParams(option *option.AiOption) error { + if option.ResourceType == "" { + return errors.New("ResourceType not set") + } - return nil + epoch := "epoch" + COMMA + "1" + option.Params = append(option.Params, epoch) + + switch option.ResourceType { + case CPU: + card := "card" + COMMA + CPU + option.Params = append(option.Params, card) + return nil + case GPU: + card := "card" + COMMA + "cuda:0" + option.Params = append(option.Params, card) + return nil + } + + return errors.New("failed to set params") } diff --git a/api/internal/storeLink/storeLink.go b/api/internal/storeLink/storeLink.go index 3693d58c..c77d3df2 100644 --- a/api/internal/storeLink/storeLink.go +++ b/api/internal/storeLink/storeLink.go @@ -40,6 +40,7 @@ type Linkage interface { } const ( + COLON = ":" PY_PARAM_PREFIX = "--" SPACE = " " UNDERSCORE = "_" From a32ff30ff082082d2d6e433abd163e3d1dcfaf12 Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 13 Mar 2024 17:33:09 +0800 Subject: [PATCH 05/12] modified aitask submit options Former-commit-id: 1eb8398a899ff5bb1129dfdf6b2559cf1ec0130c --- api/internal/storeLink/octopus.go | 7 ++--- api/internal/storeLink/shuguangai.go | 38 +++++++++++++++++----------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/api/internal/storeLink/octopus.go b/api/internal/storeLink/octopus.go index 8060ca05..7dc97026 100644 --- a/api/internal/storeLink/octopus.go +++ b/api/internal/storeLink/octopus.go @@ -46,7 +46,8 @@ const ( SAILINGSI = "sailingsi" MLU = "MLU" CAMBRICONMLU290 = 256 - GCU = "enflame" + GCU = "GCU" + ENFLAME = "enflame" EnflameT20 = 128 BASE_TOPS = 128 CAMBRICON = "cambricon" @@ -57,7 +58,7 @@ const ( var ( cardAliasMap = map[string]string{ MLU: CAMBRICON, - GCU: GCU, + GCU: ENFLAME, } ) @@ -449,7 +450,7 @@ func (o *OctopusLink) generateAlgorithmId(option *option.AiOption) error { for _, algorithm := range resp.Payload.Algorithms { if algorithm.FrameworkName == strings.Title(option.TaskType) { - ns := strings.Split(algorithm.AlgorithmName, DASH) + ns := strings.Split(algorithm.AlgorithmName, UNDERSCORE) if ns[0] != option.DatasetsName { continue } diff --git a/api/internal/storeLink/shuguangai.go b/api/internal/storeLink/shuguangai.go index 36c9311b..1bd86443 100644 --- a/api/internal/storeLink/shuguangai.go +++ b/api/internal/storeLink/shuguangai.go @@ -57,17 +57,17 @@ var RESOURCESGAIMAP = map[string]ResourceSpecSGAI{ }, "OBtVaaXAv9n9FbLR7pWAoa3yR13jXwNc": { CPU: 2, - GPU: 1, + GPU: 3, RAM: 4 * RAM_SIZE_1G, }, "sBWfpkntUzsWYly11kdwEHZOYYIsFmve": { - CPU: 5, - GPU: 1, - RAM: 10 * RAM_SIZE_1G, + CPU: 4, + GPU: 4, + RAM: 8 * RAM_SIZE_1G, }, "jeYBVPwyIALjVYNzHvysh2o5CsBpBLp2": { CPU: 5, - GPU: 2, + GPU: 5, RAM: 10 * RAM_SIZE_1G, }, } @@ -75,9 +75,9 @@ var RESOURCESGAIMAP = map[string]ResourceSpecSGAI{ var RESOURCESPECSAI = map[string]string{ "WodTB2rJ8SobMgQ1nrtR245jxOrsovFi": "CPU:1, DCU:1, RAM:2G", "6d41v1XV53MQPmQOJ5kNatIck9yl8nWZ": "CPU:1, DCU:2, RAM:2G", - "OBtVaaXAv9n9FbLR7pWAoa3yR13jXwNc": "CPU:2, DCU:1, RAM:4G", - "sBWfpkntUzsWYly11kdwEHZOYYIsFmve": "CPU:5, DCU:1, RAM:10G", - "jeYBVPwyIALjVYNzHvysh2o5CsBpBLp2": "CPU:5, DCU:2, RAM:10G", + "OBtVaaXAv9n9FbLR7pWAoa3yR13jXwNc": "CPU:2, DCU:3, RAM:4G", + "sBWfpkntUzsWYly11kdwEHZOYYIsFmve": "CPU:4, DCU:4, RAM:8G", + "jeYBVPwyIALjVYNzHvysh2o5CsBpBLp2": "CPU:5, DCU:5, RAM:10G", } type ResourceSpecSGAI struct { @@ -356,17 +356,25 @@ func (s *ShuguangAi) generateResourceId(option *option.AiOption) error { } if option.ResourceType == CARD { - if option.Tops == 0 { + if 0 <= option.Tops && option.Tops <= DCU_TOPS { option.ResourceId = "WodTB2rJ8SobMgQ1nrtR245jxOrsovFi" return nil } - if option.Tops > DCU_TOPS { + cardNum := 5 + for k, v := range RESOURCESGAIMAP { + for i := 1; i <= cardNum; i++ { + if float64(i)*DCU_TOPS <= option.Tops && option.Tops <= float64(v.GPU)*DCU_TOPS { + option.ResourceId = k + return nil + } + } + } + + if option.Tops > float64(cardNum)*DCU_TOPS { option.ResourceId = "jeYBVPwyIALjVYNzHvysh2o5CsBpBLp2" return nil } - - //Todo add more dcu specs } return errors.New("failed to get ResourceId") @@ -443,15 +451,15 @@ func (s *ShuguangAi) generateParams(option *option.AiOption) error { return errors.New("ResourceType not set") } - epoch := "epoch" + COMMA + "1" - option.Params = append(option.Params, epoch) + //epoch := "epoch" + COMMA + "1" + //option.Params = append(option.Params, epoch) switch option.ResourceType { case CPU: card := "card" + COMMA + CPU option.Params = append(option.Params, card) return nil - case GPU: + case CARD: card := "card" + COMMA + "cuda:0" option.Params = append(option.Params, card) return nil From cbc4674662fa07a3ee85f83af894d3f80fa979af Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Wed, 13 Mar 2024 20:49:10 +0800 Subject: [PATCH 06/12] pcm-client for participant to pull and push task info Former-commit-id: 9e0057609cdd0c9aa60a1c97d23a8012254fadd1 --- api/client/client.go | 13 ++++ api/client/client_impl.go | 41 +++++++++++ api/client/task.go | 41 +++++++++++ api/client/task_impl.go | 143 ++++++++++++++++++++++++++++++++++++++ api/client/types.go | 79 +++++++++++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 api/client/client.go create mode 100644 api/client/client_impl.go create mode 100644 api/client/task.go create mode 100644 api/client/task_impl.go create mode 100644 api/client/types.go diff --git a/api/client/client.go b/api/client/client.go new file mode 100644 index 00000000..1e13a835 --- /dev/null +++ b/api/client/client.go @@ -0,0 +1,13 @@ +package client + +type Options struct { + Url string + DataSource string +} +type Client interface { + Task(TaskOptions) (Task, error) +} + +func NewClient(options Options) (Client, error) { + return newClient(options) +} diff --git a/api/client/client_impl.go b/api/client/client_impl.go new file mode 100644 index 00000000..3b69c1b8 --- /dev/null +++ b/api/client/client_impl.go @@ -0,0 +1,41 @@ +package client + +import ( + "gorm.io/driver/mysql" + "gorm.io/gorm" + "gorm.io/gorm/logger" + "gorm.io/gorm/schema" + "time" +) + +type client struct { + url string + dataSource string + DbEngin *gorm.DB +} + +func (c *client) Task(options TaskOptions) (Task, error) { + task, _ := newTask(c, &options) + return task, nil +} + +func newClient(options Options) (Client, error) { + //init dbEngine + dbEngin, _ := gorm.Open(mysql.Open(options.DataSource), &gorm.Config{ + NamingStrategy: schema.NamingStrategy{ + SingularTable: true, + }, + Logger: logger.Default.LogMode(logger.Warn), + }) + sqlDB, _ := dbEngin.DB() + sqlDB.SetMaxIdleConns(10) + sqlDB.SetMaxOpenConns(50) + sqlDB.SetConnMaxLifetime(time.Hour) + c := &client{ + url: options.Url, + dataSource: options.DataSource, + DbEngin: dbEngin, + } + + return c, nil +} diff --git a/api/client/task.go b/api/client/task.go new file mode 100644 index 00000000..557f2052 --- /dev/null +++ b/api/client/task.go @@ -0,0 +1,41 @@ +package client + +type TaskOptions struct { + pullTaskInfoReq PullTaskInfoReq + pushTaskInfoReq PushTaskInfoReq + pushResourceInfoReq PushResourceInfoReq +} + +type PullTaskInfoReq struct { + AdapterId int64 `json:"adapterId"` +} + +type PullTaskInfoResp struct { + HpcInfoList []*HpcInfo `json:"HpcInfoList,omitempty"` + CloudInfoList []*CloudInfo `json:"CloudInfoList,omitempty"` + AiInfoList []*AiInfo `json:"AiInfoList,omitempty"` + VmInfoList []*VmInfo `json:"VmInfoList,omitempty"` +} + +type PushTaskInfoReq struct { + AdapterId int64 `json:"adapterId"` + HpcInfoList []*HpcInfo + CloudInfoList []*CloudInfo + AiInfoList []*AiInfo + VmInfoList []*VmInfo +} + +type PushTaskInfoResp struct { + Code int64 + Msg string +} + +type PushResourceInfoReq struct { + AdapterId int64 `json:"adapterId"` +} + +type Task interface { + PullTaskInfo(pullTaskInfoReq PullTaskInfoReq) (*PullTaskInfoResp, error) + PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp, error) + PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) +} diff --git a/api/client/task_impl.go b/api/client/task_impl.go new file mode 100644 index 00000000..cb716d65 --- /dev/null +++ b/api/client/task_impl.go @@ -0,0 +1,143 @@ +package client + +import ( + "github.com/zeromicro/go-zero/core/logx" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + "gorm.io/gorm" + "log" + "strings" + "sync" +) + +type task struct { + sync.RWMutex + client *client + options *TaskOptions + log log.Logger +} + +func newTask(client *client, options *TaskOptions) (*task, error) { + task := &task{ + RWMutex: sync.RWMutex{}, + client: client, + options: options, + log: log.Logger{}, + } + return task, nil +} + +func (t task) PullTaskInfo(pullTaskInfoReq PullTaskInfoReq) (*PullTaskInfoResp, error) { + result := PullTaskInfoResp{} + // 查询p端类型 + var kind int32 + t.client.DbEngin.Raw("select type as kind from `t_adapter` where id = ?", pullTaskInfoReq.AdapterId).Scan(&kind) + // 查询云智超中的数据列表 + switch kind { + case 2: + var hpcModelList []models.TaskHpc + findModelList(pullTaskInfoReq.AdapterId, t.client.DbEngin, &hpcModelList) + utils.Convert(hpcModelList, &result.HpcInfoList) + case 0: + var cloudModelList []models.Cloud + findModelList(pullTaskInfoReq.AdapterId, t.client.DbEngin, &cloudModelList) + utils.Convert(cloudModelList, &result.CloudInfoList) + case 1: + var aiModelList []models.Ai + findModelList(pullTaskInfoReq.AdapterId, t.client.DbEngin, &aiModelList) + utils.Convert(aiModelList, &result.AiInfoList) + } + return &result, nil +} + +func (t task) PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp, error) { + // 查询p端类型 + var kind int32 + t.client.DbEngin.Raw("select type as kind from t_adapter where id = ?", pushTaskInfoReq.AdapterId).Scan(&kind) + switch kind { + case 0: + for _, cloudInfo := range pushTaskInfoReq.CloudInfoList { + t.client.DbEngin.Exec("update cloud set status = ?,start_time = ?,result = ? where participant_id = ? and id = ?", + cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, pushTaskInfoReq.AdapterId, cloudInfo.Id) + syncTask(t.client.DbEngin, cloudInfo.TaskId) + } + case 2: + for _, hpcInfo := range pushTaskInfoReq.HpcInfoList { + t.client.DbEngin.Exec("update task_hpc set status = ?,start_time = ?,job_id = ? where cluster_id = ? and task_id = ? and name = ?", + hpcInfo.Status, hpcInfo.StartTime, hpcInfo.RunningTime, hpcInfo.JobId, pushTaskInfoReq.AdapterId, hpcInfo.TaskId, hpcInfo.Name) + syncTask(t.client.DbEngin, hpcInfo.TaskId) + } + case 1: + for _, aiInfo := range pushTaskInfoReq.AiInfoList { + t.client.DbEngin.Exec("update ai set status = ?,start_time = ?,project_id = ?,job_id = ? where participant_id = ? and task_id = ? and name = ?", + aiInfo.Status, aiInfo.StartTime, aiInfo.ProjectId, aiInfo.JobId, pushTaskInfoReq.AdapterId, aiInfo.TaskId, aiInfo.Name) + syncTask(t.client.DbEngin, aiInfo.TaskId) + } + } + + return &PushTaskInfoResp{}, nil +} + +func (t task) PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) { + //TODO implement me + panic("implement me") +} + +func findModelList(participantId int64, dbEngin *gorm.DB, data interface{}) error { + tx := dbEngin.Where("cluster_id = (select id from t_cluster where adapter_id = ?) AND status NOT IN ?", participantId, []string{"Deleted", "Succeeded", "Completed", "Failed"}).Find(data) + if tx.Error != nil { + return tx.Error + } + return nil +} + +func syncTask(gorm *gorm.DB, taskId int64) { + + var allStatus string + tx := gorm.Raw("SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.status) ,GROUP_CONCAT(DISTINCT a.status) ,GROUP_CONCAT(DISTINCT c.status))as status from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?", taskId).Scan(&allStatus) + if tx.Error != nil { + logx.Error(tx.Error) + } + // 子状态统一则修改主任务状态 + statusArray := strings.Split(allStatus, ",") + if len(removeRepeatedElement(statusArray)) == 1 { + updateTask(gorm, taskId, statusArray[0]) + + } + // 子任务包含失败状态 主任务则失败 + if strings.Contains(allStatus, constants.Failed) { + updateTask(gorm, taskId, constants.Failed) + + } + if strings.Contains(allStatus, constants.Running) { + updateTask(gorm, taskId, constants.Running) + } + +} + +func updateTask(gorm *gorm.DB, taskId int64, status string) { + var task models.Task + gorm.Where("id = ? ", taskId).Find(&task) + if task.Status != status { + task.Status = status + gorm.Updates(&task) + } +} + +func removeRepeatedElement(arr []string) (newArr []string) { + newArr = make([]string, 0) + for i := 0; i < len(arr); i++ { + repeat := false + for j := i + 1; j < len(arr); j++ { + if arr[i] == arr[j] { + repeat = true + break + } + } + if !repeat { + newArr = append(newArr, arr[i]) + } + } + return +} diff --git a/api/client/types.go b/api/client/types.go new file mode 100644 index 00000000..69e828ab --- /dev/null +++ b/api/client/types.go @@ -0,0 +1,79 @@ +package client + +type HpcInfo struct { + ParticipantId int64 `json:"participantId,omitempty"` + TaskId int64 `json:"taskId,omitempty"` + JobId string `json:"jobId,omitempty"` + Name string `json:"name,omitempty"` + Status string `json:"status,omitempty"` + StartTime string `json:"startTime,omitempty"` + RunningTime int64 `json:"runningTime,omitempty"` + Result string `json:"result,omitempty"` + WorkDir string `json:"workDir,omitempty"` + WallTime string `json:"wallTime,omitempty"` + CmdScript string `json:"cmdScript,omitempty"` + DerivedEs string `json:"derivedEs,omitempty"` + Cluster string `json:"cluster,omitempty"` + BlockId string `json:"blockId,omitempty"` + AllocNodes uint32 `json:"allocNodes,omitempty"` + AllocCpu uint32 `json:"allocCpu,omitempty"` + Version string `json:"version,omitempty"` + Account string `json:"account,omitempty"` + ExitCode uint32 `json:"exitCode,omitempty"` + AssocId uint32 `json:"assocId,omitempty"` + AppType string `json:"appType,omitempty"` + AppName string `json:"appName,omitempty"` + Queue string `json:"queue,omitempty"` + SubmitType string `json:"submitType,omitempty"` + NNode string `json:"nNode,omitempty"` + StdOutFile string `json:"stdOutFile,omitempty"` + StdErrFile string `json:"stdErrFile,omitempty"` + StdInput string `json:"stdInput,omitempty"` + Environment string `json:"environment,omitempty"` +} + +type CloudInfo struct { + Participant int64 `json:"participant,omitempty"` + Id int64 `json:"id,omitempty"` + TaskId int64 `json:"taskId,omitempty"` + ApiVersion string `json:"apiVersion,omitempty"` + Kind string `json:"kind,omitempty"` + Namespace string `json:"namespace,omitempty"` + Name string `json:"name,omitempty"` + Status string `json:"status,omitempty"` + StartTime string `json:"startTime,omitempty"` + RunningTime int64 `json:"runningTime,omitempty"` + Result string `json:"result,omitempty"` + YamlString string `json:"yamlString,omitempty"` +} + +type AiInfo struct { + ParticipantId int64 `json:"participantId,omitempty"` + TaskId int64 `json:"taskId,omitempty"` + ProjectId string `json:"project_id,omitempty"` + Name string `json:"name,omitempty"` + Status string `json:"status,omitempty"` + StartTime string `json:"startTime,omitempty"` + RunningTime int64 `json:"runningTime,omitempty"` + Result string `json:"result,omitempty"` + JobId string `json:"jobId,omitempty"` + CreateTime string `json:"createTime,omitempty"` + ImageUrl string `json:"imageUrl,omitempty"` + Command string `json:"command,omitempty"` + FlavorId string `json:"flavorId,omitempty"` + SubscriptionId string `json:"subscriptionId,omitempty"` + ItemVersionId string `json:"itemVersionId,omitempty"` +} + +type VmInfo struct { + ParticipantId int64 `json:"participantId,omitempty"` + TaskId int64 `json:"taskId,omitempty"` + Name string `json:"name,omitempty"` + FlavorRef string `json:"flavor_ref,omitempty"` + ImageRef string `json:"image_ref,omitempty"` + NetworkUuid string `json:"network_uuid,omitempty"` + BlockUuid string `json:"block_uuid,omitempty"` + SourceType string `json:"source_type,omitempty"` + DeleteOnTermination bool `json:"delete_on_termination,omitempty"` + State string `json:"state,omitempty"` +} From 5a314f4cf82cd8ad7ab78d0e86eab730c72c28f5 Mon Sep 17 00:00:00 2001 From: jagger Date: Thu, 14 Mar 2024 10:41:06 +0800 Subject: [PATCH 07/12] :sparkles: Dictionary data lists support paging queries Signed-off-by: jagger Former-commit-id: bd79becb758037abb2338825453e13760cd15580 --- api/desc/core/pcm-core.api | 20 ++++++++ api/desc/pcm.api | 7 ++- .../dictionary/listdictitembycodehandler.go | 24 ++++++++++ api/internal/handler/routes.go | 5 ++ .../logic/dictionary/editdictitemlogic.go | 1 + .../logic/dictionary/editdictlogic.go | 1 + .../dictionary/listdictitembycodelogic.go | 41 +++++++++++++++++ .../logic/dictionary/listdictitemlogic.go | 46 +++++++++++++++---- .../logic/dictionary/listdictlogic.go | 40 ++++++++++++---- api/internal/types/types.go | 18 ++++++++ 10 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 api/internal/handler/dictionary/listdictitembycodehandler.go create mode 100644 api/internal/logic/dictionary/listdictitembycodelogic.go diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 87a531a6..82611a16 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -839,6 +839,7 @@ type ( Description string `form:"description,optional"` Type string `form:"type,optional"` Status string `form:"status,optional"` + PageInfo } DictEditReq { @@ -889,6 +890,7 @@ type ( Type string `form:"type,optional"` ParentId string `form:"parentId,optional"` Status string `form:"status,optional"` + PageInfo } DictItemEditReq { @@ -920,6 +922,10 @@ type ( DictItems { List []DictItemInfo `json:"list,omitempty"` } + + DictCodeReq { + DictCode string `path:"dictCode"` + } ) type ( @@ -930,4 +936,18 @@ type ( CIds { Ids []string `json:"ids,omitempty" validate:"required"` } +) + +type ( + PageInfo { + PageNum int `form:"pageNum"` + PageSize int `form:"pageSize"` + } + + PageResult { + List interface{} `json:"list,omitempty"` + Total int64 `json:"total,omitempty"` + PageNum int `json:"pageNum,omitempty"` + PageSize int `json:"pageSize,omitempty"` + } ) \ No newline at end of file diff --git a/api/desc/pcm.api b/api/desc/pcm.api index f082f3f2..465621dd 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -878,7 +878,7 @@ service pcm { get /dict/:id (CId) returns (DictResp) @handler ListDict - get /dicts (DictReq) returns (Dicts) + get /dicts (DictReq) returns (PageResult) @handler AddDict post /dict (DictEditReq) returns (DictResp) @@ -893,7 +893,7 @@ service pcm { get /dictItem/:id (CId) returns (DictItemResp) @handler ListDictItem - get /dictItems (DictItemReq) returns (DictItems) + get /dictItems (DictItemReq) returns (PageResult) @handler AddDictItem post /dictItem (DictItemEditReq) returns (DictItemResp) @@ -903,4 +903,7 @@ service pcm { @handler DeleteDictItem delete /dictItem/:id (CId) returns (DictItemResp) + + @handler ListDictItemByCode + get /dictItem/code/:dictCode (DictCodeReq) returns (PageResult) } \ No newline at end of file diff --git a/api/internal/handler/dictionary/listdictitembycodehandler.go b/api/internal/handler/dictionary/listdictitembycodehandler.go new file mode 100644 index 00000000..c6400185 --- /dev/null +++ b/api/internal/handler/dictionary/listdictitembycodehandler.go @@ -0,0 +1,24 @@ +package dictionary + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func ListDictItemByCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DictCodeReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := dictionary.NewListDictItemByCodeLogic(r.Context(), svcCtx) + resp, err := l.ListDictItemByCode(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 73b25377..33f818f4 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -1130,6 +1130,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/dictItem/:id", Handler: dictionary.DeleteDictItemHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/dictItem/code/:dictCode", + Handler: dictionary.ListDictItemByCodeHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/api/internal/logic/dictionary/editdictitemlogic.go b/api/internal/logic/dictionary/editdictitemlogic.go index 1960a483..b09de93b 100644 --- a/api/internal/logic/dictionary/editdictitemlogic.go +++ b/api/internal/logic/dictionary/editdictitemlogic.go @@ -30,6 +30,7 @@ func (l *EditDictItemLogic) EditDictItem(req *types.DictItemEditReq) (resp *type dictItem := &types.DictItemInfo{} result := l.svcCtx.DbEngin.Table("t_dict_item").First(&dictItem, req.Id) if errors.Is(result.Error, gorm.ErrRecordNotFound) { + logx.Errorf("Dictionary data editing failure. errors: %s", err.Error()) return nil, errors.New("DictItem does not exist") } utils.Convert(req, &dictItem) diff --git a/api/internal/logic/dictionary/editdictlogic.go b/api/internal/logic/dictionary/editdictlogic.go index 26e6930b..a9323e29 100644 --- a/api/internal/logic/dictionary/editdictlogic.go +++ b/api/internal/logic/dictionary/editdictlogic.go @@ -31,6 +31,7 @@ func (l *EditDictLogic) EditDict(req *types.DictEditReq) (resp *types.DictResp, dict := &types.DictInfo{} result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.Id) if errors.Is(result.Error, gorm.ErrRecordNotFound) { + logx.Errorf("Dictionary editing failure. errors: %s", err.Error()) return nil, errors.New("Dict does not exist") } utils.Convert(req, &dict) diff --git a/api/internal/logic/dictionary/listdictitembycodelogic.go b/api/internal/logic/dictionary/listdictitembycodelogic.go new file mode 100644 index 00000000..b8eb2331 --- /dev/null +++ b/api/internal/logic/dictionary/listdictitembycodelogic.go @@ -0,0 +1,41 @@ +package dictionary + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ListDictItemByCodeLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewListDictItemByCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictItemByCodeLogic { + return &ListDictItemByCodeLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ListDictItemByCodeLogic) ListDictItemByCode(req *types.DictCodeReq) (resp *types.PageResult, err error) { + var dictList []types.DictItemInfo + resp = &types.PageResult{} + db := l.svcCtx.DbEngin.Model(&types.DictInfo{}).Table("t_dict") + + // 左连接查询 + db.Select("t_dict_item.*").Joins("left join t_dict_item on t_dict.id = t_dict_item.dict_id"). + Where("t_dict.dict_code = ?", req.DictCode). + Where("t_dict_item.status", 1). + Order("t_dict_item.sort_order").Scan(&dictList) + if err != nil { + return resp, err + } + resp.List = dictList + return resp, nil +} diff --git a/api/internal/logic/dictionary/listdictitemlogic.go b/api/internal/logic/dictionary/listdictitemlogic.go index 2179aeec..3c209ad8 100644 --- a/api/internal/logic/dictionary/listdictitemlogic.go +++ b/api/internal/logic/dictionary/listdictitemlogic.go @@ -2,8 +2,6 @@ package dictionary import ( "context" - "fmt" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" @@ -24,16 +22,44 @@ func NewListDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *List } } -func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.DictItems, err error) { - resp = &types.DictItems{} - sql := fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null ORDER BY create_time Desc`) +func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.PageResult, err error) { + limit := req.PageSize + offset := req.PageSize * (req.PageNum - 1) + resp = &types.PageResult{} + var dictList []types.DictItemInfo + db := l.svcCtx.DbEngin.Model(&types.DictItemInfo{}).Table("t_dict_item") + if req.ItemText != "" { - sql = fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null and c.item_text like '%%%s%%'`, req.ItemText) + db = db.Where("item_text LIKE ?", "%"+req.ItemText+"%") } - tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List) - if tx.Error != nil { - logx.Errorf(tx.Error.Error()) - return nil, tx.Error + if req.ItemValue != "" { + db = db.Where("item_value LIKE ?", "%"+req.ItemValue+"%") } + if req.Type != "" { + db = db.Where("type = ?", req.Type) + } + if req.ParentId != "" { + db = db.Where("parent_id = ?", req.ParentId) + } + if req.Status != "" { + db = db.Where("status = ?", req.Status) + } + if req.DictId != "" { + db = db.Where("dict_id = ?", req.DictId) + } + var total int64 + err = db.Count(&total).Error + + if err != nil { + return resp, err + } + db = db.Limit(limit).Offset(offset) + err = db.Order("create_time desc").Find(&dictList).Error + + resp.List = dictList + resp.PageSize = req.PageSize + resp.PageNum = req.PageNum + resp.Total = total + return resp, nil } diff --git a/api/internal/logic/dictionary/listdictlogic.go b/api/internal/logic/dictionary/listdictlogic.go index 15959cef..35122a3e 100644 --- a/api/internal/logic/dictionary/listdictlogic.go +++ b/api/internal/logic/dictionary/listdictlogic.go @@ -2,8 +2,6 @@ package dictionary import ( "context" - "fmt" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" @@ -24,16 +22,38 @@ func NewListDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDict } } -func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.Dicts, err error) { - resp = &types.Dicts{} - sqlStr := "select * from t_dict where `deleted_at` IS NULL ORDER BY create_time Desc" +func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.PageResult, err error) { + limit := req.PageSize + offset := req.PageSize * (req.PageNum - 1) + resp = &types.PageResult{} + var dictList []types.DictInfo + db := l.svcCtx.DbEngin.Model(&types.DictInfo{}).Table("t_dict") + if req.DictName != "" { - sqlStr = fmt.Sprintf("select * from t_dict where `deleted_at` IS NULL and dict_name like '%%%s%%' ORDER BY create_time Desc", req.DictName) + db = db.Where("dict_name LIKE ?", "%"+req.DictName+"%") } - tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List) - if tx.Error != nil { - logx.Errorf(tx.Error.Error()) - return nil, tx.Error + if req.DictCode != "" { + db = db.Where("dict_code LIKE ?", "%"+req.DictCode+"%") } + if req.Type != "" { + db = db.Where("type = ?", req.Type) + } + if req.Status != "" { + db = db.Where("status = ?", req.Status) + } + var total int64 + err = db.Count(&total).Error + + if err != nil { + return resp, err + } + db = db.Limit(limit).Offset(offset) + err = db.Order("create_time desc").Find(&dictList).Error + + resp.List = dictList + resp.PageSize = req.PageSize + resp.PageNum = req.PageNum + resp.Total = total + return resp, nil } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 361b4a4c..e51aa30b 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -805,6 +805,7 @@ type DictReq struct { Description string `form:"description,optional"` Type string `form:"type,optional"` Status string `form:"status,optional"` + PageInfo } type DictEditReq struct { @@ -854,6 +855,7 @@ type DictItemReq struct { Type string `form:"type,optional"` ParentId string `form:"parentId,optional"` Status string `form:"status,optional"` + PageInfo } type DictItemEditReq struct { @@ -886,6 +888,10 @@ type DictItems struct { List []DictItemInfo `json:"list,omitempty"` } +type DictCodeReq struct { + DictCode string `path:"dictCode"` +} + type CId struct { Id string `path:"id":"id,omitempty" validate:"required"` } @@ -894,6 +900,18 @@ type CIds struct { Ids []string `json:"ids,omitempty" validate:"required"` } +type PageInfo struct { + PageNum int `form:"pageNum"` + PageSize int `form:"pageSize"` +} + +type PageResult struct { + List interface{} `json:"list,omitempty"` + Total int64 `json:"total,omitempty"` + PageNum int `json:"pageNum,omitempty"` + PageSize int `json:"pageSize,omitempty"` +} + type Job struct { SlurmVersion string `json:"slurmVersion"` Name string `json:"name"` From 7cb535a73952c18a965b975ef1f63f7d0363a4a5 Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Thu, 14 Mar 2024 11:21:28 +0800 Subject: [PATCH 08/12] change hpc model structure Former-commit-id: e1c2ea6e8441d0ccba5e26160a59ee44cc5fbd8f --- api/client/types.go | 72 +++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/api/client/types.go b/api/client/types.go index 69e828ab..06e0b00d 100644 --- a/api/client/types.go +++ b/api/client/types.go @@ -1,35 +1,49 @@ package client +import ( + "database/sql" + "time" +) + type HpcInfo struct { - ParticipantId int64 `json:"participantId,omitempty"` - TaskId int64 `json:"taskId,omitempty"` - JobId string `json:"jobId,omitempty"` - Name string `json:"name,omitempty"` - Status string `json:"status,omitempty"` - StartTime string `json:"startTime,omitempty"` - RunningTime int64 `json:"runningTime,omitempty"` - Result string `json:"result,omitempty"` - WorkDir string `json:"workDir,omitempty"` - WallTime string `json:"wallTime,omitempty"` - CmdScript string `json:"cmdScript,omitempty"` - DerivedEs string `json:"derivedEs,omitempty"` - Cluster string `json:"cluster,omitempty"` - BlockId string `json:"blockId,omitempty"` - AllocNodes uint32 `json:"allocNodes,omitempty"` - AllocCpu uint32 `json:"allocCpu,omitempty"` - Version string `json:"version,omitempty"` - Account string `json:"account,omitempty"` - ExitCode uint32 `json:"exitCode,omitempty"` - AssocId uint32 `json:"assocId,omitempty"` - AppType string `json:"appType,omitempty"` - AppName string `json:"appName,omitempty"` - Queue string `json:"queue,omitempty"` - SubmitType string `json:"submitType,omitempty"` - NNode string `json:"nNode,omitempty"` - StdOutFile string `json:"stdOutFile,omitempty"` - StdErrFile string `json:"stdErrFile,omitempty"` - StdInput string `json:"stdInput,omitempty"` - Environment string `json:"environment,omitempty"` + Id int64 `json:"id"` // id + TaskId int64 `json:"task_id"` // 任务id + JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) + ClusterId int64 `json:"cluster_id"` // 执行任务的集群id + Name string `json:"name"` // 名称 + Status string `json:"status"` // 状态 + CmdScript string `json:"cmd_script"` + StartTime string `json:"start_time"` // 开始时间 + RunningTime int64 `json:"running_time"` // 运行时间 + DerivedEs string `json:"derived_es"` + Cluster string `json:"cluster"` + BlockId int64 `json:"block_id"` + AllocNodes int64 `json:"alloc_nodes"` + AllocCpu int64 `json:"alloc_cpu"` + CardCount int64 `json:"card_count"` // 卡数 + Version string `json:"version"` + Account string `json:"account"` + WorkDir string `json:"work_dir"` // 工作路径 + AssocId int64 `json:"assoc_id"` + ExitCode int64 `json:"exit_code"` + WallTime string `json:"wall_time"` // 最大运行时间 + Result string `json:"result"` // 运行结果 + DeletedAt sql.NullTime `json:"deleted_at"` // 删除时间 + YamlString string `json:"yaml_string"` + AppType string `json:"app_type"` // 应用类型 + AppName string `json:"app_name"` // 应用名称 + Queue string `json:"queue"` // 队列名称 + SubmitType string `json:"submit_type"` // cmd(命令行模式) + NNode string `json:"n_node"` // 节点个数(当指定该参数时,GAP_NODE_STRING必须为"") + StdOutFile string `json:"std_out_file"` // 工作路径/std.err.%j + StdErrFile string `json:"std_err_file"` // 工作路径/std.err.%j + StdInput string `json:"std_input"` + Environment string `json:"environment"` + DeletedFlag int64 `json:"deleted_flag"` // 是否删除(0-否,1-是) + CreatedBy int64 `json:"created_by"` // 创建人 + CreatedTime time.Time `json:"created_time"` // 创建时间 + UpdatedBy int64 `json:"updated_by"` // 更新人 + UpdatedTime time.Time `json:"updated_time"` // 更新时间 } type CloudInfo struct { From 43bd51ce09ad5fb94391d7a64ea5ca561962f410 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Thu, 14 Mar 2024 16:57:12 +0800 Subject: [PATCH 09/12] Providing metrics information to Prometheus Former-commit-id: f3afc76fa6e855dfa3861424d062f9d629d7b0a8 --- api/desc/core/pcm-core.api | 142 ++++++++++-------- api/desc/pcm.api | 8 + api/internal/handler/core/metricshandler.go | 12 ++ .../handler/core/syncclusterloadhandler.go | 25 +++ api/internal/handler/routes.go | 10 ++ api/internal/logic/core/metricslogic.go | 28 ++++ .../logic/core/syncclusterloadlogic.go | 35 +++++ api/internal/types/types.go | 11 ++ pkg/tracker/queryoptions.go | 1 + pkg/tracker/tracker.go | 25 +++ 10 files changed, 233 insertions(+), 64 deletions(-) create mode 100644 api/internal/handler/core/metricshandler.go create mode 100644 api/internal/handler/core/syncclusterloadhandler.go create mode 100644 api/internal/logic/core/metricslogic.go create mode 100644 api/internal/logic/core/syncclusterloadlogic.go diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index df879ab2..7e24e18d 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -158,7 +158,7 @@ type ( centerResourcesResp { CentersIndex []CenterIndex `json:"centersIndex"` } - CenterIndex{ + CenterIndex { name string `json:"name"` cpu float32 `json:"cpu"` memory float32 `json:"memory"` @@ -166,6 +166,20 @@ type ( centerType string `json:"centerType"` } ) +type ( + syncClusterLoadReq { + clusterLoadRecords []ClusterLoadRecord `json:"clusterLoadRecords"` + } + ClusterLoadRecord { + ClusterName string `json:"clusterName"` + CpuUsage float64 `json:"cpuUsage"` + MemoryUsage float64 `json:"memoryUsage"` + DiskUsage float64 `json:"diskUsage"` + } +) + + + type ( getClusterListReq { Id int64 `form:"id"` @@ -670,7 +684,7 @@ type ( type ( AdapterQueryReq { - Id string `form:"id,optional" db:"id"` + Id string `form:"id,optional" db:"id"` Name string `form:"name,optional"` Type string `form:"type,optional"` Nickname string `form:"nickname,optional"` @@ -678,7 +692,7 @@ type ( Server string `form:"server,optional"` } AdapterReq { - Id string `json:"id,optional" db:"id"` + Id string `json:"id,optional" db:"id"` Name string `json:"name,optional"` Type string `json:"type,optional"` Nickname string `json:"nickname,optional"` @@ -686,7 +700,7 @@ type ( Server string `json:"server,optional"` } AdapterCreateReq { - Id string `json:"id,optional" db:"id"` + Id string `json:"id,optional" db:"id"` Name string `json:"name"` Type string `json:"type"` Nickname string `json:"nickname"` @@ -694,7 +708,7 @@ type ( Server string `json:"server"` } AdapterDelReq { - Id string `form:"id,optional" db:"id"` + Id string `form:"id,optional" db:"id"` } AdapterInfo { Id string `json:"id,omitempty" db:"id"` @@ -727,51 +741,51 @@ type ( ) type ClusterReq { - Id string `form:"id,optional"` - AdapterId string `form:"adapterId,optional"` - Name string `json:"name,optional"` - Nickname string `json:"nickname,optional"` - Description string `json:"description,optional"` - Server string `json:"server,optional"` - MonitorServer string `json:"monitorServer,optional"` - Username string `json:"username,optional"` - Password string `json:"password,optional"` - Token string `json:"token,optional"` - Ak string `json:"ak,optional"` - Sk string `json:"sk,optional"` - Region string `json:"region,optional"` - ProjectId string `json:"projectId,optional"` - Version string `json:"version,optional"` - Label string `json:"label,optional"` - OwnerId string `json:"ownerId,omitempty,optional"` - AuthType string `json:"authType,optional"` - Type string `json:"type,optional"` + Id string `form:"id,optional"` + AdapterId string `form:"adapterId,optional"` + Name string `json:"name,optional"` + Nickname string `json:"nickname,optional"` + Description string `json:"description,optional"` + Server string `json:"server,optional"` + MonitorServer string `json:"monitorServer,optional"` + Username string `json:"username,optional"` + Password string `json:"password,optional"` + Token string `json:"token,optional"` + Ak string `json:"ak,optional"` + Sk string `json:"sk,optional"` + Region string `json:"region,optional"` + ProjectId string `json:"projectId,optional"` + Version string `json:"version,optional"` + Label string `json:"label,optional"` + OwnerId string `json:"ownerId,omitempty,optional"` + AuthType string `json:"authType,optional"` + Type string `json:"type,optional"` } type ClusterDelReq { - Id string `form:"id,optional"` + Id string `form:"id,optional"` } type ClusterInfo { - Id string `json:"id,omitempty" db:"id"` - AdapterId string `json:"adapterId,omitempty" db:"adapter_id"` - Name string `json:"name,omitempty" db:"name"` - Nickname string `json:"nickname,omitempty" db:"nickname"` - Description string `json:"description,omitempty" db:"description"` - Server string `json:"server,omitempty" db:"server"` - MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"` - Username string `json:"username,omitempty" db:"username"` - Password string `json:"password,omitempty" db:"password"` - Token string `json:"token,omitempty" db:"token"` - Ak string `json:"ak,omitempty" db:"ak"` - Sk string `json:"sk,omitempty" db:"sk"` - Region string `json:"region,omitempty" db:"region"` - ProjectId string `json:"projectId,omitempty" db:"project_id"` - Version string `json:"version,omitempty" db:"version"` - Label string `json:"label,omitempty" db:"label"` - OwnerId string `json:"ownerId,omitempty" db:"owner_id"` - AuthType string `json:"authType,omitempty" db:"auth_type"` - CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + Id string `json:"id,omitempty" db:"id"` + AdapterId string `json:"adapterId,omitempty" db:"adapter_id"` + Name string `json:"name,omitempty" db:"name"` + Nickname string `json:"nickname,omitempty" db:"nickname"` + Description string `json:"description,omitempty" db:"description"` + Server string `json:"server,omitempty" db:"server"` + MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"` + Username string `json:"username,omitempty" db:"username"` + Password string `json:"password,omitempty" db:"password"` + Token string `json:"token,omitempty" db:"token"` + Ak string `json:"ak,omitempty" db:"ak"` + Sk string `json:"sk,omitempty" db:"sk"` + Region string `json:"region,omitempty" db:"region"` + ProjectId string `json:"projectId,omitempty" db:"project_id"` + Version string `json:"version,omitempty" db:"version"` + Label string `json:"label,omitempty" db:"label"` + OwnerId string `json:"ownerId,omitempty" db:"owner_id"` + AuthType string `json:"authType,omitempty" db:"auth_type"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` } type ClusterResp { @@ -786,7 +800,7 @@ type clusterSumReq { } -type clusterSumReqResp{ +type clusterSumReqResp { ClusterSum int `json:"ClusterSum,omitempty"` AdapterSum int `json:"AdapterSum,omitempty"` TaskSum int `json:"TaskSum,omitempty"` @@ -800,23 +814,23 @@ type ClusterRelationInfo { Version string `json:"version,omitempty" db:"version"` Server string `json:"server,omitempty" db:"server"` CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"` - CId string `json:"cId,omitempty" db:"id"` - CAdapterId string `json:"cAdapterId,omitempty" db:"adapter_id"` - CName string `json:"cName,omitempty" db:"name"` - CNickname string `json:"cNickname,omitempty" db:"nickname"` - CDescription string `json:"cDescription,omitempty" db:"description"` - CServer string `json:"cServer,omitempty" db:"server"` - CMonitorServer string `json:"cMonitorServer,omitempty" db:"monitor_server"` - CUsername string `json:"cUsername,omitempty" db:"username"` - CPassword string `json:"cPassword,omitempty" db:"password"` - CToken string `json:"cToken,omitempty" db:"token"` - CAk string `json:"cAk,omitempty" db:"ak"` - CSk string `json:"cSk,omitempty" db:"sk"` - CRegion string `json:"cRegion,omitempty" db:"region"` - CProjectId string `json:"cProjectId,omitempty" db:"project_id"` - CVersion string `json:"cVersion,omitempty" db:"version"` - CLabel string `json:"cLabel,omitempty" db:"label"` - COwnerId string `json:"cOwnerId,omitempty" db:"owner_id"` - CAuthType string `json:"cAuthType,omitempty" db:"auth_type"` - CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + CId string `json:"cId,omitempty" db:"id"` + CAdapterId string `json:"cAdapterId,omitempty" db:"adapter_id"` + CName string `json:"cName,omitempty" db:"name"` + CNickname string `json:"cNickname,omitempty" db:"nickname"` + CDescription string `json:"cDescription,omitempty" db:"description"` + CServer string `json:"cServer,omitempty" db:"server"` + CMonitorServer string `json:"cMonitorServer,omitempty" db:"monitor_server"` + CUsername string `json:"cUsername,omitempty" db:"username"` + CPassword string `json:"cPassword,omitempty" db:"password"` + CToken string `json:"cToken,omitempty" db:"token"` + CAk string `json:"cAk,omitempty" db:"ak"` + CSk string `json:"cSk,omitempty" db:"sk"` + CRegion string `json:"cRegion,omitempty" db:"region"` + CProjectId string `json:"cProjectId,omitempty" db:"project_id"` + CVersion string `json:"cVersion,omitempty" db:"version"` + CLabel string `json:"cLabel,omitempty" db:"label"` + COwnerId string `json:"cOwnerId,omitempty" db:"owner_id"` + CAuthType string `json:"cAuthType,omitempty" db:"auth_type"` + CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"` } diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 2651f6ee..1b15ac59 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -112,6 +112,14 @@ service pcm { @doc "Center Resources top3" @handler centerResourcesHandler get /core/centerResources returns (centerResourcesResp) + + @doc "Synchronize Cluster Load Information" + @handler syncClusterLoadHandler + post /core/syncClusterLoad (syncClusterLoadReq) + + @doc "metrics" + @handler metricsHandler + get /core/metrics } //hpc二级接口 diff --git a/api/internal/handler/core/metricshandler.go b/api/internal/handler/core/metricshandler.go new file mode 100644 index 00000000..fb157525 --- /dev/null +++ b/api/internal/handler/core/metricshandler.go @@ -0,0 +1,12 @@ +package core + +import ( + "github.com/prometheus/client_golang/prometheus/promhttp" + "net/http" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" +) + +func MetricsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return promhttp.Handler().ServeHTTP +} diff --git a/api/internal/handler/core/syncclusterloadhandler.go b/api/internal/handler/core/syncclusterloadhandler.go new file mode 100644 index 00000000..cd8de3a3 --- /dev/null +++ b/api/internal/handler/core/syncclusterloadhandler.go @@ -0,0 +1,25 @@ +package core + +import ( + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" +) + +func SyncClusterLoadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.SyncClusterLoadReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := core.NewSyncClusterLoadLogic(r.Context(), svcCtx) + err := l.SyncClusterLoad(&req) + result.HttpResult(r, w, nil, err) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 0280f82d..f944795a 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -133,6 +133,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/core/centerResources", Handler: core.CenterResourcesHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/core/syncClusterLoad", + Handler: core.SyncClusterLoadHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/core/metrics", + Handler: core.MetricsHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/api/internal/logic/core/metricslogic.go b/api/internal/logic/core/metricslogic.go new file mode 100644 index 00000000..9f947fe3 --- /dev/null +++ b/api/internal/logic/core/metricslogic.go @@ -0,0 +1,28 @@ +package core + +import ( + "context" + + "github.com/zeromicro/go-zero/core/logx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" +) + +type MetricsLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewMetricsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MetricsLogic { + return &MetricsLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *MetricsLogic) Metrics() error { + // todo: add your logic here and delete this line + + return nil +} diff --git a/api/internal/logic/core/syncclusterloadlogic.go b/api/internal/logic/core/syncclusterloadlogic.go new file mode 100644 index 00000000..2c0f87e9 --- /dev/null +++ b/api/internal/logic/core/syncclusterloadlogic.go @@ -0,0 +1,35 @@ +package core + +import ( + "context" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker" + + "github.com/zeromicro/go-zero/core/logx" +) + +type SyncClusterLoadLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewSyncClusterLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SyncClusterLoadLogic { + return &SyncClusterLoadLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *SyncClusterLoadLogic) SyncClusterLoad(req *types.SyncClusterLoadReq) error { + if len(req.ClusterLoadRecords) != 0 { + for _, record := range req.ClusterLoadRecords { + tracker.ClusterCpuGauge.WithLabelValues(record.ClusterName).Set(record.CpuUsage) + tracker.ClusterMemoryGauge.WithLabelValues(record.ClusterName).Set(record.MemoryUsage) + tracker.ClusterDiskGauge.WithLabelValues(record.ClusterName).Set(record.DiskUsage) + } + } + return nil +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index bcc6c69c..eb4c203f 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -150,6 +150,17 @@ type CenterIndex struct { CenterType string `json:"centerType"` } +type SyncClusterLoadReq struct { + ClusterLoadRecords []ClusterLoadRecord `json:"clusterLoadRecords"` +} + +type ClusterLoadRecord struct { + ClusterName string `json:"clusterName"` + CpuUsage float64 `json:"cpuUsage"` + MemoryUsage float64 `json:"memoryUsage"` + DiskUsage float64 `json:"diskUsage"` +} + type GetClusterListReq struct { Id int64 `form:"id"` } diff --git a/pkg/tracker/queryoptions.go b/pkg/tracker/queryoptions.go index 06968907..bc0bc9ac 100644 --- a/pkg/tracker/queryoptions.go +++ b/pkg/tracker/queryoptions.go @@ -254,6 +254,7 @@ type ControllerOption struct { Namespace string Kind string WorkloadName string + PodsName string Level string } diff --git a/pkg/tracker/tracker.go b/pkg/tracker/tracker.go index c24b07f9..298d7635 100644 --- a/pkg/tracker/tracker.go +++ b/pkg/tracker/tracker.go @@ -18,6 +18,7 @@ import ( "context" "github.com/prometheus/client_golang/api" v1 "github.com/prometheus/client_golang/api/prometheus/v1" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "strconv" "strings" @@ -25,6 +26,30 @@ import ( "time" ) +var ( + ClusterCpuGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "cluster_cpu_usage", + Help: "Cluster CPU Utilization Rate.", + }, []string{"cluster_name"}) + ClusterMemoryGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "cluster_memory_usage", + Help: "Cluster Memory Utilization Rate.", + }, []string{"cluster_name"}) + ClusterDiskGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "cluster_disk_usage", + Help: "Cluster Disk Utilization Rate.", + }, []string{"cluster_name"}) + metrics = []prometheus.Collector{ + ClusterCpuGauge, + ClusterMemoryGauge, + ClusterDiskGauge, + } +) + +func init() { + prometheus.MustRegister(metrics...) +} + type Prometheus struct { prometheus Interface client v1.API From 7c18ceb63cc94a73ceef23165d64b550fa01ce0b Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Thu, 14 Mar 2024 17:02:35 +0800 Subject: [PATCH 10/12] add clusterType info for hpc task Former-commit-id: bfc1b11eb5673c989ba33e09dc2e569ece7f14aa --- api/client/task_impl.go | 13 +++++++++++++ api/client/types.go | 13 +++++++------ go.mod | 6 ++---- go.sum | 8 -------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/api/client/task_impl.go b/api/client/task_impl.go index cb716d65..8b141cea 100644 --- a/api/client/task_impl.go +++ b/api/client/task_impl.go @@ -1,6 +1,7 @@ package client import ( + "github.com/jinzhu/copier" "github.com/zeromicro/go-zero/core/logx" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" @@ -39,6 +40,18 @@ func (t task) PullTaskInfo(pullTaskInfoReq PullTaskInfoReq) (*PullTaskInfoResp, var hpcModelList []models.TaskHpc findModelList(pullTaskInfoReq.AdapterId, t.client.DbEngin, &hpcModelList) utils.Convert(hpcModelList, &result.HpcInfoList) + if len(result.HpcInfoList) > 0 { + for i, hpcInfo := range hpcModelList { + err := copier.CopyWithOption(result.HpcInfoList[i], hpcInfo, copier.Option{Converters: utils.Converters}) + if err != nil { + return nil, err + } + var clusterType string + t.client.DbEngin.Raw("SELECT label FROM `t_cluster` where id = ? ", hpcInfo.ClusterId).Scan(&clusterType) + + result.HpcInfoList[i].ClusterType = clusterType + } + } case 0: var cloudModelList []models.Cloud findModelList(pullTaskInfoReq.AdapterId, t.client.DbEngin, &cloudModelList) diff --git a/api/client/types.go b/api/client/types.go index 06e0b00d..155ad628 100644 --- a/api/client/types.go +++ b/api/client/types.go @@ -6,12 +6,13 @@ import ( ) type HpcInfo struct { - Id int64 `json:"id"` // id - TaskId int64 `json:"task_id"` // 任务id - JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) - ClusterId int64 `json:"cluster_id"` // 执行任务的集群id - Name string `json:"name"` // 名称 - Status string `json:"status"` // 状态 + Id int64 `json:"id"` // id + TaskId int64 `json:"task_id"` // 任务id + JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) + ClusterId int64 `json:"cluster_id"` // 执行任务的集群id + ClusterType string `json:"cluster_type"` // 执行任务的集群类型 + Name string `json:"name"` // 名称 + Status string `json:"status"` // 状态 CmdScript string `json:"cmd_script"` StartTime string `json:"start_time"` // 开始时间 RunningTime int64 `json:"running_time"` // 运行时间 diff --git a/go.mod b/go.mod index cae9b25c..13dde252 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,6 @@ require ( gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240307072630-6ff50727536a gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5 gitlink.org.cn/jcce-pcm/pcm-ac v0.0.0-20240301085553-f6ad88fa357a - gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.19 gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230904090036-24fc730ec87d gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20231101085149-724c7c4cc090 gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20240222124813-e275cfa342f4 @@ -44,6 +43,7 @@ require ( ) require ( + github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect github.com/alibabacloud-go/tea v1.1.17 // indirect @@ -97,9 +97,6 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/redis/go-redis/v9 v9.5.1 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes v0.0.0-20231214084401-de9ac5db7246 // indirect - gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231102023739-81a3d353c10d // indirect - gitlink.org.cn/jcce-pcm/pcm-slurm v0.0.0-20231107115628-f74106c47dfa // indirect go.etcd.io/etcd/api/v3 v3.5.12 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect go.etcd.io/etcd/client/v3 v3.5.12 // indirect @@ -117,6 +114,7 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect golang.org/x/crypto v0.21.0 // indirect + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.22.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect diff --git a/go.sum b/go.sum index 6905bf91..ebd640ab 100644 --- a/go.sum +++ b/go.sum @@ -1006,20 +1006,12 @@ gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5 h1:+/5vnz gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5/go.mod h1:97AlUXN13g9UN3+9/DzCHpeoU5sbdyv0IQuTEHNexzQ= gitlink.org.cn/jcce-pcm/pcm-ac v0.0.0-20240301085553-f6ad88fa357a h1:fY1KmyZ6O7wVBvgt2HB+C9e1DncJdk/Wkv8m5Qz7abw= gitlink.org.cn/jcce-pcm/pcm-ac v0.0.0-20240301085553-f6ad88fa357a/go.mod h1:oMaWf5sEDFKTfCbIlT6/7IFI3f6PsuiRnWzzQruSF5Q= -gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.19 h1:qeBcLo7NTGPsowxxgc7dD+fdWHEOZBrt1vY26+3wv+k= -gitlink.org.cn/jcce-pcm/pcm-coordinator v0.1.19/go.mod h1:0dHxKCTjH3ud1qRQZjE6EqXSs3NTOpiHWTpaip4mrWE= gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230904090036-24fc730ec87d h1:DHjl/rLuH2gKYtY0MKMGNQDHFT12APg25RlMUQo+tHk= gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230904090036-24fc730ec87d/go.mod h1:r/KLzUpupCV5jdxSfgDhc2pVjP0fBi3VhAWRttsBn30= -gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes v0.0.0-20231214084401-de9ac5db7246 h1:VVyI1H3hRv5tDWHt41jIlrucmxF10z3bMqv/hIwCcw0= -gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes v0.0.0-20231214084401-de9ac5db7246/go.mod h1:LM+XeDayimN6b1AY7AhNbbhq9HJyS0u7tszMCNsNmAo= gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20231101085149-724c7c4cc090 h1:jztlHo72bcWM1jUwvG3Hfk2K+AJL0RvlsdIqlktH/MI= gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20231101085149-724c7c4cc090/go.mod h1:pisJKAI8FRFFUcBaH3Gob+ENXWRM97rpuYmv9s1raag= gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20240222124813-e275cfa342f4 h1:NrxKAZ5uAzshB9EHcPw+XTOTzpxb5HslNRMYBrFC1Qo= gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20240222124813-e275cfa342f4/go.mod h1:uyvpVqG1jHDXX+ubXI0RBwnWXzVykD/mliqGQIDvRoo= -gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231102023739-81a3d353c10d h1:hdSxVD+AN7W6j847/GsnNgOAX5IdRQRV1KLz+d4FlS0= -gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231102023739-81a3d353c10d/go.mod h1:m75SVNfNa1TUBlQtBfR0CeETQ0ez2RIUqlSCn1Mb/js= -gitlink.org.cn/jcce-pcm/pcm-slurm v0.0.0-20231107115628-f74106c47dfa h1:U0YV9ju5OPpUe8iUk4OEUtYJlINgpI0vgLC1IfZ2JUY= -gitlink.org.cn/jcce-pcm/pcm-slurm v0.0.0-20231107115628-f74106c47dfa/go.mod h1:tqj8GWoM2P21agWvJyUwN1U37CqfALwZTkRs9Ekgrbw= go.etcd.io/etcd/api/v3 v3.5.7/go.mod h1:9qew1gCdDDLu+VwmeG+iFpL+QlpHTo7iubavdVDgCAA= go.etcd.io/etcd/api/v3 v3.5.12 h1:W4sw5ZoU2Juc9gBWuLk5U6fHfNVyY1WC5g9uiXZio/c= go.etcd.io/etcd/api/v3 v3.5.12/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4= From 1bd68400ce80b7c51fe70fc656706705143c47f5 Mon Sep 17 00:00:00 2001 From: jagger Date: Thu, 14 Mar 2024 17:06:43 +0800 Subject: [PATCH 11/12] :bug: fix bugs Signed-off-by: jagger Former-commit-id: 53a7c41f3f2d4bb67da7c6593893d63d1d4ea189 --- api/desc/core/pcm-core.api | 120 +++++++++++------- api/desc/pcm.api | 14 +- .../handler/adapters/adapterslisthandler.go | 12 +- .../handler/adapters/clusterlisthandler.go | 12 +- .../handler/adapters/createadapterhandler.go | 12 +- .../handler/adapters/createclusterhandler.go | 14 +- .../handler/adapters/deleteadapterhandler.go | 12 +- .../handler/adapters/deleteclusterhandler.go | 14 +- .../handler/adapters/getadapterhandler.go | 12 +- .../adapters/getadapterrelationhandler.go | 12 +- .../handler/adapters/getclusterhandler.go | 14 +- .../handler/adapters/getclustersumhandler.go | 12 +- .../handler/adapters/updateadapterhandler.go | 12 +- .../handler/adapters/updateclusterhandler.go | 14 +- .../logic/adapters/adapterslistlogic.go | 40 ++++-- .../logic/adapters/clusterlistlogic.go | 56 ++++++-- .../logic/adapters/createclusterlogic.go | 2 +- .../logic/adapters/deleteclusterlogic.go | 2 +- .../logic/adapters/getadapterrelationlogic.go | 39 ++++-- .../logic/adapters/getclusterlogic.go | 2 +- .../logic/adapters/updateclusterlogic.go | 2 +- api/internal/svc/servicecontext.go | 2 + api/internal/types/types.go | 43 ++++++- 23 files changed, 281 insertions(+), 193 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index b391d714..6ec35622 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -510,6 +510,7 @@ type ( Nickname string `form:"nickname,optional"` Version string `form:"version,optional"` Server string `form:"server,optional"` + PageInfo } AdapterReq { Id string `json:"id,optional" db:"id"` @@ -560,54 +561,83 @@ type ( } ) -type ClusterReq { - Id string `form:"id,optional"` - AdapterId string `form:"adapterId,optional"` - Name string `json:"name,optional"` - Nickname string `json:"nickname,optional"` - Description string `json:"description,optional"` - Server string `json:"server,optional"` - MonitorServer string `json:"monitorServer,optional"` - Username string `json:"username,optional"` - Password string `json:"password,optional"` - Token string `json:"token,optional"` - Ak string `json:"ak,optional"` - Sk string `json:"sk,optional"` - Region string `json:"region,optional"` - ProjectId string `json:"projectId,optional"` - Version string `json:"version,optional"` - Label string `json:"label,optional"` - OwnerId string `json:"ownerId,omitempty,optional"` - AuthType string `json:"authType,optional"` - Type string `json:"type,optional"` -} +type ( + ClusterReq { + Id string `form:"id,optional"` + AdapterId string `form:"adapterId,optional"` + Name string `form:"name,optional"` + Nickname string `form:"nickname,optional"` + Description string `form:"description,optional"` + Server string `form:"server,optional"` + MonitorServer string `form:"monitorServer,optional"` + Username string `form:"username,optional"` + Password string `form:"password,optional"` + Token string `form:"token,optional"` + Ak string `form:"ak,optional"` + Sk string `form:"sk,optional"` + Region string `form:"region,optional"` + ProjectId string `form:"projectId,optional"` + Version string `form:"version,optional"` + Label string `form:"label,optional"` + OwnerId string `form:"ownerId,omitempty,optional"` + AuthType string `form:"authType,optional"` + Type string `form:"type,optional"` + producerDict string `form:"producerDict,optional"` + regionDict string `form:"regionDict,optional"` + PageInfo + } + + ClusterCreateReq { + Id string `json:"id,optional"` + AdapterId string `json:"adapterId,optional"` + Name string `json:"name,optional"` + Nickname string `json:"nickname,optional"` + Description string `json:"description,optional"` + Server string `json:"server,optional"` + MonitorServer string `json:"monitorServer,optional"` + Username string `json:"username,optional"` + Password string `json:"password,optional"` + Token string `json:"token,optional"` + Ak string `json:"ak,optional"` + Sk string `json:"sk,optional"` + Region string `json:"region,optional"` + ProjectId string `json:"projectId,optional"` + Version string `json:"version,optional"` + Label string `json:"label,optional"` + OwnerId string `json:"ownerId,omitempty,optional"` + AuthType string `json:"authType,optional"` + producerDict string `json:"producerDict,optional"` + regionDict string `json:"regionDict,optional"` + } + ClusterInfo { + Id string `json:"id,omitempty" db:"id"` + AdapterId string `json:"adapterId,omitempty" db:"adapter_id"` + Name string `json:"name,omitempty" db:"name"` + Nickname string `json:"nickname,omitempty" db:"nickname"` + Description string `json:"description,omitempty" db:"description"` + Server string `json:"server,omitempty" db:"server"` + MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"` + Username string `json:"username,omitempty" db:"username"` + Password string `json:"password,omitempty" db:"password"` + Token string `json:"token,omitempty" db:"token"` + Ak string `json:"ak,omitempty" db:"ak"` + Sk string `json:"sk,omitempty" db:"sk"` + Region string `json:"region,omitempty" db:"region"` + ProjectId string `json:"projectId,omitempty" db:"project_id"` + Version string `json:"version,omitempty" db:"version"` + Label string `json:"label,omitempty" db:"label"` + OwnerId string `json:"ownerId,omitempty" db:"owner_id"` + AuthType string `json:"authType,omitempty" db:"auth_type"` + producerDict string `json:"producerDict,omitempty" db:"producer_dict"` + regionDict string `json:"regionDict,omitempty" db:"region_dict"` + CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` + } +) type ClusterDelReq { Id string `form:"id,optional"` } -type ClusterInfo { - Id string `json:"id,omitempty" db:"id"` - AdapterId string `json:"adapterId,omitempty" db:"adapter_id"` - Name string `json:"name,omitempty" db:"name"` - Nickname string `json:"nickname,omitempty" db:"nickname"` - Description string `json:"description,omitempty" db:"description"` - Server string `json:"server,omitempty" db:"server"` - MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"` - Username string `json:"username,omitempty" db:"username"` - Password string `json:"password,omitempty" db:"password"` - Token string `json:"token,omitempty" db:"token"` - Ak string `json:"ak,omitempty" db:"ak"` - Sk string `json:"sk,omitempty" db:"sk"` - Region string `json:"region,omitempty" db:"region"` - ProjectId string `json:"projectId,omitempty" db:"project_id"` - Version string `json:"version,omitempty" db:"version"` - Label string `json:"label,omitempty" db:"label"` - OwnerId string `json:"ownerId,omitempty" db:"owner_id"` - AuthType string `json:"authType,omitempty" db:"auth_type"` - CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` -} - type ClusterResp { List ClusterInfo `json:"list,omitempty"` } @@ -770,6 +800,10 @@ type ( CIds { Ids []string `json:"ids,omitempty" validate:"required"` } + + FId { + Id string `form:"id":"id,omitempty" validate:"required"` + } ) type ( diff --git a/api/desc/pcm.api b/api/desc/pcm.api index c84e2d6b..5759332e 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -806,7 +806,7 @@ service pcm { service pcm { @handler AdaptersListHandler - get /adapter/list (AdapterQueryReq) returns (AdapterListResp) + get /adapter/list (AdapterQueryReq) returns (PageResult) @handler CreateAdapterHandler post /adapter/create (AdapterCreateReq) returns (AdapterResp) @@ -821,22 +821,22 @@ service pcm { get /adapter/get (AdapterDelReq) returns (AdapterInfo) @handler ClusterListHandler - get /adapter/cluster/list (ClusterReq) returns (ClusterListResp) + get /adapter/cluster/list (ClusterReq) returns (PageResult) @handler CreateClusterHandler - post /adapter/cluster/create (ClusterReq) returns (ClusterResp) + post /adapter/cluster/create (ClusterCreateReq) returns (ClusterResp) @handler UpdateClusterHandler - put /adapter/cluster/update (ClusterReq) returns (ClusterResp) + put /adapter/cluster/update (ClusterCreateReq) returns (ClusterResp) @handler DeleteClusterHandler - delete /adapter/cluster/delete (ClusterDelReq) returns (ClusterResp) + delete /adapter/cluster/delete (FId) returns (ClusterResp) @handler GetClusterHandler - get /adapter/cluster/get (ClusterDelReq) returns (ClusterResp) + get /adapter/cluster/get (FId) returns (ClusterResp) @handler GetAdapterRelationHandler - get /adapter/relation (AdapterQueryReq) returns (AdapterRelationResp) + get /adapter/relation (AdapterQueryReq) returns (PageResult) @handler GetClusterSumHandler get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp) diff --git a/api/internal/handler/adapters/adapterslisthandler.go b/api/internal/handler/adapters/adapterslisthandler.go index 3d84c0c8..6ae5c320 100644 --- a/api/internal/handler/adapters/adapterslisthandler.go +++ b/api/internal/handler/adapters/adapterslisthandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func AdaptersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.AdapterQueryReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewAdaptersListLogic(r.Context(), svcCtx) resp, err := l.AdaptersList(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/clusterlisthandler.go b/api/internal/handler/adapters/clusterlisthandler.go index f1863304..bf168fbc 100644 --- a/api/internal/handler/adapters/clusterlisthandler.go +++ b/api/internal/handler/adapters/clusterlisthandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func ClusterListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.ClusterReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewClusterListLogic(r.Context(), svcCtx) resp, err := l.ClusterList(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/createadapterhandler.go b/api/internal/handler/adapters/createadapterhandler.go index 42b60968..be20ca49 100644 --- a/api/internal/handler/adapters/createadapterhandler.go +++ b/api/internal/handler/adapters/createadapterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func CreateAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.AdapterCreateReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewCreateAdapterLogic(r.Context(), svcCtx) resp, err := l.CreateAdapter(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/createclusterhandler.go b/api/internal/handler/adapters/createclusterhandler.go index bea76404..47e1e8b6 100644 --- a/api/internal/handler/adapters/createclusterhandler.go +++ b/api/internal/handler/adapters/createclusterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func CreateClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.ClusterReq + var req types.ClusterCreateReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewCreateClusterLogic(r.Context(), svcCtx) resp, err := l.CreateCluster(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/deleteadapterhandler.go b/api/internal/handler/adapters/deleteadapterhandler.go index b2e1c7ca..3b2fb374 100644 --- a/api/internal/handler/adapters/deleteadapterhandler.go +++ b/api/internal/handler/adapters/deleteadapterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func DeleteAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.AdapterDelReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewDeleteAdapterLogic(r.Context(), svcCtx) resp, err := l.DeleteAdapter(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/deleteclusterhandler.go b/api/internal/handler/adapters/deleteclusterhandler.go index 02b280cb..2f9d3c9e 100644 --- a/api/internal/handler/adapters/deleteclusterhandler.go +++ b/api/internal/handler/adapters/deleteclusterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func DeleteClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.ClusterDelReq + var req types.FId if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewDeleteClusterLogic(r.Context(), svcCtx) resp, err := l.DeleteCluster(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/getadapterhandler.go b/api/internal/handler/adapters/getadapterhandler.go index 2e4e189d..3967cc56 100644 --- a/api/internal/handler/adapters/getadapterhandler.go +++ b/api/internal/handler/adapters/getadapterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func GetAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.AdapterDelReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewGetAdapterLogic(r.Context(), svcCtx) resp, err := l.GetAdapter(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/getadapterrelationhandler.go b/api/internal/handler/adapters/getadapterrelationhandler.go index 64d11ecc..5695767b 100644 --- a/api/internal/handler/adapters/getadapterrelationhandler.go +++ b/api/internal/handler/adapters/getadapterrelationhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func GetAdapterRelationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.AdapterQueryReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewGetAdapterRelationLogic(r.Context(), svcCtx) resp, err := l.GetAdapterRelation(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/getclusterhandler.go b/api/internal/handler/adapters/getclusterhandler.go index d73f6116..7fe828e9 100644 --- a/api/internal/handler/adapters/getclusterhandler.go +++ b/api/internal/handler/adapters/getclusterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func GetClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.ClusterDelReq + var req types.FId if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewGetClusterLogic(r.Context(), svcCtx) resp, err := l.GetCluster(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/getclustersumhandler.go b/api/internal/handler/adapters/getclustersumhandler.go index 18fd747e..bcd6d6af 100644 --- a/api/internal/handler/adapters/getclustersumhandler.go +++ b/api/internal/handler/adapters/getclustersumhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func GetClusterSumHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.ClusterSumReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewGetClusterSumLogic(r.Context(), svcCtx) resp, err := l.GetClusterSum(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/updateadapterhandler.go b/api/internal/handler/adapters/updateadapterhandler.go index 3800fc16..2f9ee8fa 100644 --- a/api/internal/handler/adapters/updateadapterhandler.go +++ b/api/internal/handler/adapters/updateadapterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func UpdateAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.AdapterReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewUpdateAdapterLogic(r.Context(), svcCtx) resp, err := l.UpdateAdapter(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/adapters/updateclusterhandler.go b/api/internal/handler/adapters/updateclusterhandler.go index ee605344..197d0198 100644 --- a/api/internal/handler/adapters/updateclusterhandler.go +++ b/api/internal/handler/adapters/updateclusterhandler.go @@ -1,28 +1,24 @@ package adapters import ( - "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" ) func UpdateClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.ClusterReq + var req types.ClusterCreateReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := adapters.NewUpdateClusterLogic(r.Context(), svcCtx) resp, err := l.UpdateCluster(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/logic/adapters/adapterslistlogic.go b/api/internal/logic/adapters/adapterslistlogic.go index 2a35d4bf..5f4aba2a 100644 --- a/api/internal/logic/adapters/adapterslistlogic.go +++ b/api/internal/logic/adapters/adapterslistlogic.go @@ -2,8 +2,6 @@ package adapters import ( "context" - "fmt" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" @@ -24,16 +22,38 @@ func NewAdaptersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Adap } } -func (l *AdaptersListLogic) AdaptersList(req *types.AdapterQueryReq) (resp *types.AdapterListResp, err error) { - resp = &types.AdapterListResp{} - sqlStr := "select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc" +func (l *AdaptersListLogic) AdaptersList(req *types.AdapterQueryReq) (resp *types.PageResult, err error) { + limit := req.PageSize + offset := req.PageSize * (req.PageNum - 1) + resp = &types.PageResult{} + var list []types.AdapterInfo + db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter") + if req.Name != "" { - sqlStr = fmt.Sprintf("select * from t_adapter where `deleted_at` IS NULL and name like '%%%s%%' ORDER BY create_time Desc", req.Name) + db = db.Where("name LIKE ?", "%"+req.Name+"%") } - tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List) - if tx.Error != nil { - logx.Errorf(tx.Error.Error()) - return nil, tx.Error + if req.Nickname != "" { + db = db.Where("nickname LIKE ?", "%"+req.Nickname+"%") } + if req.Type != "" { + db = db.Where("type = ?", req.Type) + } + if req.Version != "" { + db = db.Where("version = ?", req.Version) + } + var total int64 + err = db.Count(&total).Error + + if err != nil { + return resp, err + } + db = db.Where("deleted_at is null").Limit(limit).Offset(offset) + err = db.Order("create_time desc").Find(&list).Error + + resp.List = list + resp.PageSize = req.PageSize + resp.PageNum = req.PageNum + resp.Total = total + return resp, nil } diff --git a/api/internal/logic/adapters/clusterlistlogic.go b/api/internal/logic/adapters/clusterlistlogic.go index a2806a1e..2dbb0f76 100644 --- a/api/internal/logic/adapters/clusterlistlogic.go +++ b/api/internal/logic/adapters/clusterlistlogic.go @@ -2,8 +2,6 @@ package adapters import ( "context" - "fmt" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" @@ -24,20 +22,56 @@ func NewClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clust } } -func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.ClusterListResp, err error) { - resp = &types.ClusterListResp{} +func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.PageResult, err error) { + limit := req.PageSize + offset := req.PageSize * (req.PageNum - 1) + resp = &types.PageResult{} + var list []types.ClusterInfo + db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter") - sql := fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null`) + db = db.Joins("left join t_cluster on t_adapter.id = t_cluster.adapter_id"). + Where("t_cluster.deleted_at is null") + if req.Name != "" { + db = db.Where("t_cluster.name LIKE ?", "%"+req.Name+"%") + } if req.AdapterId != "" { - sql = fmt.Sprintf(`select * from t_cluster where adapter_id = %s and deleted_at is null `, req.AdapterId) + db = db.Where("t_cluster.adapter_id = ?", "%"+req.AdapterId+"%") + } + if req.Nickname != "" { + db = db.Where("t_cluster.nickname LIKE ?", "%"+req.Nickname+"%") + } + if req.Label != "" { + db = db.Where("t_cluster.label = ?", req.Label) + } + if req.Version != "" { + db = db.Where("t_cluster.version = ?", req.Version) + } + if req.ProducerDict != "" { + db = db.Where("t_cluster.producer_dict = ?", req.ProducerDict) + } + if req.RegionDict != "" { + db = db.Where("t_cluster.region_dict = ?", req.RegionDict) } if req.Type != "" { - sql = fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null and a.type = %s`, req.Type) + db = db.Where("t_adapter.type = ?", req.Type) } - tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List) - if tx.Error != nil { - logx.Errorf(tx.Error.Error()) - return nil, tx.Error + + //count total + var total int64 + err = db.Select("*").Count(&total).Error + if err != nil { + return resp, err } + + db = db.Limit(limit).Offset(offset) + err = db.Select("t_cluster.*").Order("t_cluster.create_time desc").Scan(&list).Error + if err != nil { + return resp, err + } + resp.List = list + resp.PageSize = req.PageSize + resp.PageNum = req.PageNum + resp.Total = total + return resp, nil } diff --git a/api/internal/logic/adapters/createclusterlogic.go b/api/internal/logic/adapters/createclusterlogic.go index b2ecb5b5..48ef2fea 100644 --- a/api/internal/logic/adapters/createclusterlogic.go +++ b/api/internal/logic/adapters/createclusterlogic.go @@ -27,7 +27,7 @@ func NewCreateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre } } -func (l *CreateClusterLogic) CreateCluster(req *types.ClusterReq) (resp *types.ClusterResp, err error) { +func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) { adapter := &types.AdapterInfo{} result := l.svcCtx.DbEngin.Table("t_adapter").First(&adapter, req.AdapterId) if errors.Is(result.Error, gorm.ErrRecordNotFound) { diff --git a/api/internal/logic/adapters/deleteclusterlogic.go b/api/internal/logic/adapters/deleteclusterlogic.go index 7bb56ac2..5fd39ed6 100644 --- a/api/internal/logic/adapters/deleteclusterlogic.go +++ b/api/internal/logic/adapters/deleteclusterlogic.go @@ -24,7 +24,7 @@ func NewDeleteClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Del } } -func (l *DeleteClusterLogic) DeleteCluster(req *types.ClusterDelReq) (resp *types.ClusterResp, err error) { +func (l *DeleteClusterLogic) DeleteCluster(req *types.FId) (resp *types.ClusterResp, err error) { db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&types.ClusterInfo{}) if db.Error != nil { logx.Errorf("err %v", db.Error.Error()) diff --git a/api/internal/logic/adapters/getadapterrelationlogic.go b/api/internal/logic/adapters/getadapterrelationlogic.go index 8b6fb4fb..c2e21e44 100644 --- a/api/internal/logic/adapters/getadapterrelationlogic.go +++ b/api/internal/logic/adapters/getadapterrelationlogic.go @@ -2,7 +2,6 @@ package adapters import ( "context" - "fmt" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" @@ -25,19 +24,32 @@ func NewGetAdapterRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext) } } -func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterQueryReq) (resp *types.AdapterRelationResp, err error) { - resp = &types.AdapterRelationResp{} - adapter := make([]types.AdapterInfo, 0) - sqlStr := "select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc" +func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterQueryReq) (resp *types.PageResult, err error) { + resp = &types.PageResult{} + var list []types.AdapterInfo + db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter") + if req.Name != "" { - sqlStr = fmt.Sprintf("select * from t_adapter where `deleted_at` IS NULL and name like '%%%s%%' ORDER BY create_time Desc", req.Name) + db = db.Where("name LIKE ?", "%"+req.Name+"%") } - tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&adapter) - if tx.Error != nil { - logx.Errorf(tx.Error.Error()) - return nil, tx.Error + if req.Nickname != "" { + db = db.Where("nickname LIKE ?", "%"+req.Nickname+"%") } - for _, v := range adapter { + if req.Type != "" { + db = db.Where("type = ?", req.Type) + } + if req.Version != "" { + db = db.Where("version = ?", req.Version) + } + + err = db.Where("deleted_at is null").Order("create_time desc").Find(&list).Error + + if err != nil { + return resp, err + } + + rlist := make([]*types.ClusterRelationInfo, 0) + for _, v := range list { cr := &types.ClusterRelationInfo{} utils.Convert(&v, &cr) clusters := make([]*types.ClusterInfo, 0) @@ -64,11 +76,12 @@ func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterQueryReq) cr.COwnerId = c.OwnerId cr.CAuthType = c.AuthType cr.CCreateTime = c.CreateTime - resp.List = append(resp.List, cr) + rlist = append(rlist, cr) } if len(clusters) == 0 { - resp.List = append(resp.List, cr) + rlist = append(rlist, cr) } } + resp.List = rlist return resp, nil } diff --git a/api/internal/logic/adapters/getclusterlogic.go b/api/internal/logic/adapters/getclusterlogic.go index 5e7f2efa..ba5fb31c 100644 --- a/api/internal/logic/adapters/getclusterlogic.go +++ b/api/internal/logic/adapters/getclusterlogic.go @@ -24,7 +24,7 @@ func NewGetClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClu } } -func (l *GetClusterLogic) GetCluster(req *types.ClusterDelReq) (resp *types.ClusterInfo, err error) { +func (l *GetClusterLogic) GetCluster(req *types.FId) (resp *types.ClusterInfo, err error) { resp = &types.ClusterInfo{} db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&resp) if db.Error != nil { diff --git a/api/internal/logic/adapters/updateclusterlogic.go b/api/internal/logic/adapters/updateclusterlogic.go index e71ffc81..360b18a8 100644 --- a/api/internal/logic/adapters/updateclusterlogic.go +++ b/api/internal/logic/adapters/updateclusterlogic.go @@ -26,7 +26,7 @@ func NewUpdateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd } } -func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterReq) (resp *types.ClusterResp, err error) { +func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) { cluster := &types.ClusterInfo{} result := l.svcCtx.DbEngin.Table("t_cluster").First(&cluster, req.Id) if errors.Is(result.Error, gorm.ErrRecordNotFound) { diff --git a/api/internal/svc/servicecontext.go b/api/internal/svc/servicecontext.go index 19630851..e165ceb6 100644 --- a/api/internal/svc/servicecontext.go +++ b/api/internal/svc/servicecontext.go @@ -38,6 +38,7 @@ import ( "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopusclient" "gorm.io/driver/mysql" "gorm.io/gorm" + "gorm.io/gorm/logger" "gorm.io/gorm/schema" "time" ) @@ -84,6 +85,7 @@ func NewServiceContext(c config.Config) *ServiceContext { NamingStrategy: schema.NamingStrategy{ SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user` }, + Logger: logger.Default.LogMode(logger.Info), }) if err != nil { logx.Errorf("数据库连接失败, err%v", err) diff --git a/api/internal/types/types.go b/api/internal/types/types.go index cb68cfd0..cc26cc34 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -485,6 +485,7 @@ type AdapterQueryReq struct { Nickname string `form:"nickname,optional"` Version string `form:"version,optional"` Server string `form:"server,optional"` + PageInfo } type AdapterReq struct { @@ -545,6 +546,31 @@ type AdapterRelation struct { type ClusterReq struct { Id string `form:"id,optional"` AdapterId string `form:"adapterId,optional"` + Name string `form:"name,optional"` + Nickname string `form:"nickname,optional"` + Description string `form:"description,optional"` + Server string `form:"server,optional"` + MonitorServer string `form:"monitorServer,optional"` + Username string `form:"username,optional"` + Password string `form:"password,optional"` + Token string `form:"token,optional"` + Ak string `form:"ak,optional"` + Sk string `form:"sk,optional"` + Region string `form:"region,optional"` + ProjectId string `form:"projectId,optional"` + Version string `form:"version,optional"` + Label string `form:"label,optional"` + OwnerId string `form:"ownerId,omitempty,optional"` + AuthType string `form:"authType,optional"` + Type string `form:"type,optional"` + ProducerDict string `form:"producerDict,optional"` + RegionDict string `form:"regionDict,optional"` + PageInfo +} + +type ClusterCreateReq struct { + Id string `json:"id,optional"` + AdapterId string `json:"adapterId,optional"` Name string `json:"name,optional"` Nickname string `json:"nickname,optional"` Description string `json:"description,optional"` @@ -561,11 +587,8 @@ type ClusterReq struct { Label string `json:"label,optional"` OwnerId string `json:"ownerId,omitempty,optional"` AuthType string `json:"authType,optional"` - Type string `json:"type,optional"` -} - -type ClusterDelReq struct { - Id string `form:"id,optional"` + ProducerDict string `json:"producerDict,optional"` + RegionDict string `json:"regionDict,optional"` } type ClusterInfo struct { @@ -587,9 +610,15 @@ type ClusterInfo struct { Label string `json:"label,omitempty" db:"label"` OwnerId string `json:"ownerId,omitempty" db:"owner_id"` AuthType string `json:"authType,omitempty" db:"auth_type"` + ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"` + RegionDict string `json:"regionDict,omitempty" db:"region_dict"` CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` } +type ClusterDelReq struct { + Id string `form:"id,optional"` +} + type ClusterResp struct { List ClusterInfo `json:"list,omitempty"` } @@ -748,6 +777,10 @@ type CIds struct { Ids []string `json:"ids,omitempty" validate:"required"` } +type FId struct { + Id string `form:"id":"id,omitempty" validate:"required"` +} + type PageInfo struct { PageNum int `form:"pageNum"` PageSize int `form:"pageSize"` From b831ff2204504f9d2276a493676c25a1b6d6799a Mon Sep 17 00:00:00 2001 From: jagger Date: Fri, 15 Mar 2024 15:27:13 +0800 Subject: [PATCH 12/12] :bug: fix bugs Signed-off-by: jagger Former-commit-id: f030b1c53b5f3a208c6b15d978ad988e0f2ef3db --- api/internal/logic/adapters/clusterlistlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/internal/logic/adapters/clusterlistlogic.go b/api/internal/logic/adapters/clusterlistlogic.go index 2dbb0f76..764878b2 100644 --- a/api/internal/logic/adapters/clusterlistlogic.go +++ b/api/internal/logic/adapters/clusterlistlogic.go @@ -35,7 +35,7 @@ func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.PageR db = db.Where("t_cluster.name LIKE ?", "%"+req.Name+"%") } if req.AdapterId != "" { - db = db.Where("t_cluster.adapter_id = ?", "%"+req.AdapterId+"%") + db = db.Where("t_cluster.adapter_id = ?", req.AdapterId) } if req.Nickname != "" { db = db.Where("t_cluster.nickname LIKE ?", "%"+req.Nickname+"%")