Merge pull request 'modified storelink module structure' (#14) from tzwang/pcm-coordinator:master into master

Former-commit-id: 2c539fe282f5a0c471398b5efd272d7363e05eeb
This commit is contained in:
tzwang 2024-01-26 17:26:50 +08:00
commit ea2c9412d3
19 changed files with 494 additions and 598 deletions

View File

@ -57,9 +57,18 @@ func (l *DeleteLinkImageLogic) DeleteLinkImage(req *types.DeleteLinkImageReq) (r
return nil, err return nil, err
} }
if img == nil { if img == nil {
return nil, nil return nil, storeLink.ERROR_RESP_EMPTY
} }
imgResp := img.(types.DeleteLinkImageResp) resp = &types.DeleteLinkImageResp{}
return &imgResp, nil //转换成统一返回类型
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
} }

View File

@ -57,9 +57,18 @@ func (l *DeleteLinkTaskLogic) DeleteLinkTask(req *types.DeleteLinkTaskReq) (resp
return nil, err return nil, err
} }
if task == nil { if task == nil {
return nil, nil return nil, storeLink.ERROR_RESP_EMPTY
} }
taskResp := task.(types.DeleteLinkTaskResp) resp = &types.DeleteLinkTaskResp{}
return &taskResp, nil //转换成统一返回类型
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
} }

View File

@ -57,9 +57,18 @@ func (l *GetAISpecsLogic) GetAISpecs(req *types.GetResourceSpecsReq) (resp *type
return nil, err return nil, err
} }
if specs == nil { if specs == nil {
return nil, nil return nil, storeLink.ERROR_RESP_EMPTY
} }
specsResp := specs.(types.GetResourceSpecsResp) resp = &types.GetResourceSpecsResp{}
return &specsResp, nil //转换成统一返回类型
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
} }

View File

@ -57,9 +57,18 @@ func (l *GetLinkImageListLogic) GetLinkImageList(req *types.GetLinkImageListReq)
return nil, err return nil, err
} }
if list == nil { if list == nil {
return nil, nil return nil, storeLink.ERROR_RESP_EMPTY
} }
listResp := list.(types.GetLinkImageListResp) resp = &types.GetLinkImageListResp{}
return &listResp, nil //转换成统一返回类型
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
} }

View File

@ -58,9 +58,18 @@ func (l *GetLinkTaskLogic) GetLinkTask(req *types.GetLinkTaskReq) (resp *types.G
return nil, err return nil, err
} }
if task == nil { if task == nil {
return nil, nil return nil, storeLink.ERROR_RESP_EMPTY
} }
taskResp := task.(types.GetLinkTaskResp) resp = &types.GetLinkTaskResp{}
return &taskResp, nil //转换成统一返回类型
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
} }

View File

@ -72,6 +72,15 @@ func (l *SubmitLinkTaskLogic) SubmitLinkTask(req *types.SubmitLinkTaskReq) (resp
return nil, err return nil, err
} }
taskResp := task.(types.SubmitLinkTaskResp) resp = &types.SubmitLinkTaskResp{}
return &taskResp, nil //转换成统一返回类型
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
} }

View File

@ -58,9 +58,18 @@ func (l *UploadLinkImageLogic) UploadLinkImage(req *types.UploadLinkImageReq) (r
return nil, err return nil, err
} }
if img == nil { if img == nil {
return nil, nil return nil, storeLink.ERROR_RESP_EMPTY
} }
imgResp := img.(types.UploadLinkImageResp) resp = &types.UploadLinkImageResp{}
return &imgResp, nil //转换成统一返回类型
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
} }

View File

@ -33,7 +33,7 @@ type AiQueue struct {
} }
func NewAiMq(ctx context.Context, svcCtx *svc.ServiceContext) *AiQueue { 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{ return &AiQueue{
ctx: ctx, ctx: ctx,
svcCtx: svcCtx, svcCtx: svcCtx,

View File

@ -83,6 +83,8 @@ func (as *AiScheduler) AssignTask(clusters []*strategy.AssignedCluster) error {
return errors.New("clusters is nil") return errors.New("clusters is nil")
} }
_ = *as.AiExecutor
return nil return nil
} }

View File

@ -1,13 +1,11 @@
package service package service
import ( 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/collector"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/executor" "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-coordinator/api/internal/storeLink"
"gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/imagesservice" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/client/modelartsservice"
"gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopusclient"
) )
const ( 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) executorMap := make(map[string]executor.Executor)
collectorMap := make(map[string]collector.ResourceCollector) collectorMap := make(map[string]collector.ResourceCollector)
for k, v := range AiTypeMap { for k, v := range AiTypeMap {
switch v { switch v {
case OCTOPUS: case OCTOPUS:
octopus := impl.NewOctopusExecutor(OctopusRpc, k) octopus := storeLink.NewOctopusLink(ctx, svcCtx, k, 0)
collectorMap[k] = octopus collectorMap[k] = octopus
executorMap[k] = octopus executorMap[k] = octopus
case MODELARTS: case MODELARTS:
modelarts := impl.NewModelartsExecutor(ModelArtsRpc, ModelArtsImgRpc, k) modelarts := storeLink.NewModelArtsLink(ctx, svcCtx, k, 0)
collectorMap[k] = modelarts collectorMap[k] = modelarts
executorMap[k] = modelarts executorMap[k] = modelarts
case SHUGUANGAI: case SHUGUANGAI:
sgai := impl.NewShuguangAiExecutor(ACRpc, k) sgai := storeLink.NewShuguangAi(ctx, svcCtx, k, 0)
collectorMap[k] = sgai collectorMap[k] = sgai
executorMap[k] = sgai executorMap[k] = sgai
} }

View File

@ -1,17 +1,8 @@
package executor package executor
type Executor interface { type Executor interface {
QueryImageList() ([]Image, error) QueryImageList() (interface{}, error)
SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (Task, error) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error)
QueryTask(taskId string) (Task, error) QueryTask(taskId string) (interface{}, error)
QuerySpecs() (Spec, error) QuerySpecs() (interface{}, error)
}
type Image struct {
}
type Task struct {
}
type Spec struct {
} }

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -16,8 +16,8 @@ package storeLink
import ( import (
"context" "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/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-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts" "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts"
"strconv" "strconv"
@ -25,16 +25,16 @@ import (
) )
type ModelArtsLink struct { type ModelArtsLink struct {
ctx context.Context ctx context.Context
svcCtx *svc.ServiceContext svcCtx *svc.ServiceContext
platform string platform string
pageIndex int32 participantId int64
pageSize int32 pageIndex int32
participant *models.StorelinkCenter pageSize int32
} }
func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ModelArtsLink { func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *ModelArtsLink {
return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, participant: participant, platform: participant.Name, pageIndex: 1, pageSize: 100} return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id, pageIndex: 1, pageSize: 100}
} }
func (o *ModelArtsLink) UploadImage(path string) (interface{}, error) { func (o *ModelArtsLink) UploadImage(path string) (interface{}, error) {
@ -59,13 +59,7 @@ func (o *ModelArtsLink) QueryImageList() (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
imgListResp, err := ConvertType[modelarts.ListReposDetailsResp](resp, nil)
if err != nil {
return nil, err
}
return imgListResp, nil
} }
func (o *ModelArtsLink) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) { 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 return nil, err
} }
//转换成统一返回类型 return resp, nil
submitResp, err := ConvertType[modelarts.CreateTrainingJobResp](resp, nil)
if err != nil {
return nil, err
}
return submitResp, nil
} }
func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) { func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) {
@ -130,13 +118,7 @@ func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
taskResp, err := ConvertType[modelarts.JobResponse](resp, o.participant)
if err != nil {
return nil, err
}
return taskResp, nil
} }
func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) { func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) {
@ -150,13 +132,7 @@ func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
deleteResp, err := ConvertType[modelarts.DeleteTrainingJobResp](resp, nil)
if err != nil {
return nil, err
}
return deleteResp, nil
} }
func (o *ModelArtsLink) QuerySpecs() (interface{}, error) { func (o *ModelArtsLink) QuerySpecs() (interface{}, error) {
@ -169,11 +145,9 @@ func (o *ModelArtsLink) QuerySpecs() (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
specsResp, err := ConvertType[modelarts.TrainingJobFlavorsResp](resp, o.participant) }
if err != nil {
return nil, err func (o *ModelArtsLink) GetResourceSpecs() (*collector.ResourceSpecs, error) {
} return nil, nil
return specsResp, nil
} }

View File

@ -16,19 +16,20 @@ package storeLink
import ( import (
"context" "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/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-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus" "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus"
"strings" "strings"
) )
type OctopusLink struct { type OctopusLink struct {
ctx context.Context ctx context.Context
svcCtx *svc.ServiceContext svcCtx *svc.ServiceContext
pageIndex int32 pageIndex int32
pageSize int32 pageSize int32
participant *models.StorelinkCenter platform string
participantId int64
} }
const ( const (
@ -38,14 +39,14 @@ const (
RESOURCE_POOL = "common-pool" RESOURCE_POOL = "common-pool"
) )
func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *OctopusLink { func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *OctopusLink {
return &OctopusLink{ctx: ctx, svcCtx: svcCtx, participant: participant, pageIndex: 1, pageSize: 100} return &OctopusLink{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id, pageIndex: 1, pageSize: 100}
} }
func (o *OctopusLink) UploadImage(path string) (interface{}, error) { func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
// octopus创建镜像 // octopus创建镜像
createReq := &octopus.CreateImageReq{ createReq := &octopus.CreateImageReq{
Platform: o.participant.Name, Platform: o.platform,
CreateImage: &octopus.CreateImage{ CreateImage: &octopus.CreateImage{
SourceType: 1, SourceType: 1,
ImageName: IMG_NAME_PREFIX + utils.RandomString(7), ImageName: IMG_NAME_PREFIX + utils.RandomString(7),
@ -59,7 +60,7 @@ func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
// octopus上传镜像 // octopus上传镜像
uploadReq := &octopus.UploadImageReq{ uploadReq := &octopus.UploadImageReq{
Platform: o.participant.Name, Platform: o.platform,
ImageId: createResp.Payload.ImageId, ImageId: createResp.Payload.ImageId,
Params: &octopus.UploadImageParam{ Params: &octopus.UploadImageParam{
Domain: "", Domain: "",
@ -73,19 +74,13 @@ func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
// Todo 实际上传 // Todo 实际上传
//转换成统一返回类型 return uploadResp, nil
resp, err := ConvertType[octopus.UploadImageResp](uploadResp, nil)
if err != nil {
return nil, err
}
return resp, nil
} }
func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) { func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) {
// octopus删除镜像 // octopus删除镜像
req := &octopus.DeleteImageReq{ req := &octopus.DeleteImageReq{
Platform: o.participant.Name, Platform: o.platform,
ImageId: imageId, ImageId: imageId,
} }
resp, err := o.svcCtx.OctopusRpc.DeleteImage(o.ctx, req) resp, err := o.svcCtx.OctopusRpc.DeleteImage(o.ctx, req)
@ -93,19 +88,13 @@ func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
deleteResp, err := ConvertType[octopus.DeleteImageResp](resp, nil)
if err != nil {
return nil, err
}
return deleteResp, nil
} }
func (o *OctopusLink) QueryImageList() (interface{}, error) { func (o *OctopusLink) QueryImageList() (interface{}, error) {
// octopus获取镜像列表 // octopus获取镜像列表
req := &octopus.GetUserImageListReq{ req := &octopus.GetUserImageListReq{
Platform: o.participant.Name, Platform: o.platform,
PageIndex: o.pageIndex, PageIndex: o.pageIndex,
PageSize: o.pageSize, PageSize: o.pageSize,
} }
@ -114,13 +103,7 @@ func (o *OctopusLink) QueryImageList() (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
imgListResp, err := ConvertType[octopus.GetUserImageListResp](resp, nil)
if err != nil {
return nil, err
}
return imgListResp, nil
} }
func (o *OctopusLink) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) { 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{ req := &octopus.CreateTrainJobReq{
Platform: o.participant.Name, Platform: o.platform,
Params: &octopus.CreateTrainJobParam{ Params: &octopus.CreateTrainJobParam{
ImageId: imageId, ImageId: imageId,
Name: TASK_NAME_PREFIX + UNDERSCORE + utils.RandomString(10), 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 return nil, err
} }
//转换成统一返回类型 return resp, nil
submitResp, err := ConvertType[octopus.CreateTrainJobResp](resp, nil)
if err != nil {
return nil, err
}
return submitResp, nil
} }
func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) { func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) {
// octopus获取任务 // octopus获取任务
req := &octopus.GetTrainJobReq{ req := &octopus.GetTrainJobReq{
Platform: o.participant.Name, Platform: o.platform,
Id: taskId, Id: taskId,
} }
resp, err := o.svcCtx.OctopusRpc.GetTrainJob(o.ctx, req) resp, err := o.svcCtx.OctopusRpc.GetTrainJob(o.ctx, req)
@ -187,19 +164,13 @@ func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
taskResp, err := ConvertType[octopus.GetTrainJobResp](resp, nil)
if err != nil {
return nil, err
}
return taskResp, nil
} }
func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) { func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) {
// octopus删除任务 // octopus删除任务
req := &octopus.DeleteTrainJobReq{ req := &octopus.DeleteTrainJobReq{
Platform: o.participant.Name, Platform: o.platform,
JobIds: []string{taskId}, JobIds: []string{taskId},
} }
resp, err := o.svcCtx.OctopusRpc.DeleteTrainJob(o.ctx, req) resp, err := o.svcCtx.OctopusRpc.DeleteTrainJob(o.ctx, req)
@ -207,19 +178,13 @@ func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
deleteResp, err := ConvertType[octopus.DeleteTrainJobResp](resp, nil)
if err != nil {
return nil, err
}
return deleteResp, nil
} }
func (o *OctopusLink) QuerySpecs() (interface{}, error) { func (o *OctopusLink) QuerySpecs() (interface{}, error) {
// octopus查询资源规格 // octopus查询资源规格
req := &octopus.GetResourceSpecsReq{ req := &octopus.GetResourceSpecsReq{
Platform: o.participant.Name, Platform: o.platform,
ResourcePool: "common-pool", ResourcePool: "common-pool",
} }
resp, err := o.svcCtx.OctopusRpc.GetResourceSpecs(o.ctx, req) resp, err := o.svcCtx.OctopusRpc.GetResourceSpecs(o.ctx, req)
@ -227,11 +192,9 @@ func (o *OctopusLink) QuerySpecs() (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
specsResp, err := ConvertType[octopus.GetResourceSpecsResp](resp, o.participant) }
if err != nil {
return nil, err func (o *OctopusLink) GetResourceSpecs() (*collector.ResourceSpecs, error) {
} return nil, nil
return specsResp, nil
} }

View File

@ -7,16 +7,16 @@ import (
"gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC" "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/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "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" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"strconv" "strconv"
"strings" "strings"
) )
type ShuguangHpc struct { type ShuguangHpc struct {
ctx context.Context ctx context.Context
svcCtx *svc.ServiceContext svcCtx *svc.ServiceContext
participant *models.StorelinkCenter platform string
participantId int64
} }
const ( const (
@ -128,8 +128,8 @@ type ResourceSpec struct {
GAP_NDCU string GAP_NDCU string
} }
func NewShuguangHpc(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ShuguangHpc { func NewShuguangHpc(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *ShuguangHpc {
return &ShuguangHpc{ctx: ctx, svcCtx: svcCtx, participant: participant} return &ShuguangHpc{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id}
} }
func (s ShuguangHpc) UploadImage(path string) (interface{}, error) { 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 return nil, err
} }
//转换成统一返回类型 return resp, nil
submitResp, err := ConvertType[hpcAC.SubmitJobResp](resp, nil)
if err != nil {
return nil, err
}
return submitResp, nil
} }
@ -221,30 +215,21 @@ func (s ShuguangHpc) QueryTask(taskId string) (interface{}, error) {
//实时作业检查是否成功 //实时作业检查是否成功
if respC.Data != nil && respC.Data.JobEndTime != "" { 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 { if err != nil {
return nil, err return nil, err
} }
return taskRespC, nil
}
//历史作业 return respH, nil
reqH := &hpcAC.HistoryJobDetailReq{
JobId: taskId,
JobmanagerId: strconv.Itoa(StrJobManagerID),
} }
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) { func (s ShuguangHpc) QuerySpecs() (interface{}, error) {
@ -254,8 +239,8 @@ func (s ShuguangHpc) QuerySpecs() (interface{}, error) {
var respec types.ResourceSpecSl var respec types.ResourceSpecSl
respec.SpecId = k respec.SpecId = k
respec.SpecName = v respec.SpecName = v
respec.ParticipantId = s.participant.Id respec.ParticipantId = s.participantId
respec.ParticipantName = s.participant.Name respec.ParticipantName = s.platform
resp.ResourceSpecs = append(resp.ResourceSpecs, &respec) resp.ResourceSpecs = append(resp.ResourceSpecs, &respec)
} }
@ -273,13 +258,7 @@ func (s ShuguangHpc) DeleteTask(taskId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
taskResp, err := ConvertType[hpcAC.DeleteJobResp](resp, nil)
if err != nil {
return nil, err
}
return taskResp, nil
} }
func updateRequestByResourceId(resourceId string, req *hpcAC.SubmitJobReq) { func updateRequestByResourceId(resourceId string, req *hpcAC.SubmitJobReq) {

View File

@ -18,16 +18,17 @@ import (
"context" "context"
"errors" "errors"
"gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC" "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/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-coordinator/pkg/utils"
"strings" "strings"
) )
type ShuguangAi struct { type ShuguangAi struct {
ctx context.Context ctx context.Context
svcCtx *svc.ServiceContext svcCtx *svc.ServiceContext
participant *models.StorelinkCenter platform string
participantId int64
} }
const ( const (
@ -47,8 +48,8 @@ const (
PythonCodePath = "/work/home/acgnnmfbwo/111111/py/test.py" PythonCodePath = "/work/home/acgnnmfbwo/111111/py/test.py"
) )
func NewShuguangAi(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ShuguangAi { func NewShuguangAi(ctx context.Context, svcCtx *svc.ServiceContext, name string, id int64) *ShuguangAi {
return &ShuguangAi{ctx: ctx, svcCtx: svcCtx, participant: participant} return &ShuguangAi{ctx: ctx, svcCtx: svcCtx, platform: name, participantId: id}
} }
func (s *ShuguangAi) UploadImage(path string) (interface{}, error) { func (s *ShuguangAi) UploadImage(path string) (interface{}, error) {
@ -70,13 +71,7 @@ func (s *ShuguangAi) QueryImageList() (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
imgListResp, err := ConvertType[hpcAC.GetImageListAiResp](resp, nil)
if err != nil {
return nil, err
}
return imgListResp, nil
} }
func (s *ShuguangAi) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) { 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 return nil, err
} }
//转换成统一返回类型 return resp, nil
submitResp, err := ConvertType[hpcAC.SubmitTaskAiResp](resp, nil)
if err != nil {
return nil, err
}
return submitResp, nil
} }
func (s *ShuguangAi) QueryTask(taskId string) (interface{}, error) { func (s *ShuguangAi) QueryTask(taskId string) (interface{}, error) {
@ -152,13 +141,7 @@ func (s *ShuguangAi) QueryTask(taskId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
taskResp, err := ConvertType[hpcAC.GetPytorchTaskResp](resp, nil)
if err != nil {
return nil, err
}
return taskResp, nil
} }
func (s *ShuguangAi) DeleteTask(taskId string) (interface{}, error) { func (s *ShuguangAi) DeleteTask(taskId string) (interface{}, error) {
@ -171,13 +154,7 @@ func (s *ShuguangAi) DeleteTask(taskId string) (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return resp, nil
deleteResp, err := ConvertType[hpcAC.DeleteTaskAiResp](resp, nil)
if err != nil {
return nil, err
}
return deleteResp, nil
} }
func (o *ShuguangAi) QuerySpecs() (interface{}, error) { func (o *ShuguangAi) QuerySpecs() (interface{}, error) {
@ -191,11 +168,9 @@ func (o *ShuguangAi) QuerySpecs() (interface{}, error) {
return nil, err return nil, err
} }
//转换成统一返回类型 return specs, nil
specsResp, err := ConvertType[hpcAC.GetResourceSpecResp](specs, o.participant) }
if err != nil {
return nil, err func (o *ShuguangAi) GetResourceSpecs() (*collector.ResourceSpecs, error) {
} return nil, nil
return specsResp, nil
} }

View File

@ -65,6 +65,8 @@ var (
"3": SHUGUANGAI, "3": SHUGUANGAI,
"4": SHUGUANGHPC, "4": SHUGUANGHPC,
} }
ERROR_RESP_EMPTY = errors.New("resp empty error")
ERROR_CONVERT_EMPTY = errors.New("convert empty error")
) )
type StoreLink struct { type StoreLink struct {
@ -74,16 +76,16 @@ type StoreLink struct {
func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *StoreLink { func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *StoreLink {
switch participant.Type { switch participant.Type {
case TYPE_OCTOPUS: case TYPE_OCTOPUS:
linkStruct := NewOctopusLink(ctx, svcCtx, participant) linkStruct := NewOctopusLink(ctx, svcCtx, participant.Name, participant.Id)
return &StoreLink{ILinkage: linkStruct} return &StoreLink{ILinkage: linkStruct}
case TYPE_MODELARTS: case TYPE_MODELARTS:
linkStruct := NewModelArtsLink(ctx, svcCtx, participant) linkStruct := NewModelArtsLink(ctx, svcCtx, participant.Name, participant.Id)
return &StoreLink{ILinkage: linkStruct} return &StoreLink{ILinkage: linkStruct}
case TYPE_SHUGUANGAI: case TYPE_SHUGUANGAI:
linkStruct := NewShuguangAi(ctx, svcCtx, participant) linkStruct := NewShuguangAi(ctx, svcCtx, participant.Name, participant.Id)
return &StoreLink{ILinkage: linkStruct} return &StoreLink{ILinkage: linkStruct}
case TYPE_SHUGUANGHPC: case TYPE_SHUGUANGHPC:
linkStruct := NewShuguangHpc(ctx, svcCtx, participant) linkStruct := NewShuguangHpc(ctx, svcCtx, participant.Name, participant.Id)
return &StoreLink{ILinkage: linkStruct} return &StoreLink{ILinkage: linkStruct}
default: default:
return nil return nil
@ -102,7 +104,7 @@ func GetParticipantById(partId int64, dbEngin *gorm.DB) *models.StorelinkCenter
return &participant 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) { switch (interface{})(in).(type) {
case *octopus.UploadImageResp: case *octopus.UploadImageResp:
@ -121,332 +123,412 @@ func ConvertType2[T any, RESP any](in *T, out *RESP, participant *models.Storeli
case *octopus.DeleteImageResp: case *octopus.DeleteImageResp:
inresp := (interface{})(in).(*octopus.DeleteImageResp) inresp := (interface{})(in).(*octopus.DeleteImageResp)
var resp types.DeleteLinkImageResp switch (interface{})(out).(type) {
resp.Success = inresp.Success case *types.DeleteLinkImageResp:
if !resp.Success { resp := (interface{})(out).(*types.DeleteLinkImageResp)
resp.ErrorMsg = inresp.Error.Message resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil return resp, nil
} }
return nil, nil
return resp, nil
case *octopus.GetUserImageListResp: case *octopus.GetUserImageListResp:
inresp := (interface{})(in).(*octopus.GetUserImageListResp) inresp := (interface{})(in).(*octopus.GetUserImageListResp)
var resp types.GetLinkImageListResp switch (interface{})(out).(type) {
resp.Success = inresp.Success case *types.GetLinkImageListResp:
if !resp.Success { resp := (interface{})(out).(*types.GetLinkImageListResp)
resp.ErrorMsg = inresp.Error.Message resp.Success = inresp.Success
resp.Images = nil 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 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: case *modelarts.ListReposDetailsResp:
inresp := (interface{})(in).(*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 = true
resp.Success = false for _, v := range inresp.Items {
resp.ErrorMsg = inresp.Errors[0].ErrorMessage for _, r := range v.Tags {
resp.Images = nil 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 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: case *hpcAC.GetImageListAiResp:
inresp := (interface{})(in).(*hpcAC.GetImageListAiResp) inresp := (interface{})(in).(*hpcAC.GetImageListAiResp)
var resp types.GetLinkImageListResp switch (interface{})(out).(type) {
case *types.GetLinkImageListResp:
if inresp.Code == "0" { resp := (interface{})(out).(*types.GetLinkImageListResp)
resp.Success = true if inresp.Code == "0" {
for _, img := range inresp.Data { resp.Success = true
var image types.ImageSl for _, img := range inresp.Data {
image.ImageId = img.ImageId var image types.ImageSl
image.ImageName = img.Version image.ImageId = img.ImageId
image.ImageStatus = "created" image.ImageName = img.Version
resp.Images = append(resp.Images, &image) image.ImageStatus = "created"
resp.Images = append(resp.Images, &image)
}
} else {
resp.Success = false
resp.ErrorMsg = inresp.Msg
resp.Images = nil
} }
} else { return resp, nil
resp.Success = false
resp.ErrorMsg = inresp.Msg
resp.Images = nil
} }
return resp, nil return nil, nil
case *octopus.CreateTrainJobResp: case *octopus.CreateTrainJobResp:
inresp := (interface{})(in).(*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 resp, nil
} }
return nil, nil
resp.TaskId = inresp.Payload.JobId
return resp, nil
case *modelarts.CreateTrainingJobResp: case *modelarts.CreateTrainingJobResp:
inresp := (interface{})(in).(*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 return resp, nil
} }
resp.Success = true return nil, nil
resp.TaskId = inresp.Metadata.Id
return resp, nil
case *hpcAC.SubmitTaskAiResp: case *hpcAC.SubmitTaskAiResp:
inresp := (interface{})(in).(*hpcAC.SubmitTaskAiResp) inresp := (interface{})(in).(*hpcAC.SubmitTaskAiResp)
var resp types.SubmitLinkTaskResp switch (interface{})(out).(type) {
case *types.SubmitLinkTaskResp:
if inresp.Code == "0" { resp := (interface{})(out).(*types.SubmitLinkTaskResp)
resp.Success = true if inresp.Code == "0" {
resp.TaskId = inresp.Data resp.Success = true
} else { resp.TaskId = inresp.Data
resp.Success = false } else {
resp.ErrorMsg = inresp.Msg resp.Success = false
resp.ErrorMsg = inresp.Msg
}
return resp, nil
} }
return resp, nil return nil, nil
case *hpcAC.SubmitJobResp: case *hpcAC.SubmitJobResp:
inresp := (interface{})(in).(*hpcAC.SubmitJobResp) inresp := (interface{})(in).(*hpcAC.SubmitJobResp)
var resp types.SubmitLinkTaskResp switch (interface{})(out).(type) {
case *types.SubmitLinkTaskResp:
if inresp.Code == "0" { resp := (interface{})(out).(*types.SubmitLinkTaskResp)
resp.Success = true if inresp.Code == "0" {
resp.TaskId = inresp.Data resp.Success = true
} else { resp.TaskId = inresp.Data
resp.Success = false } else {
resp.ErrorMsg = inresp.Msg resp.Success = false
resp.ErrorMsg = inresp.Msg
}
return resp, nil
} }
return resp, nil return nil, nil
case *octopus.GetTrainJobResp: case *octopus.GetTrainJobResp:
inresp := (interface{})(in).(*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 var task types.TaskSl
if !resp.Success { task.TaskId = inresp.Payload.TrainJob.Id
resp.ErrorMsg = inresp.Error.Message 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 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: case *modelarts.JobResponse:
inresp := (interface{})(in).(*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 return resp, nil
} }
resp.Success = true return nil, nil
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 resp, nil
case *hpcAC.GetPytorchTaskResp: case *hpcAC.GetPytorchTaskResp:
inresp := (interface{})(in).(*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" { return resp, nil
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 nil, nil
return resp, nil
case *hpcAC.GetJobDetailResp: case *hpcAC.GetJobDetailResp:
inresp := (interface{})(in).(*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" { return resp, nil
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 nil, nil
return resp, nil
case *hpcAC.HistoryJobDetailResp: case *hpcAC.HistoryJobDetailResp:
inresp := (interface{})(in).(*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" { return resp, nil
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 nil, nil
return resp, nil
case *octopus.DeleteTrainJobResp: case *octopus.DeleteTrainJobResp:
inresp := (interface{})(in).(*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 resp, nil
} }
return nil, nil
return resp, nil
case *modelarts.DeleteTrainingJobResp: case *modelarts.DeleteTrainingJobResp:
inresp := (interface{})(in).(*modelarts.DeleteTrainingJobResp) inresp := (interface{})(in).(*modelarts.DeleteTrainingJobResp)
var resp types.DeleteLinkTaskResp switch (interface{})(out).(type) {
case *types.DeleteLinkTaskResp:
if inresp.ErrorMsg != "" { resp := (interface{})(out).(*types.DeleteLinkTaskResp)
resp.ErrorMsg = inresp.ErrorMsg if inresp.ErrorMsg != "" {
resp.Success = false resp.ErrorMsg = inresp.ErrorMsg
resp.Success = false
return resp, nil
}
resp.Success = true
return resp, nil return resp, nil
} }
resp.Success = true return nil, nil
return resp, nil
case *hpcAC.DeleteTaskAiResp: case *hpcAC.DeleteTaskAiResp:
inresp := (interface{})(in).(*hpcAC.DeleteTaskAiResp) inresp := (interface{})(in).(*hpcAC.DeleteTaskAiResp)
var resp types.DeleteLinkTaskResp switch (interface{})(out).(type) {
case *types.DeleteLinkTaskResp:
if inresp.Code == "0" { resp := (interface{})(out).(*types.DeleteLinkTaskResp)
resp.Success = true if inresp.Code == "0" {
} else { resp.Success = true
resp.Success = false } else {
resp.ErrorMsg = inresp.Msg resp.Success = false
resp.ErrorMsg = inresp.Msg
}
return resp, nil
} }
return resp, nil return nil, nil
case *hpcAC.DeleteJobResp: case *hpcAC.DeleteJobResp:
inresp := (interface{})(in).(*hpcAC.DeleteJobResp) inresp := (interface{})(in).(*hpcAC.DeleteJobResp)
var resp types.DeleteLinkTaskResp switch (interface{})(out).(type) {
case *types.DeleteLinkTaskResp:
if inresp.Code == "0" { resp := (interface{})(out).(*types.DeleteLinkTaskResp)
resp.Success = true if inresp.Code == "0" {
} else { resp.Success = true
resp.Success = false } else {
resp.ErrorMsg = inresp.Msg resp.Success = false
resp.ErrorMsg = inresp.Msg
}
return resp, nil
} }
return resp, nil return nil, nil
case *octopus.GetResourceSpecsResp: case *octopus.GetResourceSpecsResp:
inresp := (interface{})(in).(*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 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: case *hpcAC.GetResourceSpecResp:
inresp := (interface{})(in).(*hpcAC.GetResourceSpecResp) inresp := (interface{})(in).(*hpcAC.GetResourceSpecResp)
var resp types.GetResourceSpecsResp switch (interface{})(out).(type) {
case *types.GetResourceSpecsResp:
if inresp.Code != "0" { resp := (interface{})(out).(*types.GetResourceSpecsResp)
resp.Success = false if inresp.Code != "0" {
resp.ResourceSpecs = nil resp.Success = false
} else { resp.ResourceSpecs = nil
var spec types.ResourceSpecSl } else {
resp.Success = true var spec types.ResourceSpecSl
spec.ParticipantName = participant.Name resp.Success = true
spec.ParticipantId = participant.Id spec.ParticipantName = participant.Name
spec.SpecName = SHUGUANGAI_CUSTOM_RESOURCE_NAME spec.ParticipantId = participant.Id
spec.SpecId = SHUGUANGAI_CUSTOM_RESOURCE_ID spec.SpecName = SHUGUANGAI_CUSTOM_RESOURCE_NAME
resp.ResourceSpecs = append(resp.ResourceSpecs, &spec) 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
return resp, nil return resp, nil
} }
return nil, nil
for _, spec := range inresp.Flavors { case *modelarts.TrainingJobFlavorsResp:
var respec types.ResourceSpecSl inresp := (interface{})(in).(*modelarts.TrainingJobFlavorsResp)
respec.SpecId = spec.FlavorId switch (interface{})(out).(type) {
respec.SpecName = spec.FlavorName case *types.GetResourceSpecsResp:
respec.ParticipantId = participant.Id resp := (interface{})(out).(*types.GetResourceSpecsResp)
respec.ParticipantName = participant.Name resp.Success = true
respec.SpecPrice = 0
resp.ResourceSpecs = append(resp.ResourceSpecs, &respec) 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: default:
return nil, errors.New("type convert fail") 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) { switch (interface{})(in).(type) {
case *octopus.UploadImageResp: case *octopus.UploadImageResp: