forked from JointCloud/pcm-coordinator
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package inference
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"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 {
|
|
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
|
|
}
|