From 5bd7e859f9918cf3c0e165bb6b92884349d57c65 Mon Sep 17 00:00:00 2001 From: tzwang Date: Fri, 30 Aug 2024 16:31:25 +0800 Subject: [PATCH] updated getdeploytaskbytype logic Former-commit-id: 39c631187cb2a2a9da837c0e70c34ad49f9114ff --- .../inference/getdeploytasksbytypelogic.go | 36 ++++++++++++++++++- .../logic/inference/imageinferencelogic.go | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/internal/logic/inference/getdeploytasksbytypelogic.go b/internal/logic/inference/getdeploytasksbytypelogic.go index 90c96b5c..c3fbdbfc 100644 --- a/internal/logic/inference/getdeploytasksbytypelogic.go +++ b/internal/logic/inference/getdeploytasksbytypelogic.go @@ -3,6 +3,8 @@ package inference import ( "context" "github.com/pkg/errors" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" @@ -36,6 +38,38 @@ func (l *GetDeployTasksByTypeLogic) GetDeployTasksByType(req *types.GetDeployTas return nil, errors.New("实列不存在") } - resp.List = list + listcopy := make([]*models.AiDeployInstanceTask, len(list)) + copy(listcopy, list) + + for _, task := range list { + inslist, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(task.Id) + if err != nil { + return nil, err + } + if len(inslist) == 0 { + removeItem(listcopy, task.Id) + } + var count int + for _, ins := range inslist { + if ins.Status == constants.Running { + count++ + } + } + if count >= 1 { + continue + } + + removeItem(listcopy, task.Id) + } + + resp.List = listcopy return resp, nil } + +func removeItem(items []*models.AiDeployInstanceTask, id int64) { + for i := len(items) - 1; i >= 0; i-- { + if items[i].Id == id { + items = append(items[:i], items[i+1:]...) + } + } +} diff --git a/internal/logic/inference/imageinferencelogic.go b/internal/logic/inference/imageinferencelogic.go index a1a4df53..242cf265 100644 --- a/internal/logic/inference/imageinferencelogic.go +++ b/internal/logic/inference/imageinferencelogic.go @@ -136,6 +136,7 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere return nil, errors.New("clusters is nil") } + //remove empty replica for i := len(clusters) - 1; i >= 0; i-- { if clusters[i].Replicas == 0 { clusters = append(clusters[:i], clusters[i+1:]...)