diff --git a/go.mod b/go.mod index b964a352..97ad27ad 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241125115811-72f3568255a4 gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20241211021152-9771ba5670b7 gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110 - gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20241230091026-2cbf3b839993 + gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20250102093846-164b4884c9ec gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203 gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5 go.opentelemetry.io/otel/trace v1.32.0 diff --git a/go.sum b/go.sum index 69f3ba3c..7aaf567b 100644 --- a/go.sum +++ b/go.sum @@ -532,8 +532,8 @@ gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20241211021152-9771ba5670b7 h1:sP gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20241211021152-9771ba5670b7/go.mod h1:V19vFg8dWRAbaskASoSj70dgpacswOqZu/SaI02dxac= gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110 h1:GaXwr5sgDh0raHjUf9IewTvnRvajYea7zbLsaerYyXo= gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240817071412-44397870b110/go.mod h1:QOD5+/l2D+AYBjF2h5T0mdJyfGAmF78QmeKdbBXbjLQ= -gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20241230091026-2cbf3b839993 h1:u4fv0QNk/ubbkQTsijVUd6Zln7ESYrdXIHUL2Ydd5js= -gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20241230091026-2cbf3b839993/go.mod h1:oDJrr/TNbUCaVjI+RaOrUtGawD7UPAvp7U/oVgT2Dhc= +gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20250102093846-164b4884c9ec h1:Yul2JOAIS94B+eIg0UvmBSe8JrtSrZ2OA47gAYLiBYI= +gitlink.org.cn/JointCloud/pcm-openi v0.0.0-20250102093846-164b4884c9ec/go.mod h1:oDJrr/TNbUCaVjI+RaOrUtGawD7UPAvp7U/oVgT2Dhc= gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203 h1:s6PsZ1+bev294IWdZRlV7mnOwI1+UzFcldVW/BqhQzI= gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203/go.mod h1:i2rrbMQ+Fve345BY9Heh4MUqVTAimZQElQhzzRee5B8= gitlink.org.cn/JointCloud/pcm-slurm v0.0.0-20240301080743-8b94bbaf57f5 h1:+/5vnzkJBfMRnya1NrhOzlroUtRa5ePiYbPKlHLoLV0= diff --git a/internal/storeLink/openi.go b/internal/storeLink/openi.go index 309efbd7..48b4917b 100644 --- a/internal/storeLink/openi.go +++ b/internal/storeLink/openi.go @@ -37,6 +37,7 @@ const ( ReposUrl = "/api/v1/user/repos" TaskListUrl = "/api/v1/task/list" TaskDetailsUrl = "/api/v1/task/detail" + TaskLogUrl = "/api/v1/task/log" ) // compute source @@ -156,7 +157,7 @@ func (o OpenI) Execute(ctx context.Context, option *option.AiOption, mode int) ( for _, s := range resp.Data.Data.Specs.All { if spec.ResType == s.ComputeResource && spec.Name == s.AccCardType { if int(spec.Number) == s.AccCardsNum { - option.ResourceId = strconv.Itoa(s.Id) + option.ResourceId = strconv.Itoa(s.Id) + FORWARD_SLASH + spec.ResType break } } @@ -184,10 +185,14 @@ func (o *OpenI) SubmitTask(ctx context.Context, imageId string, cmd string, envs return nil, errors.New("algorithmId format is incorrect") } - specId, err := strconv.ParseInt(resourceId, 10, 0) + specs := strings.Split(resourceId, FORWARD_SLASH) + specId, err := strconv.ParseInt(specs[0], 10, 0) if err != nil { return nil, err } + + computeSource := specs[1] + repoName = codePaths[0] branchName = codePaths[1] bootFile = codePaths[2] @@ -195,10 +200,11 @@ func (o *OpenI) SubmitTask(ctx context.Context, imageId string, cmd string, envs //params := "{\"parameter\":[{\"label\":\"a\",\"value\":\"1\"},{\"label\":\"b\",\"value\":\"2\"}]}" taskParam := &model.CreateTaskParam{ + Description: algorithmId, // temporarily set reponame contained in the algorithmId to desc for missing taskdetail's reponame JobType: TRAIN, Cluster: C2NET, DisplayJobName: TRAIN + UNDERSCORE + utils.RandomString(10), - ComputeSource: "", + ComputeSource: computeSource, SpecId: int(specId), BranchName: branchName, ImageId: imageId, @@ -235,6 +241,7 @@ func (o *OpenI) SubmitTask(ctx context.Context, imageId string, cmd string, envs Send() if err != nil { + return nil, err } return resp.Data, nil @@ -285,9 +292,57 @@ func (o OpenI) GetAlgorithms(ctx context.Context) ([]*collector.Algorithm, error } func (o OpenI) GetTrainingTaskLog(ctx context.Context, taskId string, instanceNum string) (string, error) { + task, err := o.getTrainingTask(ctx, taskId) + if err != nil { + return "", err + } + + codePaths := strings.Split(task.Data.Task.Description, FORWARD_SLASH) + if len(codePaths) != 3 { + return "", errors.New("failed to get log, openI desc not set") + } + + repoName := codePaths[0] + + tasklogurl := o.host + TaskLogUrl + param := model.GetLogParam{ + UserName: o.userName, + RepoName: repoName, + Id: taskId, + } + + b, _ := json.Marshal(param) + byt := bytes.NewBuffer(b) + + resp := struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data model.TaskDetail `json:"data"` + }{} + + req := common.GetRestyRequest(common.TIMEOUT) + r, _ := http.NewRequest("GET", tasklogurl, byt) + req.RawRequest = r + req.URL = tasklogurl + + _, err = req. + SetHeader("Content-Type", "application/json"). + SetQueryParam(common.ACCESSTOKEN, o.accessToken). + SetBody(byt). + SetResult(&resp). + Send() + + if err != nil { + return "", errors.New("failed to invoke taskDetails") + } + return "", errors.New("failed to implement") } +func (o OpenI) getTrainingTask(ctx context.Context, taskId string) (*model.TaskDetail, error) { + return nil, nil +} + func (o OpenI) GetTrainingTask(ctx context.Context, taskId string) (*collector.Task, error) { taskDetailsUrl := o.host + TaskDetailsUrl