diff --git a/api/internal/logic/hpc/commithpctasklogic.go b/api/internal/logic/hpc/commithpctasklogic.go index 13281d92..ebd6f252 100644 --- a/api/internal/logic/hpc/commithpctasklogic.go +++ b/api/internal/logic/hpc/commithpctasklogic.go @@ -8,7 +8,6 @@ import ( "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" "k8s.io/apimachinery/pkg/util/json" "math/rand" - "strconv" "time" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" @@ -51,26 +50,25 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t } var clusterIds []int64 - l.svcCtx.DbEngin.Raw("SELECT id FROM `t_cluster` where adapter_id = ? and label = ?", req.AdapterId, req.ClusterType).Scan(&clusterIds) - - adapterId, _ := strconv.ParseInt(req.AdapterId, 10, 64) - var adapterName string - l.svcCtx.DbEngin.Raw("SELECT name FROM `t_adapter` where id = ?", req.AdapterId).Scan(&adapterName) - if len(adapterName) == 0 || adapterName == "" { - return nil, errors.New("no corresponding adapter found") - } - clusterId := clusterIds[rand.Intn(len(clusterIds))] - var clusterName string - l.svcCtx.DbEngin.Raw("SELECT nickname FROM `t_cluster` where id = ?", clusterId).Scan(&clusterName) - - env, _ := json.Marshal(req.Environment) - + l.svcCtx.DbEngin.Raw("SELECT id FROM `t_cluster` where adapter_id in ? and label = ?", req.AdapterIds, req.ClusterType).Scan(&clusterIds) if len(clusterIds) == 0 || clusterIds == nil { resp.Code = 400 resp.Msg = "no cluster found" return resp, nil } + var clusterName string + var adapterId int64 + var adapterName string + clusterId := clusterIds[rand.Intn(len(clusterIds))] + l.svcCtx.DbEngin.Raw("SELECT nickname FROM `t_cluster` where id = ?", clusterId).Scan(&clusterName) + l.svcCtx.DbEngin.Raw("SELECT adapter_id FROM `t_cluster` where id = ?", clusterId).Scan(&adapterId) + l.svcCtx.DbEngin.Raw("SELECT name FROM `t_adapter` where id = ?", adapterId).Scan(&adapterName) + if len(adapterName) == 0 || adapterName == "" { + return nil, errors.New("no corresponding adapter found") + } + env, _ := json.Marshal(req.Environment) + hpcInfo := models.TaskHpc{ TaskId: taskModel.Id, AdapterId: uint(adapterId),