Browse Source

[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
3.2.0-release
Kerwin 2 years ago committed by GitHub
parent
commit
79cb707b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java
  2. 16
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java
  3. 17
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
  4. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/schedule/ScheduleCreateRequest.java
  5. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowCreateRequest.java
  6. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowUpdateRequest.java
  7. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  8. 11
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
  9. 9
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java
  10. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
  11. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
  12. 34
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java
  13. 105
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  14. 18
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
  15. 45
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
  16. 22
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java
  17. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/ScheduleVo.java
  18. 15
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecuteFunctionControllerTest.java
  19. 10
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java
  20. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
  21. 3
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/WorkflowV2ControllerTest.java
  22. 40
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecuteFunctionServiceTest.java
  23. 28
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  24. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
  25. 1
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceTest.java
  26. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java
  27. 28
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java
  28. 5
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java
  29. 5
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java
  30. 20
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java
  31. 1
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionLog.java
  32. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java
  33. 5
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java
  34. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java
  35. 16
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java
  36. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java
  37. 20
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/JsonSplitDao.java
  38. 4
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml
  39. 18
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml
  40. 16
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml
  41. 11
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml
  42. 8
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql
  43. 8
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql
  44. 8
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql
  45. 36
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl.sql
  46. 20
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_ddl_post.sql
  47. 4
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_dml.sql
  48. 37
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl.sql
  49. 20
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl_post.sql
  50. 4
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_dml.sql
  51. 21
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java
  52. 2
      dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowE2ETest.java
  53. 1
      dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java
  54. 23
      dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowSaveDialog.java
  55. 7
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/StreamTaskExecuteRunnable.java
  56. 4
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java
  57. 22
      dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/consumer/TaskPriorityQueueConsumerTest.java
  58. 2
      dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/task/CommonTaskProcessorTest.java
  59. 2
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/task/TaskExecuteStartMessage.java
  60. 1
      dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/ProcessScheduleTask.java
  61. 3
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
  62. 33
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
  63. 2
      dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v200/V200DolphinSchedulerUpgrader.java
  64. 24
      dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v320/V320DolphinSchedulerUpgrader.java
  65. 3
      dolphinscheduler-ui/src/locales/en_US/project.ts
  66. 3
      dolphinscheduler-ui/src/locales/zh_CN/project.ts
  67. 1
      dolphinscheduler-ui/src/service/modules/process-definition/types.ts
  68. 1
      dolphinscheduler-ui/src/service/modules/process-instances/types.ts
  69. 8
      dolphinscheduler-ui/src/views/projects/task/definition/components/start-modal.tsx
  70. 13
      dolphinscheduler-ui/src/views/projects/task/definition/components/use-start.tsx
  71. 1
      dolphinscheduler-ui/src/views/projects/task/definition/types.ts
  72. 35
      dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx
  73. 5
      dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx
  74. 3
      dolphinscheduler-ui/src/views/projects/workflow/components/dag/types.ts
  75. 18
      dolphinscheduler-ui/src/views/projects/workflow/definition/components/start-modal.tsx
  76. 18
      dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx
  77. 1
      dolphinscheduler-ui/src/views/projects/workflow/definition/components/types.ts
  78. 2
      dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-form.ts
  79. 13
      dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts
  80. 1
      dolphinscheduler-ui/src/views/projects/workflow/definition/create/index.tsx
  81. 1
      dolphinscheduler-ui/src/views/projects/workflow/definition/detail/index.tsx
  82. 5
      dolphinscheduler-ui/src/views/projects/workflow/definition/timing/use-table.ts
  83. 1
      dolphinscheduler-ui/src/views/projects/workflow/instance/detail/index.tsx

15
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 = "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 = "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 = "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 = "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 = "timeout", description = "TIMEOUT", schema = @Schema(implementation = int.class, example = "100")),
@Parameter(name = "expectedParallelismNumber", description = "EXPECTED_PARALLELISM_NUMBER", schema = @Schema(implementation = int.class, example = "8")), @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 = "runMode", required = false) RunMode runMode,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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 = "environmentCode", required = false, defaultValue = "-1") Long environmentCode,
@RequestParam(value = "timeout", required = false) Integer timeout, @RequestParam(value = "timeout", required = false) Integer timeout,
@RequestParam(value = "startParams", required = false) String startParams, @RequestParam(value = "startParams", required = false) String startParams,
@ -164,7 +166,8 @@ public class ExecutorController extends BaseController {
Map<String, Object> result = execService.execProcessInstance(loginUser, projectCode, processDefinitionCode, Map<String, Object> result = execService.execProcessInstance(loginUser, projectCode, processDefinitionCode,
scheduleTime, execType, failureStrategy, scheduleTime, execType, failureStrategy,
startNodeList, taskDependType, warningType, warningGroupId, runMode, processInstancePriority, startNodeList, taskDependType, warningType, warningGroupId, runMode, processInstancePriority,
workerGroup, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun, testFlag, workerGroup, tenantCode, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun,
testFlag,
complementDependentMode, version); complementDependentMode, version);
return returnDataList(result); return returnDataList(result);
} }
@ -187,6 +190,7 @@ public class ExecutorController extends BaseController {
* @param runMode run mode * @param runMode run mode
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param timeout timeout * @param timeout timeout
* @param expectedParallelismNumber the expected parallelism number when execute complement in parallel mode * @param expectedParallelismNumber the expected parallelism number when execute complement in parallel mode
* @param testFlag testFlag * @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 = "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 = "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 = "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 = "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 = "timeout", description = "TIMEOUT", schema = @Schema(implementation = int.class, example = "100")),
@Parameter(name = "expectedParallelismNumber", description = "EXPECTED_PARALLELISM_NUMBER", schema = @Schema(implementation = int.class, example = "8")), @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 = "runMode", required = false) RunMode runMode,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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 = "environmentCode", required = false, defaultValue = "-1") Long environmentCode,
@RequestParam(value = "timeout", required = false) Integer timeout, @RequestParam(value = "timeout", required = false) Integer timeout,
@RequestParam(value = "startParams", required = false) String startParams, @RequestParam(value = "startParams", required = false) String startParams,
@ -263,7 +269,8 @@ public class ExecutorController extends BaseController {
result = execService.execProcessInstance(loginUser, projectCode, processDefinitionCode, scheduleTime, result = execService.execProcessInstance(loginUser, projectCode, processDefinitionCode, scheduleTime,
execType, failureStrategy, execType, failureStrategy,
startNodeList, taskDependType, warningType, warningGroupId, runMode, processInstancePriority, startNodeList, taskDependType, warningType, warningGroupId, runMode, processInstancePriority,
workerGroup, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun, testFlag, workerGroup, tenantCode, environmentCode, timeout, startParamMap, expectedParallelismNumber, dryRun,
testFlag,
complementDependentMode, null); complementDependentMode, null);
if (!Status.SUCCESS.equals(result.get(Constants.STATUS))) { 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 = "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 = "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 = "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 = "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 = "timeout", description = "TIMEOUT", schema = @Schema(implementation = int.class, example = "100")),
@Parameter(name = "dryRun", description = "DRY_RUN", schema = @Schema(implementation = int.class, example = "0")), @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 = "version", required = true) int version,
@RequestParam(value = "warningGroupId", required = false, defaultValue = "0") Integer warningGroupId, @RequestParam(value = "warningGroupId", required = false, defaultValue = "0") Integer warningGroupId,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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 = "environmentCode", required = false, defaultValue = "-1") Long environmentCode,
@RequestParam(value = "startParams", required = false) String startParams, @RequestParam(value = "startParams", required = false) String startParams,
@RequestParam(value = "dryRun", defaultValue = "0", required = false) int dryRun) { @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:{}.", log.info("Start to execute stream task instance, projectCode:{}, taskDefinitionCode:{}, taskVersion:{}.",
projectCode, code, version); projectCode, code, version);
Map<String, Object> result = execService.execStreamTaskInstance(loginUser, projectCode, code, version, Map<String, Object> result = execService.execStreamTaskInstance(loginUser, projectCode, code, version,
warningGroupId, workerGroup, environmentCode, startParamMap, dryRun); warningGroupId, workerGroup, tenantCode, environmentCode, startParamMap, dryRun);
return returnDataList(result); return returnDataList(result);
} }

16
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 globalParams globalParams
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param taskRelationJson relation json for nodes * @param taskRelationJson relation json for nodes
* @param taskDefinitionJson taskDefinitionJson * @param taskDefinitionJson taskDefinitionJson
* @param otherParamsJson otherParamsJson handle other params * @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 = "globalParams", required = false, defaultValue = "[]") String globalParams,
@RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, @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 = "taskRelationJson", required = true) String taskRelationJson,
@RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson, @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson,
@RequestParam(value = "otherParamsJson", required = false) String otherParamsJson, @RequestParam(value = "otherParamsJson", required = false) String otherParamsJson,
@RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType) { @RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType) {
Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectCode, name, Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectCode, name,
description, globalParams, description, globalParams,
locations, timeout, tenantCode, taskRelationJson, taskDefinitionJson, otherParamsJson, executionType); locations, timeout, taskRelationJson, taskDefinitionJson, otherParamsJson, executionType);
return returnDataList(result); return returnDataList(result);
} }
@ -222,7 +220,6 @@ public class ProcessDefinitionController extends BaseController {
* @param globalParams globalParams * @param globalParams globalParams
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param taskRelationJson relation json for nodes * @param taskRelationJson relation json for nodes
* @param taskDefinitionJson taskDefinitionJson * @param taskDefinitionJson taskDefinitionJson
* @param otherParamsJson otherParamsJson handle other params * @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 = "globalParams", required = false, defaultValue = "[]") String globalParams,
@RequestParam(value = "locations", required = false) String locations, @RequestParam(value = "locations", required = false) String locations,
@RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, @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 = "taskRelationJson", required = true) String taskRelationJson,
@RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson, @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson,
@RequestParam(value = "otherParamsJson", required = false) String otherParamsJson, @RequestParam(value = "otherParamsJson", required = false) String otherParamsJson,
@ -258,7 +254,7 @@ public class ProcessDefinitionController extends BaseController {
Map<String, Object> result = processDefinitionService.updateProcessDefinition(loginUser, projectCode, name, Map<String, Object> result = processDefinitionService.updateProcessDefinition(loginUser, projectCode, name,
code, description, globalParams, 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 the update fails, the result will be returned directly
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataList(result); return returnDataList(result);
@ -754,7 +750,6 @@ public class ProcessDefinitionController extends BaseController {
* @param description description * @param description description
* @param globalParams globalParams * @param globalParams globalParams
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param scheduleJson scheduleJson * @param scheduleJson scheduleJson
* @return process definition code * @return process definition code
*/ */
@ -774,12 +769,11 @@ public class ProcessDefinitionController extends BaseController {
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams,
@RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, @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 = "scheduleJson", required = false) String scheduleJson,
@RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType) { @RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType) {
return returnDataList(processDefinitionService.createEmptyProcessDefinition(loginUser, projectCode, name, return returnDataList(processDefinitionService.createEmptyProcessDefinition(loginUser, projectCode, name,
description, globalParams, description, globalParams,
timeout, tenantCode, scheduleJson, executionType)); timeout, scheduleJson, executionType));
} }
/** /**
@ -792,7 +786,6 @@ public class ProcessDefinitionController extends BaseController {
* @param description description * @param description description
* @param globalParams globalParams * @param globalParams globalParams
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param scheduleJson scheduleJson * @param scheduleJson scheduleJson
* @param executionType executionType * @param executionType executionType
* @param releaseState releaseState * @param releaseState releaseState
@ -818,14 +811,13 @@ public class ProcessDefinitionController extends BaseController {
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams,
@RequestParam(value = "timeout", required = false, defaultValue = "0") int timeout, @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 = "scheduleJson", required = false) String scheduleJson,
@RequestParam(value = "otherParamsJson", required = false) String otherParamsJson, @RequestParam(value = "otherParamsJson", required = false) String otherParamsJson,
@RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType, @RequestParam(value = "executionType", defaultValue = "PARALLEL") ProcessExecutionTypeEnum executionType,
@RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) { @RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) {
Map<String, Object> result = processDefinitionService.updateProcessDefinitionBasicInfo(loginUser, projectCode, Map<String, Object> result = processDefinitionService.updateProcessDefinitionBasicInfo(loginUser, projectCode,
name, code, description, globalParams, name, code, description, globalParams,
timeout, tenantCode, scheduleJson, otherParamsJson, executionType); timeout, scheduleJson, otherParamsJson, executionType);
// If the update fails, the result will be returned directly // If the update fails, the result will be returned directly
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return returnDataList(result); return returnDataList(result);

17
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 failureStrategy failure strategy
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @return create result code * @return create result code
*/ */
@Operation(summary = "createSchedule", description = "CREATE_SCHEDULE_NOTES") @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 = "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 = "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 = "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 = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = long.class)),
@Parameter(name = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", schema = @Schema(implementation = Priority.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 = "warningGroupId", required = false, defaultValue = DEFAULT_NOTIFY_GROUP_ID) int warningGroupId,
@RequestParam(value = "failureStrategy", required = false, defaultValue = DEFAULT_FAILURE_POLICY) FailureStrategy failureStrategy, @RequestParam(value = "failureStrategy", required = false, defaultValue = DEFAULT_FAILURE_POLICY) FailureStrategy failureStrategy,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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 = "environmentCode", required = false, defaultValue = "-1") Long environmentCode,
@RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) { @RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) {
Map<String, Object> result = schedulerService.insertSchedule( Map<String, Object> result = schedulerService.insertSchedule(
@ -125,6 +128,7 @@ public class SchedulerController extends BaseController {
failureStrategy, failureStrategy,
processInstancePriority, processInstancePriority,
workerGroup, workerGroup,
tenantCode,
environmentCode); environmentCode);
return returnDataList(result); return returnDataList(result);
@ -141,6 +145,7 @@ public class SchedulerController extends BaseController {
* @param warningGroupId warning group id * @param warningGroupId warning group id
* @param failureStrategy failure strategy * @param failureStrategy failure strategy
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @return update result code * @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 = "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 = "failureStrategy", description = "FAILURE_STRATEGY", schema = @Schema(implementation = FailureStrategy.class)),
@Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), @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 = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", schema = @Schema(implementation = Priority.class)),
@Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = long.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 = "warningGroupId", required = false) int warningGroupId,
@RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy, @RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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 = "environmentCode", required = false, defaultValue = "-1") Long environmentCode,
@RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) { @RequestParam(value = "processInstancePriority", required = false, defaultValue = DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) {
Map<String, Object> result = schedulerService.updateSchedule(loginUser, projectCode, id, schedule, Map<String, Object> result = schedulerService.updateSchedule(loginUser, projectCode, id, schedule,
warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, environmentCode); warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, tenantCode,
environmentCode);
return returnDataList(result); 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 = "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 = "failureStrategy", description = "FAILURE_STRATEGY", schema = @Schema(implementation = FailureStrategy.class)),
@Parameter(name = "workerGroup", description = "WORKER_GROUP", schema = @Schema(implementation = String.class, example = "default")), @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 = "processInstancePriority", description = "PROCESS_INSTANCE_PRIORITY", schema = @Schema(implementation = Priority.class)),
@Parameter(name = "environmentCode", description = "ENVIRONMENT_CODE", schema = @Schema(implementation = long.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 = "warningGroupId", required = false) int warningGroupId,
@RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy, @RequestParam(value = "failureStrategy", required = false, defaultValue = "END") FailureStrategy failureStrategy,
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @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 = "environmentCode", required = false, defaultValue = "-1") long environmentCode,
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) { @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) {
Map<String, Object> result = schedulerService.updateScheduleByProcessDefinitionCode(loginUser, projectCode, Map<String, Object> result = schedulerService.updateScheduleByProcessDefinitionCode(loginUser, projectCode,
processDefinitionCode, schedule, processDefinitionCode, schedule,
warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, environmentCode); warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup, tenantCode,
environmentCode);
return returnDataList(result); return returnDataList(result);
} }
} }

4
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") @Schema(example = "worker-group-name")
private String workerGroup; private String workerGroup;
@Schema(example = "tenant-code")
private String tenantCode;
@Schema(example = "environment-code") @Schema(example = "environment-code")
private long environmentCode; private long environmentCode;
@ -91,6 +94,7 @@ public class ScheduleCreateRequest {
schedule.setTimezoneId(this.timezoneId); schedule.setTimezoneId(this.timezoneId);
schedule.setWarningGroupId(this.warningGroupId); schedule.setWarningGroupId(this.warningGroupId);
schedule.setWorkerGroup(this.workerGroup); schedule.setWorkerGroup(this.workerGroup);
schedule.setTenantCode(this.tenantCode);
schedule.setEnvironmentCode(this.environmentCode); schedule.setEnvironmentCode(this.environmentCode);
FailureStrategy newFailureStrategy = FailureStrategy newFailureStrategy =

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowCreateRequest.java

@ -55,9 +55,6 @@ public class WorkflowCreateRequest {
@Schema(example = "60") @Schema(example = "60")
private int timeout; 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.") @Schema(allowableValues = "PARALLEL / SERIAL_WAIT / SERIAL_DISCARD / SERIAL_PRIORITY", example = "PARALLEL", description = "default PARALLEL if not provide.")
private String executionType; private String executionType;
@ -70,7 +67,6 @@ public class WorkflowCreateRequest {
processDefinition.setGlobalParams(this.globalParams); processDefinition.setGlobalParams(this.globalParams);
processDefinition.setWarningGroupId(this.warningGroupId); processDefinition.setWarningGroupId(this.warningGroupId);
processDefinition.setTimeout(this.timeout); processDefinition.setTimeout(this.timeout);
processDefinition.setTenantCode(this.tenantCode);
ReleaseState pdReleaseState = ReleaseState pdReleaseState =
this.releaseState == null ? ReleaseState.OFFLINE : ReleaseState.valueOf(this.releaseState); this.releaseState == null ? ReleaseState.OFFLINE : ReleaseState.valueOf(this.releaseState);

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/workflow/WorkflowUpdateRequest.java

@ -56,9 +56,6 @@ public class WorkflowUpdateRequest {
@Schema(example = "60") @Schema(example = "60")
private int timeout; 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.") @Schema(allowableValues = "PARALLEL / SERIAL_WAIT / SERIAL_DISCARD / SERIAL_PRIORITY", example = "PARALLEL", description = "default PARALLEL if not provide.")
private String executionType; private String executionType;
@ -93,9 +90,6 @@ public class WorkflowUpdateRequest {
if (this.timeout != 0) { if (this.timeout != 0) {
processDefinitionDeepCopy.setTimeout(this.timeout); processDefinitionDeepCopy.setTimeout(this.timeout);
} }
if (this.tenantCode != null) {
processDefinitionDeepCopy.setTenantCode(this.tenantCode);
}
if (this.executionType != null) { if (this.executionType != null) {
processDefinitionDeepCopy.setExecutionType(ProcessExecutionTypeEnum.valueOf(this.executionType)); processDefinitionDeepCopy.setExecutionType(ProcessExecutionTypeEnum.valueOf(this.executionType));
} }

2
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失败"), LOGIN_SESSION_FAILED(10014, "create session failed!", "创建session失败"),
DATASOURCE_EXIST(10015, "data source name already exists", "数据源名称已存在"), DATASOURCE_EXIST(10015, "data source name already exists", "数据源名称已存在"),
DATASOURCE_CONNECT_FAILED(10016, "data source connection failed", "建立数据源连接失败"), 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_NOT_FOUND(10018, "project {0} not found ", "项目[{0}]不存在"),
PROJECT_ALREADY_EXISTS(10019, "project {0} already exists", "项目名称[{0}]已存在"), PROJECT_ALREADY_EXISTS(10019, "project {0} already exists", "项目名称[{0}]已存在"),
TASK_INSTANCE_NOT_EXISTS(10020, "task instance {0} does not exist", "任务实例[{0}]不存在"), TASK_INSTANCE_NOT_EXISTS(10020, "task instance {0} does not exist", "任务实例[{0}]不存在"),

11
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java

@ -266,12 +266,12 @@ public class PythonGateway {
ReleaseState.OFFLINE); ReleaseState.OFFLINE);
processDefinitionService.updateProcessDefinition(user, projectCode, name, processDefinitionService.updateProcessDefinition(user, projectCode, name,
processDefinitionCode, description, globalParams, processDefinitionCode, description, globalParams,
null, timeout, user.getTenantCode(), taskRelationJson, taskDefinitionJson, otherParamsJson, null, timeout, taskRelationJson, taskDefinitionJson, otherParamsJson,
executionTypeEnum); executionTypeEnum);
} else { } else {
Map<String, Object> result = processDefinitionService.createProcessDefinition(user, projectCode, name, Map<String, Object> result = processDefinitionService.createProcessDefinition(user, projectCode, name,
description, globalParams, description, globalParams,
null, timeout, user.getTenantCode(), taskRelationJson, taskDefinitionJson, otherParamsJson, null, timeout, taskRelationJson, taskDefinitionJson, otherParamsJson,
executionTypeEnum); executionTypeEnum);
processDefinition = (ProcessDefinition) result.get(Constants.DATA_LIST); processDefinition = (ProcessDefinition) result.get(Constants.DATA_LIST);
processDefinitionCode = processDefinition.getCode(); processDefinitionCode = processDefinition.getCode();
@ -343,14 +343,16 @@ public class PythonGateway {
ReleaseState.ONLINE); ReleaseState.ONLINE);
Map<String, Object> result = schedulerService.insertSchedule(user, projectCode, workflowCode, Map<String, Object> result = schedulerService.insertSchedule(user, projectCode, workflowCode,
schedule, WarningType.valueOf(warningType), 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"); scheduleId = (int) result.get("scheduleId");
} else { } else {
scheduleId = scheduleObj.getId(); scheduleId = scheduleObj.getId();
processDefinitionService.releaseProcessDefinition(user, projectCode, workflowCode, processDefinitionService.releaseProcessDefinition(user, projectCode, workflowCode,
ReleaseState.OFFLINE); ReleaseState.OFFLINE);
schedulerService.updateSchedule(user, projectCode, scheduleId, schedule, WarningType.valueOf(warningType), 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) { if (onlineSchedule) {
// set workflow online to make sure we can set schedule online // set workflow online to make sure we can set schedule online
@ -389,6 +391,7 @@ public class PythonGateway {
DEFAULT_RUN_MODE, DEFAULT_RUN_MODE,
DEFAULT_PRIORITY, DEFAULT_PRIORITY,
workerGroup, workerGroup,
user.getTenantCode(),
DEFAULT_ENVIRONMENT_CODE, DEFAULT_ENVIRONMENT_CODE,
timeout, timeout,
null, null,

9
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 warningGroupId notify group id
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group name * @param workerGroup worker group name
* @param tenantCode tenant code
* @param environmentCode environment code * @param environmentCode environment code
* @param runMode run mode * @param runMode run mode
* @param timeout timeout * @param timeout timeout
@ -65,7 +66,8 @@ public interface ExecutorService {
TaskDependType taskDependType, WarningType warningType, TaskDependType taskDependType, WarningType warningType,
Integer warningGroupId, Integer warningGroupId,
RunMode runMode, RunMode runMode,
Priority processInstancePriority, String workerGroup, Long environmentCode, Priority processInstancePriority, String workerGroup, String tenantCode,
Long environmentCode,
Integer timeout, Integer timeout,
Map<String, String> startParams, Integer expectedParallelismNumber, Map<String, String> startParams, Integer expectedParallelismNumber,
int dryRun, int testFlag, int dryRun, int testFlag,
@ -154,6 +156,7 @@ public interface ExecutorService {
* @param projectCode project code * @param projectCode project code
* @param warningGroupId notify group id * @param warningGroupId notify group id
* @param workerGroup worker group name * @param workerGroup worker group name
* @param tenantCode tenant code
* @param environmentCode environment code * @param environmentCode environment code
* @param startParams the global param values which pass to new process instance * @param startParams the global param values which pass to new process instance
* @return execute process instance code * @return execute process instance code
@ -161,7 +164,9 @@ public interface ExecutorService {
Map<String, Object> execStreamTaskInstance(User loginUser, long projectCode, Map<String, Object> execStreamTaskInstance(User loginUser, long projectCode,
long taskDefinitionCode, int taskDefinitionVersion, long taskDefinitionCode, int taskDefinitionVersion,
int warningGroupId, int warningGroupId,
String workerGroup, Long environmentCode, String workerGroup,
String tenantCode,
Long environmentCode,
Map<String, String> startParams, Map<String, String> startParams,
int dryRun); int dryRun);
} }

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java

@ -52,7 +52,6 @@ public interface ProcessDefinitionService {
* @param globalParams global params * @param globalParams global params
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param taskRelationJson relation json for nodes * @param taskRelationJson relation json for nodes
* @param taskDefinitionJson taskDefinitionJson * @param taskDefinitionJson taskDefinitionJson
* @param otherParamsJson otherParamsJson handle other params * @param otherParamsJson otherParamsJson handle other params
@ -65,7 +64,6 @@ public interface ProcessDefinitionService {
String globalParams, String globalParams,
String locations, String locations,
int timeout, int timeout,
String tenantCode,
String taskRelationJson, String taskRelationJson,
String taskDefinitionJson, String taskDefinitionJson,
String otherParamsJson, String otherParamsJson,
@ -207,7 +205,6 @@ public interface ProcessDefinitionService {
* @param globalParams global params * @param globalParams global params
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param taskRelationJson relation json for nodes * @param taskRelationJson relation json for nodes
* @param taskDefinitionJson taskDefinitionJson * @param taskDefinitionJson taskDefinitionJson
* @param otherParamsJson otherParamsJson handle other params * @param otherParamsJson otherParamsJson handle other params
@ -221,7 +218,6 @@ public interface ProcessDefinitionService {
String globalParams, String globalParams,
String locations, String locations,
int timeout, int timeout,
String tenantCode,
String taskRelationJson, String taskRelationJson,
String taskDefinitionJson, String taskDefinitionJson,
String otherParamsJson, String otherParamsJson,
@ -427,7 +423,6 @@ public interface ProcessDefinitionService {
* @param description description * @param description description
* @param globalParams globalParams * @param globalParams globalParams
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param scheduleJson scheduleJson * @param scheduleJson scheduleJson
* @return process definition code * @return process definition code
*/ */
@ -437,7 +432,6 @@ public interface ProcessDefinitionService {
String description, String description,
String globalParams, String globalParams,
int timeout, int timeout,
String tenantCode,
String scheduleJson, String scheduleJson,
ProcessExecutionTypeEnum executionType); ProcessExecutionTypeEnum executionType);
@ -451,7 +445,6 @@ public interface ProcessDefinitionService {
* @param description description * @param description description
* @param globalParams globalParams * @param globalParams globalParams
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param scheduleJson scheduleJson * @param scheduleJson scheduleJson
* @param otherParamsJson otherParamsJson handle other params * @param otherParamsJson otherParamsJson handle other params
* @param executionType executionType * @param executionType executionType
@ -464,7 +457,6 @@ public interface ProcessDefinitionService {
String description, String description,
String globalParams, String globalParams,
int timeout, int timeout,
String tenantCode,
String scheduleJson, String scheduleJson,
String otherParamsJson, String otherParamsJson,
ProcessExecutionTypeEnum executionType); ProcessExecutionTypeEnum executionType);

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java

@ -49,6 +49,7 @@ public interface SchedulerService {
* @param failureStrategy failure strategy * @param failureStrategy failure strategy
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param environmentCode environment code * @param environmentCode environment code
* @return create result code * @return create result code
*/ */
@ -61,6 +62,7 @@ public interface SchedulerService {
FailureStrategy failureStrategy, FailureStrategy failureStrategy,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup, String workerGroup,
String tenantCode,
Long environmentCode); Long environmentCode);
/** /**
@ -84,6 +86,7 @@ public interface SchedulerService {
* @param warningGroupId warning group id * @param warningGroupId warning group id
* @param failureStrategy failure strategy * @param failureStrategy failure strategy
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param environmentCode environment code * @param environmentCode environment code
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @return update result code * @return update result code
@ -97,6 +100,7 @@ public interface SchedulerService {
FailureStrategy failureStrategy, FailureStrategy failureStrategy,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup, String workerGroup,
String tenantCode,
Long environmentCode); Long environmentCode);
/** /**
@ -206,6 +210,7 @@ public interface SchedulerService {
* @param warningGroupId warning group id * @param warningGroupId warning group id
* @param failureStrategy failure strategy * @param failureStrategy failure strategy
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @return update result code * @return update result code
*/ */
@ -218,5 +223,6 @@ public interface SchedulerService {
FailureStrategy failureStrategy, FailureStrategy failureStrategy,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup, String workerGroup,
String tenantCode,
long environmentCode); long environmentCode);
} }

34
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.Schedule;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskGroupQueue; 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.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; 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.TaskDefinitionLogMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskGroupQueueMapper; 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.dao.repository.ProcessInstanceDao;
import org.apache.dolphinscheduler.plugin.task.api.TaskConstants; import org.apache.dolphinscheduler.plugin.task.api.TaskConstants;
import org.apache.dolphinscheduler.remote.command.Message; import org.apache.dolphinscheduler.remote.command.Message;
@ -181,6 +183,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
@Autowired @Autowired
private ExecuteClient executeClient; private ExecuteClient executeClient;
@Autowired
private TenantMapper tenantMapper;
/** /**
* execute process instance * execute process instance
* *
@ -196,6 +201,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
* @param warningGroupId notify group id * @param warningGroupId notify group id
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group name * @param workerGroup worker group name
* @param tenantCode tenant code
* @param environmentCode environment code * @param environmentCode environment code
* @param runMode run mode * @param runMode run mode
* @param timeout timeout * @param timeout timeout
@ -212,6 +218,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
TaskDependType taskDependType, WarningType warningType, TaskDependType taskDependType, WarningType warningType,
Integer warningGroupId, RunMode runMode, Integer warningGroupId, RunMode runMode,
Priority processInstancePriority, String workerGroup, Priority processInstancePriority, String workerGroup,
String tenantCode,
Long environmentCode, Integer timeout, Long environmentCode, Integer timeout,
Map<String, String> startParams, Integer expectedParallelismNumber, Map<String, String> startParams, Integer expectedParallelismNumber,
int dryRun, int testFlag, int dryRun, int testFlag,
@ -229,6 +236,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
putMsg(result, Status.TASK_TIMEOUT_PARAMS_ERROR); putMsg(result, Status.TASK_TIMEOUT_PARAMS_ERROR);
return result; return result;
} }
checkValidTenant(tenantCode);
ProcessDefinition processDefinition; ProcessDefinition processDefinition;
if (null != version) { if (null != version) {
processDefinition = processService.findProcessDefinition(processDefinitionCode, version); processDefinition = processService.findProcessDefinition(processDefinitionCode, version);
@ -254,7 +262,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
failureStrategy, failureStrategy,
startNodeList, startNodeList,
cronTime, warningType, loginUser.getId(), warningGroupId, runMode, processInstancePriority, cronTime, warningType, loginUser.getId(), warningGroupId, runMode, processInstancePriority,
workerGroup, workerGroup, tenantCode,
environmentCode, startParams, expectedParallelismNumber, dryRun, testFlag, environmentCode, startParams, expectedParallelismNumber, dryRun, testFlag,
complementDependentMode); complementDependentMode);
@ -361,6 +369,20 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
.isEmpty(); .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 instancepause, stop, repeat, recover from pause, recover from stoprerun failed task * do action to process instancepause, stop, repeat, recover from pause, recover from stoprerun failed task
* *
@ -723,7 +745,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
private int createCommand(Long triggerCode, CommandType commandType, long processDefineCode, TaskDependType nodeDep, private int createCommand(Long triggerCode, CommandType commandType, long processDefineCode, TaskDependType nodeDep,
FailureStrategy failureStrategy, String startNodeList, String schedule, FailureStrategy failureStrategy, String startNodeList, String schedule,
WarningType warningType, int executorId, Integer warningGroupId, RunMode runMode, WarningType warningType, int executorId, Integer warningGroupId, RunMode runMode,
Priority processInstancePriority, String workerGroup, Long environmentCode, Priority processInstancePriority, String workerGroup, String tenantCode,
Long environmentCode,
Map<String, String> startParams, Integer expectedParallelismNumber, int dryRun, Map<String, String> startParams, Integer expectedParallelismNumber, int dryRun,
int testFlag, ComplementDependentMode complementDependentMode) { int testFlag, ComplementDependentMode complementDependentMode) {
@ -760,6 +783,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
command.setWarningGroupId(warningGroupId); command.setWarningGroupId(warningGroupId);
command.setProcessInstancePriority(processInstancePriority); command.setProcessInstancePriority(processInstancePriority);
command.setWorkerGroup(workerGroup); command.setWorkerGroup(workerGroup);
command.setTenantCode(tenantCode);
command.setEnvironmentCode(environmentCode); command.setEnvironmentCode(environmentCode);
command.setDryRun(dryRun); command.setDryRun(dryRun);
command.setTestFlag(testFlag); command.setTestFlag(testFlag);
@ -1140,7 +1164,8 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
@Override @Override
public Map<String, Object> execStreamTaskInstance(User loginUser, long projectCode, long taskDefinitionCode, public Map<String, Object> execStreamTaskInstance(User loginUser, long projectCode, long taskDefinitionCode,
int taskDefinitionVersion, int taskDefinitionVersion,
int warningGroupId, String workerGroup, Long environmentCode, int warningGroupId, String workerGroup, String tenantCode,
Long environmentCode,
Map<String, String> startParams, int dryRun) { Map<String, String> startParams, int dryRun) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
@ -1149,7 +1174,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
checkValidTenant(tenantCode);
checkMasterExists(); checkMasterExists();
// todo dispatch improvement // todo dispatch improvement
List<Server> masterServerList = monitorService.getServerListFromRegistry(true); List<Server> masterServerList = monitorService.getServerListFromRegistry(true);
@ -1162,6 +1187,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ
taskExecuteStartMessage.setTaskDefinitionCode(taskDefinitionCode); taskExecuteStartMessage.setTaskDefinitionCode(taskDefinitionCode);
taskExecuteStartMessage.setTaskDefinitionVersion(taskDefinitionVersion); taskExecuteStartMessage.setTaskDefinitionVersion(taskDefinitionVersion);
taskExecuteStartMessage.setWorkerGroup(workerGroup); taskExecuteStartMessage.setWorkerGroup(workerGroup);
taskExecuteStartMessage.setTenantCode(tenantCode);
taskExecuteStartMessage.setWarningGroupId(warningGroupId); taskExecuteStartMessage.setWarningGroupId(warningGroupId);
taskExecuteStartMessage.setEnvironmentCode(environmentCode); taskExecuteStartMessage.setEnvironmentCode(environmentCode);
taskExecuteStartMessage.setStartParams(startParams); taskExecuteStartMessage.setStartParams(startParams);

105
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.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.entity.TaskMainInfo; 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.User;
import org.apache.dolphinscheduler.dao.entity.UserWithProcessDefinitionCode; import org.apache.dolphinscheduler.dao.entity.UserWithProcessDefinitionCode;
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; 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.TaskDefinitionLogMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; 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.mapper.UserMapper;
import org.apache.dolphinscheduler.dao.model.PageListingResult; import org.apache.dolphinscheduler.dao.model.PageListingResult;
import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao; 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.dolphinscheduler.service.process.ProcessService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@ -242,9 +241,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
@Autowired @Autowired
private SchedulerService schedulerService; private SchedulerService schedulerService;
@Autowired
private TenantMapper tenantMapper;
@Autowired @Autowired
private DataSourceMapper dataSourceMapper; private DataSourceMapper dataSourceMapper;
@ -267,7 +263,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @param globalParams global params * @param globalParams global params
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param taskRelationJson relation json for nodes * @param taskRelationJson relation json for nodes
* @param taskDefinitionJson taskDefinitionJson * @param taskDefinitionJson taskDefinitionJson
* @return create result code * @return create result code
@ -281,7 +276,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
String globalParams, String globalParams,
String locations, String locations,
int timeout, int timeout,
String tenantCode,
String taskRelationJson, String taskRelationJson,
String taskDefinitionJson, String taskDefinitionJson,
String otherParamsJson, String otherParamsJson,
@ -308,19 +302,11 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson);
List<ProcessTaskRelationLog> taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); List<ProcessTaskRelationLog> 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(); long processDefinitionCode = CodeGenerateUtils.getInstance().genCode();
ProcessDefinition processDefinition = ProcessDefinition processDefinition =
new ProcessDefinition(projectCode, name, processDefinitionCode, description, new ProcessDefinition(projectCode, name, processDefinitionCode, description,
globalParams, locations, timeout, loginUser.getId(), tenantId); globalParams, locations, timeout, loginUser.getId());
processDefinition.setExecutionType(executionType); processDefinition.setExecutionType(executionType);
return createDagDefine(loginUser, taskRelationList, processDefinition, taskDefinitionLogs, otherParamsJson); 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()); 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) { 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); throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
} }
processDefinition.setTenantId(this.getTenantId(processDefinition));
processDefinition.setCode(processDefinitionCode); processDefinition.setCode(processDefinitionCode);
processDefinition.setUserId(loginUser.getId()); processDefinition.setUserId(loginUser.getId());
@ -693,10 +665,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
log.error("Process definition does not exist, processCode:{}.", code); log.error("Process definition does not exist, processCode:{}.", code);
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, String.valueOf(code)); putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, String.valueOf(code));
} else { } else {
Tenant tenant = tenantMapper.queryById(processDefinition.getTenantId());
if (tenant != null) {
processDefinition.setTenantCode(tenant.getTenantCode());
}
DagData dagData = processService.genDagData(processDefinition); DagData dagData = processService.genDagData(processDefinition);
result.put(Constants.DATA_LIST, dagData); result.put(Constants.DATA_LIST, dagData);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -722,11 +690,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// check user access for project // check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION); projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION);
Tenant tenant = tenantMapper.queryById(processDefinition.getTenantId());
if (tenant != null) {
processDefinition.setTenantCode(tenant.getTenantCode());
}
return processDefinition; return processDefinition;
} }
@ -782,7 +745,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @param globalParams global params * @param globalParams global params
* @param locations locations for nodes * @param locations locations for nodes
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param taskRelationJson relation json for nodes * @param taskRelationJson relation json for nodes
* @param taskDefinitionJson taskDefinitionJson * @param taskDefinitionJson taskDefinitionJson
* @param otherParamsJson otherParamsJson handle other params * @param otherParamsJson otherParamsJson handle other params
@ -798,7 +760,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
String globalParams, String globalParams,
String locations, String locations,
int timeout, int timeout,
String tenantCode,
String taskRelationJson, String taskRelationJson,
String taskDefinitionJson, String taskDefinitionJson,
String otherParamsJson, String otherParamsJson,
@ -820,17 +781,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson);
List<ProcessTaskRelationLog> taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); List<ProcessTaskRelationLog> 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); ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code);
// check process definition exists // check process definition exists
if (processDefinition == null || projectCode != processDefinition.getProjectCode()) { if (processDefinition == null || projectCode != processDefinition.getProjectCode()) {
@ -857,7 +807,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
ProcessDefinition processDefinitionDeepCopy = ProcessDefinition processDefinitionDeepCopy =
JSONUtils.parseObject(JSONUtils.toJsonString(processDefinition), ProcessDefinition.class); 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); processDefinition.setExecutionType(executionType);
return updateDagDefine(loginUser, taskRelationList, processDefinition, processDefinitionDeepCopy, return updateDagDefine(loginUser, taskRelationList, processDefinition, processDefinitionDeepCopy,
taskDefinitionLogs, otherParamsJson); taskDefinitionLogs, otherParamsJson);
@ -1366,7 +1316,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
CodeGenerateUtils.getInstance().genCode(), CodeGenerateUtils.getInstance().genCode(),
"", "",
"[]", null, "[]", null,
0, loginUser.getId(), loginUser.getTenantId()); 0, loginUser.getId());
ZipEntry entry; ZipEntry entry;
while ((entry = zIn.getNextEntry()) != null) { while ((entry = zIn.getNextEntry()) != null) {
@ -2501,7 +2451,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @param description description * @param description description
* @param globalParams globalParams * @param globalParams globalParams
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param scheduleJson scheduleJson * @param scheduleJson scheduleJson
* @return process definition code * @return process definition code
*/ */
@ -2513,7 +2462,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
String description, String description,
String globalParams, String globalParams,
int timeout, int timeout,
String tenantCode,
String scheduleJson, String scheduleJson,
ProcessExecutionTypeEnum executionType) { ProcessExecutionTypeEnum executionType) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
@ -2538,16 +2486,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result; 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; long processDefinitionCode;
try { try {
processDefinitionCode = CodeGenerateUtils.getInstance().genCode(); processDefinitionCode = CodeGenerateUtils.getInstance().genCode();
@ -2558,7 +2496,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
ProcessDefinition processDefinition = ProcessDefinition processDefinition =
new ProcessDefinition(projectCode, name, processDefinitionCode, description, new ProcessDefinition(projectCode, name, processDefinitionCode, description,
globalParams, "", timeout, loginUser.getId(), tenantId); globalParams, "", timeout, loginUser.getId());
processDefinition.setExecutionType(executionType); processDefinition.setExecutionType(executionType);
result = createEmptyDagDefine(loginUser, processDefinition); result = createEmptyDagDefine(loginUser, processDefinition);
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
@ -2645,7 +2583,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @param description description * @param description description
* @param globalParams globalParams * @param globalParams globalParams
* @param timeout timeout * @param timeout timeout
* @param tenantCode tenantCode
* @param scheduleJson scheduleJson * @param scheduleJson scheduleJson
* @param otherParamsJson otherParamsJson handle other params * @param otherParamsJson otherParamsJson handle other params
* @param executionType executionType * @param executionType executionType
@ -2660,7 +2597,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
String description, String description,
String globalParams, String globalParams,
int timeout, int timeout,
String tenantCode,
String scheduleJson, String scheduleJson,
String otherParamsJson, String otherParamsJson,
ProcessExecutionTypeEnum executionType) { ProcessExecutionTypeEnum executionType) {
@ -2677,16 +2613,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR); putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
return result; 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); ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code);
// check process definition exists // check process definition exists
@ -2714,7 +2640,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
ProcessDefinition processDefinitionDeepCopy = ProcessDefinition processDefinitionDeepCopy =
JSONUtils.parseObject(JSONUtils.toJsonString(processDefinition), ProcessDefinition.class); 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); processDefinition.setExecutionType(executionType);
List<ProcessTaskRelationLog> taskRelationList = processTaskRelationLogMapper List<ProcessTaskRelationLog> taskRelationList = processTaskRelationLogMapper
.queryByProcessCodeAndVersion(processDefinition.getCode(), processDefinition.getVersion()); .queryByProcessCodeAndVersion(processDefinition.getCode(), processDefinition.getVersion());
@ -2785,13 +2711,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessDefinition processDefinitionUpdate = workflowUpdateRequest.mergeIntoProcessDefinition(processDefinition); ProcessDefinition processDefinitionUpdate = workflowUpdateRequest.mergeIntoProcessDefinition(processDefinition);
this.updateWorkflowValid(loginUser, processDefinition, processDefinitionUpdate); 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); int insertVersion = this.saveProcessDefine(loginUser, processDefinitionUpdate);
if (insertVersion == 0) { if (insertVersion == 0) {
log.error("Update process definition error, projectCode:{}, processDefinitionName:{}.", log.error("Update process definition error, projectCode:{}, processDefinitionName:{}.",
@ -2910,12 +2829,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
// set default value // set default value
FailureStrategy failureStrategy = FailureStrategy failureStrategy =
schedule.getFailureStrategy() == null ? FailureStrategy.CONTINUE : schedule.getFailureStrategy(); ObjectUtils.defaultIfNull(schedule.getFailureStrategy(), FailureStrategy.CONTINUE);
WarningType warningType = schedule.getWarningType() == null ? WarningType.NONE : schedule.getWarningType(); WarningType warningType = ObjectUtils.defaultIfNull(schedule.getWarningType(), WarningType.NONE);
Priority processInstancePriority = Priority processInstancePriority =
schedule.getProcessInstancePriority() == null ? Priority.MEDIUM : schedule.getProcessInstancePriority(); ObjectUtils.defaultIfNull(schedule.getProcessInstancePriority(), Priority.MEDIUM);
int warningGroupId = schedule.getWarningGroupId() == 0 ? 1 : schedule.getWarningGroupId(); 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(); long environmentCode = schedule.getEnvironmentCode() == null ? -1 : schedule.getEnvironmentCode();
ScheduleParam param = new ScheduleParam(); ScheduleParam param = new ScheduleParam();
@ -2934,6 +2854,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
failureStrategy, failureStrategy,
processInstancePriority, processInstancePriority,
workerGroup, workerGroup,
tenantCode,
environmentCode); environmentCode);
} }

18
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.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; 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.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; 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); log.error("Process definition does not exist, projectCode:{}.", projectCode);
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId);
} else { } else {
Tenant tenant = tenantMapper.queryById(processDefinition.getTenantId());
if (tenant != null) {
processDefinition.setTenantCode(tenant.getTenantCode());
}
processInstance.setLocations(processDefinition.getLocations()); processInstance.setLocations(processDefinition.getLocations());
processInstance.setDagData(processService.genDagData(processDefinition)); processInstance.setDagData(processService.genDagData(processDefinition));
result.put(DATA_LIST, processInstance); result.put(DATA_LIST, processInstance);
@ -693,18 +688,9 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; 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(), processDefinition.set(projectCode, processDefinition.getName(), processDefinition.getDescription(),
globalParams, locations, timeout, tenantId); globalParams, locations, timeout);
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, syncDefine, Boolean.FALSE); int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, syncDefine, Boolean.FALSE);
if (insertVersion == 0) { if (insertVersion == 0) {

45
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.ProcessTaskRelation;
import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.Schedule; 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.entity.User;
import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; 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.scheduler.api.SchedulerApi;
import org.apache.dolphinscheduler.service.cron.CronUtils; import org.apache.dolphinscheduler.service.cron.CronUtils;
import org.apache.dolphinscheduler.service.exceptions.CronParseException; import org.apache.dolphinscheduler.service.exceptions.CronParseException;
@ -117,6 +119,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
@Autowired @Autowired
private EnvironmentMapper environmentMapper; private EnvironmentMapper environmentMapper;
@Autowired
private TenantMapper tenantMapper;
/** /**
* save schedule * save schedule
* *
@ -129,6 +134,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
* @param failureStrategy failure strategy * @param failureStrategy failure strategy
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param environmentCode environment code * @param environmentCode environment code
* @return create result code * @return create result code
*/ */
@ -143,6 +149,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
FailureStrategy failureStrategy, FailureStrategy failureStrategy,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup, String workerGroup,
String tenantCode,
Long environmentCode) { Long environmentCode) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
@ -163,6 +170,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
Schedule scheduleObj = new Schedule(); Schedule scheduleObj = new Schedule();
Date now = new Date(); Date now = new Date();
checkValidTenant(tenantCode);
scheduleObj.setTenantCode(tenantCode);
scheduleObj.setProjectName(project.getName()); scheduleObj.setProjectName(project.getName());
scheduleObj.setProcessDefinitionCode(processDefineCode); scheduleObj.setProcessDefinitionCode(processDefineCode);
scheduleObj.setProcessDefinitionName(processDefinition.getName()); scheduleObj.setProcessDefinitionName(processDefinition.getName());
@ -269,11 +279,14 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
scheduleExists.getId()); scheduleExists.getId());
} }
checkValidTenant(scheduleCreateRequest.getTenantCode());
Schedule schedule = scheduleCreateRequest.convert2Schedule(); Schedule schedule = scheduleCreateRequest.convert2Schedule();
Environment environment = environmentMapper.queryByEnvironmentCode(schedule.getEnvironmentCode()); Environment environment = environmentMapper.queryByEnvironmentCode(schedule.getEnvironmentCode());
if (environment == null) { if (environment == null) {
throw new ServiceException(Status.QUERY_ENVIRONMENT_BY_CODE_ERROR, schedule.getEnvironmentCode()); throw new ServiceException(Status.QUERY_ENVIRONMENT_BY_CODE_ERROR, schedule.getEnvironmentCode());
} }
schedule.setUserId(loginUser.getId()); schedule.setUserId(loginUser.getId());
// give more detail when return schedule object // give more detail when return schedule object
schedule.setUserName(loginUser.getUserName()); schedule.setUserName(loginUser.getUserName());
@ -301,6 +314,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
* @param warningGroupId warning group id * @param warningGroupId warning group id
* @param failureStrategy failure strategy * @param failureStrategy failure strategy
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param environmentCode environment code * @param environmentCode environment code
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @return update result code * @return update result code
@ -316,6 +330,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
FailureStrategy failureStrategy, FailureStrategy failureStrategy,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup, String workerGroup,
String tenantCode,
Long environmentCode) { Long environmentCode) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
@ -345,7 +360,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
} }
updateSchedule(result, schedule, processDefinition, scheduleExpression, warningType, warningGroupId, updateSchedule(result, schedule, processDefinition, scheduleExpression, warningType, warningGroupId,
failureStrategy, processInstancePriority, workerGroup, environmentCode); failureStrategy, processInstancePriority, workerGroup, tenantCode, environmentCode);
return result; return result;
} }
@ -561,16 +576,16 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
} }
Page<Schedule> page = new Page<>(pageNo, pageSize); Page<Schedule> page = new Page<>(pageNo, pageSize);
IPage<Schedule> scheduleIPage = IPage<Schedule> schedulePage =
scheduleMapper.queryByProcessDefineCodePaging(page, processDefineCode, searchVal); scheduleMapper.queryByProcessDefineCodePaging(page, processDefineCode, searchVal);
List<ScheduleVo> scheduleList = new ArrayList<>(); List<ScheduleVo> scheduleList = new ArrayList<>();
for (Schedule schedule : scheduleIPage.getRecords()) { for (Schedule schedule : schedulePage.getRecords()) {
scheduleList.add(new ScheduleVo(schedule)); scheduleList.add(new ScheduleVo(schedule));
} }
PageInfo<ScheduleVo> pageInfo = new PageInfo<>(pageNo, pageSize); PageInfo<ScheduleVo> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) scheduleIPage.getTotal()); pageInfo.setTotal((int) schedulePage.getTotal());
pageInfo.setTotalList(scheduleList); pageInfo.setTotalList(scheduleList);
result.setData(pageInfo); result.setData(pageInfo);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -752,6 +767,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
* @param warningGroupId warning group id * @param warningGroupId warning group id
* @param failureStrategy failure strategy * @param failureStrategy failure strategy
* @param workerGroup worker group * @param workerGroup worker group
* @param tenantCode tenant code
* @param processInstancePriority process instance priority * @param processInstancePriority process instance priority
* @return update result code * @return update result code
*/ */
@ -765,6 +781,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
FailureStrategy failureStrategy, FailureStrategy failureStrategy,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup, String workerGroup,
String tenantCode,
long environmentCode) { long environmentCode) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
@ -789,13 +806,14 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
} }
updateSchedule(result, schedule, processDefinition, scheduleExpression, warningType, warningGroupId, updateSchedule(result, schedule, processDefinition, scheduleExpression, warningType, warningGroupId,
failureStrategy, processInstancePriority, workerGroup, environmentCode); failureStrategy, processInstancePriority, workerGroup, tenantCode, environmentCode);
return result; return result;
} }
private void updateSchedule(Map<String, Object> result, Schedule schedule, ProcessDefinition processDefinition, private void updateSchedule(Map<String, Object> result, Schedule schedule, ProcessDefinition processDefinition,
String scheduleExpression, WarningType warningType, int warningGroupId, String scheduleExpression, WarningType warningType, int warningGroupId,
FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup, FailureStrategy failureStrategy, Priority processInstancePriority, String workerGroup,
String tenantCode,
long environmentCode) { long environmentCode) {
if (checkValid(result, schedule.getReleaseState() == ReleaseState.ONLINE, if (checkValid(result, schedule.getReleaseState() == ReleaseState.ONLINE,
Status.SCHEDULE_CRON_ONLINE_FORBID_UPDATE)) { Status.SCHEDULE_CRON_ONLINE_FORBID_UPDATE)) {
@ -806,6 +824,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
Date now = new Date(); Date now = new Date();
checkValidTenant(tenantCode);
schedule.setTenantCode(tenantCode);
// updateProcessInstance param // updateProcessInstance param
if (!StringUtils.isEmpty(scheduleExpression)) { if (!StringUtils.isEmpty(scheduleExpression)) {
ScheduleParam scheduleParam = JSONUtils.parseObject(scheduleExpression, ScheduleParam.class); ScheduleParam scheduleParam = JSONUtils.parseObject(scheduleExpression, ScheduleParam.class);
@ -860,4 +881,18 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
processDefinition.getProjectCode(), processDefinition.getCode(), schedule.getId()); processDefinition.getProjectCode(), processDefinition.getCode(), schedule.getId());
putMsg(result, Status.SUCCESS); 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);
}
}
}
} }

22
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.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.utils.PropertyUtils; 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.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.Queue; 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.Tenant;
import org.apache.dolphinscheduler.dao.entity.User; 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.ProcessInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
@ -77,7 +77,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
private ProcessInstanceMapper processInstanceMapper; private ProcessInstanceMapper processInstanceMapper;
@Autowired @Autowired
private ProcessDefinitionMapper processDefinitionMapper; private ScheduleMapper scheduleMapper;
@Autowired @Autowired
private UserMapper userMapper; 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()); throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL, processInstances.size());
} }
List<ProcessDefinition> processDefinitions = List<Schedule> schedules =
processDefinitionMapper.queryDefinitionListByTenant(tenant.getId()); scheduleMapper.queryScheduleListByTenant(tenant.getTenantCode());
if (CollectionUtils.isNotEmpty(processDefinitions)) { if (CollectionUtils.isNotEmpty(schedules)) {
log.warn("Delete tenant failed, because there are {} process definitions using it.", log.warn("Delete tenant failed, because there are {} schedule using it.",
processDefinitions.size()); schedules.size());
throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_DEFINES, processDefinitions.size()); throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_DEFINES, schedules.size());
} }
List<User> userList = userMapper.queryUserListByTenant(tenant.getId()); List<User> userList = userMapper.queryUserListByTenant(tenant.getId());
@ -299,7 +299,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
int delete = tenantMapper.deleteById(id); int delete = tenantMapper.deleteById(id);
if (delete > 0) { if (delete > 0) {
processInstanceMapper.updateProcessInstanceByTenantId(id, -1); processInstanceMapper.updateProcessInstanceByTenantCode(tenant.getTenantCode(), Constants.DEFAULT);
log.info("Tenant is deleted and id is {}.", id); log.info("Tenant is deleted and id is {}.", id);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} else { } else {
@ -311,7 +311,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
} }
private List<ProcessInstance> getProcessInstancesByTenant(Tenant tenant) { private List<ProcessInstance> getProcessInstancesByTenant(Tenant tenant) {
return processInstanceMapper.queryByTenantIdAndStatus(tenant.getId(), return processInstanceMapper.queryByTenantCodeAndStatus(tenant.getTenantCode(),
org.apache.dolphinscheduler.service.utils.Constants.NOT_TERMINATED_STATES); org.apache.dolphinscheduler.service.utils.Constants.NOT_TERMINATED_STATES);
} }

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/vo/ScheduleVo.java

@ -125,6 +125,11 @@ public class ScheduleVo {
*/ */
private String workerGroup; private String workerGroup;
/**
* tenantCode
*/
private String tenantCode;
/** /**
* environment code * environment code
*/ */
@ -156,5 +161,6 @@ public class ScheduleVo {
this.setStartTime(DateUtils.dateToString(schedule.getStartTime(), ZoneId.systemDefault().getId())); this.setStartTime(DateUtils.dateToString(schedule.getStartTime(), ZoneId.systemDefault().getId()));
this.setEndTime(DateUtils.dateToString(schedule.getEndTime(), ZoneId.systemDefault().getId())); this.setEndTime(DateUtils.dateToString(schedule.getEndTime(), ZoneId.systemDefault().getId()));
this.setEnvironmentName(schedule.getEnvironmentName()); this.setEnvironmentName(schedule.getEnvironmentName());
this.setTenantCode(schedule.getTenantCode());
} }
} }

15
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 RunMode runMode = RunMode.RUN_MODE_SERIAL;
final Priority processInstancePriority = Priority.HIGH; final Priority processInstancePriority = Priority.HIGH;
final String workerGroup = "workerGroup"; final String workerGroup = "workerGroup";
final String tenantCode = "root";
final Long environmentCode = 4L; final Long environmentCode = 4L;
final Integer timeout = 5; final Integer timeout = 5;
final ImmutableMap<String, String> startParams = ImmutableMap.of("start", "params"); final ImmutableMap<String, String> startParams = ImmutableMap.of("start", "params");
@ -104,6 +105,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
paramsMap.add("runMode", String.valueOf(runMode)); paramsMap.add("runMode", String.valueOf(runMode));
paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority)); paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority));
paramsMap.add("workerGroup", workerGroup); paramsMap.add("workerGroup", workerGroup);
paramsMap.add("tenantCode", tenantCode);
paramsMap.add("environmentCode", String.valueOf(environmentCode)); paramsMap.add("environmentCode", String.valueOf(environmentCode));
paramsMap.add("timeout", String.valueOf(timeout)); paramsMap.add("timeout", String.valueOf(timeout));
paramsMap.add("startParams", gson.toJson(startParams)); 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), when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType), eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType),
eq(warningType), 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(timeout), eq(startParams), eq(expectedParallelismNumber), eq(dryRun), eq(testFlag),
eq(complementDependentMode), eq(version))) eq(complementDependentMode), eq(version)))
.thenReturn(executeServiceResult); .thenReturn(executeServiceResult);
@ -148,6 +151,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
paramsMap.add("runMode", String.valueOf(runMode)); paramsMap.add("runMode", String.valueOf(runMode));
paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority)); paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority));
paramsMap.add("workerGroup", workerGroup); paramsMap.add("workerGroup", workerGroup);
paramsMap.add("tenantCode", tenantCode);
paramsMap.add("environmentCode", String.valueOf(environmentCode)); paramsMap.add("environmentCode", String.valueOf(environmentCode));
paramsMap.add("startParams", gson.toJson(startParams)); paramsMap.add("startParams", gson.toJson(startParams));
paramsMap.add("expectedParallelismNumber", String.valueOf(expectedParallelismNumber)); 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), when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType), eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType),
eq(warningType), 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(Constants.MAX_TASK_TIMEOUT), eq(startParams), eq(expectedParallelismNumber), eq(dryRun),
eq(testFlag), eq(testFlag),
eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult); eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult);
@ -191,6 +196,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
paramsMap.add("runMode", String.valueOf(runMode)); paramsMap.add("runMode", String.valueOf(runMode));
paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority)); paramsMap.add("processInstancePriority", String.valueOf(processInstancePriority));
paramsMap.add("workerGroup", workerGroup); paramsMap.add("workerGroup", workerGroup);
paramsMap.add("tenantCode", tenantCode);
paramsMap.add("environmentCode", String.valueOf(environmentCode)); paramsMap.add("environmentCode", String.valueOf(environmentCode));
paramsMap.add("timeout", String.valueOf(timeout)); paramsMap.add("timeout", String.valueOf(timeout));
paramsMap.add("expectedParallelismNumber", String.valueOf(expectedParallelismNumber)); 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), when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType), eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType),
eq(warningType), 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(timeout), eq(null), eq(expectedParallelismNumber), eq(dryRun), eq(testFlag),
eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult); 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), when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(null), eq(failureStrategy), eq(null), eq(null), eq(warningType), 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(Constants.MAX_TASK_TIMEOUT), eq(null), eq(null), eq(0), eq(0),
eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult); eq(complementDependentMode), eq(version))).thenReturn(executeServiceResult);

10
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java

@ -90,20 +90,19 @@ public class ProcessDefinitionControllerTest {
String globalParams = "[]"; String globalParams = "[]";
String locations = "[]"; String locations = "[]";
int timeout = 0; int timeout = 0;
String tenantCode = "root";
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, 1); result.put(Constants.DATA_LIST, 1);
Mockito.when( Mockito.when(
processDefinitionService.createProcessDefinition(user, projectCode, name, description, globalParams, processDefinitionService.createProcessDefinition(user, projectCode, name, description, globalParams,
locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", locations, timeout, relationJson, taskDefinitionJson, "",
ProcessExecutionTypeEnum.PARALLEL)) ProcessExecutionTypeEnum.PARALLEL))
.thenReturn(result); .thenReturn(result);
Result response = Result response =
processDefinitionController.createProcessDefinition(user, projectCode, name, description, globalParams, processDefinitionController.createProcessDefinition(user, projectCode, name, description, globalParams,
locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", locations, timeout, relationJson, taskDefinitionJson, "",
ProcessExecutionTypeEnum.PARALLEL); ProcessExecutionTypeEnum.PARALLEL);
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }
@ -160,7 +159,6 @@ public class ProcessDefinitionControllerTest {
String description = "desc test"; String description = "desc test";
String globalParams = "[]"; String globalParams = "[]";
int timeout = 0; int timeout = 0;
String tenantCode = "root";
long code = 123L; long code = 123L;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -168,12 +166,12 @@ public class ProcessDefinitionControllerTest {
Mockito.when(processDefinitionService.updateProcessDefinition(user, projectCode, name, code, description, Mockito.when(processDefinitionService.updateProcessDefinition(user, projectCode, name, code, description,
globalParams, globalParams,
locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", locations, timeout, relationJson, taskDefinitionJson, "",
ProcessExecutionTypeEnum.PARALLEL)).thenReturn(result); ProcessExecutionTypeEnum.PARALLEL)).thenReturn(result);
Result response = processDefinitionController.updateProcessDefinition(user, projectCode, name, code, Result response = processDefinitionController.updateProcessDefinition(user, projectCode, name, code,
description, globalParams, description, globalParams,
locations, timeout, tenantCode, relationJson, taskDefinitionJson, "", ProcessExecutionTypeEnum.PARALLEL, locations, timeout, relationJson, taskDefinitionJson, "", ProcessExecutionTypeEnum.PARALLEL,
ReleaseState.OFFLINE); ReleaseState.OFFLINE);
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }

6
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("receivers", "");
paramsMap.add("receiversCc", ""); paramsMap.add("receiversCc", "");
paramsMap.add("workerGroupId", "1"); paramsMap.add("workerGroupId", "1");
paramsMap.add("tenantCode", "root");
paramsMap.add("processInstancePriority", String.valueOf(Priority.HIGH)); paramsMap.add("processInstancePriority", String.valueOf(Priority.HIGH));
Mockito.when(schedulerService.insertSchedule(isA(User.class), isA(Long.class), isA(Long.class), 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(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) MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/", 123)
.header(SESSION_ID, sessionId) .header(SESSION_ID, sessionId)
@ -97,11 +98,12 @@ public class SchedulerControllerTest extends AbstractControllerTest {
paramsMap.add("receivers", ""); paramsMap.add("receivers", "");
paramsMap.add("receiversCc", ""); paramsMap.add("receiversCc", "");
paramsMap.add("workerGroupId", "1"); paramsMap.add("workerGroupId", "1");
paramsMap.add("tenantCode", "root");
paramsMap.add("processInstancePriority", String.valueOf(Priority.HIGH)); paramsMap.add("processInstancePriority", String.valueOf(Priority.HIGH));
Mockito.when(schedulerService.updateSchedule(isA(User.class), isA(Long.class), isA(Integer.class), 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(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) MvcResult mvcResult = mockMvc.perform(put("/projects/{projectCode}/schedules/{id}", 123, 37)
.header(SESSION_ID, sessionId) .header(SESSION_ID, sessionId)

3
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/WorkflowV2ControllerTest.java

@ -86,7 +86,6 @@ public class WorkflowV2ControllerTest {
workflowCreateRequest.setDescription(description); workflowCreateRequest.setDescription(description);
workflowCreateRequest.setGlobalParams(EMPTY_STRING); workflowCreateRequest.setGlobalParams(EMPTY_STRING);
workflowCreateRequest.setTimeout(timeout); workflowCreateRequest.setTimeout(timeout);
workflowCreateRequest.setTenantCode(tenantCode);
workflowCreateRequest.setWarningGroupId(warningGroupId); workflowCreateRequest.setWarningGroupId(warningGroupId);
workflowCreateRequest.setExecutionType(executionType); workflowCreateRequest.setExecutionType(executionType);
@ -139,7 +138,6 @@ public class WorkflowV2ControllerTest {
processDefinition.setDescription(description); processDefinition.setDescription(description);
processDefinition.setReleaseState(ReleaseState.valueOf(releaseState)); processDefinition.setReleaseState(ReleaseState.valueOf(releaseState));
processDefinition.setProjectCode(projectCode); processDefinition.setProjectCode(projectCode);
processDefinition.setTenantId(1);
processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType)); processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType));
processDefinition.setWarningGroupId(warningGroupId); processDefinition.setWarningGroupId(warningGroupId);
processDefinition.setGlobalParams(EMPTY_STRING); processDefinition.setGlobalParams(EMPTY_STRING);
@ -153,7 +151,6 @@ public class WorkflowV2ControllerTest {
processDefinition.setDescription(description); processDefinition.setDescription(description);
processDefinition.setReleaseState(ReleaseState.valueOf(releaseState)); processDefinition.setReleaseState(ReleaseState.valueOf(releaseState));
processDefinition.setProjectCode(projectCode); processDefinition.setProjectCode(projectCode);
processDefinition.setTenantId(1);
processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType)); processDefinition.setExecutionType(ProcessExecutionTypeEnum.valueOf(executionType));
processDefinition.setWarningGroupId(warningGroupId); processDefinition.setWarningGroupId(warningGroupId);
processDefinition.setGlobalParams(EMPTY_STRING); processDefinition.setGlobalParams(EMPTY_STRING);

40
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.TaskDefinitionLogMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskGroupQueueMapper; 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.dao.repository.ProcessInstanceDao;
import org.apache.dolphinscheduler.remote.processor.StateEventCallbackService; import org.apache.dolphinscheduler.remote.processor.StateEventCallbackService;
import org.apache.dolphinscheduler.service.command.CommandService; import org.apache.dolphinscheduler.service.command.CommandService;
@ -132,6 +133,9 @@ public class ExecuteFunctionServiceTest {
@Mock @Mock
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@Mock
private TenantMapper tenantMapper;
@Mock @Mock
private ProjectServiceImpl projectService; private ProjectServiceImpl projectService;
@ -167,7 +171,7 @@ public class ExecuteFunctionServiceTest {
private int processInstanceId = 1; private int processInstanceId = 1;
private int tenantId = 1; private String tenantCode = "root";
private int userId = 1; private int userId = 1;
@ -199,7 +203,6 @@ public class ExecuteFunctionServiceTest {
// processDefinition // processDefinition
processDefinition.setId(processDefinitionId); processDefinition.setId(processDefinitionId);
processDefinition.setReleaseState(ReleaseState.ONLINE); processDefinition.setReleaseState(ReleaseState.ONLINE);
processDefinition.setTenantId(tenantId);
processDefinition.setUserId(userId); processDefinition.setUserId(userId);
processDefinition.setVersion(1); processDefinition.setVersion(1);
processDefinition.setCode(1L); processDefinition.setCode(1L);
@ -210,7 +213,6 @@ public class ExecuteFunctionServiceTest {
processInstance.setProjectCode(projectCode); processInstance.setProjectCode(projectCode);
processInstance.setState(WorkflowExecutionStatus.FAILURE); processInstance.setState(WorkflowExecutionStatus.FAILURE);
processInstance.setExecutorId(userId); processInstance.setExecutorId(userId);
processInstance.setTenantId(tenantId);
processInstance.setHost("127.0.0.1:5678"); processInstance.setHost("127.0.0.1:5678");
processInstance.setProcessDefinitionVersion(1); processInstance.setProcessDefinitionVersion(1);
processInstance.setProcessDefinitionCode(1L); processInstance.setProcessDefinitionCode(1L);
@ -240,7 +242,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START)) Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_START))
.thenReturn(checkProjectAndAuth()); .thenReturn(checkProjectAndAuth());
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(this.processDefinition); 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(1).when(commandService).createCommand(argThat(c -> c.getId() == null));
doReturn(0).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()); Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(getMasterServersList());
@ -270,6 +272,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode))
.thenReturn(zeroSchedulerList()); .thenReturn(zeroSchedulerList());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode,
processDefinitionCode, processDefinitionCode,
"{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", "{\"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, null, null, null, null, null,
RunMode.RUN_MODE_SERIAL, 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, Constants.TEST_FLAG_NO,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
@ -293,6 +296,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode))
.thenReturn(zeroSchedulerList()); .thenReturn(zeroSchedulerList());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode,
processDefinitionCode, processDefinitionCode,
"{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", "{\"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, "123456789,987654321",
null, null, null, null, null, null,
RunMode.RUN_MODE_SERIAL, 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, Constants.TEST_FLAG_NO,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
@ -312,6 +316,7 @@ public class ExecuteFunctionServiceTest {
public void testComplementWithOldStartNodeList() { public void testComplementWithOldStartNodeList() {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode))
.thenReturn(zeroSchedulerList()); .thenReturn(zeroSchedulerList());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
try { try {
result = executorService.execProcessInstance(loginUser, projectCode, result = executorService.execProcessInstance(loginUser, projectCode,
@ -321,7 +326,8 @@ public class ExecuteFunctionServiceTest {
null, "1123456789,987654321", null, "1123456789,987654321",
null, null, null, null, null, null,
RunMode.RUN_MODE_SERIAL, 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, Constants.TEST_FLAG_NO,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
} catch (ServiceException e) { } catch (ServiceException e) {
@ -381,6 +387,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode))
.thenReturn(zeroSchedulerList()); .thenReturn(zeroSchedulerList());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode,
processDefinitionCode, processDefinitionCode,
"{\"complementStartDate\":\"2022-01-07 12:12:12\",\"complementEndDate\":\"2022-01-06 12:12:12\"}", "{\"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, null, null, null, null, null,
RunMode.RUN_MODE_SERIAL, 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, Constants.TEST_FLAG_NO,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
Assertions.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS)); Assertions.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS));
@ -403,6 +410,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode))
.thenReturn(zeroSchedulerList()); .thenReturn(zeroSchedulerList());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode,
processDefinitionCode, processDefinitionCode,
"{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", "{\"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, null, null, null, null, null,
RunMode.RUN_MODE_SERIAL, 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, Constants.TEST_FLAG_NO,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
@ -425,6 +433,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode))
.thenReturn(zeroSchedulerList()); .thenReturn(zeroSchedulerList());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode,
processDefinitionCode, processDefinitionCode,
"{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", "{\"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, null, null, null, null, null,
RunMode.RUN_MODE_PARALLEL, 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, Constants.TEST_FLAG_NO,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
@ -448,6 +457,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode)) Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionCode(processDefinitionCode))
.thenReturn(oneSchedulerList()); .thenReturn(oneSchedulerList());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode,
processDefinitionCode, processDefinitionCode,
"{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", "{\"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, null, null, null, null, null,
RunMode.RUN_MODE_PARALLEL, 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, Constants.TEST_FLAG_NO,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
@ -481,6 +492,7 @@ public class ExecuteFunctionServiceTest {
RunMode.RUN_MODE_PARALLEL, RunMode.RUN_MODE_PARALLEL,
Priority.LOW, Priority.LOW,
Constants.DEFAULT_WORKER_GROUP, Constants.DEFAULT_WORKER_GROUP,
tenantCode,
100L, 100L,
110, 110,
null, null,
@ -510,6 +522,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(commandService.verifyIsNeedCreateCommand(any(Command.class))).thenReturn(true); Mockito.when(commandService.verifyIsNeedCreateCommand(any(Command.class))).thenReturn(true);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, RERUN)) Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, RERUN))
.thenReturn(checkProjectAndAuth()); .thenReturn(checkProjectAndAuth());
Mockito.when(tenantMapper.queryByTenantCode(tenantCode)).thenReturn(new Tenant());
Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode, Map<String, Object> result = executorService.execProcessInstance(loginUser, projectCode,
processDefinitionCode, processDefinitionCode,
"{\"complementStartDate\":\"2020-01-01 00:00:00\",\"complementEndDate\":\"2020-01-31 23:00:00\"}", "{\"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,
null, null, 0, null, null, 0,
RunMode.RUN_MODE_PARALLEL, 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, Constants.TEST_FLAG_YES,
ComplementDependentMode.OFF_MODE, null); ComplementDependentMode.OFF_MODE, null);
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
@ -630,7 +644,7 @@ public class ExecuteFunctionServiceTest {
Mockito.when(processService.findProcessDefinition(Mockito.anyLong(), Mockito.anyInt())) Mockito.when(processService.findProcessDefinition(Mockito.anyLong(), Mockito.anyInt()))
.thenReturn(processDefinition); .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); when(processInstanceMock.getState().isFinished()).thenReturn(false);
WorkflowExecuteResponse responseInstanceIsNotFinished = WorkflowExecuteResponse responseInstanceIsNotFinished =

28
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_ONLINE_OFFLINE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_TREE_VIEW; 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.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.apache.dolphinscheduler.common.constants.Constants.EMPTY_STRING;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA; 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.Schedule;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskMainInfo; 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.User;
import org.apache.dolphinscheduler.dao.entity.UserWithProcessDefinitionCode; import org.apache.dolphinscheduler.dao.entity.UserWithProcessDefinitionCode;
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; 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.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; 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.mapper.UserMapper;
import org.apache.dolphinscheduler.dao.model.PageListingResult; import org.apache.dolphinscheduler.dao.model.PageListingResult;
import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao; import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao;
@ -167,9 +164,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Mock @Mock
private ProcessInstanceService processInstanceService; private ProcessInstanceService processInstanceService;
@Mock
private TenantMapper tenantMapper;
@Mock @Mock
private DataSourceMapper dataSourceMapper; private DataSourceMapper dataSourceMapper;
@ -202,7 +196,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
protected final static int warningGroupId = 1; protected final static int warningGroupId = 1;
protected final static int timeout = 60; protected final static int timeout = 60;
protected final static String executionType = "PARALLEL"; protected final static String executionType = "PARALLEL";
protected final static String tenantCode = "tenant";
@BeforeEach @BeforeEach
public void before() { public void before() {
@ -317,9 +310,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Project project = getProject(projectCode); Project project = getProject(projectCode);
Tenant tenant = new Tenant();
tenant.setId(1);
tenant.setTenantCode("root");
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
@ -345,7 +335,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION)) Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_DEFINITION))
.thenReturn(result); .thenReturn(result);
Mockito.when(tenantMapper.queryById(1)).thenReturn(tenant);
Map<String, Object> successRes = Map<String, Object> successRes =
processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 46L); processDefinitionService.queryProcessDefinitionByCode(user, projectCode, 46L);
Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
@ -833,7 +822,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
try { try {
processDefinitionService.updateProcessDefinition(user, projectCode, "test", 1, processDefinitionService.updateProcessDefinition(user, projectCode, "test", 1,
"", "", "", 0, "root", null, "", null, ProcessExecutionTypeEnum.PARALLEL); "", "", "", 0, null, "", null, ProcessExecutionTypeEnum.PARALLEL);
Assertions.fail(); Assertions.fail();
} catch (ServiceException ex) { } catch (ServiceException ex) {
Assertions.assertEquals(Status.DATA_IS_NOT_VALID.getCode(), ex.getCode()); 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(), Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(),
((ServiceException) exception).getCode()); ((ServiceException) exception).getCode());
// tenant not exists
Mockito.when(processDefinitionMapper.verifyByDefineName(project.getCode(), name)).thenReturn(null); 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 // test success
workflowCreateRequest.setTenantCode(DEFAULT);
workflowCreateRequest.setDescription(description); workflowCreateRequest.setDescription(description);
workflowCreateRequest.setTimeout(timeout); workflowCreateRequest.setTimeout(timeout);
workflowCreateRequest.setReleaseState(releaseState); workflowCreateRequest.setReleaseState(releaseState);
@ -1081,18 +1065,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(), Assertions.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST.getCode(),
((ServiceException) exception).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.queryByCode(processDefinitionCode)).thenReturn(processDefinition);
Mockito.when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName())) Mockito.when(processDefinitionMapper.verifyByDefineName(projectCode, workflowUpdateRequest.getName()))
.thenReturn(null); .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 // error update process definition mapper
workflowUpdateRequest.setName(name); workflowUpdateRequest.setName(name);
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition);
@ -1154,7 +1129,6 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
processDefinition.setId(46); processDefinition.setId(46);
processDefinition.setProjectCode(1L); processDefinition.setProjectCode(1L);
processDefinition.setName("test_pdf"); processDefinition.setName("test_pdf");
processDefinition.setTenantId(1);
processDefinition.setDescription(""); processDefinition.setDescription("");
processDefinition.setCode(processDefinitionCode); processDefinition.setCode(processDefinitionCode);
processDefinition.setProjectCode(projectCode); processDefinition.setProjectCode(projectCode);

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java

@ -591,7 +591,8 @@ public class ProcessInstanceServiceTest {
Tenant tenant = getTenant(); Tenant tenant = getTenant();
when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition);
when(tenantMapper.queryByTenantCode("root")).thenReturn(tenant); 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(processInstanceDao.updateProcessInstance(processInstance)).thenReturn(1);
when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.FALSE)).thenReturn(1); when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.FALSE)).thenReturn(1);
@ -815,7 +816,6 @@ public class ProcessInstanceServiceTest {
processDefinition.setId(46); processDefinition.setId(46);
processDefinition.setName("test_pdf"); processDefinition.setName("test_pdf");
processDefinition.setProjectCode(2L); processDefinition.setProjectCode(2L);
processDefinition.setTenantId(1);
processDefinition.setDescription(""); processDefinition.setDescription("");
return processDefinition; return processDefinition;
} }

1
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceTest.java

@ -255,7 +255,6 @@ public class ProcessTaskRelationServiceTest {
processDefinition.setId(1); processDefinition.setId(1);
processDefinition.setProjectCode(1L); processDefinition.setProjectCode(1L);
processDefinition.setName("test_pdf"); processDefinition.setName("test_pdf");
processDefinition.setTenantId(1);
processDefinition.setDescription(""); processDefinition.setDescription("");
processDefinition.setCode(1L); processDefinition.setCode(1L);
processDefinition.setVersion(1); processDefinition.setVersion(1);

6
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.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.service.impl.SchedulerServiceImpl; 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.enums.ReleaseState;
import org.apache.dolphinscheduler.common.model.Server; import org.apache.dolphinscheduler.common.model.Server;
import org.apache.dolphinscheduler.dao.entity.Environment; 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.ProcessTaskRelationMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; 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.scheduler.api.SchedulerApi;
import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.dolphinscheduler.service.process.ProcessService;
@ -96,6 +98,9 @@ public class SchedulerServiceTest extends BaseServiceTestTool {
@Mock @Mock
private EnvironmentMapper environmentMapper; private EnvironmentMapper environmentMapper;
@Mock
private TenantMapper tenantMapper;
protected static User user; protected static User user;
protected Exception exception; protected Exception exception;
private static final String userName = "userName"; private static final String userName = "userName";
@ -185,6 +190,7 @@ public class SchedulerServiceTest extends BaseServiceTestTool {
ScheduleCreateRequest scheduleCreateRequest = new ScheduleCreateRequest(); ScheduleCreateRequest scheduleCreateRequest = new ScheduleCreateRequest();
scheduleCreateRequest.setProcessDefinitionCode(processDefinitionCode); scheduleCreateRequest.setProcessDefinitionCode(processDefinitionCode);
scheduleCreateRequest.setEnvironmentCode(environmentCode); scheduleCreateRequest.setEnvironmentCode(environmentCode);
scheduleCreateRequest.setTenantCode(Constants.DEFAULT);
// error process definition not exists // error process definition not exists
exception = Assertions.assertThrows(ServiceException.class, exception = Assertions.assertThrows(ServiceException.class,

28
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_CREATE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TENANT_DELETE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TENANT_DELETE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TENANT_UPDATE; 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.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException; 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.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.UserType; 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.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.Queue; 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.Tenant;
import org.apache.dolphinscheduler.dao.entity.User; 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.ProcessInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate; import org.apache.dolphinscheduler.plugin.storage.api.StorageOperate;
@ -46,6 +47,7 @@ import org.apache.commons.collections4.CollectionUtils;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -86,7 +88,7 @@ public class TenantServiceTest {
private TenantMapper tenantMapper; private TenantMapper tenantMapper;
@Mock @Mock
private ProcessDefinitionMapper processDefinitionMapper; private ScheduleMapper scheduleMapper;
@Mock @Mock
private ProcessInstanceMapper processInstanceMapper; private ProcessInstanceMapper processInstanceMapper;
@ -171,7 +173,7 @@ public class TenantServiceTest {
ids.add(1); ids.add(1);
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.TENANT, Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.TENANT,
getLoginUser().getId(), tenantServiceImplLogger)).thenReturn(ids); 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); .thenReturn(page);
Result result = tenantService.queryTenantList(getLoginUser(), tenantDesc, 1, 10); Result result = tenantService.queryTenantList(getLoginUser(), tenantDesc, 1, 10);
PageInfo<Tenant> pageInfo = (PageInfo<Tenant>) result.getData(); PageInfo<Tenant> pageInfo = (PageInfo<Tenant>) result.getData();
@ -209,10 +211,10 @@ public class TenantServiceTest {
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0,
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); 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)) org.apache.dolphinscheduler.service.utils.Constants.NOT_TERMINATED_STATES))
.thenReturn(getInstanceList()); .thenReturn(getInstanceList());
Mockito.when(processDefinitionMapper.queryDefinitionListByTenant(2)).thenReturn(getDefinitionsList()); Mockito.when(scheduleMapper.queryScheduleListByTenant(tenantCode)).thenReturn(getScheduleList());
Mockito.when(userMapper.queryUserListByTenant(3)).thenReturn(getUserList()); Mockito.when(userMapper.queryUserListByTenant(3)).thenReturn(getUserList());
// TENANT_NOT_EXIST // TENANT_NOT_EXIST
@ -241,6 +243,10 @@ public class TenantServiceTest {
Assertions.assertTrue(exception.getMessage().contains(prefix)); Assertions.assertTrue(exception.getMessage().contains(prefix));
// success // 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.queryById(4)).thenReturn(getTenant(4));
Mockito.when(tenantMapper.deleteById(4)).thenReturn(1); Mockito.when(tenantMapper.deleteById(4)).thenReturn(1);
Map<String, Object> result = tenantService.deleteTenantById(getLoginUser(), 4); Map<String, Object> result = tenantService.deleteTenantById(getLoginUser(), 4);
@ -326,11 +332,11 @@ public class TenantServiceTest {
return processInstances; return processInstances;
} }
private List<ProcessDefinition> getDefinitionsList() { private List<Schedule> getScheduleList() {
List<ProcessDefinition> processDefinitions = new ArrayList<>(); List<Schedule> schedules = new ArrayList<>();
ProcessDefinition processDefinition = new ProcessDefinition(); Schedule schedule = new Schedule();
processDefinitions.add(processDefinition); schedules.add(schedule);
return processDefinitions; return schedules;
} }
private Queue getQueue() { private Queue getQueue() {

5
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java

@ -87,6 +87,11 @@ public class Command {
@TableField("worker_group") @TableField("worker_group")
private String workerGroup; private String workerGroup;
/**
* tenant code
*/
private String tenantCode;
@TableField("environment_code") @TableField("environment_code")
private Long environmentCode; private Long environmentCode;

5
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ErrorCommand.java

@ -112,6 +112,11 @@ public class ErrorCommand {
*/ */
private String workerGroup; private String workerGroup;
/**
* tenant code
*/
private String tenantCode;
/** /**
* environment code * environment code
*/ */

20
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java

@ -148,17 +148,6 @@ public class ProcessDefinition {
*/ */
private int timeout; private int timeout;
/**
* tenant id
*/
private int tenantId;
/**
* tenant code
*/
@TableField(exist = false)
private String tenantCode;
/** /**
* modify user name * modify user name
*/ */
@ -183,9 +172,8 @@ public class ProcessDefinition {
String globalParams, String globalParams,
String locations, String locations,
int timeout, int timeout,
int userId, int userId) {
int tenantId) { set(projectCode, name, description, globalParams, locations, timeout);
set(projectCode, name, description, globalParams, locations, timeout, tenantId);
this.code = code; this.code = code;
this.userId = userId; this.userId = userId;
Date date = new Date(); Date date = new Date();
@ -198,15 +186,13 @@ public class ProcessDefinition {
String description, String description,
String globalParams, String globalParams,
String locations, String locations,
int timeout, int timeout) {
int tenantId) {
this.projectCode = projectCode; this.projectCode = projectCode;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.globalParams = globalParams; this.globalParams = globalParams;
this.locations = locations; this.locations = locations;
this.timeout = timeout; this.timeout = timeout;
this.tenantId = tenantId;
this.flag = Flag.YES; this.flag = Flag.YES;
} }

1
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.setLocations(processDefinition.getLocations());
this.setScheduleReleaseState(processDefinition.getScheduleReleaseState()); this.setScheduleReleaseState(processDefinition.getScheduleReleaseState());
this.setTimeout(processDefinition.getTimeout()); this.setTimeout(processDefinition.getTimeout());
this.setTenantId(processDefinition.getTenantId());
this.setModifyBy(processDefinition.getModifyBy()); this.setModifyBy(processDefinition.getModifyBy());
this.setWarningGroupId(processDefinition.getWarningGroupId()); this.setWarningGroupId(processDefinition.getWarningGroupId());
this.setExecutionType(processDefinition.getExecutionType()); this.setExecutionType(processDefinition.getExecutionType());

2
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java

@ -124,8 +124,6 @@ public class ProcessInstance {
private String executorName; private String executorName;
private int tenantId;
private String tenantCode; private String tenantCode;
/** /**

5
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Schedule.java

@ -133,6 +133,11 @@ public class Schedule {
*/ */
private String workerGroup; private String workerGroup;
/**
* tenant code
*/
private String tenantCode;
/** /**
* environment code * environment code
*/ */

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java

@ -150,14 +150,6 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
*/ */
List<ProcessDefinition> queryDefinitionListByIdList(@Param("ids") Integer[] ids); List<ProcessDefinition> queryDefinitionListByIdList(@Param("ids") Integer[] ids);
/**
* query process definition by tenant
*
* @param tenantId tenantId
* @return process definition list
*/
List<ProcessDefinition> queryDefinitionListByTenant(@Param("tenantId") int tenantId);
/** /**
* Statistics process definition group by project codes list * Statistics process definition group by project codes list
* <p> * <p>

16
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java

@ -63,13 +63,13 @@ public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {
List<String> queryNeedFailoverProcessInstanceHost(@Param("states") int[] stateArray); List<String> 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 * @param states states array
* @return process instance list * @return process instance list
*/ */
List<ProcessInstance> queryByTenantIdAndStatus(@Param("tenantId") int tenantId, List<ProcessInstance> queryByTenantCodeAndStatus(@Param("tenantCode") String tenantCode,
@Param("states") int[] states); @Param("states") int[] states);
/** /**
@ -139,14 +139,14 @@ public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {
@Param("destState") WorkflowExecutionStatus destState); @Param("destState") WorkflowExecutionStatus destState);
/** /**
* update process instance by tenantId * update process instance by tenantCode
* *
* @param originTenantId originTenantId * @param originTenantCode originTenantCode
* @param destTenantId destTenantId * @param destTenantCode destTenantCode
* @return update result * @return update result
*/ */
int updateProcessInstanceByTenantId(@Param("originTenantId") int originTenantId, int updateProcessInstanceByTenantCode(@Param("originTenantCode") String originTenantCode,
@Param("destTenantId") int destTenantId); @Param("destTenantCode") String destTenantCode);
/** /**
* update process instance by worker groupId * update process instance by worker groupId

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java

@ -104,4 +104,12 @@ public interface ScheduleMapper extends BaseMapper<Schedule> {
* @return schedule * @return schedule
*/ */
List<Schedule> querySchedulesByProcessDefinitionCodes(@Param("processDefinitionCodeList") List<Long> processDefinitionCodeList); List<Schedule> querySchedulesByProcessDefinitionCodes(@Param("processDefinitionCodeList") List<Long> processDefinitionCodeList);
/**
* query schedule by tenant
*
* @param tenantCode tenantCode
* @return schedule list
*/
List<Schedule> queryScheduleListByTenant(@Param("tenantCode") String tenantCode);
} }

20
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<ProcessDefinitionLog> processDefinitionLogs) { public void executeJsonSplitProcessDefinition(Connection conn, List<ProcessDefinitionLog> processDefinitionLogs) {
String updateSql = 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 = String insertLogSql =
"insert into t_ds_process_definition_log (code,name,version,description,project_code,release_state,user_id," "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 { try {
PreparedStatement processUpdate = conn.prepareStatement(updateSql); PreparedStatement processUpdate = conn.prepareStatement(updateSql);
PreparedStatement insertLog = conn.prepareStatement(insertLogSql); PreparedStatement insertLog = conn.prepareStatement(insertLogSql);
@ -50,10 +50,9 @@ public class JsonSplitDao {
for (ProcessDefinitionLog processDefinitionLog : processDefinitionLogs) { for (ProcessDefinitionLog processDefinitionLog : processDefinitionLogs) {
processUpdate.setString(1, processDefinitionLog.getGlobalParams()); processUpdate.setString(1, processDefinitionLog.getGlobalParams());
processUpdate.setInt(2, processDefinitionLog.getTimeout()); processUpdate.setInt(2, processDefinitionLog.getTimeout());
processUpdate.setInt(3, processDefinitionLog.getTenantId()); processUpdate.setString(3, processDefinitionLog.getLocations());
processUpdate.setString(4, processDefinitionLog.getLocations()); processUpdate.setDate(4, new Date(processDefinitionLog.getUpdateTime().getTime()));
processUpdate.setDate(5, new Date(processDefinitionLog.getUpdateTime().getTime())); processUpdate.setInt(5, processDefinitionLog.getId());
processUpdate.setInt(6, processDefinitionLog.getId());
processUpdate.addBatch(); processUpdate.addBatch();
insertLog.setLong(1, processDefinitionLog.getCode()); insertLog.setLong(1, processDefinitionLog.getCode());
@ -67,11 +66,10 @@ public class JsonSplitDao {
insertLog.setInt(9, processDefinitionLog.getFlag().getCode()); insertLog.setInt(9, processDefinitionLog.getFlag().getCode());
insertLog.setString(10, processDefinitionLog.getLocations()); insertLog.setString(10, processDefinitionLog.getLocations());
insertLog.setInt(11, processDefinitionLog.getTimeout()); insertLog.setInt(11, processDefinitionLog.getTimeout());
insertLog.setInt(12, processDefinitionLog.getTenantId()); insertLog.setInt(12, processDefinitionLog.getOperator());
insertLog.setInt(13, processDefinitionLog.getOperator()); insertLog.setDate(13, new Date(processDefinitionLog.getOperateTime().getTime()));
insertLog.setDate(14, new Date(processDefinitionLog.getOperateTime().getTime())); insertLog.setDate(14, new Date(processDefinitionLog.getCreateTime().getTime()));
insertLog.setDate(15, new Date(processDefinitionLog.getCreateTime().getTime())); insertLog.setDate(15, new Date(processDefinitionLog.getUpdateTime().getTime()));
insertLog.setDate(16, new Date(processDefinitionLog.getUpdateTime().getTime()));
insertLog.addBatch(); insertLog.addBatch();
i++; i++;

4
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml

@ -22,13 +22,13 @@
<sql id="baseSql"> <sql id="baseSql">
id, code, name, version, description, project_code, id, code, name, version, description, project_code,
release_state, user_id,global_params, flag, locations, 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 update_time
</sql> </sql>
<select id="queryByDefinitionName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog"> <select id="queryByDefinitionName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog">
select pd.id, pd.code, pd.name, pd.version, pd.description, pd.project_code, select pd.id, pd.code, pd.name, pd.version, pd.description, pd.project_code,
pd.release_state, pd.user_id,pd.global_params, pd.flag, pd.locations, pd.release_state, pd.user_id,pd.global_params, pd.flag, pd.locations,
pd.warning_group_id, pd.timeout, pd.tenant_id,pd.operator, pd.operate_time, pd.create_time, pd.warning_group_id, pd.timeout, pd.operator, pd.operate_time, pd.create_time,
pd.update_time, u.user_name,p.name as project_name ,pd.execution_type pd.update_time, u.user_name,p.name as project_name ,pd.execution_type
from t_ds_process_definition_log pd from t_ds_process_definition_log pd
JOIN t_ds_user u ON pd.user_id = u.id JOIN t_ds_user u ON pd.user_id = u.id

18
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml

@ -20,12 +20,12 @@
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper"> <mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper">
<sql id="baseSql"> <sql id="baseSql">
id, code, name, version, release_state, project_code, user_id, description, id, code, name, version, release_state, project_code, user_id, description,
global_params, flag, locations, warning_group_id, create_time, timeout, tenant_id, update_time,execution_type global_params, flag, locations, warning_group_id, create_time, timeout, update_time,execution_type
</sql> </sql>
<select id="verifyByDefineName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition"> <select id="verifyByDefineName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select pd.id, pd.code, pd.name, pd.version, pd.release_state, pd.project_code, pd.user_id, pd.description, 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 from t_ds_process_definition pd
WHERE pd.project_code = #{projectCode} WHERE pd.project_code = #{projectCode}
and pd.name = #{processDefinitionName} and pd.name = #{processDefinitionName}
@ -57,13 +57,11 @@
<select id="queryByDefineName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition"> <select id="queryByDefineName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select pd.id, pd.code, pd.name, pd.version, pd.release_state, pd.project_code, p.id as project_id, pd.user_id, pd.description, select pd.id, pd.code, pd.name, pd.version, pd.release_state, pd.project_code, p.id as project_id, 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.global_params, pd.flag, pd.locations, pd.warning_group_id, pd.create_time, pd.timeout, pd.update_time,
u.user_name,p.name as project_name,t.tenant_code,q.queue,q.queue_name,pd.execution_type u.user_name,p.name as project_name,pd.execution_type
from t_ds_process_definition pd from t_ds_process_definition pd
JOIN t_ds_user u ON pd.user_id = u.id JOIN t_ds_user u ON pd.user_id = u.id
JOIN t_ds_project p ON pd.project_code = p.code JOIN t_ds_project p ON pd.project_code = p.code
LEFT JOIN t_ds_tenant t ON t.id = u.tenant_id
LEFT JOIN t_ds_queue q ON t.queue_id = q.id
WHERE p.code = #{projectCode} WHERE p.code = #{projectCode}
and pd.name = #{processDefinitionName} and pd.name = #{processDefinitionName}
</select> </select>
@ -124,12 +122,6 @@
</foreach> </foreach>
</if> </if>
</select> </select>
<select id="queryDefinitionListByTenant" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select
<include refid="baseSql"/>
from t_ds_process_definition
where tenant_id = #{tenantId}
</select>
<select id="queryDefinitionListByIdList" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition"> <select id="queryDefinitionListByIdList" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select select
<include refid="baseSql"/> <include refid="baseSql"/>
@ -175,7 +167,7 @@
SELECT SELECT
pd.id, pd.code, pd.name, pd.version, pd.release_state, pd.project_code, pd.user_id, pd.description, 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.global_params, pd.flag, pd.locations, pd.warning_group_id, pd.create_time, pd.timeout,
pd.tenant_id, pd.update_time, u.user_name,p.name AS project_name ,pd.execution_type pd.update_time, u.user_name,p.name AS project_name ,pd.execution_type
FROM FROM
t_ds_process_definition pd, t_ds_process_definition pd,
t_ds_user u, t_ds_user u,

16
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml

@ -24,7 +24,7 @@
command_type, command_param, task_depend_type, max_try_times, failure_strategy, warning_type, command_type, command_param, task_depend_type, max_try_times, failure_strategy, warning_type,
warning_group_id, schedule_time, command_start_time, global_params, flag, warning_group_id, schedule_time, command_start_time, global_params, flag,
update_time, is_sub_process, executor_id, history_cmd, update_time, is_sub_process, executor_id, history_cmd,
process_instance_priority, worker_group,environment_code, timeout, tenant_id, tenant_code, var_pool, process_instance_priority, worker_group,environment_code, timeout, tenant_code, var_pool,
dry_run, test_flag, next_process_instance_id, restart_time, state_history dry_run, test_flag, next_process_instance_id, restart_time, state_history
</sql> </sql>
@ -34,7 +34,7 @@
command_type, ${alias}.command_param, ${alias}.task_depend_type, ${alias}.max_try_times, ${alias}.failure_strategy, ${alias}.warning_type, command_type, ${alias}.command_param, ${alias}.task_depend_type, ${alias}.max_try_times, ${alias}.failure_strategy, ${alias}.warning_type,
warning_group_id, ${alias}.schedule_time, ${alias}.command_start_time, ${alias}.global_params, ${alias}.flag, warning_group_id, ${alias}.schedule_time, ${alias}.command_start_time, ${alias}.global_params, ${alias}.flag,
update_time, ${alias}.is_sub_process, ${alias}.executor_id, ${alias}.history_cmd, update_time, ${alias}.is_sub_process, ${alias}.executor_id, ${alias}.history_cmd,
process_instance_priority, ${alias}.worker_group,environment_code, ${alias}.timeout, ${alias}.tenant_id, ${alias}.tenant_code, ${alias}.var_pool, process_instance_priority, ${alias}.worker_group,environment_code, ${alias}.timeout, ${alias}.tenant_code, ${alias}.var_pool,
dry_run, ${alias}.test_flag, ${alias}.next_process_instance_id, ${alias}.restart_time, ${alias}.state_history dry_run, ${alias}.test_flag, ${alias}.next_process_instance_id, ${alias}.restart_time, ${alias}.state_history
</sql> </sql>
@ -85,13 +85,13 @@
limit #{size} limit #{size}
</select> </select>
<select id="queryByTenantIdAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance"> <select id="queryByTenantCodeAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select select
<include refid="baseSql"/> <include refid="baseSql"/>
from t_ds_process_instance from t_ds_process_instance
where 1=1 where 1=1
<if test="tenantId != -1"> <if test="tenantCode != ''">
and tenant_id =#{tenantId} and tenant_code =#{tenantCode}
</if> </if>
<if test="states != null and states.length != 0"> <if test="states != null and states.length != 0">
and state in and state in
@ -168,10 +168,10 @@
where state = #{originState} where state = #{originState}
</update> </update>
<update id="updateProcessInstanceByTenantId"> <update id="updateProcessInstanceByTenantCode">
update t_ds_process_instance update t_ds_process_instance
set tenant_id = #{destTenantId} set tenant_code = #{destTenantCode}
where tenant_id = #{originTenantId} where tenant_code = #{originTenantCode}
</update> </update>
<update id="updateProcessInstanceByWorkerGroupName"> <update id="updateProcessInstanceByWorkerGroupName">

11
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml

@ -20,12 +20,12 @@
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ScheduleMapper"> <mapper namespace="org.apache.dolphinscheduler.dao.mapper.ScheduleMapper">
<sql id="baseSql"> <sql id="baseSql">
id, process_definition_code, start_time, end_time, timezone_id, crontab, failure_strategy, user_id, release_state, 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
</sql> </sql>
<sql id="baseSqlV2"> <sql id="baseSqlV2">
${alias}.id, ${alias}.process_definition_code, ${alias}.start_time, ${alias}.end_time, ${alias}.timezone_id, ${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}.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 ${alias}.update_time
</sql> </sql>
<select id="queryByProcessDefineCodePaging" resultType="org.apache.dolphinscheduler.dao.entity.Schedule"> <select id="queryByProcessDefineCodePaging" resultType="org.apache.dolphinscheduler.dao.entity.Schedule">
@ -116,4 +116,11 @@
</where> </where>
order by update_time desc, id asc order by update_time desc, id asc
</select> </select>
<select id="queryScheduleListByTenant" resultType="org.apache.dolphinscheduler.dao.entity.Schedule">
select
<include refid="baseSql"/>
from t_ds_schedules
where tenant_code = #{tenantCode}
</select>
</mapper> </mapper>

8
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql

@ -333,6 +333,7 @@ CREATE TABLE t_ds_command
update_time datetime DEFAULT NULL, update_time datetime DEFAULT NULL,
process_instance_priority int(11) DEFAULT '2', process_instance_priority int(11) DEFAULT '2',
worker_group varchar(255), worker_group varchar(255),
tenant_code varchar(64) DEFAULT 'default',
environment_code bigint(20) DEFAULT '-1', environment_code bigint(20) DEFAULT '-1',
dry_run int NULL DEFAULT 0, dry_run int NULL DEFAULT 0,
process_instance_id int(11) DEFAULT 0, process_instance_id int(11) DEFAULT 0,
@ -390,6 +391,7 @@ CREATE TABLE t_ds_error_command
update_time datetime DEFAULT NULL, update_time datetime DEFAULT NULL,
process_instance_priority int(11) DEFAULT '2', process_instance_priority int(11) DEFAULT '2',
worker_group varchar(255), worker_group varchar(255),
tenant_code varchar(64) DEFAULT 'default',
environment_code bigint(20) DEFAULT '-1', environment_code bigint(20) DEFAULT '-1',
message text, message text,
dry_run int NULL DEFAULT 0, dry_run int NULL DEFAULT 0,
@ -422,7 +424,6 @@ CREATE TABLE t_ds_process_definition
locations text, locations text,
warning_group_id int(11) DEFAULT NULL, warning_group_id int(11) DEFAULT NULL,
timeout int(11) DEFAULT '0', timeout int(11) DEFAULT '0',
tenant_id int(11) NOT NULL DEFAULT '-1',
execution_type tinyint(4) DEFAULT '0', execution_type tinyint(4) DEFAULT '0',
create_time datetime NOT NULL, create_time datetime NOT NULL,
update_time datetime DEFAULT NULL, update_time datetime DEFAULT NULL,
@ -454,7 +455,6 @@ CREATE TABLE t_ds_process_definition_log
locations text, locations text,
warning_group_id int(11) DEFAULT NULL, warning_group_id int(11) DEFAULT NULL,
timeout int(11) DEFAULT '0', timeout int(11) DEFAULT '0',
tenant_id int(11) NOT NULL DEFAULT '-1',
execution_type tinyint(4) DEFAULT '0', execution_type tinyint(4) DEFAULT '0',
operator int(11) DEFAULT NULL, operator int(11) DEFAULT NULL,
operate_time datetime DEFAULT NULL, operate_time datetime DEFAULT NULL,
@ -625,8 +625,7 @@ CREATE TABLE t_ds_process_instance
environment_code bigint(20) DEFAULT '-1', environment_code bigint(20) DEFAULT '-1',
timeout int(11) DEFAULT '0', timeout int(11) DEFAULT '0',
next_process_instance_id 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 'default',
tenant_code varchar(64) DEFAULT NULL,
var_pool longtext, var_pool longtext,
dry_run int NULL DEFAULT 0, dry_run int NULL DEFAULT 0,
restart_time datetime DEFAULT NULL, restart_time datetime DEFAULT NULL,
@ -817,6 +816,7 @@ CREATE TABLE t_ds_schedules
warning_group_id int(11) DEFAULT NULL, warning_group_id int(11) DEFAULT NULL,
process_instance_priority int(11) DEFAULT '2', process_instance_priority int(11) DEFAULT '2',
worker_group varchar(255) DEFAULT '', worker_group varchar(255) DEFAULT '',
tenant_code varchar(64) DEFAULT 'default',
environment_code bigint(20) DEFAULT '-1', environment_code bigint(20) DEFAULT '-1',
create_time datetime NOT NULL, create_time datetime NOT NULL,
update_time datetime NOT NULL, update_time datetime NOT NULL,

8
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', `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', `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', `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', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code',
`dry_run` tinyint(4) DEFAULT '0' COMMENT 'dry run flag:0 normal, 1 dry run', `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', `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', `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', `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', `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', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code',
`message` text COMMENT 'message', `message` text COMMENT 'message',
`dry_run` tinyint(4) DEFAULT '0' COMMENT 'dry run flag: 0 normal, 1 dry run', `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', `locations` text COMMENT 'Node location information',
`warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id', `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id',
`timeout` int(11) DEFAULT '0' COMMENT 'time out, unit: minute', `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', `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', `create_time` datetime NOT NULL COMMENT 'create time',
`update_time` datetime NOT NULL COMMENT 'update 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', `locations` text COMMENT 'Node location information',
`warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id', `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id',
`timeout` int(11) DEFAULT '0' COMMENT 'time out,unit: minute', `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', `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', `operator` int(11) DEFAULT NULL COMMENT 'operator user id',
`operate_time` datetime DEFAULT NULL COMMENT 'operate time', `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', `worker_group` varchar(255) DEFAULT NULL COMMENT 'worker group id',
`environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code',
`timeout` int(11) DEFAULT '0' COMMENT 'time out', `timeout` int(11) DEFAULT '0' COMMENT 'time out',
`tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id', `tenant_code` varchar(64) DEFAULT 'default' COMMENT 'tenant code',
`tenant_code` varchar(64) DEFAULT NULL COMMENT 'tenant code',
`var_pool` longtext COMMENT 'var_pool', `var_pool` longtext COMMENT 'var_pool',
`dry_run` tinyint(4) DEFAULT '0' COMMENT 'dry run flag:0 normal, 1 dry run', `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', `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', `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', `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', `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', `environment_code` bigint(20) DEFAULT '-1' COMMENT 'environment code',
`create_time` datetime NOT NULL COMMENT 'create time', `create_time` datetime NOT NULL COMMENT 'create time',
`update_time` datetime NOT NULL COMMENT 'update time', `update_time` datetime NOT NULL COMMENT 'update time',

8
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql

@ -264,6 +264,7 @@ CREATE TABLE t_ds_command (
update_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL ,
process_instance_priority int DEFAULT '2' , process_instance_priority int DEFAULT '2' ,
worker_group varchar(255), worker_group varchar(255),
tenant_code varchar(64) DEFAULT 'default',
environment_code bigint DEFAULT '-1', environment_code bigint DEFAULT '-1',
dry_run int DEFAULT '0' , dry_run int DEFAULT '0' ,
process_instance_id int DEFAULT 0, process_instance_id int DEFAULT 0,
@ -314,6 +315,7 @@ CREATE TABLE t_ds_error_command (
update_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL ,
process_instance_priority int DEFAULT '2' , process_instance_priority int DEFAULT '2' ,
worker_group varchar(255), worker_group varchar(255),
tenant_code varchar(64) DEFAULT 'default',
environment_code bigint DEFAULT '-1', environment_code bigint DEFAULT '-1',
dry_run int DEFAULT '0' , dry_run int DEFAULT '0' ,
message text , message text ,
@ -341,7 +343,6 @@ CREATE TABLE t_ds_process_definition (
warning_group_id int DEFAULT NULL , warning_group_id int DEFAULT NULL ,
flag int DEFAULT NULL , flag int DEFAULT NULL ,
timeout int DEFAULT '0' , timeout int DEFAULT '0' ,
tenant_id int DEFAULT '-1' ,
execution_type int DEFAULT '0', execution_type int DEFAULT '0',
create_time timestamp DEFAULT NULL , create_time timestamp DEFAULT NULL ,
update_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 , warning_group_id int DEFAULT NULL ,
flag int DEFAULT NULL , flag int DEFAULT NULL ,
timeout int DEFAULT '0' , timeout int DEFAULT '0' ,
tenant_id int DEFAULT '-1' ,
execution_type int DEFAULT '0', execution_type int DEFAULT '0',
operator int DEFAULT NULL , operator int DEFAULT NULL ,
operate_time timestamp DEFAULT NULL , operate_time timestamp DEFAULT NULL ,
@ -554,8 +554,7 @@ CREATE TABLE t_ds_process_instance (
worker_group varchar(255) , worker_group varchar(255) ,
environment_code bigint DEFAULT '-1', environment_code bigint DEFAULT '-1',
timeout int DEFAULT '0' , timeout int DEFAULT '0' ,
tenant_id int NOT NULL DEFAULT '-1' , tenant_code varchar(64) DEFAULT 'default',
tenant_code varchar(64) DEFAULT NULL ,
var_pool text , var_pool text ,
dry_run int DEFAULT '0' , dry_run int DEFAULT '0' ,
next_process_instance_id 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 , warning_group_id int DEFAULT NULL ,
process_instance_priority int DEFAULT '2' , process_instance_priority int DEFAULT '2' ,
worker_group varchar(255), worker_group varchar(255),
tenant_code varchar(64) DEFAULT 'default',
environment_code bigint DEFAULT '-1', environment_code bigint DEFAULT '-1',
create_time timestamp NOT NULL , create_time timestamp NOT NULL ,
update_time timestamp NOT NULL , update_time timestamp NOT NULL ,

36
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; CALL add_t_ds_task_instance_idx_cache_key;
DROP PROCEDURE 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; drop PROCEDURE if EXISTS add_t_ds_process_instance_add_project_code;
delimiter d// delimiter d//
CREATE PROCEDURE add_t_ds_process_instance_add_project_code() CREATE PROCEDURE add_t_ds_process_instance_add_project_code()
@ -266,7 +266,7 @@ delimiter ;
CALL add_t_ds_process_instance_add_project_code; CALL add_t_ds_process_instance_add_project_code;
DROP PROCEDURE 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; drop PROCEDURE if EXISTS add_t_ds_task_instance_add_project_code;
delimiter d// delimiter d//
CREATE PROCEDURE add_t_ds_task_instance_add_project_code() 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_k8s_namespace` MODIFY `namespace` varchar(255) DEFAULT NULL;
ALTER TABLE `t_ds_cluster` MODIFY `name` varchar(255) NOT NULL COMMENT 'cluster name'; 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;

20
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;

4
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/mysql/dolphinscheduler_dml.sql

@ -33,3 +33,7 @@ d//
delimiter ; delimiter ;
CALL dolphin_t_ds_tenant_insert_default(); CALL dolphin_t_ds_tenant_insert_default();
DROP PROCEDURE dolphin_t_ds_tenant_insert_default; 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;

37
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_ddl.sql

@ -242,3 +242,40 @@ 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` MODIFY k8s_name VARCHAR(255) DEFAULT NULL ;
ALTER TABLE `t_ds_k8s_namespace` MODIFY namespace 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; 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();

20
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";

4
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.0_schema/postgresql/dolphinscheduler_dml.sql

@ -16,3 +16,7 @@
*/ */
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'); 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;

21
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.setProjectCode(project.getCode());
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date()); processDefinition.setCreateTime(new Date());
processDefinition.setTenantId(tenant.getId());
processDefinition.setUserId(user.getId()); processDefinition.setUserId(user.getId());
processDefinitionMapper.insert(processDefinition); processDefinitionMapper.insert(processDefinition);
ProcessDefinition definition = processDefinitionMapper.verifyByDefineName(10L, "xxx"); ProcessDefinition definition = processDefinitionMapper.verifyByDefineName(10L, "xxx");
@ -187,7 +186,6 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest {
processDefinition.setProjectCode(project.getCode()); processDefinition.setProjectCode(project.getCode());
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date()); processDefinition.setCreateTime(new Date());
processDefinition.setTenantId(tenant.getId());
processDefinition.setUserId(user.getId()); processDefinition.setUserId(user.getId());
processDefinitionMapper.insert(processDefinition); processDefinitionMapper.insert(processDefinition);
@ -195,24 +193,6 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest {
Assertions.assertNotEquals(processDefinition1, null); 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<ProcessDefinition> definitions = processDefinitionMapper.queryDefinitionListByTenant(999);
Assertions.assertNotEquals(definitions.size(), 0);
}
/** /**
* test queryByDefineId * test queryByDefineId
*/ */
@ -250,7 +230,6 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest {
processDefinition.setProjectCode(project.getCode()); processDefinition.setProjectCode(project.getCode());
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date()); processDefinition.setCreateTime(new Date());
processDefinition.setTenantId(tenant.getId());
processDefinition.setUserId(user.getId()); processDefinition.setUserId(user.getId());
processDefinitionMapper.insert(processDefinition); processDefinitionMapper.insert(processDefinition);
ProcessDefinition definition = processDefinitionMapper.queryByDefineId(333); ProcessDefinition definition = processDefinitionMapper.queryByDefineId(333);

2
dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowE2ETest.java

@ -118,7 +118,6 @@ class WorkflowE2ETest {
.submit() .submit()
.name(workflow) .name(workflow)
.tenant(tenant)
.addGlobalParam("global_param", "hello world") .addGlobalParam("global_param", "hello world")
.submit() .submit()
; ;
@ -151,7 +150,6 @@ class WorkflowE2ETest {
.submit() .submit()
.name(workflow) .name(workflow)
.tenant(tenant)
.addGlobalParam("global_param", "hello world") .addGlobalParam("global_param", "hello world")
.submit() .submit()
; ;

1
dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java

@ -130,7 +130,6 @@ class WorkflowSwitchE2ETest {
workflowForm.submit() workflowForm.submit()
.name(workflow) .name(workflow)
.tenant(tenant)
.addGlobalParam("key", "1") .addGlobalParam("key", "1")
.submit(); .submit();

23
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; 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<WebElement> selectTenantOption;
@FindBy(className = "input-global-params") @FindBy(className = "input-global-params")
private WebElement globalParamsItems; private WebElement globalParamsItems;
@ -78,20 +69,6 @@ public final class WorkflowSaveDialog {
return this; 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) { public WorkflowSaveDialog addGlobalParam(String key, String value) {
final int len = globalParamsItems().findElements(By.tagName("input")).size(); final int len = globalParamsItems().findElements(By.tagName("input")).size();

7
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.Resource;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; 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.mapper.ProcessTaskRelationMapper;
import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
import org.apache.dolphinscheduler.plugin.task.api.TaskChannel; import org.apache.dolphinscheduler.plugin.task.api.TaskChannel;
@ -332,10 +331,10 @@ public class StreamTaskExecuteRunnable implements Runnable {
*/ */
protected TaskExecutionContext getTaskExecutionContext(TaskInstance taskInstance) { protected TaskExecutionContext getTaskExecutionContext(TaskInstance taskInstance) {
int userId = taskDefinition == null ? 0 : taskDefinition.getUserId(); 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 // verify tenant is null
if (tenant == null) { if (StringUtils.isBlank(tenantCode)) {
log.error("tenant not exists,task instance id : {}", taskInstance.getId()); log.error("tenant not exists,task instance id : {}", taskInstance.getId());
return null; return null;
} }
@ -357,7 +356,7 @@ public class StreamTaskExecuteRunnable implements Runnable {
.buildParamInfo(propertyMap) .buildParamInfo(propertyMap)
.create(); .create();
taskExecutionContext.setTenantCode(tenant.getTenantCode()); taskExecutionContext.setTenantCode(tenantCode);
taskExecutionContext.setProjectCode(processDefinition.getProjectCode()); taskExecutionContext.setProjectCode(processDefinition.getProjectCode());
taskExecutionContext.setProcessDefineCode(processDefinition.getCode()); taskExecutionContext.setProcessDefineCode(processDefinition.getCode());
taskExecutionContext.setProcessDefineVersion(processDefinition.getVersion()); taskExecutionContext.setProcessDefineVersion(processDefinition.getVersion());

4
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.DqRuleInputEntry;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; 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.UdfFunc;
import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao; import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao;
import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
@ -655,7 +654,6 @@ public abstract class BaseTaskProcessor implements ITaskProcessor {
private String getTenantCode() { private String getTenantCode() {
int userId = taskInstance.getProcessDefine() == null ? 0 : taskInstance.getProcessDefine().getUserId(); int userId = taskInstance.getProcessDefine() == null ? 0 : taskInstance.getProcessDefine().getUserId();
Tenant tenant = processService.getTenantForProcess(taskInstance.getProcessInstance().getTenantId(), userId); return processService.getTenantForProcess(taskInstance.getProcessInstance().getTenantCode(), userId);
return tenant == null ? null : tenant.getTenantCode();
} }
} }

22
dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/consumer/TaskPriorityQueueConsumerTest.java

@ -68,18 +68,20 @@ public class TaskPriorityQueueConsumerTest {
@Autowired @Autowired
private ExecutorDispatcher dispatcher; private ExecutorDispatcher dispatcher;
private static final String TENANT_CODE = "root";
@BeforeEach @BeforeEach
public void init() { public void init() {
Tenant tenant = new Tenant(); Tenant tenant = new Tenant();
tenant.setId(1); tenant.setId(1);
tenant.setTenantCode("journey"); tenant.setTenantCode(TENANT_CODE);
tenant.setDescription("journey"); tenant.setDescription(TENANT_CODE);
tenant.setQueueId(1); tenant.setQueueId(1);
tenant.setCreateTime(new Date()); tenant.setCreateTime(new Date());
tenant.setUpdateTime(new Date()); tenant.setUpdateTime(new Date());
Mockito.doReturn(tenant).when(processService).getTenantForProcess(1, 2); Mockito.doReturn(tenant).when(processService).getTenantForProcess(TENANT_CODE, 2);
} }
@Test @Test
@ -95,7 +97,7 @@ public class TaskPriorityQueueConsumerTest {
ProcessInstance processInstance = new ProcessInstance(); ProcessInstance processInstance = new ProcessInstance();
processInstance.setId(1); processInstance.setId(1);
processInstance.setTenantId(1); processInstance.setTenantCode(TENANT_CODE);
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
@ -123,7 +125,7 @@ public class TaskPriorityQueueConsumerTest {
taskInstance.setExecutorId(2); taskInstance.setExecutorId(2);
ProcessInstance processInstance = new ProcessInstance(); ProcessInstance processInstance = new ProcessInstance();
processInstance.setTenantId(1); processInstance.setTenantCode(TENANT_CODE);
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
@ -164,7 +166,7 @@ public class TaskPriorityQueueConsumerTest {
taskInstance.setExecutorId(2); taskInstance.setExecutorId(2);
ProcessInstance processInstance = new ProcessInstance(); ProcessInstance processInstance = new ProcessInstance();
processInstance.setTenantId(1); processInstance.setTenantCode(TENANT_CODE);
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
@ -203,7 +205,7 @@ public class TaskPriorityQueueConsumerTest {
taskInstance.setExecutorId(2); taskInstance.setExecutorId(2);
ProcessInstance processInstance = new ProcessInstance(); ProcessInstance processInstance = new ProcessInstance();
processInstance.setTenantId(1); processInstance.setTenantCode(TENANT_CODE);
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
@ -260,7 +262,7 @@ public class TaskPriorityQueueConsumerTest {
ProcessInstance processInstance = new ProcessInstance(); ProcessInstance processInstance = new ProcessInstance();
processInstance.setId(1); processInstance.setId(1);
processInstance.setTenantId(1); processInstance.setTenantCode(TENANT_CODE);
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION);
@ -293,7 +295,7 @@ public class TaskPriorityQueueConsumerTest {
ProcessInstance processInstance = new ProcessInstance(); ProcessInstance processInstance = new ProcessInstance();
processInstance.setId(1); processInstance.setId(1);
processInstance.setTenantId(1); processInstance.setTenantCode(TENANT_CODE);
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION);
@ -334,7 +336,7 @@ public class TaskPriorityQueueConsumerTest {
ProcessInstance processInstance = new ProcessInstance(); ProcessInstance processInstance = new ProcessInstance();
processInstance.setId(1); processInstance.setId(1);
processInstance.setTenantId(1); processInstance.setTenantCode(TENANT_CODE);
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION);

2
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 processInstance = new ProcessInstance();
processInstance.setId(1); processInstance.setId(1);
processInstance.setTenantId(1); processInstance.setTenantCode("default");
processInstance.setCommandType(CommandType.START_PROCESS); processInstance.setCommandType(CommandType.START_PROCESS);
taskInstance.setProcessInstance(processInstance); taskInstance.setProcessInstance(processInstance);
taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION); taskInstance.setState(TaskExecutionStatus.DELAY_EXECUTION);

2
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/task/TaskExecuteStartMessage.java

@ -54,7 +54,7 @@ public class TaskExecuteStartMessage extends BaseMessage {
private Map<String, String> startParams; private Map<String, String> startParams;
private int tenantId; private String tenantCode;
private int dryRun; private int dryRun;

1
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 String workerGroup = StringUtils.isEmpty(schedule.getWorkerGroup()) ? Constants.DEFAULT_WORKER_GROUP
: schedule.getWorkerGroup(); : schedule.getWorkerGroup();
command.setWorkerGroup(workerGroup); command.setWorkerGroup(workerGroup);
command.setTenantCode(schedule.getTenantCode());
command.setEnvironmentCode(schedule.getEnvironmentCode()); command.setEnvironmentCode(schedule.getEnvironmentCode());
command.setWarningType(schedule.getWarningType()); command.setWarningType(schedule.getWarningType());
command.setProcessInstancePriority(schedule.getProcessInstancePriority()); command.setProcessInstancePriority(schedule.getProcessInstancePriority());

3
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.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskGroupQueue; import org.apache.dolphinscheduler.dao.entity.TaskGroupQueue;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; 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.UdfFunc;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
@ -83,7 +82,7 @@ public interface ProcessService {
void recurseFindSubProcess(long parentCode, List<Long> ids); void recurseFindSubProcess(long parentCode, List<Long> ids);
Tenant getTenantForProcess(int tenantId, int userId); String getTenantForProcess(String tenantCode, int userId);
Environment findEnvironmentByCode(Long environmentCode); Environment findEnvironmentByCode(Long environmentCode);

33
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 // set process instance priority
processInstance.setProcessInstancePriority(command.getProcessInstancePriority()); processInstance.setProcessInstancePriority(command.getProcessInstancePriority());
String workerGroup = Strings.isNullOrEmpty(command.getWorkerGroup()) ? Constants.DEFAULT_WORKER_GROUP String workerGroup = StringUtils.defaultIfEmpty(command.getWorkerGroup(), Constants.DEFAULT_WORKER_GROUP);
: command.getWorkerGroup();
processInstance.setWorkerGroup(workerGroup); processInstance.setWorkerGroup(workerGroup);
processInstance processInstance
.setEnvironmentCode(Objects.isNull(command.getEnvironmentCode()) ? -1 : command.getEnvironmentCode()); .setEnvironmentCode(Objects.isNull(command.getEnvironmentCode()) ? -1 : command.getEnvironmentCode());
processInstance.setTimeout(processDefinition.getTimeout()); processInstance.setTimeout(processDefinition.getTimeout());
processInstance.setTenantId(processDefinition.getTenantId()); processInstance.setTenantCode(command.getTenantCode());
processInstance.setTenantCode(Optional.ofNullable(tenantMapper.queryById(processDefinition.getTenantId()))
.map(Tenant::getTenantCode).orElse(null));
return processInstance; return processInstance;
} }
@ -678,31 +675,29 @@ public class ProcessServiceImpl implements ProcessService {
} }
/** /**
* get process tenant * Get workflow runtime 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.
* *
* @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 * @param userId userId
* @return tenant * @return tenant code
*/ */
@Override @Override
public Tenant getTenantForProcess(int tenantId, int userId) { public String getTenantForProcess(String tenantCode, int userId) {
Tenant tenant = null; if (StringUtils.isNoneBlank(tenantCode) && !Constants.DEFAULT.equals(tenantCode)) {
if (tenantId >= 0) { return tenantCode;
tenant = tenantMapper.queryById(tenantId);
} }
if (userId == 0) { if (userId == 0) {
return null; return null;
} }
if (tenant == null) {
User user = userMapper.selectById(userId); User user = userMapper.selectById(userId);
tenant = tenantMapper.queryById(user.getTenantId()); Tenant tenant = tenantMapper.queryById(user.getTenantId());
} return tenant.getTenantCode();
return tenant;
} }
/** /**

2
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()); ObjectNode jsonObject = JSONUtils.parseObject(entry.getValue());
ProcessDefinition processDefinition = processDefinitionMap.get(entry.getKey()); ProcessDefinition processDefinition = processDefinitionMap.get(entry.getKey());
if (processDefinition != null) { if (processDefinition != null) {
processDefinition
.setTenantId(jsonObject.get("tenantId") == null ? -1 : jsonObject.get("tenantId").asInt());
processDefinition.setTimeout(jsonObject.get("timeout").asInt()); processDefinition.setTimeout(jsonObject.get("timeout").asInt());
processDefinition.setGlobalParams(jsonObject.get("globalParams").toString()); processDefinition.setGlobalParams(jsonObject.get("globalParams").toString());
} else { } else {

24
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; 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.ProcessDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; 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.TaskInstance;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; 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.TaskInstanceMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper; 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.DolphinSchedulerUpgrader;
import org.apache.dolphinscheduler.tools.datasource.upgrader.DolphinSchedulerVersion; import org.apache.dolphinscheduler.tools.datasource.upgrader.DolphinSchedulerVersion;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -39,6 +42,7 @@ import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -55,7 +59,7 @@ public class V320DolphinSchedulerUpgrader implements DolphinSchedulerUpgrader {
private ProcessDefinitionLogMapper processDefinitionLogMapper; private ProcessDefinitionLogMapper processDefinitionLogMapper;
@Autowired @Autowired
private TenantMapper tenantMapper; private ScheduleMapper scheduleMapper;
@Autowired @Autowired
private UserMapper userMapper; private UserMapper userMapper;
@ -63,16 +67,19 @@ public class V320DolphinSchedulerUpgrader implements DolphinSchedulerUpgrader {
@Autowired @Autowired
private TaskInstanceMapper taskInstanceMapper; private TaskInstanceMapper taskInstanceMapper;
@Lazy()
@Autowired
private UpgradeDao upgradeDao;
@Override @Override
public void doUpgrade() { public void doUpgrade() {
upgradeWorkflowInstance(); upgradeWorkflowInstance();
upgradeTaskInstance(); upgradeTaskInstance();
upgradeDao.upgradeDolphinSchedulerDDL(getCurrentVersion().getVersionName() + "_schema",
"dolphinscheduler_ddl_post.sql");
} }
private void upgradeWorkflowInstance() { private void upgradeWorkflowInstance() {
Map<Integer, String> tenantMap = tenantMapper.selectList(new QueryWrapper<>())
.stream()
.collect(Collectors.toMap(Tenant::getId, Tenant::getTenantCode));
Map<Integer, String> userMap = userMapper.selectList(new QueryWrapper<>()) Map<Integer, String> userMap = userMapper.selectList(new QueryWrapper<>())
.stream() .stream()
.collect(Collectors.toMap(User::getId, User::getUserName)); .collect(Collectors.toMap(User::getId, User::getUserName));
@ -92,9 +99,12 @@ public class V320DolphinSchedulerUpgrader implements DolphinSchedulerUpgrader {
processDefinitionLogMapper.queryByDefinitionCodeAndVersion( processDefinitionLogMapper.queryByDefinitionCodeAndVersion(
processInstance.getProcessDefinitionCode(), processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion()); processInstance.getProcessDefinitionVersion());
Schedule schedule =
scheduleMapper.queryByProcessDefinitionCode(processInstance.getProcessDefinitionCode());
if (processDefinitionLog != null) { if (processDefinitionLog != null) {
processInstance.setProjectCode(processDefinitionLog.getProjectCode()); processInstance.setProjectCode(processDefinitionLog.getProjectCode());
processInstance.setTenantCode(tenantMap.get(processDefinitionLog.getTenantId())); processInstance.setTenantCode(
StringUtils.defaultIfEmpty(schedule.getTenantCode(), Constants.DEFAULT));
processInstance.setExecutorName(userMap.get(processInstance.getExecutorId())); processInstance.setExecutorName(userMap.get(processInstance.getExecutorId()));
} else { } else {
processInstance.setProjectCode(-1L); processInstance.setProjectCode(-1L);

3
dolphinscheduler-ui/src/locales/en_US/project.ts

@ -109,6 +109,7 @@ export default {
notification_strategy: 'Notification Strategy', notification_strategy: 'Notification Strategy',
workflow_priority: 'Workflow Priority', workflow_priority: 'Workflow Priority',
worker_group: 'Worker Group', worker_group: 'Worker Group',
tenant_code: 'Tenant',
environment_name: 'Environment Name', environment_name: 'Environment Name',
alarm_group: 'Alarm Group', alarm_group: 'Alarm Group',
complement_data: 'Complement Data', complement_data: 'Complement Data',
@ -276,6 +277,7 @@ export default {
set_parameters_before_starting: 'Please set the parameters before starting', set_parameters_before_starting: 'Please set the parameters before starting',
notification_strategy: 'Notification Strategy', notification_strategy: 'Notification Strategy',
worker_group: 'Worker group', worker_group: 'Worker group',
tenant_code: 'Tenant',
environment_name: 'Environment Name', environment_name: 'Environment Name',
alarm_group: 'Alarm group', alarm_group: 'Alarm group',
startup_parameter: 'Startup Parameter', startup_parameter: 'Startup Parameter',
@ -301,7 +303,6 @@ export default {
copy_success: 'Copy Success', copy_success: 'Copy Success',
workflow_name: 'Workflow Name', workflow_name: 'Workflow Name',
description: 'Description', description: 'Description',
tenant: 'Tenant',
timeout_alert: 'Timeout Alert', timeout_alert: 'Timeout Alert',
process_execute_type: 'Process execute type', process_execute_type: 'Process execute type',
parallel: 'parallel', parallel: 'parallel',

3
dolphinscheduler-ui/src/locales/zh_CN/project.ts

@ -111,6 +111,7 @@ export default {
notification_strategy: '通知策略', notification_strategy: '通知策略',
workflow_priority: '流程优先级', workflow_priority: '流程优先级',
worker_group: 'Worker分组', worker_group: 'Worker分组',
tenant_code: '租户',
environment_name: '环境名称', environment_name: '环境名称',
alarm_group: '告警组', alarm_group: '告警组',
complement_data: '补数', complement_data: '补数',
@ -276,6 +277,7 @@ export default {
set_parameters_before_starting: '启动前请先设置参数', set_parameters_before_starting: '启动前请先设置参数',
notification_strategy: '通知策略', notification_strategy: '通知策略',
worker_group: 'Worker分组', worker_group: 'Worker分组',
tenant_code: '租户',
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: '租户',
timeout_alert: '超时告警', timeout_alert: '超时告警',
process_execute_type: '执行策略', process_execute_type: '执行策略',
parallel: '并行', parallel: '并行',

1
dolphinscheduler-ui/src/service/modules/process-definition/types.ts

@ -58,7 +58,6 @@ interface ProcessDefinitionReq {
locations: string locations: string
taskDefinitionJson: string taskDefinitionJson: string
taskRelationJson: string taskRelationJson: string
tenantCode: string
executionType: string executionType: string
description?: string description?: string
globalParams?: string globalParams?: string

1
dolphinscheduler-ui/src/service/modules/process-instances/types.ts

@ -79,7 +79,6 @@ interface ProcessInstanceReq {
scheduleTime?: string scheduleTime?: string
taskDefinitionJson?: string taskDefinitionJson?: string
taskRelationJson?: string taskRelationJson?: string
tenantCode?: string
timeout?: number timeout?: number
} }

8
dolphinscheduler-ui/src/views/projects/task/definition/components/start-modal.tsx

@ -62,6 +62,7 @@ export default defineComponent({
variables, variables,
handleStartDefinition, handleStartDefinition,
getWorkerGroups, getWorkerGroups,
getTenantList,
getAlertGroups, getAlertGroups,
getEnvironmentList, getEnvironmentList,
getStartParamsList getStartParamsList
@ -118,6 +119,7 @@ export default defineComponent({
onMounted(() => { onMounted(() => {
getWorkerGroups() getWorkerGroups()
getTenantList()
getAlertGroups() getAlertGroups()
getEnvironmentList() getEnvironmentList()
}) })
@ -178,6 +180,12 @@ export default defineComponent({
v-model:value={this.startForm.workerGroup} v-model:value={this.startForm.workerGroup}
/> />
</NFormItem> </NFormItem>
<NFormItem label={t('project.task.tenant_code')} path='tenantCode'>
<NSelect
options={this.tenantList}
v-model:value={this.startForm.tenantCode}
/>
</NFormItem>
<NFormItem <NFormItem
label={t('project.task.environment_name')} label={t('project.task.environment_name')}
path='environmentCode' path='environmentCode'

13
dolphinscheduler-ui/src/views/projects/task/definition/components/use-start.tsx

@ -22,6 +22,7 @@ import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { queryProcessDefinitionByCode } from '@/service/modules/process-definition' import { queryProcessDefinitionByCode } from '@/service/modules/process-definition'
import { queryAllWorkerGroups } from '@/service/modules/worker-groups' import { queryAllWorkerGroups } from '@/service/modules/worker-groups'
import { queryTenantList } from '@/service/modules/tenants'
import { queryAllEnvironmentList } from '@/service/modules/environment' import { queryAllEnvironmentList } from '@/service/modules/environment'
import { listAlertGroupById } from '@/service/modules/alert-group' import { listAlertGroupById } from '@/service/modules/alert-group'
import type { EnvironmentItem } from '@/service/modules/environment/types' import type { EnvironmentItem } from '@/service/modules/environment/types'
@ -40,6 +41,7 @@ export const useStart = (
warningType: 'NONE', warningType: 'NONE',
warningGroupId: null, warningGroupId: null,
workerGroup: 'default', workerGroup: 'default',
tenantCode: 'default',
environmentCode: null, environmentCode: null,
startParams: null as null | string, startParams: null as null | string,
dryRun: 0 dryRun: 0
@ -47,6 +49,7 @@ export const useStart = (
startState: { startState: {
projectCode: Number(route.params.projectCode), projectCode: Number(route.params.projectCode),
workerGroups: [], workerGroups: [],
tenantList: [],
alertGroups: [], alertGroups: [],
environmentList: [], environmentList: [],
startParamsList: [] startParamsList: []
@ -67,6 +70,15 @@ export const useStart = (
}) })
} }
const getTenantList = () => {
queryTenantList().then((res: any) => {
variables.startState.tenantList = res.map((item: any) => ({
label: item.tenantCode,
value: item.tenantCode
}))
})
}
const getEnvironmentList = () => { const getEnvironmentList = () => {
queryAllEnvironmentList().then((res: Array<EnvironmentItem>) => { queryAllEnvironmentList().then((res: Array<EnvironmentItem>) => {
variables.startState.environmentList = res.map((item) => ({ variables.startState.environmentList = res.map((item) => ({
@ -135,6 +147,7 @@ export const useStart = (
return { return {
variables, variables,
getWorkerGroups, getWorkerGroups,
getTenantList,
getEnvironmentList, getEnvironmentList,
getAlertGroups, getAlertGroups,
getStartParamsList, getStartParamsList,

1
dolphinscheduler-ui/src/views/projects/task/definition/types.ts

@ -31,6 +31,7 @@ interface IRecord {
interface IStartState { interface IStartState {
projectCode: number projectCode: number
workerGroups: Array<IOption> workerGroups: Array<IOption>
tenantList: Array<IOption>
alertGroups: Array<IOption> alertGroups: Array<IOption>
environmentList: Array<IEnvironmentNameOption> environmentList: Array<IEnvironmentNameOption>
startParamsList: Array<IParam> startParamsList: Array<IParam>

35
dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx

@ -19,7 +19,6 @@ import {
defineComponent, defineComponent,
PropType, PropType,
ref, ref,
computed,
onMounted, onMounted,
watch, watch,
getCurrentInstance getCurrentInstance
@ -36,14 +35,11 @@ import {
NDynamicInput, NDynamicInput,
NCheckbox NCheckbox
} from 'naive-ui' } from 'naive-ui'
import { queryTenantList } from '@/service/modules/tenants'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { useUserStore } from '@/store/user/user'
import { verifyName } from '@/service/modules/process-definition' import { verifyName } from '@/service/modules/process-definition'
import './x6-style.scss' import './x6-style.scss'
import { positiveIntegerRegex } from '@/utils/regex' import { positiveIntegerRegex } from '@/utils/regex'
import type { SaveForm, WorkflowDefinition, WorkflowInstance } from './types' import type { SaveForm, WorkflowDefinition, WorkflowInstance } from './types'
import type { UserInfoRes } from '@/service/modules/users/types'
const props = { const props = {
visible: { visible: {
@ -61,11 +57,6 @@ const props = {
} }
} }
interface Tenant {
tenantCode: string
id: number
}
export default defineComponent({ export default defineComponent({
name: 'dag-save-modal', name: 'dag-save-modal',
props, props,
@ -75,28 +66,10 @@ export default defineComponent({
const { t } = useI18n() const { t } = useI18n()
const projectCode = Number(route.params.projectCode) const projectCode = Number(route.params.projectCode)
const userInfo = useUserStore().getUserInfo as UserInfoRes
const tenants = ref<Tenant[]>([])
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<SaveForm>({ const formValue = ref<SaveForm>({
name: '', name: '',
description: '', description: '',
tenantCode: userInfo.tenantCode || 'default',
executionType: 'PARALLEL', executionType: 'PARALLEL',
timeoutFlag: false, timeoutFlag: false,
timeout: 0, timeout: 0,
@ -170,7 +143,6 @@ export default defineComponent({
if (process) { if (process) {
formValue.value.name = process.name formValue.value.name = process.name
formValue.value.description = process.description formValue.value.description = process.description
formValue.value.tenantCode = process.tenantCode || userInfo.tenantCode || 'default'
formValue.value.executionType = process.executionType || 'PARALLEL' formValue.value.executionType = process.executionType || 'PARALLEL'
if (process.timeout && process.timeout > 0) { if (process.timeout && process.timeout > 0) {
formValue.value.timeoutFlag = true formValue.value.timeoutFlag = true
@ -216,13 +188,6 @@ export default defineComponent({
class='input-description' class='input-description'
/> />
</NFormItem> </NFormItem>
<NFormItem label={t('project.dag.tenant')} path='tenantCode'>
<NSelect
options={tenantsDropdown.value}
v-model:value={formValue.value.tenantCode}
class='btn-select-tenant-code'
/>
</NFormItem>
<NFormItem label={t('project.dag.timeout_alert')} path='timeoutFlag'> <NFormItem label={t('project.dag.timeout_alert')} path='timeoutFlag'>
<NSwitch v-model:value={formValue.value.timeoutFlag} /> <NSwitch v-model:value={formValue.value.timeoutFlag} />
</NFormItem> </NFormItem>

5
dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-startup-param.tsx

@ -103,6 +103,7 @@ export default defineComponent({
render() { render() {
const { t } = this const { t } = this
// @ts-ignore
return ( return (
<div class={styles.box}> <div class={styles.box}>
<ul class={styles['box-bd']}> <ul class={styles['box-bd']}>
@ -153,6 +154,10 @@ export default defineComponent({
: '-'} : '-'}
</span> </span>
</li> </li>
<li>
<span class={styles.tab}>{t('project.workflow.tenant_code')}:</span>
<span class={styles.content}>{this.startupParam?.tenantCode}</span>
</li>
<li> <li>
<span class={styles.tab}> <span class={styles.tab}>
{t('project.workflow.notification_strategy')}: {t('project.workflow.notification_strategy')}:

3
dolphinscheduler-ui/src/views/projects/workflow/components/dag/types.ts

@ -113,6 +113,7 @@ export interface WorkflowInstance {
failureStrategy: string failureStrategy: string
processInstancePriority: string processInstancePriority: string
workerGroup: string workerGroup: string
tenantCode: string
warningType: string warningType: string
warningGroupId: number warningGroupId: number
} }
@ -142,7 +143,6 @@ export interface GlobalParam {
export interface SaveForm { export interface SaveForm {
name: string name: string
description: string description: string
tenantCode: string
executionType: string executionType: string
timeoutFlag: boolean timeoutFlag: boolean
timeout: number timeout: number
@ -163,6 +163,7 @@ export interface IStartupParam {
failureStrategy: string failureStrategy: string
processInstancePriority: string processInstancePriority: string
workerGroup: string workerGroup: string
tenantCode: string
warningType: string warningType: string
warningGroupId: number warningGroupId: number
} }

18
dolphinscheduler-ui/src/views/projects/workflow/definition/components/start-modal.tsx

@ -82,6 +82,7 @@ export default defineComponent({
variables, variables,
handleStartDefinition, handleStartDefinition,
getWorkerGroups, getWorkerGroups,
getTenantList,
getAlertGroups, getAlertGroups,
getEnvironmentList, getEnvironmentList,
getStartParamsList getStartParamsList
@ -195,6 +196,7 @@ export default defineComponent({
onMounted(() => { onMounted(() => {
getWorkerGroups() getWorkerGroups()
getTenantList()
getAlertGroups() getAlertGroups()
getEnvironmentList() getEnvironmentList()
}) })
@ -311,6 +313,16 @@ export default defineComponent({
v-model:value={this.startForm.workerGroup} v-model:value={this.startForm.workerGroup}
/> />
</NFormItem> </NFormItem>
<NFormItem
label={t('project.workflow.tenant_code')}
path='tenantCode'
>
<NSelect
options={this.tenantList}
v-model:value={this.startForm.tenantCode}
/>
</NFormItem>
<NFormItem <NFormItem
label={t('project.workflow.environment_name')} label={t('project.workflow.environment_name')}
path='environmentCode' path='environmentCode'
@ -323,7 +335,8 @@ export default defineComponent({
clearable clearable
/> />
</NFormItem> </NFormItem>
{this.startForm.warningType !== 'NONE' && (<NFormItem {this.startForm.warningType !== 'NONE' && (
<NFormItem
label={t('project.workflow.alarm_group')} label={t('project.workflow.alarm_group')}
path='warningGroupId' path='warningGroupId'
> >
@ -333,7 +346,8 @@ export default defineComponent({
v-model:value={this.startForm.warningGroupId} v-model:value={this.startForm.warningGroupId}
clearable clearable
/> />
</NFormItem>)} </NFormItem>
)}
<NFormItem <NFormItem
label={t('project.workflow.complement_data')} label={t('project.workflow.complement_data')}
path='complement_data' path='complement_data'

18
dolphinscheduler-ui/src/views/projects/workflow/definition/components/timing-modal.tsx

@ -80,6 +80,7 @@ export default defineComponent({
handleCreateTiming, handleCreateTiming,
handleUpdateTiming, handleUpdateTiming,
getWorkerGroups, getWorkerGroups,
getTenantList,
getAlertGroups, getAlertGroups,
getEnvironmentList, getEnvironmentList,
getPreviewSchedule getPreviewSchedule
@ -189,6 +190,7 @@ export default defineComponent({
onMounted(() => { onMounted(() => {
getWorkerGroups() getWorkerGroups()
getTenantList()
getAlertGroups() getAlertGroups()
getEnvironmentList() getEnvironmentList()
}) })
@ -209,6 +211,7 @@ export default defineComponent({
timingState.timingForm.processInstancePriority = timingState.timingForm.processInstancePriority =
props.row.processInstancePriority props.row.processInstancePriority
timingState.timingForm.workerGroup = props.row.workerGroup timingState.timingForm.workerGroup = props.row.workerGroup
timingState.timingForm.tenantCode = props.row.tenantCode
initWarningGroup() initWarningGroup()
initEnvironment() initEnvironment()
} }
@ -368,6 +371,15 @@ export default defineComponent({
v-model:value={this.timingForm.workerGroup} v-model:value={this.timingForm.workerGroup}
/> />
</NFormItem> </NFormItem>
<NFormItem
label={t('project.workflow.tenant_code')}
path='tenantCode'
>
<NSelect
options={this.tenantList}
v-model:value={this.timingForm.tenantCode}
/>
</NFormItem>
<NFormItem <NFormItem
label={t('project.workflow.environment_name')} label={t('project.workflow.environment_name')}
path='environmentCode' path='environmentCode'
@ -378,7 +390,8 @@ export default defineComponent({
clearable clearable
/> />
</NFormItem> </NFormItem>
{this.timingForm.warningType !== 'NONE' && ( <NFormItem {this.timingForm.warningType !== 'NONE' && (
<NFormItem
label={t('project.workflow.alarm_group')} label={t('project.workflow.alarm_group')}
path='warningGroupId' path='warningGroupId'
> >
@ -388,7 +401,8 @@ export default defineComponent({
v-model:value={this.timingForm.warningGroupId} v-model:value={this.timingForm.warningGroupId}
clearable clearable
/> />
</NFormItem> )} </NFormItem>
)}
</NForm> </NForm>
</Modal> </Modal>
) )

1
dolphinscheduler-ui/src/views/projects/workflow/definition/components/types.ts

@ -36,6 +36,7 @@ export interface IParam {
export interface ITimingState { export interface ITimingState {
projectCode: number projectCode: number
workerGroups: Array<IOption> workerGroups: Array<IOption>
tenantList: Array<IOption>
alertGroups: Array<IOption> alertGroups: Array<IOption>
environmentList: Array<IEnvironmentOption> environmentList: Array<IEnvironmentOption>
startParamsList: Array<IParam> startParamsList: Array<IParam>

2
dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-form.ts

@ -63,6 +63,7 @@ export const useForm = () => {
runMode: 'RUN_MODE_SERIAL', runMode: 'RUN_MODE_SERIAL',
processInstancePriority: 'MEDIUM', processInstancePriority: 'MEDIUM',
workerGroup: 'default', workerGroup: 'default',
tenantCode: 'default',
environmentCode: null, environmentCode: null,
startParams: null, startParams: null,
expectedParallelismNumber: '', expectedParallelismNumber: '',
@ -106,6 +107,7 @@ export const useForm = () => {
processInstancePriority: 'MEDIUM', processInstancePriority: 'MEDIUM',
warningGroupId: null as null | number, warningGroupId: null as null | number,
workerGroup: 'default', workerGroup: 'default',
tenantCode: 'default',
environmentCode: null as null | string environmentCode: null as null | string
}, },
saving: false saving: false

13
dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts

@ -38,6 +38,7 @@ import {
import { parseTime } from '@/common/common' import { parseTime } from '@/common/common'
import { EnvironmentItem } from '@/service/modules/environment/types' import { EnvironmentItem } from '@/service/modules/environment/types'
import { ITimingState, ProcessInstanceReq } from './types' import { ITimingState, ProcessInstanceReq } from './types'
import { queryTenantList } from '@/service/modules/tenants'
export function useModal( export function useModal(
state: any, state: any,
@ -50,6 +51,7 @@ export function useModal(
const variables = reactive<ITimingState>({ const variables = reactive<ITimingState>({
projectCode: Number(route.params.projectCode), projectCode: Number(route.params.projectCode),
workerGroups: [], workerGroups: [],
tenantList: [],
alertGroups: [], alertGroups: [],
environmentList: [], environmentList: [],
startParamsList: [], startParamsList: [],
@ -219,6 +221,7 @@ export function useModal(
? state.timingForm.warningGroupId ? state.timingForm.warningGroupId
: 0, : 0,
workerGroup: state.timingForm.workerGroup, workerGroup: state.timingForm.workerGroup,
tenantCode: state.timingForm.tenantCode,
environmentCode: state.timingForm.environmentCode environmentCode: state.timingForm.environmentCode
} }
return data 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 = () => { const getEnvironmentList = () => {
queryAllEnvironmentList().then((res: Array<EnvironmentItem>) => { queryAllEnvironmentList().then((res: Array<EnvironmentItem>) => {
variables.environmentList = res.map((item) => ({ variables.environmentList = res.map((item) => ({
@ -300,6 +312,7 @@ export function useModal(
handleUpdateTiming, handleUpdateTiming,
handleBatchCopyDefinition, handleBatchCopyDefinition,
getWorkerGroups, getWorkerGroups,
getTenantList,
getAlertGroups, getAlertGroups,
getEnvironmentList, getEnvironmentList,
getStartParamsList, getStartParamsList,

1
dolphinscheduler-ui/src/views/projects/workflow/definition/create/index.tsx

@ -69,7 +69,6 @@ export default defineComponent({
taskRelationJson: JSON.stringify(connects), taskRelationJson: JSON.stringify(connects),
locations: JSON.stringify(locations), locations: JSON.stringify(locations),
name: saveForm.name, name: saveForm.name,
tenantCode: saveForm.tenantCode,
executionType: saveForm.executionType, executionType: saveForm.executionType,
description: saveForm.description, description: saveForm.description,
globalParams: JSON.stringify(globalParams), globalParams: JSON.stringify(globalParams),

1
dolphinscheduler-ui/src/views/projects/workflow/definition/detail/index.tsx

@ -95,7 +95,6 @@ export default defineComponent({
taskRelationJson: JSON.stringify(connects), taskRelationJson: JSON.stringify(connects),
locations: JSON.stringify(locations), locations: JSON.stringify(locations),
name: saveForm.name, name: saveForm.name,
tenantCode: saveForm.tenantCode,
executionType: saveForm.executionType, executionType: saveForm.executionType,
description: saveForm.description, description: saveForm.description,
globalParams: JSON.stringify(globalParams), globalParams: JSON.stringify(globalParams),

5
dolphinscheduler-ui/src/views/projects/workflow/definition/timing/use-table.ts

@ -128,6 +128,11 @@ export function useTable() {
key: 'workerGroup', key: 'workerGroup',
width: 140 width: 140
}, },
{
title: t('project.workflow.tenant_code'),
key: 'tenantCode',
width: 140
},
{ {
title: t('project.workflow.environment_name'), title: t('project.workflow.environment_name'),
key: 'environmentName', key: 'environmentName',

1
dolphinscheduler-ui/src/views/projects/workflow/instance/detail/index.tsx

@ -93,7 +93,6 @@ export default defineComponent({
locations: JSON.stringify(locations), locations: JSON.stringify(locations),
taskDefinitionJson: JSON.stringify(taskDefinitions), taskDefinitionJson: JSON.stringify(taskDefinitions),
taskRelationJson: JSON.stringify(connects), taskRelationJson: JSON.stringify(connects),
tenantCode: saveForm.tenantCode,
timeout: saveForm.timeoutFlag ? saveForm.timeout : 0 timeout: saveForm.timeoutFlag ? saveForm.timeout : 0
}, },
id, id,

Loading…
Cancel
Save