From c3bf32b36c4f2561e00fa90fb4647ba893c8a707 Mon Sep 17 00:00:00 2001 From: tzwang Date: Thu, 12 Oct 2023 11:29:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=98=E7=AE=97=E8=81=94=E5=8A=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 85405ae5a4a320b53b0d98ec166ab91a6a99fd54 --- .../logic/storelink/submitlinktasklogic.go | 12 ++++++------ api/internal/storeLink/octopus.go | 18 +++++++++++++++--- api/internal/storeLink/storeLink.go | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/api/internal/logic/storelink/submitlinktasklogic.go b/api/internal/logic/storelink/submitlinktasklogic.go index e2ed5e44..006e85f2 100644 --- a/api/internal/logic/storelink/submitlinktasklogic.go +++ b/api/internal/logic/storelink/submitlinktasklogic.go @@ -26,14 +26,14 @@ func NewSubmitLinkTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Su func (l *SubmitLinkTaskLogic) SubmitLinkTask(req *types.SubmitLinkTaskReq) (resp *types.SubmitLinkTaskResp, err error) { participant := storeLink.GetParticipantById(req.PartId, l.svcCtx.DbEngin) storelink := storeLink.NewStoreLink(l.ctx, l.svcCtx, participant) - var envs []string - if len(req.Envs) != 0 { - for _, v := range req.Envs { - env := v.Key + storeLink.COMMA + v.Val - envs = append(envs, env) + var params []string + if len(req.Params) != 0 { + for _, v := range req.Params { + param := v.Key + storeLink.COMMA + v.Val + params = append(params, param) } } - task, err := storelink.ILinkage.SubmitTask(req.ImageId, req.Cmd, envs, "") + task, err := storelink.ILinkage.SubmitTask(req.ImageId, req.Cmd, params, req.ResourceId) if err != nil { return nil, err } diff --git a/api/internal/storeLink/octopus.go b/api/internal/storeLink/octopus.go index e7227ced..73c89f1a 100644 --- a/api/internal/storeLink/octopus.go +++ b/api/internal/storeLink/octopus.go @@ -5,6 +5,7 @@ import ( "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus" + "strings" ) type OctopusLink struct { @@ -19,6 +20,7 @@ const ( IMG_NAME_PREFIX = "oct_" IMG_VERSION_PREFIX = "version_" TASK_NAME_PREFIX = "trainJob_" + RESOURCE_POOL = "common-pool" ) func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, platform string) *OctopusLink { @@ -106,14 +108,23 @@ func (o *OctopusLink) QueryImageList() (interface{}, error) { return imgListResp, nil } -func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string, resourceId string) (interface{}, error) { +func (o *OctopusLink) SubmitTask(imageId string, cmd string, params []string, resourceId string) (interface{}, error) { // octopus提交任务 + var prms []*octopus.Parameters + for _, param := range params { + var p octopus.Parameters + s := strings.Split(param, COMMA) + p.Key = s[0] + p.Value = s[1] + prms = append(prms, &p) + } + req := &octopus.CreateTrainJobReq{ Platform: o.platform, Params: &octopus.CreateTrainJobParam{ ImageId: imageId, - Name: TASK_NAME_PREFIX + utils.RandomString(5), - ResourcePool: "common-pool", + Name: TASK_NAME_PREFIX + utils.RandomString(7), + ResourcePool: RESOURCE_POOL, Config: []*octopus.Config{ { Command: cmd, @@ -121,6 +132,7 @@ func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string, reso MinFailedTaskCount: 1, MinSucceededTaskCount: 1, TaskNumber: 1, + Parameters: prms, }, }, }, diff --git a/api/internal/storeLink/storeLink.go b/api/internal/storeLink/storeLink.go index 273846df..b05ef04c 100644 --- a/api/internal/storeLink/storeLink.go +++ b/api/internal/storeLink/storeLink.go @@ -14,7 +14,7 @@ type Linkage interface { UploadImage(path string) (interface{}, error) DeleteImage(imageId string) (interface{}, error) QueryImageList() (interface{}, error) - SubmitTask(imageId string, cmd string, envs []string, resourceId string) (interface{}, error) + SubmitTask(imageId string, cmd string, params []string, resourceId string) (interface{}, error) QueryTask(taskId string) (interface{}, error) DeleteTask(taskId string) (interface{}, error) }