68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package schedule
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
|
|
"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 ")
|
|
}
|
|
|
|
var clusters []*types.JobClusterInfo
|
|
err = yaml.Unmarshal([]byte(task.YamlString), &clusters)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
//schedule, err := l.svcCtx.Scheduler.AssignAndSchedule()
|
|
//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
|
|
}
|