updated deployinstance logics
Former-commit-id: f8fd2a32224a1367044bbc424dece4dd1897a975
This commit is contained in:
parent
8be2fba071
commit
ef9cbab35d
|
@ -1,28 +1,24 @@
|
||||||
package inference
|
package inference
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"jcc-coordinator/internal/logic/inference"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference"
|
||||||
"jcc-coordinator/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
"jcc-coordinator/internal/types"
|
"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 {
|
func DeployInstanceListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.DeployInstanceListReq
|
var req types.DeployInstanceListReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.ParamErrorResult(r, w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := inference.NewDeployInstanceListLogic(r.Context(), svcCtx)
|
l := inference.NewDeployInstanceListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.DeployInstanceList(&req)
|
resp, err := l.DeployInstanceList(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,24 @@
|
||||||
package inference
|
package inference
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"jcc-coordinator/internal/logic/inference"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference"
|
||||||
"jcc-coordinator/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
"jcc-coordinator/internal/types"
|
"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 {
|
func StartDeployInstanceListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.StartDeployInstanceReq
|
var req types.StartDeployInstanceReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.ParamErrorResult(r, w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := inference.NewStartDeployInstanceListLogic(r.Context(), svcCtx)
|
l := inference.NewStartDeployInstanceListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.StartDeployInstanceList(&req)
|
resp, err := l.StartDeployInstanceList(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,24 @@
|
||||||
package inference
|
package inference
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"jcc-coordinator/internal/logic/inference"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference"
|
||||||
"jcc-coordinator/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
"jcc-coordinator/internal/types"
|
"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 {
|
func StopDeployInstanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.StopDeployInstanceReq
|
var req types.StopDeployInstanceReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.ParamErrorResult(r, w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := inference.NewStopDeployInstanceLogic(r.Context(), svcCtx)
|
l := inference.NewStopDeployInstanceLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.StopDeployInstance(&req)
|
resp, err := l.StopDeployInstance(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package inference
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"jcc-coordinator/internal/svc"
|
|
||||||
"jcc-coordinator/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"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 {
|
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) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,10 @@ package inference
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"jcc-coordinator/internal/svc"
|
|
||||||
"jcc-coordinator/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"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 {
|
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) {
|
func (l *StartDeployInstanceListLogic) StartDeployInstanceList(req *types.StartDeployInstanceReq) (resp *types.StartDeployInstanceResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
resp = &types.StartDeployInstanceResp{}
|
||||||
|
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StartInferDeployInstance(l.ctx, req.InstanceId)
|
||||||
return
|
if !success {
|
||||||
|
return nil, errors.New("start instance failed")
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,10 @@ package inference
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"jcc-coordinator/internal/svc"
|
|
||||||
"jcc-coordinator/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"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 {
|
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) {
|
func (l *StopDeployInstanceLogic) StopDeployInstance(req *types.StopDeployInstanceReq) (resp *types.StopDeployInstanceResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
resp = &types.StopDeployInstanceResp{}
|
||||||
|
success := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[req.AdapterId][req.ClusterId].StopInferDeployInstance(l.ctx, req.InstanceId)
|
||||||
return
|
if !success {
|
||||||
|
return nil, errors.New("stop instance failed")
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
startTime := time.Now().Format(time.RFC3339)
|
||||||
// 构建主任务结构体
|
// 构建主任务结构体
|
||||||
insModel := models.AiInferDeployInstance{
|
insModel := models.AiInferDeployInstance{
|
||||||
InstanceId: "",
|
InstanceId: instanceId,
|
||||||
InstanceName: "",
|
InstanceName: instanceName,
|
||||||
AdapterId: 123,
|
AdapterId: adapterId,
|
||||||
AdapterName: "",
|
AdapterName: adapterName,
|
||||||
ClusterId: 123,
|
ClusterId: clusterId,
|
||||||
ClusterName: "",
|
ClusterName: clusterName,
|
||||||
ModelName: "",
|
ModelName: modelName,
|
||||||
ModelType: "",
|
ModelType: modelType,
|
||||||
InferCard: "",
|
InferCard: inferCard,
|
||||||
Status: constants.Saved,
|
Status: constants.Saved,
|
||||||
CreateTime: startTime,
|
CreateTime: startTime,
|
||||||
UpdateTime: startTime,
|
UpdateTime: startTime,
|
||||||
|
@ -417,3 +418,13 @@ func (s *AiStorage) GetInferDeployInstanceById(id int64) (*models.AiInferDeployI
|
||||||
}
|
}
|
||||||
return &deployIns, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
package updater
|
Loading…
Reference in New Issue