diff --git a/internal/handler/inference/deployinstancelisthandler.go b/internal/handler/inference/deployinstancelisthandler.go index 88c8605e..0b0f8856 100644 --- a/internal/handler/inference/deployinstancelisthandler.go +++ b/internal/handler/inference/deployinstancelisthandler.go @@ -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) } } diff --git a/internal/handler/inference/startdeployinstancelisthandler.go b/internal/handler/inference/startdeployinstancelisthandler.go index 76c07974..ea6589b9 100644 --- a/internal/handler/inference/startdeployinstancelisthandler.go +++ b/internal/handler/inference/startdeployinstancelisthandler.go @@ -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) } } diff --git a/internal/handler/inference/stopdeployinstancehandler.go b/internal/handler/inference/stopdeployinstancehandler.go index 7e2bce2f..3023e36b 100644 --- a/internal/handler/inference/stopdeployinstancehandler.go +++ b/internal/handler/inference/stopdeployinstancehandler.go @@ -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) } } diff --git a/internal/logic/inference/deployinstancelistlogic.go b/internal/logic/inference/deployinstancelistlogic.go index 5697cf89..1b48055f 100644 --- a/internal/logic/inference/deployinstancelistlogic.go +++ b/internal/logic/inference/deployinstancelistlogic.go @@ -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 } diff --git a/internal/logic/inference/startdeployinstancelistlogic.go b/internal/logic/inference/startdeployinstancelistlogic.go index 3ce16a74..272568fc 100644 --- a/internal/logic/inference/startdeployinstancelistlogic.go +++ b/internal/logic/inference/startdeployinstancelistlogic.go @@ -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 } diff --git a/internal/logic/inference/stopdeployinstancelogic.go b/internal/logic/inference/stopdeployinstancelogic.go index 18496a35..00c3c128 100644 --- a/internal/logic/inference/stopdeployinstancelogic.go +++ b/internal/logic/inference/stopdeployinstancelogic.go @@ -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 } diff --git a/internal/scheduler/database/aiStorage.go b/internal/scheduler/database/aiStorage.go index d7280c95..21ef869f 100644 --- a/internal/scheduler/database/aiStorage.go +++ b/internal/scheduler/database/aiStorage.go @@ -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 +} diff --git a/internal/scheduler/service/updater/deployInstance.go b/internal/scheduler/service/updater/deployInstance.go new file mode 100644 index 00000000..3ffd3d86 --- /dev/null +++ b/internal/scheduler/service/updater/deployInstance.go @@ -0,0 +1 @@ +package updater