|
- 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 UpdateDeployInstanceStatusBatch(svc *svc.ServiceContext, insList []*models.AiInferDeployInstance) {
- list := make([]*models.AiInferDeployInstance, len(insList))
- copy(list, insList)
- for i := len(list) - 1; i >= 0; i-- {
- if list[i].Status == constants.Running || list[i].Status == constants.Stopped {
- list = append(list[:i], list[i+1:]...)
- }
- }
-
- if len(list) == 0 {
- return
- }
-
- for _, instance := range list {
- go UpdateDeployInstanceStatus(svc, instance, false)
- }
- }
-
- func UpdateDeployInstanceStatus(svc *svc.ServiceContext, instance *models.AiInferDeployInstance, updatetime bool) {
- amap, found := svc.Scheduler.AiService.InferenceAdapterMap[strconv.FormatInt(instance.AdapterId, 10)]
- if !found {
- return
- }
- cmap, found := amap[strconv.FormatInt(instance.ClusterId, 10)]
- if !found {
- return
- }
- h := http.Request{}
- ins, err := cmap.GetInferDeployInstance(h.Context(), instance.InstanceId)
- if err != nil {
- return
- }
- switch instance.ClusterType {
- case storeLink.TYPE_OCTOPUS:
- switch ins.Status {
- case "running":
- if instance.Status == constants.Running {
- return
- }
- instance.Status = constants.Running
- case "stopped":
- if instance.Status == constants.Stopped {
- return
- }
- instance.Status = constants.Stopped
- default:
- instance.Status = ins.Status
- }
- case storeLink.TYPE_MODELARTS:
- switch ins.Status {
- case "running":
- if instance.Status == constants.Running {
- return
- }
- instance.Status = constants.Running
- case "stopped":
- if instance.Status == constants.Stopped {
- return
- }
- instance.Status = constants.Stopped
- default:
- instance.Status = ins.Status
- }
- case storeLink.TYPE_SHUGUANGAI:
- switch ins.Status {
- case "Running":
- if instance.Status == constants.Running {
- return
- }
- instance.Status = constants.Running
- case "Terminated":
- if instance.Status == constants.Stopped {
- return
- }
- instance.Status = constants.Stopped
- default:
- instance.Status = ins.Status
- }
- }
-
- err = svc.Scheduler.AiStorages.UpdateInferDeployInstance(instance, updatetime)
- if err != nil {
- return
- }
- }
|