Browse Source

updated deployinstance logics

Former-commit-id: f8fd2a3222
pull/270/head
tzwang 1 year ago
parent
commit
ef9cbab35d
8 changed files with 94 additions and 62 deletions
  1. +7
    -11
      internal/handler/inference/deployinstancelisthandler.go
  2. +7
    -11
      internal/handler/inference/startdeployinstancelisthandler.go
  3. +7
    -11
      internal/handler/inference/stopdeployinstancehandler.go
  4. +33
    -5
      internal/logic/inference/deployinstancelistlogic.go
  5. +9
    -7
      internal/logic/inference/startdeployinstancelistlogic.go
  6. +9
    -7
      internal/logic/inference/stopdeployinstancelogic.go
  7. +21
    -10
      internal/scheduler/database/aiStorage.go
  8. +1
    -0
      internal/scheduler/service/updater/deployInstance.go

+ 7
- 11
internal/handler/inference/deployinstancelisthandler.go View File

@@ -1,28 +1,24 @@
package inference

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"
"jcc-coordinator/internal/logic/inference"
"jcc-coordinator/internal/svc"
"jcc-coordinator/internal/types"
"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 DeployInstanceListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeployInstanceListReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}

l := inference.NewDeployInstanceListLogic(r.Context(), svcCtx)
resp, err := l.DeployInstanceList(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}

+ 7
- 11
internal/handler/inference/startdeployinstancelisthandler.go View File

@@ -1,28 +1,24 @@
package inference

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"
"jcc-coordinator/internal/logic/inference"
"jcc-coordinator/internal/svc"
"jcc-coordinator/internal/types"
"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 StartDeployInstanceListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.StartDeployInstanceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}

l := inference.NewStartDeployInstanceListLogic(r.Context(), svcCtx)
resp, err := l.StartDeployInstanceList(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}

+ 7
- 11
internal/handler/inference/stopdeployinstancehandler.go View File

@@ -1,28 +1,24 @@
package inference

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"
"jcc-coordinator/internal/logic/inference"
"jcc-coordinator/internal/svc"
"jcc-coordinator/internal/types"
"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 StopDeployInstanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.StopDeployInstanceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}

l := inference.NewStopDeployInstanceLogic(r.Context(), svcCtx)
resp, err := l.StopDeployInstance(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}

+ 33
- 5
internal/logic/inference/deployinstancelistlogic.go View File

@@ -2,11 +2,11 @@ package inference

import (
"context"

"jcc-coordinator/internal/svc"
"jcc-coordinator/internal/types"

"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
)

type DeployInstanceListLogic struct {
@@ -24,7 +24,35 @@ func NewDeployInstanceListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}

func (l *DeployInstanceListLogic) DeployInstanceList(req *types.DeployInstanceListReq) (resp *types.DeployInstanceListResp, err error) {
// todo: add your logic here and delete this line
limit := req.PageSize
offset := req.PageSize * (req.PageNum - 1)
resp = &types.DeployInstanceListResp{}

var list []*models.AiInferDeployInstance

tx := l.svcCtx.DbEngin.Raw("select * from ai_infer_deploy_instance").Scan(&list)
if tx.Error != nil {
logx.Errorf(tx.Error.Error())
return nil, tx.Error
}

//count total
var total int64
err = tx.Count(&total).Error
tx.Limit(limit).Offset(offset)

if err != nil {
return resp, err
}

err = tx.Order("create_time desc").Find(&list).Error
if err != nil {
return nil, errors.New(err.Error())
}
resp.List = &list
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum
resp.Total = total

return
}

+ 9
- 7
internal/logic/inference/startdeployinstancelistlogic.go View File

@@ -2,11 +2,10 @@ package inference

import (
"context"

"jcc-coordinator/internal/svc"
"jcc-coordinator/internal/types"

"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)

type StartDeployInstanceListLogic struct {
@@ -24,7 +23,10 @@ func NewStartDeployInstanceListLogic(ctx context.Context, svcCtx *svc.ServiceCon
}

func (l *StartDeployInstanceListLogic) StartDeployInstanceList(req *types.StartDeployInstanceReq) (resp *types.StartDeployInstanceResp, err error) {
// todo: add your logic here and delete this line

return
resp = &types.StartDeployInstanceResp{}
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StartInferDeployInstance(l.ctx, req.InstanceId)
if !success {
return nil, errors.New("start instance failed")
}
return resp, nil
}

+ 9
- 7
internal/logic/inference/stopdeployinstancelogic.go View File

@@ -2,11 +2,10 @@ package inference

import (
"context"

"jcc-coordinator/internal/svc"
"jcc-coordinator/internal/types"

"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)

type StopDeployInstanceLogic struct {
@@ -24,7 +23,10 @@ func NewStopDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}

func (l *StopDeployInstanceLogic) StopDeployInstance(req *types.StopDeployInstanceReq) (resp *types.StopDeployInstanceResp, err error) {
// todo: add your logic here and delete this line

return
resp = &types.StopDeployInstanceResp{}
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StopInferDeployInstance(l.ctx, req.InstanceId)
if !success {
return nil, errors.New("stop instance failed")
}
return resp, nil
}

+ 21
- 10
internal/scheduler/database/aiStorage.go View File

@@ -373,19 +373,20 @@ func (s *AiStorage) AddNoticeInfo(adapterId string, adapterName string, clusterI
}
}

func (s *AiStorage) SaveInferDeployInstance() (int64, error) {
func (s *AiStorage) SaveInferDeployInstance(instanceId string, instanceName string, adapterId int64,
adapterName string, clusterId int64, clusterName string, modelName string, modelType string, inferCard string) (int64, error) {
startTime := time.Now().Format(time.RFC3339)
// 构建主任务结构体
insModel := models.AiInferDeployInstance{
InstanceId: "",
InstanceName: "",
AdapterId: 123,
AdapterName: "",
ClusterId: 123,
ClusterName: "",
ModelName: "",
ModelType: "",
InferCard: "",
InstanceId: instanceId,
InstanceName: instanceName,
AdapterId: adapterId,
AdapterName: adapterName,
ClusterId: clusterId,
ClusterName: clusterName,
ModelName: modelName,
ModelType: modelType,
InferCard: inferCard,
Status: constants.Saved,
CreateTime: startTime,
UpdateTime: startTime,
@@ -417,3 +418,13 @@ func (s *AiStorage) GetInferDeployInstanceById(id int64) (*models.AiInferDeployI
}
return &deployIns, nil
}

func (s *AiStorage) GetInferDeployInstanceList() ([]*models.AiInferDeployInstance, error) {
var list []*models.AiInferDeployInstance
tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance").Scan(&list)
if tx.Error != nil {
logx.Errorf(tx.Error.Error())
return nil, tx.Error
}
return list, nil
}

+ 1
- 0
internal/scheduler/service/updater/deployInstance.go View File

@@ -0,0 +1 @@
package updater

Loading…
Cancel
Save