- /*
-
- Copyright (c) [2023] [pcm]
- [pcm-coordinator] is licensed under Mulan PSL v2.
- You can use this software according to the terms and conditions of the Mulan PSL v2.
- You may obtain a copy of Mulan PSL v2 at:
- http://license.coscl.org.cn/MulanPSL2
- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- See the Mulan PSL v2 for more details.
-
- */
-
- package storeLink
-
- import (
- "context"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/schedulers/option"
- "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/utils"
- "gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts"
- "strconv"
- "strings"
- )
-
- type ModelArtsLink struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- platform string
- participantId int64
- pageIndex int32
- pageSize int32
- }
-
- 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) {
- //TODO modelArts上传镜像
- return nil, nil
- }
-
- func (o *ModelArtsLink) DeleteImage(imageId string) (interface{}, error) {
- // TODO modelArts删除镜像
- return nil, nil
- }
-
- func (o *ModelArtsLink) QueryImageList() (interface{}, error) {
- // modelArts获取镜像列表
- req := &modelarts.ListRepoReq{
- Offset: "0",
- Limit: strconv.Itoa(int(o.pageSize)),
- Platform: o.platform,
- }
- resp, err := o.svcCtx.ModelArtsImgRpc.ListReposDetails(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- return resp, nil
- }
-
- func (o *ModelArtsLink) SubmitTask(imageId string, cmd string, envs []string, params []string, resourceId string) (interface{}, error) {
- // modelArts提交任务
- environments := make(map[string]string)
- parameters := make([]*modelarts.ParametersTrainJob, 0)
- for _, env := range envs {
- s := strings.Split(env, COMMA)
- environments[s[0]] = s[1]
- }
- for _, param := range params {
- s := strings.Split(param, COMMA)
- parameters = append(parameters, &modelarts.ParametersTrainJob{
- Name: s[0],
- Value: s[1],
- })
- }
- req := &modelarts.CreateTrainingJobReq{
- Kind: "job",
- Metadata: &modelarts.MetadataS{
- Name: TASK_NAME_PREFIX + utils.RandomString(10),
- WorkspaceId: "0",
- },
- Algorithm: &modelarts.Algorithms{
- Engine: &modelarts.EngineCreateTraining{
- ImageUrl: imageId,
- },
- Command: cmd,
- Environments: environments,
- Parameters: parameters,
- },
- Spec: &modelarts.SpecsC{
- Resource: &modelarts.ResourceCreateTraining{
- FlavorId: resourceId,
- NodeCount: 1,
- },
- },
- Platform: o.platform,
- }
- resp, err := o.svcCtx.ModelArtsRpc.CreateTrainingJob(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- return resp, nil
- }
-
- func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) {
- // 获取任务
- req := &modelarts.DetailTrainingJobsReq{
- TrainingJobId: taskId,
- Platform: o.platform,
- }
- resp, err := o.svcCtx.ModelArtsRpc.GetTrainingJobs(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- return resp, nil
- }
-
- func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) {
- // 删除任务
- req := &modelarts.DeleteTrainingJobReq{
- TrainingJobId: taskId,
- Platform: o.platform,
- }
- resp, err := o.svcCtx.ModelArtsRpc.DeleteTrainingJob(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- return resp, nil
- }
-
- func (o *ModelArtsLink) QuerySpecs() (interface{}, error) {
- // octopus查询资源规格
- req := &modelarts.TrainingJobFlavorsReq{
- Platform: o.platform,
- }
- resp, err := o.svcCtx.ModelArtsRpc.GetTrainingJobFlavors(o.ctx, req)
- if err != nil {
- return nil, err
- }
-
- return resp, nil
- }
-
- func (o *ModelArtsLink) GetResourceSpecs() (*collector.ResourceSpecs, error) {
- return nil, nil
- }
-
- func (o *ModelArtsLink) Execute(option option.AiOption) (interface{}, error) {
- return nil, nil
- }
|