updated startall logics

Former-commit-id: b2d525b2fd4931508007d08404f12743f9f65e8e
This commit is contained in:
tzwang 2024-07-31 11:12:12 +08:00
parent 1ec58ac8f2
commit 179af7cd4a
3 changed files with 53 additions and 8 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)