diff --git a/desc/inference/inference.api b/desc/inference/inference.api index b80d31aa..962b9700 100644 --- a/desc/inference/inference.api +++ b/desc/inference/inference.api @@ -176,4 +176,38 @@ type ( GetDeployTasksByTypeResp { List interface{} `json:"list"` } + + CreateDeployTaskReq { + TaskName string `form:"taskName"` + TaskDesc string `form:"taskDesc"` + ModelName string `form:"modelName"` + ModelType string `form:"modelType"` + AdapterClusterMap map[string]string `form:"adapterClusterMap"` + } + + CreateDeployTaskResp { + + } + + GetAdaptersByModelReq { + ModelName string `form:"modelName"` + ModelType string `form:"modelType"` + } + + GetAdaptersByModelResp { + Adapters []*AdapterAvail `json:"adapters"` + } + + AdapterAvail { + AdapterId string `json:"adapterId"` + AdapterName string `json:"taskName"` + Clusters []*ClusterAvail `json:"clusters"` + } + + ClusterAvail { + ClusterId string `json:"clusterId"` + ClusterName string `json:"clusterName"` + } + + ) diff --git a/desc/pcm.api b/desc/pcm.api index 9f068aa7..f075d178 100644 --- a/desc/pcm.api +++ b/desc/pcm.api @@ -971,6 +971,12 @@ service pcm { @handler GetDeployTasksByType get /inference/getDeployTasksByType (GetDeployTasksByTypeReq) returns (GetDeployTasksByTypeResp) + + @handler CreateDeployTask + get /inference/createDeployTask (CreateDeployTaskReq) returns (CreateDeployTaskResp) + + @handler GetAdaptersByModel + get /inference/getAdaptersByModel (GetAdaptersByModelReq) returns (GetAdaptersByModelResp) } @server( diff --git a/internal/handler/inference/createdeploytaskhandler.go b/internal/handler/inference/createdeploytaskhandler.go new file mode 100644 index 00000000..7fffde9d --- /dev/null +++ b/internal/handler/inference/createdeploytaskhandler.go @@ -0,0 +1,25 @@ +package inference + +import ( + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "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 { + result.ParamErrorResult(r, w, err) + return + } + + l := inference.NewCreateDeployTaskLogic(r.Context(), svcCtx) + resp, err := l.CreateDeployTask(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/internal/handler/inference/getadaptersbymodelhandler.go b/internal/handler/inference/getadaptersbymodelhandler.go new file mode 100644 index 00000000..d199313f --- /dev/null +++ b/internal/handler/inference/getadaptersbymodelhandler.go @@ -0,0 +1,25 @@ +package inference + +import ( + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "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 { + result.ParamErrorResult(r, w, err) + return + } + + l := inference.NewGetAdaptersByModelLogic(r.Context(), svcCtx) + resp, err := l.GetAdaptersByModel(&req) + result.HttpResult(r, w, resp, err) + } +} 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/deployinstancelistlogic.go b/internal/logic/inference/deployinstancelistlogic.go index 4e4c7c37..dc79c645 100644 --- a/internal/logic/inference/deployinstancelistlogic.go +++ b/internal/logic/inference/deployinstancelistlogic.go @@ -96,6 +96,7 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo deployTask := &DeployTask{ Id: t.Id, Name: t.Name, + Desc: t.Desc, Instances: list, } tasks = append(tasks, deployTask) @@ -106,5 +107,6 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo type DeployTask struct { Id int64 `json:"id,string"` Name string `json:"name,string"` + Desc string `json:"desc,string"` Instances []*models.AiInferDeployInstance `json:"instances,string"` } diff --git a/internal/logic/inference/getadaptersbymodellogic.go b/internal/logic/inference/getadaptersbymodellogic.go new file mode 100644 index 00000000..fe6a3c2b --- /dev/null +++ b/internal/logic/inference/getadaptersbymodellogic.go @@ -0,0 +1,65 @@ +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) { + resp = &types.GetAdaptersByModelResp{} + + adapterList, err := l.svcCtx.Scheduler.AiStorages.GetAdaptersByType("1") + if err != nil { + return nil, err + } + + for _, adapter := range adapterList { + var clusterAvail []*types.ClusterAvail + clusters, err := l.svcCtx.Scheduler.AiStorages.GetClustersByAdapterId(adapter.Id) + if err != nil { + return nil, err + } + + for _, cluster := range clusters.List { + exist := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[adapter.Id][cluster.Id].CheckModelExistence(l.ctx, req.ModelName, req.ModelType) + if exist { + c := &types.ClusterAvail{ + ClusterId: cluster.Id, + ClusterName: cluster.Name, + } + clusterAvail = append(clusterAvail, c) + } + } + + if len(clusterAvail) == 0 { + continue + } + + adapterAvail := &types.AdapterAvail{ + AdapterId: adapter.Id, + AdapterName: adapter.Name, + Clusters: clusterAvail, + } + + resp.Adapters = append(resp.Adapters, adapterAvail) + } + + return resp, nil +} diff --git a/internal/scheduler/service/inference/inference.go b/internal/scheduler/service/inference/inference.go index 4695ec07..95e2a058 100644 --- a/internal/scheduler/service/inference/inference.go +++ b/internal/scheduler/service/inference/inference.go @@ -18,6 +18,7 @@ type ICluster interface { StopInferDeployInstance(ctx context.Context, id string) bool GetInferDeployInstance(ctx context.Context, id string) (*DeployInstance, error) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) + CheckModelExistence(ctx context.Context, modelName string, modelType string) bool } type IInference interface { diff --git a/internal/storeLink/modelarts.go b/internal/storeLink/modelarts.go index 50f96398..d22d9ab7 100644 --- a/internal/storeLink/modelarts.go +++ b/internal/storeLink/modelarts.go @@ -543,3 +543,7 @@ func (m *ModelArtsLink) GetInferResult(ctx context.Context, url string, file mul func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) { return "", nil } + +func (m *ModelArtsLink) CheckModelExistence(ctx context.Context, name string, mtype string) bool { + return false +} diff --git a/internal/storeLink/octopus.go b/internal/storeLink/octopus.go index 0b2fc3fd..6aa7cd6f 100644 --- a/internal/storeLink/octopus.go +++ b/internal/storeLink/octopus.go @@ -1251,3 +1251,16 @@ func (o *OctopusLink) CreateInferDeployInstance(ctx context.Context, option *opt return resp.Payload.Id, nil } + +func (o *OctopusLink) CheckModelExistence(ctx context.Context, name string, mtype string) bool { + ifoption := &option.InferOption{ + ModelName: name, + ModelType: mtype, + } + err := o.generateAlgorithmId(ctx, nil, ifoption) + if err != nil { + return false + } + + return true +} diff --git a/internal/storeLink/shuguangai.go b/internal/storeLink/shuguangai.go index a756de3f..7923ef2b 100644 --- a/internal/storeLink/shuguangai.go +++ b/internal/storeLink/shuguangai.go @@ -885,3 +885,7 @@ func (s *ShuguangAi) GetInferResult(ctx context.Context, url string, file multip func (s *ShuguangAi) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) { return "", nil } + +func (s *ShuguangAi) CheckModelExistence(ctx context.Context, name string, mtype string) bool { + return false +} diff --git a/internal/types/types.go b/internal/types/types.go index 2e72d660..5af8a866 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"` +}