From 4fe189e4fa9572349c92c50d1948e6db79d8b2ed Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 26 Mar 2025 11:13:59 +0800 Subject: [PATCH 1/5] updated deployinstance status sync --- .../service/utils/status/deployInstance.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/scheduler/service/utils/status/deployInstance.go b/internal/scheduler/service/utils/status/deployInstance.go index f82e66dd..e28cae36 100644 --- a/internal/scheduler/service/utils/status/deployInstance.go +++ b/internal/scheduler/service/utils/status/deployInstance.go @@ -156,6 +156,29 @@ func UpdateDeployInstanceStatus(svc *svc.ServiceContext, instance *models.AiInfe default: instance.Status = ins.Status } + case storeLink.TYPE_OPENI: + switch ins.Status { + case "RUNNING": + if instance.Status == constants.Running { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Running + case "STOPPED": + if instance.Status == constants.Stopped { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Stopped + default: + instance.Status = ins.Status + } } err = svc.Scheduler.AiStorages.UpdateInferDeployInstance(instance, updatetime) From 1969076fb639cc199d74336e11d0dc45050b5c85 Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 26 Mar 2025 11:18:55 +0800 Subject: [PATCH 2/5] updated deployinstance status sync --- .../scheduler/service/utils/status/deployInstance.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/scheduler/service/utils/status/deployInstance.go b/internal/scheduler/service/utils/status/deployInstance.go index e28cae36..3c4f9659 100644 --- a/internal/scheduler/service/utils/status/deployInstance.go +++ b/internal/scheduler/service/utils/status/deployInstance.go @@ -17,7 +17,7 @@ func UpdateDeployInstanceStatusBatch(svc *svc.ServiceContext, insList []*models. if needfilter { for i := len(list) - 1; i >= 0; i-- { - if list[i].Status == constants.Running || list[i].Status == constants.Stopped { + if list[i].Status == constants.Running || list[i].Status == constants.Stopped || list[i].Status == constants.Failed { list = append(list[:i], list[i+1:]...) } } @@ -176,6 +176,15 @@ func UpdateDeployInstanceStatus(svc *svc.ServiceContext, instance *models.AiInfe return } instance.Status = constants.Stopped + case "CREATED_FAILED": + if instance.Status == constants.Failed { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Failed default: instance.Status = ins.Status } From 087f426b30fb4a68583eb8f149bac0b570d8bae3 Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 26 Mar 2025 15:54:06 +0800 Subject: [PATCH 3/5] added getdeployinstance api --- desc/inference/inference.api | 12 ++++++++ desc/pcm.api | 3 ++ .../inference/getdeployinstancehandler.go | 28 +++++++++++++++++ internal/handler/routes.go | 5 ++++ .../logic/inference/getdeployinstancelogic.go | 30 +++++++++++++++++++ internal/types/types.go | 11 +++++++ 6 files changed, 89 insertions(+) create mode 100644 internal/handler/inference/getdeployinstancehandler.go create mode 100644 internal/logic/inference/getdeployinstancelogic.go diff --git a/desc/inference/inference.api b/desc/inference/inference.api index 330d42d5..1b415b1e 100644 --- a/desc/inference/inference.api +++ b/desc/inference/inference.api @@ -127,6 +127,18 @@ type ( } /******************Deploy instance*************************/ + GetDeployInstanceReq{ + AdapterId string `form:"adapterId"` + ClusterId string `form:"clusterId"` + Id string `form:"id"` + InstanceId string `form:"instanceId"` + } + + GetDeployInstanceResp { + Instance interface{} `json:"instance"` + } + + DeployInstanceListReq{ PageInfo } diff --git a/desc/pcm.api b/desc/pcm.api index 31a7ebda..136e098f 100644 --- a/desc/pcm.api +++ b/desc/pcm.api @@ -960,6 +960,9 @@ service pcm { group: inference ) service pcm { + @handler GetDeployInstanceHandler + get /inference/getDeployInstance (GetDeployInstanceReq) returns (GetDeployInstanceResp) + @handler CreateInferenceTaskHandler post /inference/createTask (CreateInferenceTaskReq) returns (CreateInferenceTaskResp) diff --git a/internal/handler/inference/getdeployinstancehandler.go b/internal/handler/inference/getdeployinstancehandler.go new file mode 100644 index 00000000..4520c1da --- /dev/null +++ b/internal/handler/inference/getdeployinstancehandler.go @@ -0,0 +1,28 @@ +package inference + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" +) + +func GetDeployInstanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.GetDeployInstanceReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewGetDeployInstanceLogic(r.Context(), svcCtx) + resp, err := l.GetDeployInstance(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/routes.go b/internal/handler/routes.go index a280b9fc..b6b5f004 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -1208,6 +1208,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ + { + Method: http.MethodGet, + Path: "/inference/getDeployInstance", + Handler: inference.GetDeployInstanceHandler(serverCtx), + }, { Method: http.MethodPost, Path: "/inference/createTask", diff --git a/internal/logic/inference/getdeployinstancelogic.go b/internal/logic/inference/getdeployinstancelogic.go new file mode 100644 index 00000000..15402403 --- /dev/null +++ b/internal/logic/inference/getdeployinstancelogic.go @@ -0,0 +1,30 @@ +package inference + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetDeployInstanceLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeployInstanceLogic { + return &GetDeployInstanceLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDeployInstanceLogic) GetDeployInstance(req *types.GetDeployInstanceReq) (resp *types.GetDeployInstanceResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/types/types.go b/internal/types/types.go index b9569332..b3786d26 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -6250,6 +6250,17 @@ type TextToImageInferenceResp struct { Result []byte `json:"result"` } +type GetDeployInstanceReq struct { + AdapterId string `form:"adapterId"` + ClusterId string `form:"clusterId"` + Id string `form:"id"` + InstanceId string `form:"instanceId"` +} + +type GetDeployInstanceResp struct { + Instance interface{} `json:"instance"` +} + type DeployInstanceListReq struct { PageInfo } From 7ed4e56ecdccda53406db05596486ce9206df4c8 Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 26 Mar 2025 16:03:55 +0800 Subject: [PATCH 4/5] updated getdeployinstance logic --- .../inference/getdeployinstancehandler.go | 10 ++++------ .../logic/inference/getdeployinstancelogic.go | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/internal/handler/inference/getdeployinstancehandler.go b/internal/handler/inference/getdeployinstancehandler.go index 4520c1da..6aa14513 100644 --- a/internal/handler/inference/getdeployinstancehandler.go +++ b/internal/handler/inference/getdeployinstancehandler.go @@ -1,6 +1,7 @@ package inference import ( + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" "net/http" "github.com/zeromicro/go-zero/rest/httpx" @@ -13,16 +14,13 @@ func GetDeployInstanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.GetDeployInstanceReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.ParamErrorResult(r, w, err) return } l := inference.NewGetDeployInstanceLogic(r.Context(), svcCtx) resp, err := l.GetDeployInstance(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) + } } diff --git a/internal/logic/inference/getdeployinstancelogic.go b/internal/logic/inference/getdeployinstancelogic.go index 15402403..e084e4c2 100644 --- a/internal/logic/inference/getdeployinstancelogic.go +++ b/internal/logic/inference/getdeployinstancelogic.go @@ -2,6 +2,7 @@ package inference import ( "context" + "strconv" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" @@ -24,7 +25,20 @@ func NewGetDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) } func (l *GetDeployInstanceLogic) GetDeployInstance(req *types.GetDeployInstanceReq) (resp *types.GetDeployInstanceResp, err error) { - // todo: add your logic here and delete this line + resp = &types.GetDeployInstanceResp{} + + id, err := strconv.ParseInt(req.Id, 10, 64) + ins, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id) + if err != nil { + return nil, err + } + + 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 + } + + resp.Instance = in return } From e172479ddd971181d4c3c0f187937175adef1f20 Mon Sep 17 00:00:00 2001 From: tzwang Date: Wed, 26 Mar 2025 17:12:53 +0800 Subject: [PATCH 5/5] updated deployinstance status --- .../scheduler/service/utils/status/deployInstance.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/scheduler/service/utils/status/deployInstance.go b/internal/scheduler/service/utils/status/deployInstance.go index 3c4f9659..4faeca63 100644 --- a/internal/scheduler/service/utils/status/deployInstance.go +++ b/internal/scheduler/service/utils/status/deployInstance.go @@ -185,6 +185,15 @@ func UpdateDeployInstanceStatus(svc *svc.ServiceContext, instance *models.AiInfe return } instance.Status = constants.Failed + case "FAILED": + if instance.Status == constants.Failed { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Failed default: instance.Status = ins.Status }