From 449f3d7eec81ac88662bd5f0d678bb0abc30e09a Mon Sep 17 00:00:00 2001 From: tzwang Date: Fri, 26 Jan 2024 17:18:09 +0800 Subject: [PATCH] refactor the scheduler and storelink modules Former-commit-id: b72e4e416a990958fe6210629a461434614ceca4 --- .../logic/storelink/deletelinkimagelogic.go | 15 +- .../logic/storelink/deletelinktasklogic.go | 15 +- .../logic/storelink/getaispecslogic.go | 15 +- .../logic/storelink/getlinkimagelistlogic.go | 15 +- .../logic/storelink/getlinktasklogic.go | 15 +- .../logic/storelink/submitlinktasklogic.go | 13 +- .../logic/storelink/uploadlinkimagelogic.go | 15 +- api/internal/mqs/ScheduleAi.go | 2 +- .../scheduler/schedulers/aiScheduler.go | 2 + api/internal/scheduler/service/aiService.go | 16 +- .../scheduler/service/executor/executor.go | 17 +- .../scheduler/service/impl/modelarts.go | 44 -- .../scheduler/service/impl/octopus.go | 42 -- .../scheduler/service/impl/shuguangAi.go | 45 -- api/internal/storeLink/modelarts.go | 62 +- api/internal/storeLink/octopus.go | 93 +-- api/internal/storeLink/shuguangHpc.go | 61 +- api/internal/storeLink/shuguangai.go | 57 +- api/internal/storeLink/storeLink.go | 548 ++++++++++-------- 19 files changed, 494 insertions(+), 598 deletions(-) delete mode 100644 api/internal/scheduler/service/impl/modelarts.go delete mode 100644 api/internal/scheduler/service/impl/octopus.go delete mode 100644 api/internal/scheduler/service/impl/shuguangAi.go diff --git a/api/internal/logic/storelink/deletelinkimagelogic.go b/api/internal/logic/storelink/deletelinkimagelogic.go index 3e092aaa..1a730f0a 100644 --- a/api/internal/logic/storelink/deletelinkimagelogic.go +++ b/api/internal/logic/storelink/deletelinkimagelogic.go @@ -57,9 +57,18 @@ func (l *DeleteLinkImageLogic) DeleteLinkImage(req *types.DeleteLinkImageReq) (r return nil, err } if img == nil { - return nil, nil + return nil, storeLink.ERROR_RESP_EMPTY } - imgResp := img.(types.DeleteLinkImageResp) - return &imgResp, nil + resp = &types.DeleteLinkImageResp{} + //转换成统一返回类型 + imgResp, err := storeLink.ConvertType(img, resp, participant) + if err != nil { + return nil, err + } + if imgResp == nil { + return nil, storeLink.ERROR_CONVERT_EMPTY + } + + return imgResp.(*types.DeleteLinkImageResp), nil } diff --git a/api/internal/logic/storelink/deletelinktasklogic.go b/api/internal/logic/storelink/deletelinktasklogic.go index 420dfad5..d4bfce4f 100644 --- a/api/internal/logic/storelink/deletelinktasklogic.go +++ b/api/internal/logic/storelink/deletelinktasklogic.go @@ -57,9 +57,18 @@ func (l *DeleteLinkTaskLogic) DeleteLinkTask(req *types.DeleteLinkTaskReq) (resp return nil, err } if task == nil { - return nil, nil + return nil, storeLink.ERROR_RESP_EMPTY } - taskResp := task.(types.DeleteLinkTaskResp) - return &taskResp, nil + resp = &types.DeleteLinkTaskResp{} + //转换成统一返回类型 + taskResp, err := storeLink.ConvertType(task, resp, participant) + if err != nil { + return nil, err + } + if taskResp == nil { + return nil, storeLink.ERROR_CONVERT_EMPTY + } + + return taskResp.(*types.DeleteLinkTaskResp), nil } diff --git a/api/internal/logic/storelink/getaispecslogic.go b/api/internal/logic/storelink/getaispecslogic.go index e358f5d8..ec49eb44 100644 --- a/api/internal/logic/storelink/getaispecslogic.go +++ b/api/internal/logic/storelink/getaispecslogic.go @@ -57,9 +57,18 @@ func (l *GetAISpecsLogic) GetAISpecs(req *types.GetResourceSpecsReq) (resp *type return nil, err } if specs == nil { - return nil, nil + return nil, storeLink.ERROR_RESP_EMPTY } - specsResp := specs.(types.GetResourceSpecsResp) - return &specsResp, nil + resp = &types.GetResourceSpecsResp{} + //转换成统一返回类型 + specsResp, err := storeLink.ConvertType(specs, resp, participant) + if err != nil { + return nil, err + } + if specsResp == nil { + return nil, storeLink.ERROR_CONVERT_EMPTY + } + + return specsResp.(*types.GetResourceSpecsResp), nil } diff --git a/api/internal/logic/storelink/getlinkimagelistlogic.go b/api/internal/logic/storelink/getlinkimagelistlogic.go index 99250ca2..d6d51c40 100644 --- a/api/internal/logic/storelink/getlinkimagelistlogic.go +++ b/api/internal/logic/storelink/getlinkimagelistlogic.go @@ -57,9 +57,18 @@ func (l *GetLinkImageListLogic) GetLinkImageList(req *types.GetLinkImageListReq) return nil, err } if list == nil { - return nil, nil + return nil, storeLink.ERROR_RESP_EMPTY } - listResp := list.(types.GetLinkImageListResp) - return &listResp, nil + resp = &types.GetLinkImageListResp{} + //转换成统一返回类型 + listResp, err := storeLink.ConvertType(list, resp, participant) + if err != nil { + return nil, err + } + if listResp == nil { + return nil, storeLink.ERROR_CONVERT_EMPTY + } + + return listResp.(*types.GetLinkImageListResp), nil } diff --git a/api/internal/logic/storelink/getlinktasklogic.go b/api/internal/logic/storelink/getlinktasklogic.go index b1a04c35..f7da753f 100644 --- a/api/internal/logic/storelink/getlinktasklogic.go +++ b/api/internal/logic/storelink/getlinktasklogic.go @@ -58,9 +58,18 @@ func (l *GetLinkTaskLogic) GetLinkTask(req *types.GetLinkTaskReq) (resp *types.G return nil, err } if task == nil { - return nil, nil + return nil, storeLink.ERROR_RESP_EMPTY } - taskResp := task.(types.GetLinkTaskResp) - return &taskResp, nil + resp = &types.GetLinkTaskResp{} + //转换成统一返回类型 + taskResp, err := storeLink.ConvertType(task, resp, participant) + if err != nil { + return nil, err + } + if taskResp == nil { + return nil, storeLink.ERROR_CONVERT_EMPTY + } + + return taskResp.(*types.GetLinkTaskResp), nil } diff --git a/api/internal/logic/storelink/submitlinktasklogic.go b/api/internal/logic/storelink/submitlinktasklogic.go index 5fc3bae3..98f77f85 100644 --- a/api/internal/logic/storelink/submitlinktasklogic.go +++ b/api/internal/logic/storelink/submitlinktasklogic.go @@ -72,6 +72,15 @@ func (l *SubmitLinkTaskLogic) SubmitLinkTask(req *types.SubmitLinkTaskReq) (resp return nil, err } - taskResp := task.(types.SubmitLinkTaskResp) - return &taskResp, nil + resp = &types.SubmitLinkTaskResp{} + //转换成统一返回类型 + taskResp, err := storeLink.ConvertType(task, resp, participant) + if err != nil { + return nil, err + } + if taskResp == nil { + return nil, storeLink.ERROR_CONVERT_EMPTY + } + + return taskResp.(*types.SubmitLinkTaskResp), nil } diff --git a/api/internal/logic/storelink/uploadlinkimagelogic.go b/api/internal/logic/storelink/uploadlinkimagelogic.go index 93c579d4..92e89958 100644 --- a/api/internal/logic/storelink/uploadlinkimagelogic.go +++ b/api/internal/logic/storelink/uploadlinkimagelogic.go @@ -58,9 +58,18 @@ func (l *UploadLinkImageLogic) UploadLinkImage(req *types.UploadLinkImageReq) (r return nil, err } if img == nil { - return nil, nil + return nil, storeLink.ERROR_RESP_EMPTY } - imgResp := img.(types.UploadLinkImageResp) - return &imgResp, nil + resp = &types.UploadLinkImageResp{} + //转换成统一返回类型 + imgResp, err := storeLink.ConvertType(img, resp, participant) + if err != nil { + return nil, err + } + if imgResp == nil { + return nil, storeLink.ERROR_CONVERT_EMPTY + } + + return imgResp.(*types.UploadLinkImageResp), nil } diff --git a/api/internal/mqs/ScheduleAi.go b/api/internal/mqs/ScheduleAi.go index 836d0170..17fd5520 100644 --- a/api/internal/mqs/ScheduleAi.go +++ b/api/internal/mqs/ScheduleAi.go @@ -33,7 +33,7 @@ type AiQueue struct { } func NewAiMq(ctx context.Context, svcCtx *svc.ServiceContext) *AiQueue { - aiExecutorMap, aiCollectorMap := service.InitAiClusterMap(svcCtx.ACRpc, svcCtx.ModelArtsRpc, svcCtx.ModelArtsImgRpc, svcCtx.OctopusRpc) + aiExecutorMap, aiCollectorMap := service.InitAiClusterMap(ctx, svcCtx) return &AiQueue{ ctx: ctx, svcCtx: svcCtx, diff --git a/api/internal/scheduler/schedulers/aiScheduler.go b/api/internal/scheduler/schedulers/aiScheduler.go index ab9f4eb0..5f9f2d22 100644 --- a/api/internal/scheduler/schedulers/aiScheduler.go +++ b/api/internal/scheduler/schedulers/aiScheduler.go @@ -83,6 +83,8 @@ func (as *AiScheduler) AssignTask(clusters []*strategy.AssignedCluster) error { return errors.New("clusters is nil") } + _ = *as.AiExecutor + return nil } diff --git a/api/internal/scheduler/service/aiService.go b/api/internal/scheduler/service/aiService.go index 1a6949b7..3b46596b 100644 --- a/api/internal/scheduler/service/aiService.go +++ b/api/internal/scheduler/service/aiService.go @@ -1,13 +1,11 @@ package service import ( - "gitlink.org.cn/jcce-pcm/pcm-ac/hpcacclient" + "context" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/executor" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/impl" - "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/imagesservice" - "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/modelartsservice" - "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopusclient" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/storeLink" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" ) const ( @@ -26,21 +24,21 @@ var ( } ) -func InitAiClusterMap(ACRpc hpcacclient.HpcAC, ModelArtsRpc modelartsservice.ModelArtsService, ModelArtsImgRpc imagesservice.ImagesService, OctopusRpc octopusclient.Octopus) (*map[string]executor.Executor, *map[string]collector.ResourceCollector) { +func InitAiClusterMap(ctx context.Context, svcCtx *svc.ServiceContext) (*map[string]executor.Executor, *map[string]collector.ResourceCollector) { executorMap := make(map[string]executor.Executor) collectorMap := make(map[string]collector.ResourceCollector) for k, v := range AiTypeMap { switch v { case OCTOPUS: - octopus := impl.NewOctopusExecutor(OctopusRpc, k) + octopus := storeLink.NewOctopusLink(ctx, svcCtx, k, 0) collectorMap[k] = octopus executorMap[k] = octopus case MODELARTS: - modelarts := impl.NewModelartsExecutor(ModelArtsRpc, ModelArtsImgRpc, k) + modelarts := storeLink.NewModelArtsLink(ctx, svcCtx, k, 0) collectorMap[k] = modelarts executorMap[k] = modelarts case SHUGUANGAI: - sgai := impl.NewShuguangAiExecutor(ACRpc, k) + sgai := storeLink.NewShuguangAi(ctx, svcCtx, k, 0) collectorMap[k] = sgai executorMap[k] = sgai } diff --git a/api/internal/scheduler/service/executor/executor.go b/api/internal/scheduler/service/executor/executor.go index 61055927..917e45ca 100644 --- a/api/internal/scheduler/service/executor/executor.go +++ b/api/internal/scheduler/service/executor/executor.go @@ -1,17 +1,8 @@ package executor type Executor interface { - QueryImageList() ([]Image, error) - SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (Task, error) - QueryTask(taskId string) (Task, error) - QuerySpecs() (Spec, error) -} - -type Image struct { -} - -type Task struct { -} - -type Spec struct { + QueryImageList() (interface{}, error) + SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) + QueryTask(taskId string) (interface{}, error) + QuerySpecs() (interface{}, error) } diff --git a/api/internal/scheduler/service/impl/modelarts.go b/api/internal/scheduler/service/impl/modelarts.go deleted file mode 100644 index eb4eae84..00000000 --- a/api/internal/scheduler/service/impl/modelarts.go +++ /dev/null @@ -1,44 +0,0 @@ -package impl - -import ( - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/executor" - "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/imagesservice" - "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/modelartsservice" -) - -type ModelArtsExecutor struct { - Name string - pageIndex int32 - pageSize int32 - ModelArtsRpc modelartsservice.ModelArtsService - ModelArtsImgRpc imagesservice.ImagesService -} - -func NewModelartsExecutor(modelArtsRpc modelartsservice.ModelArtsService, modelArtsImgRpc imagesservice.ImagesService, name string) *ModelArtsExecutor { - return &ModelArtsExecutor{Name: name, ModelArtsRpc: modelArtsRpc, ModelArtsImgRpc: modelArtsImgRpc, pageIndex: 1, pageSize: 100} -} - -func (m ModelArtsExecutor) QueryImageList() ([]executor.Image, error) { - //TODO implement me - panic("implement me") -} - -func (m ModelArtsExecutor) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (executor.Task, error) { - //TODO implement me - panic("implement me") -} - -func (m ModelArtsExecutor) QueryTask(taskId string) (executor.Task, error) { - //TODO implement me - panic("implement me") -} - -func (m ModelArtsExecutor) QuerySpecs() (executor.Spec, error) { - //TODO implement me - panic("implement me") -} - -func (a *ModelArtsExecutor) GetResourceSpecs() (*collector.ResourceSpecs, error) { - return nil, nil -} diff --git a/api/internal/scheduler/service/impl/octopus.go b/api/internal/scheduler/service/impl/octopus.go deleted file mode 100644 index a0bf944b..00000000 --- a/api/internal/scheduler/service/impl/octopus.go +++ /dev/null @@ -1,42 +0,0 @@ -package impl - -import ( - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/executor" - "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopusclient" -) - -type OctopusExecutor struct { - Name string - pageIndex int32 - pageSize int32 - OctopusRpc octopusclient.Octopus -} - -func NewOctopusExecutor(OctopusRpc octopusclient.Octopus, name string) *OctopusExecutor { - return &OctopusExecutor{OctopusRpc: OctopusRpc, Name: name, pageIndex: 1, pageSize: 100} -} - -func (o OctopusExecutor) QueryImageList() ([]executor.Image, error) { - //TODO implement me - panic("implement me") -} - -func (o OctopusExecutor) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (executor.Task, error) { - //TODO implement me - panic("implement me") -} - -func (o OctopusExecutor) QueryTask(taskId string) (executor.Task, error) { - //TODO implement me - panic("implement me") -} - -func (o OctopusExecutor) QuerySpecs() (executor.Spec, error) { - //TODO implement me - panic("implement me") -} - -func (a *OctopusExecutor) GetResourceSpecs() (*collector.ResourceSpecs, error) { - return nil, nil -} diff --git a/api/internal/scheduler/service/impl/shuguangAi.go b/api/internal/scheduler/service/impl/shuguangAi.go deleted file mode 100644 index a54c55f6..00000000 --- a/api/internal/scheduler/service/impl/shuguangAi.go +++ /dev/null @@ -1,45 +0,0 @@ -package impl - -import ( - "gitlink.org.cn/jcce-pcm/pcm-ac/hpcacclient" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/executor" -) - -//单条作业费=作业运行秒数×(CPU核心数*CPU单价+GPU卡数×GPU单价+DCU卡数×DCU单价)/3600 -//CPU单价=队列CPU费率×计算中心CPU单价 -//GPU单价=队列GPU费率×计算中心GPU单价 -//DCU单价=队列DCU费率×计算中心DCU单价 - -type ShuguangAiExecutor struct { - Name string - ACRpc hpcacclient.HpcAC -} - -func NewShuguangAiExecutor(acRpc hpcacclient.HpcAC, name string) *ShuguangAiExecutor { - return &ShuguangAiExecutor{Name: name, ACRpc: acRpc} -} - -func (s ShuguangAiExecutor) QueryImageList() ([]executor.Image, error) { - //TODO implement me - panic("implement me") -} - -func (s ShuguangAiExecutor) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (executor.Task, error) { - //TODO implement me - panic("implement me") -} - -func (s ShuguangAiExecutor) QueryTask(taskId string) (executor.Task, error) { - //TODO implement me - panic("implement me") -} - -func (s ShuguangAiExecutor) QuerySpecs() (executor.Spec, error) { - //TODO implement me - panic("implement me") -} - -func (a *ShuguangAiExecutor) GetResourceSpecs() (*collector.ResourceSpecs, error) { - return nil, nil -} diff --git a/api/internal/storeLink/modelarts.go b/api/internal/storeLink/modelarts.go index 77aa7f07..350bd0ec 100644 --- a/api/internal/storeLink/modelarts.go +++ b/api/internal/storeLink/modelarts.go @@ -16,8 +16,8 @@ package storeLink import ( "context" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts" "strconv" @@ -25,16 +25,16 @@ import ( ) type ModelArtsLink struct { - ctx context.Context - svcCtx *svc.ServiceContext - platform string - pageIndex int32 - pageSize int32 - participant *models.StorelinkCenter + ctx context.Context + svcCtx *svc.ServiceContext + platform string + participantId int64 + pageIndex int32 + pageSize int32 } -func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ModelArtsLink { - return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, participant: participant, platform: participant.Name, pageIndex: 1, pageSize: 100} +func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *ModelArtsLink { + return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id, pageIndex: 1, pageSize: 100} } func (o *ModelArtsLink) UploadImage(path string) (interface{}, error) { @@ -59,13 +59,7 @@ func (o *ModelArtsLink) QueryImageList() (interface{}, error) { return nil, err } - //转换成统一返回类型 - imgListResp, err := ConvertType[modelarts.ListReposDetailsResp](resp, nil) - if err != nil { - return nil, err - } - - return imgListResp, nil + return resp, nil } func (o *ModelArtsLink) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) { @@ -110,13 +104,7 @@ func (o *ModelArtsLink) SubmitTask(imageId string, cmd string, envs []string, pa return nil, err } - //转换成统一返回类型 - submitResp, err := ConvertType[modelarts.CreateTrainingJobResp](resp, nil) - if err != nil { - return nil, err - } - - return submitResp, nil + return resp, nil } func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) { @@ -130,13 +118,7 @@ func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - taskResp, err := ConvertType[modelarts.JobResponse](resp, o.participant) - if err != nil { - return nil, err - } - - return taskResp, nil + return resp, nil } func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) { @@ -150,13 +132,7 @@ func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - deleteResp, err := ConvertType[modelarts.DeleteTrainingJobResp](resp, nil) - if err != nil { - return nil, err - } - - return deleteResp, nil + return resp, nil } func (o *ModelArtsLink) QuerySpecs() (interface{}, error) { @@ -169,11 +145,9 @@ func (o *ModelArtsLink) QuerySpecs() (interface{}, error) { return nil, err } - //转换成统一返回类型 - specsResp, err := ConvertType[modelarts.TrainingJobFlavorsResp](resp, o.participant) - if err != nil { - return nil, err - } - - return specsResp, nil + return resp, nil +} + +func (o *ModelArtsLink) GetResourceSpecs() (*collector.ResourceSpecs, error) { + return nil, nil } diff --git a/api/internal/storeLink/octopus.go b/api/internal/storeLink/octopus.go index ea935db2..370ec23c 100644 --- a/api/internal/storeLink/octopus.go +++ b/api/internal/storeLink/octopus.go @@ -16,19 +16,20 @@ package storeLink import ( "context" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus" "strings" ) type OctopusLink struct { - ctx context.Context - svcCtx *svc.ServiceContext - pageIndex int32 - pageSize int32 - participant *models.StorelinkCenter + ctx context.Context + svcCtx *svc.ServiceContext + pageIndex int32 + pageSize int32 + platform string + participantId int64 } const ( @@ -38,14 +39,14 @@ const ( RESOURCE_POOL = "common-pool" ) -func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *OctopusLink { - return &OctopusLink{ctx: ctx, svcCtx: svcCtx, participant: participant, pageIndex: 1, pageSize: 100} +func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *OctopusLink { + return &OctopusLink{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id, pageIndex: 1, pageSize: 100} } func (o *OctopusLink) UploadImage(path string) (interface{}, error) { // octopus创建镜像 createReq := &octopus.CreateImageReq{ - Platform: o.participant.Name, + Platform: o.platform, CreateImage: &octopus.CreateImage{ SourceType: 1, ImageName: IMG_NAME_PREFIX + utils.RandomString(7), @@ -59,7 +60,7 @@ func (o *OctopusLink) UploadImage(path string) (interface{}, error) { // octopus上传镜像 uploadReq := &octopus.UploadImageReq{ - Platform: o.participant.Name, + Platform: o.platform, ImageId: createResp.Payload.ImageId, Params: &octopus.UploadImageParam{ Domain: "", @@ -73,19 +74,13 @@ func (o *OctopusLink) UploadImage(path string) (interface{}, error) { // Todo 实际上传 - //转换成统一返回类型 - resp, err := ConvertType[octopus.UploadImageResp](uploadResp, nil) - if err != nil { - return nil, err - } - - return resp, nil + return uploadResp, nil } func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) { // octopus删除镜像 req := &octopus.DeleteImageReq{ - Platform: o.participant.Name, + Platform: o.platform, ImageId: imageId, } resp, err := o.svcCtx.OctopusRpc.DeleteImage(o.ctx, req) @@ -93,19 +88,13 @@ func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - deleteResp, err := ConvertType[octopus.DeleteImageResp](resp, nil) - if err != nil { - return nil, err - } - - return deleteResp, nil + return resp, nil } func (o *OctopusLink) QueryImageList() (interface{}, error) { // octopus获取镜像列表 req := &octopus.GetUserImageListReq{ - Platform: o.participant.Name, + Platform: o.platform, PageIndex: o.pageIndex, PageSize: o.pageSize, } @@ -114,13 +103,7 @@ func (o *OctopusLink) QueryImageList() (interface{}, error) { return nil, err } - //转换成统一返回类型 - imgListResp, err := ConvertType[octopus.GetUserImageListResp](resp, nil) - if err != nil { - return nil, err - } - - return imgListResp, nil + return resp, nil } func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) { @@ -144,7 +127,7 @@ func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string, para } req := &octopus.CreateTrainJobReq{ - Platform: o.participant.Name, + Platform: o.platform, Params: &octopus.CreateTrainJobParam{ ImageId: imageId, Name: TASK_NAME_PREFIX + UNDERSCORE + utils.RandomString(10), @@ -167,19 +150,13 @@ func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string, para return nil, err } - //转换成统一返回类型 - submitResp, err := ConvertType[octopus.CreateTrainJobResp](resp, nil) - if err != nil { - return nil, err - } - - return submitResp, nil + return resp, nil } func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) { // octopus获取任务 req := &octopus.GetTrainJobReq{ - Platform: o.participant.Name, + Platform: o.platform, Id: taskId, } resp, err := o.svcCtx.OctopusRpc.GetTrainJob(o.ctx, req) @@ -187,19 +164,13 @@ func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - taskResp, err := ConvertType[octopus.GetTrainJobResp](resp, nil) - if err != nil { - return nil, err - } - - return taskResp, nil + return resp, nil } func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) { // octopus删除任务 req := &octopus.DeleteTrainJobReq{ - Platform: o.participant.Name, + Platform: o.platform, JobIds: []string{taskId}, } resp, err := o.svcCtx.OctopusRpc.DeleteTrainJob(o.ctx, req) @@ -207,19 +178,13 @@ func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - deleteResp, err := ConvertType[octopus.DeleteTrainJobResp](resp, nil) - if err != nil { - return nil, err - } - - return deleteResp, nil + return resp, nil } func (o *OctopusLink) QuerySpecs() (interface{}, error) { // octopus查询资源规格 req := &octopus.GetResourceSpecsReq{ - Platform: o.participant.Name, + Platform: o.platform, ResourcePool: "common-pool", } resp, err := o.svcCtx.OctopusRpc.GetResourceSpecs(o.ctx, req) @@ -227,11 +192,9 @@ func (o *OctopusLink) QuerySpecs() (interface{}, error) { return nil, err } - //转换成统一返回类型 - specsResp, err := ConvertType[octopus.GetResourceSpecsResp](resp, o.participant) - if err != nil { - return nil, err - } - - return specsResp, nil + return resp, nil +} + +func (o *OctopusLink) GetResourceSpecs() (*collector.ResourceSpecs, error) { + return nil, nil } diff --git a/api/internal/storeLink/shuguangHpc.go b/api/internal/storeLink/shuguangHpc.go index 8e226478..7c80b456 100644 --- a/api/internal/storeLink/shuguangHpc.go +++ b/api/internal/storeLink/shuguangHpc.go @@ -7,16 +7,16 @@ import ( "gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "strconv" "strings" ) type ShuguangHpc struct { - ctx context.Context - svcCtx *svc.ServiceContext - participant *models.StorelinkCenter + ctx context.Context + svcCtx *svc.ServiceContext + platform string + participantId int64 } const ( @@ -128,8 +128,8 @@ type ResourceSpec struct { GAP_NDCU string } -func NewShuguangHpc(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ShuguangHpc { - return &ShuguangHpc{ctx: ctx, svcCtx: svcCtx, participant: participant} +func NewShuguangHpc(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *ShuguangHpc { + return &ShuguangHpc{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id} } func (s ShuguangHpc) UploadImage(path string) (interface{}, error) { @@ -199,13 +199,7 @@ func (s ShuguangHpc) SubmitTask(imageId string, cmd string, envs []string, param return nil, err } - //转换成统一返回类型 - submitResp, err := ConvertType[hpcAC.SubmitJobResp](resp, nil) - if err != nil { - return nil, err - } - - return submitResp, nil + return resp, nil } @@ -221,30 +215,21 @@ func (s ShuguangHpc) QueryTask(taskId string) (interface{}, error) { //实时作业检查是否成功 if respC.Data != nil && respC.Data.JobEndTime != "" { - taskRespC, err := ConvertType[hpcAC.GetJobDetailResp](respC, nil) + return respC, nil + } else { + //历史作业 + reqH := &hpcAC.HistoryJobDetailReq{ + JobId: taskId, + JobmanagerId: strconv.Itoa(StrJobManagerID), + } + + respH, err := s.svcCtx.ACRpc.HistoryJobDetail(s.ctx, reqH) if err != nil { return nil, err } - return taskRespC, nil - } - //历史作业 - reqH := &hpcAC.HistoryJobDetailReq{ - JobId: taskId, - JobmanagerId: strconv.Itoa(StrJobManagerID), + return respH, nil } - - respH, err := s.svcCtx.ACRpc.HistoryJobDetail(s.ctx, reqH) - if err != nil { - return nil, err - } - - taskRespH, err := ConvertType[hpcAC.HistoryJobDetailResp](respH, nil) - if err != nil { - return nil, err - } - - return taskRespH, nil } func (s ShuguangHpc) QuerySpecs() (interface{}, error) { @@ -254,8 +239,8 @@ func (s ShuguangHpc) QuerySpecs() (interface{}, error) { var respec types.ResourceSpecSl respec.SpecId = k respec.SpecName = v - respec.ParticipantId = s.participant.Id - respec.ParticipantName = s.participant.Name + respec.ParticipantId = s.participantId + respec.ParticipantName = s.platform resp.ResourceSpecs = append(resp.ResourceSpecs, &respec) } @@ -273,13 +258,7 @@ func (s ShuguangHpc) DeleteTask(taskId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - taskResp, err := ConvertType[hpcAC.DeleteJobResp](resp, nil) - if err != nil { - return nil, err - } - - return taskResp, nil + return resp, nil } func updateRequestByResourceId(resourceId string, req *hpcAC.SubmitJobReq) { diff --git a/api/internal/storeLink/shuguangai.go b/api/internal/storeLink/shuguangai.go index d243f7bb..49b2edf2 100644 --- a/api/internal/storeLink/shuguangai.go +++ b/api/internal/storeLink/shuguangai.go @@ -18,16 +18,17 @@ import ( "context" "errors" "gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "strings" ) type ShuguangAi struct { - ctx context.Context - svcCtx *svc.ServiceContext - participant *models.StorelinkCenter + ctx context.Context + svcCtx *svc.ServiceContext + platform string + participantId int64 } const ( @@ -47,8 +48,8 @@ const ( PythonCodePath = "/work/home/acgnnmfbwo/111111/py/test.py" ) -func NewShuguangAi(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ShuguangAi { - return &ShuguangAi{ctx: ctx, svcCtx: svcCtx, participant: participant} +func NewShuguangAi(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *ShuguangAi { + return &ShuguangAi{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id} } func (s *ShuguangAi) UploadImage(path string) (interface{}, error) { @@ -70,13 +71,7 @@ func (s *ShuguangAi) QueryImageList() (interface{}, error) { return nil, err } - //转换成统一返回类型 - imgListResp, err := ConvertType[hpcAC.GetImageListAiResp](resp, nil) - if err != nil { - return nil, err - } - - return imgListResp, nil + return resp, nil } func (s *ShuguangAi) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) { @@ -133,13 +128,7 @@ func (s *ShuguangAi) SubmitTask(imageId string, cmd string, envs []string, param return nil, err } - //转换成统一返回类型 - submitResp, err := ConvertType[hpcAC.SubmitTaskAiResp](resp, nil) - if err != nil { - return nil, err - } - - return submitResp, nil + return resp, nil } func (s *ShuguangAi) QueryTask(taskId string) (interface{}, error) { @@ -152,13 +141,7 @@ func (s *ShuguangAi) QueryTask(taskId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - taskResp, err := ConvertType[hpcAC.GetPytorchTaskResp](resp, nil) - if err != nil { - return nil, err - } - - return taskResp, nil + return resp, nil } func (s *ShuguangAi) DeleteTask(taskId string) (interface{}, error) { @@ -171,13 +154,7 @@ func (s *ShuguangAi) DeleteTask(taskId string) (interface{}, error) { return nil, err } - //转换成统一返回类型 - deleteResp, err := ConvertType[hpcAC.DeleteTaskAiResp](resp, nil) - if err != nil { - return nil, err - } - - return deleteResp, nil + return resp, nil } func (o *ShuguangAi) QuerySpecs() (interface{}, error) { @@ -191,11 +168,9 @@ func (o *ShuguangAi) QuerySpecs() (interface{}, error) { return nil, err } - //转换成统一返回类型 - specsResp, err := ConvertType[hpcAC.GetResourceSpecResp](specs, o.participant) - if err != nil { - return nil, err - } - - return specsResp, nil + return specs, nil +} + +func (o *ShuguangAi) GetResourceSpecs() (*collector.ResourceSpecs, error) { + return nil, nil } diff --git a/api/internal/storeLink/storeLink.go b/api/internal/storeLink/storeLink.go index 596b70d8..18046da4 100644 --- a/api/internal/storeLink/storeLink.go +++ b/api/internal/storeLink/storeLink.go @@ -65,6 +65,8 @@ var ( "3": SHUGUANGAI, "4": SHUGUANGHPC, } + ERROR_RESP_EMPTY = errors.New("resp empty error") + ERROR_CONVERT_EMPTY = errors.New("convert empty error") ) type StoreLink struct { @@ -74,16 +76,16 @@ type StoreLink struct { func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *StoreLink { switch participant.Type { case TYPE_OCTOPUS: - linkStruct := NewOctopusLink(ctx, svcCtx, participant) + linkStruct := NewOctopusLink(ctx, svcCtx, participant.Name, participant.Id) return &StoreLink{ILinkage: linkStruct} case TYPE_MODELARTS: - linkStruct := NewModelArtsLink(ctx, svcCtx, participant) + linkStruct := NewModelArtsLink(ctx, svcCtx, participant.Name, participant.Id) return &StoreLink{ILinkage: linkStruct} case TYPE_SHUGUANGAI: - linkStruct := NewShuguangAi(ctx, svcCtx, participant) + linkStruct := NewShuguangAi(ctx, svcCtx, participant.Name, participant.Id) return &StoreLink{ILinkage: linkStruct} case TYPE_SHUGUANGHPC: - linkStruct := NewShuguangHpc(ctx, svcCtx, participant) + linkStruct := NewShuguangHpc(ctx, svcCtx, participant.Name, participant.Id) return &StoreLink{ILinkage: linkStruct} default: return nil @@ -102,7 +104,7 @@ func GetParticipantById(partId int64, dbEngin *gorm.DB) *models.StorelinkCenter return &participant } -func ConvertType2[T any, RESP any](in *T, out *RESP, participant *models.StorelinkCenter) (interface{}, error) { +func ConvertType(in interface{}, out interface{}, participant *models.StorelinkCenter) (interface{}, error) { switch (interface{})(in).(type) { case *octopus.UploadImageResp: @@ -121,332 +123,412 @@ func ConvertType2[T any, RESP any](in *T, out *RESP, participant *models.Storeli case *octopus.DeleteImageResp: inresp := (interface{})(in).(*octopus.DeleteImageResp) - var resp types.DeleteLinkImageResp - resp.Success = inresp.Success - if !resp.Success { - resp.ErrorMsg = inresp.Error.Message + switch (interface{})(out).(type) { + case *types.DeleteLinkImageResp: + resp := (interface{})(out).(*types.DeleteLinkImageResp) + resp.Success = inresp.Success + if !resp.Success { + resp.ErrorMsg = inresp.Error.Message + return resp, nil + } return resp, nil } - - return resp, nil + return nil, nil case *octopus.GetUserImageListResp: inresp := (interface{})(in).(*octopus.GetUserImageListResp) - var resp types.GetLinkImageListResp - resp.Success = inresp.Success - if !resp.Success { - resp.ErrorMsg = inresp.Error.Message - resp.Images = nil + switch (interface{})(out).(type) { + case *types.GetLinkImageListResp: + resp := (interface{})(out).(*types.GetLinkImageListResp) + resp.Success = inresp.Success + if !resp.Success { + resp.ErrorMsg = inresp.Error.Message + resp.Images = nil + return resp, nil + } + + for _, v := range inresp.Payload.Images { + var image types.ImageSl + image.ImageId = v.Image.Id + image.ImageName = v.Image.ImageName + image.ImageStatus = OctImgStatus[v.Image.ImageStatus] + resp.Images = append(resp.Images, &image) + } return resp, nil } + return nil, nil - for _, v := range inresp.Payload.Images { - var image types.ImageSl - image.ImageId = v.Image.Id - image.ImageName = v.Image.ImageName - image.ImageStatus = OctImgStatus[v.Image.ImageStatus] - resp.Images = append(resp.Images, &image) - } - return resp, nil case *modelarts.ListReposDetailsResp: inresp := (interface{})(in).(*modelarts.ListReposDetailsResp) - var resp types.GetLinkImageListResp + switch (interface{})(out).(type) { + case *types.GetLinkImageListResp: + resp := (interface{})(out).(*types.GetLinkImageListResp) + if inresp.Errors != nil { + resp.Success = false + resp.ErrorMsg = inresp.Errors[0].ErrorMessage + resp.Images = nil + return resp, nil + } - if inresp.Errors != nil { - resp.Success = false - resp.ErrorMsg = inresp.Errors[0].ErrorMessage - resp.Images = nil + resp.Success = true + for _, v := range inresp.Items { + for _, r := range v.Tags { + var image types.ImageSl + image.ImageId = v.Namespace + "/" + v.Name + ":" + r + image.ImageName = v.Name + image.ImageStatus = "created" + resp.Images = append(resp.Images, &image) + } + } return resp, nil } + return nil, nil - resp.Success = true - for _, v := range inresp.Items { - for _, r := range v.Tags { - var image types.ImageSl - image.ImageId = v.Namespace + "/" + v.Name + ":" + r - image.ImageName = v.Name - image.ImageStatus = "created" - resp.Images = append(resp.Images, &image) - } - } - return resp, nil case *hpcAC.GetImageListAiResp: inresp := (interface{})(in).(*hpcAC.GetImageListAiResp) - var resp types.GetLinkImageListResp - - if inresp.Code == "0" { - resp.Success = true - for _, img := range inresp.Data { - var image types.ImageSl - image.ImageId = img.ImageId - image.ImageName = img.Version - image.ImageStatus = "created" - resp.Images = append(resp.Images, &image) + switch (interface{})(out).(type) { + case *types.GetLinkImageListResp: + resp := (interface{})(out).(*types.GetLinkImageListResp) + if inresp.Code == "0" { + resp.Success = true + for _, img := range inresp.Data { + var image types.ImageSl + image.ImageId = img.ImageId + image.ImageName = img.Version + image.ImageStatus = "created" + resp.Images = append(resp.Images, &image) + } + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + resp.Images = nil } - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg - resp.Images = nil + return resp, nil } - return resp, nil + return nil, nil case *octopus.CreateTrainJobResp: inresp := (interface{})(in).(*octopus.CreateTrainJobResp) - var resp types.SubmitLinkTaskResp + switch (interface{})(out).(type) { + case *types.SubmitLinkTaskResp: + resp := (interface{})(out).(*types.SubmitLinkTaskResp) + resp.Success = inresp.Success + if !resp.Success { + resp.ErrorMsg = inresp.Error.Message + return resp, nil + } + + resp.TaskId = inresp.Payload.JobId - resp.Success = inresp.Success - if !resp.Success { - resp.ErrorMsg = inresp.Error.Message return resp, nil } + return nil, nil - resp.TaskId = inresp.Payload.JobId - - return resp, nil case *modelarts.CreateTrainingJobResp: inresp := (interface{})(in).(*modelarts.CreateTrainingJobResp) - var resp types.SubmitLinkTaskResp + switch (interface{})(out).(type) { + case *types.SubmitLinkTaskResp: + resp := (interface{})(out).(*types.SubmitLinkTaskResp) + if inresp.ErrorMsg != "" { + resp.ErrorMsg = inresp.ErrorMsg + resp.Success = false + return resp, nil + } + resp.Success = true + resp.TaskId = inresp.Metadata.Id - if inresp.ErrorMsg != "" { - resp.ErrorMsg = inresp.ErrorMsg - resp.Success = false return resp, nil } - resp.Success = true - resp.TaskId = inresp.Metadata.Id + return nil, nil - return resp, nil case *hpcAC.SubmitTaskAiResp: inresp := (interface{})(in).(*hpcAC.SubmitTaskAiResp) - var resp types.SubmitLinkTaskResp - - if inresp.Code == "0" { - resp.Success = true - resp.TaskId = inresp.Data - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg + switch (interface{})(out).(type) { + case *types.SubmitLinkTaskResp: + resp := (interface{})(out).(*types.SubmitLinkTaskResp) + if inresp.Code == "0" { + resp.Success = true + resp.TaskId = inresp.Data + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + } + return resp, nil } - return resp, nil + return nil, nil + case *hpcAC.SubmitJobResp: inresp := (interface{})(in).(*hpcAC.SubmitJobResp) - var resp types.SubmitLinkTaskResp - - if inresp.Code == "0" { - resp.Success = true - resp.TaskId = inresp.Data - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg + switch (interface{})(out).(type) { + case *types.SubmitLinkTaskResp: + resp := (interface{})(out).(*types.SubmitLinkTaskResp) + if inresp.Code == "0" { + resp.Success = true + resp.TaskId = inresp.Data + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + } + return resp, nil } - return resp, nil + return nil, nil + case *octopus.GetTrainJobResp: inresp := (interface{})(in).(*octopus.GetTrainJobResp) - var resp types.GetLinkTaskResp + switch (interface{})(out).(type) { + case *types.GetLinkTaskResp: + resp := (interface{})(out).(*types.GetLinkTaskResp) + resp.Success = inresp.Success + if !resp.Success { + resp.ErrorMsg = inresp.Error.Message + return resp, nil + } - resp.Success = inresp.Success - if !resp.Success { - resp.ErrorMsg = inresp.Error.Message + var task types.TaskSl + task.TaskId = inresp.Payload.TrainJob.Id + task.TaskName = inresp.Payload.TrainJob.Name + task.StartedAt = inresp.Payload.TrainJob.StartedAt + task.CompletedAt = inresp.Payload.TrainJob.CompletedAt + task.TaskStatus = inresp.Payload.TrainJob.Status + + resp.Task = &task return resp, nil } + return nil, nil - var task types.TaskSl - task.TaskId = inresp.Payload.TrainJob.Id - task.TaskName = inresp.Payload.TrainJob.Name - task.StartedAt = inresp.Payload.TrainJob.StartedAt - task.CompletedAt = inresp.Payload.TrainJob.CompletedAt - task.TaskStatus = inresp.Payload.TrainJob.Status - - resp.Task = &task - return resp, nil case *modelarts.JobResponse: inresp := (interface{})(in).(*modelarts.JobResponse) - var resp types.GetLinkTaskResp + switch (interface{})(out).(type) { + case *types.GetLinkTaskResp: + resp := (interface{})(out).(*types.GetLinkTaskResp) + if inresp.ErrorMsg != "" { + resp.ErrorMsg = inresp.ErrorMsg + resp.Success = false + return resp, nil + } + resp.Success = true + resp.Task = &types.TaskSl{} + resp.Task.TaskId = inresp.Metadata.Id + resp.Task.TaskName = inresp.Metadata.Name + resp.Task.StartedAt = int64(inresp.Status.StartTime) + resp.Task.CompletedAt = int64(inresp.Status.Duration) + resp.Task.TaskStatus = inresp.Status.Phase - if inresp.ErrorMsg != "" { - resp.ErrorMsg = inresp.ErrorMsg - resp.Success = false return resp, nil } - resp.Success = true - resp.Task = &types.TaskSl{} - resp.Task.TaskId = inresp.Metadata.Id - resp.Task.TaskName = inresp.Metadata.Name - resp.Task.StartedAt = int64(inresp.Status.StartTime) - resp.Task.CompletedAt = int64(inresp.Status.Duration) - resp.Task.TaskStatus = inresp.Status.Phase + return nil, nil - return resp, nil case *hpcAC.GetPytorchTaskResp: inresp := (interface{})(in).(*hpcAC.GetPytorchTaskResp) - var resp types.GetLinkTaskResp + switch (interface{})(out).(type) { + case *types.GetLinkTaskResp: + resp := (interface{})(out).(*types.GetLinkTaskResp) + if inresp.Code == "0" { + resp.Success = true + var task types.TaskSl + task.TaskId = inresp.Data.Id + task.TaskName = inresp.Data.TaskName + task.TaskStatus = inresp.Data.Status + task.StartedAt = timeutils.StringToUnixTime(inresp.Data.StartTime) + task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.EndTime) + resp.Task = &task + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + resp.Task = nil + } - if inresp.Code == "0" { - resp.Success = true - var task types.TaskSl - task.TaskId = inresp.Data.Id - task.TaskName = inresp.Data.TaskName - task.TaskStatus = inresp.Data.Status - task.StartedAt = timeutils.StringToUnixTime(inresp.Data.StartTime) - task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.EndTime) - resp.Task = &task - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg - resp.Task = nil + return resp, nil } + return nil, nil - return resp, nil case *hpcAC.GetJobDetailResp: inresp := (interface{})(in).(*hpcAC.GetJobDetailResp) - var resp types.GetLinkTaskResp + switch (interface{})(out).(type) { + case *types.GetLinkTaskResp: + resp := (interface{})(out).(*types.GetLinkTaskResp) + if inresp.Code == "0" { + resp.Success = true + var task types.TaskSl + task.TaskId = inresp.Data.JobId + task.TaskName = inresp.Data.JobName + task.TaskStatus = AcStatus[inresp.Data.JobStatus] + task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime) + task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime) + resp.Task = &task + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + resp.Task = nil + } - if inresp.Code == "0" { - resp.Success = true - var task types.TaskSl - task.TaskId = inresp.Data.JobId - task.TaskName = inresp.Data.JobName - task.TaskStatus = AcStatus[inresp.Data.JobStatus] - task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime) - task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime) - resp.Task = &task - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg - resp.Task = nil + return resp, nil } + return nil, nil - return resp, nil case *hpcAC.HistoryJobDetailResp: inresp := (interface{})(in).(*hpcAC.HistoryJobDetailResp) - var resp types.GetLinkTaskResp + switch (interface{})(out).(type) { + case *types.GetLinkTaskResp: + resp := (interface{})(out).(*types.GetLinkTaskResp) + if inresp.Code == "0" { + resp.Success = true + var task types.TaskSl + task.TaskId = inresp.Data.JobId + task.TaskName = inresp.Data.JobName + task.TaskStatus = AcStatus[inresp.Data.JobState] + task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime) + task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime) + resp.Task = &task + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + resp.Task = nil + } - if inresp.Code == "0" { - resp.Success = true - var task types.TaskSl - task.TaskId = inresp.Data.JobId - task.TaskName = inresp.Data.JobName - task.TaskStatus = AcStatus[inresp.Data.JobState] - task.StartedAt = timeutils.StringToUnixTime(inresp.Data.JobStartTime) - task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.JobEndTime) - resp.Task = &task - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg - resp.Task = nil + return resp, nil } + return nil, nil - return resp, nil case *octopus.DeleteTrainJobResp: inresp := (interface{})(in).(*octopus.DeleteTrainJobResp) - var resp types.DeleteLinkTaskResp + switch (interface{})(out).(type) { + case *types.DeleteLinkTaskResp: + resp := (interface{})(out).(*types.DeleteLinkTaskResp) + resp.Success = inresp.Success + if !resp.Success { + resp.ErrorMsg = inresp.Error.Message + return resp, nil + } - resp.Success = inresp.Success - if !resp.Success { - resp.ErrorMsg = inresp.Error.Message return resp, nil } + return nil, nil - return resp, nil case *modelarts.DeleteTrainingJobResp: inresp := (interface{})(in).(*modelarts.DeleteTrainingJobResp) - var resp types.DeleteLinkTaskResp - - if inresp.ErrorMsg != "" { - resp.ErrorMsg = inresp.ErrorMsg - resp.Success = false + switch (interface{})(out).(type) { + case *types.DeleteLinkTaskResp: + resp := (interface{})(out).(*types.DeleteLinkTaskResp) + if inresp.ErrorMsg != "" { + resp.ErrorMsg = inresp.ErrorMsg + resp.Success = false + return resp, nil + } + resp.Success = true return resp, nil } - resp.Success = true - return resp, nil + return nil, nil + case *hpcAC.DeleteTaskAiResp: inresp := (interface{})(in).(*hpcAC.DeleteTaskAiResp) - var resp types.DeleteLinkTaskResp - - if inresp.Code == "0" { - resp.Success = true - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg + switch (interface{})(out).(type) { + case *types.DeleteLinkTaskResp: + resp := (interface{})(out).(*types.DeleteLinkTaskResp) + if inresp.Code == "0" { + resp.Success = true + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + } + return resp, nil } - return resp, nil + return nil, nil + case *hpcAC.DeleteJobResp: inresp := (interface{})(in).(*hpcAC.DeleteJobResp) - var resp types.DeleteLinkTaskResp - - if inresp.Code == "0" { - resp.Success = true - } else { - resp.Success = false - resp.ErrorMsg = inresp.Msg + switch (interface{})(out).(type) { + case *types.DeleteLinkTaskResp: + resp := (interface{})(out).(*types.DeleteLinkTaskResp) + if inresp.Code == "0" { + resp.Success = true + } else { + resp.Success = false + resp.ErrorMsg = inresp.Msg + } + return resp, nil } - return resp, nil + return nil, nil + case *octopus.GetResourceSpecsResp: inresp := (interface{})(in).(*octopus.GetResourceSpecsResp) - var resp types.GetResourceSpecsResp + switch (interface{})(out).(type) { + case *types.GetResourceSpecsResp: + resp := (interface{})(out).(*types.GetResourceSpecsResp) + resp.Success = inresp.Success + if !resp.Success { + resp.ResourceSpecs = nil + return resp, nil + } + + for _, spec := range inresp.TrainResourceSpecs { + var respec types.ResourceSpecSl + respec.SpecId = spec.Id + respec.SpecName = spec.Name + respec.ParticipantId = participant.Id + respec.ParticipantName = participant.Name + respec.SpecPrice = spec.Price + resp.ResourceSpecs = append(resp.ResourceSpecs, &respec) + } - resp.Success = inresp.Success - if !resp.Success { - resp.ResourceSpecs = nil return resp, nil } + return nil, nil - for _, spec := range inresp.TrainResourceSpecs { - var respec types.ResourceSpecSl - respec.SpecId = spec.Id - respec.SpecName = spec.Name - respec.ParticipantId = participant.Id - respec.ParticipantName = participant.Name - respec.SpecPrice = spec.Price - resp.ResourceSpecs = append(resp.ResourceSpecs, &respec) - } - - return resp, nil case *hpcAC.GetResourceSpecResp: inresp := (interface{})(in).(*hpcAC.GetResourceSpecResp) - var resp types.GetResourceSpecsResp - - if inresp.Code != "0" { - resp.Success = false - resp.ResourceSpecs = nil - } else { - var spec types.ResourceSpecSl - resp.Success = true - spec.ParticipantName = participant.Name - spec.ParticipantId = participant.Id - spec.SpecName = SHUGUANGAI_CUSTOM_RESOURCE_NAME - spec.SpecId = SHUGUANGAI_CUSTOM_RESOURCE_ID - resp.ResourceSpecs = append(resp.ResourceSpecs, &spec) - } - return resp, nil - case *modelarts.TrainingJobFlavorsResp: - inresp := (interface{})(in).(*modelarts.TrainingJobFlavorsResp) - var resp types.GetResourceSpecsResp - resp.Success = true - - if inresp.Flavors == nil { - resp.Success = false - resp.ResourceSpecs = nil + switch (interface{})(out).(type) { + case *types.GetResourceSpecsResp: + resp := (interface{})(out).(*types.GetResourceSpecsResp) + if inresp.Code != "0" { + resp.Success = false + resp.ResourceSpecs = nil + } else { + var spec types.ResourceSpecSl + resp.Success = true + spec.ParticipantName = participant.Name + spec.ParticipantId = participant.Id + spec.SpecName = SHUGUANGAI_CUSTOM_RESOURCE_NAME + spec.SpecId = SHUGUANGAI_CUSTOM_RESOURCE_ID + resp.ResourceSpecs = append(resp.ResourceSpecs, &spec) + } return resp, nil } + return nil, nil - for _, spec := range inresp.Flavors { - var respec types.ResourceSpecSl - respec.SpecId = spec.FlavorId - respec.SpecName = spec.FlavorName - respec.ParticipantId = participant.Id - respec.ParticipantName = participant.Name - respec.SpecPrice = 0 - resp.ResourceSpecs = append(resp.ResourceSpecs, &respec) + case *modelarts.TrainingJobFlavorsResp: + inresp := (interface{})(in).(*modelarts.TrainingJobFlavorsResp) + switch (interface{})(out).(type) { + case *types.GetResourceSpecsResp: + resp := (interface{})(out).(*types.GetResourceSpecsResp) + resp.Success = true + + if inresp.Flavors == nil { + resp.Success = false + resp.ResourceSpecs = nil + return resp, nil + } + + for _, spec := range inresp.Flavors { + var respec types.ResourceSpecSl + respec.SpecId = spec.FlavorId + respec.SpecName = spec.FlavorName + respec.ParticipantId = participant.Id + respec.ParticipantName = participant.Name + respec.SpecPrice = 0 + resp.ResourceSpecs = append(resp.ResourceSpecs, &respec) + } + + return resp, nil } + return nil, nil - return resp, nil default: return nil, errors.New("type convert fail") } } -func ConvertType[T any](in *T, participant *models.StorelinkCenter) (interface{}, error) { +func ConvertTypeOld[T any](in *T, participant *models.StorelinkCenter) (interface{}, error) { switch (interface{})(in).(type) { case *octopus.UploadImageResp: