From 79cb707b57931151b71e3456b99f8b92416d18bf Mon Sep 17 00:00:00 2001 From: Kerwin <37063904+zhuangchong@users.noreply.github.com> Date: Tue, 18 Apr 2023 14:56:38 +0800 Subject: [PATCH] [Improvement-13932][API] Tenant parameters and Worker group parameters are put together in the task startup parameters (#13935) * [Improvement][API] Tenant parameters and Worker group parameters are put together in the task startup parameters --- .../api/controller/ExecutorController.java | 15 ++- .../ProcessDefinitionController.java | 16 +-- .../api/controller/SchedulerController.java | 17 ++- .../dto/schedule/ScheduleCreateRequest.java | 4 + .../dto/workflow/WorkflowCreateRequest.java | 4 - .../dto/workflow/WorkflowUpdateRequest.java | 6 - .../dolphinscheduler/api/enums/Status.java | 2 +- .../api/python/PythonGateway.java | 11 +- .../api/service/ExecutorService.java | 9 +- .../api/service/ProcessDefinitionService.java | 8 -- .../api/service/SchedulerService.java | 6 + .../api/service/impl/ExecutorServiceImpl.java | 34 +++++- .../impl/ProcessDefinitionServiceImpl.java | 105 +++--------------- .../impl/ProcessInstanceServiceImpl.java | 18 +-- .../service/impl/SchedulerServiceImpl.java | 47 +++++++- .../api/service/impl/TenantServiceImpl.java | 22 ++-- .../dolphinscheduler/api/vo/ScheduleVo.java | 6 + .../ExecuteFunctionControllerTest.java | 15 ++- .../ProcessDefinitionControllerTest.java | 10 +- .../controller/SchedulerControllerTest.java | 6 +- .../v2/WorkflowV2ControllerTest.java | 3 - .../service/ExecuteFunctionServiceTest.java | 40 ++++--- .../service/ProcessDefinitionServiceTest.java | 28 +---- .../service/ProcessInstanceServiceTest.java | 4 +- .../ProcessTaskRelationServiceTest.java | 1 - .../api/service/SchedulerServiceTest.java | 6 + .../api/service/TenantServiceTest.java | 28 +++-- .../dolphinscheduler/dao/entity/Command.java | 5 + .../dao/entity/ErrorCommand.java | 5 + .../dao/entity/ProcessDefinition.java | 20 +--- .../dao/entity/ProcessDefinitionLog.java | 1 - .../dao/entity/ProcessInstance.java | 2 - .../dolphinscheduler/dao/entity/Schedule.java | 5 + .../dao/mapper/ProcessDefinitionMapper.java | 8 -- .../dao/mapper/ProcessInstanceMapper.java | 18 +-- .../dao/mapper/ScheduleMapper.java | 8 ++ .../dao/upgrade/JsonSplitDao.java | 20 ++-- .../dao/mapper/ProcessDefinitionLogMapper.xml | 4 +- .../dao/mapper/ProcessDefinitionMapper.xml | 18 +-- .../dao/mapper/ProcessInstanceMapper.xml | 16 +-- .../dao/mapper/ScheduleMapper.xml | 13 ++- .../resources/sql/dolphinscheduler_h2.sql | 8 +- .../resources/sql/dolphinscheduler_mysql.sql | 8 +- .../sql/dolphinscheduler_postgresql.sql | 8 +- .../mysql/dolphinscheduler_ddl.sql | 36 +++++- .../mysql/dolphinscheduler_ddl_post.sql | 20 ++++ .../mysql/dolphinscheduler_dml.sql | 6 +- .../postgresql/dolphinscheduler_ddl.sql | 39 ++++++- .../postgresql/dolphinscheduler_ddl_post.sql | 20 ++++ .../postgresql/dolphinscheduler_dml.sql | 6 +- .../mapper/ProcessDefinitionMapperTest.java | 21 ---- .../e2e/cases/WorkflowE2ETest.java | 2 - .../e2e/cases/WorkflowSwitchE2ETest.java | 1 - .../project/workflow/WorkflowSaveDialog.java | 23 ---- .../runner/StreamTaskExecuteRunnable.java | 7 +- .../master/runner/task/BaseTaskProcessor.java | 4 +- .../TaskPriorityQueueConsumerTest.java | 22 ++-- .../runner/task/CommonTaskProcessorTest.java | 2 +- .../command/task/TaskExecuteStartMessage.java | 2 +- .../scheduler/quartz/ProcessScheduleTask.java | 1 + .../service/process/ProcessService.java | 3 +- .../service/process/ProcessServiceImpl.java | 35 +++--- .../v200/V200DolphinSchedulerUpgrader.java | 2 - .../v320/V320DolphinSchedulerUpgrader.java | 24 ++-- .../src/locales/en_US/project.ts | 3 +- .../src/locales/zh_CN/project.ts | 3 +- .../modules/process-definition/types.ts | 1 - .../modules/process-instances/types.ts | 1 - .../definition/components/start-modal.tsx | 8 ++ .../task/definition/components/use-start.tsx | 13 +++ .../views/projects/task/definition/types.ts | 1 + .../components/dag/dag-save-modal.tsx | 35 ------ .../components/dag/dag-startup-param.tsx | 5 + .../projects/workflow/components/dag/types.ts | 3 +- .../definition/components/start-modal.tsx | 38 +++++-- .../definition/components/timing-modal.tsx | 36 ++++-- .../workflow/definition/components/types.ts | 1 + .../definition/components/use-form.ts | 2 + .../definition/components/use-modal.ts | 13 +++ .../workflow/definition/create/index.tsx | 1 - .../workflow/definition/detail/index.tsx | 1 - .../workflow/definition/timing/use-table.ts | 5 + .../workflow/instance/detail/index.tsx | 1 - 83 files changed, 589 insertions(+), 496 deletions(-) create mode 100644 dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl_post.sql create mode 100644 dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl_post.sql diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java index 4f474821a7..e8cc4327bc 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java @@ -116,6 +116,7 @@ public class ExecutorController extends BaseController { @Parameter(name = "runMode", description = "RUN_MODE", schema = @Schema(implementation = RunMode.class)), @Parameter(name = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", required = true, schema = @Schema(implementation = Priority.class)), @Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), + @Parameter(name = "tenantCode", description = "TENANT_CODE", schema = @Schema(implementation = String.class, example = "default")), @Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = Long.class, example = "-1")), @Parameter(name = "timeout", description = "TIMEOUT", schema = @Schema(implementation = int.class, example = "100")), @Parameter(name = "expectedParallelismNumber", description = "EXPECTED_PARALLELISM_NUMBER", schema = @Schema(implementation = int.class, example = "8")), @@ -140,6 +141,7 @@ public class ExecutorController extends BaseController { @RequestParam(value = "runMode", required = false) RunMode runMode, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, + @RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode, @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "timeout", required = false) Integer timeout, @RequestParam(value = "startParams", required = false) String startParams, @@ -164,7 +166,8 @@ public class ExecutorController extends BaseController { Map result = execService.execProcessInstance(loginUser, projectCode, processDefinitionCode, scheduleTime, execType, failureStrategy, startNodeList, taskDependType, warningType, warningGroupId, runMode, processInstancePriority, - workerGroup, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun, testFlag, + workerGroup, tenantCode, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun, + testFlag, complementDependentMode, version); return returnDataList(result); } @@ -187,6 +190,7 @@ public class ExecutorController extends BaseController { * @param runMode run mode * @param processInstancePriority process instance priority * @param workerGroup worker group + * @param tenantCode tenant code * @param timeout timeout * @param expectedParallelismNumber the expected parallelism number when execute complement in parallel mode * @param testFlag testFlag @@ -205,6 +209,7 @@ public class ExecutorController extends BaseController { @Parameter(name = "runMode", description = "RUN_MODE", schema = @Schema(implementation = RunMode.class)), @Parameter(name = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", required = true, schema = @Schema(implementation = Priority.class)), @Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), + @Parameter(name = "tenantCode", description = "TENANT_CODE", schema = @Schema(implementation = String.class, example = "default")), @Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = Long.class, example = "-1")), @Parameter(name = "timeout", description = "TIMEOUT", schema = @Schema(implementation = int.class, example = "100")), @Parameter(name = "expectedParallelismNumber", description = "EXPECTED_PARALLELISM_NUMBER", schema = @Schema(implementation = int.class, example = "8")), @@ -229,6 +234,7 @@ public class ExecutorController extends BaseController { @RequestParam(value = "runMode", required = false) RunMode runMode, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, + @RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode, @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "timeout", required = false) Integer timeout, @RequestParam(value = "startParams", required = false) String startParams, @@ -263,7 +269,8 @@ public class ExecutorController extends BaseController { result = execService.execProcessInstance(loginUser, projectCode, processDefinitionCode, scheduleTime, execType, failureStrategy, startNodeList, taskDependType, warningType, warningGroupId, runMode, processInstancePriority, - workerGroup, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun, testFlag, + workerGroup, tenantCode, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun, + testFlag, complementDependentMode, null); if (!Status.SUCCESS.equals(result.get(Constants.STATUS))) { @@ -419,6 +426,7 @@ public class ExecutorController extends BaseController { @Parameter(name = "warningType", description = "WARNING_TYPE", required = true, schema = @Schema(implementation = WarningType.class)), @Parameter(name = "warningGroupId", description = "WARNING_GROUP_ID", schema = @Schema(implementation = int.class, example = "100")), @Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), + @Parameter(name = "tenantCode", description = "TENANT_CODE", schema = @Schema(implementation = String.class, example = "default")), @Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = long.class, example = "-1")), @Parameter(name = "timeout", description = "TIMEOUT", schema = @Schema(implementation = int.class, example = "100")), @Parameter(name = "dryRun", description = "DRY_RUN", schema = @Schema(implementation = int.class, example = "0")), @@ -433,6 +441,7 @@ public class ExecutorController extends BaseController { @RequestParam(value = "version", required = true) int version, @RequestParam(value = "warningGroupId", required = false, defaultValue = "0") Integer warningGroupId, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, + @RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode, @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "startParams", required = false) String startParams, @RequestParam(value = "dryRun", defaultValue = "0", required = false) int dryRun) { @@ -445,7 +454,7 @@ public class ExecutorController extends BaseController { log.info("Start to execute stream task instance, projectCode:{}, taskDefinitionCode:{}, taskVersion:{}.", projectCode, code, version); Map result = execService.execStreamTaskInstance(loginUser, projectCode, code, version, - warningGroupId, workerGroup, environmentCode, startParamMap, dryRun); + warningGroupId, workerGroup, tenantCode, environmentCode, startParamMap, dryRun); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java index 4e3a5a7a06..b8dacde82b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java @@ -98,7 +98,6 @@ public class ProcessDefinitionController extends BaseController { * @param globalParams globalParams * @param locations locations for nodes * @param timeout timeout - * @param tenantCode tenantCode * @param taskRelationJson relation json for nodes * @param taskDefinitionJson taskDefinitionJson * @param otherParamsJson otherParamsJson handle other params @@ -122,14 +121,13 @@ public class ProcessDefinitionController extends BaseController { @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, - @RequestParam(value = "tenantCode", required = true) String tenantCode, @RequestParam(value = "taskRelationJson", required = true) String taskRelationJson, @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson, @RequestParam(value = "otherParamsJson", required = false) String otherParamsJson, @RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType) { Map result = processDefinitionService.createProcessDefinition(loginUser, projectCode, name, description, globalParams, - locations, timeout, tenantCode, taskRelationJson, taskDefinitionJson, otherParamsJson, executionType); + locations, timeout, taskRelationJson, taskDefinitionJson, otherParamsJson, executionType); return returnDataList(result); } @@ -222,7 +220,6 @@ public class ProcessDefinitionController extends BaseController { * @param globalParams globalParams * @param locations locations for nodes * @param timeout timeout - * @param tenantCode tenantCode * @param taskRelationJson relation json for nodes * @param taskDefinitionJson taskDefinitionJson * @param otherParamsJson otherParamsJson handle other params @@ -249,7 +246,6 @@ public class ProcessDefinitionController extends BaseController { @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, - @RequestParam(value = "tenantCode", required = true) String tenantCode, @RequestParam(value = "taskRelationJson", required = true) String taskRelationJson, @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson, @RequestParam(value = "otherParamsJson", required = false) String otherParamsJson, @@ -258,7 +254,7 @@ public class ProcessDefinitionController extends BaseController { Map result = processDefinitionService.updateProcessDefinition(loginUser, projectCode, name, code, description, globalParams, - locations, timeout, tenantCode, taskRelationJson, taskDefinitionJson, otherParamsJson, executionType); + locations, timeout, taskRelationJson, taskDefinitionJson, otherParamsJson, executionType); // If the update fails, the result will be returned directly if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataList(result); @@ -754,7 +750,6 @@ public class ProcessDefinitionController extends BaseController { * @param description description * @param globalParams globalParams * @param timeout timeout - * @param tenantCode tenantCode * @param scheduleJson scheduleJson * @return process definition code */ @@ -774,12 +769,11 @@ public class ProcessDefinitionController extends BaseController { @RequestParam(value = "description", required = false) String description, @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, - @RequestParam(value = "tenantCode", required = true) String tenantCode, @RequestParam(value = "scheduleJson", required = false) String scheduleJson, @RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType) { return returnDataList(processDefinitionService.createEmptyProcessDefinition(loginUser, projectCode, name, description, globalParams, - timeout, tenantCode, scheduleJson, executionType)); + timeout, scheduleJson, executionType)); } /** @@ -792,7 +786,6 @@ public class ProcessDefinitionController extends BaseController { * @param description description * @param globalParams globalParams * @param timeout timeout - * @param tenantCode tenantCode * @param scheduleJson scheduleJson * @param executionType executionType * @param releaseState releaseState @@ -818,14 +811,13 @@ public class ProcessDefinitionController extends BaseController { @RequestParam(value = "description", required = false) String description, @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, - @RequestParam(value = "tenantCode", required = true) String tenantCode, @RequestParam(value = "scheduleJson", required = false) String scheduleJson, @RequestParam(value = "otherParamsJson", required = false) String otherParamsJson, @RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType, @RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) { Map result = processDefinitionService.updateProcessDefinitionBasicInfo(loginUser, projectCode, name, code, description, globalParams, - timeout, tenantCode, scheduleJson, otherParamsJson, executionType); + timeout, scheduleJson, otherParamsJson, executionType); // If the update fails, the result will be returned directly if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataList(result); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java index b4e0e8853b..e0b5fdc8c4 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java @@ -88,6 +88,7 @@ public class SchedulerController extends BaseController { * @param failureStrategy failure strategy * @param processInstancePriority process instance priority * @param workerGroup worker group + * @param tenantCode tenant code * @return create result code */ @Operation(summary = "createSchedule", description = "CREATE_SCHEDULE_NOTES") @@ -97,7 +98,8 @@ public class SchedulerController extends BaseController { @Parameter(name = "warningType", description = "WARNING_TYPE", schema = @Schema(implementation = WarningType.class)), @Parameter(name = "warningGroupId", description = "WARNING_GROUP_ID", schema = @Schema(implementation = int.class, example = "100")), @Parameter(name = "failureStrategy", description = "FAILURE_STRATEGY", schema = @Schema(implementation = FailureStrategy.class)), - @Parameter(name = "workerGroupId", description = "WORKER_GROUP_ID", schema = @Schema(implementation = int.class, example = "100")), + @Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), + @Parameter(name = "tenantCode", description = "TENANT_CODE", schema = @Schema(implementation = String.class, example = "default")), @Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = long.class)), @Parameter(name = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", schema = @Schema(implementation = Priority.class)), }) @@ -113,6 +115,7 @@ public class SchedulerController extends BaseController { @RequestParam(value = "warningGroupId", required = false, defaultValue = DEFAULT_NOTIFY_GROUP_ID) int warningGroupId, @RequestParam(value = "failureStrategy", required = false, defaultValue = DEFAULT_FAILURE_POLICY) FailureStrategy failureStrategy, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, + @RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode, @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) { Map result = schedulerService.insertSchedule( @@ -125,6 +128,7 @@ public class SchedulerController extends BaseController { failureStrategy, processInstancePriority, workerGroup, + tenantCode, environmentCode); return returnDataList(result); @@ -141,6 +145,7 @@ public class SchedulerController extends BaseController { * @param warningGroupId warning group id * @param failureStrategy failure strategy * @param workerGroup worker group + * @param tenantCode tenant code * @param processInstancePriority process instance priority * @return update result code */ @@ -152,6 +157,7 @@ public class SchedulerController extends BaseController { @Parameter(name = "warningGroupId", description = "WARNING_GROUP_ID", schema = @Schema(implementation = int.class, example = "100")), @Parameter(name = "failureStrategy", description = "FAILURE_STRATEGY", schema = @Schema(implementation = FailureStrategy.class)), @Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), + @Parameter(name = "tenantCode", description = "TENANT_CODE", schema = @Schema(implementation = String.class, example = "default")), @Parameter(name = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", schema = @Schema(implementation = Priority.class)), @Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = long.class)), }) @@ -167,11 +173,13 @@ public class SchedulerController extends BaseController { @RequestParam(value = "warningGroupId", required = false) int warningGroupId, @RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, + @RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode, @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") Long environmentCode, @RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) { Map result = schedulerService.updateSchedule(loginUser, projectCode, id, schedule, - warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, environmentCode); + warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, tenantCode, + environmentCode); return returnDataList(result); } @@ -340,6 +348,7 @@ public class SchedulerController extends BaseController { @Parameter(name = "warningGroupId", description = "WARNING_GROUP_ID", schema = @Schema(implementation = int.class, example = "100")), @Parameter(name = "failureStrategy", description = "FAILURE_STRATEGY", schema = @Schema(implementation = FailureStrategy.class)), @Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), + @Parameter(name = "tenantCode", description = "TENANT_CODE", schema = @Schema(implementation = String.class, example = "default")), @Parameter(name = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", schema = @Schema(implementation = Priority.class)), @Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = long.class)), }) @@ -355,11 +364,13 @@ public class SchedulerController extends BaseController { @RequestParam(value = "warningGroupId", required = false) int warningGroupId, @RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, + @RequestParam(value = "tenantCode", required = false, defaultValue = "default") String tenantCode, @RequestParam(value = "environmentCode", required = false, defaultValue = "-1") long environmentCode, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) { Map result = schedulerService.updateScheduleByProcessDefinitionCode(loginUser, projectCode, processDefinitionCode, schedule, - warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, environmentCode); + warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, tenantCode, + environmentCode); return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/schedule/ScheduleCreateRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/schedule/ScheduleCreateRequest.java index 592e5ddb99..d97f15e7f7 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/schedule/ScheduleCreateRequest.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/schedule/ScheduleCreateRequest.java @@ -72,6 +72,9 @@ public class ScheduleCreateRequest { @Schema(example = "worker-group-name") private String workerGroup; + @Schema(example = "tenant-code") + private String tenantCode; + @Schema(example = "environment-code") private long environmentCode; @@ -91,6 +94,7 @@ public class ScheduleCreateRequest { schedule.setTimezoneId(this.timezoneId); schedule.setWarningGroupId(this.warningGroupId); schedule.setWorkerGroup(this.workerGroup); + schedule.setTenantCode(this.tenantCode); schedule.setEnvironmentCode(this.environmentCode); FailureStrategy newFailureStrategy = diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowCreateRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowCreateRequest.java index a8f8114b3a..56f4648e4f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowCreateRequest.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowCreateRequest.java @@ -55,9 +55,6 @@ public class WorkflowCreateRequest { @Schema(example = "60") private int timeout; - @Schema(example = "tenant1", required = true) - private String tenantCode; - @Schema(allowableValues = "PARALLEL / SERIAL_WAIT / SERIAL_DISCARD / SERIAL_PRIORITY", example = "PARALLEL", description = "default PARALLEL if not provide.") private String executionType; @@ -70,7 +67,6 @@ public class WorkflowCreateRequest { processDefinition.setGlobalParams(this.globalParams); processDefinition.setWarningGroupId(this.warningGroupId); processDefinition.setTimeout(this.timeout); - processDefinition.setTenantCode(this.tenantCode); ReleaseState pdReleaseState = this.releaseState == null ? ReleaseState.OFFLINE : ReleaseState.valueOf(this.releaseState); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowUpdateRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowUpdateRequest.java index c402285eff..807c661642 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowUpdateRequest.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowUpdateRequest.java @@ -56,9 +56,6 @@ public class WorkflowUpdateRequest { @Schema(example = "60") private int timeout; - @Schema(example = "tenantCode1") - private String tenantCode; - @Schema(allowableValues = "PARALLEL / SERIAL_WAIT / SERIAL_DISCARD / SERIAL_PRIORITY", example = "PARALLEL", description = "default PARALLEL if not provide.") private String executionType; @@ -93,9 +90,6 @@ public class WorkflowUpdateRequest { if (this.timeout != 0) { processDefinitionDeepCopy.setTimeout(this.timeout); } - if (this.tenantCode != null) { - processDefinitionDeepCopy.setTenantCode(this.tenantCode); - } if (this.executionType != null) { processDefinitionDeepCopy.setExecutionType(ProcessExecutionTypeEnum.valueOf(this.executionType)); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 168d0f94ae..3ce905a6bc 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -45,7 +45,7 @@ public enum Status { LOGIN_SESSION_FAILED(10014, "create session failed!", "创建session失败"), DATASOURCE_EXIST(10015, "data source name already exists", "数据源名称已存在"), DATASOURCE_CONNECT_FAILED(10016, "data source connection failed", "建立数据源连接失败"), - TENANT_NOT_EXIST(10017, "tenant not exists", "租户不存在"), + TENANT_NOT_EXIST(10017, "tenant [{0}] not exists", "租户[{0}]不存在"), PROJECT_NOT_FOUND(10018, "project {0} not found ", "项目[{0}]不存在"), PROJECT_ALREADY_EXISTS(10019, "project {0} already exists", "项目名称[{0}]已存在"), TASK_INSTANCE_NOT_EXISTS(10020, "task instance {0} does not exist", "任务实例[{0}]不存在"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java index ec2a3cb49a..f3b843bd93 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java @@ -266,12 +266,12 @@ public class PythonGateway { ReleaseState.OFFLINE); processDefinitionService.updateProcessDefinition(user, projectCode, name, processDefinitionCode, description, globalParams, - null, timeout, user.getTenantCode(), taskRelationJson, taskDefinitionJson, otherParamsJson, + null, timeout, taskRelationJson, taskDefinitionJson, otherParamsJson, executionTypeEnum); } else { Map result = processDefinitionService.createProcessDefinition(user, projectCode, name, description, globalParams, - null, timeout, user.getTenantCode(), taskRelationJson, taskDefinitionJson, otherParamsJson, + null, timeout, taskRelationJson, taskDefinitionJson, otherParamsJson, executionTypeEnum); processDefinition = (ProcessDefinition) result.get(Constants.DATA_LIST); processDefinitionCode = processDefinition.getCode(); @@ -343,14 +343,16 @@ public class PythonGateway { ReleaseState.ONLINE); Map result = schedulerService.insertSchedule(user, projectCode, workflowCode, schedule, WarningType.valueOf(warningType), - warningGroupId, DEFAULT_FAILURE_STRATEGY, DEFAULT_PRIORITY, workerGroup, DEFAULT_ENVIRONMENT_CODE); + warningGroupId, DEFAULT_FAILURE_STRATEGY, DEFAULT_PRIORITY, workerGroup, user.getTenantCode(), + DEFAULT_ENVIRONMENT_CODE); scheduleId = (int) result.get("scheduleId"); } else { scheduleId = scheduleObj.getId(); processDefinitionService.releaseProcessDefinition(user, projectCode, workflowCode, ReleaseState.OFFLINE); schedulerService.updateSchedule(user, projectCode, scheduleId, schedule, WarningType.valueOf(warningType), - warningGroupId, DEFAULT_FAILURE_STRATEGY, DEFAULT_PRIORITY, workerGroup, DEFAULT_ENVIRONMENT_CODE); + warningGroupId, DEFAULT_FAILURE_STRATEGY, DEFAULT_PRIORITY, workerGroup, user.getTenantCode(), + DEFAULT_ENVIRONMENT_CODE); } if (onlineSchedule) { // set workflow online to make sure we can set schedule online @@ -389,6 +391,7 @@ public class PythonGateway { DEFAULT_RUN_MODE, DEFAULT_PRIORITY, workerGroup, + user.getTenantCode(), DEFAULT_ENVIRONMENT_CODE, timeout, null, diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java index 3f312ebb7b..736004ff2d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java @@ -52,6 +52,7 @@ public interface ExecutorService { * @param warningGroupId notify group id * @param processInstancePriority process instance priority * @param workerGroup worker group name + * @param tenantCode tenant code * @param environmentCode environment code * @param runMode run mode * @param timeout timeout @@ -65,7 +66,8 @@ public interface ExecutorService { TaskDependType taskDependType, WarningType warningType, Integer warningGroupId, RunMode runMode, - Priority processInstancePriority, String workerGroup, Long environmentCode, + Priority processInstancePriority, String workerGroup, String tenantCode, + Long environmentCode, Integer timeout, Map startParams, Integer expectedParallelismNumber, int dryRun, int testFlag, @@ -154,6 +156,7 @@ public interface ExecutorService { * @param projectCode project code * @param warningGroupId notify group id * @param workerGroup worker group name + * @param tenantCode tenant code * @param environmentCode environment code * @param startParams the global param values which pass to new process instance * @return execute process instance code @@ -161,7 +164,9 @@ public interface ExecutorService { Map execStreamTaskInstance(User loginUser, long projectCode, long taskDefinitionCode, int taskDefinitionVersion, int warningGroupId, - String workerGroup, Long environmentCode, + String workerGroup, + String tenantCode, + Long environmentCode, Map startParams, int dryRun); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java index 12cc8a1829..6b393649e6 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java @@ -52,7 +52,6 @@ public interface ProcessDefinitionService { * @param globalParams global params * @param locations locations for nodes * @param timeout timeout - * @param tenantCode tenantCode * @param taskRelationJson relation json for nodes * @param taskDefinitionJson taskDefinitionJson * @param otherParamsJson otherParamsJson handle other params @@ -65,7 +64,6 @@ public interface ProcessDefinitionService { String globalParams, String locations, int timeout, - String tenantCode, String taskRelationJson, String taskDefinitionJson, String otherParamsJson, @@ -207,7 +205,6 @@ public interface ProcessDefinitionService { * @param globalParams global params * @param locations locations for nodes * @param timeout timeout - * @param tenantCode tenantCode * @param taskRelationJson relation json for nodes * @param taskDefinitionJson taskDefinitionJson * @param otherParamsJson otherParamsJson handle other params @@ -221,7 +218,6 @@ public interface ProcessDefinitionService { String globalParams, String locations, int timeout, - String tenantCode, String taskRelationJson, String taskDefinitionJson, String otherParamsJson, @@ -427,7 +423,6 @@ public interface ProcessDefinitionService { * @param description description * @param globalParams globalParams * @param timeout timeout - * @param tenantCode tenantCode * @param scheduleJson scheduleJson * @return process definition code */ @@ -437,7 +432,6 @@ public interface ProcessDefinitionService { String description, String globalParams, int timeout, - String tenantCode, String scheduleJson, ProcessExecutionTypeEnum executionType); @@ -451,7 +445,6 @@ public interface ProcessDefinitionService { * @param description description * @param globalParams globalParams * @param timeout timeout - * @param tenantCode tenantCode * @param scheduleJson scheduleJson * @param otherParamsJson otherParamsJson handle other params * @param executionType executionType @@ -464,7 +457,6 @@ public interface ProcessDefinitionService { String description, String globalParams, int timeout, - String tenantCode, String scheduleJson, String otherParamsJson, ProcessExecutionTypeEnum executionType); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java index e8b60e5c74..262ad2df5e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java @@ -49,6 +49,7 @@ public interface SchedulerService { * @param failureStrategy failure strategy * @param processInstancePriority process instance priority * @param workerGroup worker group + * @param tenantCode tenant code * @param environmentCode environment code * @return create result code */ @@ -61,6 +62,7 @@ public interface SchedulerService { FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, + String tenantCode, Long environmentCode); /** @@ -84,6 +86,7 @@ public interface SchedulerService { * @param warningGroupId warning group id * @param failureStrategy failure strategy * @param workerGroup worker group + * @param tenantCode tenant code * @param environmentCode environment code * @param processInstancePriority process instance priority * @return update result code @@ -97,6 +100,7 @@ public interface SchedulerService { FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, + String tenantCode, Long environmentCode); /** @@ -206,6 +210,7 @@ public interface SchedulerService { * @param warningGroupId warning group id * @param failureStrategy failure strategy * @param workerGroup worker group + * @param tenantCode tenant code * @param processInstancePriority process instance priority * @return update result code */ @@ -218,5 +223,6 @@ public interface SchedulerService { FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, + String tenantCode, long environmentCode); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java index 08bbed0b19..b9c7de3b63 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java @@ -70,6 +70,7 @@ import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskGroupQueue; +import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; @@ -78,6 +79,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskGroupQueueMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; import org.apache.dolphinscheduler.plugin.task.api.TaskConstants; import org.apache.dolphinscheduler.remote.command.Message; @@ -181,6 +183,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ @Autowired private ExecuteClient executeClient; + @Autowired + private TenantMapper tenantMapper; + /** * execute process instance * @@ -196,6 +201,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ * @param warningGroupId notify group id * @param processInstancePriority process instance priority * @param workerGroup worker group name + * @param tenantCode tenant code * @param environmentCode environment code * @param runMode run mode * @param timeout timeout @@ -212,6 +218,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ TaskDependType taskDependType, WarningType warningType, Integer warningGroupId, RunMode runMode, Priority processInstancePriority, String workerGroup, + String tenantCode, Long environmentCode, Integer timeout, Map startParams, Integer expectedParallelismNumber, int dryRun, int testFlag, @@ -229,6 +236,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ putMsg(result, Status.TASK_TIMEOUT_PARAMS_ERROR); return result; } + checkValidTenant(tenantCode); ProcessDefinition processDefinition; if (null != version) { processDefinition = processService.findProcessDefinition(processDefinitionCode, version); @@ -254,7 +262,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(), warningGroupId, runMode, processInstancePriority, - workerGroup, + workerGroup, tenantCode, environmentCode, startParams, expectedParallelismNumber, dryRun, testFlag, complementDependentMode); @@ -361,6 +369,20 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ .isEmpty(); } + /** + * check valid tenant + * + * @param tenantCode + */ + private void checkValidTenant(String tenantCode) { + if (!Constants.DEFAULT.equals(tenantCode)) { + Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); + if (tenant == null) { + throw new ServiceException(Status.TENANT_NOT_EXIST, tenantCode); + } + } + } + /** * do action to process instance:pause, stop, repeat, recover from pause, recover from stop,rerun failed task * @@ -723,7 +745,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ private int createCommand(Long triggerCode, CommandType commandType, long processDefineCode, TaskDependType nodeDep, FailureStrategy failureStrategy, String startNodeList, String schedule, WarningType warningType, int executorId, Integer warningGroupId, RunMode runMode, - Priority processInstancePriority, String workerGroup, Long environmentCode, + Priority processInstancePriority, String workerGroup, String tenantCode, + Long environmentCode, Map startParams, Integer expectedParallelismNumber, int dryRun, int testFlag, ComplementDependentMode complementDependentMode) { @@ -760,6 +783,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ command.setWarningGroupId(warningGroupId); command.setProcessInstancePriority(processInstancePriority); command.setWorkerGroup(workerGroup); + command.setTenantCode(tenantCode); command.setEnvironmentCode(environmentCode); command.setDryRun(dryRun); command.setTestFlag(testFlag); @@ -1140,7 +1164,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ @Override public Map execStreamTaskInstance(User loginUser, long projectCode, long taskDefinitionCode, int taskDefinitionVersion, - int warningGroupId, String workerGroup, Long environmentCode, + int warningGroupId, String workerGroup, String tenantCode, + Long environmentCode, Map startParams, int dryRun) { Project project = projectMapper.queryByCode(projectCode); // check user access for project @@ -1149,7 +1174,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } - + checkValidTenant(tenantCode); checkMasterExists(); // todo dispatch improvement List masterServerList = monitorService.getServerListFromRegistry(true); @@ -1162,6 +1187,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ taskExecuteStartMessage.setTaskDefinitionCode(taskDefinitionCode); taskExecuteStartMessage.setTaskDefinitionVersion(taskDefinitionVersion); taskExecuteStartMessage.setWorkerGroup(workerGroup); + taskExecuteStartMessage.setTenantCode(tenantCode); taskExecuteStartMessage.setWarningGroupId(warningGroupId); taskExecuteStartMessage.setEnvironmentCode(environmentCode); taskExecuteStartMessage.setStartParams(startParams); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java index 1af41bcfcf..4cfb55223e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java @@ -97,7 +97,6 @@ import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.TaskMainInfo; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.UserWithProcessDefinitionCode; import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; @@ -110,7 +109,6 @@ import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; -import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.model.PageListingResult; import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao; @@ -127,6 +125,7 @@ import org.apache.dolphinscheduler.service.model.TaskNode; import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import java.io.BufferedOutputStream; @@ -242,9 +241,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro @Autowired private SchedulerService schedulerService; - @Autowired - private TenantMapper tenantMapper; - @Autowired private DataSourceMapper dataSourceMapper; @@ -267,7 +263,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * @param globalParams global params * @param locations locations for nodes * @param timeout timeout - * @param tenantCode tenantCode * @param taskRelationJson relation json for nodes * @param taskDefinitionJson taskDefinitionJson * @return create result code @@ -281,7 +276,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro String globalParams, String locations, int timeout, - String tenantCode, String taskRelationJson, String taskDefinitionJson, String otherParamsJson, @@ -308,19 +302,11 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } List taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); List taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); - int tenantId = -1; - if (!Constants.DEFAULT.equals(tenantCode)) { - Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); - if (tenant == null) { - log.error("Tenant does not exist."); - throw new ServiceException(Status.TENANT_NOT_EXIST); - } - tenantId = tenant.getId(); - } + long processDefinitionCode = CodeGenerateUtils.getInstance().genCode(); ProcessDefinition processDefinition = new ProcessDefinition(projectCode, name, processDefinitionCode, description, - globalParams, locations, timeout, loginUser.getId(), tenantId); + globalParams, locations, timeout, loginUser.getId()); processDefinition.setExecutionType(executionType); return createDagDefine(loginUser, taskRelationList, processDefinition, taskDefinitionLogs, otherParamsJson); @@ -345,19 +331,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro throw new ServiceException(Status.PROCESS_DEFINITION_NAME_EXIST, processDefinition.getName()); } - this.getTenantId(processDefinition); - } - - private int getTenantId(ProcessDefinition processDefinition) { - int tenantId = -1; - if (!Constants.DEFAULT.equals(processDefinition.getTenantCode())) { - Tenant tenant = tenantMapper.queryByTenantCode(processDefinition.getTenantCode()); - if (tenant == null) { - throw new ServiceException(Status.TENANT_NOT_EXIST); - } - tenantId = tenant.getId(); - } - return tenantId; } private void syncObj2Log(User user, ProcessDefinition processDefinition) { @@ -390,7 +363,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS); } - processDefinition.setTenantId(this.getTenantId(processDefinition)); processDefinition.setCode(processDefinitionCode); processDefinition.setUserId(loginUser.getId()); @@ -693,10 +665,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro log.error("Process definition does not exist, processCode:{}.", code); putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, String.valueOf(code)); } else { - Tenant tenant = tenantMapper.queryById(processDefinition.getTenantId()); - if (tenant != null) { - processDefinition.setTenantCode(tenant.getTenantCode()); - } DagData dagData = processService.genDagData(processDefinition); result.put(Constants.DATA_LIST, dagData); putMsg(result, Status.SUCCESS); @@ -722,11 +690,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro // check user access for project projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION); - Tenant tenant = tenantMapper.queryById(processDefinition.getTenantId()); - if (tenant != null) { - processDefinition.setTenantCode(tenant.getTenantCode()); - } - return processDefinition; } @@ -782,7 +745,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * @param globalParams global params * @param locations locations for nodes * @param timeout timeout - * @param tenantCode tenantCode * @param taskRelationJson relation json for nodes * @param taskDefinitionJson taskDefinitionJson * @param otherParamsJson otherParamsJson handle other params @@ -798,7 +760,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro String globalParams, String locations, int timeout, - String tenantCode, String taskRelationJson, String taskDefinitionJson, String otherParamsJson, @@ -820,17 +781,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro List taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); List taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); - int tenantId = -1; - if (!Constants.DEFAULT.equals(tenantCode)) { - Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); - if (tenant == null) { - log.error("Tenant does not exist."); - putMsg(result, Status.TENANT_NOT_EXIST); - return result; - } - tenantId = tenant.getId(); - } - ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); // check process definition exists if (processDefinition == null || projectCode != processDefinition.getProjectCode()) { @@ -857,7 +807,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } ProcessDefinition processDefinitionDeepCopy = JSONUtils.parseObject(JSONUtils.toJsonString(processDefinition), ProcessDefinition.class); - processDefinition.set(projectCode, name, description, globalParams, locations, timeout, tenantId); + processDefinition.set(projectCode, name, description, globalParams, locations, timeout); processDefinition.setExecutionType(executionType); return updateDagDefine(loginUser, taskRelationList, processDefinition, processDefinitionDeepCopy, taskDefinitionLogs, otherParamsJson); @@ -1366,7 +1316,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro CodeGenerateUtils.getInstance().genCode(), "", "[]", null, - 0, loginUser.getId(), loginUser.getTenantId()); + 0, loginUser.getId()); ZipEntry entry; while ((entry = zIn.getNextEntry()) != null) { @@ -2501,7 +2451,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * @param description description * @param globalParams globalParams * @param timeout timeout - * @param tenantCode tenantCode * @param scheduleJson scheduleJson * @return process definition code */ @@ -2513,7 +2462,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro String description, String globalParams, int timeout, - String tenantCode, String scheduleJson, ProcessExecutionTypeEnum executionType) { Project project = projectMapper.queryByCode(projectCode); @@ -2538,16 +2486,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro return result; } - int tenantId = -1; - if (!Constants.DEFAULT.equals(tenantCode)) { - Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); - if (tenant == null) { - log.error("Tenant does not exist."); - putMsg(result, Status.TENANT_NOT_EXIST); - return result; - } - tenantId = tenant.getId(); - } long processDefinitionCode; try { processDefinitionCode = CodeGenerateUtils.getInstance().genCode(); @@ -2558,7 +2496,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } ProcessDefinition processDefinition = new ProcessDefinition(projectCode, name, processDefinitionCode, description, - globalParams, "", timeout, loginUser.getId(), tenantId); + globalParams, "", timeout, loginUser.getId()); processDefinition.setExecutionType(executionType); result = createEmptyDagDefine(loginUser, processDefinition); if (result.get(Constants.STATUS) != Status.SUCCESS) { @@ -2645,7 +2583,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * @param description description * @param globalParams globalParams * @param timeout timeout - * @param tenantCode tenantCode * @param scheduleJson scheduleJson * @param otherParamsJson otherParamsJson handle other params * @param executionType executionType @@ -2660,7 +2597,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro String description, String globalParams, int timeout, - String tenantCode, String scheduleJson, String otherParamsJson, ProcessExecutionTypeEnum executionType) { @@ -2677,16 +2613,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR); return result; } - int tenantId = -1; - if (!Constants.DEFAULT.equals(tenantCode)) { - Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); - if (tenant == null) { - log.error("Tenant does not exist."); - putMsg(result, Status.TENANT_NOT_EXIST); - return result; - } - tenantId = tenant.getId(); - } ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); // check process definition exists @@ -2714,7 +2640,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } ProcessDefinition processDefinitionDeepCopy = JSONUtils.parseObject(JSONUtils.toJsonString(processDefinition), ProcessDefinition.class); - processDefinition.set(projectCode, name, description, globalParams, "", timeout, tenantId); + processDefinition.set(projectCode, name, description, globalParams, "", timeout); processDefinition.setExecutionType(executionType); List taskRelationList = processTaskRelationLogMapper .queryByProcessCodeAndVersion(processDefinition.getCode(), processDefinition.getVersion()); @@ -2785,13 +2711,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro ProcessDefinition processDefinitionUpdate = workflowUpdateRequest.mergeIntoProcessDefinition(processDefinition); this.updateWorkflowValid(loginUser, processDefinition, processDefinitionUpdate); - if (processDefinitionUpdate.getTenantCode() != null) { - Tenant tenant = tenantMapper.queryByTenantCode(processDefinitionUpdate.getTenantCode()); - if (tenant == null) { - throw new ServiceException(Status.TENANT_NOT_EXIST); - } - processDefinitionUpdate.setTenantId(tenant.getId()); - } int insertVersion = this.saveProcessDefine(loginUser, processDefinitionUpdate); if (insertVersion == 0) { log.error("Update process definition error, projectCode:{}, processDefinitionName:{}.", @@ -2910,12 +2829,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } // set default value FailureStrategy failureStrategy = - schedule.getFailureStrategy() == null ? FailureStrategy.CONTINUE : schedule.getFailureStrategy(); - WarningType warningType = schedule.getWarningType() == null ? WarningType.NONE : schedule.getWarningType(); + ObjectUtils.defaultIfNull(schedule.getFailureStrategy(), FailureStrategy.CONTINUE); + WarningType warningType = ObjectUtils.defaultIfNull(schedule.getWarningType(), WarningType.NONE); Priority processInstancePriority = - schedule.getProcessInstancePriority() == null ? Priority.MEDIUM : schedule.getProcessInstancePriority(); + ObjectUtils.defaultIfNull(schedule.getProcessInstancePriority(), Priority.MEDIUM); int warningGroupId = schedule.getWarningGroupId() == 0 ? 1 : schedule.getWarningGroupId(); - String workerGroup = schedule.getWorkerGroup() == null ? "default" : schedule.getWorkerGroup(); + String workerGroup = StringUtils.defaultIfBlank(schedule.getWorkerGroup(), DEFAULT_WORKER_GROUP); + String tenantCode = StringUtils.defaultIfBlank(schedule.getTenantCode(), Constants.DEFAULT); long environmentCode = schedule.getEnvironmentCode() == null ? -1 : schedule.getEnvironmentCode(); ScheduleParam param = new ScheduleParam(); @@ -2934,6 +2854,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro failureStrategy, processInstancePriority, workerGroup, + tenantCode, environmentCode); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java index 547d9ee207..69620e7640 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java @@ -61,7 +61,6 @@ import org.apache.dolphinscheduler.dao.entity.ResponseTaskLog; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; @@ -265,10 +264,6 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce log.error("Process definition does not exist, projectCode:{}.", projectCode); putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); } else { - Tenant tenant = tenantMapper.queryById(processDefinition.getTenantId()); - if (tenant != null) { - processDefinition.setTenantCode(tenant.getTenantCode()); - } processInstance.setLocations(processDefinition.getLocations()); processInstance.setDagData(processService.genDagData(processDefinition)); result.put(DATA_LIST, processInstance); @@ -693,18 +688,9 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } - int tenantId = -1; - if (!Constants.DEFAULT.equals(tenantCode)) { - Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); - if (tenant == null) { - log.error("Tenant does not exist."); - putMsg(result, Status.TENANT_NOT_EXIST); - return result; - } - tenantId = tenant.getId(); - } + processDefinition.set(projectCode, processDefinition.getName(), processDefinition.getDescription(), - globalParams, locations, timeout, tenantId); + globalParams, locations, timeout); processDefinition.setUpdateTime(new Date()); int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, syncDefine, Boolean.FALSE); if (insertVersion == 0) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java index 32d4821f60..419f1151df 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java @@ -46,12 +46,14 @@ import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Schedule; +import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.scheduler.api.SchedulerApi; import org.apache.dolphinscheduler.service.cron.CronUtils; import org.apache.dolphinscheduler.service.exceptions.CronParseException; @@ -117,6 +119,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe @Autowired private EnvironmentMapper environmentMapper; + @Autowired + private TenantMapper tenantMapper; + /** * save schedule * @@ -129,6 +134,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * @param failureStrategy failure strategy * @param processInstancePriority process instance priority * @param workerGroup worker group + * @param tenantCode tenant code * @param environmentCode environment code * @return create result code */ @@ -143,6 +149,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, + String tenantCode, Long environmentCode) { Map result = new HashMap<>(); @@ -155,7 +162,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe return result; } - // check work flow define release state + // check workflow define release state ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefineCode); executorService.checkProcessDefinitionValid(projectCode, processDefinition, processDefineCode, processDefinition.getVersion()); @@ -163,6 +170,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe Schedule scheduleObj = new Schedule(); Date now = new Date(); + checkValidTenant(tenantCode); + + scheduleObj.setTenantCode(tenantCode); scheduleObj.setProjectName(project.getName()); scheduleObj.setProcessDefinitionCode(processDefineCode); scheduleObj.setProcessDefinitionName(processDefinition.getName()); @@ -269,11 +279,14 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe scheduleExists.getId()); } + checkValidTenant(scheduleCreateRequest.getTenantCode()); + Schedule schedule = scheduleCreateRequest.convert2Schedule(); Environment environment = environmentMapper.queryByEnvironmentCode(schedule.getEnvironmentCode()); if (environment == null) { throw new ServiceException(Status.QUERY_ENVIRONMENT_BY_CODE_ERROR, schedule.getEnvironmentCode()); } + schedule.setUserId(loginUser.getId()); // give more detail when return schedule object schedule.setUserName(loginUser.getUserName()); @@ -301,6 +314,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * @param warningGroupId warning group id * @param failureStrategy failure strategy * @param workerGroup worker group + * @param tenantCode tenant code * @param environmentCode environment code * @param processInstancePriority process instance priority * @return update result code @@ -316,6 +330,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, + String tenantCode, Long environmentCode) { Map result = new HashMap<>(); @@ -345,7 +360,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe } updateSchedule(result, schedule, processDefinition, scheduleExpression, warningType, warningGroupId, - failureStrategy, processInstancePriority, workerGroup, environmentCode); + failureStrategy, processInstancePriority, workerGroup, tenantCode, environmentCode); return result; } @@ -561,16 +576,16 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe } Page page = new Page<>(pageNo, pageSize); - IPage scheduleIPage = + IPage schedulePage = scheduleMapper.queryByProcessDefineCodePaging(page, processDefineCode, searchVal); List scheduleList = new ArrayList<>(); - for (Schedule schedule : scheduleIPage.getRecords()) { + for (Schedule schedule : schedulePage.getRecords()) { scheduleList.add(new ScheduleVo(schedule)); } PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); - pageInfo.setTotal((int) scheduleIPage.getTotal()); + pageInfo.setTotal((int) schedulePage.getTotal()); pageInfo.setTotalList(scheduleList); result.setData(pageInfo); putMsg(result, Status.SUCCESS); @@ -752,6 +767,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * @param warningGroupId warning group id * @param failureStrategy failure strategy * @param workerGroup worker group + * @param tenantCode tenant code * @param processInstancePriority process instance priority * @return update result code */ @@ -765,6 +781,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, + String tenantCode, long environmentCode) { Project project = projectMapper.queryByCode(projectCode); // check user access for project @@ -789,13 +806,14 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe } updateSchedule(result, schedule, processDefinition, scheduleExpression, warningType, warningGroupId, - failureStrategy, processInstancePriority, workerGroup, environmentCode); + failureStrategy, processInstancePriority, workerGroup, tenantCode, environmentCode); return result; } private void updateSchedule(Map result, Schedule schedule, ProcessDefinition processDefinition, String scheduleExpression, WarningType warningType, int warningGroupId, FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, + String tenantCode, long environmentCode) { if (checkValid(result, schedule.getReleaseState() == ReleaseState.ONLINE, Status.SCHEDULE_CRON_ONLINE_FORBID_UPDATE)) { @@ -806,6 +824,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe Date now = new Date(); + checkValidTenant(tenantCode); + schedule.setTenantCode(tenantCode); + // updateProcessInstance param if (!StringUtils.isEmpty(scheduleExpression)) { ScheduleParam scheduleParam = JSONUtils.parseObject(scheduleExpression, ScheduleParam.class); @@ -860,4 +881,18 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe processDefinition.getProjectCode(), processDefinition.getCode(), schedule.getId()); putMsg(result, Status.SUCCESS); } + + /** + * check valid tenant + * + * @param tenantCode + */ + private void checkValidTenant(String tenantCode) { + if (!Constants.DEFAULT.equals(tenantCode)) { + Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); + if (tenant == null) { + throw new ServiceException(Status.TENANT_NOT_EXIST, tenantCode); + } + } + } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java index c2d9be0d42..37d3a817b6 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java @@ -32,13 +32,13 @@ import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.utils.PropertyUtils; -import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.Queue; +import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; @@ -77,7 +77,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService private ProcessInstanceMapper processInstanceMapper; @Autowired - private ProcessDefinitionMapper processDefinitionMapper; + private ScheduleMapper scheduleMapper; @Autowired private UserMapper userMapper; @@ -278,12 +278,12 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL, processInstances.size()); } - List processDefinitions = - processDefinitionMapper.queryDefinitionListByTenant(tenant.getId()); - if (CollectionUtils.isNotEmpty(processDefinitions)) { - log.warn("Delete tenant failed, because there are {} process definitions using it.", - processDefinitions.size()); - throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_DEFINES, processDefinitions.size()); + List schedules = + scheduleMapper.queryScheduleListByTenant(tenant.getTenantCode()); + if (CollectionUtils.isNotEmpty(schedules)) { + log.warn("Delete tenant failed, because there are {} schedule using it.", + schedules.size()); + throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_DEFINES, schedules.size()); } List userList = userMapper.queryUserListByTenant(tenant.getId()); @@ -299,7 +299,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService int delete = tenantMapper.deleteById(id); if (delete > 0) { - processInstanceMapper.updateProcessInstanceByTenantId(id, -1); + processInstanceMapper.updateProcessInstanceByTenantCode(tenant.getTenantCode(), Constants.DEFAULT); log.info("Tenant is deleted and id is {}.", id); putMsg(result, Status.SUCCESS); } else { @@ -311,7 +311,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService } private List getProcessInstancesByTenant(Tenant tenant) { - return processInstanceMapper.queryByTenantIdAndStatus(tenant.getId(), + return processInstanceMapper.queryByTenantCodeAndStatus(tenant.getTenantCode(), org.apache.dolphinscheduler.service.utils.Constants.NOT_TERMINATED_STATES); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/ScheduleVo.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/ScheduleVo.java index 8be0545279..2c5429e53a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/ScheduleVo.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/ScheduleVo.java @@ -125,6 +125,11 @@ public class ScheduleVo { */ private String workerGroup; + /** + * tenantCode + */ + private String tenantCode; + /** * environment code */ @@ -156,5 +161,6 @@ public class ScheduleVo { this.setStartTime(DateUtils.dateToString(schedule.getStartTime(), ZoneId.systemDefault().getId())); this.setEndTime(DateUtils.dateToString(schedule.getEndTime(), ZoneId.systemDefault().getId())); this.setEnvironmentName(schedule.getEnvironmentName()); + this.setTenantCode(schedule.getTenantCode()); } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecuteFunctionControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecuteFunctionControllerTest.java index 2f5cfb960a..b435a7dd58 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecuteFunctionControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecuteFunctionControllerTest.java @@ -70,6 +70,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { final RunMode runMode = RunMode.RUN_MODE_SERIAL; final Priority processInstancePriority = Priority.HIGH; final String workerGroup = "workerGroup"; + final String tenantCode = "root"; final Long environmentCode = 4L; final Integer timeout = 5; final ImmutableMap startParams = ImmutableMap.of("start", "params"); @@ -104,6 +105,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { paramsMap.add("runMode", String.valueOf(runMode)); paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority)); paramsMap.add("workerGroup", workerGroup); + paramsMap.add("tenantCode", tenantCode); paramsMap.add("environmentCode", String.valueOf(environmentCode)); paramsMap.add("timeout", String.valueOf(timeout)); paramsMap.add("startParams", gson.toJson(startParams)); @@ -114,7 +116,8 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode), eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType), eq(warningType), - eq(warningGroupId), eq(runMode), eq(processInstancePriority), eq(workerGroup), eq(environmentCode), + eq(warningGroupId), eq(runMode), eq(processInstancePriority), eq(workerGroup), eq(tenantCode), + eq(environmentCode), eq(timeout), eq(startParams), eq(expectedParallelismNumber), eq(dryRun), eq(testFlag), eq(complementDependentMode), eq(version))) .thenReturn(executeServiceResult); @@ -148,6 +151,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { paramsMap.add("runMode", String.valueOf(runMode)); paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority)); paramsMap.add("workerGroup", workerGroup); + paramsMap.add("tenantCode", tenantCode); paramsMap.add("environmentCode", String.valueOf(environmentCode)); paramsMap.add("startParams", gson.toJson(startParams)); paramsMap.add("expectedParallelismNumber", String.valueOf(expectedParallelismNumber)); @@ -157,7 +161,8 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode), eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType), eq(warningType), - eq(warningGroupId), eq(runMode), eq(processInstancePriority), eq(workerGroup), eq(environmentCode), + eq(warningGroupId), eq(runMode), eq(processInstancePriority), eq(workerGroup), eq(tenantCode), + eq(environmentCode), eq(Constants.MAX_TASK_TIMEOUT), eq(startParams), eq(expectedParallelismNumber), eq(dryRun), eq(testFlag), eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult); @@ -191,6 +196,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { paramsMap.add("runMode", String.valueOf(runMode)); paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority)); paramsMap.add("workerGroup", workerGroup); + paramsMap.add("tenantCode", tenantCode); paramsMap.add("environmentCode", String.valueOf(environmentCode)); paramsMap.add("timeout", String.valueOf(timeout)); paramsMap.add("expectedParallelismNumber", String.valueOf(expectedParallelismNumber)); @@ -200,7 +206,8 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode), eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType), eq(warningType), - eq(warningGroupId), eq(runMode), eq(processInstancePriority), eq(workerGroup), eq(environmentCode), + eq(warningGroupId), eq(runMode), eq(processInstancePriority), eq(workerGroup), eq(tenantCode), + eq(environmentCode), eq(timeout), eq(null), eq(expectedParallelismNumber), eq(dryRun), eq(testFlag), eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult); @@ -229,7 +236,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest { when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode), eq(scheduleTime), eq(null), eq(failureStrategy), eq(null), eq(null), eq(warningType), - eq(null), eq(null), eq(null), eq("default"), eq(-1L), + eq(null), eq(null), eq(null), eq("default"), eq("default"), eq(-1L), eq(Constants.MAX_TASK_TIMEOUT), eq(null), eq(null), eq(0), eq(0), eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java index 06a79d3b7e..889c1388fb 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java @@ -90,20 +90,19 @@ public class ProcessDefinitionControllerTest { String globalParams = "[]"; String locations = "[]"; int timeout = 0; - String tenantCode = "root"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, 1); Mockito.when( processDefinitionService.createProcessDefinition(user, projectCode, name, description, globalParams, - locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", + locations, timeout, relationJson, taskDefinitionJson, "", ProcessExecutionTypeEnum.PARALLEL)) .thenReturn(result); Result response = processDefinitionController.createProcessDefinition(user, projectCode, name, description, globalParams, - locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", + locations, timeout, relationJson, taskDefinitionJson, "", ProcessExecutionTypeEnum.PARALLEL); Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } @@ -160,7 +159,6 @@ public class ProcessDefinitionControllerTest { String description = "desc test"; String globalParams = "[]"; int timeout = 0; - String tenantCode = "root"; long code = 123L; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); @@ -168,12 +166,12 @@ public class ProcessDefinitionControllerTest { Mockito.when(processDefinitionService.updateProcessDefinition(user, projectCode, name, code, description, globalParams, - locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", + locations, timeout, relationJson, taskDefinitionJson, "", ProcessExecutionTypeEnum.PARALLEL)).thenReturn(result); Result response = processDefinitionController.updateProcessDefinition(user, projectCode, name, code, description, globalParams, - locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", ProcessExecutionTypeEnum.PARALLEL, + locations, timeout, relationJson, taskDefinitionJson, "", ProcessExecutionTypeEnum.PARALLEL, ReleaseState.OFFLINE); Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java index efef2b076b..9190d45274 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java @@ -67,11 +67,12 @@ public class SchedulerControllerTest extends AbstractControllerTest { paramsMap.add("receivers", ""); paramsMap.add("receiversCc", ""); paramsMap.add("workerGroupId", "1"); + paramsMap.add("tenantCode", "root"); paramsMap.add("processInstancePriority", String.valueOf(Priority.HIGH)); Mockito.when(schedulerService.insertSchedule(isA(User.class), isA(Long.class), isA(Long.class), isA(String.class), isA(WarningType.class), isA(int.class), isA(FailureStrategy.class), - isA(Priority.class), isA(String.class), isA(Long.class))).thenReturn(success()); + isA(Priority.class), isA(String.class), isA(String.class), isA(Long.class))).thenReturn(success()); MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/", 123) .header(SESSION_ID, sessionId) @@ -97,11 +98,12 @@ public class SchedulerControllerTest extends AbstractControllerTest { paramsMap.add("receivers", ""); paramsMap.add("receiversCc", ""); paramsMap.add("workerGroupId", "1"); + paramsMap.add("tenantCode", "root"); paramsMap.add("processInstancePriority", String.valueOf(Priority.HIGH)); Mockito.when(schedulerService.updateSchedule(isA(User.class), isA(Long.class), isA(Integer.class), isA(String.class), isA(WarningType.class), isA(Integer.class), isA(FailureStrategy.class), - isA(Priority.class), isA(String.class), isA(Long.class))).thenReturn(success()); + isA(Priority.class), isA(String.class), isA(String.class), isA(Long.class))).thenReturn(success()); MvcResult mvcResult = mockMvc.perform(put("/projects/{projectCode}/schedules/{id}", 123, 37) .header(SESSION_ID, sessionId) diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/WorkflowV2ControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/WorkflowV2ControllerTest.java index 881725134b..e9d2240884 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/WorkflowV2ControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/WorkflowV2ControllerTest.java @@ -86,7 +86,6 @@ public class WorkflowV2ControllerTest { workflowCreateRequest.setDescription(description); workflowCreateRequest.setGlobalParams(EMPTY_STRING); workflowCreateRequest.setTimeout(timeout); - workflowCreateRequest.setTenantCode(tenantCode); workflowCreateRequest.setWarningGroupId(warningGroupId); workflowCreateRequest.setExecutionType(executionType); @@ -139,7 +138,6 @@ public class WorkflowV2ControllerTest { processDefinition.setDescription(description); processDefinition.setReleaseState(ReleaseState.valueOf(releaseState)); processDefinition.setProjectCode(projectCode); - processDefinition.setTenantId(1); processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType)); processDefinition.setWarningGroupId(warningGroupId); processDefinition.setGlobalParams(EMPTY_STRING); @@ -153,7 +151,6 @@ public class WorkflowV2ControllerTest { processDefinition.setDescription(description); processDefinition.setReleaseState(ReleaseState.valueOf(releaseState)); processDefinition.setProjectCode(projectCode); - processDefinition.setTenantId(1); processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType)); processDefinition.setWarningGroupId(warningGroupId); processDefinition.setGlobalParams(EMPTY_STRING); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecuteFunctionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecuteFunctionServiceTest.java index 2a00a6aa65..150a2a664d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecuteFunctionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecuteFunctionServiceTest.java @@ -64,6 +64,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskGroupQueueMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; import org.apache.dolphinscheduler.remote.processor.StateEventCallbackService; import org.apache.dolphinscheduler.service.command.CommandService; @@ -132,6 +133,9 @@ public class ExecuteFunctionServiceTest { @Mock private ProjectMapper projectMapper; + @Mock + private TenantMapper tenantMapper; + @Mock private ProjectServiceImpl projectService; @@ -167,7 +171,7 @@ public class ExecuteFunctionServiceTest { private int processInstanceId = 1; - private int tenantId = 1; + private String tenantCode = "root"; private int userId = 1; @@ -199,7 +203,6 @@ public class ExecuteFunctionServiceTest { // processDefinition processDefinition.setId(processDefinitionId); processDefinition.setReleaseState(ReleaseState.ONLINE); - processDefinition.setTenantId(tenantId); processDefinition.setUserId(userId); processDefinition.setVersion(1); processDefinition.setCode(1L); @@ -210,7 +213,6 @@ public class ExecuteFunctionServiceTest { processInstance.setProjectCode(projectCode); processInstance.setState(WorkflowExecutionStatus.FAILURE); processInstance.setExecutorId(userId); - processInstance.setTenantId(tenantId); processInstance.setHost("127.0.0.1:5678"); processInstance.setProcessDefinitionVersion(1); processInstance.setProcessDefinitionCode(1L); @@ -240,7 +242,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START)) .thenReturn(checkProjectAndAuth()); Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(this.processDefinition); - Mockito.when(processService.getTenantForProcess(tenantId, userId)).thenReturn(new Tenant()); + Mockito.when(processService.getTenantForProcess(tenantCode, userId)).thenReturn(tenantCode); doReturn(1).when(commandService).createCommand(argThat(c -> c.getId() == null)); doReturn(0).when(commandService).createCommand(argThat(c -> c.getId() != null)); Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(getMasterServersList()); @@ -270,6 +272,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) .thenReturn(zeroSchedulerList()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = executorService.execProcessInstance(loginUser, projectCode, processDefinitionCode, "{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", @@ -277,7 +280,7 @@ public class ExecuteFunctionServiceTest { null, null, null, null, null, RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 10, null, 0, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 10, null, 0, Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_NO, ComplementDependentMode.OFF_MODE, null); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -293,6 +296,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) .thenReturn(zeroSchedulerList()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = executorService.execProcessInstance(loginUser, projectCode, processDefinitionCode, "{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", @@ -300,7 +304,7 @@ public class ExecuteFunctionServiceTest { null, "123456789,987654321", null, null, null, RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_NO, ComplementDependentMode.OFF_MODE, null); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -312,6 +316,7 @@ public class ExecuteFunctionServiceTest { public void testComplementWithOldStartNodeList() { Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) .thenReturn(zeroSchedulerList()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = new HashMap<>(); try { result = executorService.execProcessInstance(loginUser, projectCode, @@ -321,7 +326,8 @@ public class ExecuteFunctionServiceTest { null, "1123456789,987654321", null, null, null, RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 110, null, 0, + Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_NO, ComplementDependentMode.OFF_MODE, null); } catch (ServiceException e) { @@ -381,6 +387,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) .thenReturn(zeroSchedulerList()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = executorService.execProcessInstance(loginUser, projectCode, processDefinitionCode, "{\"complementStartDate\":\"2022-01-07 12:12:12\",\"complementEndDate\":\"2022-01-06 12:12:12\"}", @@ -388,7 +395,7 @@ public class ExecuteFunctionServiceTest { null, null, null, null, null, RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_NO, ComplementDependentMode.OFF_MODE, null); Assertions.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS)); @@ -403,6 +410,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) .thenReturn(zeroSchedulerList()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = executorService.execProcessInstance(loginUser, projectCode, processDefinitionCode, "{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", @@ -410,7 +418,7 @@ public class ExecuteFunctionServiceTest { null, null, null, null, null, RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_NO, ComplementDependentMode.OFF_MODE, null); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -425,6 +433,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) .thenReturn(zeroSchedulerList()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = executorService.execProcessInstance(loginUser, projectCode, processDefinitionCode, "{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", @@ -432,7 +441,7 @@ public class ExecuteFunctionServiceTest { null, null, null, null, null, RunMode.RUN_MODE_PARALLEL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 110, null, 0, Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_NO, ComplementDependentMode.OFF_MODE, null); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -448,6 +457,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) .thenReturn(oneSchedulerList()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = executorService.execProcessInstance(loginUser, projectCode, processDefinitionCode, "{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", @@ -455,7 +465,8 @@ public class ExecuteFunctionServiceTest { null, null, null, null, null, RunMode.RUN_MODE_PARALLEL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 110, null, 15, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 110, null, 15, + Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_NO, ComplementDependentMode.OFF_MODE, null); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -481,6 +492,7 @@ public class ExecuteFunctionServiceTest { RunMode.RUN_MODE_PARALLEL, Priority.LOW, Constants.DEFAULT_WORKER_GROUP, + tenantCode, 100L, 110, null, @@ -510,6 +522,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(commandService.verifyIsNeedCreateCommand(any(Command.class))).thenReturn(true); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, RERUN)) .thenReturn(checkProjectAndAuth()); + Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant()); Map result = executorService.execProcessInstance(loginUser, projectCode, processDefinitionCode, "{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", @@ -517,7 +530,8 @@ public class ExecuteFunctionServiceTest { null, null, null, null, 0, RunMode.RUN_MODE_PARALLEL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 100L, 110, null, 15, Constants.DRY_RUN_FLAG_NO, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, tenantCode, 100L, 110, null, 15, + Constants.DRY_RUN_FLAG_NO, Constants.TEST_FLAG_YES, ComplementDependentMode.OFF_MODE, null); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); @@ -630,7 +644,7 @@ public class ExecuteFunctionServiceTest { Mockito.when(processService.findProcessDefinition(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(processDefinition); - Mockito.when(processService.getTenantForProcess(Mockito.anyInt(), Mockito.anyInt())).thenReturn(new Tenant()); + Mockito.when(processService.getTenantForProcess(Mockito.anyString(), Mockito.anyInt())).thenReturn(tenantCode); when(processInstanceMock.getState().isFinished()).thenReturn(false); WorkflowExecuteResponse responseInstanceIsNotFinished = diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java index d1c493a64b..8f6d4c78fe 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java @@ -26,7 +26,6 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_ONLINE_OFFLINE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_TREE_VIEW; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_UPDATE; -import static org.apache.dolphinscheduler.common.constants.Constants.DEFAULT; import static org.apache.dolphinscheduler.common.constants.Constants.EMPTY_STRING; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isA; @@ -58,7 +57,6 @@ import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskMainInfo; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.UserWithProcessDefinitionCode; import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; @@ -68,7 +66,6 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.model.PageListingResult; import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao; @@ -167,9 +164,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Mock private ProcessInstanceService processInstanceService; - @Mock - private TenantMapper tenantMapper; - @Mock private DataSourceMapper dataSourceMapper; @@ -202,7 +196,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { protected final static int warningGroupId = 1; protected final static int timeout = 60; protected final static String executionType = "PARALLEL"; - protected final static String tenantCode = "tenant"; @BeforeEach public void before() { @@ -317,9 +310,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Project project = getProject(projectCode); - Tenant tenant = new Tenant(); - tenant.setId(1); - tenant.setTenantCode("root"); Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); @@ -345,7 +335,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { putMsg(result, Status.SUCCESS, projectCode); Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) .thenReturn(result); - Mockito.when(tenantMapper.queryById(1)).thenReturn(tenant); Map successRes = processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 46L); Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); @@ -833,7 +822,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { try { processDefinitionService.updateProcessDefinition(user, projectCode, "test", 1, - "", "", "", 0, "root", null, "", null, ProcessExecutionTypeEnum.PARALLEL); + "", "", "", 0, null, "", null, ProcessExecutionTypeEnum.PARALLEL); Assertions.fail(); } catch (ServiceException ex) { Assertions.assertEquals(Status.DATA_IS_NOT_VALID.getCode(), ex.getCode()); @@ -958,14 +947,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(), ((ServiceException) exception).getCode()); - // tenant not exists Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)).thenReturn(null); - exception = Assertions.assertThrows(ServiceException.class, - () -> processDefinitionService.createSingleProcessDefinition(user, workflowCreateRequest)); - Assertions.assertEquals(Status.TENANT_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); // test success - workflowCreateRequest.setTenantCode(DEFAULT); workflowCreateRequest.setDescription(description); workflowCreateRequest.setTimeout(timeout); workflowCreateRequest.setReleaseState(releaseState); @@ -1081,18 +1065,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(), ((ServiceException) exception).getCode()); - // error tenant code not exists - processDefinition = this.getProcessDefinition(); - workflowUpdateRequest.setTenantCode(tenantCode); Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); Mockito.when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) .thenReturn(null); - Mockito.when(tenantMapper.queryByTenantCode(workflowUpdateRequest.getTenantCode())).thenReturn(null); - exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService - .updateSingleProcessDefinition(user, processDefinitionCode, workflowUpdateRequest)); - Assertions.assertEquals(Status.TENANT_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); - workflowUpdateRequest.setTenantCode(null); - // error update process definition mapper workflowUpdateRequest.setName(name); Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); @@ -1154,7 +1129,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { processDefinition.setId(46); processDefinition.setProjectCode(1L); processDefinition.setName("test_pdf"); - processDefinition.setTenantId(1); processDefinition.setDescription(""); processDefinition.setCode(processDefinitionCode); processDefinition.setProjectCode(projectCode); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java index d748480eb8..0282049d44 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java @@ -591,7 +591,8 @@ public class ProcessInstanceServiceTest { Tenant tenant = getTenant(); when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); when(tenantMapper.queryByTenantCode("root")).thenReturn(tenant); - when(processService.getTenantForProcess(Mockito.anyInt(), Mockito.anyInt())).thenReturn(tenant); + when(processService.getTenantForProcess(Mockito.anyString(), Mockito.anyInt())) + .thenReturn(tenant.getTenantCode()); when(processInstanceDao.updateProcessInstance(processInstance)).thenReturn(1); when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.FALSE)).thenReturn(1); @@ -815,7 +816,6 @@ public class ProcessInstanceServiceTest { processDefinition.setId(46); processDefinition.setName("test_pdf"); processDefinition.setProjectCode(2L); - processDefinition.setTenantId(1); processDefinition.setDescription(""); return processDefinition; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceTest.java index b672c15430..474d619cc2 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceTest.java @@ -255,7 +255,6 @@ public class ProcessTaskRelationServiceTest { processDefinition.setId(1); processDefinition.setProjectCode(1L); processDefinition.setName("test_pdf"); - processDefinition.setTenantId(1); processDefinition.setDescription(""); processDefinition.setCode(1L); processDefinition.setVersion(1); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java index a510f42cd4..85d3d90fba 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java @@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.api.dto.schedule.ScheduleUpdateRequest; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.service.impl.SchedulerServiceImpl; +import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.ReleaseState; import org.apache.dolphinscheduler.common.model.Server; import org.apache.dolphinscheduler.dao.entity.Environment; @@ -39,6 +40,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; +import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.scheduler.api.SchedulerApi; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -96,6 +98,9 @@ public class SchedulerServiceTest extends BaseServiceTestTool { @Mock private EnvironmentMapper environmentMapper; + @Mock + private TenantMapper tenantMapper; + protected static User user; protected Exception exception; private static final String userName = "userName"; @@ -185,6 +190,7 @@ public class SchedulerServiceTest extends BaseServiceTestTool { ScheduleCreateRequest scheduleCreateRequest = new ScheduleCreateRequest(); scheduleCreateRequest.setProcessDefinitionCode(processDefinitionCode); scheduleCreateRequest.setEnvironmentCode(environmentCode); + scheduleCreateRequest.setTenantCode(Constants.DEFAULT); // error process definition not exists exception = Assertions.assertThrows(ServiceException.class, diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java index 2b9fc0125b..832b1f1c2c 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.service; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TENANT_CREATE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TENANT_DELETE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TENANT_UPDATE; +import static org.mockito.ArgumentMatchers.any; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ServiceException; @@ -31,13 +32,13 @@ import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.Queue; +import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; @@ -46,6 +47,7 @@ import org.apache.commons.collections4.CollectionUtils; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -86,7 +88,7 @@ public class TenantServiceTest { private TenantMapper tenantMapper; @Mock - private ProcessDefinitionMapper processDefinitionMapper; + private ScheduleMapper scheduleMapper; @Mock private ProcessInstanceMapper processInstanceMapper; @@ -171,7 +173,7 @@ public class TenantServiceTest { ids.add(1); Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.TENANT, getLoginUser().getId(), tenantServiceImplLogger)).thenReturn(ids); - Mockito.when(tenantMapper.queryTenantPaging(Mockito.any(Page.class), Mockito.anyList(), Mockito.eq(tenantDesc))) + Mockito.when(tenantMapper.queryTenantPaging(any(Page.class), Mockito.anyList(), Mockito.eq(tenantDesc))) .thenReturn(page); Result result = tenantService.queryTenantList(getLoginUser(), tenantDesc, 1, 10); PageInfo pageInfo = (PageInfo) result.getData(); @@ -209,10 +211,10 @@ public class TenantServiceTest { Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0, baseServiceLogger)).thenReturn(true); Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); - Mockito.when(processInstanceMapper.queryByTenantIdAndStatus(1, + Mockito.when(processInstanceMapper.queryByTenantCodeAndStatus(tenantCode, org.apache.dolphinscheduler.service.utils.Constants.NOT_TERMINATED_STATES)) .thenReturn(getInstanceList()); - Mockito.when(processDefinitionMapper.queryDefinitionListByTenant(2)).thenReturn(getDefinitionsList()); + Mockito.when(scheduleMapper.queryScheduleListByTenant(tenantCode)).thenReturn(getScheduleList()); Mockito.when(userMapper.queryUserListByTenant(3)).thenReturn(getUserList()); // TENANT_NOT_EXIST @@ -241,6 +243,10 @@ public class TenantServiceTest { Assertions.assertTrue(exception.getMessage().contains(prefix)); // success + Mockito.when(processInstanceMapper.queryByTenantCodeAndStatus(tenantCode, + org.apache.dolphinscheduler.service.utils.Constants.NOT_TERMINATED_STATES)) + .thenReturn(Collections.emptyList()); + Mockito.when(scheduleMapper.queryScheduleListByTenant(tenantCode)).thenReturn(Collections.emptyList()); Mockito.when(tenantMapper.queryById(4)).thenReturn(getTenant(4)); Mockito.when(tenantMapper.deleteById(4)).thenReturn(1); Map result = tenantService.deleteTenantById(getLoginUser(), 4); @@ -326,11 +332,11 @@ public class TenantServiceTest { return processInstances; } - private List getDefinitionsList() { - List processDefinitions = new ArrayList<>(); - ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinitions.add(processDefinition); - return processDefinitions; + private List getScheduleList() { + List schedules = new ArrayList<>(); + Schedule schedule = new Schedule(); + schedules.add(schedule); + return schedules; } private Queue getQueue() { diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java index 12d0a69fb7..d4c2d9a8ff 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java @@ -87,6 +87,11 @@ public class Command { @TableField("worker_group") private String workerGroup; + /** + * tenant code + */ + private String tenantCode; + @TableField("environment_code") private Long environmentCode; diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java index efacc1c92b..aa4d3d4782 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java @@ -112,6 +112,11 @@ public class ErrorCommand { */ private String workerGroup; + /** + * tenant code + */ + private String tenantCode; + /** * environment code */ diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java index 9304662342..8b6f3be9ca 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java @@ -148,17 +148,6 @@ public class ProcessDefinition { */ private int timeout; - /** - * tenant id - */ - private int tenantId; - - /** - * tenant code - */ - @TableField(exist = false) - private String tenantCode; - /** * modify user name */ @@ -183,9 +172,8 @@ public class ProcessDefinition { String globalParams, String locations, int timeout, - int userId, - int tenantId) { - set(projectCode, name, description, globalParams, locations, timeout, tenantId); + int userId) { + set(projectCode, name, description, globalParams, locations, timeout); this.code = code; this.userId = userId; Date date = new Date(); @@ -198,15 +186,13 @@ public class ProcessDefinition { String description, String globalParams, String locations, - int timeout, - int tenantId) { + int timeout) { this.projectCode = projectCode; this.name = name; this.description = description; this.globalParams = globalParams; this.locations = locations; this.timeout = timeout; - this.tenantId = tenantId; this.flag = Flag.YES; } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java index ec5fba8403..d9ce86c669 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java @@ -60,7 +60,6 @@ public class ProcessDefinitionLog extends ProcessDefinition { this.setLocations(processDefinition.getLocations()); this.setScheduleReleaseState(processDefinition.getScheduleReleaseState()); this.setTimeout(processDefinition.getTimeout()); - this.setTenantId(processDefinition.getTenantId()); this.setModifyBy(processDefinition.getModifyBy()); this.setWarningGroupId(processDefinition.getWarningGroupId()); this.setExecutionType(processDefinition.getExecutionType()); diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java index 70e89cfb80..d8f01f473f 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java @@ -124,8 +124,6 @@ public class ProcessInstance { private String executorName; - private int tenantId; - private String tenantCode; /** diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java index 82253900e0..a8f339082f 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java @@ -133,6 +133,11 @@ public class Schedule { */ private String workerGroup; + /** + * tenant code + */ + private String tenantCode; + /** * environment code */ diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java index 0e0ba3ee5b..806b91982e 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java @@ -150,14 +150,6 @@ public interface ProcessDefinitionMapper extends BaseMapper { */ List queryDefinitionListByIdList(@Param("ids") Integer[] ids); - /** - * query process definition by tenant - * - * @param tenantId tenantId - * @return process definition list - */ - List queryDefinitionListByTenant(@Param("tenantId") int tenantId); - /** * Statistics process definition group by project codes list *

diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java index ea9fe453b8..9048e6f3ba 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java @@ -63,14 +63,14 @@ public interface ProcessInstanceMapper extends BaseMapper { List queryNeedFailoverProcessInstanceHost(@Param("states") int[] stateArray); /** - * query process instance by tenantId and stateArray + * query process instance by tenantCode and stateArray * - * @param tenantId tenantId + * @param tenantCode tenantCode * @param states states array * @return process instance list */ - List queryByTenantIdAndStatus(@Param("tenantId") int tenantId, - @Param("states") int[] states); + List queryByTenantCodeAndStatus(@Param("tenantCode") String tenantCode, + @Param("states") int[] states); /** * @param workerGroupName workerGroupName @@ -139,14 +139,14 @@ public interface ProcessInstanceMapper extends BaseMapper { @Param("destState") WorkflowExecutionStatus destState); /** - * update process instance by tenantId + * update process instance by tenantCode * - * @param originTenantId originTenantId - * @param destTenantId destTenantId + * @param originTenantCode originTenantCode + * @param destTenantCode destTenantCode * @return update result */ - int updateProcessInstanceByTenantId(@Param("originTenantId") int originTenantId, - @Param("destTenantId") int destTenantId); + int updateProcessInstanceByTenantCode(@Param("originTenantCode") String originTenantCode, + @Param("destTenantCode") String destTenantCode); /** * update process instance by worker groupId diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java index 65e2022ef3..953fa35c47 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java @@ -104,4 +104,12 @@ public interface ScheduleMapper extends BaseMapper { * @return schedule */ List querySchedulesByProcessDefinitionCodes(@Param("processDefinitionCodeList") List processDefinitionCodeList); + + /** + * query schedule by tenant + * + * @param tenantCode tenantCode + * @return schedule list + */ + List queryScheduleListByTenant(@Param("tenantCode") String tenantCode); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/JsonSplitDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/JsonSplitDao.java index 0388e741de..d453651782 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/JsonSplitDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/JsonSplitDao.java @@ -39,10 +39,10 @@ public class JsonSplitDao { */ public void executeJsonSplitProcessDefinition(Connection conn, List processDefinitionLogs) { String updateSql = - "UPDATE t_ds_process_definition SET global_params=?,timeout=?,tenant_id=?,locations=?,update_time=? where id=?"; + "UPDATE t_ds_process_definition SET global_params=?,timeout=?,locations=?,update_time=? where id=?"; String insertLogSql = "insert into t_ds_process_definition_log (code,name,version,description,project_code,release_state,user_id," - + "global_params,flag,locations,timeout,tenant_id,operator,operate_time,create_time,update_time) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + "global_params,flag,locations,timeout,operator,operate_time,create_time,update_time) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; try { PreparedStatement processUpdate = conn.prepareStatement(updateSql); PreparedStatement insertLog = conn.prepareStatement(insertLogSql); @@ -50,10 +50,9 @@ public class JsonSplitDao { for (ProcessDefinitionLog processDefinitionLog : processDefinitionLogs) { processUpdate.setString(1, processDefinitionLog.getGlobalParams()); processUpdate.setInt(2, processDefinitionLog.getTimeout()); - processUpdate.setInt(3, processDefinitionLog.getTenantId()); - processUpdate.setString(4, processDefinitionLog.getLocations()); - processUpdate.setDate(5, new Date(processDefinitionLog.getUpdateTime().getTime())); - processUpdate.setInt(6, processDefinitionLog.getId()); + processUpdate.setString(3, processDefinitionLog.getLocations()); + processUpdate.setDate(4, new Date(processDefinitionLog.getUpdateTime().getTime())); + processUpdate.setInt(5, processDefinitionLog.getId()); processUpdate.addBatch(); insertLog.setLong(1, processDefinitionLog.getCode()); @@ -67,11 +66,10 @@ public class JsonSplitDao { insertLog.setInt(9, processDefinitionLog.getFlag().getCode()); insertLog.setString(10, processDefinitionLog.getLocations()); insertLog.setInt(11, processDefinitionLog.getTimeout()); - insertLog.setInt(12, processDefinitionLog.getTenantId()); - insertLog.setInt(13, processDefinitionLog.getOperator()); - insertLog.setDate(14, new Date(processDefinitionLog.getOperateTime().getTime())); - insertLog.setDate(15, new Date(processDefinitionLog.getCreateTime().getTime())); - insertLog.setDate(16, new Date(processDefinitionLog.getUpdateTime().getTime())); + insertLog.setInt(12, processDefinitionLog.getOperator()); + insertLog.setDate(13, new Date(processDefinitionLog.getOperateTime().getTime())); + insertLog.setDate(14, new Date(processDefinitionLog.getCreateTime().getTime())); + insertLog.setDate(15, new Date(processDefinitionLog.getUpdateTime().getTime())); insertLog.addBatch(); i++; diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml index 9d93e858a7..02dc6af11f 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml @@ -22,13 +22,13 @@ id, code, name, version, description, project_code, release_state, user_id,global_params, flag, locations, - warning_group_id, timeout, tenant_id,operator,execution_type, operate_time, create_time, + warning_group_id, timeout, operator, execution_type, operate_time, create_time, update_time select pd.id, pd.code, pd.name, pd.version, pd.release_state, pd.project_code, pd.user_id, pd.description, - pd.global_params, pd.flag, pd.locations, pd.warning_group_id, pd.create_time, pd.timeout, pd.tenant_id, pd.update_time,pd.execution_type + pd.global_params, pd.flag, pd.locations, pd.warning_group_id, pd.create_time, pd.timeout, pd.update_time,pd.execution_type from t_ds_process_definition pd WHERE pd.project_code = #{projectCode} and pd.name = #{processDefinitionName} @@ -57,13 +57,11 @@ @@ -124,12 +122,6 @@ - - select from t_ds_process_instance where 1=1 - - and tenant_id =#{tenantId} + + and tenant_code =#{tenantCode} and state in @@ -168,10 +168,10 @@ where state = #{originState} - + update t_ds_process_instance - set tenant_id = #{destTenantId} - where tenant_id = #{originTenantId} + set tenant_code = #{destTenantCode} + where tenant_code = #{originTenantCode} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml index c61db466de..86001a1fce 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml @@ -20,12 +20,12 @@ id, process_definition_code, start_time, end_time, timezone_id, crontab, failure_strategy, user_id, release_state, - warning_type, warning_group_id, process_instance_priority, worker_group, environment_code, create_time, update_time + warning_type, warning_group_id, process_instance_priority, worker_group, tenant_code, environment_code, create_time, update_time ${alias}.id, ${alias}.process_definition_code, ${alias}.start_time, ${alias}.end_time, ${alias}.timezone_id, ${alias}.crontab, ${alias}.failure_strategy, ${alias}.user_id, ${alias}.release_state, ${alias}.warning_type, - ${alias}.warning_group_id, ${alias}.process_instance_priority, ${alias}.worker_group, ${alias}.environment_code, ${alias}.create_time, + ${alias}.warning_group_id, ${alias}.process_instance_priority, ${alias}.worker_group, ${alias}.tenant_code, ${alias}.environment_code, ${alias}.create_time, ${alias}.update_time + + diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql index 81b99d4b39..ff73f5c13d 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql @@ -333,6 +333,7 @@ CREATE TABLE t_ds_command update_time datetime DEFAULT NULL, process_instance_priority int(11) DEFAULT '2', worker_group varchar(255), + tenant_code varchar(64) DEFAULT 'default', environment_code bigint(20) DEFAULT '-1', dry_run int NULL DEFAULT 0, process_instance_id int(11) DEFAULT 0, @@ -390,6 +391,7 @@ CREATE TABLE t_ds_error_command update_time datetime DEFAULT NULL, process_instance_priority int(11) DEFAULT '2', worker_group varchar(255), + tenant_code varchar(64) DEFAULT 'default', environment_code bigint(20) DEFAULT '-1', message text, dry_run int NULL DEFAULT 0, @@ -422,7 +424,6 @@ CREATE TABLE t_ds_process_definition locations text, warning_group_id int(11) DEFAULT NULL, timeout int(11) DEFAULT '0', - tenant_id int(11) NOT NULL DEFAULT '-1', execution_type tinyint(4) DEFAULT '0', create_time datetime NOT NULL, update_time datetime DEFAULT NULL, @@ -454,7 +455,6 @@ CREATE TABLE t_ds_process_definition_log locations text, warning_group_id int(11) DEFAULT NULL, timeout int(11) DEFAULT '0', - tenant_id int(11) NOT NULL DEFAULT '-1', execution_type tinyint(4) DEFAULT '0', operator int(11) DEFAULT NULL, operate_time datetime DEFAULT NULL, @@ -625,8 +625,7 @@ CREATE TABLE t_ds_process_instance environment_code bigint(20) DEFAULT '-1', timeout int(11) DEFAULT '0', next_process_instance_id int(11) DEFAULT '0', - tenant_id int(11) NOT NULL DEFAULT '-1', - tenant_code varchar(64) DEFAULT NULL, + tenant_code varchar(64) DEFAULT 'default', var_pool longtext, dry_run int NULL DEFAULT 0, restart_time datetime DEFAULT NULL, @@ -817,6 +816,7 @@ CREATE TABLE t_ds_schedules warning_group_id int(11) DEFAULT NULL, process_instance_priority int(11) DEFAULT '2', worker_group varchar(255) DEFAULT '', + tenant_code varchar(64) DEFAULT 'default', environment_code bigint(20) DEFAULT '-1', create_time datetime NOT NULL, update_time datetime NOT NULL, diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql index f1c92edc24..d45305336b 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql @@ -341,6 +341,7 @@ CREATE TABLE `t_ds_command` ( `update_time` datetime DEFAULT NULL COMMENT 'update time', `process_instance_priority` int(11) DEFAULT '2' COMMENT 'process instance priority: 0 Highest,1 High,2 Medium,3 Low,4 Lowest', `worker_group` varchar(255) COMMENT 'worker group', + `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code', `dry_run` tinyint(4) DEFAULT '0' COMMENT 'dry run flag:0 normal, 1 dry run', `test_flag` tinyint(4) DEFAULT null COMMENT 'test flag:0 normal, 1 test run', @@ -396,6 +397,7 @@ CREATE TABLE `t_ds_error_command` ( `update_time` datetime DEFAULT NULL COMMENT 'update time', `process_instance_priority` int(11) DEFAULT '2' COMMENT 'process instance priority, 0 Highest,1 High,2 Medium,3 Low,4 Lowest', `worker_group` varchar(255) COMMENT 'worker group', + `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code', `message` text COMMENT 'message', `dry_run` tinyint(4) DEFAULT '0' COMMENT 'dry run flag: 0 normal, 1 dry run', @@ -425,7 +427,6 @@ CREATE TABLE `t_ds_process_definition` ( `locations` text COMMENT 'Node location information', `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id', `timeout` int(11) DEFAULT '0' COMMENT 'time out, unit: minute', - `tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id', `execution_type` tinyint(4) DEFAULT '0' COMMENT 'execution_type 0:parallel,1:serial wait,2:serial discard,3:serial priority', `create_time` datetime NOT NULL COMMENT 'create time', `update_time` datetime NOT NULL COMMENT 'update time', @@ -455,7 +456,6 @@ CREATE TABLE `t_ds_process_definition_log` ( `locations` text COMMENT 'Node location information', `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id', `timeout` int(11) DEFAULT '0' COMMENT 'time out,unit: minute', - `tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id', `execution_type` tinyint(4) DEFAULT '0' COMMENT 'execution_type 0:parallel,1:serial wait,2:serial discard,3:serial priority', `operator` int(11) DEFAULT NULL COMMENT 'operator user id', `operate_time` datetime DEFAULT NULL COMMENT 'operate time', @@ -626,8 +626,7 @@ CREATE TABLE `t_ds_process_instance` ( `worker_group` varchar(255) DEFAULT NULL COMMENT 'worker group id', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code', `timeout` int(11) DEFAULT '0' COMMENT 'time out', - `tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id', - `tenant_code` varchar(64) DEFAULT NULL COMMENT 'tenant code', + `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code', `var_pool` longtext COMMENT 'var_pool', `dry_run` tinyint(4) DEFAULT '0' COMMENT 'dry run flag:0 normal, 1 dry run', `next_process_instance_id` int(11) DEFAULT '0' COMMENT 'serial queue next processInstanceId', @@ -814,6 +813,7 @@ CREATE TABLE `t_ds_schedules` ( `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id', `process_instance_priority` int(11) DEFAULT '2' COMMENT 'process instance priority:0 Highest,1 High,2 Medium,3 Low,4 Lowest', `worker_group` varchar(255) DEFAULT '' COMMENT 'worker group id', + `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code', `create_time` datetime NOT NULL COMMENT 'create time', `update_time` datetime NOT NULL COMMENT 'update time', diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql index ab1701f402..56e314de85 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql @@ -264,6 +264,7 @@ CREATE TABLE t_ds_command ( update_time timestamp DEFAULT NULL , process_instance_priority int DEFAULT '2' , worker_group varchar(255), + tenant_code varchar(64) DEFAULT 'default', environment_code bigint DEFAULT '-1', dry_run int DEFAULT '0' , process_instance_id int DEFAULT 0, @@ -314,6 +315,7 @@ CREATE TABLE t_ds_error_command ( update_time timestamp DEFAULT NULL , process_instance_priority int DEFAULT '2' , worker_group varchar(255), + tenant_code varchar(64) DEFAULT 'default', environment_code bigint DEFAULT '-1', dry_run int DEFAULT '0' , message text , @@ -341,7 +343,6 @@ CREATE TABLE t_ds_process_definition ( warning_group_id int DEFAULT NULL , flag int DEFAULT NULL , timeout int DEFAULT '0' , - tenant_id int DEFAULT '-1' , execution_type int DEFAULT '0', create_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL , @@ -370,7 +371,6 @@ CREATE TABLE t_ds_process_definition_log ( warning_group_id int DEFAULT NULL , flag int DEFAULT NULL , timeout int DEFAULT '0' , - tenant_id int DEFAULT '-1' , execution_type int DEFAULT '0', operator int DEFAULT NULL , operate_time timestamp DEFAULT NULL , @@ -554,8 +554,7 @@ CREATE TABLE t_ds_process_instance ( worker_group varchar(255) , environment_code bigint DEFAULT '-1', timeout int DEFAULT '0' , - tenant_id int NOT NULL DEFAULT '-1' , - tenant_code varchar(64) DEFAULT NULL , + tenant_code varchar(64) DEFAULT 'default', var_pool text , dry_run int DEFAULT '0' , next_process_instance_id int DEFAULT '0', @@ -724,6 +723,7 @@ CREATE TABLE t_ds_schedules ( warning_group_id int DEFAULT NULL , process_instance_priority int DEFAULT '2' , worker_group varchar(255), + tenant_code varchar(64) DEFAULT 'default', environment_code bigint DEFAULT '-1', create_time timestamp NOT NULL , update_time timestamp NOT NULL , diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl.sql index 8a56785d35..76662e4280 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl.sql @@ -234,7 +234,7 @@ delimiter ; CALL add_t_ds_task_instance_idx_cache_key; DROP PROCEDURE add_t_ds_task_instance_idx_cache_key; --- ALTER TABLE `t_ds_process_instance` ADD column `project_code`, `process_definition_name`, `executor_name`, `tenant_code`; +-- ALTER TABLE `t_ds_process_instance` ADD column `project_code`, `executor_name`, `tenant_code`; drop PROCEDURE if EXISTS add_t_ds_process_instance_add_project_code; delimiter d// CREATE PROCEDURE add_t_ds_process_instance_add_project_code() @@ -266,7 +266,7 @@ delimiter ; CALL add_t_ds_process_instance_add_project_code; DROP PROCEDURE add_t_ds_process_instance_add_project_code; --- ALTER TABLE `t_ds_task_instance` ADD column `project_code`, `process_definition_name`, `executor_name`, `tenant_code`; +-- ALTER TABLE `t_ds_task_instance` ADD column `project_code`, `process_definition_name`, `executor_name` drop PROCEDURE if EXISTS add_t_ds_task_instance_add_project_code; delimiter d// CREATE PROCEDURE add_t_ds_task_instance_add_project_code() @@ -381,4 +381,34 @@ ALTER TABLE `t_ds_k8s` MODIFY `k8s_name` varchar(255) DEFAULT NULL; ALTER TABLE `t_ds_k8s_namespace` MODIFY `namespace` varchar(255) DEFAULT NULL; ALTER TABLE `t_ds_cluster` MODIFY `name` varchar(255) NOT NULL COMMENT 'cluster name'; - +-- tenant improvement +DROP PROCEDURE if EXISTS add_improvement_workflow_run_tenant; +delimiter d// +CREATE PROCEDURE add_improvement_workflow_run_tenant() +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_command' + AND TABLE_SCHEMA=(SELECT DATABASE()) + AND COLUMN_NAME ='tenant_code') + THEN +ALTER TABLE t_ds_command ADD `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code'; +END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_error_command' + AND TABLE_SCHEMA=(SELECT DATABASE()) + AND COLUMN_NAME ='tenant_code') + THEN +ALTER TABLE t_ds_task_instance ADD `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code'; +END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_schedules' + AND TABLE_SCHEMA=(SELECT DATABASE()) + AND COLUMN_NAME ='tenant_code') + THEN +ALTER TABLE t_ds_task_instance ADD `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code'; +END IF; +END; +d// +delimiter ; +CALL add_improvement_workflow_run_tenant; +DROP PROCEDURE add_improvement_workflow_run_tenant; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl_post.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl_post.sql new file mode 100644 index 0000000000..82d05072f7 --- /dev/null +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl_post.sql @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +ALTER TABLE t_ds_process_definition DROP tenant_id; +ALTER TABLE t_ds_process_definition_log DROP tenant_id; +ALTER TABLE t_ds_process_instance DROP tenant_id; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_dml.sql index dc902aa9d4..41779422bc 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_dml.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_dml.sql @@ -32,4 +32,8 @@ d// delimiter ; CALL dolphin_t_ds_tenant_insert_default(); -DROP PROCEDURE dolphin_t_ds_tenant_insert_default; \ No newline at end of file +DROP PROCEDURE dolphin_t_ds_tenant_insert_default; + +-- tenant improvement +UPDATE t_ds_schedules t1 JOIN t_ds_process_definition t2 ON t1.process_definition_code = t2.code LEFT JOIN t_ds_tenant t3 ON t2.tenant_id = t3.id SET t1.tenant_code = COALESCE(t3.tenant_code, 'default'); +UPDATE `t_ds_process_instance` SET `tenant_code` = 'default' WHERE `tenant_code` IS NULL; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl.sql index 4fbf029383..e5c22cd5b5 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl.sql @@ -241,4 +241,41 @@ ALTER TABLE `t_ds_task_group_queue` MODIFY task_name VARCHAR(255) DEFAULT NUL ALTER TABLE `t_ds_task_group` MODIFY name varchar(255) DEFAULT NULL ; ALTER TABLE `t_ds_k8s` MODIFY k8s_name VARCHAR(255) DEFAULT NULL ; ALTER TABLE `t_ds_k8s_namespace` MODIFY namespace varchar(255) DEFAULT NULL ; -ALTER TABLE `t_ds_cluster` MODIFY name varchar(255) DEFAULT NULL; \ No newline at end of file +ALTER TABLE `t_ds_cluster` MODIFY name varchar(255) DEFAULT NULL; + +-- tenant improvement +delimiter ; +DROP FUNCTION IF EXISTS add_improvement_workflow_run_tenant(); +delimiter d// +CREATE FUNCTION add_improvement_workflow_run_tenant() RETURNS void AS $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_CATALOG=current_database() + AND TABLE_SCHEMA=current_schema() + AND TABLE_NAME='t_ds_command' + AND COLUMN_NAME ='tenant_code') + THEN +ALTER TABLE t_ds_command ADD `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code'; +END IF; +IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_CATALOG=current_database() + AND TABLE_SCHEMA=current_schema() + AND TABLE_NAME='t_ds_error_command' + AND COLUMN_NAME ='tenant_code') + THEN +ALTER TABLE t_ds_error_command ADD `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code'; +END IF; +IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_CATALOG=current_database() + AND TABLE_SCHEMA=current_schema() + AND TABLE_NAME='t_ds_schedules' + AND COLUMN_NAME ='tenant_code') + THEN +ALTER TABLE t_ds_schedules ADD `tenant_code` varchar(64) DEFAULT NULL COMMENT 'tenant code'; +END IF; +END; +$$ LANGUAGE plpgsql; +d// +delimiter ; +select add_improvement_workflow_run_tenant(); +DROP FUNCTION add_improvement_workflow_run_tenant(); diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl_post.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl_post.sql new file mode 100644 index 0000000000..3a77148a20 --- /dev/null +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl_post.sql @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +ALTER TABLE "t_ds_process_definition" DROP "tenant_id"; +ALTER TABLE "t_ds_process_definition_log" DROP "tenant_id"; +ALTER TABLE "t_ds_process_instance" DROP "tenant_id"; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_dml.sql index 75f63c268c..3573da5318 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_dml.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_dml.sql @@ -15,4 +15,8 @@ * limitations under the License. */ -INSERT INTO t_ds_tenant(id, tenant_code, description, queue_id, create_time, update_time) VALUES (-1, 'default', 'default tenant', '0', '2018-03-27 15:48:50', '2018-10-24 17:40:22'); \ No newline at end of file +INSERT INTO t_ds_tenant(id, tenant_code, description, queue_id, create_time, update_time) VALUES (-1, 'default', 'default tenant', '0', '2018-03-27 15:48:50', '2018-10-24 17:40:22'); + +-- tenant improvement +UPDATE t_ds_schedules t1 SET t1.tenant_code = COALESCE(t3.tenant_code, 'default') FROM t_ds_process_definition t2 LEFT JOIN t_ds_tenant t3 ON t2.tenant_id = t3.id WHERE t1.process_definition_code = t2.code; +UPDATE t_ds_process_instance SET tenant_code = 'default' WHERE tenant_code IS NULL; diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java index c96eebc8a5..de1c50633e 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java @@ -143,7 +143,6 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest { processDefinition.setProjectCode(project.getCode()); processDefinition.setUpdateTime(new Date()); processDefinition.setCreateTime(new Date()); - processDefinition.setTenantId(tenant.getId()); processDefinition.setUserId(user.getId()); processDefinitionMapper.insert(processDefinition); ProcessDefinition definition = processDefinitionMapper.verifyByDefineName(10L, "xxx"); @@ -187,7 +186,6 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest { processDefinition.setProjectCode(project.getCode()); processDefinition.setUpdateTime(new Date()); processDefinition.setCreateTime(new Date()); - processDefinition.setTenantId(tenant.getId()); processDefinition.setUserId(user.getId()); processDefinitionMapper.insert(processDefinition); @@ -195,24 +193,6 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest { Assertions.assertNotEquals(processDefinition1, null); } - /** - * test queryDefinitionListByTenant - */ - @Test - public void testQueryDefinitionListByTenant() { - ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinition.setCode(1L); - processDefinition.setName("def 1"); - processDefinition.setProjectCode(888L); - processDefinition.setUpdateTime(new Date()); - processDefinition.setCreateTime(new Date()); - processDefinition.setTenantId(999); - processDefinition.setUserId(1234); - processDefinitionMapper.insert(processDefinition); - List definitions = processDefinitionMapper.queryDefinitionListByTenant(999); - Assertions.assertNotEquals(definitions.size(), 0); - } - /** * test queryByDefineId */ @@ -250,7 +230,6 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest { processDefinition.setProjectCode(project.getCode()); processDefinition.setUpdateTime(new Date()); processDefinition.setCreateTime(new Date()); - processDefinition.setTenantId(tenant.getId()); processDefinition.setUserId(user.getId()); processDefinitionMapper.insert(processDefinition); ProcessDefinition definition = processDefinitionMapper.queryByDefineId(333); diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowE2ETest.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowE2ETest.java index 360cdb5ccf..06e2a55ccd 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowE2ETest.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowE2ETest.java @@ -118,7 +118,6 @@ class WorkflowE2ETest { .submit() .name(workflow) - .tenant(tenant) .addGlobalParam("global_param", "hello world") .submit() ; @@ -151,7 +150,6 @@ class WorkflowE2ETest { .submit() .name(workflow) - .tenant(tenant) .addGlobalParam("global_param", "hello world") .submit() ; diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java index f50c708ac3..fdd48399f6 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java @@ -130,7 +130,6 @@ class WorkflowSwitchE2ETest { workflowForm.submit() .name(workflow) - .tenant(tenant) .addGlobalParam("key", "1") .submit(); diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowSaveDialog.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowSaveDialog.java index ab54e6ea78..6f7b8470ae 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowSaveDialog.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowSaveDialog.java @@ -53,15 +53,6 @@ public final class WorkflowSaveDialog { }) private WebElement buttonGlobalCustomParameters; - @FindBys({ - @FindBy(className = "btn-select-tenant-code"), - @FindBy(className = "n-base-selection"), - }) - private WebElement selectTenant; - - @FindBy(className = "n-base-select-option__content") - private List selectTenantOption; - @FindBy(className = "input-global-params") private WebElement globalParamsItems; @@ -78,20 +69,6 @@ public final class WorkflowSaveDialog { return this; } - public WorkflowSaveDialog tenant(String tenant) { - selectTenant().click(); - - selectTenantOption() - .stream() - .filter(it -> it.getAttribute("innerText").contains(tenant)) - .findFirst() - .orElseThrow(() -> new RuntimeException(String.format("No %s in workflow save dialog tenant dropdown " + - "list", tenant))) - .click(); - - return this; - } - public WorkflowSaveDialog addGlobalParam(String key, String value) { final int len = globalParamsItems().findElements(By.tagName("input")).size(); diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/StreamTaskExecuteRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/StreamTaskExecuteRunnable.java index cda2310ef6..9689519940 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/StreamTaskExecuteRunnable.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/StreamTaskExecuteRunnable.java @@ -29,7 +29,6 @@ import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; import org.apache.dolphinscheduler.dao.entity.Resource; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.plugin.task.api.TaskChannel; @@ -332,10 +331,10 @@ public class StreamTaskExecuteRunnable implements Runnable { */ protected TaskExecutionContext getTaskExecutionContext(TaskInstance taskInstance) { int userId = taskDefinition == null ? 0 : taskDefinition.getUserId(); - Tenant tenant = processService.getTenantForProcess(processDefinition.getTenantId(), userId); + String tenantCode = processService.getTenantForProcess(taskExecuteStartMessage.getTenantCode(), userId); // verify tenant is null - if (tenant == null) { + if (StringUtils.isBlank(tenantCode)) { log.error("tenant not exists,task instance id : {}", taskInstance.getId()); return null; } @@ -357,7 +356,7 @@ public class StreamTaskExecuteRunnable implements Runnable { .buildParamInfo(propertyMap) .create(); - taskExecutionContext.setTenantCode(tenant.getTenantCode()); + taskExecutionContext.setTenantCode(tenantCode); taskExecutionContext.setProjectCode(processDefinition.getProjectCode()); taskExecutionContext.setProcessDefineCode(processDefinition.getCode()); taskExecutionContext.setProcessDefineVersion(processDefinition.getVersion()); diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java index 94bf85b965..6045e2609e 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java @@ -45,7 +45,6 @@ import org.apache.dolphinscheduler.dao.entity.DqRuleExecuteSql; import org.apache.dolphinscheduler.dao.entity.DqRuleInputEntry; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.UdfFunc; import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; @@ -655,7 +654,6 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { private String getTenantCode() { int userId = taskInstance.getProcessDefine() == null ? 0 : taskInstance.getProcessDefine().getUserId(); - Tenant tenant = processService.getTenantForProcess(taskInstance.getProcessInstance().getTenantId(), userId); - return tenant == null ? null : tenant.getTenantCode(); + return processService.getTenantForProcess(taskInstance.getProcessInstance().getTenantCode(), userId); } } diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/consumer/TaskPriorityQueueConsumerTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/consumer/TaskPriorityQueueConsumerTest.java index 135e7d0073..7c947fbcc2 100644 --- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/consumer/TaskPriorityQueueConsumerTest.java +++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/consumer/TaskPriorityQueueConsumerTest.java @@ -68,18 +68,20 @@ public class TaskPriorityQueueConsumerTest { @Autowired private ExecutorDispatcher dispatcher; + private static final String TENANT_CODE = "root"; + @BeforeEach public void init() { Tenant tenant = new Tenant(); tenant.setId(1); - tenant.setTenantCode("journey"); - tenant.setDescription("journey"); + tenant.setTenantCode(TENANT_CODE); + tenant.setDescription(TENANT_CODE); tenant.setQueueId(1); tenant.setCreateTime(new Date()); tenant.setUpdateTime(new Date()); - Mockito.doReturn(tenant).when(processService).getTenantForProcess(1, 2); + Mockito.doReturn(tenant).when(processService).getTenantForProcess(TENANT_CODE, 2); } @Test @@ -95,7 +97,7 @@ public class TaskPriorityQueueConsumerTest { ProcessInstance processInstance = new ProcessInstance(); processInstance.setId(1); - processInstance.setTenantId(1); + processInstance.setTenantCode(TENANT_CODE); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); @@ -123,7 +125,7 @@ public class TaskPriorityQueueConsumerTest { taskInstance.setExecutorId(2); ProcessInstance processInstance = new ProcessInstance(); - processInstance.setTenantId(1); + processInstance.setTenantCode(TENANT_CODE); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); @@ -164,7 +166,7 @@ public class TaskPriorityQueueConsumerTest { taskInstance.setExecutorId(2); ProcessInstance processInstance = new ProcessInstance(); - processInstance.setTenantId(1); + processInstance.setTenantCode(TENANT_CODE); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); @@ -203,7 +205,7 @@ public class TaskPriorityQueueConsumerTest { taskInstance.setExecutorId(2); ProcessInstance processInstance = new ProcessInstance(); - processInstance.setTenantId(1); + processInstance.setTenantCode(TENANT_CODE); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); @@ -260,7 +262,7 @@ public class TaskPriorityQueueConsumerTest { ProcessInstance processInstance = new ProcessInstance(); processInstance.setId(1); - processInstance.setTenantId(1); + processInstance.setTenantCode(TENANT_CODE); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); @@ -293,7 +295,7 @@ public class TaskPriorityQueueConsumerTest { ProcessInstance processInstance = new ProcessInstance(); processInstance.setId(1); - processInstance.setTenantId(1); + processInstance.setTenantCode(TENANT_CODE); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); @@ -334,7 +336,7 @@ public class TaskPriorityQueueConsumerTest { ProcessInstance processInstance = new ProcessInstance(); processInstance.setId(1); - processInstance.setTenantId(1); + processInstance.setTenantCode(TENANT_CODE); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessorTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessorTest.java index 68f1214c80..30c4de3cbf 100644 --- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessorTest.java +++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessorTest.java @@ -104,7 +104,7 @@ public class CommonTaskProcessorTest { ProcessInstance processInstance = new ProcessInstance(); processInstance.setId(1); - processInstance.setTenantId(1); + processInstance.setTenantCode("default"); processInstance.setCommandType(CommandType.START_PROCESS); taskInstance.setProcessInstance(processInstance); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/task/TaskExecuteStartMessage.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/task/TaskExecuteStartMessage.java index 5b8530186a..619fb8e2c9 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/task/TaskExecuteStartMessage.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/task/TaskExecuteStartMessage.java @@ -54,7 +54,7 @@ public class TaskExecuteStartMessage extends BaseMessage { private Map startParams; - private int tenantId; + private String tenantCode; private int dryRun; diff --git a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/ProcessScheduleTask.java b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/ProcessScheduleTask.java index b0d0bb39ff..2c189d2bf8 100644 --- a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/ProcessScheduleTask.java +++ b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/ProcessScheduleTask.java @@ -99,6 +99,7 @@ public class ProcessScheduleTask extends QuartzJobBean { String workerGroup = StringUtils.isEmpty(schedule.getWorkerGroup()) ? Constants.DEFAULT_WORKER_GROUP : schedule.getWorkerGroup(); command.setWorkerGroup(workerGroup); + command.setTenantCode(schedule.getTenantCode()); command.setEnvironmentCode(schedule.getEnvironmentCode()); command.setWarningType(schedule.getWarningType()); command.setProcessInstancePriority(schedule.getProcessInstancePriority()); diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java index bfacd6fc0e..97c9e9f28e 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java @@ -45,7 +45,6 @@ import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskGroupQueue; import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.UdfFunc; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; @@ -83,7 +82,7 @@ public interface ProcessService { void recurseFindSubProcess(long parentCode, List ids); - Tenant getTenantForProcess(int tenantId, int userId); + String getTenantForProcess(String tenantCode, int userId); Environment findEnvironmentByCode(Long environmentCode); diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java index 676207c3bf..43196ad569 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java @@ -631,15 +631,12 @@ public class ProcessServiceImpl implements ProcessService { // set process instance priority processInstance.setProcessInstancePriority(command.getProcessInstancePriority()); - String workerGroup = Strings.isNullOrEmpty(command.getWorkerGroup()) ? Constants.DEFAULT_WORKER_GROUP - : command.getWorkerGroup(); + String workerGroup = StringUtils.defaultIfEmpty(command.getWorkerGroup(), Constants.DEFAULT_WORKER_GROUP); processInstance.setWorkerGroup(workerGroup); processInstance .setEnvironmentCode(Objects.isNull(command.getEnvironmentCode()) ? -1 : command.getEnvironmentCode()); processInstance.setTimeout(processDefinition.getTimeout()); - processInstance.setTenantId(processDefinition.getTenantId()); - processInstance.setTenantCode(Optional.ofNullable(tenantMapper.queryById(processDefinition.getTenantId())) - .map(Tenant::getTenantCode).orElse(null)); + processInstance.setTenantCode(command.getTenantCode()); return processInstance; } @@ -678,31 +675,29 @@ public class ProcessServiceImpl implements ProcessService { } /** - * get process tenant - * there is tenant id in definition, use the tenant of the definition. - * if there is not tenant id in the definiton or the tenant not exist - * use definition creator's tenant. + * Get workflow runtime tenant * - * @param tenantId tenantId + * the workflow provides a tenant and uses the provided tenant; + * when no tenant is provided or the provided tenant is the default tenant, \ + * the user's tenant created by the workflow is used + * + * @param tenantCode tenantCode * @param userId userId - * @return tenant + * @return tenant code */ @Override - public Tenant getTenantForProcess(int tenantId, int userId) { - Tenant tenant = null; - if (tenantId >= 0) { - tenant = tenantMapper.queryById(tenantId); + public String getTenantForProcess(String tenantCode, int userId) { + if (StringUtils.isNoneBlank(tenantCode) && !Constants.DEFAULT.equals(tenantCode)) { + return tenantCode; } if (userId == 0) { return null; } - if (tenant == null) { - User user = userMapper.selectById(userId); - tenant = tenantMapper.queryById(user.getTenantId()); - } - return tenant; + User user = userMapper.selectById(userId); + Tenant tenant = tenantMapper.queryById(user.getTenantId()); + return tenant.getTenantCode(); } /** diff --git a/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v200/V200DolphinSchedulerUpgrader.java b/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v200/V200DolphinSchedulerUpgrader.java index c986119d8c..f14ed15d22 100644 --- a/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v200/V200DolphinSchedulerUpgrader.java +++ b/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v200/V200DolphinSchedulerUpgrader.java @@ -144,8 +144,6 @@ public class V200DolphinSchedulerUpgrader implements DolphinSchedulerUpgrader { ObjectNode jsonObject = JSONUtils.parseObject(entry.getValue()); ProcessDefinition processDefinition = processDefinitionMap.get(entry.getKey()); if (processDefinition != null) { - processDefinition - .setTenantId(jsonObject.get("tenantId") == null ? -1 : jsonObject.get("tenantId").asInt()); processDefinition.setTimeout(jsonObject.get("timeout").asInt()); processDefinition.setGlobalParams(jsonObject.get("globalParams").toString()); } else { diff --git a/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v320/V320DolphinSchedulerUpgrader.java b/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v320/V320DolphinSchedulerUpgrader.java index d33c9017d1..61405b7ffc 100644 --- a/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v320/V320DolphinSchedulerUpgrader.java +++ b/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v320/V320DolphinSchedulerUpgrader.java @@ -17,20 +17,23 @@ package org.apache.dolphinscheduler.tools.datasource.upgrader.v320; +import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; +import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; +import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; -import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; +import org.apache.dolphinscheduler.tools.datasource.dao.UpgradeDao; import org.apache.dolphinscheduler.tools.datasource.upgrader.DolphinSchedulerUpgrader; import org.apache.dolphinscheduler.tools.datasource.upgrader.DolphinSchedulerVersion; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; @@ -39,6 +42,7 @@ import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -55,7 +59,7 @@ public class V320DolphinSchedulerUpgrader implements DolphinSchedulerUpgrader { private ProcessDefinitionLogMapper processDefinitionLogMapper; @Autowired - private TenantMapper tenantMapper; + private ScheduleMapper scheduleMapper; @Autowired private UserMapper userMapper; @@ -63,16 +67,19 @@ public class V320DolphinSchedulerUpgrader implements DolphinSchedulerUpgrader { @Autowired private TaskInstanceMapper taskInstanceMapper; + @Lazy() + @Autowired + private UpgradeDao upgradeDao; + @Override public void doUpgrade() { upgradeWorkflowInstance(); upgradeTaskInstance(); + upgradeDao.upgradeDolphinSchedulerDDL(getCurrentVersion().getVersionName() + "_schema", + "dolphinscheduler_ddl_post.sql"); } private void upgradeWorkflowInstance() { - Map tenantMap = tenantMapper.selectList(new QueryWrapper<>()) - .stream() - .collect(Collectors.toMap(Tenant::getId, Tenant::getTenantCode)); Map userMap = userMapper.selectList(new QueryWrapper<>()) .stream() .collect(Collectors.toMap(User::getId, User::getUserName)); @@ -92,9 +99,12 @@ public class V320DolphinSchedulerUpgrader implements DolphinSchedulerUpgrader { processDefinitionLogMapper.queryByDefinitionCodeAndVersion( processInstance.getProcessDefinitionCode(), processInstance.getProcessDefinitionVersion()); + Schedule schedule = + scheduleMapper.queryByProcessDefinitionCode(processInstance.getProcessDefinitionCode()); if (processDefinitionLog != null) { processInstance.setProjectCode(processDefinitionLog.getProjectCode()); - processInstance.setTenantCode(tenantMap.get(processDefinitionLog.getTenantId())); + processInstance.setTenantCode( + StringUtils.defaultIfEmpty(schedule.getTenantCode(), Constants.DEFAULT)); processInstance.setExecutorName(userMap.get(processInstance.getExecutorId())); } else { processInstance.setProjectCode(-1L); diff --git a/dolphinscheduler-ui/src/locales/en_US/project.ts b/dolphinscheduler-ui/src/locales/en_US/project.ts index 7c7b85557e..58ab0618da 100644 --- a/dolphinscheduler-ui/src/locales/en_US/project.ts +++ b/dolphinscheduler-ui/src/locales/en_US/project.ts @@ -109,6 +109,7 @@ export default { notification_strategy: 'Notification Strategy', workflow_priority: 'Workflow Priority', worker_group: 'Worker Group', + tenant_code: 'Tenant', environment_name: 'Environment Name', alarm_group: 'Alarm Group', complement_data: 'Complement Data', @@ -276,6 +277,7 @@ export default { set_parameters_before_starting: 'Please set the parameters before starting', notification_strategy: 'Notification Strategy', worker_group: 'Worker group', + tenant_code: 'Tenant', environment_name: 'Environment Name', alarm_group: 'Alarm group', startup_parameter: 'Startup Parameter', @@ -301,7 +303,6 @@ export default { copy_success: 'Copy Success', workflow_name: 'Workflow Name', description: 'Description', - tenant: 'Tenant', timeout_alert: 'Timeout Alert', process_execute_type: 'Process execute type', parallel: 'parallel', diff --git a/dolphinscheduler-ui/src/locales/zh_CN/project.ts b/dolphinscheduler-ui/src/locales/zh_CN/project.ts index 400e370214..e44c7dfa16 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/project.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/project.ts @@ -111,6 +111,7 @@ export default { notification_strategy: '通知策略', workflow_priority: '流程优先级', worker_group: 'Worker分组', + tenant_code: '租户', environment_name: '环境名称', alarm_group: '告警组', complement_data: '补数', @@ -276,6 +277,7 @@ export default { set_parameters_before_starting: '启动前请先设置参数', notification_strategy: '通知策略', worker_group: 'Worker分组', + tenant_code: '租户', environment_name: '环境名称', alarm_group: '告警组', startup_parameter: '启动参数', @@ -301,7 +303,6 @@ export default { copy_success: '复制成功', workflow_name: '工作流名称', description: '描述', - tenant: '租户', timeout_alert: '超时告警', process_execute_type: '执行策略', parallel: '并行', diff --git a/dolphinscheduler-ui/src/service/modules/process-definition/types.ts b/dolphinscheduler-ui/src/service/modules/process-definition/types.ts index 7f5b6ae0c5..7bd71db907 100644 --- a/dolphinscheduler-ui/src/service/modules/process-definition/types.ts +++ b/dolphinscheduler-ui/src/service/modules/process-definition/types.ts @@ -58,7 +58,6 @@ interface ProcessDefinitionReq { locations: string taskDefinitionJson: string taskRelationJson: string - tenantCode: string executionType: string description?: string globalParams?: string diff --git a/dolphinscheduler-ui/src/service/modules/process-instances/types.ts b/dolphinscheduler-ui/src/service/modules/process-instances/types.ts index ca6f79ce1a..da932e5614 100644 --- a/dolphinscheduler-ui/src/service/modules/process-instances/types.ts +++ b/dolphinscheduler-ui/src/service/modules/process-instances/types.ts @@ -79,7 +79,6 @@ interface ProcessInstanceReq { scheduleTime?: string taskDefinitionJson?: string taskRelationJson?: string - tenantCode?: string timeout?: number } diff --git a/dolphinscheduler-ui/src/views/projects/task/definition/components/start-modal.tsx b/dolphinscheduler-ui/src/views/projects/task/definition/components/start-modal.tsx index 0834a2d2cc..10b2098058 100644 --- a/dolphinscheduler-ui/src/views/projects/task/definition/components/start-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/task/definition/components/start-modal.tsx @@ -62,6 +62,7 @@ export default defineComponent({ variables, handleStartDefinition, getWorkerGroups, + getTenantList, getAlertGroups, getEnvironmentList, getStartParamsList @@ -118,6 +119,7 @@ export default defineComponent({ onMounted(() => { getWorkerGroups() + getTenantList() getAlertGroups() getEnvironmentList() }) @@ -178,6 +180,12 @@ export default defineComponent({ v-model:value={this.startForm.workerGroup} /> + + + { + queryTenantList().then((res: any) => { + variables.startState.tenantList = res.map((item: any) => ({ + label: item.tenantCode, + value: item.tenantCode + })) + }) + } + const getEnvironmentList = () => { queryAllEnvironmentList().then((res: Array) => { variables.startState.environmentList = res.map((item) => ({ @@ -135,6 +147,7 @@ export const useStart = ( return { variables, getWorkerGroups, + getTenantList, getEnvironmentList, getAlertGroups, getStartParamsList, diff --git a/dolphinscheduler-ui/src/views/projects/task/definition/types.ts b/dolphinscheduler-ui/src/views/projects/task/definition/types.ts index 3ca196bd72..d62ffb1787 100644 --- a/dolphinscheduler-ui/src/views/projects/task/definition/types.ts +++ b/dolphinscheduler-ui/src/views/projects/task/definition/types.ts @@ -31,6 +31,7 @@ interface IRecord { interface IStartState { projectCode: number workerGroups: Array + tenantList: Array alertGroups: Array environmentList: Array startParamsList: Array diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx index 17ef9a9e3b..f977e2e4c6 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx @@ -19,7 +19,6 @@ import { defineComponent, PropType, ref, - computed, onMounted, watch, getCurrentInstance @@ -36,14 +35,11 @@ import { NDynamicInput, NCheckbox } from 'naive-ui' -import { queryTenantList } from '@/service/modules/tenants' import { useRoute } from 'vue-router' -import { useUserStore } from '@/store/user/user' import { verifyName } from '@/service/modules/process-definition' import './x6-style.scss' import { positiveIntegerRegex } from '@/utils/regex' import type { SaveForm, WorkflowDefinition, WorkflowInstance } from './types' -import type { UserInfoRes } from '@/service/modules/users/types' const props = { visible: { @@ -61,11 +57,6 @@ const props = { } } -interface Tenant { - tenantCode: string - id: number -} - export default defineComponent({ name: 'dag-save-modal', props, @@ -75,28 +66,10 @@ export default defineComponent({ const { t } = useI18n() const projectCode = Number(route.params.projectCode) - const userInfo = useUserStore().getUserInfo as UserInfoRes - const tenants = ref([]) - const tenantsDropdown = computed(() => { - if (tenants.value) { - return tenants.value - .map((t) => ({ - label: t.tenantCode, - value: t.tenantCode - })) - } - return [] - }) - onMounted(() => { - queryTenantList().then((res: any) => { - tenants.value = res - }) - }) const formValue = ref({ name: '', description: '', - tenantCode: userInfo.tenantCode || 'default', executionType: 'PARALLEL', timeoutFlag: false, timeout: 0, @@ -170,7 +143,6 @@ export default defineComponent({ if (process) { formValue.value.name = process.name formValue.value.description = process.description - formValue.value.tenantCode = process.tenantCode || userInfo.tenantCode || 'default' formValue.value.executionType = process.executionType || 'PARALLEL' if (process.timeout && process.timeout > 0) { formValue.value.timeoutFlag = true @@ -216,13 +188,6 @@ export default defineComponent({ class='input-description' /> - - - diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx index 5b3102c6f0..0887f2324f 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx @@ -103,6 +103,7 @@ export default defineComponent({ render() { const { t } = this + // @ts-ignore return (

    @@ -153,6 +154,10 @@ export default defineComponent({ : '-'} +
  • + {t('project.workflow.tenant_code')}: + {this.startupParam?.tenantCode} +
  • {t('project.workflow.notification_strategy')}: diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/types.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/types.ts index a68fe25003..454f289d00 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dag/types.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dag/types.ts @@ -113,6 +113,7 @@ export interface WorkflowInstance { failureStrategy: string processInstancePriority: string workerGroup: string + tenantCode: string warningType: string warningGroupId: number } @@ -142,7 +143,6 @@ export interface GlobalParam { export interface SaveForm { name: string description: string - tenantCode: string executionType: string timeoutFlag: boolean timeout: number @@ -163,6 +163,7 @@ export interface IStartupParam { failureStrategy: string processInstancePriority: string workerGroup: string + tenantCode: string warningType: string warningGroupId: number } diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/start-modal.tsx b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/start-modal.tsx index a3e057def2..cfacf510cc 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/start-modal.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/start-modal.tsx @@ -82,6 +82,7 @@ export default defineComponent({ variables, handleStartDefinition, getWorkerGroups, + getTenantList, getAlertGroups, getEnvironmentList, getStartParamsList @@ -92,7 +93,7 @@ export default defineComponent({ } const handleStart = () => { - handleStartDefinition(props.row.code,props.row.version) + handleStartDefinition(props.row.code, props.row.version) } const generalWarningTypeListOptions = () => [ @@ -195,6 +196,7 @@ export default defineComponent({ onMounted(() => { getWorkerGroups() + getTenantList() getAlertGroups() getEnvironmentList() }) @@ -311,6 +313,16 @@ export default defineComponent({ v-model:value={this.startForm.workerGroup} /> + + + + - {this.startForm.warningType !== 'NONE' && ( - - )} + {this.startForm.warningType !== 'NONE' && ( + + + + )} { getWorkerGroups() + getTenantList() getAlertGroups() getEnvironmentList() }) @@ -209,6 +211,7 @@ export default defineComponent({ timingState.timingForm.processInstancePriority = props.row.processInstancePriority timingState.timingForm.workerGroup = props.row.workerGroup + timingState.timingForm.tenantCode = props.row.tenantCode initWarningGroup() initEnvironment() } @@ -368,6 +371,15 @@ export default defineComponent({ v-model:value={this.timingForm.workerGroup} /> + + + - {this.timingForm.warningType !== 'NONE' && ( - - )} + {this.timingForm.warningType !== 'NONE' && ( + + + + )} ) diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/types.ts b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/types.ts index 28fb164262..222924f6a5 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/types.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/types.ts @@ -36,6 +36,7 @@ export interface IParam { export interface ITimingState { projectCode: number workerGroups: Array + tenantList: Array alertGroups: Array environmentList: Array startParamsList: Array diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-form.ts b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-form.ts index 2b353a8626..1c793957a9 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-form.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-form.ts @@ -63,6 +63,7 @@ export const useForm = () => { runMode: 'RUN_MODE_SERIAL', processInstancePriority: 'MEDIUM', workerGroup: 'default', + tenantCode: 'default', environmentCode: null, startParams: null, expectedParallelismNumber: '', @@ -106,6 +107,7 @@ export const useForm = () => { processInstancePriority: 'MEDIUM', warningGroupId: null as null | number, workerGroup: 'default', + tenantCode: 'default', environmentCode: null as null | string }, saving: false diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts index d5d1b19c5a..a1174479e1 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts @@ -38,6 +38,7 @@ import { import { parseTime } from '@/common/common' import { EnvironmentItem } from '@/service/modules/environment/types' import { ITimingState, ProcessInstanceReq } from './types' +import { queryTenantList } from '@/service/modules/tenants' export function useModal( state: any, @@ -50,6 +51,7 @@ export function useModal( const variables = reactive({ projectCode: Number(route.params.projectCode), workerGroups: [], + tenantList: [], alertGroups: [], environmentList: [], startParamsList: [], @@ -219,6 +221,7 @@ export function useModal( ? state.timingForm.warningGroupId : 0, workerGroup: state.timingForm.workerGroup, + tenantCode: state.timingForm.tenantCode, environmentCode: state.timingForm.environmentCode } return data @@ -233,6 +236,15 @@ export function useModal( }) } + const getTenantList = () => { + queryTenantList().then((res: any) => { + variables.tenantList = res.map((item: any) => ({ + label: item.tenantCode, + value: item.tenantCode + })) + }) + } + const getEnvironmentList = () => { queryAllEnvironmentList().then((res: Array) => { variables.environmentList = res.map((item) => ({ @@ -300,6 +312,7 @@ export function useModal( handleUpdateTiming, handleBatchCopyDefinition, getWorkerGroups, + getTenantList, getAlertGroups, getEnvironmentList, getStartParamsList, diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/create/index.tsx b/dolphinscheduler-ui/src/views/projects/workflow/definition/create/index.tsx index d15440ab7b..bc97fd8558 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/create/index.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/create/index.tsx @@ -69,7 +69,6 @@ export default defineComponent({ taskRelationJson: JSON.stringify(connects), locations: JSON.stringify(locations), name: saveForm.name, - tenantCode: saveForm.tenantCode, executionType: saveForm.executionType, description: saveForm.description, globalParams: JSON.stringify(globalParams), diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/detail/index.tsx b/dolphinscheduler-ui/src/views/projects/workflow/definition/detail/index.tsx index 8a090f5b09..d9c573633c 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/detail/index.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/detail/index.tsx @@ -95,7 +95,6 @@ export default defineComponent({ taskRelationJson: JSON.stringify(connects), locations: JSON.stringify(locations), name: saveForm.name, - tenantCode: saveForm.tenantCode, executionType: saveForm.executionType, description: saveForm.description, globalParams: JSON.stringify(globalParams), diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/timing/use-table.ts b/dolphinscheduler-ui/src/views/projects/workflow/definition/timing/use-table.ts index 308daaad27..061e353172 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/timing/use-table.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/timing/use-table.ts @@ -128,6 +128,11 @@ export function useTable() { key: 'workerGroup', width: 140 }, + { + title: t('project.workflow.tenant_code'), + key: 'tenantCode', + width: 140 + }, { title: t('project.workflow.environment_name'), key: 'environmentName', diff --git a/dolphinscheduler-ui/src/views/projects/workflow/instance/detail/index.tsx b/dolphinscheduler-ui/src/views/projects/workflow/instance/detail/index.tsx index 8ea1b54828..8ea767659c 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/instance/detail/index.tsx +++ b/dolphinscheduler-ui/src/views/projects/workflow/instance/detail/index.tsx @@ -93,7 +93,6 @@ export default defineComponent({ locations: JSON.stringify(locations), taskDefinitionJson: JSON.stringify(taskDefinitions), taskRelationJson: JSON.stringify(connects), - tenantCode: saveForm.tenantCode, timeout: saveForm.timeoutFlag ? saveForm.timeout : 0 }, id,