From cd6d3d8b432fa6b38999d9aedf38bdc44ba5e6e1 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Tue, 12 Nov 2024 18:34:18 +0800 Subject: [PATCH] add DisplayName in jobTask, improve generate jobName Signed-off-by: Patrick Zhao --- .../repository/models/wokflow_task_v4.go | 8 +++--- .../aslan/core/common/util/workflow.go | 2 +- .../service/workflow/job/job_apollo.go | 5 ++-- .../service/workflow/job/job_approval.go | 5 ++-- .../workflow/job/job_blue_green_deploy.go | 8 +++--- .../workflow/job/job_blue_green_deploy_v2.go | 7 ++--- .../workflow/job/job_blue_green_release.go | 8 +++--- .../workflow/job/job_blue_green_release_v2.go | 8 +++--- .../service/workflow/job/job_blueking.go | 5 ++-- .../service/workflow/job/job_build.go | 7 ++--- .../service/workflow/job/job_canary_deploy.go | 8 +++--- .../workflow/job/job_canary_release.go | 8 +++--- .../service/workflow/job/job_custom_deploy.go | 7 ++--- .../service/workflow/job/job_deploy.go | 14 +++++----- .../workflow/job/job_distribute_image.go | 5 ++-- .../service/workflow/job/job_freestyle.go | 20 +++++++------- .../service/workflow/job/job_grafana.go | 5 ++-- .../service/workflow/job/job_gray_release.go | 6 ++--- .../service/workflow/job/job_gray_rollback.go | 6 ++--- .../service/workflow/job/job_guanceyun.go | 5 ++-- .../workflow/job/job_helm_chart_deploy.go | 5 ++-- .../service/workflow/job/job_istio_release.go | 4 ++- .../workflow/job/job_istio_rollback.go | 6 +++-- .../service/workflow/job/job_jenkins.go | 5 ++-- .../workflow/service/workflow/job/job_jira.go | 5 ++-- .../service/workflow/job/job_k8s_patch.go | 5 ++-- .../workflow/job/job_meego_transition.go | 5 ++-- .../workflow/job/job_mse_gray_offline.go | 5 ++-- .../workflow/job/job_mse_gray_release.go | 6 ++--- .../service/workflow/job/job_nacos.go | 5 ++-- .../service/workflow/job/job_notification.go | 5 ++-- .../workflow/job/job_offline_service.go | 7 ++--- .../service/workflow/job/job_plugin.go | 5 ++-- .../service/workflow/job/job_scanning.go | 18 ++++++++----- .../workflow/service/workflow/job/job_sql.go | 5 ++-- .../service/workflow/job/job_testing.go | 22 ++++++++------- .../job/job_update_env_istio_config.go | 4 ++- .../service/workflow/job/job_vm_deploy.go | 7 ++--- .../workflow/job/job_workflow_trigger.go | 5 ++-- .../workflow/service/workflow/job/utils.go | 27 +++++++++++++++++++ 40 files changed, 186 insertions(+), 117 deletions(-) diff --git a/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go b/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go index 518dd55769..07ef05168e 100644 --- a/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go +++ b/pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go @@ -85,10 +85,12 @@ type StageTask struct { type JobTask struct { ProjectKey string `bson:"project_key" json:"project_key"` WorkflowKey string `bson:"workflow_key" json:"workflow_key"` + // job key, used by global variable in context + Key string `bson:"key" json:"key"` + // job name, and also the job id, unique in a workflow Name string `bson:"name" json:"name"` - // jobTask unique id, unique in the workflow - Key string `bson:"key" json:"key"` - K8sJobName string `bson:"k8s_job_name" json:"k8s_job_name"` + DisplayName string `bson:"display_name" json:"display_name"` + K8sJobName string `bson:"k8s_job_name" json:"k8s_job_name"` // JobInfo contains the fields that make up the job task name, for frontend display JobInfo interface{} `bson:"job_info" json:"job_info"` JobType string `bson:"type" json:"type"` diff --git a/pkg/microservice/aslan/core/common/util/workflow.go b/pkg/microservice/aslan/core/common/util/workflow.go index 65928d868c..72512f1a53 100644 --- a/pkg/microservice/aslan/core/common/util/workflow.go +++ b/pkg/microservice/aslan/core/common/util/workflow.go @@ -34,4 +34,4 @@ func CalcWorkflowTaskRunningTime(task *commonmodels.WorkflowTask) int64 { } } return runningTime -} +} \ No newline at end of file diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go index 5d9e792dcc..c60e79c919 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_apollo.go @@ -268,11 +268,12 @@ func (j *ApolloJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { return nil, errors.New("apollo issue list is empty") } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, - Key: j.job.Name, JobType: string(config.JobApollo), Spec: &commonmodels.JobTaskApolloSpec{ ApolloID: j.spec.ApolloID, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_approval.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_approval.go index bd6d4c2227..40004b885c 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_approval.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_approval.go @@ -137,11 +137,12 @@ func (j *ApprovalJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { WorkWXApproval: j.spec.WorkWXApproval, } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, - Key: j.job.Name, JobType: string(config.JobApproval), Spec: jobSpec, Timeout: j.spec.Timeout, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy.go index 364657ac1a..752440aa0e 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "regexp" - "strings" "time" "k8s.io/apimachinery/pkg/labels" @@ -100,7 +99,7 @@ func (j *BlueGreenDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, erro return resp, err } - for _, target := range j.spec.Targets { + for jobSubTaskID, target := range j.spec.Targets { service, exist, err := getter.GetService(j.spec.Namespace, target.K8sServiceName, kubeClient) if err != nil || !exist { msg := fmt.Sprintf("Failed to get service, err: %v", err) @@ -134,8 +133,9 @@ func (j *BlueGreenDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, erro target.BlueK8sServiceName = target.K8sServiceName + config.BlueServiceNameSuffix target.BlueWorkloadName = getBlueWorkloadName(deployment.Name, version) task := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.K8sServiceName), - Key: strings.Join([]string{j.job.Name, target.K8sServiceName}, "."), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name, target.K8sServiceName), + DisplayName: genJobDisplayName(j.job.Name, target.K8sServiceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "k8s_service_name": target.K8sServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go index 94e11d7c9d..053f20d033 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_deploy_v2.go @@ -415,7 +415,7 @@ func (j *BlueGreenDeployV2Job) ToJobs(taskID int64) ([]*commonmodels.JobTask, er return resp, errors.Errorf("target services is empty") } - for _, target := range j.spec.Services { + for jobSubTaskID, target := range j.spec.Services { var ( deployment *v1.Deployment deploymentYaml string @@ -536,8 +536,9 @@ func (j *BlueGreenDeployV2Job) ToJobs(taskID int64) ([]*commonmodels.JobTask, er target.GreenDeploymentName = greenDeploymentName task := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.ServiceName), - Key: strings.Join([]string{j.job.Name, target.ServiceName}, "."), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, "service_name": target.ServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release.go index 238246e4bf..12fa172b57 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release.go @@ -18,7 +18,6 @@ package job import ( "fmt" - "strings" "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" @@ -83,13 +82,14 @@ func (j *BlueGreenReleaseJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, err if !found { return resp, fmt.Errorf("no blue-green release job: %s found, please check workflow configuration", j.spec.FromJob) } - for _, target := range deployJobSpec.Targets { + for jobSubTaskID, target := range deployJobSpec.Targets { if target.WorkloadName == "" { continue } task := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.K8sServiceName), - Key: strings.Join([]string{j.job.Name, target.K8sServiceName}, "."), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name, target.K8sServiceName), + DisplayName: genJobDisplayName(j.job.Name, target.K8sServiceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "k8s_service_name": target.K8sServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go index d5ab30ef06..bb624a0d06 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blue_green_release_v2.go @@ -18,7 +18,6 @@ package job import ( "fmt" - "strings" "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" @@ -103,10 +102,11 @@ func (j *BlueGreenReleaseV2Job) ToJobs(taskID int64) ([]*commonmodels.JobTask, e } timeout := templateProduct.Timeout * 60 - for _, target := range deployJobSpec.Services { + for jobSubTaskID, target := range deployJobSpec.Services { task := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.ServiceName), - Key: strings.Join([]string{j.job.Name, target.ServiceName}, "."), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name, target.ServiceName), + DisplayName: genJobDisplayName(j.job.Name, target.ServiceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "service_name": target.ServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go index 0a6a5ffe25..559f714a63 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_blueking.go @@ -130,12 +130,13 @@ func (j *BlueKingJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { resp := make([]*commonmodels.JobTask, 0) resp = append(resp, &commonmodels.JobTask{ - Name: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name, strconv.FormatInt(j.spec.ExecutionPlanID, 10)), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, "blueking_job_id": strconv.FormatInt(j.spec.ExecutionPlanID, 10), }, - Key: j.job.Name + "." + strconv.FormatInt(j.spec.ExecutionPlanID, 10), JobType: string(config.JobBlueKing), Spec: &commonmodels.JobTaskBlueKingSpec{ ToolID: j.spec.ToolID, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go index 8b351abaa3..2451466e43 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_build.go @@ -400,7 +400,7 @@ func (j *BuildJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } buildSvc := commonservice.NewBuildService() - for _, build := range j.spec.ServiceAndBuilds { + for i, build := range j.spec.ServiceAndBuilds { imageTag := commonservice.ReleaseCandidate(build.Repos, taskID, j.workflow.Project, build.ServiceModule, "", build.ImageName, "image") image := fmt.Sprintf("%s/%s", registry.RegAddr, imageTag) @@ -428,13 +428,14 @@ func (j *BuildJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { outputs := ensureBuildInOutputs(buildInfo.Outputs) jobTaskSpec := &commonmodels.JobTaskFreestyleSpec{} jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(build.ServiceName + "-" + build.ServiceModule + "-" + j.job.Name), JobInfo: map[string]string{ "service_name": build.ServiceName, "service_module": build.ServiceModule, JobNameKey: j.job.Name, }, - Key: strings.Join([]string{j.job.Name, build.ServiceName, build.ServiceModule}, "."), + Key: genJobKey(j.job.Name, build.ServiceName, build.ServiceModule), + Name: genJobName(j.workflow, j.job.Name, i), + DisplayName: genJobDisplayName(j.job.Name, build.ServiceName, build.ServiceModule), JobType: string(config.JobZadigBuild), Spec: jobTaskSpec, Timeout: int64(buildInfo.Timeout), diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go index 2285495bf8..57b4768569 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_deploy.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "math" - "strings" commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/util" @@ -214,7 +213,7 @@ func (j *CanaryDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) return resp, fmt.Errorf("failed to get kube client: %s, err: %v", j.spec.ClusterID, err) } - for _, target := range j.spec.Targets { + for jobSubTaskID, target := range j.spec.Targets { service, exist, err := getter.GetService(j.spec.Namespace, target.K8sServiceName, kubeClient) if err != nil || !exist { msg := fmt.Sprintf("Failed to get service, err: %v", err) @@ -248,8 +247,9 @@ func (j *CanaryDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) target.WorkloadType = setting.Deployment canaryReplica := math.Ceil(float64(*deployment.Spec.Replicas) * (float64(target.CanaryPercentage) / 100)) task := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.K8sServiceName), - Key: strings.Join([]string{j.job.Name, target.K8sServiceName}, "."), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name, target.K8sServiceName), + DisplayName: genJobDisplayName(j.job.Name, target.K8sServiceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "k8s_service_name": target.K8sServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go index d65d936175..a385247745 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_canary_release.go @@ -18,7 +18,6 @@ package job import ( "fmt" - "strings" "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" @@ -95,13 +94,14 @@ func (j *CanaryReleaseJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) if !found { return resp, fmt.Errorf("no canary release job: %s found, please check workflow configuration", j.spec.FromJob) } - for _, target := range deployJobSpec.Targets { + for jobSubTaskID, target := range deployJobSpec.Targets { if target.WorkloadName == "" { continue } task := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.K8sServiceName), - Key: strings.Join([]string{j.job.Name, target.K8sServiceName}, "."), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name, target.K8sServiceName), + DisplayName: genJobDisplayName(j.job.Name, target.K8sServiceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "k8s_service_name": target.K8sServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go index 2c0bdfe16c..f00399c800 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_custom_deploy.go @@ -185,7 +185,7 @@ func (j *CustomDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) if err := commonmodels.IToi(j.job.Spec, j.spec); err != nil { return resp, err } - for _, target := range j.spec.Targets { + for jobSubTaskID, target := range j.spec.Targets { t := strings.Split(target.Target, "/") if len(t) != 3 { log.Errorf("target string: %s wrong format", target.Target) @@ -205,8 +205,9 @@ func (j *CustomDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) SkipCheckRunStatus: j.spec.SkipCheckRunStatus, } jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + workloadType + "-" + workloadName + "-" + containerName), - Key: strings.Join([]string{j.job.Name, workloadType, workloadName, containerName}, "."), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name, workloadType, workloadName, containerName), + DisplayName: genJobDisplayName(j.job.Name, workloadType, workloadName, containerName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "workload_type": workloadType, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go index 06a905aeaf..8a9b3ec5dd 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_deploy.go @@ -855,7 +855,7 @@ func (j *DeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { timeout := templateProduct.Timeout * 60 if j.spec.DeployType == setting.K8SDeployType { - for _, svc := range j.spec.Services { + for jobSubTaskID, svc := range j.spec.Services { serviceName := svc.ServiceName jobTaskSpec := &commonmodels.JobTaskDeploySpec{ Env: envName, @@ -921,8 +921,9 @@ func (j *DeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } } jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(serviceName + "-" + j.job.Name), - Key: strings.Join([]string{j.job.Name, serviceName}, "."), + Key: genJobKey(j.job.Name, serviceName), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + DisplayName: genJobDisplayName(j.job.Name, serviceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "service_name": serviceName, @@ -992,7 +993,7 @@ func (j *DeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } if j.spec.DeployType == setting.HelmDeployType { - for _, svc := range j.spec.Services { + for jobSubTaskID, svc := range j.spec.Services { var serviceRevision int64 if pSvc, ok := productServiceMap[svc.ServiceName]; ok { serviceRevision = pSvc.Revision @@ -1035,8 +1036,9 @@ func (j *DeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { }) } jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(svc.ServiceName + "-" + j.job.Name), - Key: strings.Join([]string{j.job.Name, svc.ServiceName}, "."), + Key: genJobKey(j.job.Name, svc.ServiceName), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + DisplayName: genJobDisplayName(j.job.Name, svc.ServiceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "service_name": svc.ServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go index 0d19a1757c..863dc391bd 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_distribute_image.go @@ -322,8 +322,9 @@ func (j *ImageDistributeJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, erro }, } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go index 2b2c29aaae..f50f12d5f9 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_freestyle.go @@ -319,8 +319,8 @@ func (j *FreeStyleJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { j.spec.Services = targets } - for _, service := range j.spec.Services { - task, err := j.toJob(taskID, registries, service, logger) + for i, service := range j.spec.Services { + task, err := j.toJob(taskID, i, registries, service, logger) if err != nil { return nil, err } @@ -329,7 +329,7 @@ func (j *FreeStyleJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { return tasks, nil } else { // save user defined variables. - jobTask, err := j.toJob(taskID, registries, nil, logger) + jobTask, err := j.toJob(taskID, 0, registries, nil, logger) if err != nil { return nil, err } @@ -337,26 +337,28 @@ func (j *FreeStyleJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } } -func (j *FreeStyleJob) toJob(taskID int64, registries []*commonmodels.RegistryNamespace, service *commonmodels.FreeStyleServiceInfo, logger *zap.SugaredLogger) (*commonmodels.JobTask, error) { +func (j *FreeStyleJob) toJob(taskID int64, jobSubTaskID int, registries []*commonmodels.RegistryNamespace, service *commonmodels.FreeStyleServiceInfo, logger *zap.SugaredLogger) (*commonmodels.JobTask, error) { jobTaskSpec := &commonmodels.JobTaskFreestyleSpec{ Properties: *j.spec.Properties, Steps: j.stepsToStepTasks(j.spec.Steps, service, registries), } - jobName := j.job.Name - jobKey := j.job.Name + jobDisplayName := genJobDisplayName(j.job.Name) + jobKey := genJobKey(j.job.Name) + jobName := genJobName(j.workflow, j.job.Name, jobSubTaskID) jobInfo := map[string]string{ JobNameKey: j.job.Name, } if service != nil { - jobName = jobNameFormat(service.ServiceName + "-" + service.ServiceModule + "-" + j.job.Name) - jobKey = strings.Join([]string{j.job.Name, service.ServiceName, service.ServiceModule}, ".") + jobDisplayName = genJobDisplayName(j.job.Name, service.ServiceName, service.ServiceModule) + jobKey = genJobKey(j.job.Name, service.ServiceName, service.ServiceModule) jobInfo["service_name"] = service.ServiceName jobInfo["service_module"] = service.ServiceModule } jobTask := &commonmodels.JobTask{ - Name: jobName, Key: jobKey, + Name: jobName, + DisplayName: jobDisplayName, JobInfo: jobInfo, JobType: string(config.JobFreestyle), Spec: jobTaskSpec, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go index 1ab260700c..e21fa85be4 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_grafana.go @@ -141,11 +141,12 @@ func (j *GrafanaJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, - Key: j.job.Name, JobType: string(config.JobGrafana), Spec: &commonmodels.JobTaskGrafanaSpec{ ID: j.spec.ID, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go index 3d4efef749..9adb9ed169 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_release.go @@ -16,7 +16,6 @@ package job import ( "fmt" "math" - "strings" "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" @@ -257,8 +256,9 @@ func (j *GrayReleaseJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { for _, target := range j.spec.Targets { grayReplica := math.Ceil(float64(*&target.Replica) * (float64(j.spec.GrayScale) / 100)) jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.WorkloadName), - Key: strings.Join([]string{j.job.Name, target.WorkloadName}, "."), + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name, target.WorkloadName), + DisplayName: genJobDisplayName(j.job.Name, target.WorkloadName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "workload_name": target.WorkloadName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go index 3824a77db7..b593eb9a93 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_gray_rollback.go @@ -16,7 +16,6 @@ package job import ( "fmt" "strconv" - "strings" "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" @@ -264,8 +263,9 @@ func (j *GrayRollbackJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) return resp, fmt.Errorf("deployment %s get gray rollback info failed: %v", target.WorkloadName, err) } jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.WorkloadName), - Key: strings.Join([]string{j.job.Name, target.WorkloadName}, "."), + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name, target.WorkloadName), + DisplayName: genJobDisplayName(j.job.Name, target.WorkloadName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "workload_name": target.WorkloadName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go index b1ee69d21c..d212f44009 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_guanceyun.go @@ -92,8 +92,9 @@ func (j *GuanceyunCheckJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go index aa845be1f8..2387eeb585 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_helm_chart_deploy.go @@ -292,8 +292,9 @@ func (j *HelmChartDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, erro } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, "release_name": deploy.ReleaseName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go index f849698d9e..5883566ae6 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_release.go @@ -265,7 +265,9 @@ func (j *IstioReleaseJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) for _, target := range j.spec.Targets { newReplicaCount := math.Ceil(float64(target.CurrentReplica) * (float64(j.spec.ReplicaPercentage) / 100)) jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.WorkloadName), + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name, target.WorkloadName), + DisplayName: genJobDisplayName(j.job.Name, target.WorkloadName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "workload_name": target.WorkloadName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go index 3efb447d3b..dd91481a3d 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_istio_rollback.go @@ -192,8 +192,10 @@ func (j *IstioRollBackJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) for _, target := range j.spec.Targets { jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name + "-" + target.WorkloadName), - JobType: string(config.JobIstioRollback), + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name, target.WorkloadName), + DisplayName: genJobDisplayName(j.job.Name, target.WorkloadName), + JobType: string(config.JobIstioRollback), JobInfo: map[string]string{ JobNameKey: j.job.Name, "workload_name": target.WorkloadName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go index 2d5cbc21d8..a499fd63b0 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jenkins.go @@ -169,12 +169,13 @@ func (j *JenkinsJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } for _, job := range j.spec.Jobs { resp = append(resp, &commonmodels.JobTask{ - Name: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name, job.JobName), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, "jenkins_job_name": job.JobName, }, - Key: j.job.Name + "." + job.JobName, JobType: string(config.JobJenkins), Spec: &commonmodels.JobTaskJenkinsSpec{ ID: j.spec.ID, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go index 0678a93ab9..ce178bef6e 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_jira.go @@ -151,8 +151,9 @@ func (j *JiraJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { issue.Link = fmt.Sprintf("%s/browse/%s", info.JiraHost, issue.Key) } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go index b339fb2210..2008cfe8e3 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_k8s_patch.go @@ -230,8 +230,9 @@ func (j *K8sPacthJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { return resp, err } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go index 5a298ed8a3..d26b09e952 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_meego_transition.go @@ -134,8 +134,9 @@ func (j *MeegoTransitionJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, erro return nil, errors.New("failed to find meego integration info") } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go index a7a502e656..8666de1de4 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_offline.go @@ -88,8 +88,9 @@ func (j *MseGrayOfflineJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error } resp = append(resp, &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go index 8c624e6771..426d34d8b1 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_mse_gray_release.go @@ -18,7 +18,6 @@ package job import ( "fmt" - "strings" commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/util" @@ -201,8 +200,9 @@ func (j *MseGrayReleaseJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error return nil, errors.Errorf("service-%s: each service must contain one deployment", service.ServiceName) } resp = append(resp, &commonmodels.JobTask{ - Name: jobNameFormat(service.ServiceName + "-" + j.job.Name), - Key: strings.Join([]string{j.job.Name, service.ServiceName}, "."), + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name, service.ServiceName), + DisplayName: genJobDisplayName(j.job.Name, service.ServiceName), JobInfo: map[string]string{ JobNameKey: j.job.Name, "service_name": service.ServiceName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go index 69beb5a6c4..89525975e6 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_nacos.go @@ -296,8 +296,9 @@ func (j *NacosJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_notification.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_notification.go index c51e1125d3..9a949db9c0 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_notification.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_notification.go @@ -128,11 +128,12 @@ func (j *NotificationJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) } j.job.Spec = j.spec jobTask := &commonmodels.JobTask{ - Name: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, - Key: j.job.Name, JobType: string(config.JobNotification), Spec: &commonmodels.JobTaskNotificationSpec{ WebHookType: j.spec.WebHookType, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go index f33539abd5..260bf230b4 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_offline_service.go @@ -124,9 +124,10 @@ func (j *OfflineServiceJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error j.job.Spec = j.spec jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, - JobType: string(config.JobOfflineService), + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), + JobType: string(config.JobOfflineService), Spec: &commonmodels.JobTaskOfflineServiceSpec{ EnvType: j.spec.EnvType, EnvName: j.spec.EnvName, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go index 62301e10f9..e7d9c03f7e 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_plugin.go @@ -98,8 +98,9 @@ func (j *PluginJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { Plugin: j.spec.Plugin, } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go index e0e3525aa8..ac48491696 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_scanning.go @@ -274,7 +274,7 @@ func (j *ScanningJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { if j.spec.ScanningType == config.NormalScanningType { for _, scanning := range j.spec.Scannings { - jobTask, err := j.toJobTask(scanning, taskID, string(j.spec.ScanningType), "", "", logger) + jobTask, err := j.toJobTask(0, scanning, taskID, string(j.spec.ScanningType), "", "", logger) if err != nil { return nil, err } @@ -299,15 +299,17 @@ func (j *ScanningJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } if j.spec.ScanningType == config.ServiceScanningType { + jobSubTaskID := 0 for _, target := range j.spec.TargetServices { for _, scanning := range j.spec.ServiceAndScannings { if scanning.ServiceName != target.ServiceName || scanning.ServiceModule != target.ServiceModule { continue } - jobTask, err := j.toJobTask(&scanning.ScanningModule, taskID, string(j.spec.ScanningType), scanning.ServiceName, scanning.ServiceModule, logger) + jobTask, err := j.toJobTask(jobSubTaskID, &scanning.ScanningModule, taskID, string(j.spec.ScanningType), scanning.ServiceName, scanning.ServiceModule, logger) if err != nil { return resp, err } + jobSubTaskID++ resp = append(resp, jobTask) } } @@ -454,7 +456,7 @@ func (j *ScanningJob) GetRenderVariables(ctx *internalhandler.Context, jobName, return keyValMap.List(), nil } -func (j *ScanningJob) toJobTask(scanning *commonmodels.ScanningModule, taskID int64, scanningType, serviceName, serviceModule string, logger *zap.SugaredLogger) (*commonmodels.JobTask, error) { +func (j *ScanningJob) toJobTask(jobSubTaskID int, scanning *commonmodels.ScanningModule, taskID int64, scanningType, serviceName, serviceModule string, logger *zap.SugaredLogger) (*commonmodels.JobTask, error) { scanningInfo, err := commonrepo.NewScanningColl().Find(j.workflow.Project, scanning.Name) if err != nil { return nil, fmt.Errorf("find scanning: %s error: %v", scanning.Name, err) @@ -489,14 +491,18 @@ func (j *ScanningJob) toJobTask(scanning *commonmodels.ScanningModule, taskID in jobInfo["service_module"] = serviceModule } - jobKey := strings.Join([]string{j.job.Name, scanning.Name}, ".") + jobName := genJobName(j.workflow, j.job.Name, jobSubTaskID) + jobKey := genJobKey(j.job.Name, scanning.Name) + jobDisplayName := genJobDisplayName(j.job.Name, scanning.Name) if scanningType == string(config.ServiceScanningType) { - jobKey = strings.Join([]string{j.job.Name, scanning.Name, serviceName, serviceModule}, ".") + jobKey = genJobKey(j.job.Name, serviceName, serviceModule) + jobDisplayName = genJobDisplayName(j.job.Name, serviceName, serviceModule) } jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(strings.Join([]string{scanning.Name, j.job.Name, serviceName, serviceModule}, "-")), Key: jobKey, + Name: jobName, + DisplayName: jobDisplayName, JobInfo: jobInfo, JobType: string(config.JobZadigScanning), Spec: jobTaskSpec, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go index c80e813ffa..8d5270d3cf 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_sql.go @@ -122,11 +122,12 @@ func (j *SQLJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } j.job.Spec = j.spec jobTask := &commonmodels.JobTask{ - Name: j.job.Name, + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), + Name: genJobName(j.workflow, j.job.Name, 0), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, - Key: j.job.Name, JobType: string(config.JobSQL), Spec: &commonmodels.JobTaskSQLSpec{ ID: j.spec.ID, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go index 9d8a8a257d..c6bc4af385 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_testing.go @@ -236,7 +236,7 @@ func (j *TestingJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { if j.spec.TestType == config.ProductTestType { for _, testing := range j.spec.TestModules { - jobTask, err := j.toJobtask(testing, defaultS3, taskID, "", "", "", logger) + jobTask, err := j.toJobtask(0, testing, defaultS3, taskID, "", "", "", logger) if err != nil { return resp, err } @@ -261,15 +261,17 @@ func (j *TestingJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } if j.spec.TestType == config.ServiceTestType { + jobSubTaskID := 0 for _, target := range j.spec.TargetServices { for _, testing := range j.spec.ServiceAndTests { if testing.ServiceName != target.ServiceName || testing.ServiceModule != target.ServiceModule { continue } - jobTask, err := j.toJobtask(&testing.TestModule, defaultS3, taskID, string(j.spec.TestType), testing.ServiceName, testing.ServiceModule, logger) + jobTask, err := j.toJobtask(jobSubTaskID, &testing.TestModule, defaultS3, taskID, string(j.spec.TestType), testing.ServiceName, testing.ServiceModule, logger) if err != nil { return resp, err } + jobSubTaskID++ resp = append(resp, jobTask) } } @@ -365,7 +367,7 @@ func (j *TestingJob) getOriginReferedJobTargets(jobName string) ([]*commonmodels return nil, fmt.Errorf("TestingJob: refered job %s not found", jobName) } -func (j *TestingJob) toJobtask(testing *commonmodels.TestModule, defaultS3 *commonmodels.S3Storage, taskID int64, testType, serviceName, serviceModule string, logger *zap.SugaredLogger) (*commonmodels.JobTask, error) { +func (j *TestingJob) toJobtask(jobSubTaskID int, testing *commonmodels.TestModule, defaultS3 *commonmodels.S3Storage, taskID int64, testType, serviceName, serviceModule string, logger *zap.SugaredLogger) (*commonmodels.JobTask, error) { testingInfo, err := commonrepo.NewTestingColl().Find(testing.Name, "") if err != nil { return nil, fmt.Errorf("find testing: %s error: %v", testing.Name, err) @@ -379,7 +381,9 @@ func (j *TestingJob) toJobtask(testing *commonmodels.TestModule, defaultS3 *comm return nil, fmt.Errorf("list registries error: %v", err) } randStr := rand.String(5) - jobName := jobNameFormat(testing.Name + "-" + j.job.Name + "-" + randStr) + jobKey := genJobKey(j.job.Name, testing.Name) + jobName := genJobName(j.workflow, j.job.Name, jobSubTaskID) + jobDisplayName := genJobDisplayName(j.job.Name, testing.Name) jobInfo := map[string]string{ JobNameKey: j.job.Name, "test_type": testType, @@ -387,7 +391,8 @@ func (j *TestingJob) toJobtask(testing *commonmodels.TestModule, defaultS3 *comm "rand_str": randStr, } if testType == string(config.ServiceTestType) { - jobName = jobNameFormat(serviceName + "-" + serviceModule + "-" + j.job.Name) + jobDisplayName = genJobDisplayName(j.job.Name, serviceName, serviceModule) + jobKey = genJobKey(j.job.Name, serviceName, serviceModule) jobInfo = map[string]string{ JobNameKey: j.job.Name, "test_type": testType, @@ -396,14 +401,11 @@ func (j *TestingJob) toJobtask(testing *commonmodels.TestModule, defaultS3 *comm } } - jobKey := strings.Join([]string{j.job.Name, testing.Name}, ".") - if testType == string(config.ServiceTestType) { - jobKey = strings.Join([]string{j.job.Name, testing.Name, serviceName, serviceModule}, ".") - } jobTaskSpec := &commonmodels.JobTaskFreestyleSpec{} jobTask := &commonmodels.JobTask{ - Name: jobName, Key: jobKey, + Name: jobName, + DisplayName: jobDisplayName, JobInfo: jobInfo, JobType: string(config.JobZadigTesting), Spec: jobTaskSpec, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go index b556a44e50..796ba4f18b 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_update_env_istio_config.go @@ -87,7 +87,9 @@ func (j *UpdateEnvIstioConfigJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, } jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(j.job.Name), + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go index 536d27cd4b..0f8cf4a456 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_vm_deploy.go @@ -421,7 +421,7 @@ func (j *VMDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { } buildSvc := commonservice.NewBuildService() - for _, vmDeployInfo := range j.spec.ServiceAndVMDeploys { + for jobSubTaskID, vmDeployInfo := range j.spec.ServiceAndVMDeploys { s3Storage.Subfolder = originS3StorageSubfolder service, ok := serviceMap[vmDeployInfo.ServiceName] @@ -439,13 +439,14 @@ func (j *VMDeployJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, error) { jobTaskSpec := &commonmodels.JobTaskFreestyleSpec{} jobTask := &commonmodels.JobTask{ - Name: jobNameFormat(vmDeployInfo.ServiceName + "-" + vmDeployInfo.ServiceModule + "-" + j.job.Name), + Name: genJobName(j.workflow, j.job.Name, jobSubTaskID), + Key: genJobKey(j.job.Name, vmDeployInfo.ServiceName, vmDeployInfo.ServiceModule), + DisplayName: genJobDisplayName(j.job.Name, vmDeployInfo.ServiceName, vmDeployInfo.ServiceModule), JobInfo: map[string]string{ "service_name": vmDeployInfo.ServiceName, "service_module": vmDeployInfo.ServiceModule, JobNameKey: j.job.Name, }, - Key: strings.Join([]string{j.job.Name, vmDeployInfo.ServiceName, vmDeployInfo.ServiceModule}, "."), JobType: string(config.JobZadigVMDeploy), Spec: jobTaskSpec, Timeout: int64(buildInfo.Timeout), diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go index 60a8437b28..046d1f9eaf 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/job_workflow_trigger.go @@ -193,8 +193,9 @@ func (j *WorkflowTriggerJob) ToJobs(taskID int64) ([]*commonmodels.JobTask, erro } jobTask := &commonmodels.JobTask{ - Name: j.job.Name, - Key: j.job.Name, + Name: genJobName(j.workflow, j.job.Name, 0), + Key: genJobKey(j.job.Name), + DisplayName: genJobDisplayName(j.job.Name), JobInfo: map[string]string{ JobNameKey: j.job.Name, }, diff --git a/pkg/microservice/aslan/core/workflow/service/workflow/job/utils.go b/pkg/microservice/aslan/core/workflow/service/workflow/job/utils.go index 5947339869..1179abf98e 100644 --- a/pkg/microservice/aslan/core/workflow/service/workflow/job/utils.go +++ b/pkg/microservice/aslan/core/workflow/service/workflow/job/utils.go @@ -173,3 +173,30 @@ func (m *KeyValMap) List() []*commonmodels.KeyVal { } return ret } +func genJobDisplayName(jobName string, options ...string) string { + parts := append([]string{jobName}, options...) + return strings.Join(parts, "-") +} + +func genJobKey(jobName string, options ...string) string { + parts := append([]string{jobName}, options...) + return strings.Join(parts, ".") +} + +func genJobName(workflow *commonmodels.WorkflowV4, jobName string, subTaskID int) string { + stageName := "" + // stageIndex := 0 + // jobIndex := 0 + for i, stage := range workflow.Stages { + for j, job := range stage.Jobs { + if job.Name == jobName { + stageName = stage.Name + _ = i + _ = j + break + } + } + } + + return fmt.Sprintf("%s-%s-%d", stageName, jobName, subTaskID) +}