Merge pull request 'updated deploytask logics' (#291) from tzwang/pcm-coordinator:master into master
Former-commit-id: a8f2b46f1ca2fe87a75214107bad2774e7b558af
This commit is contained in:
commit
b0a4b9ee27
|
@ -176,4 +176,38 @@ type (
|
||||||
GetDeployTasksByTypeResp {
|
GetDeployTasksByTypeResp {
|
||||||
List interface{} `json:"list"`
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -971,6 +971,12 @@ service pcm {
|
||||||
|
|
||||||
@handler GetDeployTasksByType
|
@handler GetDeployTasksByType
|
||||||
get /inference/getDeployTasksByType (GetDeployTasksByTypeReq) returns (GetDeployTasksByTypeResp)
|
get /inference/getDeployTasksByType (GetDeployTasksByTypeReq) returns (GetDeployTasksByTypeResp)
|
||||||
|
|
||||||
|
@handler CreateDeployTask
|
||||||
|
get /inference/createDeployTask (CreateDeployTaskReq) returns (CreateDeployTaskResp)
|
||||||
|
|
||||||
|
@handler GetAdaptersByModel
|
||||||
|
get /inference/getAdaptersByModel (GetAdaptersByModelReq) returns (GetAdaptersByModelResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@server(
|
@server(
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1233,6 +1233,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/inference/getDeployTasksByType",
|
Path: "/inference/getDeployTasksByType",
|
||||||
Handler: inference.GetDeployTasksByTypeHandler(serverCtx),
|
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"),
|
rest.WithPrefix("/pcm/v1"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -96,6 +96,7 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo
|
||||||
deployTask := &DeployTask{
|
deployTask := &DeployTask{
|
||||||
Id: t.Id,
|
Id: t.Id,
|
||||||
Name: t.Name,
|
Name: t.Name,
|
||||||
|
Desc: t.Desc,
|
||||||
Instances: list,
|
Instances: list,
|
||||||
}
|
}
|
||||||
tasks = append(tasks, deployTask)
|
tasks = append(tasks, deployTask)
|
||||||
|
@ -106,5 +107,6 @@ func (l *DeployInstanceListLogic) GenerateDeployTasks(tasklist []*models.AiDeplo
|
||||||
type DeployTask struct {
|
type DeployTask struct {
|
||||||
Id int64 `json:"id,string"`
|
Id int64 `json:"id,string"`
|
||||||
Name string `json:"name,string"`
|
Name string `json:"name,string"`
|
||||||
|
Desc string `json:"desc,string"`
|
||||||
Instances []*models.AiInferDeployInstance `json:"instances,string"`
|
Instances []*models.AiInferDeployInstance `json:"instances,string"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ type ICluster interface {
|
||||||
StopInferDeployInstance(ctx context.Context, id string) bool
|
StopInferDeployInstance(ctx context.Context, id string) bool
|
||||||
GetInferDeployInstance(ctx context.Context, id string) (*DeployInstance, error)
|
GetInferDeployInstance(ctx context.Context, id string) (*DeployInstance, error)
|
||||||
CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error)
|
CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error)
|
||||||
|
CheckModelExistence(ctx context.Context, modelName string, modelType string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type IInference interface {
|
type IInference interface {
|
||||||
|
|
|
@ -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) {
|
func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ModelArtsLink) CheckModelExistence(ctx context.Context, name string, mtype string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -1251,3 +1251,16 @@ func (o *OctopusLink) CreateInferDeployInstance(ctx context.Context, option *opt
|
||||||
|
|
||||||
return resp.Payload.Id, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -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) {
|
func (s *ShuguangAi) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ShuguangAi) CheckModelExistence(ctx context.Context, name string, mtype string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -6073,3 +6073,34 @@ type GetDeployTasksByTypeReq struct {
|
||||||
type GetDeployTasksByTypeResp struct {
|
type GetDeployTasksByTypeResp struct {
|
||||||
List interface{} `json:"list"`
|
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"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue