package inference import ( "context" "errors" "github.com/zeromicro/go-zero/core/logx" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/status" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "strconv" ) type StopDeployInstanceLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewStopDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StopDeployInstanceLogic { return &StopDeployInstanceLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *StopDeployInstanceLogic) StopDeployInstance(req *types.StopDeployInstanceReq) (resp *types.StopDeployInstanceResp, err error) { resp = &types.StopDeployInstanceResp{} id, err := strconv.ParseInt(req.Id, 10, 64) ins, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id) if err != nil { return nil, err } in, err := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].GetInferDeployInstance(l.ctx, ins.InstanceId) if status.CheckRunningStatus(in) { success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StopInferDeployInstance(l.ctx, req.InstanceId) if !success { return nil, errors.New("stop instance failed") } } go status.UpdateDeployInstanceStatus(l.svcCtx, ins, true) return resp, nil }