diff --git a/desc/inference/inference.api b/desc/inference/inference.api index 330d42d5..1b415b1e 100644 --- a/desc/inference/inference.api +++ b/desc/inference/inference.api @@ -127,6 +127,18 @@ type ( } /******************Deploy instance*************************/ + GetDeployInstanceReq{ + AdapterId string `form:"adapterId"` + ClusterId string `form:"clusterId"` + Id string `form:"id"` + InstanceId string `form:"instanceId"` + } + + GetDeployInstanceResp { + Instance interface{} `json:"instance"` + } + + DeployInstanceListReq{ PageInfo } diff --git a/desc/pcm.api b/desc/pcm.api index 31a7ebda..136e098f 100644 --- a/desc/pcm.api +++ b/desc/pcm.api @@ -960,6 +960,9 @@ service pcm { group: inference ) service pcm { + @handler GetDeployInstanceHandler + get /inference/getDeployInstance (GetDeployInstanceReq) returns (GetDeployInstanceResp) + @handler CreateInferenceTaskHandler post /inference/createTask (CreateInferenceTaskReq) returns (CreateInferenceTaskResp) diff --git a/internal/handler/inference/getdeployinstancehandler.go b/internal/handler/inference/getdeployinstancehandler.go new file mode 100644 index 00000000..6aa14513 --- /dev/null +++ b/internal/handler/inference/getdeployinstancehandler.go @@ -0,0 +1,26 @@ +package inference + +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/inference" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" +) + +func GetDeployInstanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.GetDeployInstanceReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := inference.NewGetDeployInstanceLogic(r.Context(), svcCtx) + resp, err := l.GetDeployInstance(&req) + result.HttpResult(r, w, resp, err) + + } +} diff --git a/internal/handler/routes.go b/internal/handler/routes.go index a280b9fc..b6b5f004 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -1208,6 +1208,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ + { + Method: http.MethodGet, + Path: "/inference/getDeployInstance", + Handler: inference.GetDeployInstanceHandler(serverCtx), + }, { Method: http.MethodPost, Path: "/inference/createTask", diff --git a/internal/logic/inference/getdeployinstancelogic.go b/internal/logic/inference/getdeployinstancelogic.go new file mode 100644 index 00000000..e084e4c2 --- /dev/null +++ b/internal/logic/inference/getdeployinstancelogic.go @@ -0,0 +1,44 @@ +package inference + +import ( + "context" + "strconv" + + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetDeployInstanceLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetDeployInstanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeployInstanceLogic { + return &GetDeployInstanceLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDeployInstanceLogic) GetDeployInstance(req *types.GetDeployInstanceReq) (resp *types.GetDeployInstanceResp, err error) { + resp = &types.GetDeployInstanceResp{} + + id, err := strconv.ParseInt(req.Id, 10, 64) + ins, err := l.svcCtx.Scheduler.AiStorages.GetInferDeployInstanceById(id) + if err != nil { + return nil, err + } + + in, err := l.svcCtx.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(ins.AdapterId, 10)][strconv.FormatInt(ins.ClusterId, 10)].GetInferDeployInstance(l.ctx, ins.InstanceId) + if err != nil { + return nil, err + } + + resp.Instance = in + + return +} diff --git a/internal/scheduler/service/utils/status/deployInstance.go b/internal/scheduler/service/utils/status/deployInstance.go index f82e66dd..4faeca63 100644 --- a/internal/scheduler/service/utils/status/deployInstance.go +++ b/internal/scheduler/service/utils/status/deployInstance.go @@ -17,7 +17,7 @@ func UpdateDeployInstanceStatusBatch(svc *svc.ServiceContext, insList []*models. if needfilter { for i := len(list) - 1; i >= 0; i-- { - if list[i].Status == constants.Running || list[i].Status == constants.Stopped { + if list[i].Status == constants.Running || list[i].Status == constants.Stopped || list[i].Status == constants.Failed { list = append(list[:i], list[i+1:]...) } } @@ -156,6 +156,47 @@ func UpdateDeployInstanceStatus(svc *svc.ServiceContext, instance *models.AiInfe default: instance.Status = ins.Status } + case storeLink.TYPE_OPENI: + switch ins.Status { + case "RUNNING": + if instance.Status == constants.Running { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Running + case "STOPPED": + if instance.Status == constants.Stopped { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Stopped + case "CREATED_FAILED": + if instance.Status == constants.Failed { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Failed + case "FAILED": + if instance.Status == constants.Failed { + if ch != nil { + <-ch + return + } + return + } + instance.Status = constants.Failed + default: + instance.Status = ins.Status + } } err = svc.Scheduler.AiStorages.UpdateInferDeployInstance(instance, updatetime) diff --git a/internal/types/types.go b/internal/types/types.go index b9569332..b3786d26 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -6250,6 +6250,17 @@ type TextToImageInferenceResp struct { Result []byte `json:"result"` } +type GetDeployInstanceReq struct { + AdapterId string `form:"adapterId"` + ClusterId string `form:"clusterId"` + Id string `form:"id"` + InstanceId string `form:"instanceId"` +} + +type GetDeployInstanceResp struct { + Instance interface{} `json:"instance"` +} + type DeployInstanceListReq struct { PageInfo }