package inference import ( "context" "errors" "github.com/zeromicro/go-zero/core/logx" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/storeLink" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "strconv" ) type StartAllByDeployTaskIdLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewStartAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StartAllByDeployTaskIdLogic { return &StartAllByDeployTaskIdLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *StartAllByDeployTaskIdLogic) StartAllByDeployTaskId(req *types.StartAllByDeployTaskIdReq) (resp *types.StartAllByDeployTaskIdResp, err error) { resp = &types.StartAllByDeployTaskIdResp{} id, err := strconv.ParseInt(req.Id, 10, 64) list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(id) if err != nil { return nil, err } for _, ins := range list { in, err := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].GetInferDeployInstance(l.ctx, ins.InstanceId) if err != nil { return nil, err } if checkStopStatus(in) { success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].StartInferDeployInstance(l.ctx, ins.InstanceId) if !success { return nil, errors.New(ins.InstanceName + " start failed") } } } err = l.svcCtx.Scheduler.AiStorages.UpdateDeployTaskById(id) if err != nil { return nil, err } return resp, nil } func checkStopStatus(in *inference.DeployInstance) bool { switch in.ClusterType { case storeLink.TYPE_OCTOPUS: switch in.Status { case "stopped": return true default: return false } case storeLink.TYPE_MODELARTS: switch in.Status { case "stopped": return true default: return false } case storeLink.TYPE_SHUGUANGAI: switch in.Status { case "Terminated": return true default: return false } default: return false } }