diff --git a/internal/logic/inference/imageinferencelogic.go b/internal/logic/inference/imageinferencelogic.go index 2b26e8b9..a1a4df53 100644 --- a/internal/logic/inference/imageinferencelogic.go +++ b/internal/logic/inference/imageinferencelogic.go @@ -46,11 +46,14 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere if err != nil { return nil, err } + if instance == nil { + return nil, errors.New("instance is empty ") + } instanceList = append(instanceList, instance) } if len(instanceList) == 0 { - return nil, errors.New("instances are empty") + return nil, errors.New("instanceList are empty") } // process uploaded images @@ -110,7 +113,7 @@ func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInfere } // set strategy - if opt.Strategy != "" { + if opt.Strategy == "" { return nil, errors.New("strategy is empty") } diff --git a/internal/scheduler/database/aiStorage.go b/internal/scheduler/database/aiStorage.go index 4bf9725d..603f5719 100644 --- a/internal/scheduler/database/aiStorage.go +++ b/internal/scheduler/database/aiStorage.go @@ -413,23 +413,23 @@ func (s *AiStorage) UpdateInferDeployInstance(instance *models.AiInferDeployInst } func (s *AiStorage) GetInferDeployInstanceById(id int64) (*models.AiInferDeployInstance, error) { - var deployIns models.AiInferDeployInstance + var deployIns *models.AiInferDeployInstance tx := s.DbEngin.Raw("select * from ai_infer_deploy_instance where `id` = ?", id).Scan(&deployIns) if tx.Error != nil { logx.Errorf(tx.Error.Error()) return nil, tx.Error } - return &deployIns, nil + return deployIns, nil } func (s *AiStorage) GetDeployTaskById(id int64) (*models.AiDeployInstanceTask, error) { - var task models.AiDeployInstanceTask + var task *models.AiDeployInstanceTask tx := s.DbEngin.Raw("select * from ai_deploy_instance_task where `id` = ?", id).Scan(&task) if tx.Error != nil { logx.Errorf(tx.Error.Error()) return nil, tx.Error } - return &task, nil + return task, nil } func (s *AiStorage) GetDeployTaskListByType(modelType string) ([]*models.AiDeployInstanceTask, error) { diff --git a/internal/scheduler/service/inference/imageInference/imageInference.go b/internal/scheduler/service/inference/imageInference/imageInference.go index 101ba45f..700eb864 100644 --- a/internal/scheduler/service/inference/imageInference/imageInference.go +++ b/internal/scheduler/service/inference/imageInference/imageInference.go @@ -198,6 +198,8 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) { for _, cluster := range i.clusters { var inferurls []*inference.InferUrl var clustertype string + var clusterName string + for _, instance := range i.instances { clusterId := strconv.FormatInt(instance.ClusterId, 10) adapterId := strconv.FormatInt(instance.AdapterId, 10) @@ -214,6 +216,7 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) { inferurls = append(inferurls, &url) clustertype = deployInstance.ClusterType + clusterName = deployInstance.ClusterName } } if len(inferurls) == 0 { @@ -224,7 +227,8 @@ func (i *ImageInference) filterClusters() ([]*FilteredCluster, error) { var f FilteredCluster f.urls = inferurls - f.clusterName = cluster.ClusterName + f.clusterId = cluster.ClusterId + f.clusterName = clusterName f.clusterType = clustertype f.imageNum = cluster.Replicas cs = append(cs, &f) @@ -448,12 +452,19 @@ func (i *ImageInference) saveAiSubTasks(id int64, aiTaskList []*models.TaskAi, c } func getInferResult(url string, file multipart.File, fileName string, clusterId string, clusterType string, inferAdapter map[string]map[string]inference.ICluster, adapterId string) (string, error) { - inferMap := inferAdapter[adapterId] + adapter, found := inferAdapter[adapterId] + if !found { + return "", errors.New("adapterId not found") + } + iCluster, found := adapter[clusterId] + if !found { + return "", errors.New("clusterId not found") + } switch clusterType { case storeLink.TYPE_OCTOPUS: r := http.Request{} - result, err := inferMap[clusterId].GetInferResult(r.Context(), url, file, fileName) + result, err := iCluster.GetInferResult(r.Context(), url, file, fileName) if err != nil { return "", err } diff --git a/internal/storeLink/octopus.go b/internal/storeLink/octopus.go index 6aa7cd6f..2317ad7a 100644 --- a/internal/storeLink/octopus.go +++ b/internal/storeLink/octopus.go @@ -1158,12 +1158,21 @@ func (o *OctopusLink) GetInferDeployInstance(ctx context.Context, id string) (*i url := strings.Replace(resp.Payload.Notebook.Tasks[0].Url, FORWARD_SLASH, "", -1) inferUrl := DOMAIN + url + var card string + if resp.Payload.Notebook.Desc != "" { + str := strings.Split(resp.Payload.Notebook.Desc, FORWARD_SLASH) + if len(str) == 3 { + card = str[2] + } + } + ins.InstanceName = resp.Payload.Notebook.Name ins.InstanceId = resp.Payload.Notebook.Id ins.ClusterName = o.platform ins.Status = resp.Payload.Notebook.Status ins.ClusterType = TYPE_OCTOPUS ins.InferUrl = inferUrl + ins.InferCard = card return ins, nil }