From a6ce316c733446e60a0c80a96e41866c58cc8505 Mon Sep 17 00:00:00 2001 From: tzwang Date: Thu, 25 Jul 2024 11:13:10 +0800 Subject: [PATCH] added deployinstancestat rpcs Former-commit-id: 4fca3dba57c83b69b8a55caa1d9f49a977b8fbca --- .../handler/ai/trainingtaskstathandler.go | 21 +++++++++++++ .../inference/deployinstancestathandler.go | 28 +++++++++++++++++ .../inference/inferencetaskstathandler.go | 28 +++++++++++++++++ internal/handler/routes.go | 15 ++++++++++ internal/logic/ai/trainingtaskstatlogic.go | 30 +++++++++++++++++++ .../inference/deployinstancestatlogic.go | 30 +++++++++++++++++++ .../logic/inference/inferencetaskstatlogic.go | 30 +++++++++++++++++++ internal/types/types.go | 21 +++++++++++++ 8 files changed, 203 insertions(+) create mode 100644 internal/handler/ai/trainingtaskstathandler.go create mode 100644 internal/handler/inference/deployinstancestathandler.go create mode 100644 internal/handler/inference/inferencetaskstathandler.go create mode 100644 internal/logic/ai/trainingtaskstatlogic.go create mode 100644 internal/logic/inference/deployinstancestatlogic.go create mode 100644 internal/logic/inference/inferencetaskstatlogic.go diff --git a/internal/handler/ai/trainingtaskstathandler.go b/internal/handler/ai/trainingtaskstathandler.go new file mode 100644 index 00000000..34459d0b --- /dev/null +++ b/internal/handler/ai/trainingtaskstathandler.go @@ -0,0 +1,21 @@ +package ai + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/ai" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" +) + +func TrainingTaskStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + l := ai.NewTrainingTaskStatLogic(r.Context(), svcCtx) + resp, err := l.TrainingTaskStat() + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/inference/deployinstancestathandler.go b/internal/handler/inference/deployinstancestathandler.go new file mode 100644 index 00000000..e031c9a7 --- /dev/null +++ b/internal/handler/inference/deployinstancestathandler.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 DeployInstanceStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DeployInstanceStatReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewDeployInstanceStatLogic(r.Context(), svcCtx) + resp, err := l.DeployInstanceStat(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/inference/inferencetaskstathandler.go b/internal/handler/inference/inferencetaskstathandler.go new file mode 100644 index 00000000..8da35222 --- /dev/null +++ b/internal/handler/inference/inferencetaskstathandler.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 InferenceTaskStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.InferenceTaskStatReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewInferenceTaskStatLogic(r.Context(), svcCtx) + resp, err := l.InferenceTaskStat(&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 e6f2d564..8144516f 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -287,6 +287,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ + { + Method: http.MethodGet, + Path: "/ai/trainingTaskStat", + Handler: ai.TrainingTaskStatHandler(serverCtx), + }, { Method: http.MethodGet, Path: "/ai/getCenterOverview", @@ -1198,6 +1203,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/inference/stopDeployInstance", Handler: inference.StopDeployInstanceHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/inference/deployInstanceStat", + Handler: inference.DeployInstanceStatHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/inference/taskStat", + Handler: inference.InferenceTaskStatHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/internal/logic/ai/trainingtaskstatlogic.go b/internal/logic/ai/trainingtaskstatlogic.go new file mode 100644 index 00000000..1d59186e --- /dev/null +++ b/internal/logic/ai/trainingtaskstatlogic.go @@ -0,0 +1,30 @@ +package ai + +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 TrainingTaskStatLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewTrainingTaskStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TrainingTaskStatLogic { + return &TrainingTaskStatLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *TrainingTaskStatLogic) TrainingTaskStat() (resp *types.TrainingTaskStatResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/logic/inference/deployinstancestatlogic.go b/internal/logic/inference/deployinstancestatlogic.go new file mode 100644 index 00000000..e65ed2d0 --- /dev/null +++ b/internal/logic/inference/deployinstancestatlogic.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 DeployInstanceStatLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDeployInstanceStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeployInstanceStatLogic { + return &DeployInstanceStatLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeployInstanceStatLogic) DeployInstanceStat(req *types.DeployInstanceStatReq) (resp *types.DeployInstanceStatResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/logic/inference/inferencetaskstatlogic.go b/internal/logic/inference/inferencetaskstatlogic.go new file mode 100644 index 00000000..8f7c71f4 --- /dev/null +++ b/internal/logic/inference/inferencetaskstatlogic.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 InferenceTaskStatLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewInferenceTaskStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InferenceTaskStatLogic { + return &InferenceTaskStatLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *InferenceTaskStatLogic) InferenceTaskStat(req *types.InferenceTaskStatReq) (resp *types.InferenceTaskStatResp, 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 eafd0bc2..2dea4ea4 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -2902,6 +2902,11 @@ type AiTask struct { TimeElapsed int32 `json:"elapsed,optional"` } +type TrainingTaskStatResp struct { + Running string `json:"running"` + Total string `json:"total"` +} + type ChatReq struct { ApiUrl string `json:"apiUrl"` Method string `json:"method,optional"` @@ -5989,3 +5994,19 @@ type StopDeployInstanceReq struct { type StopDeployInstanceResp struct { } + +type DeployInstanceStatReq struct { +} + +type DeployInstanceStatResp struct { + Running string `json:"running"` + Total string `json:"total"` +} + +type InferenceTaskStatReq struct { +} + +type InferenceTaskStatResp struct { + Running string `json:"running"` + Total string `json:"total"` +}