forked from JointCloud/pcm-coordinator
Merge pull request 'updated createdeployinstance logics' (#292) from tzwang/pcm-coordinator:master into master
Former-commit-id: 3080046eb7
This commit is contained in:
commit
9ec43307d7
|
@ -182,7 +182,7 @@ type (
|
||||||
TaskDesc string `form:"taskDesc"`
|
TaskDesc string `form:"taskDesc"`
|
||||||
ModelName string `form:"modelName"`
|
ModelName string `form:"modelName"`
|
||||||
ModelType string `form:"modelType"`
|
ModelType string `form:"modelType"`
|
||||||
AdapterClusterMap map[string]string `form:"adapterClusterMap"`
|
AdapterClusterMap map[string][]string `form:"adapterClusterMap"`
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateDeployTaskResp {
|
CreateDeployTaskResp {
|
||||||
|
|
|
@ -973,7 +973,7 @@ service pcm {
|
||||||
get /inference/getDeployTasksByType (GetDeployTasksByTypeReq) returns (GetDeployTasksByTypeResp)
|
get /inference/getDeployTasksByType (GetDeployTasksByTypeReq) returns (GetDeployTasksByTypeResp)
|
||||||
|
|
||||||
@handler CreateDeployTask
|
@handler CreateDeployTask
|
||||||
get /inference/createDeployTask (CreateDeployTaskReq) returns (CreateDeployTaskResp)
|
post /inference/createDeployTask (CreateDeployTaskReq) returns (CreateDeployTaskResp)
|
||||||
|
|
||||||
@handler GetAdaptersByModel
|
@handler GetAdaptersByModel
|
||||||
get /inference/getAdaptersByModel (GetAdaptersByModelReq) returns (GetAdaptersByModelResp)
|
get /inference/getAdaptersByModel (GetAdaptersByModelReq) returns (GetAdaptersByModelResp)
|
||||||
|
|
|
@ -1234,7 +1234,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Handler: inference.GetDeployTasksByTypeHandler(serverCtx),
|
Handler: inference.GetDeployTasksByTypeHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodPost,
|
||||||
Path: "/inference/createDeployTask",
|
Path: "/inference/createDeployTask",
|
||||||
Handler: inference.CreateDeployTaskHandler(serverCtx),
|
Handler: inference.CreateDeployTaskHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,9 @@ package inference
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||||
|
@ -24,7 +27,78 @@ func NewCreateDeployTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *CreateDeployTaskLogic) CreateDeployTask(req *types.CreateDeployTaskReq) (resp *types.CreateDeployTaskResp, err error) {
|
func (l *CreateDeployTaskLogic) CreateDeployTask(req *types.CreateDeployTaskReq) (resp *types.CreateDeployTaskResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
resp = &types.CreateDeployTaskResp{}
|
||||||
|
|
||||||
|
if len(req.AdapterClusterMap) == 0 {
|
||||||
|
return nil, errors.New("adapters are empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := &option.InferOption{
|
||||||
|
TaskName: req.TaskName,
|
||||||
|
ModelType: req.ModelType,
|
||||||
|
ModelName: req.ModelName,
|
||||||
|
Cmd: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
taskId, err := l.svcCtx.Scheduler.AiStorages.SaveInferDeployTask(req.TaskName, req.ModelName, req.ModelType, req.TaskDesc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for aid, v := range req.AdapterClusterMap {
|
||||||
|
for _, cid := range v {
|
||||||
|
err = l.createDeployInstance(taskId, aid, cid, opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *CreateDeployTaskLogic) createDeployInstance(taskId int64, adapterId string, clusterId string, opt *option.InferOption) error {
|
||||||
|
cmap, found := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[adapterId]
|
||||||
|
if !found {
|
||||||
|
return errors.New("adapterId not exist: " + adapterId)
|
||||||
|
}
|
||||||
|
iCluster, found := cmap[clusterId]
|
||||||
|
if !found {
|
||||||
|
return errors.New("clusterId not exist: " + clusterId)
|
||||||
|
}
|
||||||
|
insId, err := iCluster.CreateInferDeployInstance(l.ctx, opt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
aid, err := strconv.ParseInt(adapterId, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cid, err := strconv.ParseInt(clusterId, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
adapterName, err := l.svcCtx.Scheduler.AiStorages.GetAdapterNameById(adapterId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
clusterName, err := l.svcCtx.Scheduler.AiStorages.GetClusterNameById(clusterId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ins, err := iCluster.GetInferDeployInstance(l.ctx, insId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = l.svcCtx.Scheduler.AiStorages.SaveInferDeployInstance(taskId, ins.InstanceId, ins.InstanceName, aid, adapterName, cid, clusterName, ins.ModelName, ins.ModelType, ins.InferCard)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -373,23 +373,24 @@ func (s *AiStorage) AddNoticeInfo(adapterId string, adapterName string, clusterI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AiStorage) SaveInferDeployInstance(instanceId string, instanceName string, adapterId int64,
|
func (s *AiStorage) SaveInferDeployInstance(taskId int64, instanceId string, instanceName string, adapterId int64,
|
||||||
adapterName string, clusterId int64, clusterName string, modelName string, modelType string, inferCard string) (int64, error) {
|
adapterName string, clusterId int64, clusterName string, modelName string, modelType string, inferCard string) (int64, error) {
|
||||||
startTime := time.Now().Format(time.RFC3339)
|
startTime := time.Now().Format(time.RFC3339)
|
||||||
// 构建主任务结构体
|
// 构建主任务结构体
|
||||||
insModel := models.AiInferDeployInstance{
|
insModel := models.AiInferDeployInstance{
|
||||||
InstanceId: instanceId,
|
DeployInstanceTaskId: taskId,
|
||||||
InstanceName: instanceName,
|
InstanceId: instanceId,
|
||||||
AdapterId: adapterId,
|
InstanceName: instanceName,
|
||||||
AdapterName: adapterName,
|
AdapterId: adapterId,
|
||||||
ClusterId: clusterId,
|
AdapterName: adapterName,
|
||||||
ClusterName: clusterName,
|
ClusterId: clusterId,
|
||||||
ModelName: modelName,
|
ClusterName: clusterName,
|
||||||
ModelType: modelType,
|
ModelName: modelName,
|
||||||
InferCard: inferCard,
|
ModelType: modelType,
|
||||||
Status: constants.Saved,
|
InferCard: inferCard,
|
||||||
CreateTime: startTime,
|
Status: constants.Stopped,
|
||||||
UpdateTime: startTime,
|
CreateTime: startTime,
|
||||||
|
UpdateTime: startTime,
|
||||||
}
|
}
|
||||||
// 保存任务数据到数据库
|
// 保存任务数据到数据库
|
||||||
tx := s.DbEngin.Table("ai_infer_deploy_instance").Create(&insModel)
|
tx := s.DbEngin.Table("ai_infer_deploy_instance").Create(&insModel)
|
||||||
|
|
|
@ -6075,11 +6075,11 @@ type GetDeployTasksByTypeResp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateDeployTaskReq struct {
|
type CreateDeployTaskReq struct {
|
||||||
TaskName string `form:"taskName"`
|
TaskName string `form:"taskName"`
|
||||||
TaskDesc string `form:"taskDesc"`
|
TaskDesc string `form:"taskDesc"`
|
||||||
ModelName string `form:"modelName"`
|
ModelName string `form:"modelName"`
|
||||||
ModelType string `form:"modelType"`
|
ModelType string `form:"modelType"`
|
||||||
AdapterClusterMap map[string]string `form:"adapterClusterMap"`
|
AdapterClusterMap map[string][]string `form:"adapterClusterMap"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateDeployTaskResp struct {
|
type CreateDeployTaskResp struct {
|
||||||
|
|
Loading…
Reference in New Issue