From ddbcb6a0342124126023d1dc07d585f1e48b8fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=B9=89=E8=B6=85?= Date: Tue, 31 Mar 2026 17:05:59 +0800 Subject: [PATCH 1/2] Remove unused code in messages --- .../src/main/resources/i18n/messages.properties | 15 --------------- .../resources/i18n/messages_en_US.properties | 15 --------------- .../resources/i18n/messages_zh_CN.properties | 16 ---------------- 3 files changed, 46 deletions(-) diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages.properties b/dolphinscheduler-api/src/main/resources/i18n/messages.properties index 586a35c88cb6..0798e6f9261a 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages.properties @@ -94,7 +94,6 @@ SUFFIX=resource file suffix CONTENT=resource file content UPDATE_RESOURCE_NOTES=edit resource file online DOWNLOAD_RESOURCE_NOTES=download resource file -CLASS_NAME=package and class name VERIFY_QUEUE_NOTES=verify queue TENANT_TAG=tenant related operation CREATE_TENANT_NOTES=create tenant @@ -112,7 +111,6 @@ QUERY_ALL_PROJECT_LIST_NOTES=query all project list QUERY_AUTHORIZED_PROJECT_NOTES=query authorized project QUERY_AUTHORIZED_USER_NOTES=query authorized user CREATE_TOKEN_NOTES=create access token for specified user -CREATE_TOKEN_V2=create access token for specified user (V2) UPDATE_TOKEN_NOTES=update access token for specified user TOKEN=access token string, it will be automatically generated when it absent EXPIRE_TIME=expire time for the token @@ -149,7 +147,6 @@ VERIFY_WORKFLOW_DEFINITION_NAME_NOTES=verify workflow definition name LOGIN_NOTES=user login SSO_LOGIN_NOTES=user sso login UPDATE_WORKFLOW_DEFINITION_NOTES=update workflow definition -WORKFLOW_DEFINITION_ID=workflow definition id RELEASE_WORKFLOW_DEFINITION_NOTES=release workflow definition QUERY_WORKFLOW_DEFINITION_BY_NAME_NOTES=query workflow definition by name QUERY_WORKFLOW_DEFINITION_LIST_NOTES=query workflow definition list @@ -173,8 +170,6 @@ TASK_ID=task instance id SKIP_LINE_NUM=skip line num QUERY_TASK_INSTANCE_LOG_NOTES=query task instance log DOWNLOAD_TASK_INSTANCE_LOG_NOTES=download task instance log -QUERY_TASK_INSTANCE_LOG_IN_SPECIFIED_PROJECT_NOTES=query task instance log in specified project -DOWNLOAD_TASK_INSTANCE_LOG_IN_SPECIFIED_PROJECT_NOTES=download task instance log in specified project USERS_TAG=users related operation SCHEDULE_TAG=schedule related operation CREATE_SCHEDULE_NOTES=create schedule @@ -240,7 +235,6 @@ STATE=state TABLE_NAME=table name AUDIT_LOG_TAG=audit log related operation TASK_DEFINITION_TAG=task definition related operation -WORKFLOW_TASK_RELATION_TAG=workflow task relation related operation ENVIRONMENT_TAG=environment related operation CREATE_ENVIRONMENT_NOTES=create environment ENVIRONMENT_NAME=environment name @@ -295,14 +289,6 @@ QUERY_AVAILABLE_NAMESPACE_LIST_NOTES=query available k8s namespace QUERY_WORKFLOW_DEFINITION_All_BY_PROJECT_CODE_NOTES=query all workflow definition by project code -CREATE_WORKFLOW_TASK_RELATION_NOTES=create workflow task relation -DELETE_WORKFLOW_TASK_RELATION_NOTES=delete workflow task relation -DELETE_UPSTREAM_RELATION_NOTES=delete upstream task relation -DELETE_DOWNSTREAM_RELATION_NOTES=delete downstream task relation -QUERY_UPSTREAM_RELATION_NOTES=query upstream task relation -QUERY_DOWNSTREAM_RELATION_NOTES=query downstream task relation -DELETE_EDGE_NOTES=delete edge - TASK_DEFINITION_JSON=task definition json UPSTREAM_CODES=upstream code list UPDATE_TASK_DEFINITION_NOTES=update task definition @@ -343,7 +329,6 @@ QUERY_WORKFLOW_LINEAGE_BY_NAME_NOTES=query workflow lineage by name QUERY_WORKFLOW_LINEAGE_BY_CODE_NOTE=query workflow lineage by code list QUERY_WORKFLOW_LINEAGE_NOTES=query workflow lineage VERIFY_TASK_CAN_DELETE=verify if task can be deleted -WORKFLOW_TAG_V2=work flow lineage related operation (V2) PROJECT_PARAMETER_TAG=project parameter related operation CREATE_PROJECT_PARAMETER_NOTES=create project parameter diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties index 075c8ca561b2..388f8c48a53f 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties @@ -34,7 +34,6 @@ VERIFY_ALERT_GROUP_NAME_NOTES=verify alert group name, check alert group exist o EXECUTOR_TAG=executor operation EXECUTOR_NAME=executor name WORKER_GROUP=work group -startParams=start parameters ALERT_GROUP_TAG=alert group related operation ALERT_PLUGIN_INSTANCE_TAG=alert plugin instance related operation WORK_FLOW_LINEAGE_TAG=work flow lineage related operation @@ -99,7 +98,6 @@ SUFFIX=resource file suffix CONTENT=resource file content UPDATE_RESOURCE_NOTES=edit resource file online DOWNLOAD_RESOURCE_NOTES=download resource file -CLASS_NAME=package and class name VERIFY_QUEUE_NOTES=verify queue TENANT_TAG=tenant related operation CREATE_TENANT_NOTES=create tenant @@ -117,7 +115,6 @@ QUERY_UNAUTHORIZED_PROJECT_NOTES=query unauthorized project QUERY_AUTHORIZED_PROJECT_NOTES=query authorized project QUERY_AUTHORIZED_USER_NOTES=query authorized user CREATE_TOKEN_NOTES=create access token for specified user -CREATE_TOKEN_V2=create access token for specified user (V2) UPDATE_TOKEN_NOTES=update access token for specified user TOKEN=access token string, it will be automatically generated when it absent EXPIRE_TIME=expire time for the token @@ -203,8 +200,6 @@ WORKFLOW_INSTANCE_IDS=workflow instance ids, delimiter by "," if more than one i SKIP_LINE_NUM=skip line num QUERY_TASK_INSTANCE_LOG_NOTES=query task instance log DOWNLOAD_TASK_INSTANCE_LOG_NOTES=download task instance log -QUERY_TASK_INSTANCE_LOG_IN_SPECIFIED_PROJECT_NOTES=query task instance log in specified project -DOWNLOAD_TASK_INSTANCE_LOG_IN_SPECIFIED_PROJECT_NOTES=download task instance log in specified project USERS_TAG=users related operation SCHEDULE_TAG=schedule related operation CREATE_SCHEDULE_NOTES=create schedule @@ -274,7 +269,6 @@ TABLE_NAME=table name QUERY_AUDIT_LOG=query audit log AUDIT_LOG_TAG=audit log related operation TASK_DEFINITION_TAG=task definition related operation -WORKFLOW_TASK_RELATION_TAG=process task relation related operation ENVIRONMENT_TAG=environment related operation CREATE_ENVIRONMENT_NOTES=create environment ENVIRONMENT_NAME=environment name @@ -325,14 +319,6 @@ QUERY_AVAILABLE_NAMESPACE_LIST_NOTES=query available k8s namespace QUERY_WORKFLOW_DEFINITION_All_BY_PROJECT_CODE_NOTES=query all process definition by project code -CREATE_WORKFLOW_TASK_RELATION_NOTES=create process task relation -DELETE_WORKFLOW_TASK_RELATION_NOTES=delete process task relation -DELETE_UPSTREAM_RELATION_NOTES=delete upstream task relation -DELETE_DOWNSTREAM_RELATION_NOTES=delete downstream task relation -QUERY_UPSTREAM_RELATION_NOTES=query upstream task relation -QUERY_DOWNSTREAM_RELATION_NOTES=query downstream task relation -DELETE_EDGE_NOTES=delete edge - TASK_DEFINITION_JSON=task definition json UPSTREAM_CODES=upstream code list UPDATE_TASK_DEFINITION_NOTES=update task definition @@ -370,7 +356,6 @@ TASK_INSTANCE_STOP=stop task instance QUERY_WORKFLOW_LINEAGE_BY_CODE_NOTE=query workflow lineage by code list QUERY_WORKFLOW_LINEAGE_NOTES=query workflow lineage VERIFY_TASK_CAN_DELETE=verify if task can be deleted -WORKFLOW_TAG_V2=work flow lineage related operation (V2) PROJECT_PARAMETER_TAG=project parameter related operation CREATE_PROJECT_PARAMETER_NOTES=create project parameter diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties index b85daa0a119d..73a5e167c95c 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties @@ -32,7 +32,6 @@ EXECUTOR_NAME=\u6D41\u7A0B\u540D\u79F0 DESC=\u5907\u6CE8(\u63CF\u8FF0) GROUP_NAME=\u7EC4\u540D\u79F0 WORKER_GROUP=worker\u7FA4\u7EC4 -startParams=\u542F\u52A8\u53C2\u6570 QUERY_ALERT_GROUP_LIST_NOTES=\u544A\u8B66\u7EC4\u5217\u8868 UPDATE_ALERT_GROUP_NOTES=\u7F16\u8F91(\u66F4\u65B0)\u544A\u8B66\u7EC4 DELETE_ALERT_GROUP_BY_ID_NOTES=\u901A\u8FC7ID\u5220\u9664\u544A\u8B66\u7EC4 @@ -86,7 +85,6 @@ SUFFIX=\u8D44\u6E90\u6587\u4EF6\u540E\u7F00 CONTENT=\u8D44\u6E90\u6587\u4EF6\u5185\u5BB9 UPDATE_RESOURCE_NOTES=\u5728\u7EBF\u66F4\u65B0\u8D44\u6E90\u6587\u4EF6 DOWNLOAD_RESOURCE_NOTES=\u4E0B\u8F7D\u8D44\u6E90\u6587\u4EF6 -CLASS_NAME=\u5305\u540D\u7C7B\u540D VERIFY_QUEUE_NOTES=\u9A8C\u8BC1\u961F\u5217 TENANT_TAG=\u79DF\u6237\u76F8\u5173\u64CD\u4F5C CREATE_TENANT_NOTES=\u521B\u5EFA\u79DF\u6237 @@ -104,7 +102,6 @@ QUERY_UNAUTHORIZED_PROJECT_NOTES=\u67E5\u8BE2\u672A\u6388\u6743\u7684\u9879\u76E QUERY_AUTHORIZED_PROJECT_NOTES=\u67E5\u8BE2\u6388\u6743\u9879\u76EE QUERY_AUTHORIZED_USER_NOTES=\u67E5\u8BE2\u62E5\u6709\u9879\u76EE\u6388\u6743\u7684\u7528\u6237 CREATE_TOKEN_NOTES=\u4E3A\u6307\u5B9A\u7528\u6237\u521B\u5EFA\u5B89\u5168\u4EE4\u724C -CREATE_TOKEN_V2=\u4E3A\u6307\u5B9A\u7528\u6237\u521B\u5EFA\u5B89\u5168\u4EE4\u724C (V2) UPDATE_TOKEN_NOTES=\u66F4\u65B0\u6307\u5B9A\u7528\u6237\u7684\u5B89\u5168\u4EE4\u724C TOKEN=\u5B89\u5168\u4EE4\u724C\u5B57\u7B26\u4E32\uFF0C\u82E5\u672A\u663E\u5F0F\u6307\u5B9A\u5C06\u4F1A\u81EA\u52A8\u751F\u6210 EXPIRE_TIME=\u5B89\u5168\u4EE4\u724C\u7684\u8FC7\u671F\u65F6\u95F4 @@ -144,7 +141,6 @@ QUERY_WORKFLOW_INSTANCE_LIST_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9E\u4F8B\u5217\u8 VERIFY_WORKFLOW_DEFINITION_NAME_NOTES=\u9A8C\u8BC1\u6D41\u7A0B\u5B9A\u4E49\u540D\u5B57 LOGIN_NOTES=\u7528\u6237\u767B\u5F55 UPDATE_WORKFLOW_DEFINITION_NOTES=\u66F4\u65B0\u6D41\u7A0B\u5B9A\u4E49 -WORKFLOW_DEFINITION_ID=\u6D41\u7A0B\u5B9A\u4E49ID RELEASE_WORKFLOW_DEFINITION_NOTES=\u53D1\u5E03\u6D41\u7A0B\u5B9A\u4E49 QUERY_WORKFLOW_DEFINITION_LIST_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9A\u4E49\u5217\u8868 QUERY_WORKFLOW_DEFINITION_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u6D41\u7A0B\u5B9A\u4E49\u5217\u8868 @@ -184,8 +180,6 @@ TASK_ID=\u4EFB\u52A1\u5B9E\u4F8BID SKIP_LINE_NUM=\u5FFD\u7565\u884C\u6570 QUERY_TASK_INSTANCE_LOG_NOTES=\u67E5\u8BE2\u4EFB\u52A1\u5B9E\u4F8B\u65E5\u5FD7 DOWNLOAD_TASK_INSTANCE_LOG_NOTES=\u4E0B\u8F7D\u4EFB\u52A1\u5B9E\u4F8B\u65E5\u5FD7 -QUERY_TASK_INSTANCE_LOG_IN_SPECIFIED_PROJECT_NOTES=\u67E5\u8BE2\u6307\u5B9A\u9879\u76EE\u7684\u4EFB\u52A1\u5B9E\u4F8B\u65E5\u5FD7 -DOWNLOAD_TASK_INSTANCE_LOG_IN_SPECIFIED_PROJECT_NOTES=\u4E0B\u8F7D\u6307\u5B9A\u9879\u76EE\u7684\u4EFB\u52A1\u5B9E\u4F8B\u65E5\u5FD7 USERS_TAG=\u7528\u6237\u76F8\u5173\u64CD\u4F5C SCHEDULE_TAG=\u5B9A\u65F6\u76F8\u5173\u64CD\u4F5C CREATE_SCHEDULE_NOTES=\u521B\u5EFA\u5B9A\u65F6 @@ -273,7 +267,6 @@ TABLE_NAME=\u8868\u540D QUERY_AUDIT_LOG=\u67E5\u8BE2\u5BA1\u8BA1\u65E5\u5FD7 AUDIT_LOG_TAG=\u5BA1\u8BA1\u65E5\u5FD7\u6267\u884C\u76F8\u5173\u64CD\u4F5C TASK_DEFINITION_TAG=\u4EFB\u52A1\u5B9A\u4E49\u76F8\u5173\u64CD\u4F5C -WORKFLOW_TASK_RELATION_TAG=\u5DE5\u4F5C\u6D41\u5173\u7CFB\u76F8\u5173\u64CD\u4F5C ENVIRONMENT_TAG=\u73AF\u5883\u76F8\u5173\u64CD\u4F5C CREATE_ENVIRONMENT_NOTES=\u521B\u5EFA\u73AF\u5883 ENVIRONMENT_NAME=\u73AF\u5883\u540D\u79F0 @@ -324,14 +317,6 @@ QUERY_AVAILABLE_NAMESPACE_LIST_NOTES=\u67E5\u8BE2\u53EF\u7528\u547D\u540D\u7A7A\ QUERY_WORKFLOW_DEFINITION_All_BY_PROJECT_CODE_NOTES=\u901A\u8FC7\u9879\u76EE\u4EE3\u7801\u67E5\u8BE2\u6240\u6709\u5DE5\u4F5C\u91CF\u5B9A\u4E49 -CREATE_WORKFLOW_TASK_RELATION_NOTES=\u521B\u5EFA\u5DE5\u4F5C\u6D41\u4EFB\u52A1\u5173\u7CFB -DELETE_WORKFLOW_TASK_RELATION_NOTES=\u5220\u9664\u5DE5\u4F5C\u6D41\u4EFB\u52A1\u5173\u7CFB -DELETE_UPSTREAM_RELATION_NOTES=\u5220\u9664\u4E0A\u6E38\u5DE5\u4F5C\u6D41\u4EFB\u52A1\u5173\u7CFB -DELETE_DOWNSTREAM_RELATION_NOTES=\u5220\u9664\u4E0B\u6E38\u5DE5\u4F5C\u6D41\u4EFB\u52A1\u5173\u7CFB -QUERY_UPSTREAM_RELATION_NOTES=\u67E5\u8BE2\u4E0A\u6E38\u5DE5\u4F5C\u6D41\u4EFB\u52A1\u5173\u7CFB -QUERY_DOWNSTREAM_RELATION_NOTES=\u67E5\u8BE2\u4E0B\u6E38\u5DE5\u4F5C\u6D41\u4EFB\u52A1\u5173\u7CFB -DELETE_EDGE_NOTES=\u5220\u9664\u5DE5\u4F5C\u6D41\u4EFB\u52A1\u8FDE\u63A5\u7EBF - TASK_DEFINITION_JSON=\u4EFB\u52A1\u5B9A\u4E49JSON UPSTREAM_CODES=\u4E0A\u6E38\u4EE3\u7801\u5217\u8868 UPDATE_TASK_DEFINITION_NOTES=\u66F4\u65B0\u4EFB\u52A1\u5B9A\u4E49 @@ -369,7 +354,6 @@ TASK_INSTANCE_STOP=\u505C\u6B62\u4EFB\u52A1\u5B9E\u4F8B QUERY_WORKFLOW_LINEAGE_BY_CODE_NOTE=\u901A\u8FC7\u8840\u7F18\u4EE3\u7801\u67E5\u8BE2\u5DE5\u4F5C\u6D41\u8840\u7F18\u5173\u7CFB QUERY_WORKFLOW_LINEAGE_NOTES=\u67E5\u8BE2\u5DE5\u4F5C\u91CF\u8840\u7F18\u5173\u7CFB VERIFY_TASK_CAN_DELETE=\u6821\u9A8C\u662F\u5426\u53EF\u4EE5\u5220\u9664\u4EFB\u52A1 -WORKFLOW_TAG_V2=\u5DE5\u4F5C\u91CF\u8840\u7F18\u5173\u7CFB\u76F8\u5173\u64CD\u4F5C (V2) PROJECT_PARAMETER_TAG=\u9879\u76EE\u53C2\u6570\u76F8\u5173\u64CD\u4F5C CREATE_PROJECT_PARAMETER_NOTES=\u65B0\u589E\u9879\u76EE\u53C2\u6570 From 5d2c3f2034730bc04a15faafad9593369b6d27ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=B9=89=E8=B6=85?= Date: Sun, 5 Apr 2026 21:21:25 +0800 Subject: [PATCH 2/2] Remove unused methods from the class. --- .../audit/constants/AuditLogConstants.java | 1 - .../ApiFuncIdentificationConstant.java | 50 - .../api/dto/CommandStateCount.java | 40 +- .../api/dto/ScheduleParam.java | 49 +- .../api/dto/gantt/GanttDto.java | 19 - .../dolphinscheduler/api/dto/gantt/Task.java | 70 +- .../visitor/ResourceTreeVisitor.java | 18 +- .../TaskRelationFilterRequest.java | 6 - .../api/dto/treeview/Instance.java | 3 - .../api/dto/treeview/TreeViewDto.java | 46 +- .../api/enums/ExecuteType.java | 2 + .../BackfillWorkflowExecutorDelegate.java | 8 - .../api/permission/PermissionCheck.java | 53 +- .../api/python/PythonGateway.java | 17 - .../api/service/TaskDefinitionService.java | 12 - .../api/service/TaskInstanceService.java | 11 - .../api/service/WorkflowInstanceService.java | 12 - .../api/service/WorkflowLineageService.java | 2 - .../service/WorkflowTaskRelationService.java | 133 --- .../api/service/impl/ExecutorServiceImpl.java | 331 ------- .../service/impl/SchedulerServiceImpl.java | 20 - .../impl/TaskDefinitionServiceImpl.java | 170 ---- .../service/impl/TaskInstanceServiceImpl.java | 17 - .../api/service/impl/TenantServiceImpl.java | 4 - .../api/service/impl/UsersServiceImpl.java | 4 - .../impl/WorkflowDefinitionServiceImpl.java | 144 +-- .../impl/WorkflowInstanceServiceImpl.java | 33 - .../impl/WorkflowLineageServiceImpl.java | 10 +- .../impl/WorkflowTaskRelationServiceImpl.java | 888 ------------------ .../dolphinscheduler/api/utils/FileUtils.java | 88 -- .../dolphinscheduler/api/utils/Result.java | 3 - .../BackfillWorkflowRequestTransformer.java | 4 - .../api/vo/TaskDefinitionVO.java | 11 +- .../api/service/AlertGroupServiceTest.java | 1 - .../AlertPluginInstanceServiceTest.java | 5 - .../api/service/AuditServiceTest.java | 4 - .../api/service/BaseServiceTest.java | 9 - .../api/service/DataSourceServiceTest.java | 4 - .../api/service/K8SNamespaceServiceTest.java | 8 - .../api/service/ProjectServiceTest.java | 8 +- .../api/service/SchedulerServiceTest.java | 14 - .../api/service/SessionServiceTest.java | 4 - .../service/TaskDefinitionLogServiceTest.java | 7 - .../TaskDefinitionServiceImplTest.java | 6 - .../api/service/TaskGroupServiceTest.java | 15 - .../api/service/TaskInstanceServiceTest.java | 5 +- .../api/service/TenantServiceTest.java | 4 - .../api/service/UsersServiceTest.java | 15 - .../WorkflowDefinitionServiceTest.java | 36 - .../service/WorkflowInstanceServiceTest.java | 24 +- .../WorkflowTaskLineageServiceTest.java | 4 - .../WorkflowTaskRelationServiceTest.java | 622 ------------ .../api/service/impl/ClusterServiceTest.java | 4 - .../api/utils/FileUtilsTest.java | 122 --- 54 files changed, 57 insertions(+), 3143 deletions(-) delete mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FileUtils.java delete mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationServiceTest.java delete mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/FileUtilsTest.java diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/constants/AuditLogConstants.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/constants/AuditLogConstants.java index b7200adc1313..b24abf56f9d8 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/constants/AuditLogConstants.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/constants/AuditLogConstants.java @@ -41,6 +41,5 @@ private AuditLogConstants() { public static final String ALIAS = "alias"; public static final String FILE_NAME = "fileName"; public static final String FULL_NAME = "fullName"; - public static final String FUNC_NAME = "funcName"; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/constants/ApiFuncIdentificationConstant.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/constants/ApiFuncIdentificationConstant.java index 12a0bee29180..001a5910dded 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/constants/ApiFuncIdentificationConstant.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/constants/ApiFuncIdentificationConstant.java @@ -24,8 +24,6 @@ public class ApiFuncIdentificationConstant { - public static final String ACCESS_TOKEN_MANAGE = "security:token:view"; - public static final String ACCESS_TOKEN_VIEW = "security:token:view"; public static final String ACCESS_TOKEN_CREATE = "security:token:create"; public static final String ACCESS_TOKEN_UPDATE = "security:token:update"; public static final String ACCESS_TOKEN_DELETE = "security:token:delete"; @@ -33,7 +31,6 @@ public class ApiFuncIdentificationConstant { public static final String ALERT_GROUP_CREATE = "security:alert-group:create"; public static final String ALERT_GROUP_UPDATE = "security:alert-group:update"; public static final String ALERT_GROUP_DELETE = "security:alert-group:delete"; - public static final String TENANT_MANAGER = "security:tenant:view"; public static final String TENANT_CREATE = "security:tenant:create"; public static final String TENANT_UPDATE = "security:tenant:update"; public static final String TENANT_DELETE = "security:tenant:delete"; @@ -41,27 +38,13 @@ public class ApiFuncIdentificationConstant { public static final String ALERT_PLUGIN_UPDATE = "security:alert-plugin:update"; public static final String ALERT_PLUGIN_DELETE = "security:alert-plugin:delete"; public static final String WORKER_GROUP_CREATE = "security:worker-group:create"; - public static final String WORKER_GROUP_EDIT = "security:worker-group:update"; public static final String WORKER_GROUP_DELETE = "security:worker-group:delete"; - public static final String YARN_QUEUE_MANAGE = "security:queue:view"; public static final String YARN_QUEUE_CREATE = "security:queue:create"; public static final String YARN_QUEUE_UPDATE = "security:queue:update"; public static final String ENVIRONMENT_CREATE = "security:environment:create"; public static final String ENVIRONMENT_UPDATE = "security:environment:update"; public static final String ENVIRONMENT_DELETE = "security:environment:delete"; - public static final String ENVIRONMENT_MANAGER = "security:environment:view"; - public static final String CALENDAR_CREATE = "security:calendar:create"; - public static final String CALENDAR_EDIT = "security:calendar:update"; - public static final String CALENDAR_DELETE = "security:calendar:delete"; - public static final String CARDS_CREATE = "security:cards:create"; - public static final String CARDS_EDIT = "security:cards:update"; - public static final String CARDS_EDIT_VALUE = "security:cards:value"; - public static final String CARDS_CARDS_DELETE = "security:cards:delete"; - public static final String ALARM_GROUP_MANAGE = "security:alert-group:view"; public static final String ALARM_INSTANCE_MANAGE = "security:alert-plugin:view"; - public static final String WORKER_GROUP_MANAGE = "security:worker-group:view"; - public static final String CALENDAR_MANAGE = "security:calendar:view"; - public static final String CARDS_MANAGER = "security:cards:view"; public static final String USER_MANAGER = "security:user:view"; public static final String PROJECT = "project:view"; @@ -70,22 +53,12 @@ public class ApiFuncIdentificationConstant { public static final String PROJECT_DELETE = "project:delete"; public static final String WORKFLOW_DEFINITION = "project:definition:list"; public static final String WORKFLOW_CREATE = "project:definition:create"; - public static final String WORKFLOW_IMPORT = "project:definition:import"; public static final String WORKFLOW_UPDATE = "project:definition:update"; - public static final String WORKFLOW_START = "project:executors:start"; - public static final String TIMING = "project:schedules:timing"; public static final String WORKFLOW_ONLINE_OFFLINE = "project:definition:release"; - public static final String WORKFLOW_COPY = "project:definition:copy"; - public static final String CRON_MANAGE = "project:schedules:corn"; - public static final String WORKFLOW_DELETE = "project:definition:delete"; public static final String WORKFLOW_TREE_VIEW = "project:definition:view-tree"; - public static final String WORKFLOW_EXPORT = "project:definition:export"; public static final String WORKFLOW_BATCH_COPY = "project:definition:batch-copy"; - public static final String WORKFLOW_DEFINITION_EXPORT = "project:definition:batch-export"; - public static final String WORKFLOW_DEFINITION_BATCH_DELETE = "project:definition:batch-delete"; public static final String WORKFLOW_SWITCH_TO_THIS_VERSION = "project:definition:version:switch"; public static final String WORKFLOW_DEFINITION_DELETE = "project:definition:version:delete"; - public static final String WORKFLOW_SAVE = "project:definition:verify-name"; public static final String WORKFLOW_INSTANCE = "project:process-instance:list"; public static final String RERUN = "project:executors:execute"; public static final String FAILED_TO_RETRY = "project:executors:retry"; @@ -93,57 +66,34 @@ public class ApiFuncIdentificationConstant { public static final String RECOVERY_SUSPEND = "project:executors:recover"; public static final String PAUSE = "project:executors:pause"; public static final String INSTANCE_DELETE = "project:process-instance:delete"; - public static final String INSTANCE_BATCH_DELETE = "project:process-instance:batch-delete"; public static final String FORCED_SUCCESS = "project:task-instance:force-success"; public static final String VIEW_LOG = "project:log:detail"; public static final String DOWNLOAD_LOG = "project:log:download-log"; public static final String PROJECT_OVERVIEW = "project:overview:view"; - public static final String WORKFLOW_RELATION = "project:lineages:view"; - public static final String WORKFLOW_DEFINITION_VIEW = "project:definition:view"; - public static final String WORKFLOW_INSTANCE_VIEW = "project:process-instance:view"; public static final String TASK_INSTANCE = "project:task-instance:view"; public static final String INSTANCE_UPDATE = "project:process-instance:update"; public static final String VERSION_LIST = "project:version:list"; public static final String TASK_DEFINITION = "project:task-definition:view"; - public static final String TASK_DEFINITION_CREATE = "project:task-definition:create"; - public static final String TASK_DEFINITION_UPDATE = "project:task-definition:edit"; public static final String TASK_DEFINITION_MOVE = "project:task-definition:move"; public static final String TASK_VERSION_VIEW = "project:task-definition:version"; public static final String TASK_DEFINITION_DELETE = "project:task-definition:delete"; - public static final String VERSION_DELETE = "project:version:delete"; public static final String DATASOURCE = "datasource:view"; public static final String DATASOURCE_CREATE_DATASOURCE = "datasource:create"; public static final String DATASOURCE_UPDATE = "datasource:update"; public static final String DATASOURCE_DELETE = "datasource:delete"; - public static final String DATASOURCE_LIST = "datasource:list"; - public static final String DATASOURCE_PARAM_VIEW = "datasource:param-view"; - - public static final String FILE_VIEW = "resources:file:view"; - public static final String FOLDER_ONLINE_CREATE = "resources:file:create"; - public static final String FILE_ONLINE_CREATE = "resources:file:online-create"; - public static final String FILE_UPLOAD = "resources:file:upload"; - public static final String FILE_UPDATE = "resources:file:update-content"; - public static final String FILE_RENAME = "resources:file:rename"; - public static final String FILE_DOWNLOAD = "resources:file:download"; - public static final String FILE_DELETE = "resources:file:delete"; public static final String TASK_GROUP_VIEW = "resources:task-group:view"; public static final String TASK_GROUP_CREATE = "resources:task-group:create"; public static final String TASK_GROUP_CLOSE = "resources:task-group:close"; public static final String TASK_GROUP_EDIT = "resources:task-group:update"; - public static final String TASK_GROUP_VIEW_QUEUE = "resources:task-group:queue-view"; - public static final String TASK_GROUP_QUEUE = "resources:task-group-queue:view"; public static final String TASK_GROUP_QUEUE_PRIORITY = "resources:task-group-queue:priority"; public static final String TASK_GROUP_QUEUE_START = "resources:task-group-queue:start"; public static final String MONITOR_MASTER_VIEW = "monitor:masters:view"; - public static final String MONITOR_WORKER_VIEW = "monitor:workers:view"; public static final String MONITOR_DATABASES_VIEW = "monitor:databases:view"; - public static final String MONITOR_STATISTICS_VIEW = "monitor:statistics:view"; - public final static Map map = new HashMap(); static { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/CommandStateCount.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/CommandStateCount.java index b1b0eb66c964..14cd718fc22d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/CommandStateCount.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/CommandStateCount.java @@ -19,48 +19,22 @@ import org.apache.dolphinscheduler.common.enums.CommandType; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * command state count */ +@Data +@AllArgsConstructor +@NoArgsConstructor public class CommandStateCount { private int errorCount; private int normalCount; private CommandType commandState; - public CommandStateCount() { - } - - public CommandStateCount(int errorCount, int normalCount, CommandType commandState) { - this.errorCount = errorCount; - this.normalCount = normalCount; - this.commandState = commandState; - } - - public int getErrorCount() { - return errorCount; - } - - public void setErrorCount(int errorCount) { - this.errorCount = errorCount; - } - - public int getNormalCount() { - return normalCount; - } - - public void setNormalCount(int normalCount) { - this.normalCount = normalCount; - } - - public CommandType getCommandState() { - return commandState; - } - - public void setCommandState(CommandType commandState) { - this.commandState = commandState; - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ScheduleParam.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ScheduleParam.java index a3c4f08d8a75..de1e3933c047 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ScheduleParam.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ScheduleParam.java @@ -19,9 +19,16 @@ import java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * schedule parameters */ +@Data +@AllArgsConstructor +@NoArgsConstructor public class ScheduleParam { private Date startTime; @@ -29,48 +36,6 @@ public class ScheduleParam { private String crontab; private String timezoneId; - public ScheduleParam() { - } - - public ScheduleParam(Date startTime, Date endTime, String timezoneId, String crontab) { - this.startTime = startTime; - this.endTime = endTime; - this.timezoneId = timezoneId; - this.crontab = crontab; - } - - public Date getStartTime() { - return startTime; - } - - public void setStartTime(Date startTime) { - this.startTime = startTime; - } - - public Date getEndTime() { - return endTime; - } - - public void setEndTime(Date endTime) { - this.endTime = endTime; - } - - public String getCrontab() { - return crontab; - } - - public void setCrontab(String crontab) { - this.crontab = crontab; - } - - public String getTimezoneId() { - return timezoneId; - } - - public void setTimezoneId(String timezoneId) { - this.timezoneId = timezoneId; - } - @Override public String toString() { return "ScheduleParam{" diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/GanttDto.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/GanttDto.java index 06edac8fd5d3..706d631f7f8c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/GanttDto.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/GanttDto.java @@ -27,11 +27,6 @@ @Data public class GanttDto { - /** - * height - */ - private int height; - /** * tasks list */ @@ -52,18 +47,4 @@ public GanttDto() { taskStatus.put("success", "success"); } - public GanttDto(int height, List tasks, List taskNames) { - this(); - this.height = height; - this.tasks = tasks; - this.taskNames = taskNames; - } - - public GanttDto(int height, List tasks, List taskNames, Map taskStatus) { - this.height = height; - this.tasks = tasks; - this.taskNames = taskNames; - this.taskStatus = taskStatus; - } - } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/Task.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/Task.java index 5370f61e8a4d..86fe3fd9fcff 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/Task.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/gantt/Task.java @@ -21,9 +21,16 @@ import java.util.LinkedList; import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * Task */ +@Data +@AllArgsConstructor +@NoArgsConstructor public class Task { /** @@ -65,67 +72,4 @@ public class Task { */ private String duration; - public String getTaskName() { - return taskName; - } - - public void setTaskName(String taskName) { - this.taskName = taskName; - } - - public List getStartDate() { - return startDate; - } - - public void setStartDate(List startDate) { - this.startDate = startDate; - } - - public List getEndDate() { - return endDate; - } - - public void setEndDate(List endDate) { - this.endDate = endDate; - } - - public Date getExecutionDate() { - return executionDate; - } - - public void setExecutionDate(Date executionDate) { - this.executionDate = executionDate; - } - - public Date getIsoStart() { - return isoStart; - } - - public void setIsoStart(Date isoStart) { - this.isoStart = isoStart; - } - - public Date getIsoEnd() { - return isoEnd; - } - - public void setIsoEnd(Date isoEnd) { - this.isoEnd = isoEnd; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getDuration() { - return duration; - } - - public void setDuration(String duration) { - this.duration = duration; - } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/resources/visitor/ResourceTreeVisitor.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/resources/visitor/ResourceTreeVisitor.java index f7f93e780db0..b58db3b81987 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/resources/visitor/ResourceTreeVisitor.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/resources/visitor/ResourceTreeVisitor.java @@ -26,9 +26,16 @@ import java.util.List; import java.util.Objects; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * resource tree visitor */ +@Data +@AllArgsConstructor +@NoArgsConstructor public class ResourceTreeVisitor implements Visitor { /** @@ -36,17 +43,6 @@ public class ResourceTreeVisitor implements Visitor { */ private List resourceList; - public ResourceTreeVisitor() { - } - - /** - * constructor - * @param resourceList resource list - */ - public ResourceTreeVisitor(List resourceList) { - this.resourceList = resourceList; - } - /** * visit * @return resoruce component diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskRelation/TaskRelationFilterRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskRelation/TaskRelationFilterRequest.java index d19813468168..188255984c7c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskRelation/TaskRelationFilterRequest.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/taskRelation/TaskRelationFilterRequest.java @@ -44,12 +44,6 @@ public class TaskRelationFilterRequest extends PageQueryDto { @Schema(example = "1234567890123") private long postTaskCode; - public TaskRelationFilterRequest(long workflowCode, long preTaskCode, long postTaskCode) { - this.workflowCode = workflowCode; - this.preTaskCode = preTaskCode; - this.postTaskCode = postTaskCode; - } - public TaskRelationFilterRequest(long preTaskCode, long postTaskCode) { this.preTaskCode = preTaskCode; this.postTaskCode = postTaskCode; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java index 84c0db7dbcda..b05ee430db09 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/Instance.java @@ -68,9 +68,6 @@ public class Instance { private long subflowCode; - public Instance() { - } - public Instance(int id, String name, long code, String type) { this.id = id; this.name = name; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java index 8645bf30b698..607be51a45e6 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/treeview/TreeViewDto.java @@ -20,9 +20,16 @@ import java.util.ArrayList; import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * TreeView */ +@Data +@AllArgsConstructor +@NoArgsConstructor public class TreeViewDto { /** @@ -51,43 +58,4 @@ public class TreeViewDto { */ private List children = new ArrayList<>(); - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public long getCode() { - return code; - } - - public void setCode(long code) { - this.code = code; - } - - public List getInstances() { - return instances; - } - - public void setInstances(List instances) { - this.instances = instances; - } - - public List getChildren() { - return children; - } - - public void setChildren(List children) { - this.children = children; - } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/ExecuteType.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/ExecuteType.java index ff3f122a2366..c6f9933d19b1 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/ExecuteType.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/ExecuteType.java @@ -24,11 +24,13 @@ public enum ExecuteType { /** * operation type + * 0 none * 1 repeat running * 2 resume pause * 3 resume failure * 4 stop * 5 pause + * 6 execute task */ NONE(0, "NONE"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/BackfillWorkflowExecutorDelegate.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/BackfillWorkflowExecutorDelegate.java index 0c684f2876f2..ddda4e5f0318 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/BackfillWorkflowExecutorDelegate.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/BackfillWorkflowExecutorDelegate.java @@ -25,14 +25,12 @@ import org.apache.dolphinscheduler.common.model.Server; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; -import org.apache.dolphinscheduler.dao.repository.CommandDao; import org.apache.dolphinscheduler.extract.base.client.Clients; import org.apache.dolphinscheduler.extract.master.IWorkflowControlClient; import org.apache.dolphinscheduler.extract.master.transportor.workflow.WorkflowBackfillTriggerRequest; import org.apache.dolphinscheduler.extract.master.transportor.workflow.WorkflowBackfillTriggerResponse; import org.apache.dolphinscheduler.registry.api.RegistryClient; import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType; -import org.apache.dolphinscheduler.service.process.ProcessService; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -51,12 +49,6 @@ @Component public class BackfillWorkflowExecutorDelegate implements IExecutorDelegate> { - @Autowired - private CommandDao commandDao; - - @Autowired - private ProcessService processService; - @Autowired private RegistryClient registryClient; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/PermissionCheck.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/PermissionCheck.java index 6ace0b64acab..220bfc9d3c69 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/PermissionCheck.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/PermissionCheck.java @@ -20,7 +20,6 @@ import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import org.apache.dolphinscheduler.service.exceptions.ServiceException; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -28,14 +27,17 @@ import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + import org.slf4j.Logger; +@Data +@AllArgsConstructor +@NoArgsConstructor public class PermissionCheck { - /** - * logger - */ - private Logger logger; /** * Authorization Type */ @@ -51,48 +53,15 @@ public class PermissionCheck { */ private T[] needChecks; - /** - * resoruce info - */ - private List resourceList; - /** * user id */ private int userId; - public PermissionCheck(AuthorizationType authorizationType, ProcessService processService, T[] needChecks, - int userId, Logger logger) { - this.authorizationType = authorizationType; - this.processService = processService; - this.needChecks = needChecks; - this.userId = userId; - this.logger = logger; - } - - public ProcessService getProcessService() { - return processService; - } - - public void setProcessService(ProcessService processService) { - this.processService = processService; - } - - public int getUserId() { - return userId; - } - - public void setUserId(int userId) { - this.userId = userId; - } - - public List getResourceList() { - return resourceList; - } - - public void setResourceList(List resourceList) { - this.resourceList = resourceList; - } + /** + * logger + */ + private Logger logger; /** * check permission diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java index d6650a404499..95111cb2e5c8 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java @@ -34,13 +34,10 @@ import org.apache.dolphinscheduler.api.service.WorkflowDefinitionService; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.CommandType; -import org.apache.dolphinscheduler.common.enums.ComplementDependentMode; -import org.apache.dolphinscheduler.common.enums.ExecutionOrder; import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.Priority; import org.apache.dolphinscheduler.common.enums.ReleaseState; -import org.apache.dolphinscheduler.common.enums.RunMode; import org.apache.dolphinscheduler.common.enums.TaskDependType; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.enums.WarningType; @@ -49,7 +46,6 @@ import org.apache.dolphinscheduler.dao.entity.DataSource; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.ProjectUser; -import org.apache.dolphinscheduler.dao.entity.Queue; import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.Tenant; @@ -94,11 +90,6 @@ public class PythonGateway { private static final Priority DEFAULT_PRIORITY = Priority.MEDIUM; private static final Long DEFAULT_ENVIRONMENT_CODE = -1L; - private static final TaskDependType DEFAULT_TASK_DEPEND_TYPE = TaskDependType.TASK_POST; - private static final RunMode DEFAULT_RUN_MODE = RunMode.RUN_MODE_SERIAL; - private static final ExecutionOrder DEFAULT_EXECUTION_ORDER = ExecutionOrder.DESC_ORDER; - private static final int DEFAULT_DRY_RUN = 0; - private static final ComplementDependentMode COMPLEMENT_DEPENDENT_MODE = ComplementDependentMode.OFF_MODE; // We use admin user's user_id to skip some permission issue from python gateway service private static final int ADMIN_USER_ID = 1; @@ -160,14 +151,6 @@ public class PythonGateway { } }; - private final Queue queuePythonGateway = new Queue() { - - { - setId(Integer.MAX_VALUE); - setQueueName("queuePythonGateway"); - } - }; - public String ping() { return "PONG"; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java index 00d1f430934f..05343c736d1c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java @@ -17,8 +17,6 @@ package org.apache.dolphinscheduler.api.service; -import org.apache.dolphinscheduler.api.dto.task.TaskFilterRequest; -import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.enums.ReleaseState; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; @@ -54,16 +52,6 @@ Map queryTaskDefinitionByName(User loginUser, TaskDefinition getTaskDefinition(User loginUser, long taskCode); - /** - * Get resource task definition according to query parameter - * - * @param loginUser login user - * @param taskFilterRequest taskFilterRequest - * @return PageResourceResponse from condition - */ - PageInfo filterTaskDefinition(User loginUser, - TaskFilterRequest taskFilterRequest); - /** * update task definition and upstream * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java index 3690aa118c6f..63b65d9a5452 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java @@ -19,7 +19,6 @@ import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.enums.TaskExecuteType; -import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; @@ -90,15 +89,5 @@ void forceTaskSuccess(User loginUser, */ Result stopTask(User loginUser, long projectCode, Integer taskInstanceId); - /** - * query taskInstance by taskInstanceCode - * - * @param loginUser login user - * @param projectCode project code - * @param taskInstanceId taskInstance id - * @return the result code and msg - */ - TaskInstance queryTaskInstanceById(User loginUser, long projectCode, Long taskInstanceId); - void deleteByWorkflowInstanceId(Integer workflowInstanceId); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceService.java index cd8ae1ced6d3..0eb224d30503 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceService.java @@ -51,18 +51,6 @@ Map queryWorkflowInstanceById(User loginUser, long projectCode, Integer workflowInstanceId); - WorkflowInstance queryByWorkflowInstanceIdThrowExceptionIfNotFound(Integer workflowInstanceId); - - /** - * query workflow instance by id - * - * @param loginUser login user - * @param workflowInstanceId workflow instance id - * @return workflow instance detail - */ - Map queryWorkflowInstanceById(User loginUser, - Integer workflowInstanceId); - /** * paging query workflow instance list, filtering according to project, workflow definition, time range, keyword, workflow status * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowLineageService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowLineageService.java index f20503b1409e..8340029eec21 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowLineageService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowLineageService.java @@ -55,8 +55,6 @@ public interface WorkflowLineageService { List queryDependentWorkflowDefinitions(long projectCode, long workflowDefinitionCode, Long taskCode); - int createWorkflowLineage(List workflowTaskLineages); - /** * Replace the lineage of given workflow definition by new lineage list. * When the list is empty, existing lineage data will be deleted. diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationService.java index 23fa22815aa2..8c5ca80703aa 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationService.java @@ -17,145 +17,12 @@ package org.apache.dolphinscheduler.api.service; -import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationCreateRequest; -import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationUpdateUpstreamRequest; -import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelation; import java.util.List; -import java.util.Map; public interface WorkflowTaskRelationService { - /** - * create workflow task relation - * - * @param loginUser login user - * @param projectCode project code - * @param workflowDefinitionCode workflowDefinitionCode - * @param preTaskCode preTaskCode - * @param postTaskCode postTaskCode - * @return create result code - */ - Map createWorkflowTaskRelation(User loginUser, - long projectCode, - long workflowDefinitionCode, - long preTaskCode, - long postTaskCode); - - /** - * create resource workflow task relation - * - * @param loginUser login user - * @param taskRelationCreateRequest project code - * @return WorkflowTaskRelation object - */ - WorkflowTaskRelation createWorkflowTaskRelationV2(User loginUser, - TaskRelationCreateRequest taskRelationCreateRequest); - - /** - * delete workflow task relation - * - * @param loginUser login user - * @param projectCode project code - * @param workflowDefinitionCode workflow definition code - * @param taskCode the post task code - * @return delete result code - */ - Map deleteTaskWorkflowRelation(User loginUser, - long projectCode, - long workflowDefinitionCode, - long taskCode); - - /** - * delete workflow task relation, will delete exists relation preTaskCode -> postTaskCode, throw error if not exists - * - * @param loginUser login user - * @param preTaskCode relation upstream code - * @param postTaskCode relation downstream code - */ - void deleteTaskWorkflowRelationV2(User loginUser, - long preTaskCode, - long postTaskCode); - - /** - * delete workflow task relation, will delete exists relation upstream -> downstream, throw error if not exists - * - * @param loginUser login user - * @param taskCode relation upstream code - * @param needSyncDag needSyncDag - * @param taskRelationUpdateUpstreamRequest relation downstream code - */ - List updateUpstreamTaskDefinitionWithSyncDag(User loginUser, - long taskCode, - Boolean needSyncDag, - TaskRelationUpdateUpstreamRequest taskRelationUpdateUpstreamRequest); - - /** - * delete task upstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param preTaskCodes the pre task codes, sep ',' - * @param taskCode the post task code - * @return delete result code - */ - Map deleteUpstreamRelation(User loginUser, - long projectCode, - String preTaskCodes, - long taskCode); - - /** - * delete task downstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param postTaskCodes the post task codes, sep ',' - * @param taskCode the pre task code - * @return delete result code - */ - Map deleteDownstreamRelation(User loginUser, - long projectCode, - String postTaskCodes, - long taskCode); - - /** - * query task upstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param taskCode current task code (post task code) - * @return workflow task relation list - */ - Map queryUpstreamRelation(User loginUser, - long projectCode, - long taskCode); - - /** - * query task downstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param taskCode pre task code - * @return workflow task relation list - */ - Map queryDownstreamRelation(User loginUser, - long projectCode, - long taskCode); - - /** - * delete edge - * - * @param loginUser login user - * @param projectCode project code - * @param workflowDefinitionCode workflow definition code - * @param preTaskCode pre task code - * @param postTaskCode post task code - * @return delete result code - */ - Map deleteEdge(User loginUser, long projectCode, long workflowDefinitionCode, long preTaskCode, - long postTaskCode); - List queryByWorkflowDefinitionCode(long workflowDefinitionCode, int workflowDefinitionVersion); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java index c308c7f420d3..47eb69c2555f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java @@ -18,13 +18,9 @@ package org.apache.dolphinscheduler.api.service.impl; import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_COMPLEMENT_DATA_END_DATE; -import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST; -import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_COMPLEMENT_DATA_START_DATE; import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_RECOVER_WORKFLOW_ID_STRING; import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_START_NODES; import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_SUB_WORKFLOW_DEFINITION_CODE; -import static org.apache.dolphinscheduler.common.constants.Constants.COMMA; import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant; import org.apache.dolphinscheduler.api.dto.workflow.WorkflowBackFillRequest; @@ -36,8 +32,6 @@ import org.apache.dolphinscheduler.api.executor.workflow.ExecutorClient; import org.apache.dolphinscheduler.api.service.ExecutorService; import org.apache.dolphinscheduler.api.service.ProjectService; -import org.apache.dolphinscheduler.api.service.WorkerGroupService; -import org.apache.dolphinscheduler.api.service.WorkflowLineageService; import org.apache.dolphinscheduler.api.validator.workflow.BackfillWorkflowDTO; import org.apache.dolphinscheduler.api.validator.workflow.BackfillWorkflowDTOValidator; import org.apache.dolphinscheduler.api.validator.workflow.BackfillWorkflowRequestTransformer; @@ -46,21 +40,13 @@ import org.apache.dolphinscheduler.api.validator.workflow.TriggerWorkflowRequestTransformer; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.CommandType; -import org.apache.dolphinscheduler.common.enums.ComplementDependentMode; -import org.apache.dolphinscheduler.common.enums.CycleEnum; -import org.apache.dolphinscheduler.common.enums.ExecutionOrder; import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.ReleaseState; -import org.apache.dolphinscheduler.common.enums.RunMode; import org.apache.dolphinscheduler.common.enums.TaskDependType; -import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.Command; -import org.apache.dolphinscheduler.dao.entity.DependentWorkflowDefinition; -import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskGroupQueue; -import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; @@ -68,29 +54,18 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskGroupQueueMapper; -import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowTaskRelationMapper; import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.dolphinscheduler.plugin.task.api.utils.TaskTypeUtils; import org.apache.dolphinscheduler.service.command.CommandService; -import org.apache.dolphinscheduler.service.cron.CronUtils; -import org.apache.dolphinscheduler.service.exceptions.CronParseException; import org.apache.dolphinscheduler.service.process.ProcessService; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; - -import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -101,8 +76,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.google.common.base.Splitter; - @Service @Slf4j public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorService { @@ -135,15 +108,6 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ @Autowired private TaskGroupQueueMapper taskGroupQueueMapper; - @Autowired - private WorkerGroupService workerGroupService; - - @Autowired - private TenantMapper tenantMapper; - - @Autowired - private WorkflowLineageService workflowLineageService; - @Autowired private TriggerWorkflowRequestTransformer triggerWorkflowRequestTransformer; @@ -238,20 +202,6 @@ public boolean checkSubWorkflowDefinitionValid(WorkflowDefinition workflowDefini .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); - } - } - } - @Override public void controlWorkflowInstance(User loginUser, Integer workflowInstanceId, ExecuteType executeType) { checkNotNull(workflowInstanceId, "workflowInstanceId cannot be null"); @@ -427,287 +377,6 @@ public Map forceStartTaskInstance(User loginUser, int queueId) { return result; } - private int createComplementCommand(Long triggerCode, Command command, Map cmdParam, - List dateTimeList, List schedules, - ComplementDependentMode complementDependentMode, boolean allLevelDependent) { - - String dateTimeListStr = dateTimeList.stream() - .map(item -> DateUtils.dateToString(item)) - .collect(Collectors.joining(COMMA)); - - cmdParam.put(CMD_PARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST, dateTimeListStr); - command.setCommandParam(JSONUtils.toJsonString(cmdParam)); - - log.info("Creating command, commandInfo:{}.", command); - int createCount = commandService.createCommand(command); - - if (createCount > 0) { - log.info("Create {} command complete, workflowDefinitionCode:{}", - command.getCommandType().getDescp(), command.getWorkflowDefinitionCode()); - } else { - log.error("Create {} command error, workflowDefinitionCode:{}", - command.getCommandType().getDescp(), command.getWorkflowDefinitionCode()); - } - - if (schedules.isEmpty() || complementDependentMode == ComplementDependentMode.OFF_MODE) { - log.info( - "Complement dependent mode is off mode or Scheduler is empty, so skip create complement dependent command, workflowDefinitionCode:{}.", - command.getWorkflowDefinitionCode()); - } else { - log.info( - "Complement dependent mode is all dependent and Scheduler is not empty, need create complement dependent command, workflowDefinitionCode:{}.", - command.getWorkflowDefinitionCode()); - createComplementDependentCommand(schedules, command, allLevelDependent); - } - - return createCount; - } - - protected int createComplementCommandList(Long triggerCode, String scheduleTimeParam, RunMode runMode, - Command command, - Integer expectedParallelismNumber, - ComplementDependentMode complementDependentMode, - boolean allLevelDependent, - ExecutionOrder executionOrder) throws CronParseException { - int createCount = 0; - int dependentWorkflowDefinitionCreateCount = 0; - runMode = (runMode == null) ? RunMode.RUN_MODE_SERIAL : runMode; - Map cmdParam = JSONUtils.toMap(command.getCommandParam()); - Map scheduleParam = JSONUtils.toMap(scheduleTimeParam); - - if (Objects.isNull(executionOrder)) { - executionOrder = ExecutionOrder.DESC_ORDER; - } - - List schedules = processService.queryReleaseSchedulerListByWorkflowDefinitionCode( - command.getWorkflowDefinitionCode()); - - List listDate = new ArrayList<>(); - if (scheduleParam.containsKey(CMD_PARAM_COMPLEMENT_DATA_START_DATE) && scheduleParam.containsKey( - CMD_PARAM_COMPLEMENT_DATA_END_DATE)) { - String startDate = scheduleParam.get(CMD_PARAM_COMPLEMENT_DATA_START_DATE); - String endDate = scheduleParam.get(CMD_PARAM_COMPLEMENT_DATA_END_DATE); - if (startDate != null && endDate != null) { - listDate = CronUtils.getSelfFireDateList( - DateUtils.stringToZoneDateTime(startDate), - DateUtils.stringToZoneDateTime(endDate), - schedules); - } - } - - if (scheduleParam.containsKey(CMD_PARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST)) { - String dateList = scheduleParam.get(CMD_PARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST); - - if (StringUtils.isNotBlank(dateList)) { - listDate = Splitter.on(COMMA).splitToStream(dateList) - .map(item -> DateUtils.stringToZoneDateTime(item.trim())) - .distinct() - .collect(Collectors.toList()); - } - } - - if (CollectionUtils.isEmpty(listDate)) { - throw new ServiceException(Status.TASK_COMPLEMENT_DATA_DATE_ERROR); - } - - if (executionOrder.equals(ExecutionOrder.DESC_ORDER)) { - Collections.sort(listDate, Collections.reverseOrder()); - } else { - Collections.sort(listDate); - } - - switch (runMode) { - case RUN_MODE_SERIAL: { - log.info("RunMode of {} command is serial run, workflowDefinitionCode:{}.", - command.getCommandType().getDescp(), command.getWorkflowDefinitionCode()); - createCount = createComplementCommand(triggerCode, command, cmdParam, listDate, schedules, - complementDependentMode, allLevelDependent); - break; - } - case RUN_MODE_PARALLEL: { - log.info("RunMode of {} command is parallel run, workflowDefinitionCode:{}.", - command.getCommandType().getDescp(), command.getWorkflowDefinitionCode()); - - int queueNum = 0; - if (CollectionUtils.isNotEmpty(listDate)) { - queueNum = listDate.size(); - if (expectedParallelismNumber != null && expectedParallelismNumber != 0) { - queueNum = Math.min(queueNum, expectedParallelismNumber); - } - log.info("Complement command run in parallel mode, current expectedParallelismNumber:{}.", - queueNum); - List[] queues = new List[queueNum]; - - for (int i = 0; i < listDate.size(); i++) { - if (Objects.isNull(queues[i % queueNum])) { - queues[i % queueNum] = new ArrayList(); - } - queues[i % queueNum].add(listDate.get(i)); - } - for (List queue : queues) { - createCount = createComplementCommand(triggerCode, command, cmdParam, queue, schedules, - complementDependentMode, allLevelDependent); - } - } - break; - } - default: - break; - } - log.info("Create complement command count:{}, Create dependent complement command count:{}", createCount, - dependentWorkflowDefinitionCreateCount); - return createCount; - } - - /** - * create complement dependent command - */ - public int createComplementDependentCommand(List schedules, Command command, boolean allLevelDependent) { - int dependentWorkflowDefinitionCreateCount = 0; - Command dependentCommand; - - try { - dependentCommand = (Command) BeanUtils.cloneBean(command); - } catch (Exception e) { - log.error("Copy dependent command error.", e); - return dependentWorkflowDefinitionCreateCount; - } - - List dependentWorkflowDefinitionList = - getComplementDependentDefinitionList(dependentCommand.getWorkflowDefinitionCode(), - CronUtils.getMaxCycle(schedules.get(0).getCrontab()), dependentCommand.getWorkerGroup(), - allLevelDependent); - dependentCommand.setTaskDependType(TaskDependType.TASK_POST); - for (DependentWorkflowDefinition dependentWorkflowDefinition : dependentWorkflowDefinitionList) { - // If the id is Integer, the auto-increment id will be obtained by mybatis-plus - // and causing duplicate when clone it. - dependentCommand.setId(null); - dependentCommand.setWorkflowDefinitionCode(dependentWorkflowDefinition.getWorkflowDefinitionCode()); - dependentCommand.setWorkflowDefinitionVersion(dependentWorkflowDefinition.getWorkflowDefinitionVersion()); - dependentCommand.setWorkerGroup(dependentWorkflowDefinition.getWorkerGroup()); - Map cmdParam = JSONUtils.toMap(dependentCommand.getCommandParam()); - cmdParam.put(CMD_PARAM_START_NODES, String.valueOf(dependentWorkflowDefinition.getTaskDefinitionCode())); - dependentCommand.setCommandParam(JSONUtils.toJsonString(cmdParam)); - log.info("Creating complement dependent command, commandInfo:{}.", command); - dependentWorkflowDefinitionCreateCount += commandService.createCommand(dependentCommand); - } - - return dependentWorkflowDefinitionCreateCount; - } - - /** - * get complement dependent online workflow definition list - */ - private List getComplementDependentDefinitionList(long workflowDefinitionCode, - CycleEnum workflowDefinitionCycle, - String workerGroup, - boolean allLevelDependent) { - List dependentWorkflowDefinitionList = - checkDependentWorkflowDefinitionValid( - workflowLineageService.queryDownstreamDependentWorkflowDefinitions(workflowDefinitionCode), - workflowDefinitionCycle, workerGroup, - workflowDefinitionCode); - - if (dependentWorkflowDefinitionList.isEmpty()) { - return dependentWorkflowDefinitionList; - } - - if (allLevelDependent) { - List childList = new ArrayList<>(dependentWorkflowDefinitionList); - while (true) { - List childDependentList = childList - .stream() - .flatMap(dependentWorkflowDefinition -> checkDependentWorkflowDefinitionValid( - workflowLineageService.queryDownstreamDependentWorkflowDefinitions( - dependentWorkflowDefinition.getWorkflowDefinitionCode()), - workflowDefinitionCycle, - workerGroup, - dependentWorkflowDefinition.getWorkflowDefinitionCode()).stream()) - .collect(Collectors.toList()); - if (childDependentList.isEmpty()) { - break; - } - dependentWorkflowDefinitionList.addAll(childDependentList); - childList = new ArrayList<>(childDependentList); - } - } - return dependentWorkflowDefinitionList; - } - - /** - * Check whether the dependency cycle of the dependent node is consistent with the schedule cycle of - * the dependent workflow definition and if there is no worker group in the schedule, use the complement selection's - * worker group - */ - private List checkDependentWorkflowDefinitionValid( - List dependentWorkflowDefinitionList, - CycleEnum workflowDefinitionCycle, - String workerGroup, - long upstreamWorkflowDefinitionCode) { - List validDependentWorkflowDefinitionList = new ArrayList<>(); - - List workflowDefinitionCodeList = - dependentWorkflowDefinitionList.stream().map(DependentWorkflowDefinition::getWorkflowDefinitionCode) - .collect(Collectors.toList()); - - Map workflowDefinitionWorkerGroupMap = - workerGroupService.queryWorkerGroupByWorkflowDefinitionCodes(workflowDefinitionCodeList); - - for (DependentWorkflowDefinition dependentWorkflowDefinition : dependentWorkflowDefinitionList) { - if (dependentWorkflowDefinition - .getDependentCycle(upstreamWorkflowDefinitionCode) == workflowDefinitionCycle) { - if (workflowDefinitionWorkerGroupMap - .get(dependentWorkflowDefinition.getWorkflowDefinitionCode()) == null) { - dependentWorkflowDefinition.setWorkerGroup(workerGroup); - } - - validDependentWorkflowDefinitionList.add(dependentWorkflowDefinition); - } - } - - return validDependentWorkflowDefinitionList; - } - - /** - * @param schedule - * @return check error return 0, otherwise 1 - */ - private boolean isValidateScheduleTime(String schedule) { - Map scheduleResult = JSONUtils.toMap(schedule); - if (scheduleResult == null) { - return false; - } - if (scheduleResult.containsKey(CMD_PARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST)) { - if (scheduleResult.get(CMD_PARAM_COMPLEMENT_DATA_SCHEDULE_DATE_LIST) == null) { - return false; - } - } - if (scheduleResult.containsKey(CMD_PARAM_COMPLEMENT_DATA_START_DATE)) { - String startDate = scheduleResult.get(CMD_PARAM_COMPLEMENT_DATA_START_DATE); - String endDate = scheduleResult.get(CMD_PARAM_COMPLEMENT_DATA_END_DATE); - if (startDate == null || endDate == null) { - return false; - } - try { - ZonedDateTime start = DateUtils.stringToZoneDateTime(startDate); - ZonedDateTime end = DateUtils.stringToZoneDateTime(endDate); - if (start == null || end == null) { - return false; - } - if (start.isAfter(end)) { - log.error( - "Complement data parameter error, start time should be before end time, startDate:{}, endDate:{}.", - start, end); - return false; - } - } catch (Exception ex) { - log.warn("Parse schedule time error, startDate:{}, endDate:{}.", startDate, endDate); - return false; - } - } - return true; - } - @Override public void execStreamTaskInstance(User loginUser, long projectCode, diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java index 70b192a69751..e43863f5092e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java @@ -42,7 +42,6 @@ import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; -import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; @@ -97,9 +96,6 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe @Autowired private SchedulerApi schedulerApi; - @Autowired - private EnvironmentMapper environmentMapper; - @Autowired private TenantExistValidator tenantExistValidator; @@ -226,22 +222,6 @@ protected void projectPermCheckByWorkflowCode(User loginUser, long workflowDefin this.projectService.checkProjectAndAuthThrowException(loginUser, project, null); } - private void scheduleParamCheck(String scheduleParamStr) { - ScheduleParam scheduleParam = JSONUtils.parseObject(scheduleParamStr, ScheduleParam.class); - if (scheduleParam == null) { - throw new ServiceException(Status.PARSE_SCHEDULE_PARAM_ERROR, scheduleParamStr); - } - if (DateUtils.differSec(scheduleParam.getStartTime(), scheduleParam.getEndTime()) == 0) { - throw new ServiceException(Status.SCHEDULE_START_TIME_END_TIME_SAME); - } - if (scheduleParam.getStartTime().getTime() > scheduleParam.getEndTime().getTime()) { - throw new ServiceException(Status.START_TIME_BIGGER_THAN_END_TIME_ERROR); - } - if (!CronUtils.isValidExpression(scheduleParam.getCrontab())) { - throw new ServiceException(Status.SCHEDULE_CRON_CHECK_FAILED, scheduleParam.getCrontab()); - } - } - /** * updateWorkflowInstance schedule * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java index da10229d56ae..9ee45ee4426c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java @@ -18,20 +18,15 @@ package org.apache.dolphinscheduler.api.service.impl; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION; -import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_DELETE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_VERSION_VIEW; -import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_DEFINITION; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_SWITCH_TO_THIS_VERSION; import static org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager.checkTaskParameters; -import org.apache.dolphinscheduler.api.dto.task.TaskFilterRequest; -import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationUpdateUpstreamRequest; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.permission.PermissionCheck; import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.TaskDefinitionService; -import org.apache.dolphinscheduler.api.service.WorkflowDefinitionService; import org.apache.dolphinscheduler.api.service.WorkflowTaskRelationService; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; @@ -48,7 +43,6 @@ import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; -import org.apache.dolphinscheduler.dao.entity.TaskMainInfo; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinitionLog; @@ -127,44 +121,9 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe @Autowired private ProcessService processService; - @Autowired - private WorkflowDefinitionService workflowDefinitionService; - @Autowired private WorkflowDefinitionLogMapper workflowDefinitionLogMapper; - private TaskDefinitionLog persist2TaskDefinitionLog(User user, TaskDefinition taskDefinition) { - TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog(taskDefinition); - taskDefinitionLog.setOperator(user.getId()); - taskDefinitionLog.setOperateTime(new Date()); - int result = taskDefinitionLogMapper.insert(taskDefinitionLog); - if (result <= 0) { - throw new ServiceException(Status.CREATE_TASK_DEFINITION_LOG_ERROR, taskDefinitionLog.getName()); - } - return taskDefinitionLog; - } - - private void checkTaskDefinitionValid(User user, TaskDefinition taskDefinition, String permissions) { - // check user access for project - Project project = projectMapper.queryByCode(taskDefinition.getProjectCode()); - projectService.checkProjectAndAuthThrowException(user, project, permissions); - - if (!checkTaskParameters(taskDefinition.getTaskType(), taskDefinition.getTaskParams())) { - throw new ServiceException(Status.WORKFLOW_NODE_S_PARAMETER_INVALID, taskDefinition.getName()); - } - } - - private List updateTaskUpstreams(User user, long workflowCode, long taskCode, - String upstreamCodes) { - TaskRelationUpdateUpstreamRequest taskRelationUpdateUpstreamRequest = new TaskRelationUpdateUpstreamRequest(); - taskRelationUpdateUpstreamRequest.setWorkflowCode(workflowCode); - if (upstreamCodes != null) { - taskRelationUpdateUpstreamRequest.setUpstreams(upstreamCodes); - } - return workflowTaskRelationService.updateUpstreamTaskDefinitionWithSyncDag(user, taskCode, Boolean.FALSE, - taskRelationUpdateUpstreamRequest); - } - /** * query task definition * @@ -196,38 +155,6 @@ public Map queryTaskDefinitionByName(User loginUser, long projec return result; } - /** - * Whether task definition can be deleted or not - */ - private void taskCanDeleteValid(User user, TaskDefinition taskDefinition, User loginUser) { - // check user access for project - Project project = projectMapper.queryByCode(taskDefinition.getProjectCode()); - projectService.checkProjectAndAuthThrowException(user, project, TASK_DEFINITION_DELETE); - // check if user have write perm for project - Map result = new HashMap<>(); - boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); - if (!hasProjectAndWritePerm) { - throw new ServiceException(Status.TASK_DEFINITION_STATE_ONLINE, taskDefinition.getCode()); - } - - // Whether task relation workflow is online - if (processService.isTaskOnline(taskDefinition.getCode()) && taskDefinition.getFlag() == Flag.YES) { - throw new ServiceException(Status.TASK_DEFINITION_STATE_ONLINE, taskDefinition.getCode()); - } - - // Whether task have downstream tasks - List workflowTaskRelationList = - workflowTaskRelationMapper.queryDownstreamByTaskCode(taskDefinition.getCode()); - if (CollectionUtils.isNotEmpty(workflowTaskRelationList)) { - Set postTaskCodes = workflowTaskRelationList - .stream() - .map(WorkflowTaskRelation::getPostTaskCode) - .collect(Collectors.toSet()); - String postTaskCodesStr = StringUtils.join(postTaskCodes, Constants.COMMA); - throw new ServiceException(Status.TASK_HAS_DOWNSTREAM, postTaskCodesStr); - } - } - public void updateDag(User loginUser, long workflowDefinitionCode, List workflowTaskRelationList, List taskDefinitionLogs) { @@ -262,28 +189,6 @@ public void updateDag(User loginUser, long workflowDefinitionCode, } } - private void TaskDefinitionUpdateValid(TaskDefinition taskDefinitionOriginal, TaskDefinition taskDefinitionUpdate) { - // Task already online - if (processService.isTaskOnline(taskDefinitionOriginal.getCode()) - && taskDefinitionOriginal.getFlag() == Flag.YES) { - // if stream, can update task definition without online check - if (taskDefinitionOriginal.getTaskExecuteType() != TaskExecuteType.STREAM) { - throw new ServiceException(Status.NOT_SUPPORT_UPDATE_TASK_DEFINITION); - } - } - - // not update anything - if (taskDefinitionOriginal.equals(taskDefinitionUpdate)) { - throw new ServiceException(Status.TASK_DEFINITION_NOT_CHANGE, taskDefinitionOriginal.getCode()); - } - - // check version invalid - Integer version = taskDefinitionLogMapper.queryMaxVersionForDefinition(taskDefinitionOriginal.getCode()); - if (version == null || version == 0) { - throw new ServiceException(Status.DATA_IS_NOT_VALID, taskDefinitionOriginal.getCode()); - } - } - /** * Get resource task definition by code * @@ -303,36 +208,6 @@ public TaskDefinition getTaskDefinition(User loginUser, return taskDefinition; } - /** - * Get resource task definition according to query parameter - * - * @param loginUser login user - * @param taskFilterRequest taskFilterRequest object you want to filter the resource task definitions - * @return TaskDefinitions of page - */ - @Override - public PageInfo filterTaskDefinition(User loginUser, - TaskFilterRequest taskFilterRequest) { - TaskDefinition taskDefinition = taskFilterRequest.convert2TaskDefinition(); - if (taskDefinition.getProjectName() != null) { - Project project = projectMapper.queryByName(taskDefinition.getProjectName()); - // check user access for project - projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_DEFINITION); - taskDefinition.setProjectCode(project.getCode()); - } - - Page page = - new Page<>(taskFilterRequest.getPageNo(), taskFilterRequest.getPageSize()); - IPage taskDefinitionIPage = - taskDefinitionMapper.filterTaskDefinition(page, taskDefinition); - - PageInfo pageInfo = - new PageInfo<>(taskFilterRequest.getPageNo(), taskFilterRequest.getPageSize()); - pageInfo.setTotal((int) taskDefinitionIPage.getTotal()); - pageInfo.setTotalList(taskDefinitionIPage.getRecords()); - return pageInfo; - } - private TaskDefinitionLog updateTask(User loginUser, long projectCode, long taskCode, String taskDefinitionJsonObj, Map result) { Project project = projectMapper.queryByCode(projectCode); @@ -798,51 +673,6 @@ public Map queryTaskDefinitionDetail(User loginUser, long projec return result; } - private void fillRecords(long projectCode, IPage taskMainInfoIPage) { - List records = Collections.emptyList(); - if (CollectionUtils.isNotEmpty(taskMainInfoIPage.getRecords())) { - // query task relevant info by task code - records = taskDefinitionMapper.queryDefineListByCodeList(projectCode, - taskMainInfoIPage.getRecords().stream().map(TaskMainInfo::getTaskCode) - .collect(Collectors.toList())); - } - // because first step, so need init records - taskMainInfoIPage.setRecords(Collections.emptyList()); - if (CollectionUtils.isNotEmpty(records)) { - // task code and task info map - Map taskMainInfoMap = new HashMap<>(); - // construct task code and relevant upstream task list map - for (TaskMainInfo info : records) { - taskMainInfoMap.compute(info.getTaskCode(), (k, v) -> { - if (v == null) { - Map upstreamTaskMap = new HashMap<>(); - if (info.getUpstreamTaskCode() != 0) { - upstreamTaskMap.put(info.getUpstreamTaskCode(), info.getUpstreamTaskName()); - info.setUpstreamTaskCode(0L); - info.setUpstreamTaskName(StringUtils.EMPTY); - } - info.setUpstreamTaskMap(upstreamTaskMap); - v = info; - } - if (info.getUpstreamTaskCode() != 0) { - v.getUpstreamTaskMap().put(info.getUpstreamTaskCode(), info.getUpstreamTaskName()); - } - return v; - }); - } - - // because taskMainInfoMap's value is TaskMainInfo, - // TaskMainInfo have task code info, so only need gain taskMainInfoMap's values - List resultRecords = Lists.newArrayList(taskMainInfoMap.values()); - resultRecords.sort((o1, o2) -> o2.getTaskUpdateTime().compareTo(o1.getTaskUpdateTime())); - taskMainInfoIPage.setRecords(resultRecords); - } - } - - private void fillWorkflowInfo(long projectCode, IPage taskMainInfoIPage) { - - } - @Override public Map genTaskCodeList(Integer genNum) { Map result = new HashMap<>(); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java index 1e599eb7a778..b5abbc86a6a7 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java @@ -36,7 +36,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; @@ -89,9 +88,6 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst @Autowired UsersService usersService; - @Autowired - TaskDefinitionMapper taskDefinitionMapper; - @Autowired private TaskGroupQueueService taskGroupQueueService; @@ -302,19 +298,6 @@ public Result stopTask(User loginUser, long projectCode, Integer taskInstanceId) return result; } - @Override - public TaskInstance queryTaskInstanceById(User loginUser, long projectCode, Long taskInstanceId) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - projectService.checkProjectAndAuthThrowException(loginUser, project, FORCED_SUCCESS); - TaskInstance taskInstance = taskInstanceMapper.selectById(taskInstanceId); - if (taskInstance == null) { - log.error("Task instance can not be found, projectCode:{}, taskInstanceId:{}.", projectCode, - taskInstanceId); - } - return taskInstance; - } - @Override public void deleteByWorkflowInstanceId(Integer workflowInstanceId) { List needToDeleteTaskInstances = diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java index f2dab3b868ee..9dbb6bcc98cd 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java @@ -40,7 +40,6 @@ import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; -import org.apache.dolphinscheduler.plugin.storage.api.StorageOperator; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -81,9 +80,6 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService @Autowired private QueueService queueService; - @Autowired(required = false) - private StorageOperator storageOperator; - /** * Check the tenant new object valid or not * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java index 0d0ecc0e9e55..e706be2a371a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java @@ -47,7 +47,6 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; -import org.apache.dolphinscheduler.plugin.storage.api.StorageOperator; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -102,9 +101,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { @Autowired private ProjectMapper projectMapper; - @Autowired(required = false) - private StorageOperator storageOperator; - @Autowired private K8sNamespaceUserMapper k8sNamespaceUserMapper; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java index 2085948e28f2..4ff7110e4235 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java @@ -17,7 +17,6 @@ package org.apache.dolphinscheduler.api.service.impl; -import static java.util.stream.Collectors.toSet; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_MOVE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.VERSION_LIST; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_BATCH_COPY; @@ -27,7 +26,6 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_ONLINE_OFFLINE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_SWITCH_TO_THIS_VERSION; 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.enums.Status.WORKFLOW_DEFINITION_NOT_EXIST; import static org.apache.dolphinscheduler.common.constants.CommandKeyConstants.CMD_PARAM_SUB_WORKFLOW_DEFINITION_CODE; import static org.apache.dolphinscheduler.common.constants.Constants.COPY_SUFFIX; @@ -170,6 +168,7 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl implements Wo @Autowired private WorkflowDefinitionLogDao workflowDefinitionLogDao; + @Lazy @Autowired private WorkflowInstanceService workflowInstanceService; @@ -277,36 +276,6 @@ public Map createWorkflowDefinition(User loginUser, return result; } - private void createWorkflowValid(User user, WorkflowDefinition workflowDefinition) { - Project project = projectMapper.queryByCode(workflowDefinition.getProjectCode()); - if (project == null) { - throw new ServiceException(Status.PROJECT_NOT_FOUND, workflowDefinition.getProjectCode()); - } - // check user access for project - projectService.checkProjectAndAuthThrowException(user, project, WORKFLOW_CREATE); - - if (checkDescriptionLength(workflowDefinition.getDescription())) { - throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR); - } - - // check whether the new workflow definition name exist - WorkflowDefinition definition = - workflowDefinitionMapper.verifyByDefineName(project.getCode(), workflowDefinition.getName()); - if (definition != null) { - throw new ServiceException(Status.WORKFLOW_DEFINITION_NAME_EXIST, workflowDefinition.getName()); - } - - } - - private void syncObj2Log(User user, WorkflowDefinition workflowDefinition) { - WorkflowDefinitionLog workflowDefinitionLog = new WorkflowDefinitionLog(workflowDefinition); - workflowDefinitionLog.setOperator(user.getId()); - int result = workflowDefinitionLogMapper.insert(workflowDefinitionLog); - if (result <= 0) { - throw new ServiceException(Status.CREATE_WORKFLOW_DEFINITION_LOG_ERROR); - } - } - protected Map createDagDefine(User loginUser, List taskRelationList, WorkflowDefinition workflowDefinition, @@ -1917,117 +1886,6 @@ public void deleteWorkflowDefinitionVersion(User loginUser, } - private void updateWorkflowValid(User user, WorkflowDefinition oldWorkflowDefinition, - WorkflowDefinition newWorkflowDefinition) { - // online can not permit edit - if (oldWorkflowDefinition.getReleaseState() == ReleaseState.ONLINE) { - throw new ServiceException(Status.WORKFLOW_DEFINITION_NOT_ALLOWED_EDIT, oldWorkflowDefinition.getName()); - } - - Project project = projectMapper.queryByCode(oldWorkflowDefinition.getProjectCode()); - // check user access for project - projectService.checkProjectAndAuthThrowException(user, project, WORKFLOW_UPDATE); - - if (checkDescriptionLength(newWorkflowDefinition.getDescription())) { - throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR); - } - - // check whether the new workflow define name exist - if (!oldWorkflowDefinition.getName().equals(newWorkflowDefinition.getName())) { - WorkflowDefinition definition = workflowDefinitionMapper - .verifyByDefineName(newWorkflowDefinition.getProjectCode(), newWorkflowDefinition.getName()); - if (definition != null) { - throw new ServiceException(Status.WORKFLOW_DEFINITION_NAME_EXIST, newWorkflowDefinition.getName()); - } - } - } - - public int saveWorkflowDefine(User loginUser, WorkflowDefinition workflowDefinition) { - WorkflowDefinitionLog workflowDefinitionLog = new WorkflowDefinitionLog(workflowDefinition); - Integer version = workflowDefinitionLogMapper.queryMaxVersionForDefinition(workflowDefinition.getCode()); - int insertVersion = version == null || version == 0 ? Constants.VERSION_FIRST : version + 1; - workflowDefinitionLog.setVersion(insertVersion); - workflowDefinition.setVersion(insertVersion); - - workflowDefinitionLog.setOperator(loginUser.getId()); - workflowDefinition.setUserId(loginUser.getId()); - workflowDefinitionLog.setOperateTime(workflowDefinition.getUpdateTime()); - workflowDefinition.setUpdateTime(workflowDefinition.getUpdateTime()); - workflowDefinitionLog.setId(null); - int result = workflowDefinitionMapper.updateById(workflowDefinition); - - int insertLog = workflowDefinitionLogMapper.insert(workflowDefinitionLog); - workflowDefinitionLog.setId(workflowDefinition.getId()); - return (insertLog & result) > 0 ? insertVersion : 0; - } - - public int saveTaskRelation(User loginUser, WorkflowDefinition workflowDefinition, - int workflowDefinitionVersion) { - long projectCode = workflowDefinition.getProjectCode(); - long workflowDefinitionCode = workflowDefinition.getCode(); - List taskRelations = - workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode); - List taskRelationList = - taskRelations.stream().map(WorkflowTaskRelationLog::new).collect(Collectors.toList()); - - List taskCodeList = - taskRelations.stream().map(WorkflowTaskRelation::getPostTaskCode).collect(Collectors.toList()); - List taskDefinitions = taskDefinitionMapper.queryByCodeList(taskCodeList); - List taskDefinitionLogs = - taskDefinitions.stream().map(TaskDefinitionLog::new).collect(Collectors.toList()); - - if (taskRelationList.isEmpty()) { - return Constants.EXIT_CODE_SUCCESS; - } - Map taskDefinitionLogMap = null; - if (CollectionUtils.isNotEmpty(taskDefinitionLogs)) { - taskDefinitionLogMap = taskDefinitionLogs - .stream() - .collect(Collectors.toMap(TaskDefinition::getCode, taskDefinitionLog -> taskDefinitionLog)); - } - Date now = new Date(); - for (WorkflowTaskRelationLog workflowTaskRelationLog : taskRelationList) { - workflowTaskRelationLog.setProjectCode(projectCode); - workflowTaskRelationLog.setWorkflowDefinitionCode(workflowDefinitionCode); - workflowTaskRelationLog.setWorkflowDefinitionVersion(workflowDefinitionVersion); - if (taskDefinitionLogMap != null) { - TaskDefinitionLog preTaskDefinitionLog = - taskDefinitionLogMap.get(workflowTaskRelationLog.getPreTaskCode()); - if (preTaskDefinitionLog != null) { - workflowTaskRelationLog.setPreTaskVersion(preTaskDefinitionLog.getVersion()); - } - TaskDefinitionLog postTaskDefinitionLog = - taskDefinitionLogMap.get(workflowTaskRelationLog.getPostTaskCode()); - if (postTaskDefinitionLog != null) { - workflowTaskRelationLog.setPostTaskVersion(postTaskDefinitionLog.getVersion()); - } - } - workflowTaskRelationLog.setCreateTime(now); - workflowTaskRelationLog.setUpdateTime(now); - workflowTaskRelationLog.setOperator(loginUser.getId()); - workflowTaskRelationLog.setOperateTime(now); - } - if (!taskRelations.isEmpty()) { - Set workflowTaskRelationSet = - taskRelations.stream().map(WorkflowTaskRelation::hashCode).collect(toSet()); - Set taskRelationSet = - taskRelationList.stream().map(WorkflowTaskRelationLog::hashCode).collect(toSet()); - boolean isSame = CollectionUtils.isEqualCollection(workflowTaskRelationSet, - taskRelationSet); - if (isSame) { - log.info("workflow task relations is non-existent, projectCode:{}, workflowDefinitionCode:{}.", - workflowDefinition.getProjectCode(), workflowDefinition.getCode()); - return Constants.EXIT_CODE_SUCCESS; - } - workflowTaskRelationMapper.deleteByWorkflowDefinitionCode(projectCode, workflowDefinitionCode); - } - List workflowTaskRelations = - taskRelationList.stream().map(WorkflowTaskRelation::new).collect(Collectors.toList()); - int insert = workflowTaskRelationMapper.batchInsert(workflowTaskRelations); - int resultLog = workflowTaskRelationLogMapper.batchInsert(taskRelationList); - return (insert & resultLog) > 0 ? Constants.EXIT_CODE_SUCCESS : Constants.EXIT_CODE_FAILURE; - } - @Transactional @Override public void onlineWorkflowDefinition(User loginUser, Long projectCode, Long workflowDefinitionCode) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java index 7ae19e010f03..4059b17b0700 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java @@ -34,8 +34,6 @@ import org.apache.dolphinscheduler.api.dto.gantt.Task; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ServiceException; -import org.apache.dolphinscheduler.api.service.ExecutorService; -import org.apache.dolphinscheduler.api.service.LoggerService; import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.TaskInstanceService; import org.apache.dolphinscheduler.api.service.UsersService; @@ -152,15 +150,9 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl implements Work @Autowired WorkflowDefinitionService workflowDefinitionService; - @Autowired - ExecutorService execService; - @Autowired TaskInstanceMapper taskInstanceMapper; - @Autowired - LoggerService loggerService; - @Autowired WorkflowDefinitionLogMapper workflowDefinitionLogMapper; @@ -268,31 +260,6 @@ public Map queryWorkflowInstanceById(User loginUser, long projec return result; } - @Override - public WorkflowInstance queryByWorkflowInstanceIdThrowExceptionIfNotFound(Integer workflowInstanceId) { - WorkflowInstance workflowInstance = workflowInstanceDao.queryById(workflowInstanceId); - if (workflowInstance == null) { - throw new ServiceException(WORKFLOW_INSTANCE_NOT_EXIST, workflowInstanceId); - } - return workflowInstance; - } - - /** - * query workflow instance by id - * - * @param loginUser login user - * @param workflowInstanceId workflow instance id - * @return workflow instance detail - */ - @Override - public Map queryWorkflowInstanceById(User loginUser, Integer workflowInstanceId) { - WorkflowInstance workflowInstance = workflowInstanceMapper.selectById(workflowInstanceId); - WorkflowDefinition workflowDefinition = - workflowDefinitionMapper.queryByCode(workflowInstance.getWorkflowDefinitionCode()); - - return queryWorkflowInstanceById(loginUser, workflowDefinition.getProjectCode(), workflowInstanceId); - } - /** * paging query workflow instance list, filtering according to project, workflow definition, time range, keyword, workflow status * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java index ab2ac16af853..998aaf79292b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowLineageServiceImpl.java @@ -31,7 +31,6 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; import org.apache.dolphinscheduler.dao.entity.WorkflowTaskLineage; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; import org.apache.dolphinscheduler.dao.repository.WorkflowTaskLineageDao; @@ -60,14 +59,12 @@ public class WorkflowLineageServiceImpl extends BaseServiceImpl implements Workf @Autowired private ProjectMapper projectMapper; - @Autowired - private TaskDefinitionLogMapper taskDefinitionLogMapper; - @Autowired private TaskDefinitionMapper taskDefinitionMapper; @Autowired private WorkflowTaskLineageDao workflowTaskLineageDao; + @Autowired private WorkflowDefinitionMapper workflowDefinitionMapper; @@ -322,11 +319,6 @@ public List queryDependentWorkflowDefinitions(long project return dependentLineageTaskList; } - @Override - public int createWorkflowLineage(List workflowTaskLineages) { - return workflowTaskLineageDao.batchInsert(workflowTaskLineages); - } - @Override public int updateWorkflowLineage(long workflowDefinitionCode, List workflowTaskLineages) { // Remove existing lineage first to keep data consistent diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowTaskRelationServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowTaskRelationServiceImpl.java index 2b46d126813c..620a04eafe73 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowTaskRelationServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowTaskRelationServiceImpl.java @@ -17,883 +17,24 @@ package org.apache.dolphinscheduler.api.service.impl; -import static java.util.stream.Collectors.toSet; - -import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationCreateRequest; -import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationFilterRequest; -import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationUpdateUpstreamRequest; -import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.exceptions.ServiceException; -import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.WorkflowTaskRelationService; -import org.apache.dolphinscheduler.common.constants.Constants; -import org.apache.dolphinscheduler.common.enums.ConditionType; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.TaskDefinition; -import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; -import org.apache.dolphinscheduler.dao.entity.WorkflowDefinitionLog; import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelation; -import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelationLog; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionLogMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowTaskRelationLogMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowTaskRelationMapper; -import org.apache.dolphinscheduler.plugin.task.api.utils.TaskTypeUtils; -import org.apache.dolphinscheduler.service.process.ProcessService; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.google.common.collect.Lists; @Service @Slf4j public class WorkflowTaskRelationServiceImpl extends BaseServiceImpl implements WorkflowTaskRelationService { - @Autowired - private ProjectMapper projectMapper; - - @Autowired - private ProjectService projectService; - @Autowired private WorkflowTaskRelationMapper workflowTaskRelationMapper; - @Autowired - private TaskDefinitionLogMapper taskDefinitionLogMapper; - - @Autowired - private TaskDefinitionMapper taskDefinitionMapper; - - @Autowired - private WorkflowDefinitionMapper workflowDefinitionMapper; - - @Autowired - private WorkflowDefinitionLogMapper workflowDefinitionLogMapper; - - @Autowired - private ProcessService processService; - - @Autowired - private WorkflowTaskRelationLogMapper workflowTaskRelationLogMapper; - - /** - * create workflow task relation - * - * @param loginUser login user - * @param projectCode project code - * @param workflowDefinitionCode workflowDefinitionCode - * @param preTaskCode preTaskCode - * @param postTaskCode postTaskCode - * @return create result code - */ - @Transactional - @Override - public Map createWorkflowTaskRelation(User loginUser, long projectCode, long workflowDefinitionCode, - long preTaskCode, long postTaskCode) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode, null); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - WorkflowDefinition workflowDefinition = workflowDefinitionMapper.queryByCode(workflowDefinitionCode); - if (workflowDefinition == null) { - log.error("workflow definition does not exist, workflowDefinitionCode:{}.", workflowDefinitionCode); - putMsg(result, Status.WORKFLOW_DEFINITION_NOT_EXIST, String.valueOf(workflowDefinitionCode)); - return result; - } - if (workflowDefinition.getProjectCode() != projectCode) { - log.error("workflow definition's project does not match project {}.", projectCode); - putMsg(result, Status.PROJECT_WORKFLOW_NOT_MATCH); - return result; - } - updateWorkflowDefiniteVersion(loginUser, result, workflowDefinition); - List workflowTaskRelationList = - workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode); - List workflowTaskRelations = Lists.newArrayList(workflowTaskRelationList); - if (!workflowTaskRelations.isEmpty()) { - Map preTaskCodeMap = - workflowTaskRelations.stream().filter(r -> r.getPostTaskCode() == postTaskCode) - .collect(Collectors.toMap(WorkflowTaskRelation::getPreTaskCode, - workflowTaskRelation -> workflowTaskRelation)); - if (!preTaskCodeMap.isEmpty()) { - if (preTaskCodeMap.containsKey(preTaskCode) || (!preTaskCodeMap.containsKey(0L) && preTaskCode == 0L)) { - putMsg(result, Status.WORKFLOW_TASK_RELATION_EXIST, String.valueOf(workflowDefinitionCode)); - return result; - } - if (preTaskCodeMap.containsKey(0L) && preTaskCode != 0L) { - // delete no upstream - workflowTaskRelations.remove(preTaskCodeMap.get(0L)); - } - } - } - TaskDefinition postTaskDefinition = taskDefinitionMapper.queryByCode(postTaskCode); - WorkflowTaskRelation workflowTaskRelation = setRelation(workflowDefinition, postTaskDefinition); - if (preTaskCode != 0L) { - TaskDefinition preTaskDefinition = taskDefinitionMapper.queryByCode(preTaskCode); - List upstreamTaskRelationList = workflowTaskRelations.stream() - .filter(r -> r.getPostTaskCode() == preTaskCode).collect(Collectors.toList()); - // upstream is or not exist - if (upstreamTaskRelationList.isEmpty()) { - WorkflowTaskRelation preWorkflowTaskRelation = setRelation(workflowDefinition, preTaskDefinition); - preWorkflowTaskRelation.setPreTaskCode(0L); - preWorkflowTaskRelation.setPreTaskVersion(0); - workflowTaskRelations.add(preWorkflowTaskRelation); - } - workflowTaskRelation.setPreTaskCode(preTaskDefinition.getCode()); - workflowTaskRelation.setPreTaskVersion(preTaskDefinition.getVersion()); - } else { - workflowTaskRelation.setPreTaskCode(0L); - workflowTaskRelation.setPreTaskVersion(0); - } - workflowTaskRelations.add(workflowTaskRelation); - updateRelation(loginUser, result, workflowDefinition, workflowTaskRelations); - return result; - } - - private WorkflowTaskRelationLog persist2WorkflowTaskRelationLog(User user, - WorkflowTaskRelation workflowTaskRelation) { - WorkflowTaskRelationLog workflowTaskRelationLog = new WorkflowTaskRelationLog(workflowTaskRelation); - workflowTaskRelationLog.setOperator(user.getId()); - workflowTaskRelationLog.setOperateTime(new Date()); - int result = workflowTaskRelationLogMapper.insert(workflowTaskRelationLog); - if (result <= 0) { - throw new ServiceException(Status.CREATE_WORKFLOW_TASK_RELATION_LOG_ERROR, - workflowTaskRelationLog.getPreTaskCode(), workflowTaskRelationLog.getPostTaskCode()); - } - return workflowTaskRelationLog; - } - - private void updateVersions(WorkflowTaskRelation workflowTaskRelation) { - // workflow - WorkflowDefinition workflowDefinition = - workflowDefinitionMapper.queryByCode(workflowTaskRelation.getWorkflowDefinitionCode()); - workflowTaskRelation.setWorkflowDefinitionVersion(workflowDefinition.getVersion()); - - // tasks - TaskDefinition preTaskDefinition = taskDefinitionMapper.queryByCode(workflowTaskRelation.getPreTaskCode()); - workflowTaskRelation.setPreTaskVersion(preTaskDefinition.getVersion()); - TaskDefinition postTaskDefinition = taskDefinitionMapper.queryByCode(workflowTaskRelation.getPostTaskCode()); - workflowTaskRelation.setPostTaskVersion(postTaskDefinition.getVersion()); - } - - /** - * create resource workflow task relation - * - * @param loginUser login user - * @param taskRelationCreateRequest project code - * @return workflowTaskRelation object - */ - @Override - @Transactional - public WorkflowTaskRelation createWorkflowTaskRelationV2(User loginUser, - TaskRelationCreateRequest taskRelationCreateRequest) { - WorkflowTaskRelation workflowTaskRelation = taskRelationCreateRequest.convert2WorkflowTaskRelation(); - WorkflowDefinition workflowDefinition = - workflowDefinitionMapper.queryByCode(workflowTaskRelation.getWorkflowDefinitionCode()); - if (workflowDefinition == null) { - throw new ServiceException(Status.WORKFLOW_DEFINITION_NOT_EXIST, - String.valueOf(workflowTaskRelation.getWorkflowDefinitionCode())); - } - if (workflowTaskRelation.getProjectCode() == 0) { - workflowTaskRelation.setProjectCode(workflowDefinition.getProjectCode()); - } - Project project = projectMapper.queryByCode(workflowTaskRelation.getProjectCode()); - projectService.checkProjectAndAuthThrowException(loginUser, project, null); - - // persistence workflow task relation and workflow task relation log to database - this.updateVersions(workflowTaskRelation); - int insert = workflowTaskRelationMapper.insert(workflowTaskRelation); - if (insert <= 0) { - throw new ServiceException(Status.CREATE_WORKFLOW_TASK_RELATION_ERROR, - workflowTaskRelation.getPreTaskCode(), - workflowTaskRelation.getPostTaskCode()); - } - this.persist2WorkflowTaskRelationLog(loginUser, workflowTaskRelation); - - return workflowTaskRelation; - } - - private WorkflowTaskRelation setRelation(WorkflowDefinition workflowDefinition, TaskDefinition taskDefinition) { - Date now = new Date(); - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setProjectCode(workflowDefinition.getProjectCode()); - workflowTaskRelation.setWorkflowDefinitionCode(workflowDefinition.getCode()); - workflowTaskRelation.setWorkflowDefinitionVersion(workflowDefinition.getVersion()); - workflowTaskRelation.setPostTaskCode(taskDefinition.getCode()); - workflowTaskRelation.setPostTaskVersion(taskDefinition.getVersion()); - workflowTaskRelation.setConditionType(ConditionType.NONE); - workflowTaskRelation.setConditionParams("{}"); - workflowTaskRelation.setCreateTime(now); - workflowTaskRelation.setUpdateTime(now); - return workflowTaskRelation; - } - - private void updateWorkflowDefiniteVersion(User loginUser, Map result, - WorkflowDefinition workflowDefinition) { - int insertVersion = - processService.saveWorkflowDefine(loginUser, workflowDefinition, Boolean.TRUE, Boolean.TRUE); - if (insertVersion <= 0) { - log.error("Update workflow definition error, projectCode:{}, workflowDefinitionCode:{}.", - workflowDefinition.getProjectCode(), workflowDefinition.getCode()); - putMsg(result, Status.UPDATE_WORKFLOW_DEFINITION_ERROR); - throw new ServiceException(Status.UPDATE_WORKFLOW_DEFINITION_ERROR); - } else - log.info( - "Update workflow definition complete, new version is {}, projectCode:{}, workflowDefinitionCode:{}.", - insertVersion, workflowDefinition.getProjectCode(), workflowDefinition.getCode()); - workflowDefinition.setVersion(insertVersion); - } - - /** - * delete workflow task relation - * - * @param loginUser login user - * @param projectCode project code - * @param workflowDefinitionCode workflow definition code - * @param taskCode the post task code - * @return delete result code - */ - @Transactional - @Override - public Map deleteTaskWorkflowRelation(User loginUser, long projectCode, long workflowDefinitionCode, - long taskCode) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode, null); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - if (taskCode == 0) { - log.error( - "delete task workflow relation error due to parameter taskCode is 0, projectCode:{}, workflowDefinitionCode:{}.", - projectCode, workflowDefinitionCode); - putMsg(result, Status.DELETE_TASK_WORKFLOW_RELATION_ERROR); - return result; - } - WorkflowDefinition workflowDefinition = workflowDefinitionMapper.queryByCode(workflowDefinitionCode); - if (workflowDefinition == null) { - log.error("workflow definition does not exist, workflowDefinitionCode:{}.", workflowDefinitionCode); - putMsg(result, Status.WORKFLOW_DEFINITION_NOT_EXIST, String.valueOf(workflowDefinitionCode)); - return result; - } - TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode); - if (null == taskDefinition) { - log.error("Task definition does not exist, taskDefinitionCode:{}.", taskCode); - putMsg(result, Status.TASK_DEFINE_NOT_EXIST, String.valueOf(taskCode)); - return result; - } - List workflowTaskRelations = - workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode); - List workflowTaskRelationList = Lists.newArrayList(workflowTaskRelations); - if (CollectionUtils.isEmpty(workflowTaskRelationList)) { - log.error("workflow task relations are empty, projectCode:{}, workflowDefinitionCode:{}.", projectCode, - workflowDefinitionCode); - putMsg(result, Status.DATA_IS_NULL, "workflowTaskRelationList"); - return result; - } - List downstreamList = Lists.newArrayList(); - for (WorkflowTaskRelation workflowTaskRelation : workflowTaskRelations) { - if (workflowTaskRelation.getPreTaskCode() == taskCode) { - downstreamList.add(workflowTaskRelation.getPostTaskCode()); - } - if (workflowTaskRelation.getPostTaskCode() == taskCode) { - workflowTaskRelationList.remove(workflowTaskRelation); - } - } - if (CollectionUtils.isNotEmpty(downstreamList)) { - String downstream = StringUtils.join(downstreamList, ","); - log.warn( - "Relation can not be deleted because task has downstream tasks:[{}], projectCode:{}, workflowDefinitionCode:{}, taskDefinitionCode:{}.", - downstream, projectCode, workflowDefinitionCode, taskCode); - putMsg(result, Status.TASK_HAS_DOWNSTREAM, downstream); - return result; - } - updateWorkflowDefiniteVersion(loginUser, result, workflowDefinition); - updateRelation(loginUser, result, workflowDefinition, workflowTaskRelationList); - if (TaskTypeUtils.isConditionTask(taskDefinition.getTaskType()) - || TaskTypeUtils.isSubWorkflowTask(taskDefinition.getTaskType()) - || TaskTypeUtils.isDependentTask(taskDefinition.getTaskType())) { - int deleteTaskDefinition = taskDefinitionMapper.deleteByCode(taskCode); - if (0 == deleteTaskDefinition) { - log.error("Delete task definition error, taskDefinitionCode:{}.", taskCode); - putMsg(result, Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); - throw new ServiceException(Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); - } else - log.info("Delete {} type task definition complete, taskDefinitionCode:{}.", - taskDefinition.getTaskType(), taskCode); - } - putMsg(result, Status.SUCCESS); - return result; - } - - /** - * delete workflow task relation, will delete exists relation preTaskCode -> postTaskCode, throw error if not exists - * - * @param loginUser login user - * @param preTaskCode relation upstream code - * @param postTaskCode relation downstream code - */ - @Override - @Transactional - public void deleteTaskWorkflowRelationV2(User loginUser, - long preTaskCode, - long postTaskCode) { - WorkflowTaskRelation workflowTaskRelation = - new TaskRelationFilterRequest(preTaskCode, postTaskCode).convert2TaskDefinition(); - - Page page = - new Page<>(new TaskRelationFilterRequest(preTaskCode, postTaskCode).getPageNo(), - new TaskRelationFilterRequest(preTaskCode, postTaskCode).getPageSize()); - IPage workflowTaskRelationIPage = - workflowTaskRelationMapper.filterWorkflowTaskRelation(page, workflowTaskRelation); - - List workflowTaskRelations = workflowTaskRelationIPage.getRecords(); - if (workflowTaskRelations.size() != 1) { - throw new ServiceException(Status.WORKFLOW_TASK_RELATION_NOT_EXPECT, 1, workflowTaskRelations.size()); - } - - WorkflowTaskRelation workflowTaskRelationDb = workflowTaskRelations.get(0); - Project project = projectMapper.queryByCode(workflowTaskRelationDb.getProjectCode()); - projectService.checkProjectAndAuthThrowException(loginUser, project, null); - workflowTaskRelationMapper.deleteById(workflowTaskRelationDb.getId()); - } - - /** - * delete workflow task relation, will delete exists relation upstream -> downstream, throw error if not exists - * - * @param loginUser login user - * @param taskCode relation upstream code - * @param needSyncDag needSyncDag - * @param taskRelationUpdateUpstreamRequest relation downstream code - */ - @Override - @Transactional - public List updateUpstreamTaskDefinitionWithSyncDag(User loginUser, - long taskCode, - Boolean needSyncDag, - TaskRelationUpdateUpstreamRequest taskRelationUpdateUpstreamRequest) { - TaskDefinition downstreamTask = taskDefinitionMapper.queryByCode(taskCode); - if (downstreamTask == null) { - throw new ServiceException(Status.TASK_DEFINE_NOT_EXIST, taskCode); - } - List upstreamTaskCodes = taskRelationUpdateUpstreamRequest.getUpstreams(); - - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setPostTaskCode(taskCode); - - Page page = new Page<>(taskRelationUpdateUpstreamRequest.getPageNo(), - taskRelationUpdateUpstreamRequest.getPageSize()); - IPage workflowTaskRelationExistsIPage = - workflowTaskRelationMapper.filterWorkflowTaskRelation(page, workflowTaskRelation); - List workflowTaskRelationExists = workflowTaskRelationExistsIPage.getRecords(); - - WorkflowDefinition workflowDefinition = null; - if (CollectionUtils.isNotEmpty(workflowTaskRelationExists)) { - workflowDefinition = - workflowDefinitionMapper.queryByCode(workflowTaskRelationExists.get(0).getWorkflowDefinitionCode()); - } else if (taskRelationUpdateUpstreamRequest.getWorkflowCode() != 0L) { - workflowDefinition = - workflowDefinitionMapper.queryByCode(taskRelationUpdateUpstreamRequest.getWorkflowCode()); - } - if (workflowDefinition == null) { - throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, - taskRelationUpdateUpstreamRequest.toString()); - } - workflowDefinition.setUpdateTime(new Date()); - int insertVersion = workflowDefinition.getVersion(); - if (needSyncDag) { - insertVersion = - this.saveWorkflowDefinition(loginUser, workflowDefinition); - if (insertVersion <= 0) { - throw new ServiceException(Status.UPDATE_WORKFLOW_DEFINITION_ERROR); - } - } - // get new relation to create and out of date relation to delete - List taskCodeCreates = upstreamTaskCodes - .stream() - .filter(upstreamTaskCode -> workflowTaskRelationExists.stream().noneMatch( - workflowTaskRelation1 -> workflowTaskRelation1.getPreTaskCode() == upstreamTaskCode)) - .collect(Collectors.toList()); - List taskCodeDeletes = workflowTaskRelationExists.stream() - .filter(ptr -> !upstreamTaskCodes.contains(ptr.getPreTaskCode())) - .map(WorkflowTaskRelation::getId) - .collect(Collectors.toList()); - - // delete relation not exists - if (CollectionUtils.isNotEmpty(taskCodeDeletes)) { - int delete = workflowTaskRelationMapper.deleteBatchIds(taskCodeDeletes); - if (delete != taskCodeDeletes.size()) { - throw new ServiceException(Status.WORKFLOW_TASK_RELATION_BATCH_DELETE_ERROR, taskCodeDeletes); - } - } - - // create relation not exists - List workflowTaskRelations = new ArrayList<>(); - for (long createCode : taskCodeCreates) { - long upstreamCode = 0L; - int version = 0; - if (createCode != 0L) { - // 0 for DAG root, should not, it may already exists and skip to create anymore - TaskDefinition upstreamTask = taskDefinitionMapper.queryByCode(createCode); - if (upstreamTask == null) { - throw new ServiceException(Status.TASK_DEFINE_NOT_EXIST, createCode); - } - upstreamCode = upstreamTask.getCode(); - version = upstreamTask.getVersion(); - } - WorkflowTaskRelation workflowTaskRelationCreate = - new WorkflowTaskRelation(null, workflowDefinition.getVersion(), downstreamTask.getProjectCode(), - workflowDefinition.getCode(), upstreamCode, version, - downstreamTask.getCode(), downstreamTask.getVersion(), null, null); - workflowTaskRelations.add(workflowTaskRelationCreate); - } - int batchInsert = workflowTaskRelationMapper.batchInsert(workflowTaskRelations); - if (batchInsert != workflowTaskRelations.size()) { - throw new ServiceException(Status.WORKFLOW_TASK_RELATION_BATCH_CREATE_ERROR, taskCodeCreates); - } - - // batch sync to workflow task relation log - int saveTaskRelationResult = saveTaskRelation(loginUser, workflowDefinition, insertVersion); - if (saveTaskRelationResult != Constants.EXIT_CODE_SUCCESS) { - log.error( - "Save workflow task relations error, projectCode:{}, workflowDefinitionCode:{}, workflowDefinitionVersion:{}.", - workflowDefinition.getProjectCode(), workflowDefinition.getCode(), insertVersion); - throw new ServiceException(Status.CREATE_WORKFLOW_TASK_RELATION_ERROR); - } - log.info( - "Save workflow task relations complete, projectCode:{}, workflowDefinitionCode:{}, workflowDefinitionVersion:{}.", - workflowDefinition.getProjectCode(), workflowDefinition.getCode(), insertVersion); - workflowTaskRelations.get(0).setWorkflowDefinitionVersion(insertVersion); - return workflowTaskRelations; - } - - public int saveTaskRelation(User loginUser, WorkflowDefinition workflowDefinition, - int workflowDefinitionVersion) { - long projectCode = workflowDefinition.getProjectCode(); - long workflowDefinitionCode = workflowDefinition.getCode(); - List taskRelations = - workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode); - List taskRelationList = - taskRelations.stream().map(WorkflowTaskRelationLog::new).collect(Collectors.toList()); - - List taskCodeList = - taskRelations.stream().map(WorkflowTaskRelation::getPostTaskCode).collect(Collectors.toList()); - List taskDefinitions = taskDefinitionMapper.queryByCodeList(taskCodeList); - List taskDefinitionLogs = - taskDefinitions.stream().map(TaskDefinitionLog::new).collect(Collectors.toList()); - - if (taskRelationList.isEmpty()) { - return Constants.EXIT_CODE_SUCCESS; - } - Map taskDefinitionLogMap = null; - if (org.apache.commons.collections.CollectionUtils.isNotEmpty(taskDefinitionLogs)) { - taskDefinitionLogMap = taskDefinitionLogs - .stream() - .collect(Collectors.toMap(TaskDefinition::getCode, taskDefinitionLog -> taskDefinitionLog)); - } - Date now = new Date(); - for (WorkflowTaskRelationLog workflowTaskRelationLog : taskRelationList) { - workflowTaskRelationLog.setProjectCode(projectCode); - workflowTaskRelationLog.setWorkflowDefinitionCode(workflowDefinitionCode); - workflowTaskRelationLog.setWorkflowDefinitionVersion(workflowDefinitionVersion); - if (taskDefinitionLogMap != null) { - TaskDefinitionLog preTaskDefinitionLog = - taskDefinitionLogMap.get(workflowTaskRelationLog.getPreTaskCode()); - if (preTaskDefinitionLog != null) { - workflowTaskRelationLog.setPreTaskVersion(preTaskDefinitionLog.getVersion()); - } - TaskDefinitionLog postTaskDefinitionLog = - taskDefinitionLogMap.get(workflowTaskRelationLog.getPostTaskCode()); - if (postTaskDefinitionLog != null) { - workflowTaskRelationLog.setPostTaskVersion(postTaskDefinitionLog.getVersion()); - } - } - workflowTaskRelationLog.setCreateTime(now); - workflowTaskRelationLog.setUpdateTime(now); - workflowTaskRelationLog.setOperator(loginUser.getId()); - workflowTaskRelationLog.setOperateTime(now); - } - if (CollectionUtils.isNotEmpty(taskRelations)) { - Set workflowTaskRelationSet = - taskRelations.stream().map(WorkflowTaskRelation::hashCode).collect(toSet()); - Set taskRelationSet = - taskRelationList.stream().map(WorkflowTaskRelationLog::hashCode).collect(toSet()); - boolean isSame = org.apache.commons.collections.CollectionUtils.isEqualCollection(workflowTaskRelationSet, - taskRelationSet); - if (isSame) { - return Constants.EXIT_CODE_SUCCESS; - } - workflowTaskRelationMapper.deleteByWorkflowDefinitionCode(projectCode, workflowDefinitionCode); - } - List workflowTaskRelations = - taskRelationList.stream().map(WorkflowTaskRelation::new).collect(Collectors.toList()); - int insert = workflowTaskRelationMapper.batchInsert(workflowTaskRelations); - int resultLog = workflowTaskRelationLogMapper.batchInsert(taskRelationList); - return (insert & resultLog) > 0 ? Constants.EXIT_CODE_SUCCESS : Constants.EXIT_CODE_FAILURE; - } - - public int saveWorkflowDefinition(User loginUser, WorkflowDefinition workflowDefinition) { - WorkflowDefinitionLog workflowDefinitionLog = new WorkflowDefinitionLog(workflowDefinition); - Integer version = workflowDefinitionLogMapper.queryMaxVersionForDefinition(workflowDefinition.getCode()); - int insertVersion = version == null || version == 0 ? Constants.VERSION_FIRST : version + 1; - workflowDefinitionLog.setVersion(insertVersion); - workflowDefinitionLog.setOperator(loginUser.getId()); - workflowDefinitionLog.setOperateTime(workflowDefinition.getUpdateTime()); - workflowDefinitionLog.setId(null); - int insertLog = workflowDefinitionLogMapper.insert(workflowDefinitionLog); - - workflowDefinitionLog.setId(workflowDefinition.getId()); - int result = workflowDefinitionMapper.updateById(workflowDefinitionLog); - return (insertLog & result) > 0 ? insertVersion : 0; - } - - private void updateRelation(User loginUser, Map result, WorkflowDefinition workflowDefinition, - List workflowTaskRelationList) { - List relationLogs = - workflowTaskRelationList.stream().map(WorkflowTaskRelationLog::new).collect(Collectors.toList()); - int insertResult = processService.saveTaskRelation(loginUser, workflowDefinition.getProjectCode(), - workflowDefinition.getCode(), - workflowDefinition.getVersion(), relationLogs, Lists.newArrayList(), Boolean.TRUE); - if (insertResult == Constants.EXIT_CODE_SUCCESS) { - log.info( - "Update task relations complete, projectCode:{}, workflowDefinitionCode:{}, workflowDefinitionVersion:{}.", - workflowDefinition.getProjectCode(), workflowDefinition.getCode(), workflowDefinition.getVersion()); - putMsg(result, Status.SUCCESS); - result.put(Constants.DATA_LIST, workflowDefinition); - } else { - log.error( - "Update task relations error, projectCode:{}, workflowDefinitionCode:{}, workflowDefinitionVersion:{}.", - workflowDefinition.getProjectCode(), workflowDefinition.getCode(), workflowDefinition.getVersion()); - putMsg(result, Status.UPDATE_WORKFLOW_DEFINITION_ERROR); - throw new ServiceException(Status.UPDATE_WORKFLOW_DEFINITION_ERROR); - } - } - - /** - * delete task upstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param preTaskCodes the pre task codes, sep ',' - * @param taskCode the post task code - * @return delete result code - */ - @Transactional - @Override - public Map deleteUpstreamRelation(User loginUser, long projectCode, String preTaskCodes, - long taskCode) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode, null); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - if (StringUtils.isEmpty(preTaskCodes)) { - log.warn("Parameter preTaskCodes is empty."); - putMsg(result, Status.DATA_IS_NULL, "preTaskCodes"); - return result; - } - List upstreamList = workflowTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); - if (CollectionUtils.isEmpty(upstreamList)) { - log.error("Upstream tasks based on the task do not exist, theTaskDefinitionCode:{}.", taskCode); - putMsg(result, Status.DATA_IS_NULL, "taskCode"); - return result; - } - - List preTaskCodeList = Lists.newArrayList(preTaskCodes.split(Constants.COMMA)).stream() - .map(Long::parseLong).collect(Collectors.toList()); - if (preTaskCodeList.contains(0L)) { - log.warn("Parameter preTaskCodes contain 0."); - putMsg(result, Status.DATA_IS_NULL, "preTaskCodes"); - return result; - } - List currentUpstreamList = - upstreamList.stream().map(WorkflowTaskRelation::getPreTaskCode).collect(Collectors.toList()); - if (currentUpstreamList.contains(0L)) { - log.error("Upstream taskCodes based on the task contain, theTaskDefinitionCode:{}.", taskCode); - putMsg(result, Status.DATA_IS_NOT_VALID, "currentUpstreamList"); - return result; - } - List tmpCurrent = Lists.newArrayList(currentUpstreamList); - tmpCurrent.removeAll(preTaskCodeList); - preTaskCodeList.removeAll(currentUpstreamList); - if (!preTaskCodeList.isEmpty()) { - String invalidPreTaskCodes = StringUtils.join(preTaskCodeList, Constants.COMMA); - log.error("Some upstream taskCodes are invalid, preTaskCodeList:{}.", invalidPreTaskCodes); - putMsg(result, Status.DATA_IS_NOT_VALID, invalidPreTaskCodes); - return result; - } - WorkflowDefinition workflowDefinition = - workflowDefinitionMapper.queryByCode(upstreamList.get(0).getWorkflowDefinitionCode()); - if (workflowDefinition == null) { - log.error("workflow definition does not exist, workflowDefinitionCode:{}.", - upstreamList.get(0).getWorkflowDefinitionCode()); - putMsg(result, Status.WORKFLOW_DEFINITION_NOT_EXIST, - String.valueOf(upstreamList.get(0).getWorkflowDefinitionCode())); - return result; - } - List workflowTaskRelations = - workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinition.getCode()); - List workflowTaskRelationList = Lists.newArrayList(workflowTaskRelations); - List workflowTaskRelationWaitRemove = Lists.newArrayList(); - for (WorkflowTaskRelation workflowTaskRelation : workflowTaskRelationList) { - if (currentUpstreamList.size() > 1) { - if (currentUpstreamList.contains(workflowTaskRelation.getPreTaskCode())) { - currentUpstreamList.remove(workflowTaskRelation.getPreTaskCode()); - workflowTaskRelationWaitRemove.add(workflowTaskRelation); - } - } else { - if (workflowTaskRelation.getPostTaskCode() == taskCode - && (currentUpstreamList.isEmpty() || tmpCurrent.isEmpty())) { - workflowTaskRelation.setPreTaskVersion(0); - workflowTaskRelation.setPreTaskCode(0L); - } - } - } - workflowTaskRelationList.removeAll(workflowTaskRelationWaitRemove); - updateWorkflowDefiniteVersion(loginUser, result, workflowDefinition); - updateRelation(loginUser, result, workflowDefinition, workflowTaskRelationList); - return result; - } - - /** - * delete task downstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param postTaskCodes the post task codes, sep ',' - * @param taskCode the pre task code - * @return delete result code - */ - @Transactional - @Override - public Map deleteDownstreamRelation(User loginUser, long projectCode, String postTaskCodes, - long taskCode) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode, null); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - if (StringUtils.isEmpty(postTaskCodes)) { - log.warn("Parameter postTaskCodes is empty."); - putMsg(result, Status.DATA_IS_NULL, "postTaskCodes"); - return result; - } - List downstreamList = - workflowTaskRelationMapper.queryDownstreamByCode(projectCode, taskCode); - if (CollectionUtils.isEmpty(downstreamList)) { - log.error("Downstream tasks based on the task do not exist, theTaskDefinitionCode:{}.", taskCode); - putMsg(result, Status.DATA_IS_NULL, "taskCode"); - return result; - } - List postTaskCodeList = Lists.newArrayList(postTaskCodes.split(Constants.COMMA)).stream() - .map(Long::parseLong).collect(Collectors.toList()); - if (postTaskCodeList.contains(0L)) { - log.warn("Parameter postTaskCodes contains 0."); - putMsg(result, Status.DATA_IS_NULL, "postTaskCodes"); - return result; - } - WorkflowDefinition workflowDefinition = - workflowDefinitionMapper.queryByCode(downstreamList.get(0).getWorkflowDefinitionCode()); - if (workflowDefinition == null) { - log.error("workflow definition does not exist, workflowDefinitionCode:{}.", - downstreamList.get(0).getWorkflowDefinitionCode()); - putMsg(result, Status.WORKFLOW_DEFINITION_NOT_EXIST, - String.valueOf(downstreamList.get(0).getWorkflowDefinitionCode())); - return result; - } - List workflowTaskRelations = - workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinition.getCode()); - List workflowTaskRelationList = Lists.newArrayList(workflowTaskRelations); - workflowTaskRelationList - .removeIf(workflowTaskRelation -> postTaskCodeList.contains(workflowTaskRelation.getPostTaskCode()) - && workflowTaskRelation.getPreTaskCode() == taskCode); - updateWorkflowDefiniteVersion(loginUser, result, workflowDefinition); - updateRelation(loginUser, result, workflowDefinition, workflowTaskRelationList); - return result; - } - - /** - * query task upstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param taskCode current task code (post task code) - * @return the upstream task definitions - */ - @Override - public Map queryUpstreamRelation(User loginUser, long projectCode, long taskCode) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode, null); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - List workflowTaskRelationList = - workflowTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); - List taskDefinitionLogList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(workflowTaskRelationList)) { - Set taskDefinitions = workflowTaskRelationList - .stream() - .map(workflowTaskRelation -> { - TaskDefinition taskDefinition = buildTaskDefinition(); - taskDefinition.setProjectCode(workflowTaskRelation.getProjectCode()); - taskDefinition.setCode(workflowTaskRelation.getPreTaskCode()); - taskDefinition.setVersion(workflowTaskRelation.getPreTaskVersion()); - return taskDefinition; - }) - .collect(Collectors.toSet()); - taskDefinitionLogList = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions); - } - result.put(Constants.DATA_LIST, taskDefinitionLogList); - putMsg(result, Status.SUCCESS); - return result; - } - - /** - * query task downstream relation - * - * @param loginUser login user - * @param projectCode project code - * @param taskCode pre task code - * @return the downstream task definitions - */ - @Override - public Map queryDownstreamRelation(User loginUser, long projectCode, long taskCode) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode, null); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - List workflowTaskRelationList = - workflowTaskRelationMapper.queryDownstreamByCode(projectCode, taskCode); - List taskDefinitionLogList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(workflowTaskRelationList)) { - Set taskDefinitions = workflowTaskRelationList - .stream() - .map(workflowTaskRelation -> { - TaskDefinition taskDefinition = buildTaskDefinition(); - taskDefinition.setProjectCode(workflowTaskRelation.getProjectCode()); - taskDefinition.setCode(workflowTaskRelation.getPostTaskCode()); - taskDefinition.setVersion(workflowTaskRelation.getPostTaskVersion()); - return taskDefinition; - }) - .collect(Collectors.toSet()); - taskDefinitionLogList = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions); - } - result.put(Constants.DATA_LIST, taskDefinitionLogList); - putMsg(result, Status.SUCCESS); - return result; - } - - /** - * delete edge - * - * @param loginUser login user - * @param projectCode project code - * @param workflowDefinitionCode workflow definition code - * @param preTaskCode pre task code - * @param postTaskCode post task code - * @return delete result code - */ - @Transactional - @Override - public Map deleteEdge(User loginUser, long projectCode, long workflowDefinitionCode, - long preTaskCode, long postTaskCode) { - Project project = projectMapper.queryByCode(projectCode); - // check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode, null); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - WorkflowDefinition workflowDefinition = workflowDefinitionMapper.queryByCode(workflowDefinitionCode); - if (workflowDefinition == null) { - log.error("workflow definition does not exist, projectCode:{}, workflowDefinitionCode:{}.", projectCode, - workflowDefinitionCode); - putMsg(result, Status.WORKFLOW_DEFINITION_NOT_EXIST, String.valueOf(workflowDefinitionCode)); - return result; - } - List workflowTaskRelations = - workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode); - List workflowTaskRelationList = Lists.newArrayList(workflowTaskRelations); - if (CollectionUtils.isEmpty(workflowTaskRelationList)) { - log.error("workflow task relations are empty, projectCode:{}, workflowDefinitionCode:{}.", projectCode, - workflowDefinitionCode); - putMsg(result, Status.DATA_IS_NULL, "workflowTaskRelationList"); - return result; - } - Map> taskRelationMap = new HashMap<>(); - for (WorkflowTaskRelation workflowTaskRelation : workflowTaskRelationList) { - taskRelationMap.compute(workflowTaskRelation.getPostTaskCode(), (k, v) -> { - if (v == null) { - v = new ArrayList<>(); - } - v.add(workflowTaskRelation); - return v; - }); - } - if (!taskRelationMap.containsKey(postTaskCode)) { - putMsg(result, Status.DATA_IS_NULL, "postTaskCode"); - return result; - } - if (taskRelationMap.get(postTaskCode).size() > 1) { - for (WorkflowTaskRelation workflowTaskRelation : taskRelationMap.get(postTaskCode)) { - if (workflowTaskRelation.getPreTaskCode() == preTaskCode) { - int delete = workflowTaskRelationMapper.deleteById(workflowTaskRelation.getId()); - if (delete == 0) { - log.error( - "Delete task relation edge error, workflowTaskRelationId:{}, preTaskCode:{}, postTaskCode:{}", - workflowTaskRelation.getId(), preTaskCode, postTaskCode); - putMsg(result, Status.DELETE_EDGE_ERROR); - throw new ServiceException(Status.DELETE_EDGE_ERROR); - } else - log.info( - "Delete task relation edge complete, workflowTaskRelationId:{}, preTaskCode:{}, postTaskCode:{}", - workflowTaskRelation.getId(), preTaskCode, postTaskCode); - workflowTaskRelationList.remove(workflowTaskRelation); - } - } - } else { - WorkflowTaskRelation workflowTaskRelation = taskRelationMap.get(postTaskCode).get(0); - workflowTaskRelationList.remove(workflowTaskRelation); - workflowTaskRelation.setPreTaskVersion(0); - workflowTaskRelation.setPreTaskCode(0L); - workflowTaskRelationList.add(workflowTaskRelation); - log.info( - "Delete task relation through set invalid value for it: preTaskCode from {} to 0, workflowTaskRelationId:{}.", - preTaskCode, workflowTaskRelation.getId()); - } - updateWorkflowDefiniteVersion(loginUser, result, workflowDefinition); - updateRelation(loginUser, result, workflowDefinition, workflowTaskRelationList); - return result; - } - @Override public List queryByWorkflowDefinitionCode(long workflowDefinitionCode, int workflowDefinitionVersion) { @@ -907,33 +48,4 @@ public void deleteByWorkflowDefinitionCode(long workflowDefinitionCode, int work workflowDefinitionVersion); } - /** - * build task definition - * - * @return task definition - */ - private TaskDefinition buildTaskDefinition() { - - return new TaskDefinition() { - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof TaskDefinition)) { - return false; - } - TaskDefinition that = (TaskDefinition) o; - return getCode() == that.getCode() - && getVersion() == that.getVersion() - && getProjectCode() == that.getProjectCode(); - } - - @Override - public int hashCode() { - return Objects.hash(getCode(), getVersion(), getProjectCode()); - } - }; - } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FileUtils.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FileUtils.java deleted file mode 100644 index ac35663ab0c3..000000000000 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FileUtils.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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. - */ - -package org.apache.dolphinscheduler.api.utils; - -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; - -import lombok.extern.slf4j.Slf4j; - -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.web.multipart.MultipartFile; - -/** - * file utils - */ -@Slf4j -public class FileUtils { - - /** - * copy source InputStream to target file - * @param file - * @param destFilename - */ - public static void copyInputStreamToFile(MultipartFile file, String destFilename) { - try { - org.apache.commons.io.FileUtils.copyInputStreamToFile(file.getInputStream(), new File(destFilename)); - } catch (IOException e) { - log.error("failed to copy file , {} is empty file", file.getOriginalFilename(), e); - } - } - - /** - * file to resource - * - * @param filename file name - * @return resource - * @throws MalformedURLException io exceptions - */ - public static Resource file2Resource(String filename) throws MalformedURLException { - Path file = Paths.get(filename); - - Resource resource = new UrlResource(file.toUri()); - if (resource.exists() || resource.isReadable()) { - return resource; - } else { - log.error("File can not be read, fileName:{}", filename); - } - return null; - } - - /** - * file convert String - * @param file MultipartFile file - * @return file content string - */ - public static String file2String(MultipartFile file) { - try (InputStream inputStream = file.getInputStream()) { - return IOUtils.toString(inputStream, StandardCharsets.UTF_8); - } catch (IOException e) { - log.error("file convert to string failed: {}", file.getName()); - } - - return ""; - } -} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/Result.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/Result.java index 90273e5bb426..d83ce0771b23 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/Result.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/Result.java @@ -146,7 +146,4 @@ public String toString() { + '}'; } - public Boolean checkResult() { - return this.code == Status.SUCCESS.getCode(); - } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/workflow/BackfillWorkflowRequestTransformer.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/workflow/BackfillWorkflowRequestTransformer.java index b9f0b36316a1..8fea31a95385 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/workflow/BackfillWorkflowRequestTransformer.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/workflow/BackfillWorkflowRequestTransformer.java @@ -25,7 +25,6 @@ import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; -import org.apache.dolphinscheduler.dao.repository.ProjectDao; import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionDao; import org.apache.dolphinscheduler.plugin.task.api.utils.PropertyUtils; import org.apache.dolphinscheduler.service.cron.CronUtils; @@ -49,9 +48,6 @@ public class BackfillWorkflowRequestTransformer implements ITransformer workflowTaskRelationList; - public TaskDefinitionVO() { - } - - public TaskDefinitionVO(List workflowTaskRelationList) { - this.workflowTaskRelationList = workflowTaskRelationList; - } - public static TaskDefinitionVO fromTaskDefinition(TaskDefinition taskDefinition) { TaskDefinitionVO taskDefinitionVo = new TaskDefinitionVO(); BeanUtils.copyProperties(taskDefinition, taskDefinitionVo); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java index cf1fcb0a62ef..99acaab58064 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java @@ -67,7 +67,6 @@ public class AlertGroupServiceTest { private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); - private static final Logger logger = LoggerFactory.getLogger(AlertGroupServiceTest.class); private static final Logger alertGroupServiceLogger = LoggerFactory.getLogger(AlertGroupServiceImpl.class); private String tooLongDescription = "this is a toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java index 98126e197173..c9abca643ba9 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java @@ -32,7 +32,6 @@ import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.model.Server; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; @@ -95,10 +94,6 @@ public class AlertPluginInstanceServiceTest { private User noPermUser; - private final Integer GLOBAL_ALERT_GROUP_ID = 2; - - private static final WarningType warningType = WarningType.ALL; - private String uiParams = "[\n" + " {\n" + " \"field\":\"userParams\",\n" diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AuditServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AuditServiceTest.java index 86238f05980d..e06dfc77db2d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AuditServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AuditServiceTest.java @@ -38,8 +38,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -50,8 +48,6 @@ @ExtendWith(MockitoExtension.class) public class AuditServiceTest { - private static final Logger logger = LoggerFactory.getLogger(AuditServiceTest.class); - @InjectMocks private AuditServiceImpl auditService; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseServiceTest.java index ea5988f560c4..162d82a90af7 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseServiceTest.java @@ -23,7 +23,6 @@ import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.plugin.storage.hdfs.HdfsStorageOperator; import java.util.HashMap; import java.util.Map; @@ -32,10 +31,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * base service test @@ -43,13 +39,8 @@ @ExtendWith(MockitoExtension.class) public class BaseServiceTest { - private static final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class); - private BaseServiceImpl baseService; - @Mock - private HdfsStorageOperator hdfsStorageOperator; - @BeforeEach public void setUp() { baseService = new BaseServiceImpl(); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java index 1824b509235b..6ba50e2f1390 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java @@ -35,7 +35,6 @@ import org.apache.dolphinscheduler.dao.entity.DataSource; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; -import org.apache.dolphinscheduler.dao.mapper.DataSourceUserMapper; import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO; import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor; import org.apache.dolphinscheduler.plugin.datasource.api.plugin.DataSourceClientProvider; @@ -93,9 +92,6 @@ public class DataSourceServiceTest { @Mock private DataSourceMapper dataSourceMapper; - @Mock - private DataSourceUserMapper datasourceUserMapper; - @Mock private ResourcePermissionCheckService resourcePermissionCheckService; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java index de5e48b58932..19241f1912f9 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/K8SNamespaceServiceTest.java @@ -20,7 +20,6 @@ import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException; import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.k8s.K8sClientService; import org.apache.dolphinscheduler.api.service.impl.K8SNamespaceServiceImpl; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; @@ -31,7 +30,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ClusterMapper; import org.apache.dolphinscheduler.dao.mapper.K8sNamespaceMapper; -import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.commons.collections4.CollectionUtils; @@ -67,12 +65,6 @@ public class K8SNamespaceServiceTest { @Mock private K8sNamespaceMapper k8sNamespaceMapper; - @Mock - private K8sClientService k8sClientService; - - @Mock - private UserMapper userMapper; - @Mock private ClusterMapper clusterMapper; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java index b14d31124e5c..8a6feab74ac9 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java @@ -37,7 +37,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; @@ -75,15 +74,13 @@ public class ProjectServiceTest { private static final Logger logger = LoggerFactory.getLogger(ProjectServiceTest.class); private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); private static final Logger projectLogger = LoggerFactory.getLogger(ProjectServiceImpl.class); + @InjectMocks private ProjectServiceImpl projectService; @Mock private ProjectMapper projectMapper; - @Mock - private ProjectUserMapper projectUserMapper; - @Mock private WorkflowDefinitionMapper workflowDefinitionMapper; @@ -93,9 +90,6 @@ public class ProjectServiceTest { @Mock private ResourcePermissionCheckService resourcePermissionCheckService; - @Mock - private TaskGroupService taskGroupService; - private String projectName = "ProjectServiceTest"; private String userName = "ProjectServiceTest"; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java index 71af5364226f..33b487340ce6 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java @@ -25,11 +25,9 @@ import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; -import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; -import org.apache.dolphinscheduler.scheduler.api.SchedulerApi; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -64,15 +62,6 @@ public class SchedulerServiceTest extends BaseServiceTestTool { @Mock private ProjectService projectService; - @Mock - private SchedulerApi schedulerApi; - - @Mock - private ExecutorService executorService; - - @Mock - private EnvironmentMapper environmentMapper; - protected static User user; protected Exception exception; private static final String userName = "userName"; @@ -84,9 +73,6 @@ public class SchedulerServiceTest extends BaseServiceTestTool { private static final int processDefinitionVersion = 3; private static final int scheduleId = 3; private static final long environmentCode = 4L; - private static final String startTime = "2020-01-01 12:13:14"; - private static final String endTime = "2020-02-01 12:13:14"; - private static final String crontab = "0 0 * * * ? *"; @BeforeEach public void setUp() { diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SessionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SessionServiceTest.java index cb82554f2bcc..97626ae87717 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SessionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SessionServiceTest.java @@ -38,8 +38,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * session service test @@ -47,8 +45,6 @@ @ExtendWith(MockitoExtension.class) public class SessionServiceTest { - private static final Logger logger = LoggerFactory.getLogger(SessionServiceTest.class); - @InjectMocks private SessionServiceImpl sessionService; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionLogServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionLogServiceTest.java index 0e6263294da8..d1bb66918fee 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionLogServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionLogServiceTest.java @@ -22,8 +22,6 @@ import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionLogServiceImpl; import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelationLog; -import org.apache.dolphinscheduler.dao.mapper.WorkflowTaskRelationLogMapper; -import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao; import org.apache.dolphinscheduler.dao.repository.WorkflowTaskRelationLogDao; import java.util.Arrays; @@ -48,11 +46,6 @@ public class TaskDefinitionLogServiceTest { @Mock private WorkflowTaskRelationLogDao workflowTaskRelationLogDao; - @Mock - private TaskDefinitionLogDao taskDefinitionLogDao; - @Mock - private WorkflowTaskRelationLogMapper workflowTaskRelationLogMapper; - private List getProcessTaskRelationList() { WorkflowTaskRelationLog processTaskRelationLog1 = new WorkflowTaskRelationLog(); processTaskRelationLog1.setPreTaskCode(0L); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java index d3c6cdb54171..00dc2650f2d2 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java @@ -108,15 +108,9 @@ public class TaskDefinitionServiceImplTest { @Mock private WorkflowTaskRelationMapper workflowTaskRelationMapper; - @Mock - private WorkflowTaskRelationService workflowTaskRelationService; - @Mock private WorkflowDefinitionMapper workflowDefinitionMapper; - @Mock - private WorkflowDefinitionService workflowDefinitionService; - @Mock private WorkflowTaskRelationLogDao workflowTaskRelationLogDao; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskGroupServiceTest.java index 22de6c675ace..91c45e93ebcb 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskGroupServiceTest.java @@ -32,9 +32,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.TaskGroupMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskGroupQueueMapper; -import org.apache.dolphinscheduler.dao.mapper.UserMapper; -import org.apache.dolphinscheduler.service.process.ProcessService; import java.util.ArrayList; import java.util.List; @@ -67,21 +64,9 @@ public class TaskGroupServiceTest { @InjectMocks private TaskGroupServiceImpl taskGroupService; - @Mock - private TaskGroupQueueService taskGroupQueueService; - - @Mock - private ProcessService processService; - @Mock private TaskGroupMapper taskGroupMapper; - @Mock - private TaskGroupQueueMapper taskGroupQueueMapper; - - @Mock - private UserMapper userMapper; - @Mock private ProjectMapper projectMapper; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java index 5a8dabaaae04..9663b065d17d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java @@ -41,7 +41,6 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; @@ -93,11 +92,9 @@ public class TaskInstanceServiceTest { @Mock UsersService usersService; - @Mock - TaskDefinitionMapper taskDefinitionMapper; - @Mock TaskInstanceDao taskInstanceDao; + @Mock WorkflowInstanceDao workflowInstanceDao; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java index 58a36c6348c6..57746b3040a0 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java @@ -42,7 +42,6 @@ import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; -import org.apache.dolphinscheduler.plugin.storage.api.StorageOperator; import org.apache.commons.collections4.CollectionUtils; @@ -95,9 +94,6 @@ public class TenantServiceTest { @Mock private ResourcePermissionCheckService resourcePermissionCheckService; - @Mock - private StorageOperator storageOperator; - private static final String tenantCode = "hayden"; private static final String tenantDesc = "This is the tenant desc"; private static final String queue = "queue"; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java index 12882e689329..26b66a670a73 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java @@ -38,15 +38,12 @@ import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.AccessTokenMapper; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.DataSourceUserMapper; import org.apache.dolphinscheduler.dao.mapper.K8sNamespaceUserMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; -import org.apache.dolphinscheduler.plugin.storage.api.StorageOperator; import org.apache.commons.collections4.CollectionUtils; @@ -85,9 +82,6 @@ public class UsersServiceTest { @Mock private UserMapper userMapper; - @Mock - private AccessTokenMapper accessTokenMapper; - @Mock private TenantMapper tenantMapper; @@ -97,24 +91,15 @@ public class UsersServiceTest { @Mock private DataSourceUserMapper datasourceUserMapper; - @Mock - private ProjectUserMapper projectUserMapper; - @Mock private K8sNamespaceUserMapper k8sNamespaceUserMapper; @Mock private ProjectMapper projectMapper; - @Mock - private StorageOperator storageOperator; - @Mock private ResourcePermissionCheckService resourcePermissionCheckService; - @Mock - private SessionService sessionService; - private String queueName = "UsersServiceTestQueue"; private static final Logger serviceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java index f8c59bf7b321..e29860855d51 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java @@ -40,7 +40,6 @@ import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; import org.apache.dolphinscheduler.api.service.impl.WorkflowDefinitionServiceImpl; import org.apache.dolphinscheduler.api.utils.PageInfo; -import org.apache.dolphinscheduler.api.validator.GlobalParamsValidator; import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.Priority; @@ -60,19 +59,14 @@ import org.apache.dolphinscheduler.dao.entity.UserWithWorkflowDefinitionCode; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelation; -import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowTaskRelationMapper; import org.apache.dolphinscheduler.dao.model.PageListingResult; import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao; import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionDao; -import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionLogDao; import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils; import org.apache.dolphinscheduler.plugin.task.api.model.ConditionDependentItem; import org.apache.dolphinscheduler.plugin.task.api.model.ConditionDependentTaskModel; @@ -143,12 +137,6 @@ public class WorkflowDefinitionServiceTest extends BaseServiceTestTool { @Mock private WorkflowDefinitionMapper workflowDefinitionMapper; - @Mock - private TaskDefinitionMapper taskDefinitionMapper; - - @Mock - private WorkflowDefinitionLogMapper workflowDefinitionLogMapper; - @Mock private WorkflowDefinitionDao workflowDefinitionDao; @@ -173,33 +161,12 @@ public class WorkflowDefinitionServiceTest extends BaseServiceTestTool { @Mock private TaskDefinitionLogDao taskDefinitionLogDao; - @Mock - private WorkflowInstanceService workflowInstanceService; - - @Mock - private DataSourceMapper dataSourceMapper; - @Mock private WorkflowLineageService workflowLineageService; - @Mock - private TaskDefinitionService taskDefinitionService; - - @Mock - private TaskDefinitionLogService taskDefinitionLogService; - - @Mock - private WorkflowDefinitionLogDao workflowDefinitionLogDao; - - @Mock - private TaskDefinitionLogMapper taskDefinitionLogMapper; - @Mock private UserMapper userMapper; - @Mock - private GlobalParamsValidator globalParamsValidator; - protected User user; protected Exception exception; protected final static long projectCode = 1L; @@ -207,10 +174,7 @@ public class WorkflowDefinitionServiceTest extends BaseServiceTestTool { protected final static long processDefinitionCode = 11L; protected final static String name = "testProcessDefinitionName"; protected final static String description = "this is a description"; - protected final static String releaseState = "ONLINE"; - protected final static int warningGroupId = 1; protected final static int timeout = 60; - protected final static String executionType = "PARALLEL"; @BeforeEach public void before() { diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java index 592231fffc57..790a23955b28 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java @@ -42,7 +42,6 @@ import org.apache.dolphinscheduler.common.model.TaskNodeRelation; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; -import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.entity.DependentResultTaskInstanceContext; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; @@ -56,9 +55,7 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowDefinitionLog; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; @@ -66,7 +63,6 @@ import org.apache.dolphinscheduler.dao.repository.TaskInstanceContextDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; -import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceMapDao; import org.apache.dolphinscheduler.extract.master.command.RunWorkflowCommandParam; import org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager; import org.apache.dolphinscheduler.plugin.task.api.enums.DataType; @@ -74,7 +70,6 @@ import org.apache.dolphinscheduler.plugin.task.api.enums.Direct; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.dolphinscheduler.plugin.task.api.model.Property; -import org.apache.dolphinscheduler.service.expand.CuringParamsService; import org.apache.dolphinscheduler.service.model.TaskNode; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -135,9 +130,6 @@ public class WorkflowInstanceServiceTest { @Mock WorkflowDefinitionService workflowDefinitionService; - @Mock - TaskInstanceMapper taskInstanceMapper; - @Mock LoggerServiceImpl loggerService; @@ -146,23 +138,9 @@ public class WorkflowInstanceServiceTest { @Mock TenantMapper tenantMapper; - @Mock - TaskDefinitionMapper taskDefinitionMapper; @Mock - ScheduleMapper scheduleMapper; - - @Mock - CuringParamsService curingGlobalParamsService; - - @Mock - AlertDao alertDao; - - @Mock - private TaskInstanceService taskInstanceService; - - @Mock - private WorkflowInstanceMapDao workflowInstanceMapDao; + TaskDefinitionMapper taskDefinitionMapper; @Mock private TaskInstanceContextDao taskInstanceContextDao; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskLineageServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskLineageServiceTest.java index c8be7bba6935..78a18d94bc9b 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskLineageServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskLineageServiceTest.java @@ -33,7 +33,6 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; import org.apache.dolphinscheduler.dao.entity.WorkflowTaskLineage; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; import org.apache.dolphinscheduler.dao.repository.WorkflowTaskLineageDao; @@ -64,9 +63,6 @@ public class WorkflowTaskLineageServiceTest { @Mock private ProjectMapper projectMapper; - @Mock - private TaskDefinitionLogMapper taskDefinitionLogMapper; - @Mock private TaskDefinitionMapper taskDefinitionMapper; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationServiceTest.java deleted file mode 100644 index fc6ed64aa185..000000000000 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowTaskRelationServiceTest.java +++ /dev/null @@ -1,622 +0,0 @@ -/* - * 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. - */ - -package org.apache.dolphinscheduler.api.service; - -import static org.mockito.ArgumentMatchers.isA; - -import org.apache.dolphinscheduler.api.dto.taskRelation.TaskRelationCreateRequest; -import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.exceptions.ServiceException; -import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; -import org.apache.dolphinscheduler.api.service.impl.WorkflowTaskRelationServiceImpl; -import org.apache.dolphinscheduler.common.constants.Constants; -import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.TaskDefinition; -import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; -import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelation; -import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelationLog; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; -import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowTaskRelationLogMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowTaskRelationMapper; -import org.apache.dolphinscheduler.service.process.ProcessService; - -import org.apache.commons.collections4.CollectionUtils; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.junit.jupiter.MockitoSettings; -import org.mockito.quality.Strictness; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.google.common.collect.Lists; - -@ExtendWith(MockitoExtension.class) -@MockitoSettings(strictness = Strictness.LENIENT) -public class WorkflowTaskRelationServiceTest { - - @InjectMocks - WorkflowTaskRelationServiceImpl workflowTaskRelationService; - - @Mock - private ProjectMapper projectMapper; - - @Mock - private ProjectServiceImpl projectService; - - @Mock - private WorkflowTaskRelationMapper workflowTaskRelationMapper; - - @Mock - private TaskDefinitionLogMapper taskDefinitionLogMapper; - - @Mock - private WorkflowDefinitionMapper workflowDefinitionMapper; - - @Mock - private TaskDefinitionMapper taskDefinitionMapper; - - @Mock - private WorkflowTaskRelationLogMapper workflowTaskRelationLogMapper; - - @Mock - private ProcessService processService; - - private static final long PROJECT_CODE = 1L; - private static final long WORKFLOW_DEFINITION_CODE = 2L; - private static final long UPSTREAM_TASK_CODE = 3L; - private static final long DOWNSTREAM_TASK_CODE = 4L; - protected User user; - protected Exception exception; - - @BeforeEach - public void before() { - User loginUser = new User(); - loginUser.setId(1); - loginUser.setTenantId(2); - loginUser.setUserType(UserType.GENERAL_USER); - loginUser.setUserName("admin"); - user = loginUser; - } - - /** - * get mock Project - * - * @param projectCode projectCode - * @return Project - */ - private Project getProject(long projectCode) { - Project project = new Project(); - project.setCode(projectCode); - project.setId(1); - project.setName("project_test1"); - project.setUserId(1); - return project; - } - - private void putMsg(Map result, Status status, Object... statusParams) { - result.put(Constants.STATUS, status); - if (statusParams != null && statusParams.length > 0) { - result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); - } else { - result.put(Constants.MSG, status.getMsg()); - } - } - - private TaskDefinitionLog buildTaskDefinitionLog(long projectCode, long code, int version) { - - TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog() { - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof TaskDefinitionLog)) { - return false; - } - TaskDefinitionLog that = (TaskDefinitionLog) o; - return getCode() == that.getCode() - && getVersion() == that.getVersion() - && getProjectCode() == that.getProjectCode(); - } - - @Override - public int hashCode() { - return Objects.hash(getCode(), getVersion(), getProjectCode()); - } - }; - taskDefinitionLog.setProjectCode(projectCode); - taskDefinitionLog.setCode(code); - taskDefinitionLog.setVersion(version); - return taskDefinitionLog; - } - - private TaskDefinition buildTaskDefinition(long projectCode, long code, int version) { - - TaskDefinition taskDefinition = new TaskDefinition() { - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof TaskDefinition)) { - return false; - } - TaskDefinition that = (TaskDefinition) o; - return getCode() == that.getCode() - && getVersion() == that.getVersion() - && getProjectCode() == that.getProjectCode(); - } - - @Override - public int hashCode() { - return Objects.hash(getCode(), getVersion(), getProjectCode()); - } - }; - taskDefinition.setProjectCode(projectCode); - taskDefinition.setCode(code); - taskDefinition.setVersion(version); - return taskDefinition; - } - - private List getWorkflowTaskUpstreamRelationList(long projectCode, long taskCode) { - WorkflowTaskRelation workflowTaskRelationUpstream0 = new WorkflowTaskRelation(); - workflowTaskRelationUpstream0.setPostTaskCode(taskCode); - workflowTaskRelationUpstream0.setPreTaskVersion(1); - workflowTaskRelationUpstream0.setProjectCode(projectCode); - workflowTaskRelationUpstream0.setPreTaskCode(123); - workflowTaskRelationUpstream0.setWorkflowDefinitionCode(123); - WorkflowTaskRelation workflowTaskRelationUpstream1 = new WorkflowTaskRelation(); - workflowTaskRelationUpstream1.setPostTaskCode(taskCode); - workflowTaskRelationUpstream1.setPreTaskVersion(1); - workflowTaskRelationUpstream1.setPreTaskCode(123); - workflowTaskRelationUpstream1.setWorkflowDefinitionCode(124); - workflowTaskRelationUpstream1.setProjectCode(projectCode); - WorkflowTaskRelation workflowTaskRelationUpstream2 = new WorkflowTaskRelation(); - workflowTaskRelationUpstream2.setPostTaskCode(taskCode); - workflowTaskRelationUpstream2.setPreTaskVersion(2); - workflowTaskRelationUpstream2.setPreTaskCode(123); - workflowTaskRelationUpstream2.setWorkflowDefinitionCode(125); - workflowTaskRelationUpstream2.setProjectCode(projectCode); - List workflowTaskRelationList = new ArrayList<>(); - workflowTaskRelationList.add(workflowTaskRelationUpstream0); - workflowTaskRelationList.add(workflowTaskRelationUpstream1); - workflowTaskRelationList.add(workflowTaskRelationUpstream2); - return workflowTaskRelationList; - } - - private List getWorkflowTaskDownstreamRelationList(long projectCode, long taskCode) { - WorkflowTaskRelation workflowTaskRelationDownstream0 = new WorkflowTaskRelation(); - workflowTaskRelationDownstream0.setPreTaskCode(taskCode); - workflowTaskRelationDownstream0.setPostTaskCode(456); - workflowTaskRelationDownstream0.setPostTaskVersion(1); - workflowTaskRelationDownstream0.setProjectCode(projectCode); - WorkflowTaskRelation workflowTaskRelationDownstream1 = new WorkflowTaskRelation(); - workflowTaskRelationDownstream1.setPreTaskCode(taskCode); - workflowTaskRelationDownstream1.setPostTaskCode(456); - workflowTaskRelationDownstream1.setPostTaskVersion(1); - workflowTaskRelationDownstream1.setProjectCode(projectCode); - WorkflowTaskRelation workflowTaskRelationDownstream2 = new WorkflowTaskRelation(); - workflowTaskRelationDownstream2.setPreTaskCode(taskCode); - workflowTaskRelationDownstream2.setPostTaskCode(4567); - workflowTaskRelationDownstream2.setPostTaskVersion(1); - workflowTaskRelationDownstream2.setProjectCode(projectCode); - List workflowTaskRelationList = new ArrayList<>(); - workflowTaskRelationList.add(workflowTaskRelationDownstream0); - workflowTaskRelationList.add(workflowTaskRelationDownstream1); - workflowTaskRelationList.add(workflowTaskRelationDownstream2); - return workflowTaskRelationList; - } - - private WorkflowDefinition getWorkflowDefinition() { - WorkflowDefinition workflowDefinition = new WorkflowDefinition(); - workflowDefinition.setId(1); - workflowDefinition.setProjectCode(1L); - workflowDefinition.setName("test_pdf"); - workflowDefinition.setDescription(""); - workflowDefinition.setCode(1L); - workflowDefinition.setVersion(1); - return workflowDefinition; - } - - private TaskDefinition getTaskDefinition() { - TaskDefinition taskDefinition = new TaskDefinition(); - taskDefinition.setProjectCode(1L); - taskDefinition.setCode(1L); - taskDefinition.setVersion(1); - taskDefinition.setTaskType("SHELL"); - return taskDefinition; - } - - @Test - public void testCreateWorkflowTaskRelation() { - long projectCode = 1L; - long workflowDefinitionCode = 1L; - long preTaskCode = 0L; - long postTaskCode = 1L; - - Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - Mockito.when(workflowDefinitionMapper.queryByCode(workflowDefinitionCode)).thenReturn(getWorkflowDefinition()); - Mockito.when( - workflowTaskRelationMapper.queryByCode(projectCode, workflowDefinitionCode, preTaskCode, postTaskCode)) - .thenReturn(Lists.newArrayList()); - Mockito.when(taskDefinitionMapper.queryByCode(postTaskCode)).thenReturn(getTaskDefinition()); - - List workflowTaskRelationList = Lists.newArrayList(); - List workflowTaskRelationLogList = Lists.newArrayList(); - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setProjectCode(projectCode); - workflowTaskRelation.setWorkflowDefinitionCode(workflowDefinitionCode); - workflowTaskRelation.setPreTaskCode(0L); - workflowTaskRelation.setPreTaskVersion(0); - workflowTaskRelation.setPostTaskCode(postTaskCode); - workflowTaskRelation.setPostTaskVersion(1); - workflowTaskRelationList.add(workflowTaskRelation); - workflowTaskRelationLogList.add(new WorkflowTaskRelationLog(workflowTaskRelation)); - - Mockito.when(workflowTaskRelationMapper.batchInsert(workflowTaskRelationList)).thenReturn(1); - Mockito.when(workflowTaskRelationLogMapper.batchInsert(workflowTaskRelationLogList)).thenReturn(1); - Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } - - @Test - public void testQueryDownstreamRelation() { - long projectCode = 1L; - long taskCode = 2L; - - Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - - List workflowTaskRelationList = - getWorkflowTaskDownstreamRelationList(projectCode, taskCode); - - Mockito.when(workflowTaskRelationMapper.queryDownstreamByCode(projectCode, taskCode)) - .thenReturn(workflowTaskRelationList); - - if (CollectionUtils.isNotEmpty(workflowTaskRelationList)) { - Set taskDefinitions = workflowTaskRelationList - .stream() - .map(workflowTaskRelation -> buildTaskDefinition( - workflowTaskRelation.getProjectCode(), - workflowTaskRelation.getPostTaskCode(), - workflowTaskRelation.getPostTaskVersion())) - .collect(Collectors.toSet()); - - Set taskDefinitionLogSet = workflowTaskRelationList - .stream() - .map(workflowTaskRelation -> buildTaskDefinitionLog( - workflowTaskRelation.getProjectCode(), - workflowTaskRelation.getPostTaskCode(), - workflowTaskRelation.getPostTaskVersion())) - .collect(Collectors.toSet()); - List taskDefinitionLogList = taskDefinitionLogSet.stream().collect(Collectors.toList()); - Mockito.when(taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions)) - .thenReturn(taskDefinitionLogList); - } - Map relation = workflowTaskRelationService - .queryDownstreamRelation(user, projectCode, taskCode); - Assertions.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); - Assertions.assertEquals(2, ((List) relation.get("data")).size()); - } - - @Test - public void testQueryUpstreamRelation() { - long projectCode = 1L; - long taskCode = 2L; - - Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - List workflowTaskRelationList = - getWorkflowTaskUpstreamRelationList(projectCode, taskCode); - - Mockito.when(workflowTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode)) - .thenReturn(workflowTaskRelationList); - - if (CollectionUtils.isNotEmpty(workflowTaskRelationList)) { - Set taskDefinitions = workflowTaskRelationList - .stream() - .map(workflowTaskRelation -> buildTaskDefinition( - workflowTaskRelation.getProjectCode(), - workflowTaskRelation.getPreTaskCode(), - workflowTaskRelation.getPreTaskVersion())) - .collect(Collectors.toSet()); - - Set taskDefinitionLogSet = workflowTaskRelationList - .stream() - .map(workflowTaskRelation -> buildTaskDefinitionLog( - workflowTaskRelation.getProjectCode(), - workflowTaskRelation.getPreTaskCode(), - workflowTaskRelation.getPreTaskVersion())) - .collect(Collectors.toSet()); - List taskDefinitionLogList = taskDefinitionLogSet.stream().collect(Collectors.toList()); - Mockito.when(taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions)) - .thenReturn(taskDefinitionLogList); - } - Map relation = workflowTaskRelationService - .queryUpstreamRelation(user, projectCode, taskCode); - Assertions.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); - Assertions.assertEquals(2, ((List) relation.get("data")).size()); - } - - @Test - public void testDeleteDownstreamRelation() { - long projectCode = 1L; - long taskCode = 2L; - Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - List workflowTaskRelationList = new ArrayList<>(); - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setProjectCode(projectCode); - workflowTaskRelation.setWorkflowDefinitionCode(1L); - workflowTaskRelation.setPreTaskCode(taskCode); - workflowTaskRelation.setPostTaskCode(123L); - workflowTaskRelationList.add(workflowTaskRelation); - Mockito.when(workflowTaskRelationMapper.queryDownstreamByCode(projectCode, taskCode)) - .thenReturn(workflowTaskRelationList); - WorkflowTaskRelationLog workflowTaskRelationLog = new WorkflowTaskRelationLog(workflowTaskRelation); - Mockito.when(workflowTaskRelationMapper.deleteRelation(workflowTaskRelationLog)).thenReturn(1); - Mockito.when(workflowTaskRelationLogMapper.deleteRelation(workflowTaskRelationLog)).thenReturn(1); - WorkflowDefinition workflowDefinition = getWorkflowDefinition(); - Mockito.when(workflowDefinitionMapper.queryByCode(1L)).thenReturn(workflowDefinition); - Mockito.when(processService.saveWorkflowDefine(user, workflowDefinition, Boolean.TRUE, Boolean.TRUE)) - .thenReturn(1); - Map result1 = - workflowTaskRelationService.deleteDownstreamRelation(user, projectCode, "123", taskCode); - Assertions.assertEquals(Status.SUCCESS, result1.get(Constants.STATUS)); - } - - @Test - public void testDeleteUpstreamRelation() { - long projectCode = 1L; - long taskCode = 2L; - Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectCode); - List workflowTaskRelationList = Lists.newArrayList(); - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setProjectCode(projectCode); - workflowTaskRelation.setWorkflowDefinitionCode(1L); - workflowTaskRelation.setPreTaskCode(0L); - workflowTaskRelation.setPreTaskVersion(0); - workflowTaskRelation.setPostTaskCode(taskCode); - workflowTaskRelation.setPostTaskVersion(1); - workflowTaskRelationList.add(workflowTaskRelation); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - Mockito.when(workflowTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode)) - .thenReturn(workflowTaskRelationList); - Mockito.when(workflowDefinitionMapper.queryByCode(1L)).thenReturn(getWorkflowDefinition()); - Mockito.when(workflowTaskRelationMapper.queryByWorkflowDefinitionCode(1L)).thenReturn(workflowTaskRelationList); - List relationLogs = - workflowTaskRelationList.stream().map(WorkflowTaskRelationLog::new).collect(Collectors.toList()); - Mockito.when(processService.saveTaskRelation(user, 1L, 1L, - 1, relationLogs, Lists.newArrayList(), Boolean.TRUE)).thenReturn(0); - Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } - - @Test - public void testDeleteTaskWorkflowRelation() { - long projectCode = 1L; - long taskCode = 1L; - long workflowDefinitionCode = 1L; - long preTaskCode = 4L; - long postTaskCode = 5L; - Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - Mockito.when( - workflowTaskRelationMapper.queryByCode(projectCode, workflowDefinitionCode, preTaskCode, postTaskCode)) - .thenReturn(Lists.newArrayList()); - Mockito.when(workflowDefinitionMapper.queryByCode(workflowDefinitionCode)).thenReturn(getWorkflowDefinition()); - Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(getTaskDefinition()); - TaskDefinition taskDefinition = new TaskDefinition(); - taskDefinition.setTaskType("CONDITIONS"); - Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(taskDefinition); - List workflowTaskRelationList = Lists.newArrayList(); - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setProjectCode(projectCode); - workflowTaskRelation.setWorkflowDefinitionCode(1L); - workflowTaskRelation.setPreTaskCode(0L); - workflowTaskRelation.setPreTaskVersion(0); - workflowTaskRelation.setPostTaskCode(taskCode); - workflowTaskRelation.setPostTaskVersion(1); - workflowTaskRelationList.add(workflowTaskRelation); - Mockito.when(workflowTaskRelationMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode)) - .thenReturn(workflowTaskRelationList); - List relationLogs = - workflowTaskRelationList.stream().map(WorkflowTaskRelationLog::new).collect(Collectors.toList()); - - Mockito.when(processService.saveTaskRelation(user, 1L, 1L, - 1, relationLogs, Lists.newArrayList(), Boolean.TRUE)).thenReturn(0); - Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } - - @Test - public void testDeleteEdge() { - long projectCode = 1L; - long workflowDefinitionCode = 3L; - long preTaskCode = 0L; - long postTaskCode = 5L; - Project project = getProject(projectCode); - Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setProjectCode(projectCode); - workflowTaskRelation.setWorkflowDefinitionCode(workflowDefinitionCode); - workflowTaskRelation.setWorkflowDefinitionVersion(1); - workflowTaskRelation.setPreTaskCode(preTaskCode); - workflowTaskRelation.setPostTaskCode(postTaskCode); - WorkflowTaskRelationLog processTaskRelationLog = new WorkflowTaskRelationLog(workflowTaskRelation); - processTaskRelationLog.setOperator(user.getId()); - List workflowTaskRelationList = new ArrayList<>(); - workflowTaskRelationList.add(workflowTaskRelation); - Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, null)).thenReturn(result); - Mockito.when(workflowTaskRelationMapper.queryByWorkflowDefinitionCode(1L)).thenReturn(workflowTaskRelationList); - List relationLogs = - workflowTaskRelationList.stream().map(WorkflowTaskRelationLog::new).collect(Collectors.toList()); - Mockito.when(processService.saveTaskRelation(user, 1L, 1L, - 1, relationLogs, Lists.newArrayList(), Boolean.TRUE)).thenReturn(0); - Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } - - @Test - public void testCreateWorkflowTaskRelationV2() { - TaskRelationCreateRequest taskRelationCreateRequest = new TaskRelationCreateRequest(); - taskRelationCreateRequest.setWorkflowCode(WORKFLOW_DEFINITION_CODE); - - // error workflow definition not exists - exception = Assertions.assertThrows(ServiceException.class, - () -> workflowTaskRelationService.createWorkflowTaskRelationV2(user, taskRelationCreateRequest)); - Assertions.assertEquals(Status.WORKFLOW_DEFINITION_NOT_EXIST.getCode(), - ((ServiceException) exception).getCode()); - - // error project without permissions - Mockito.when(workflowDefinitionMapper.queryByCode(WORKFLOW_DEFINITION_CODE)) - .thenReturn(getWorkflowDefinition()); - Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject(PROJECT_CODE)); - Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM)).when(projectService) - .checkProjectAndAuthThrowException(user, getProject(PROJECT_CODE), null); - exception = Assertions.assertThrows(ServiceException.class, - () -> workflowTaskRelationService.createWorkflowTaskRelationV2(user, taskRelationCreateRequest)); - Assertions.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM.getCode(), - ((ServiceException) exception).getCode()); - - // error insert workflow task relation - Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, getProject(PROJECT_CODE), - null); - Mockito.when(workflowTaskRelationMapper.insert(isA(WorkflowTaskRelation.class))).thenReturn(0); - Mockito.when(taskDefinitionMapper.queryByCode(isA(Long.class))).thenReturn(getTaskDefinition()); - exception = Assertions.assertThrows(ServiceException.class, - () -> workflowTaskRelationService.createWorkflowTaskRelationV2(user, taskRelationCreateRequest)); - Assertions.assertEquals(Status.CREATE_WORKFLOW_TASK_RELATION_ERROR.getCode(), - ((ServiceException) exception).getCode()); - - // error insert workflow task relation log - Mockito.when(workflowTaskRelationMapper.insert(isA(WorkflowTaskRelation.class))).thenReturn(1); - Mockito.when(workflowTaskRelationLogMapper.insert(isA(WorkflowTaskRelationLog.class))).thenReturn(0); - exception = Assertions.assertThrows(ServiceException.class, - () -> workflowTaskRelationService.createWorkflowTaskRelationV2(user, taskRelationCreateRequest)); - Assertions.assertEquals(Status.CREATE_WORKFLOW_TASK_RELATION_LOG_ERROR.getCode(), - ((ServiceException) exception).getCode()); - - // success - Mockito.when(workflowTaskRelationLogMapper.insert(isA(WorkflowTaskRelationLog.class))).thenReturn(1); - Assertions.assertDoesNotThrow( - () -> workflowTaskRelationService.createWorkflowTaskRelationV2(user, taskRelationCreateRequest)); - } - - @Test - public void testDeleteTaskWorkflowRelationV2() { - TaskRelationCreateRequest taskRelationCreateRequest = new TaskRelationCreateRequest(); - taskRelationCreateRequest.setWorkflowCode(WORKFLOW_DEFINITION_CODE); - - // error task relation size - Mockito.when( - workflowTaskRelationMapper.filterWorkflowTaskRelation(isA(Page.class), isA(WorkflowTaskRelation.class))) - .thenReturn(getMultiWorkflowTaskRelations()); - exception = Assertions.assertThrows(ServiceException.class, () -> workflowTaskRelationService - .deleteTaskWorkflowRelationV2(user, UPSTREAM_TASK_CODE, DOWNSTREAM_TASK_CODE)); - Assertions.assertEquals(Status.WORKFLOW_TASK_RELATION_NOT_EXPECT.getCode(), - ((ServiceException) exception).getCode()); - - // success - Mockito.when( - workflowTaskRelationMapper.filterWorkflowTaskRelation(isA(Page.class), isA(WorkflowTaskRelation.class))) - .thenReturn(getOneWorkflowTaskRelation()); - Assertions.assertDoesNotThrow(() -> workflowTaskRelationService.deleteTaskWorkflowRelationV2(user, - UPSTREAM_TASK_CODE, DOWNSTREAM_TASK_CODE)); - } - - private IPage getOneWorkflowTaskRelation() { - IPage workflowTaskRelationIPage = new Page<>(); - WorkflowTaskRelation workflowTaskRelation = new WorkflowTaskRelation(); - workflowTaskRelation.setWorkflowDefinitionCode(WORKFLOW_DEFINITION_CODE); - workflowTaskRelation.setPreTaskCode(UPSTREAM_TASK_CODE); - workflowTaskRelation.setPostTaskCode(DOWNSTREAM_TASK_CODE); - workflowTaskRelationIPage.setRecords(Collections.singletonList(workflowTaskRelation)); - return workflowTaskRelationIPage; - } - - private IPage getMultiWorkflowTaskRelations() { - IPage workflowTaskRelationIPage = new Page<>(); - List workflowTaskRelations = new ArrayList<>(); - - WorkflowTaskRelation workflowTaskRelation0 = new WorkflowTaskRelation(); - workflowTaskRelation0.setWorkflowDefinitionCode(WORKFLOW_DEFINITION_CODE); - workflowTaskRelation0.setPreTaskCode(UPSTREAM_TASK_CODE); - workflowTaskRelation0.setPostTaskCode(DOWNSTREAM_TASK_CODE); - workflowTaskRelations.add(workflowTaskRelation0); - - WorkflowTaskRelation workflowTaskRelation1 = new WorkflowTaskRelation(); - workflowTaskRelation1.setWorkflowDefinitionCode(WORKFLOW_DEFINITION_CODE); - workflowTaskRelation1.setPreTaskCode(UPSTREAM_TASK_CODE); - workflowTaskRelation1.setPostTaskCode(DOWNSTREAM_TASK_CODE); - workflowTaskRelations.add(workflowTaskRelation1); - - workflowTaskRelationIPage.setRecords(workflowTaskRelations); - return workflowTaskRelationIPage; - } -} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/ClusterServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/ClusterServiceTest.java index addc8626a720..e445869bf7c0 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/ClusterServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/impl/ClusterServiceTest.java @@ -24,7 +24,6 @@ import org.apache.dolphinscheduler.api.dto.ClusterDto; import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.k8s.K8sManager; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.dao.entity.Cluster; @@ -70,9 +69,6 @@ public class ClusterServiceTest { @Mock private K8sNamespaceMapper k8sNamespaceMapper; - @Mock - private K8sManager k8sManager; - public static final String testUserName = "clusterServerTest"; public static final String clusterName = "Env1"; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/FileUtilsTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/FileUtilsTest.java deleted file mode 100644 index 59b88625c405..000000000000 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/FileUtilsTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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. - */ - -package org.apache.dolphinscheduler.api.utils; - -import org.apache.http.entity.ContentType; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.file.Path; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; -import org.mockito.Mockito; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.web.multipart.MultipartFile; - -public class FileUtilsTest { - - private static final Logger logger = LoggerFactory.getLogger(FileUtilsTest.class); - - @TempDir - public Path folder; - - private String rootPath; - - @BeforeEach - public void setUp() throws Exception { - rootPath = folder.toString(); - } - - /** - * Use mock to test copyFile - * @throws IOException - */ - @Test - public void testCopyFile() throws IOException { - - // Define dest file path - String src = rootPath + System.getProperty("file.separator") + "src.txt"; - String destFilename = rootPath + System.getProperty("file.separator") + "data.txt"; - logger.info("destFilename: " + destFilename); - - // Define InputStream for MultipartFile - String data = "data text"; - org.apache.commons.io.FileUtils.writeStringToFile(new File(src), data); - - // Use Mockito to mock MultipartFile - MultipartFile file = Mockito.mock(MultipartFile.class, Mockito.RETURNS_DEEP_STUBS); - Mockito.when(file.getInputStream()).thenReturn(new FileInputStream(src)); - - // Invoke copyFile - FileUtils.copyInputStreamToFile(file, destFilename); - - // Test file exists - File destFile = new File(destFilename); - Assertions.assertTrue(destFile.exists()); - - } - - @Test - public void testFile2Resource() throws IOException { - - // Define dest file path - String destFilename = rootPath + System.getProperty("file.separator") + "resource.txt"; - logger.info("destFilename: " + destFilename); - - // Define test resource - File file = new File(destFilename); - org.apache.commons.io.FileUtils.writeStringToFile(file, "test data", Charset.defaultCharset()); - - // Invoke file2Resource and test not null - Resource resource = FileUtils.file2Resource(file.toString()); - Assertions.assertNotNull(resource); - - // Invoke file2Resource and test null - Resource resource1 = FileUtils.file2Resource(file + "abc"); - Assertions.assertNull(resource1); - - } - - @Test - public void testFile2String() throws IOException { - String content = "123"; - org.apache.commons.io.FileUtils.writeStringToFile(new File("/tmp/task.json"), content, - Charset.defaultCharset()); - - File file = new File("/tmp/task.json"); - FileInputStream fileInputStream = new FileInputStream("/tmp/task.json"); - MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(), - ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream); - - String resultStr = FileUtils.file2String(multipartFile); - - Assertions.assertEquals(content, resultStr); - - boolean delete = file.delete(); - - Assertions.assertTrue(delete); - } -}