updated deployinstance logics

This commit is contained in:
tzwang 2024-07-25 17:13:10 +08:00
parent 739d039f21
commit 6ce56194e8
12 changed files with 114 additions and 38 deletions

2
go.mod
View File

@ -18,7 +18,7 @@ require (
github.com/prometheus/common v0.55.0
github.com/robfig/cron/v3 v3.0.1
github.com/zeromicro/go-zero v1.6.6
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240722032933-7bd6ab00d249
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240725071305-f751eec4dde1
gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240722092017-50d17f36d023
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240718073732-bc5d687f6330
gitlink.org.cn/JointCloud/pcm-openstack v0.0.0-20240403033338-e7edabad4203

4
go.sum
View File

@ -471,8 +471,8 @@ github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/zeromicro/go-zero v1.6.6 h1:nZTVYObklHiBdYJ/nPoAZ8kGVAplWSDjT7DGE7ur0uk=
github.com/zeromicro/go-zero v1.6.6/go.mod h1:olKf1/hELbSmuIgLgJeoeNVp3tCbLqj6UmO7ATSta4A=
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240722032933-7bd6ab00d249 h1:bHJGq5P+8w4fP62PZhIiq/fvOhvDPRtkM4pcmU8OZ1w=
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240722032933-7bd6ab00d249/go.mod h1:3eECiw9O2bIFkkePlloKyLNXiqBAhOxNrDoGaaGseGY=
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240725071305-f751eec4dde1 h1:DicBXoQiC6mumMBeyqSPNrsjtqJIgk5Pv2hscu2xryw=
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240725071305-f751eec4dde1/go.mod h1:3eECiw9O2bIFkkePlloKyLNXiqBAhOxNrDoGaaGseGY=
gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240722092017-50d17f36d023 h1:9DNobl0gvRCSXtjyMsfUwq0w0TMvds4rqNRsEqeX4j8=
gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240722092017-50d17f36d023/go.mod h1:/eOmBFZKWGoabG3sRVkVvIbLwsd2631k4jkUBR6x1AA=
gitlink.org.cn/JointCloud/pcm-octopus v0.0.0-20240718073732-bc5d687f6330 h1:WxPrFSO6LjDCr+k7nmNFlPst8CtoTHQ2iSjv+D2rNnM=

View File

@ -1,9 +1,9 @@
package ai
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/ai"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)
@ -12,10 +12,6 @@ func TrainingTaskStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := ai.NewTrainingTaskStatLogic(r.Context(), svcCtx)
resp, err := l.TrainingTaskStat()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,6 +1,7 @@
package inference
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
@ -13,16 +14,13 @@ func DeployInstanceStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeployInstanceStatReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
l := inference.NewDeployInstanceStatLogic(r.Context(), svcCtx)
resp, err := l.DeployInstanceStat(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1,28 +1,25 @@
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"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func InferenceTaskStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.InferenceTaskStatReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
l := inference.NewInferenceTaskStatLogic(r.Context(), svcCtx)
resp, err := l.InferenceTaskStat(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}

View File

@ -2,6 +2,7 @@ package ai
import (
"context"
"errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -24,7 +25,23 @@ func NewTrainingTaskStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *TrainingTaskStatLogic) TrainingTaskStat() (resp *types.TrainingTaskStatResp, err error) {
// todo: add your logic here and delete this line
resp = &types.TrainingTaskStatResp{}
return
total, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetTrainingTaskRunningNum()
if err != nil {
return nil, err
}
if total == 0 {
return nil, errors.New("get statistics failed")
}
resp.Total = total
resp.Running = running
return resp, nil
}

View File

@ -2,6 +2,7 @@ package inference
import (
"context"
"errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -24,7 +25,23 @@ func NewDeployInstanceStatLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *DeployInstanceStatLogic) DeployInstanceStat(req *types.DeployInstanceStatReq) (resp *types.DeployInstanceStatResp, err error) {
// todo: add your logic here and delete this line
resp = &types.DeployInstanceStatResp{}
return
total, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceRunningNum()
if err != nil {
return nil, err
}
if total == 0 {
return nil, errors.New("get statistics failed")
}
resp.Total = total
resp.Running = running
return resp, nil
}

View File

@ -2,6 +2,7 @@ package inference
import (
"context"
"errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -24,7 +25,23 @@ func NewInferenceTaskStatLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *InferenceTaskStatLogic) InferenceTaskStat(req *types.InferenceTaskStatReq) (resp *types.InferenceTaskStatResp, err error) {
// todo: add your logic here and delete this line
resp = &types.InferenceTaskStatResp{}
return
total, err := l.svcCtx.Scheduler.AiStorages.GetInferenceTaskTotalNum()
if err != nil {
return nil, err
}
running, err := l.svcCtx.Scheduler.AiStorages.GetInferenceTaskRunningNum()
if err != nil {
return nil, err
}
if total == 0 {
return nil, errors.New("get statistics failed")
}
resp.Total = total
resp.Running = running
return resp, nil
}

View File

@ -6,6 +6,7 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
)
type StartDeployInstanceListLogic struct {
@ -25,8 +26,17 @@ func NewStartDeployInstanceListLogic(ctx context.Context, svcCtx *svc.ServiceCon
func (l *StartDeployInstanceListLogic) StartDeployInstanceList(req *types.StartDeployInstanceReq) (resp *types.StartDeployInstanceResp, err error) {
resp = &types.StartDeployInstanceResp{}
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StartInferDeployInstance(l.ctx, req.InstanceId)
id, err := strconv.ParseInt(req.Id, 10, 64)
ins, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id)
if err != nil {
return nil, err
}
l.svcCtx.Scheduler.AiStorages.UpdateInferDeployInstance(ins)
if !success {
return nil, errors.New("start instance failed")
}
return resp, nil
}

View File

@ -6,6 +6,7 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"strconv"
)
type StopDeployInstanceLogic struct {
@ -25,6 +26,14 @@ func NewStopDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext)
func (l *StopDeployInstanceLogic) StopDeployInstance(req *types.StopDeployInstanceReq) (resp *types.StopDeployInstanceResp, err error) {
resp = &types.StopDeployInstanceResp{}
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StopInferDeployInstance(l.ctx, req.InstanceId)
id, err := strconv.ParseInt(req.Id, 10, 64)
ins, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id)
if err != nil {
return nil, err
}
l.svcCtx.Scheduler.AiStorages.UpdateInferDeployInstance(ins)
if !success {
return nil, errors.New("stop instance failed")
}

View File

@ -1,16 +1,14 @@
package updater
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/storeLink"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"net/http"
"strconv"
)
//func UpdateDeployInstanceStatus(svc *svc.ServiceContext, list []*models.AiInferDeployInstance) {
//
//}
func UpdateDeployInstanceStatus(svc *svc.ServiceContext, instance *models.AiInferDeployInstance) {
amap, found := svc.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(instance.AdapterId, 10)]
if !found {
@ -25,13 +23,29 @@ func UpdateDeployInstanceStatus(svc *svc.ServiceContext, instance *models.AiInfe
if err != nil {
return
}
instance.Status = ins.Status
switch instance.ClusterType {
case storeLink.TYPE_OCTOPUS:
switch ins.Status {
case "running":
instance.Status = constants.Running
case "stopped":
instance.Status = constants.Stopped
default:
instance.Status = ins.Status
}
case storeLink.TYPE_SHUGUANGAI:
switch ins.Status {
case "running":
instance.Status = constants.Running
case "Terminated":
instance.Status = constants.Stopped
default:
instance.Status = ins.Status
}
}
err = svc.Scheduler.AiStorages.UpdateInferDeployInstance(instance)
if err != nil {
return
}
}
func UpdateDeployInstanceStatusByClusterId(svc *svc.ServiceContext, list []*models.AiInferDeployInstance) {
}

View File

@ -48,6 +48,7 @@ type (
Status string `db:"status"`
CreateTime string `db:"create_time"`
UpdateTime string `db:"update_time"`
ClusterType string `db:"cluster_type"`
}
)