|
- package inference
-
- import (
- "context"
- "errors"
- "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"
-
- "github.com/zeromicro/go-zero/core/logx"
- )
-
- type StopAllByDeployTaskIdLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
-
- func NewStopAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StopAllByDeployTaskIdLogic {
- return &StopAllByDeployTaskIdLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
-
- func (l *StopAllByDeployTaskIdLogic) StopAllByDeployTaskId(req *types.StopAllByDeployTaskIdReq) (resp *types.StopAllByDeployTaskIdResp, err error) {
- resp = &types.StopAllByDeployTaskIdResp{}
-
- 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 checkStatus(in) {
- success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].StopInferDeployInstance(l.ctx, ins.InstanceId)
- if !success {
- return nil, errors.New(ins.InstanceName + " stop failed")
- }
- }
- }
-
- err = l.svcCtx.Scheduler.AiStorages.UpdateDeployTaskById(id)
- if err != nil {
- return nil, err
- }
-
- return resp, nil
- }
-
- func checkStatus(in *inference.DeployInstance) bool {
- switch in.ClusterType {
- case storeLink.TYPE_OCTOPUS:
- switch in.Status {
- case "running":
- return true
- default:
- return false
- }
- case storeLink.TYPE_MODELARTS:
- switch in.Status {
- case "running":
- return true
- default:
- return false
- }
- case storeLink.TYPE_SHUGUANGAI:
- switch in.Status {
- case "Running":
- return true
- default:
- return false
- }
- default:
- return false
- }
- }
|