From 7aad9ecd4d5e285ceed1c1a1c74103942d0ba7d5 Mon Sep 17 00:00:00 2001 From: tzwang Date: Thu, 29 Aug 2024 10:54:33 +0800 Subject: [PATCH] added createDeployTask logics Former-commit-id: 52bab362ac9b2167969b1e6a70922ce26836dbd4 --- .../inference/createdeploytaskhandler.go | 28 +++++++++++++++++ .../inference/getadaptersbymodelhandler.go | 28 +++++++++++++++++ internal/handler/routes.go | 10 ++++++ .../logic/inference/createdeploytasklogic.go | 30 ++++++++++++++++++ .../inference/getadaptersbymodellogic.go | 30 ++++++++++++++++++ internal/types/types.go | 31 +++++++++++++++++++ 6 files changed, 157 insertions(+) create mode 100644 internal/handler/inference/createdeploytaskhandler.go create mode 100644 internal/handler/inference/getadaptersbymodelhandler.go create mode 100644 internal/logic/inference/createdeploytasklogic.go create mode 100644 internal/logic/inference/getadaptersbymodellogic.go diff --git a/internal/handler/inference/createdeploytaskhandler.go b/internal/handler/inference/createdeploytaskhandler.go new file mode 100644 index 00000000..3ed4e9d3 --- /dev/null +++ b/internal/handler/inference/createdeploytaskhandler.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 CreateDeployTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CreateDeployTaskReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewCreateDeployTaskLogic(r.Context(), svcCtx) + resp, err := l.CreateDeployTask(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/inference/getadaptersbymodelhandler.go b/internal/handler/inference/getadaptersbymodelhandler.go new file mode 100644 index 00000000..7aeabfad --- /dev/null +++ b/internal/handler/inference/getadaptersbymodelhandler.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 GetAdaptersByModelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.GetAdaptersByModelReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewGetAdaptersByModelLogic(r.Context(), svcCtx) + resp, err := l.GetAdaptersByModel(&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 0e7f6b77..ceb90566 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -1233,6 +1233,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/inference/getDeployTasksByType", Handler: inference.GetDeployTasksByTypeHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/inference/createDeployTask", + Handler: inference.CreateDeployTaskHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/inference/getAdaptersByModel", + Handler: inference.GetAdaptersByModelHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/internal/logic/inference/createdeploytasklogic.go b/internal/logic/inference/createdeploytasklogic.go new file mode 100644 index 00000000..1daa8fc5 --- /dev/null +++ b/internal/logic/inference/createdeploytasklogic.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 CreateDeployTaskLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCreateDeployTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDeployTaskLogic { + return &CreateDeployTaskLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateDeployTaskLogic) CreateDeployTask(req *types.CreateDeployTaskReq) (resp *types.CreateDeployTaskResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/logic/inference/getadaptersbymodellogic.go b/internal/logic/inference/getadaptersbymodellogic.go new file mode 100644 index 00000000..f0450fd5 --- /dev/null +++ b/internal/logic/inference/getadaptersbymodellogic.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 GetAdaptersByModelLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetAdaptersByModelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdaptersByModelLogic { + return &GetAdaptersByModelLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetAdaptersByModelLogic) GetAdaptersByModel(req *types.GetAdaptersByModelReq) (resp *types.GetAdaptersByModelResp, 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 2e72d660..438a6cce 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -6073,3 +6073,34 @@ type GetDeployTasksByTypeReq struct { type GetDeployTasksByTypeResp struct { List interface{} `json:"list"` } + +type CreateDeployTaskReq struct { + TaskName string `form:"taskName"` + TaskDesc string `form:"taskDesc"` + ModelName string `form:"modelName"` + ModelType string `form:"modelType"` + AdapterClusterMap map[string]string `form:"adapterClusterMap"` +} + +type CreateDeployTaskResp struct { +} + +type GetAdaptersByModelReq struct { + ModelName string `form:"modelName"` + ModelType string `form:"modelType"` +} + +type GetAdaptersByModelResp struct { + Adapters []AdapterAvail `json:"adapters"` +} + +type AdapterAvail struct { + AdapterId string `json:"adapterId"` + AdapterName string `json:"taskName"` + Clusters []ClusterAvail `json:"clusters"` +} + +type ClusterAvail struct { + ClusterId string `json:"clusterId"` + ClusterName string `json:"clusterName"` +}