diff --git a/internal/logic/inference/startallbydeploytaskidlogic.go b/internal/logic/inference/startallbydeploytaskidlogic.go index 34d3891b..2519cf00 100644 --- a/internal/logic/inference/startallbydeploytaskidlogic.go +++ b/internal/logic/inference/startallbydeploytaskidlogic.go @@ -2,11 +2,12 @@ package inference import ( "context" - + "errors" + "github.com/zeromicro/go-zero/core/logx" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/updater" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" - - "github.com/zeromicro/go-zero/core/logx" + "strconv" ) type StartAllByDeployTaskIdLogic struct { @@ -24,7 +25,23 @@ func NewStartAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceCont } func (l *StartAllByDeployTaskIdLogic) StartAllByDeployTaskId(req *types.StartAllByDeployTaskIdReq) (resp *types.StartAllByDeployTaskIdResp, err error) { - // todo: add your logic here and delete this line + resp = &types.StartAllByDeployTaskIdResp{} - return + 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 { + 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") + } + } + + go updater.UpdateDeployInstanceStatusBatch(l.svcCtx, list) + + return resp, nil } diff --git a/internal/logic/inference/stopallbydeploytaskidlogic.go b/internal/logic/inference/stopallbydeploytaskidlogic.go index d1595138..14f65f58 100644 --- a/internal/logic/inference/stopallbydeploytaskidlogic.go +++ b/internal/logic/inference/stopallbydeploytaskidlogic.go @@ -2,9 +2,11 @@ package inference import ( "context" - + "errors" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/updater" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" + "strconv" "github.com/zeromicro/go-zero/core/logx" ) @@ -24,7 +26,23 @@ func NewStopAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceConte } func (l *StopAllByDeployTaskIdLogic) StopAllByDeployTaskId(req *types.StopAllByDeployTaskIdReq) (resp *types.StopAllByDeployTaskIdResp, err error) { - // todo: add your logic here and delete this line + resp = &types.StopAllByDeployTaskIdResp{} - return + 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 { + 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") + } + } + + go updater.UpdateDeployInstanceStatusBatch(l.svcCtx, list) + + return resp, nil } diff --git a/internal/scheduler/database/aiStorage.go b/internal/scheduler/database/aiStorage.go index 421bcc42..949b3b4c 100644 --- a/internal/scheduler/database/aiStorage.go +++ b/internal/scheduler/database/aiStorage.go @@ -421,6 +421,16 @@ func (s *AiStorage) GetInferDeployInstanceById(id int64) (*models.AiInferDeployI return &deployIns, nil } +func (s *AiStorage) GetInstanceListByDeployTaskId(id int64) ([]*models.AiInferDeployInstance, error) { + var list []*models.AiInferDeployInstance + tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance where `deploy_instance_task_id` = ?", id).Scan(&list) + if tx.Error != nil { + logx.Errorf(tx.Error.Error()) + return nil, tx.Error + } + return list, nil +} + func (s *AiStorage) GetInferDeployInstanceList() ([]*models.AiInferDeployInstance, error) { var list []*models.AiInferDeployInstance tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance").Scan(&list)