package schedule import ( "context" "errors" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" "gopkg.in/yaml.v2" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type ScheduleRunTaskLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewScheduleRunTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleRunTaskLogic { return &ScheduleRunTaskLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *ScheduleRunTaskLogic) ScheduleRunTask(req *types.RunTaskReq) (resp *types.RunTaskResp, err error) { task, err := l.svcCtx.Scheduler.AiStorages.GetTaskById(req.TaskID) if err != nil { return nil, err } if task == nil { return nil, errors.New("task not found ") } if task.Status == constants.Cancelled { return nil, errors.New("task has been cancelled ") } var clusters []*strategy.AssignedCluster err = yaml.Unmarshal([]byte(task.YamlString), &clusters) if err != nil { return nil, err } opt := &option.AiOption{} aiSchdl, err := schedulers.NewAiScheduler(l.ctx, "", l.svcCtx.Scheduler, opt) if err != nil { return nil, err } _, err = l.svcCtx.Scheduler.AssignAndSchedule(aiSchdl, scheduler.STORAGE_SCHEDULE_MODE, clusters) if err != nil { return nil, err } //adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(ADAPTERID) //if err != nil { // return nil, err //} // //for _, i := range clusters { // clusterName, _ := l.svcCtx.Scheduler.AiStorages.GetClusterNameById(i.ClusterID) // // opt := &option.AiOption{} // // err := l.svcCtx.Scheduler.AiStorages.SaveAiTask(task.Id, opt, adapterName, i.ClusterID, clusterName, "", constants.Saved, "") // if err != nil { // return nil, errors.New("database add failed: " + err.Error()) // } //} return }