Merge pull request 'updated deployinstance logics' (#278) from tzwang/pcm-coordinator:master into master

This commit is contained in:
tzwang 2024-07-31 11:12:37 +08:00
commit 2d1a34712b
14 changed files with 306 additions and 15 deletions

View File

@ -120,4 +120,28 @@ type (
Running int32 `json:"running"`
Total int32 `json:"total"`
}
StartAllByDeployTaskIdReq {
Id string `form:"deployTaskid"`
}
StartAllByDeployTaskIdResp {
}
StopAllByDeployTaskIdReq {
Id string `form:"deployTaskid"`
}
StopAllByDeployTaskIdResp {
}
GetDeployTasksReq {
PageInfo
}
GetDeployTasksResp {
PageResult
}
)

View File

@ -959,6 +959,15 @@ service pcm {
@handler InferenceTaskStatHandler
get /inference/taskStat (InferenceTaskStatReq) returns (InferenceTaskStatResp)
@handler StartAllByDeployTaskId
post /inference/startAll (StartAllByDeployTaskIdReq) returns (StartAllByDeployTaskIdResp)
@handler StopAllByDeployTaskId
post /inference/stopAll (StopAllByDeployTaskIdReq) returns (StopAllByDeployTaskIdResp)
@handler GetDeployTasks
get /inference/getDeployTasks (GetDeployTasksReq) returns (GetDeployTasksResp)
}
@server(

View File

@ -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 GetDeployTasksHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetDeployTasksReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := inference.NewGetDeployTasksLogic(r.Context(), svcCtx)
resp, err := l.GetDeployTasks(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -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 StartAllByDeployTaskIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.StartAllByDeployTaskIdReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := inference.NewStartAllByDeployTaskIdLogic(r.Context(), svcCtx)
resp, err := l.StartAllByDeployTaskId(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -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 StopAllByDeployTaskIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.StopAllByDeployTaskIdReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := inference.NewStopAllByDeployTaskIdLogic(r.Context(), svcCtx)
resp, err := l.StopAllByDeployTaskId(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -1213,6 +1213,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/inference/taskStat",
Handler: inference.InferenceTaskStatHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/inference/startAll",
Handler: inference.StartAllByDeployTaskIdHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/inference/stopAll",
Handler: inference.StopAllByDeployTaskIdHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/inference/getDeployTasks",
Handler: inference.GetDeployTasksHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)

View File

@ -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 GetDeployTasksLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetDeployTasksLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeployTasksLogic {
return &GetDeployTasksLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetDeployTasksLogic) GetDeployTasks(req *types.GetDeployTasksReq) (resp *types.GetDeployTasksResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -0,0 +1,47 @@
package inference
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/updater"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
)
type StartAllByDeployTaskIdLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewStartAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StartAllByDeployTaskIdLogic {
return &StartAllByDeployTaskIdLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *StartAllByDeployTaskIdLogic) StartAllByDeployTaskId(req *types.StartAllByDeployTaskIdReq) (resp *types.StartAllByDeployTaskIdResp, err error) {
resp = &types.StartAllByDeployTaskIdResp{}
id, err := strconv.ParseInt(req.Id, 10, 64)
list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(id)
if err != nil {
return nil, err
}
for _, ins := range list {
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].StartInferDeployInstance(l.ctx, ins.InstanceId)
if !success {
return nil, errors.New(ins.InstanceName + " start failed")
}
}
go updater.UpdateDeployInstanceStatusBatch(l.svcCtx, list)
return resp, nil
}

View File

@ -0,0 +1,48 @@
package inference
import (
"context"
"errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/updater"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
type StopAllByDeployTaskIdLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewStopAllByDeployTaskIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StopAllByDeployTaskIdLogic {
return &StopAllByDeployTaskIdLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *StopAllByDeployTaskIdLogic) StopAllByDeployTaskId(req *types.StopAllByDeployTaskIdReq) (resp *types.StopAllByDeployTaskIdResp, err error) {
resp = &types.StopAllByDeployTaskIdResp{}
id, err := strconv.ParseInt(req.Id, 10, 64)
list, err := l.svcCtx.Scheduler.AiStorages.GetInstanceListByDeployTaskId(id)
if err != nil {
return nil, err
}
for _, ins := range list {
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].StopInferDeployInstance(l.ctx, ins.InstanceId)
if !success {
return nil, errors.New(ins.InstanceName + " stop failed")
}
}
go updater.UpdateDeployInstanceStatusBatch(l.svcCtx, list)
return resp, nil
}

View File

@ -421,6 +421,16 @@ func (s *AiStorage) GetInferDeployInstanceById(id int64) (*models.AiInferDeployI
return &deployIns, nil
}
func (s *AiStorage) GetInstanceListByDeployTaskId(id int64) ([]*models.AiInferDeployInstance, error) {
var list []*models.AiInferDeployInstance
tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance where `deploy_instance_task_id` = ?", id).Scan(&list)
if tx.Error != nil {
logx.Errorf(tx.Error.Error())
return nil, tx.Error
}
return list, nil
}
func (s *AiStorage) GetInferDeployInstanceList() ([]*models.AiInferDeployInstance, error) {
var list []*models.AiInferDeployInstance
tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance").Scan(&list)

View File

@ -3,7 +3,7 @@ package imageInference
import "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
const (
IMAGETOTEXT = "image-to-text"
IMAGETOTEXT = "image"
IMAGETOTEXT_AiTYPE = "13"
)

View File

@ -81,6 +81,7 @@ var (
ModelTypeMap = map[string][]string{
"image_classification": {"imagenet_resnet50"},
"text_to_text": {"chatGLM_6B"},
"image_to_text": {"blip-image-captioning-base"},
}
AITYPE = map[string]string{
"1": OCTOPUS,

View File

@ -6012,3 +6012,25 @@ type InferenceTaskStatResp struct {
Running int32 `json:"running"`
Total int32 `json:"total"`
}
type StartAllByDeployTaskIdReq struct {
Id string `form:"deployTaskid"`
}
type StartAllByDeployTaskIdResp struct {
}
type StopAllByDeployTaskIdReq struct {
Id string `form:"deployTaskid"`
}
type StopAllByDeployTaskIdResp struct {
}
type GetDeployTasksReq struct {
PageInfo
}
type GetDeployTasksResp struct {
PageResult
}

View File

@ -35,20 +35,21 @@ type (
}
AiInferDeployInstance struct {
Id int64 `db:"id" json:"id,string"`
InstanceId string `db:"instance_id" json:"instanceId"`
InstanceName string `db:"instance_name" json:"instanceName"`
AdapterId int64 `db:"adapter_id" json:"adapterId,string"`
AdapterName string `db:"adapter_name" json:"adapterName" `
ClusterId int64 `db:"cluster_id" json:"clusterId,string"`
ClusterName string `db:"cluster_name" json:"clusterName"`
ModelName string `db:"model_name" json:"modelName"`
ModelType string `db:"model_type" json:"modelType"`
InferCard string `db:"infer_card" json:"inferCard"`
Status string `db:"status" json:"status"`
CreateTime string `db:"create_time" json:"createTime"`
UpdateTime string `db:"update_time" json:"updateTime"`
ClusterType string `db:"cluster_type" json:"clusterType"`
Id int64 `db:"id" json:"id,string"`
DeployInstanceTaskId int64 `db:"deploy_instance_task_id" json:"deployTaskId,string"`
InstanceId string `db:"instance_id" json:"instanceId"`
InstanceName string `db:"instance_name" json:"instanceName"`
AdapterId int64 `db:"adapter_id" json:"adapterId,string"`
AdapterName string `db:"adapter_name" json:"adapterName" `
ClusterId int64 `db:"cluster_id" json:"clusterId,string"`
ClusterName string `db:"cluster_name" json:"clusterName"`
ModelName string `db:"model_name" json:"modelName"`
ModelType string `db:"model_type" json:"modelType"`
InferCard string `db:"infer_card" json:"inferCard"`
Status string `db:"status" json:"status"`
CreateTime string `db:"create_time" json:"createTime"`
UpdateTime string `db:"update_time" json:"updateTime"`
ClusterType string `db:"cluster_type" json:"clusterType"`
}
)