You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by we...@apache.org on 2024/04/07 02:03:54 UTC
(dolphinscheduler) branch dev_wenjun_refactorMaster updated (0c2bb5ce25 -> 6b6feb008a)
This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a change to branch dev_wenjun_refactorMaster
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
discard 0c2bb5ce25 Remove dag package in master
omit 514d713aef Add dolphinscheduler-workflow-engine module
add dcc9d64ef6 Fix Switch logic task doesn't check the branch exist (#15755)
add bcf1b67255 [Fix] add resource full name check (#15757)
add 5466117838 [Bug][Worker] Replace jre with jdk (#15764)
add 5e3dc7b16f [Fix-15771] Fix normal user can grant project permission (#15772)
add 929f4cf568 Remove replace sql_mode in dolphinscheduler_mysql.sql (#15775)
add 723126b52b hotfix(ui): update datasourceTypes following the DbType in spi module (#15776)
add ae1fe84e85 [TEST] fill up alert group service test (#15777)
add dc4dad135c Fix TaskGroupCoordinator might cause OOM when there is a lot of waiting TaskGroupQueue (#15773)
add d39bdcb165 [RemoteLogging] Move init into loghandler (#15780)
add ac0189a636 [DSIP-24][RemoteLogging]Support AbsRemoteLogHandler (#15769)
add 8acc697942 [Improvement] add resource full name check (#15786)
add 920ac154cb [Improvement-15744][parameter] project parameter add update time and update user id (#15745)
add 0419543d81 Directly use Quartz replase api to bootstrap a schedule (#15781)
add c0435e5bd8 fix dependent task logic (#15795)
add 5d8808dda4 [Fix-15760][datasource-plugin] fix sql task split error (#15760) (#15794)
add 98bc9ce4c9 feat: inc coverage of alert plugin instance svc (#15799)
add 3b1de41acb Remove dolphinscheduler-data-quality from dolphinscheduler-task-dataquality (#15791)
new 5dcb0fb59c Add dolphinscheduler-workflow-engine module
new bd82aecbd1 Remove dag package in master
new aa9a8b9431 Rename Node and Edge
new 6b6feb008a Add TaskExecutionRunnable in WorkflowExecutionDAG
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (0c2bb5ce25)
\
N -- N -- N refs/heads/dev_wenjun_refactorMaster (6b6feb008a)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
docs/docs/en/guide/remote-logging.md | 12 +-
docs/docs/en/guide/task/java.md | 2 +
docs/docs/zh/guide/remote-logging.md | 12 +-
docs/docs/zh/guide/task/java.md | 1 +
dolphinscheduler-api/pom.xml | 5 +
.../constants/ApiFuncIdentificationConstant.java | 3 +-
.../apache/dolphinscheduler/api/enums/Status.java | 2 +
.../api/service/ResourcesService.java | 6 +-
.../impl/AlertPluginInstanceServiceImpl.java | 6 +-
.../service/impl/ProjectParameterServiceImpl.java | 2 +
.../api/service/impl/ResourcesServiceImpl.java | 130 +++----
.../api/service/impl/UsersServiceImpl.java | 17 +
.../api/service/AlertGroupServiceTest.java | 83 +++-
.../service/AlertPluginInstanceServiceTest.java | 107 +++++-
.../api/service/ProjectParameterServiceTest.java | 3 +
.../api/service/ResourcesServiceTest.java | 427 +++++++++------------
.../api/service/UsersServiceTest.java | 25 ++
dolphinscheduler-common/pom.xml | 5 +
.../common/constants/Constants.java | 7 +
.../common/log/remote/AbsRemoteLogHandler.java | 137 +++++++
.../common/log/remote/GcsRemoteLogHandler.java | 21 +-
.../common/log/remote/OssRemoteLogHandler.java | 17 +-
.../common/log/remote/RemoteLogHandlerFactory.java | 2 +
.../common/log/remote/S3RemoteLogHandler.java | 19 +-
.../src/main/resources/common.properties | 7 +-
.../common/log/remote/AbsRemoteLogHandlerTest.java | 144 +++++++
.../dao/entity/ProjectParameter.java | 8 +
.../dao/mapper/ProcessInstanceMapper.java | 6 +-
.../dao/mapper/TaskGroupQueueMapper.java | 14 +
.../dao/repository/ProcessInstanceDao.java | 6 +-
.../dao/repository/TaskGroupQueueDao.java | 31 ++
.../repository/impl/ProcessInstanceDaoImpl.java | 10 +-
.../dao/repository/impl/TaskGroupQueueDaoImpl.java | 22 ++
.../dao/mapper/ProcessInstanceMapper.xml | 9 +-
.../dao/mapper/ProjectParameterMapper.xml | 14 +-
.../dao/mapper/TaskGroupQueueMapper.xml | 27 ++
.../src/main/resources/sql/dolphinscheduler_h2.sql | 1 +
.../main/resources/sql/dolphinscheduler_mysql.sql | 3 +-
.../resources/sql/dolphinscheduler_postgresql.sql | 1 +
.../3.2.2_schema/mysql/dolphinscheduler_ddl.sql | 1 +
.../postgresql/dolphinscheduler_ddl.sql | 4 +-
.../dao/mapper/ProcessInstanceMapperTest.java | 3 +-
.../repository/impl/TaskGroupQueueDaoImplTest.java | 76 ++++
.../data/quality/flow/batch/reader/JdbcReader.java | 8 +-
.../data/quality/flow/batch/writer/JdbcWriter.java | 8 +-
.../datasource/AbstractDataSourceProcessor.java | 3 +-
.../param/ClickHouseDataSourceProcessor.java | 3 +-
.../dameng/param/DamengDataSourceProcessor.java | 3 +-
.../db2/param/Db2DataSourceProcessor.java | 3 +-
.../hive/param/HiveDataSourceProcessor.java | 3 +-
.../hive/param/HiveDataSourceProcessorTest.java | 20 +
.../mysql/param/MySQLDataSourceProcessor.java | 3 +-
.../param/OceanBaseDataSourceProcessor.java | 3 +-
.../param/PostgreSQLDataSourceProcessor.java | 3 +-
.../param/SQLServerDataSourceProcessor.java | 3 +-
.../trino/param/TrinoDataSourceProcessor.java | 3 +-
.../runner/task/switchtask/SwitchLogicTask.java | 116 +++---
.../runner/taskgroup/TaskGroupCoordinator.java | 60 ++-
.../server/master/utils/DependentExecute.java | 2 +-
.../scheduler/api/SchedulerException.java | 8 +-
.../scheduler/api/SchedulerExceptionEnum.java | 8 +-
.../scheduler/quartz/ProcessScheduleTask.java | 11 +-
.../scheduler/quartz/QuartzCornTriggerBuilder.java | 95 +++++
.../scheduler/quartz/QuartzJobData.java | 62 +++
.../scheduler/quartz/QuartzJobDetailBuilder.java | 58 +++
.../scheduler/quartz/QuartzJobKey.java | 49 +++
.../scheduler/quartz/QuartzScheduler.java | 123 ++----
.../quartz/QuartzSchedulerConfiguration.java | 14 +-
.../scheduler/quartz/QuartzTriggerBuilder.java | 9 +-
.../exception/QuartzSchedulerExceptionEnum.java | 43 +--
.../scheduler/quartz/utils/QuartzTaskUtils.java | 59 ---
.../scheduler/quartz/QuartzJobDataTest.java | 56 +++
.../scheduler/quartz/QuartzJobKeyTest.java | 30 +-
.../QuartzSchedulerExceptionEnumTest.java | 23 +-
.../dolphinscheduler-task-dataquality/pom.xml | 5 -
.../plugin/task/dq/utils/RuleParserUtils.java | 23 +-
dolphinscheduler-ui/src/locales/en_US/project.ts | 2 +
dolphinscheduler-ui/src/locales/zh_CN/project.ts | 2 +
.../src/views/projects/parameter/use-table.ts | 10 +
.../task/components/node/fields/use-datasource.ts | 27 +-
.../components/resource/table/use-table.ts | 4 +-
dolphinscheduler-worker/src/main/docker/Dockerfile | 2 +-
.../engine/{event/IEvent.java => dag/BaseDAG.java} | 7 +-
.../dolphinscheduler/workflow/engine/dag/DAG.java | 82 +---
.../workflow/engine/dag/DAGNode.java | 92 -----
.../engine/dag/{IDAGNodeAction.java => Edge.java} | 22 +-
.../IWorkflowInstance.java => dag/ITask.java} | 8 +-
.../{event/IEvent.java => dag/ITaskChain.java} | 8 +-
.../{event/IEvent.java => dag/ITaskContext.java} | 6 +-
.../ITaskInstance.java => dag/ITaskIdentify.java} | 6 +-
.../WorkflowFailedEvent.java => dag/Node.java} | 23 +-
.../NodeContext.java} | 19 +-
.../dag/{IDAGNode.java => NodeIdentify.java} | 19 +-
.../engine/dag/{IDAGNode.java => Task.java} | 22 +-
.../engine/dag/{IDAGNode.java => TaskChain.java} | 25 +-
.../{event/IEvent.java => dag/TaskContext.java} | 7 +-
.../TaskIdentify.java} | 23 +-
.../workflow/engine/dag/WorkflowDAG.java | 111 ++++--
.../workflow/engine/dag/WorkflowDAGBuilder.java | 8 +-
.../workflow/engine/engine/DAGEngine.java | 211 +++++-----
.../workflow/engine/engine/DAGEngineFactory.java | 2 +-
.../workflow/engine/engine/EventEngine.java | 21 +-
.../workflow/engine/engine/IDAGEngine.java | 32 +-
.../workflow/engine/engine/IWorkflowEngine.java | 13 +-
.../workflow/engine/engine/WorkflowEngine.java | 39 +-
.../workflow/engine/event/EventDispatcher.java | 44 +++
.../workflow/engine/event/IEvent.java | 2 +
.../engine/{engine => event}/IEventDispatcher.java | 4 +-
.../engine/event/{IEvent.java => IEventType.java} | 5 +-
.../workflow/engine/event/ITaskEvent.java | 4 +-
.../workflow/engine/event/IWorkflowEvent.java | 4 +-
...nt.java => TaskExecutionPlanChainEndEvent.java} | 18 +-
.../workflow/engine/event/TaskOperationEvent.java | 11 +-
.../engine/event/TaskOperationEventOperator.java | 20 +-
...rationType.java => TaskOperationEventType.java} | 4 +-
.../workflow/engine/event/WorkflowFailedEvent.java | 16 +-
.../workflow/engine/event/WorkflowFinishEvent.java | 15 +-
.../engine/event/WorkflowOperationEvent.java | 48 ++-
.../event/WorkflowOperationEventOperator.java | 10 +-
...onType.java => WorkflowOperationEventType.java} | 2 +-
.../WorkflowExecuteRunnableNotFoundException.java | 10 +-
...a => DefaultTaskExecutionRunnableDelegate.java} | 31 +-
...efaultTaskExecutionRunnableDelegateFactory.java | 51 +++
... DefaultWorkflowExecutionRunnableDelegate.java} | 31 +-
...tWorkflowExecutionRunnableDelegateFactory.java} | 16 +-
.../workflow/IEventfulExecutionRunnable.java | 4 -
.../engine/workflow/ITaskExecutionContext.java | 6 +-
.../workflow/ITaskExecutionContextFactory.java | 4 +-
.../engine/workflow/ITaskExecutionPlan.java | 52 +++
...wInstance.java => ITaskExecutionPlanChain.java} | 6 +-
.../engine/workflow/ITaskExecutionRunnable.java | 19 +-
...tance.java => ITaskExecutionRunnableChain.java} | 6 +-
...ce.java => ITaskExecutionRunnableDelegate.java} | 14 +-
... => ITaskExecutionRunnableDelegateFactory.java} | 15 +-
.../workflow/ITaskExecutionRunnableFactory.java | 4 +-
...ce.java => ITaskExecutionRunnableIdentify.java} | 8 +-
.../engine/workflow/IWorkflowExecutionContext.java | 18 +-
.../engine/workflow/IWorkflowExecutionDAG.java | 37 +-
.../workflow/IWorkflowExecutionRunnable.java | 13 +-
...ava => IWorkflowExecutionRunnableDelegate.java} | 13 +-
...IWorkflowExecutionRunnableDelegateFactory.java} | 4 +-
...ava => IWorkflowExecutionRunnableIdentify.java} | 4 +-
.../IWorkflowExecutionRunnableRepository.java | 4 +-
...ngletonWorkflowExecutionRunnableRepository.java | 17 +-
.../engine/workflow/TaskExecutionContext.java | 10 -
.../engine/workflow/TaskExecutionPlan.java | 117 ++++++
.../engine/workflow/TaskExecutionRunnable.java | 32 +-
.../workflow/TaskExecutionRunnableFactory.java | 18 +-
...nce.java => TaskExecutionRunnableIdentify.java} | 29 +-
.../engine/workflow/WorkflowExecutionContext.java | 26 +-
.../engine/workflow/WorkflowExecutionDAG.java | 147 +++----
...tance.java => WorkflowExecutionDAGFactory.java} | 8 +-
.../engine/workflow/WorkflowExecutionRunnable.java | 59 +--
.../workflow/WorkflowExecutionRunnableFactory.java | 12 +-
...e.java => WorkflowExecutionRunnableStatus.java} | 14 +-
...orkflowExecuteRunnableRepositoryAssertions.java | 4 +-
.../engine/dag/{DAGNodeTest.java => NodeTest.java} | 20 +-
.../workflow/engine/engine/WorkflowEngineTest.java | 12 +-
.../engine/event/WorkflowOperationEventTest.java | 6 +-
159 files changed, 2789 insertions(+), 1530 deletions(-)
create mode 100644 dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/AbsRemoteLogHandler.java
create mode 100644 dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/log/remote/AbsRemoteLogHandlerTest.java
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java => dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-api/src/main/java/org/apache/dolphinscheduler/scheduler/api/SchedulerExceptionEnum.java (85%)
create mode 100644 dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzCornTriggerBuilder.java
create mode 100644 dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzJobData.java
create mode 100644 dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzJobDetailBuilder.java
create mode 100644 dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzJobKey.java
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java => dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzTriggerBuilder.java (84%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java => dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/exception/QuartzSchedulerExceptionEnum.java (51%)
delete mode 100644 dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/utils/QuartzTaskUtils.java
create mode 100644 dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/test/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzJobDataTest.java
rename dolphinscheduler-data-quality/src/test/java/org/apache/dolphinscheduler/data/quality/utils/ParserUtilsTest.java => dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/test/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzJobKeyTest.java (57%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java => dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/test/java/org/apache/dolphinscheduler/scheduler/quartz/exception/QuartzSchedulerExceptionEnumTest.java (59%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{event/IEvent.java => dag/BaseDAG.java} (86%)
delete mode 100644 dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNode.java
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/{IDAGNodeAction.java => Edge.java} (77%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{workflow/IWorkflowInstance.java => dag/ITask.java} (84%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{event/IEvent.java => dag/ITaskChain.java} (86%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{event/IEvent.java => dag/ITaskContext.java} (86%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{workflow/ITaskInstance.java => dag/ITaskIdentify.java} (88%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{event/WorkflowFailedEvent.java => dag/Node.java} (67%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{event/WorkflowFailedEvent.java => dag/NodeContext.java} (77%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/{IDAGNode.java => NodeIdentify.java} (78%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/{IDAGNode.java => Task.java} (65%)
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/{IDAGNode.java => TaskChain.java} (64%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{event/IEvent.java => dag/TaskContext.java} (86%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{workflow/WorkflowInstance.java => dag/TaskIdentify.java} (71%)
create mode 100644 dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventDispatcher.java
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/{engine => event}/IEventDispatcher.java (87%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/{IEvent.java => IEventType.java} (93%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/{WorkflowFinishEvent.java => TaskExecutionPlanChainEndEvent.java} (64%)
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/{TaskOperationType.java => TaskOperationEventType.java} (92%)
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/{WorkflowOperationType.java => WorkflowOperationEventType.java} (94%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{TaskExecutionContext.java => DefaultTaskExecutionRunnableDelegate.java} (70%)
create mode 100644 dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultTaskExecutionRunnableDelegateFactory.java
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{TaskExecutionContext.java => DefaultWorkflowExecutionRunnableDelegate.java} (69%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{TaskExecutionContext.java => DefaultWorkflowExecutionRunnableDelegateFactory.java} (58%)
create mode 100644 dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionPlan.java
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{IWorkflowInstance.java => ITaskExecutionPlanChain.java} (88%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskInstance.java => ITaskExecutionRunnableChain.java} (87%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskInstance.java => ITaskExecutionRunnableDelegate.java} (81%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskExecutionRunnableFactory.java => ITaskExecutionRunnableDelegateFactory.java} (58%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskInstance.java => ITaskExecutionRunnableIdentify.java} (83%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskInstance.java => IWorkflowExecutionRunnableDelegate.java} (81%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskExecutionContext.java => IWorkflowExecutionRunnableDelegateFactory.java} (81%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskInstance.java => IWorkflowExecutionRunnableIdentify.java} (92%)
create mode 100644 dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionPlan.java
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{WorkflowInstance.java => TaskExecutionRunnableIdentify.java} (60%)
copy dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskInstance.java => WorkflowExecutionDAGFactory.java} (85%)
rename dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/{ITaskInstance.java => WorkflowExecutionRunnableStatus.java} (84%)
rename dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/{DAGNodeTest.java => NodeTest.java} (89%)
(dolphinscheduler) 01/04: Add dolphinscheduler-workflow-engine module
Posted by we...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev_wenjun_refactorMaster
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
commit 5dcb0fb59c5392138616ddaffec5e2cecab3e35f
Author: Wenjun Ruan <we...@apache.org>
AuthorDate: Tue Mar 5 15:48:00 2024 +0800
Add dolphinscheduler-workflow-engine module
---
.../dao/entity/ProcessInstance.java | 8 +-
.../dao/repository/ProcessTaskRelationLogDao.java | 3 +
.../impl/ProcessTaskRelationLogDaoImpl.java | 6 +
.../server/master/dag/BasicDAG.java | 71 ++++++
.../dolphinscheduler/server/master/dag/DAG.java | 146 +++++++++++
.../server/master/dag/DAGEdge.java | 51 ++++
.../server/master/dag/DAGEngine.java | 148 +++++++++++
.../DAGEngineFactory.java} | 16 +-
.../server/master/dag/DAGNode.java | 92 +++++++
.../server/master/dag/IDAGEngine.java | 70 +++++
.../IDAGEngineFactory.java} | 8 +-
.../IDAGNodeAction.java} | 19 +-
.../IEventRepositoryFactory.java} | 10 +-
.../IEventfulExecutionRunnable.java} | 16 +-
.../ITaskExecutionContext.java} | 10 +-
.../ITaskExecutionContextFactory.java} | 8 +-
.../server/master/dag/ITaskExecutionRunnable.java | 59 +++++
.../ITaskExecutionRunnableFactory.java} | 8 +-
.../ITaskExecutionRunnableRepository.java} | 17 +-
.../ITaskExecutionRunnableRepositoryFactory.java} | 8 +-
.../IWorkflowDAG.java} | 11 +-
.../IWorkflowDAGFactory.java} | 19 +-
.../server/master/dag/IWorkflowEngine.java | 57 +++++
.../master/dag/IWorkflowExecutionContext.java | 35 ++-
.../server/master/dag/IWorkflowExecutionDAG.java | 74 ++++++
.../IWorkflowExecutionDAGFactory.java} | 9 +-
.../master/dag/IWorkflowExecutionRunnable.java | 39 ++-
.../MemoryEventRepositoryFactory.java} | 19 +-
.../TaskExecutionContext.java} | 19 +-
.../TaskExecutionRunnable.java} | 38 ++-
.../dag/TaskExecutionRunnableRepository.java | 68 +++++
.../TaskExecutionRunnableRepositoryFactory.java} | 14 +-
.../TaskExecutionValve.java} | 11 +-
.../TaskIdentify.java} | 8 +-
.../WorkflowDAG.java} | 11 +-
.../server/master/dag/WorkflowDAGBuilder.java | 125 +++++++++
.../server/master/dag/WorkflowDAGFactory.java | 65 +++++
.../server/master/dag/WorkflowEngine.java | 82 ++++++
.../dag/WorkflowExecuteRunnableRepository.java | 52 ++++
.../master/dag/WorkflowExecutionContext.java | 36 ++-
.../WorkflowExecutionContextFactory.java} | 13 +-
.../server/master/dag/WorkflowExecutionDAG.java | 116 +++++++++
.../master/dag/WorkflowExecutionDAGFactory.java | 60 +++++
.../master/dag/WorkflowExecutionRunnable.java | 64 +++++
.../WorkflowExecutionRunnableFactory.java} | 22 +-
.../WorkflowIdentify.java} | 19 +-
.../server/master/events/EventEngine.java | 111 ++++++++
.../server/master/events/EventFirer.java | 95 +++++++
.../EventOperatorManager.java} | 18 +-
.../IAsyncEvent.java} | 12 +-
.../IDelayEvent.java} | 10 +-
.../IEvent.java} | 8 +-
.../IEventFirer.java} | 19 +-
.../IEventOperator.java} | 16 +-
.../IEventOperatorManager.java} | 17 +-
.../IEventRepository.java} | 21 +-
.../ISyncEvent.java} | 9 +-
.../ITaskEvent.java} | 10 +-
.../ITaskEventOperator.java} | 8 +-
.../IWorkflowEvent.java} | 13 +-
.../IWorkflowEventOperator.java} | 11 +-
.../master/events/MemoryEventRepository.java | 60 +++++
.../TaskLogSendToRemoteEvent.java} | 20 +-
.../TaskLogSendToRemoteEventOperator.java} | 22 +-
.../TaskOperationEvent.java} | 28 +-
.../master/events/TaskOperationEventOperator.java | 47 ++++
.../TaskOperationType.java} | 13 +-
.../TaskSuccessEvent.java} | 17 +-
.../master/events/TaskSuccessEventOperator.java | 47 ++++
.../WorkflowFailedEvent.java} | 19 +-
.../master/events/WorkflowFailedEventOperator.java | 57 +++++
.../WorkflowFinalizeEvent.java} | 16 +-
.../WorkflowFinalizeEventOperator.java} | 24 +-
.../WorkflowFinishEvent.java} | 21 +-
.../master/events/WorkflowOperationEvent.java | 51 ++++
.../events/WorkflowOperationEventOperator.java | 87 +++++++
.../WorkflowOperationType.java} | 20 +-
.../WorkflowTimeoutEvent.java} | 17 +-
.../events/WorkflowTimeoutEventOperator.java | 61 +++++
.../WorkflowTriggerNextTaskEvent.java} | 22 +-
.../WorkflowTriggerNextTaskEventOperator.java | 44 ++++
.../WorkflowTriggeredEvent.java} | 17 +-
.../events/WorkflowTriggeredEventOperator.java | 63 +++++
...a => TaskExecuteRunnableNotFoundException.java} | 9 +-
... WorkflowExecuteRunnableNotFoundException.java} | 10 +-
.../master/runner/DefaultTaskExecuteRunnable.java | 3 +-
.../master/runner/TaskExecutionContextFactory.java | 3 +-
.../execute/DefaultTaskExecuteRunnableFactory.java | 18 +-
.../ExceptionUtils.java} | 13 +-
.../server/master/dag/DAGNodeTest.java | 121 +++++++++
.../dag/MockWorkflowExecutionContextFactory.java | 88 +++++++
.../dag/MockWorkflowExecutionRunnableFactory.java} | 15 +-
.../server/master/dag/WorkflowDAGAssertion.java | 171 +++++++++++++
.../server/master/dag/WorkflowDAGBuilderTest.java | 282 +++++++++++++++++++++
.../server/master/dag/WorkflowEngineIT.java} | 8 +-
.../server/master/dag/WorkflowEngineTest.java | 114 +++++++++
.../dag/WorkflowExecutionRunnableAssertions.java | 48 ++++
...kflowExecutionRunnableRepositoryAssertions.java | 43 ++++
.../master/dag/WorkflowExecutionRunnableTest.java | 51 ++++
.../master/events/WorkflowOperationEventTest.java | 46 ++++
.../server/master/utils/ExceptionUtilsTest.java | 18 ++
dolphinscheduler-workflow-engine/README.md | 2 +
dolphinscheduler-workflow-engine/pom.xml | 36 +++
.../dolphinscheduler/workflow/engine/dag/DAG.java | 146 +++++++++++
.../workflow/engine/dag/DAGEdge.java | 53 ++++
.../workflow/engine/dag/DAGNode.java | 92 +++++++
.../workflow/engine/dag/DAGNodeDefinition.java | 19 +-
.../workflow/engine/dag/IDAGNode.java | 16 +-
.../workflow/engine/dag/IDAGNodeAction.java | 19 +-
.../workflow/engine/dag/WorkflowDAG.java | 75 ++++++
.../workflow/engine/dag/WorkflowDAGBuilder.java | 107 ++++++++
.../workflow/engine/engine/DAGEngine.java | 171 +++++++++++++
.../workflow/engine/engine/DAGEngineFactory.java | 20 +-
.../workflow/engine/engine/IDAGEngine.java | 72 ++++++
.../workflow/engine/engine/IDAGEngineFactory.java | 10 +-
.../workflow/engine/engine/IWorkflowEngine.java | 58 +++++
.../engine/engine/IWorkflowEngineFactory.java | 8 +-
.../workflow/engine/engine/WorkflowEngine.java | 82 ++++++
.../engine/engine/WorkflowEngineFactory.java | 12 +-
.../workflow/engine/event/EventEngine.java | 111 ++++++++
.../workflow/engine/event/EventFirer.java | 91 +++++++
.../engine/event/EventOperatorManager.java | 18 +-
.../workflow/engine/event/IAsyncEvent.java | 12 +-
.../workflow/engine/event/IDelayEvent.java | 10 +-
.../workflow/engine/event/IEvent.java | 8 +-
.../workflow/engine/event/IEventFirer.java | 19 +-
.../workflow/engine/event/IEventOperator.java | 16 +-
.../engine/event/IEventOperatorManager.java | 17 +-
.../workflow/engine/event/IEventRepository.java | 21 +-
.../workflow/engine/event/ISyncEvent.java | 9 +-
.../workflow/engine/event/ITaskEvent.java | 10 +-
.../workflow/engine/event/ITaskEventOperator.java | 8 +-
.../workflow/engine/event/IWorkflowEvent.java | 13 +-
.../engine/event/IWorkflowEventOperator.java | 11 +-
.../engine/event/MemoryEventRepository.java | 64 +++++
.../workflow/engine/event/TaskOperationEvent.java | 21 +-
.../engine/event/TaskOperationEventOperator.java | 44 ++++
.../workflow/engine/event/TaskOperationType.java | 13 +-
.../workflow/engine/event/WorkflowFailedEvent.java | 19 +-
.../engine/event/WorkflowFinalizeEvent.java | 16 +-
.../event/WorkflowFinalizeEventOperator.java | 41 +++
.../workflow/engine/event/WorkflowFinishEvent.java | 21 +-
.../engine/event/WorkflowOperationEvent.java | 51 ++++
.../event/WorkflowOperationEventOperator.java | 84 ++++++
.../engine/event/WorkflowOperationType.java | 20 +-
.../WorkflowExecuteRunnableNotFoundException.java | 12 +-
.../workflow/engine/utils/ExceptionUtils.java | 10 +-
.../workflow/IEventfulExecutionRunnable.java | 16 +-
.../engine/workflow/ITaskExecutionContext.java | 8 +-
.../workflow/ITaskExecutionContextFactory.java | 9 +-
.../engine/workflow/ITaskExecutionRunnable.java | 59 +++++
.../workflow/ITaskExecutionRunnableFactory.java | 25 +-
.../workflow/ITaskExecutionRunnableRepository.java | 18 +-
.../workflow/engine/workflow/ITaskInstance.java | 10 +-
.../IWorkflowExecuteRunnableRepository.java | 17 +-
.../engine/workflow/IWorkflowExecutionContext.java | 20 +-
.../engine/workflow/IWorkflowExecutionDAG.java | 71 ++++++
.../workflow/IWorkflowExecutionDAGFactory.java | 8 +-
.../workflow/IWorkflowExecutionRunnable.java | 56 ++++
.../IWorkflowExecutionRunnableFactory.java | 8 +-
.../engine/workflow/IWorkflowInstance.java | 10 +-
...SingletonWorkflowExecuteRunnableRepository.java | 61 +++++
.../engine/workflow/TaskExecutionContext.java | 14 +-
.../workflow/TaskExecutionContextFactory.java | 11 +-
.../engine/workflow/TaskExecutionRunnable.java | 39 ++-
.../workflow/TaskExecutionRunnableFactory.java | 35 +++
.../engine/workflow/WorkflowExecutionContext.java | 23 +-
.../engine/workflow/WorkflowExecutionDAG.java | 124 +++++++++
.../engine/workflow/WorkflowExecutionRunnable.java | 64 +++++
.../workflow/WorkflowExecutionRunnableFactory.java | 18 +-
.../workflow/engine/workflow/WorkflowInstance.java | 20 +-
...orkflowExecuteRunnableRepositoryAssertions.java | 37 +++
.../engine/assertions/WorkflowDAGAssertion.java | 173 +++++++++++++
.../WorkflowExecutionRunnableAssertions.java | 49 ++++
.../workflow/engine/dag/DAGNodeTest.java | 104 ++++++++
.../engine/dag/WorkflowDAGBuilderTest.java | 260 +++++++++++++++++++
.../workflow/engine/engine/WorkflowEngineIT.java | 8 +-
.../workflow/engine/engine/WorkflowEngineTest.java | 105 ++++++++
.../engine/event/WorkflowOperationEventTest.java | 30 +++
.../MockWorkflowExecutionRunnableFactory.java | 46 ++++
pom.xml | 1 +
181 files changed, 6848 insertions(+), 569 deletions(-)
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java
index d8f01f473f..8075dc4091 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java
@@ -34,6 +34,7 @@ import java.util.Date;
import java.util.List;
import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -44,11 +45,10 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.google.common.base.Strings;
-/**
- * process instance
- */
-@NoArgsConstructor
@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@TableName("t_ds_process_instance")
public class ProcessInstance {
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
index 8bd12026f0..40955a8a67 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
@@ -27,6 +27,9 @@ public interface ProcessTaskRelationLogDao extends IDao<ProcessTaskRelationLog>
List<ProcessTaskRelationLog> queryByWorkflowDefinitionCode(long workflowDefinitionCode);
+ List<ProcessTaskRelationLog> queryByWorkflowDefinitionCodeAndVersion(long workflowDefinitionCode,
+ int workflowDefinitionVerison);
+
void deleteByWorkflowDefinitionCode(long workflowDefinitionCode);
/**
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/ProcessTaskRelationLogDaoImpl.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/ProcessTaskRelationLogDaoImpl.java
index 81c29b89da..b800acb5c7 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/ProcessTaskRelationLogDaoImpl.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/ProcessTaskRelationLogDaoImpl.java
@@ -44,6 +44,12 @@ public class ProcessTaskRelationLogDaoImpl extends BaseDao<ProcessTaskRelationLo
return mybatisMapper.queryByProcessCode(workflowDefinitionCode);
}
+ @Override
+ public List<ProcessTaskRelationLog> queryByWorkflowDefinitionCodeAndVersion(long workflowDefinitionCode,
+ int workflowDefinitionVerison) {
+ return mybatisMapper.queryByProcessCodeAndVersion(workflowDefinitionCode, workflowDefinitionVerison);
+ }
+
@Override
public void deleteByWorkflowDefinitionCode(long workflowDefinitionCode) {
mybatisMapper.deleteByWorkflowDefinitionCode(workflowDefinitionCode);
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/BasicDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/BasicDAG.java
new file mode 100644
index 0000000000..26037eec17
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/BasicDAG.java
@@ -0,0 +1,71 @@
+/*
+ * 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.server.master.dag;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import lombok.experimental.SuperBuilder;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@SuperBuilder
+public abstract class BasicDAG implements DAG {
+
+ protected Map<String, DAGNode> dagNodeMap;
+
+ @Override
+ public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
+ final String nodeName = dagNode.getNodeName();
+ if (!dagNodeMap.containsKey(nodeName)) {
+ return Collections.emptyList();
+ }
+ DAGNode node = dagNodeMap.get(nodeName);
+ List<DAGNode> dagNodes = new ArrayList<>();
+ for (DAGEdge edge : node.getOutDegrees()) {
+ if (dagNodeMap.containsKey(edge.getToNodeName())) {
+ dagNodes.add(dagNodeMap.get(edge.getToNodeName()));
+ }
+ }
+ return dagNodes;
+ }
+
+ @Override
+ public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
+ final String nodeName = dagNode.getNodeName();
+ if (!dagNodeMap.containsKey(nodeName)) {
+ return Collections.emptyList();
+ }
+ DAGNode node = dagNodeMap.get(nodeName);
+ List<DAGNode> dagNodes = new ArrayList<>();
+ for (DAGEdge edge : node.getInDegrees()) {
+ if (dagNodeMap.containsKey(edge.getFromNodeName())) {
+ dagNodes.add(dagNodeMap.get(edge.getFromNodeName()));
+ }
+ }
+ return dagNodes;
+ }
+
+ @Override
+ public DAGNode getDAGNode(String nodeName) {
+ return dagNodeMap.get(nodeName);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAG.java
new file mode 100644
index 0000000000..40dee4f119
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAG.java
@@ -0,0 +1,146 @@
+/*
+ * 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.server.master.dag;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * The Directed Acyclic Graph class.
+ * <p>
+ * The DAG is a directed graph, which contains the nodes and the edges, the nodeName is the unique identifier of the node.
+ * The nodes are the tasks, the edges are the dependencies between the tasks.
+ * The DAG is acyclic, which means there is no cycle in the graph.
+ * The DAG is a directed graph, which means the edges have direction.
+ *
+ */
+public interface DAG {
+
+ /**
+ * Get the direct post node of given dagNode, if the dagNode is null, return the nodes which doesn't have inDegrees.
+ * e.g. The DAG is:
+ * <pre>
+ * {@code
+ * 1 -> 2 -> 3
+ * 4 -> 5
+ * 6
+ * }
+ * </pre>
+ * <li> The post node of 1 is 2.
+ * <li> The post node of 3 is empty.
+ * <li> The post node of null is 1,4,6.
+ *
+ * @param dagNode the node of the DAG, can be null.
+ * @return post node list, sort by priority.
+ */
+ List<DAGNode> getDirectPostNodes(DAGNode dagNode);
+
+ /**
+ * Same with {@link #getDirectPostNodes(DAGNode)}.
+ * <p>
+ * If the dagNodeName is null, return the nodes which doesn't have inDegrees. Otherwise, return the post nodes of
+ * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return post task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<DAGNode> getDirectPostNodes(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPostNodes(dagNode);
+ }
+
+ /**
+ * Same with {@link #getDirectPostNodes(String)}. Return the post node names.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return post task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<String> getDirectPostNodeNames(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPostNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the direct pre node of given dagNode, if the dagNode is null, return the nodes which doesn't have outDegrees.
+ * e.g. The DAG is:
+ * <pre>
+ * {@code
+ * 1 -> 2 -> 3
+ * 4 -> 5
+ * 6
+ * }
+ * </pre>
+ * <li> The pre node of 1 is empty.
+ * <li> The pre node of 3 is 2.
+ * <li> The pre node of null is 3,5,6.
+ *
+ * @param dagNode the node of the DAG, can be null.
+ * @return pre node list, sort by priority.
+ */
+ List<DAGNode> getDirectPreNodes(DAGNode dagNode);
+
+ /**
+ * Same with {@link #getDirectPreNodes(DAGNode)}.
+ * <p>
+ * If the dagNodeName is null, return the nodes which doesn't have outDegrees. Otherwise, return the pre nodes of
+ * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return pre task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<DAGNode> getDirectPreNodes(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPreNodes(dagNode);
+ }
+
+ /**
+ * Same with {@link #getDirectPreNodes(String)}. Return the pre node names.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return pre task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<String> getDirectPreNodeNames(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPreNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the node of the DAG by the node name.
+ *
+ * @param nodeName the node name.
+ * @return the node of the DAG, return null if cannot find the node.
+ */
+ DAGNode getDAGNode(String nodeName);
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEdge.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEdge.java
new file mode 100644
index 0000000000..d3ede91fef
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEdge.java
@@ -0,0 +1,51 @@
+/*
+ * 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.server.master.dag;
+
+import lombok.Builder;
+import lombok.Data;
+
+/**
+ * The edge of the DAG.
+ * <p>
+ * The edge contains the fromNodeName and the toNodeName, the fromNodeName is the node name of the from node, the toNodeName is the node name of the to node.
+ * <p>
+ * The formNodeName can be null, which means the edge is from the start node of the DAG.
+ * The toNodeName can be null, which means the edge is to the end node of the DAG.
+ * The fromNodeName and the toNodeName cannot be null at the same time.
+ */
+@Data
+@Builder
+public class DAGEdge {
+
+ private String fromNodeName;
+ private String toNodeName;
+
+ public DAGEdge(String fromNodeName, String toNodeName) {
+ if (fromNodeName == null && toNodeName == null) {
+ throw new IllegalArgumentException("fromNodeName and toNodeName cannot be null at the same time"
+ + "fromNodeName: " + fromNodeName + ", toNodeName: " + toNodeName);
+ }
+ if (fromNodeName != null && fromNodeName.equals(toNodeName)) {
+ throw new IllegalArgumentException("fromNodeName and toNodeName cannot be the same"
+ + "fromNodeName: " + fromNodeName + ", toNodeName: " + toNodeName);
+ }
+ this.fromNodeName = fromNodeName;
+ this.toNodeName = toNodeName;
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngine.java
new file mode 100644
index 0000000000..cf1daca1f7
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngine.java
@@ -0,0 +1,148 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.server.master.events.TaskOperationEvent;
+import org.apache.dolphinscheduler.server.master.events.TaskOperationType;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DAGEngine implements IDAGEngine {
+
+ private final IWorkflowExecutionContext workflowExecutionContext;
+
+ public DAGEngine(IWorkflowExecutionContext workflowExecutionContext) {
+ this.workflowExecutionContext = workflowExecutionContext;
+ }
+
+ @Override
+ public void triggerNextTasks(String parentTaskNodeName) {
+ workflowExecutionContext.getWorkflowExecutionDAG()
+ .getDirectPostNodeNames(parentTaskNodeName)
+ .forEach(this::triggerTask);
+ }
+
+ @Override
+ public void triggerTask(String taskName) {
+ IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
+ DAGNode dagNode = workflowExecutionDAG.getDAGNode(taskName);
+ if (dagNode == null) {
+ log.error("Cannot find the DAGNode for task: {}", taskName);
+ return;
+ }
+ // Use condition check?
+ if (!workflowExecutionDAG.isTaskAbleToBeTriggered(taskName)) {
+ log.info("The task: {} is not able to be triggered", taskName);
+ return;
+ }
+
+ if (dagNode.isSkip()) {
+ log.info("The task: {} is skipped", taskName);
+ triggerNextTasks(taskName);
+ return;
+ }
+
+ TaskExecutionRunnable taskExecutionRunnable = workflowExecutionDAG.triggerTask(taskName);
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.RUN)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void failoverTask(Integer taskInstanceId) {
+ TaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.FAILOVER)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void retryTask(Integer taskInstanceId) {
+ TaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.RETRY)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void pauseAllTask() {
+ workflowExecutionContext.getWorkflowExecutionDAG()
+ .getActiveTaskExecutionRunnable()
+ .stream()
+ .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
+ .forEach(this::pauseTask);
+ }
+
+ @Override
+ public void pauseTask(Integer taskInstanceId) {
+ TaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.PAUSE)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void killAllTask() {
+ workflowExecutionContext.getWorkflowExecutionDAG()
+ .getActiveTaskExecutionRunnable()
+ .stream()
+ .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
+ .forEach(this::killTask);
+ }
+
+ @Override
+ public void killTask(Integer taskInstanceId) {
+ TaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.KILL)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngineFactory.java
similarity index 68%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngineFactory.java
index ac37c94438..43b1a3e5c0 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngineFactory.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.extern.slf4j.Slf4j;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class DAGEngineFactory implements IDAGEngineFactory {
+ @Override
+ public IDAGEngine createDAGEngine(IWorkflowExecutionContext workflowExecutionContext) {
+ return new DAGEngine(workflowExecutionContext);
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGNode.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGNode.java
new file mode 100644
index 0000000000..95bd6c75ba
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGNode.java
@@ -0,0 +1,92 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+/**
+ * The node of the DAG.
+ * <p>
+ * The node contains the node name, the content of the node, the inDegrees and the outDegrees.
+ * The inDegrees is the edge from other nodes to the current node, the outDegrees is the edge from the current
+ * node to other nodes.
+ */
+@Getter
+@Builder
+@NoArgsConstructor
+public class DAGNode {
+
+ private String nodeName;
+
+ /**
+ * whether the node is skipped, default is false, which means the node is not skipped.
+ * If the node is skipped, the node will not be executed.
+ */
+ @Builder.Default
+ private boolean skip = false;
+
+ private List<DAGEdge> inDegrees;
+ private List<DAGEdge> outDegrees;
+
+ public DAGNode(String nodeName,
+ List<DAGEdge> inDegrees,
+ List<DAGEdge> outDegrees) {
+ this(nodeName, false, inDegrees, outDegrees);
+ }
+
+ public DAGNode(String nodeName,
+ boolean skip,
+ List<DAGEdge> inDegrees,
+ List<DAGEdge> outDegrees) {
+ if (StringUtils.isEmpty(nodeName)) {
+ throw new IllegalArgumentException("nodeName cannot be empty");
+ }
+
+ if (CollectionUtils.isNotEmpty(inDegrees)) {
+ inDegrees.forEach(dagEdge -> {
+ if (!nodeName.equals(dagEdge.getToNodeName())) {
+ throw new IllegalArgumentException(
+ "The toNodeName of inDegree should be the nodeName of the node: "
+ + nodeName + ", inDegree: " + dagEdge);
+ }
+ });
+ }
+
+ if (CollectionUtils.isNotEmpty(outDegrees)) {
+ outDegrees.forEach(dagEdge -> {
+ if (!nodeName.equals(dagEdge.getFromNodeName())) {
+ throw new IllegalArgumentException(
+ "The fromNodeName of outDegree should be the nodeName of the node: "
+ + nodeName + ", outDegree: " + dagEdge);
+ }
+ });
+ }
+
+ this.nodeName = nodeName;
+ this.inDegrees = inDegrees;
+ this.outDegrees = outDegrees;
+ this.skip = skip;
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngine.java
new file mode 100644
index 0000000000..7adc2d9a1e
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngine.java
@@ -0,0 +1,70 @@
+/*
+ * 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.server.master.dag;
+
+/**
+ * The IDAGEngine is responsible for triggering, killing, pausing, and finalizing task in {@link IWorkflowExecutionDAG}.
+ * <p>All DAG operation should directly use the method in IDAGEngine, new {@link IWorkflowExecutionDAG} should be triggered by new IDAGEngine.
+ */
+public interface IDAGEngine {
+
+ /**
+ * Trigger the tasks which are post of the given task.
+ * <P> If there are no task after the given taskNode, will try to finish the WorkflowExecutionRunnable.
+ * <p> If the
+ *
+ * @param parentTaskNodeName the parent task name
+ */
+ void triggerNextTasks(String parentTaskNodeName);
+
+ /**
+ * Trigger the given task
+ *
+ * @param taskName task name
+ */
+ void triggerTask(String taskName);
+
+ /**
+ * Failover the given task.
+ *
+ * @param taskInstanceId taskInstanceId
+ */
+ void failoverTask(Integer taskInstanceId);
+
+ /**
+ * Retry the given task.
+ *
+ * @param taskInstanceId taskInstanceId
+ */
+ void retryTask(Integer taskInstanceId);
+
+ void pauseAllTask();
+
+ /**
+ * Pause the given task.
+ */
+ void pauseTask(Integer taskInstanceId);
+
+ void killAllTask();
+
+ /**
+ * Kill the given task.
+ */
+ void killTask(Integer taskId);
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngineFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngineFactory.java
index ac37c94438..0ae555ea8d 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngineFactory.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IDAGEngineFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ IDAGEngine createDAGEngine(IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGNodeAction.java
similarity index 76%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGNodeAction.java
index ac37c94438..70148bd737 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGNodeAction.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+/**
+ * The IDAGNodeAction represent the action of a DAG node.
+ */
+public interface IDAGNodeAction {
+
+ void run();
+
+ void kill();
+
+ void pause();
+
+ void success();
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ void failure();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventRepositoryFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventRepositoryFactory.java
index ac37c94438..630d412856 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventRepositoryFactory.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.server.master.events.IEventRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface IEventRepositoryFactory {
+
+ IEventRepository createEventRepository();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventfulExecutionRunnable.java
similarity index 62%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventfulExecutionRunnable.java
index ac37c94438..952fa23120 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventfulExecutionRunnable.java
@@ -15,12 +15,20 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.server.master.events.IEvent;
+import org.apache.dolphinscheduler.server.master.events.IEventRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+public interface IEventfulExecutionRunnable {
+
+ IEventRepository getEventRepository();
+
+ default void storeEventToTail(IEvent event) {
+ getEventRepository().storeEventToTail(event);
}
+ default void storeEventToHead(IEvent event) {
+ getEventRepository().storeEventToHead(event);
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContext.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContext.java
index ac37c94438..818cbd0e10 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContext.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface ITaskExecutionContext {
+
+ TaskInstance getTaskInstance();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContextFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContextFactory.java
index ac37c94438..7c67307371 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContextFactory.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface ITaskExecutionContextFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ ITaskExecutionContext createTaskExecutionContext();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnable.java
new file mode 100644
index 0000000000..dceff535c5
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnable.java
@@ -0,0 +1,59 @@
+/*
+ * 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.server.master.dag;
+
+/**
+ * The TaskExecutionRunnable represent the running task, it is responsible for operate the task instance. e.g. dispatch, kill, pause.
+ */
+public interface ITaskExecutionRunnable {
+
+ /**
+ * Dispatch the task instance.
+ */
+ void dispatch();
+
+ /**
+ * Run the task instance.
+ */
+ void run();
+
+ /**
+ * Kill the task instance.
+ */
+ void kill();
+
+ /**
+ * Pause the task instance.
+ */
+ void pause();
+
+ /**
+ * Get the task execution context.
+ *
+ * @return the task execution context
+ */
+ TaskExecutionContext getTaskExecutionContext();
+
+ /**
+ * Determine whether the current task can be accessed to the post task.
+ *
+ * @param taskNodeName post task name
+ * @return true if the current task can be accessed to the post task.
+ */
+ boolean canAccessTo(String taskNodeName);
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableFactory.java
index ac37c94438..d1d2cf1ae9 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableFactory.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface ITaskExecutionRunnableFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ TaskExecutionRunnable createTaskExecutionRunnable(ITaskExecutionContext taskExecutionContext);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepository.java
similarity index 60%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepository.java
index ac37c94438..094b752cf1 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepository.java
@@ -15,12 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.Collection;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface ITaskExecutionRunnableRepository {
+ void storeTaskExecutionRunnable(TaskExecutionRunnable taskExecutionRunnable);
+
+ TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId);
+
+ TaskExecutionRunnable getTaskExecutionRunnableByName(String taskInstanceName);
+
+ Collection<TaskExecutionRunnable> getActiveTaskExecutionRunnable();
+
+ void removeTaskExecutionRunnable(Integer taskInstanceId);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepositoryFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepositoryFactory.java
index ac37c94438..6e237a2b06 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepositoryFactory.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface ITaskExecutionRunnableRepositoryFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ TaskExecutionRunnableRepository createTaskExecutionRunnableRepository();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAG.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAG.java
index ac37c94438..fca3010035 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAG.java
@@ -15,12 +15,11 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+/**
+ * The IWorkflowDAG represent the DAG of a workflow.
+ */
+public interface IWorkflowDAG extends DAG {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAGFactory.java
similarity index 65%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAGFactory.java
index ac37c94438..00c9e237da 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAGFactory.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+/**
+ * The Factory used to create {@link IWorkflowDAG}
+ */
+public interface IWorkflowDAGFactory {
+
+ /**
+ * Create the WorkflowDAG
+ *
+ * @param workflowInstance workflowInstance.
+ * @return workflow DAG.
+ */
+ IWorkflowDAG createWorkflowDAG(ProcessInstance workflowInstance);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowEngine.java
new file mode 100644
index 0000000000..0c3f38dce9
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowEngine.java
@@ -0,0 +1,57 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.server.master.exception.WorkflowExecuteRunnableNotFoundException;
+
+/**
+ * The WorkflowEngine is responsible for starting, stopping, pausing, and finalizing workflows.
+ */
+public interface IWorkflowEngine {
+
+ /**
+ * Trigger a workflow to start.
+ *
+ * @param workflowExecuteRunnable the workflow to start
+ */
+ void triggerWorkflow(IWorkflowExecutionRunnable workflowExecuteRunnable);
+
+ /**
+ * Pause a workflow instance.
+ *
+ * @param workflowInstanceId the ID of the workflow to pause
+ * @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
+ */
+ void pauseWorkflow(Integer workflowInstanceId);
+
+ /**
+ * Kill a workflow instance.
+ *
+ * @param workflowInstanceId the ID of the workflow to stop
+ * @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
+ */
+ void killWorkflow(Integer workflowInstanceId);
+
+ /**
+ * Finalize a workflow instance. Once a workflow has been finalized, then it cannot receive new operation, and will be removed from memory.
+ *
+ * @param workflowInstanceId the ID of the workflow to finalize
+ */
+ void finalizeWorkflow(Integer workflowInstanceId);
+
+}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionContext.java
similarity index 53%
copy from dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionContext.java
index 8bd12026f0..53bcf3555b 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionContext.java
@@ -15,25 +15,32 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.dao.repository;
+package org.apache.dolphinscheduler.server.master.dag;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
-
-import org.apache.ibatis.annotations.Param;
+import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.server.master.events.IEventRepository;
import java.util.List;
-public interface ProcessTaskRelationLogDao extends IDao<ProcessTaskRelationLog> {
+public interface IWorkflowExecutionContext {
+
+ IWorkflowExecutionDAG getWorkflowExecutionDAG();
+
+ ProcessInstance getWorkflowInstance();
+
+ ProcessDefinition getWorkflowDefinition();
+
+ List<String> getBeginNodeNames();
+
+ IEventRepository getEventRepository();
- List<ProcessTaskRelationLog> queryByWorkflowDefinitionCode(long workflowDefinitionCode);
+ default int getWorkflowInstanceId() {
+ return getWorkflowInstance().getId();
+ }
- void deleteByWorkflowDefinitionCode(long workflowDefinitionCode);
+ default String getWorkflowInstanceName() {
+ return getWorkflowInstance().getName();
+ }
- /**
- * batch insert process task relation
- *
- * @param taskRelationList taskRelationList
- * @return int
- */
- int batchInsert(@Param("taskRelationList") List<ProcessTaskRelationLog> taskRelationList);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAG.java
new file mode 100644
index 0000000000..33e597cf2e
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAG.java
@@ -0,0 +1,74 @@
+/*
+ * 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.server.master.dag;
+
+import java.util.List;
+
+/**
+ * The WorkflowExecutionDAG represent the running workflow DAG.
+ */
+public interface IWorkflowExecutionDAG extends DAG {
+
+ /**
+ * Trigger the taskNode by given taskName.
+ *
+ * @param taskName taskNodeName
+ * @return TaskExecutionRunnable
+ */
+ TaskExecutionRunnable triggerTask(String taskName);
+
+ /**
+ * Get TaskExecutionRunnable by given TaskInstanceId.
+ *
+ * @param taskInstanceId taskInstanceId.
+ * @return TaskExecutionRunnable
+ */
+ TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId);
+
+ /**
+ * Get TaskExecutionRunnable by given taskName.
+ *
+ * @param taskName task name.
+ * @return TaskExecutionRunnable
+ */
+ TaskExecutionRunnable getTaskExecutionRunnableByName(String taskName);
+
+ /**
+ * Get TaskExecutionRunnable which is not finished.
+ *
+ * @return TaskExecutionRunnable
+ */
+ List<TaskExecutionRunnable> getActiveTaskExecutionRunnable();
+
+ /**
+ * Get the direct pre TaskExecutionRunnable of the given taskName.
+ *
+ * @param taskName task name.
+ * @return TaskExecutionRunnable
+ */
+ List<TaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName);
+
+ /**
+ * Check whether the taskNode is ready to run.
+ *
+ * @param taskName taskNodeName
+ * @return true if the taskNode is ready to run.
+ */
+ boolean isTaskAbleToBeTriggered(String taskName);
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAGFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAGFactory.java
index ac37c94438..429987ca1f 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAGFactory.java
@@ -15,12 +15,9 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface IWorkflowExecutionDAGFactory {
+ IWorkflowExecutionDAG createWorkflowExecutionDAG();
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionRunnable.java
similarity index 50%
copy from dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionRunnable.java
index 8bd12026f0..d0a641239d 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionRunnable.java
@@ -15,25 +15,40 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.dao.repository;
+package org.apache.dolphinscheduler.server.master.dag;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
-
-import org.apache.ibatis.annotations.Param;
+/**
+ * The IWorkflowExecuteRunnable represent a running workflow instance, it is responsible for operate the workflow instance. e.g. start, kill, pause.
+ */
+public interface IWorkflowExecutionRunnable extends IEventfulExecutionRunnable {
-import java.util.List;
+ /**
+ * Start the workflow instance.
+ */
+ void start();
-public interface ProcessTaskRelationLogDao extends IDao<ProcessTaskRelationLog> {
+ /**
+ * Kill the workflow instance.
+ */
+ void kill();
- List<ProcessTaskRelationLog> queryByWorkflowDefinitionCode(long workflowDefinitionCode);
+ /**
+ * Pause the workflow instance.
+ */
+ void pause();
- void deleteByWorkflowDefinitionCode(long workflowDefinitionCode);
+ /**
+ * Get the workflow execution context.
+ *
+ * @return the workflow execution context
+ */
+ IWorkflowExecutionContext getWorkflowExecutionContext();
/**
- * batch insert process task relation
+ * Get the {@link IDAGEngine} which used to execute the dag of the workflow instance.
*
- * @param taskRelationList taskRelationList
- * @return int
+ * @return dag engine.
*/
- int batchInsert(@Param("taskRelationList") List<ProcessTaskRelationLog> taskRelationList);
+ IDAGEngine getDagEngine();
+
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/MemoryEventRepositoryFactory.java
similarity index 61%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/MemoryEventRepositoryFactory.java
index ac37c94438..e61351f472 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/MemoryEventRepositoryFactory.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.server.master.events.IEventRepository;
+import org.apache.dolphinscheduler.server.master.events.MemoryEventRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+@Slf4j
+@Component
+public class MemoryEventRepositoryFactory implements IEventRepositoryFactory {
+
+ @Override
+ public IEventRepository createEventRepository() {
+ return new MemoryEventRepository();
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionContext.java
similarity index 67%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionContext.java
index ac37c94438..bf079e861f 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionContext.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class TaskExecutionContext implements ITaskExecutionContext {
+
+ private TaskInstance taskInstance;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnable.java
similarity index 53%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnable.java
index ac37c94438..0f21592b26 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnable.java
@@ -15,12 +15,42 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.Builder;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+@Slf4j
+@Getter
+@Builder
+public class TaskExecutionRunnable implements ITaskExecutionRunnable {
+
+ private TaskExecutionContext taskExecutionContext;
+
+ @Override
+ public void dispatch() {
+ // todo: check if the operation is valid
+ }
+
+ @Override
+ public void run() {
+
+ }
+
+ @Override
+ public void kill() {
+ // todo: check if the operation is valid
+ }
+
+ @Override
+ public void pause() {
+ // todo: check if the operation is valid
+ }
+
+ @Override
+ public boolean canAccessTo(String postTaskNodeName) {
+ return false;
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepository.java
new file mode 100644
index 0000000000..eb8799c212
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepository.java
@@ -0,0 +1,68 @@
+/*
+ * 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.server.master.dag;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+/**
+ * Use to store the TaskExecutionRunnable of a DAG.
+ */
+public class TaskExecutionRunnableRepository implements ITaskExecutionRunnableRepository {
+
+ private final Map<Integer, TaskExecutionRunnable> taskExecuteRunnableMap = new ConcurrentHashMap<>();
+
+ private final Map<String, TaskExecutionRunnable> taskExecuteRunnableNameMap = new ConcurrentHashMap<>();
+
+ @Override
+ public void storeTaskExecutionRunnable(TaskExecutionRunnable taskExecutionRunnable) {
+ taskExecuteRunnableMap.put(taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId(),
+ taskExecutionRunnable);
+ taskExecuteRunnableNameMap.put(taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getName(),
+ taskExecutionRunnable);
+ }
+
+ public TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId) {
+ return taskExecuteRunnableMap.get(taskInstanceId);
+ }
+
+ @Override
+ public TaskExecutionRunnable getTaskExecutionRunnableByName(String taskInstanceName) {
+ return taskExecuteRunnableNameMap.get(taskInstanceName);
+ }
+
+ public Collection<TaskExecutionRunnable> getActiveTaskExecutionRunnable() {
+ return taskExecuteRunnableMap.values()
+ .stream()
+ .filter(taskExecutionRunnable -> {
+ return taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getState().isRunning();
+ })
+ .collect(Collectors.toList());
+ }
+
+ public void removeTaskExecutionRunnable(Integer taskInstanceId) {
+ TaskExecutionRunnable taskExecutionRunnable = taskExecuteRunnableMap.remove(taskInstanceId);
+ if (taskExecutionRunnable != null) {
+ taskExecuteRunnableNameMap
+ .remove(taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getName());
+ }
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepositoryFactory.java
similarity index 66%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepositoryFactory.java
index ac37c94438..55ff26916d 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepositoryFactory.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.extern.slf4j.Slf4j;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class TaskExecutionRunnableRepositoryFactory implements ITaskExecutionRunnableRepositoryFactory {
+
+ public TaskExecutionRunnableRepository createTaskExecutionRunnableRepository() {
+ return new TaskExecutionRunnableRepository();
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionValve.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionValve.java
index ac37c94438..2bf015992d 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionValve.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+/**
+ * Used to judge whether the task can be executed.
+ */
+public interface TaskExecutionValve {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ boolean canOpen(TaskExecutionRunnable preTask, String postTask);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskIdentify.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskIdentify.java
index ac37c94438..d9dd0d0b1c 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskIdentify.java
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public class TaskIdentify {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAG.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAG.java
index ac37c94438..c48785b795 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAG.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.experimental.SuperBuilder;
+import lombok.extern.slf4j.Slf4j;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Slf4j
+@SuperBuilder
+public class WorkflowDAG extends BasicDAG implements IWorkflowDAG {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilder.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilder.java
new file mode 100644
index 0000000000..1906afc7fb
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilder.java
@@ -0,0 +1,125 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.common.enums.Flag;
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Used to build WorkflowDAG, you need to add TaskNode first, then add TaskEdge.
+ * After adding all the TaskNodes and TaskEdges, you can call the build method to get the WorkflowDAG.
+ * <p>
+ * Example:
+ * <pre>
+ * {@code
+ * WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ * .addTaskNode(taskNodeA)
+ * .addTaskNode(taskNodeB)
+ * .addTaskNode(taskNodeC)
+ * .addTaskEdge(edgeAB)
+ * .addTaskEdge(edgeBC)
+ * .build();
+ * }
+ * </pre>
+ */
+public class WorkflowDAGBuilder {
+
+ private final Map<String, DAGNode> taskNameMap;
+
+ private final Map<Long, DAGNode> taskCodeMap;
+
+ private WorkflowDAGBuilder() {
+ this.taskCodeMap = new HashMap<>();
+ this.taskNameMap = new HashMap<>();
+ }
+
+ public static WorkflowDAGBuilder newBuilder() {
+ return new WorkflowDAGBuilder();
+ }
+
+ public WorkflowDAGBuilder addTaskNodes(List<TaskDefinitionLog> taskDefinitionList) {
+ taskDefinitionList.forEach(this::addTaskNode);
+ return this;
+ }
+
+ public WorkflowDAGBuilder addTaskNode(TaskDefinitionLog taskDefinition) {
+ String taskName = taskDefinition.getName();
+ long taskCode = taskDefinition.getCode();
+ if (taskCodeMap.containsKey(taskCode)) {
+ throw new IllegalArgumentException("TaskNode with code " + taskCode + " already exists");
+ }
+ if (taskNameMap.containsKey(taskName)) {
+ throw new IllegalArgumentException("TaskNode with name " + taskName + " already exists");
+ }
+
+ DAGNode taskNode = DAGNode.builder()
+ .nodeName(taskName)
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .skip(Flag.NO.equals(taskDefinition.getFlag()))
+ .build();
+ taskNameMap.put(taskName, taskNode);
+ taskCodeMap.put(taskCode, taskNode);
+ return this;
+ }
+
+ public WorkflowDAGBuilder addTaskEdges(List<ProcessTaskRelationLog> processTaskRelations) {
+ processTaskRelations.forEach(this::addTaskEdge);
+ return this;
+ }
+
+ public WorkflowDAGBuilder addTaskEdge(ProcessTaskRelationLog processTaskRelation) {
+ long preTaskCode = processTaskRelation.getPreTaskCode();
+ long postTaskCode = processTaskRelation.getPostTaskCode();
+
+ if (taskCodeMap.containsKey(preTaskCode)) {
+ DAGNode fromTask = taskCodeMap.get(preTaskCode);
+ if (taskCodeMap.containsKey(postTaskCode)) {
+ DAGNode toTask = taskCodeMap.get(postTaskCode);
+ DAGEdge edge = DAGEdge.builder()
+ .fromNodeName(fromTask.getNodeName())
+ .toNodeName(toTask.getNodeName())
+ .build();
+ if (fromTask.getOutDegrees().contains(edge)) {
+ throw new IllegalArgumentException(
+ "Edge from " + fromTask.getNodeName() + " to " + toTask.getNodeName() + " already exists");
+ }
+ fromTask.getOutDegrees().add(edge);
+ if (toTask.getInDegrees().contains(edge)) {
+ throw new IllegalArgumentException(
+ "Edge from " + fromTask.getNodeName() + " to " + toTask.getNodeName() + " already exists");
+ }
+ toTask.getInDegrees().add(edge);
+ }
+ }
+ return this;
+ }
+
+ public WorkflowDAG build() {
+ return WorkflowDAG.builder()
+ .dagNodeMap(taskNameMap)
+ .build();
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGFactory.java
new file mode 100644
index 0000000000..de743c2851
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGFactory.java
@@ -0,0 +1,65 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
+import org.apache.dolphinscheduler.dao.repository.ProcessTaskRelationLogDao;
+import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao;
+
+import java.util.List;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowDAGFactory implements IWorkflowDAGFactory {
+
+ @Autowired
+ private TaskDefinitionLogDao taskDefinitionLogDao;
+
+ @Autowired
+ private ProcessTaskRelationLogDao processTaskRelationLogDao;
+
+ @Override
+ public IWorkflowDAG createWorkflowDAG(ProcessInstance processInstance) {
+ Long workflowDefinitionCode = processInstance.getProcessDefinitionCode();
+ Integer workflowDefinitionVersion = processInstance.getProcessDefinitionVersion();
+ List<TaskDefinitionLog> taskDefinitions = queryTaskNodes(workflowDefinitionCode, workflowDefinitionVersion);
+ List<ProcessTaskRelationLog> taskRelations = queryTaskEdges(workflowDefinitionCode, workflowDefinitionVersion);
+ return WorkflowDAGBuilder.newBuilder()
+ .addTaskNodes(taskDefinitions)
+ .addTaskEdges(taskRelations)
+ .build();
+ }
+
+ private List<TaskDefinitionLog> queryTaskNodes(Long workflowDefinitionCode, Integer workflowDefinitionVersion) {
+ return taskDefinitionLogDao.queryByWorkflowDefinitionCodeAndVersion(workflowDefinitionCode,
+ workflowDefinitionVersion);
+ }
+
+ private List<ProcessTaskRelationLog> queryTaskEdges(Long workflowDefinitionCode,
+ Integer workflowDefinitionVersion) {
+ return processTaskRelationLogDao.queryByWorkflowDefinitionCodeAndVersion(workflowDefinitionCode,
+ workflowDefinitionVersion);
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngine.java
new file mode 100644
index 0000000000..550c837ffc
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngine.java
@@ -0,0 +1,82 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.server.master.events.WorkflowOperationEvent;
+import org.apache.dolphinscheduler.server.master.exception.WorkflowExecuteRunnableNotFoundException;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowEngine implements IWorkflowEngine {
+
+ private final WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ public WorkflowEngine(WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ }
+
+ @Override
+ public void triggerWorkflow(IWorkflowExecutionRunnable workflowExecuteRunnable) {
+ IWorkflowExecutionContext workflowExecutionContext = workflowExecuteRunnable.getWorkflowExecutionContext();
+ Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
+ log.info("Triggering WorkflowExecutionRunnable: {}", workflowExecutionContext.getWorkflowInstanceName());
+ workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(workflowExecuteRunnable);
+ workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.triggerEvent(workflowInstanceId));
+ }
+
+ @Override
+ public void pauseWorkflow(Integer workflowInstanceId) {
+ IWorkflowExecutionRunnable workflowExecuteRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ if (workflowExecuteRunnable == null) {
+ throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
+ }
+ log.info("Pausing WorkflowExecutionRunnable: {}",
+ workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
+ workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.pauseEvent(workflowInstanceId));
+ }
+
+ @Override
+ public void killWorkflow(Integer workflowInstanceId) {
+ IWorkflowExecutionRunnable workflowExecuteRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ if (workflowExecuteRunnable == null) {
+ throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
+ }
+ log.info("Killing WorkflowExecutionRunnable: {}",
+ workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
+ workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.killEvent(workflowInstanceId));
+ }
+
+ @Override
+ public void finalizeWorkflow(Integer workflowInstanceId) {
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ if (workflowExecutionRunnable == null) {
+ return;
+ }
+ log.info("Finalizing WorkflowExecutionRunnable: {}",
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
+ workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecuteRunnableRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecuteRunnableRepository.java
new file mode 100644
index 0000000000..78beaa44e7
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecuteRunnableRepository.java
@@ -0,0 +1,52 @@
+/*
+ * 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.server.master.dag;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowExecuteRunnableRepository {
+
+ private final Map<Integer, IWorkflowExecutionRunnable> workflowExecutionRunnableMap = new ConcurrentHashMap<>();
+
+ public void storeWorkflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ workflowExecutionRunnableMap.put(
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceId(),
+ workflowExecutionRunnable);
+ }
+
+ public IWorkflowExecutionRunnable getWorkflowExecutionRunnableById(Integer workflowInstanceId) {
+ return workflowExecutionRunnableMap.get(workflowInstanceId);
+ }
+
+ public Collection<IWorkflowExecutionRunnable> getActiveWorkflowExecutionRunnable() {
+ return workflowExecutionRunnableMap.values();
+ }
+
+ public void removeWorkflowExecutionRunnable(Integer workflowInstanceId) {
+ workflowExecutionRunnableMap.remove(workflowInstanceId);
+ }
+
+}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContext.java
similarity index 52%
copy from dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContext.java
index 8bd12026f0..be9c165882 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContext.java
@@ -15,25 +15,33 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.dao.repository;
+package org.apache.dolphinscheduler.server.master.dag;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
-
-import org.apache.ibatis.annotations.Param;
+import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.server.master.events.IEventRepository;
import java.util.List;
-public interface ProcessTaskRelationLogDao extends IDao<ProcessTaskRelationLog> {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowExecutionContext implements IWorkflowExecutionContext {
+
+ private ProcessDefinition workflowDefinition;
+
+ private ProcessInstance workflowInstance;
+
+ private List<String> beginNodeNames;
- List<ProcessTaskRelationLog> queryByWorkflowDefinitionCode(long workflowDefinitionCode);
+ private IWorkflowExecutionDAG workflowExecutionDAG;
- void deleteByWorkflowDefinitionCode(long workflowDefinitionCode);
+ private IEventRepository eventRepository;
- /**
- * batch insert process task relation
- *
- * @param taskRelationList taskRelationList
- * @return int
- */
- int batchInsert(@Param("taskRelationList") List<ProcessTaskRelationLog> taskRelationList);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContextFactory.java
similarity index 71%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContextFactory.java
index ac37c94438..69ad93b106 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContextFactory.java
@@ -15,12 +15,17 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.dao.entity.Command;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import org.springframework.stereotype.Component;
+
+@Component
+public class WorkflowExecutionContextFactory {
+
+ public WorkflowExecutionContext createWorkflowExecutionContext(Command command) {
+ return null;
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAG.java
new file mode 100644
index 0000000000..86c690d44f
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAG.java
@@ -0,0 +1,116 @@
+/*
+ * 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.server.master.dag;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import lombok.experimental.SuperBuilder;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * The WorkflowExecutionDAG represent a running workflow instance DAG.
+ */
+@Slf4j
+@SuperBuilder
+public class WorkflowExecutionDAG implements IWorkflowExecutionDAG {
+
+ private final ITaskExecutionContextFactory taskExecutionContextFactory;
+
+ private final ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
+
+ private final TaskExecutionRunnableRepository taskExecutionRunnableRepository;
+
+ private final IWorkflowDAG workflowDAG;
+
+ @Override
+ public TaskExecutionRunnable triggerTask(String taskName) {
+ DAGNode dagNode = getDAGNode(taskName);
+ if (dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the DAGNode for task: " + taskName);
+ }
+ // Create task execution context
+ taskExecutionContextFactory.createTaskExecutionContext();
+ TaskExecutionRunnable taskExecutionRunnable = taskExecutionRunnableFactory.createTaskExecutionRunnable(null);
+ taskExecutionRunnableRepository.storeTaskExecutionRunnable(taskExecutionRunnable);
+ return taskExecutionRunnable;
+ }
+
+ @Override
+ public TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId) {
+ return taskExecutionRunnableRepository.getTaskExecutionRunnableById(taskInstanceId);
+ }
+
+ @Override
+ public TaskExecutionRunnable getTaskExecutionRunnableByName(String taskName) {
+ return taskExecutionRunnableRepository.getTaskExecutionRunnableByName(taskName);
+ }
+
+ @Override
+ public List<TaskExecutionRunnable> getActiveTaskExecutionRunnable() {
+ return new ArrayList<>(taskExecutionRunnableRepository.getActiveTaskExecutionRunnable());
+ }
+
+ @Override
+ public List<TaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName) {
+ return getDirectPreNodeNames(taskName)
+ .stream()
+ .map(taskExecutionRunnableRepository::getTaskExecutionRunnableByName)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public boolean isTaskAbleToBeTriggered(String taskNodeName) {
+ // todo: Check whether the workflow instance is finished or ready to finish.
+ List<DAGNode> directPreNodes = getDirectPreNodes(taskNodeName);
+ if (log.isDebugEnabled()) {
+ log.debug("Begin to check whether the task {} is able to be triggered.", taskNodeName);
+ log.debug("Task {} directly dependent on the task: {}.", taskNodeName,
+ directPreNodes.stream().map(DAGNode::getNodeName).collect(Collectors.toList()));
+ }
+ for (DAGNode directPreNode : directPreNodes) {
+ if (directPreNode.isSkip()) {
+ log.debug("The task {} is skipped.", directPreNode.getNodeName());
+ continue;
+ }
+ TaskExecutionRunnable taskExecutionRunnable = getTaskExecutionRunnableByName(directPreNode.getNodeName());
+ if (taskExecutionRunnable == null || taskExecutionRunnable.canAccessTo(taskNodeName)) {
+ log.debug("The task {} is not finished or not able to access to the task {}.",
+ directPreNode.getNodeName(), taskNodeName);
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
+ return workflowDAG.getDirectPostNodes(dagNode);
+ }
+
+ @Override
+ public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
+ return workflowDAG.getDirectPreNodes(dagNode);
+ }
+
+ @Override
+ public DAGNode getDAGNode(String nodeName) {
+ return workflowDAG.getDAGNode(nodeName);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAGFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAGFactory.java
new file mode 100644
index 0000000000..fa1e897c20
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAGFactory.java
@@ -0,0 +1,60 @@
+/*
+ * 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.server.master.dag;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowExecutionDAGFactory implements IWorkflowExecutionDAGFactory {
+
+ @Autowired
+ private ITaskExecutionRunnableRepositoryFactory taskExecutionRunnableRepositoryFactory;
+
+ @Autowired
+ private ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
+
+ @Autowired
+ private ITaskExecutionContextFactory taskExecutionContextFactory;
+
+ @Override
+ public IWorkflowExecutionDAG createWorkflowExecutionDAG() {
+ // todo:
+ TaskExecutionRunnableRepository taskExecutionRunnableRepository =
+ taskExecutionRunnableRepositoryFactory.createTaskExecutionRunnableRepository();
+ loadTheHistoryTaskExecutionRunnable()
+ .forEach(taskExecutionRunnableRepository::storeTaskExecutionRunnable);
+
+ return WorkflowExecutionDAG.builder()
+ .taskExecutionContextFactory(taskExecutionContextFactory)
+ .taskExecutionRunnableFactory(taskExecutionRunnableFactory)
+ .taskExecutionRunnableRepository(taskExecutionRunnableRepository)
+ .workflowDAG(null)
+ .build();
+ }
+
+ private List<TaskExecutionRunnable> loadTheHistoryTaskExecutionRunnable() {
+ return new ArrayList<>();
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnable.java
new file mode 100644
index 0000000000..1c9b4208e7
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnable.java
@@ -0,0 +1,64 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.server.master.events.IEventRepository;
+import org.apache.dolphinscheduler.server.master.events.WorkflowTriggeredEvent;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Getter
+@Builder
+@AllArgsConstructor
+public class WorkflowExecutionRunnable implements IWorkflowExecutionRunnable {
+
+ private final IWorkflowExecutionContext workflowExecutionContext;
+
+ private final IDAGEngine dagEngine;
+
+ public void start() {
+ if (CollectionUtils.isEmpty(workflowExecutionContext.getBeginNodeNames())) {
+ dagEngine.triggerNextTasks(null);
+ } else {
+ workflowExecutionContext.getBeginNodeNames().forEach(dagEngine::triggerTask);
+ }
+ getEventRepository()
+ .storeEventToTail(new WorkflowTriggeredEvent(workflowExecutionContext.getWorkflowInstance().getId()));
+ }
+
+ @Override
+ public void pause() {
+ dagEngine.pauseAllTask();
+ }
+
+ @Override
+ public void kill() {
+ dagEngine.killAllTask();
+ }
+
+ @Override
+ public IEventRepository getEventRepository() {
+ return workflowExecutionContext.getEventRepository();
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableFactory.java
similarity index 52%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableFactory.java
index ac37c94438..4d3f766725 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableFactory.java
@@ -15,12 +15,26 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.extern.slf4j.Slf4j;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowExecutionRunnableFactory {
+
+ @Autowired
+ private IDAGEngineFactory dagEngineFactory;
+
+ public WorkflowExecutionRunnable createWorkflowExecuteRunnable(IWorkflowExecutionContext workflowExecutionContext) {
+ IDAGEngine dagEngine = dagEngineFactory.createDAGEngine(workflowExecutionContext);
+ return WorkflowExecutionRunnable.builder()
+ .workflowExecutionContext(workflowExecutionContext)
+ .dagEngine(dagEngine)
+ .build();
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowIdentify.java
similarity index 71%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowIdentify.java
index ac37c94438..0b7981199a 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowIdentify.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowIdentify {
+
+ private long workflowCode;
+
+ private int workflowVersion;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventEngine.java
new file mode 100644
index 0000000000..f614a59caf
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventEngine.java
@@ -0,0 +1,111 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.plugin.task.api.utils.LogUtils;
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionContext;
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
+
+import org.apache.commons.lang3.time.StopWatch;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class EventEngine extends BaseDaemonThread {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Autowired
+ private EventFirer eventFirer;
+
+ private final Set<Integer> firingWorkflowInstanceIds = ConcurrentHashMap.newKeySet();
+
+ public EventEngine() {
+ super("EventEngine");
+ }
+
+ @Override
+ public synchronized void start() {
+ super.start();
+ log.info(getClass().getName() + " started");
+ }
+
+ @Override
+ public void run() {
+ for (;;) {
+ try {
+ StopWatch stopWatch = StopWatch.createStarted();
+ fireAllActiveEvents();
+ stopWatch.stop();
+ log.info("Fire all active events cost: {} ms", stopWatch.getTime());
+ this.wait(5_000);
+ } catch (Throwable throwable) {
+ log.error("Fire active event error", throwable);
+ ThreadUtils.sleep(3_000);
+ }
+ }
+ }
+
+ public void fireAllActiveEvents() {
+ Collection<IWorkflowExecutionRunnable> workflowExecutionRunnableCollection =
+ workflowExecuteRunnableRepository.getActiveWorkflowExecutionRunnable();
+ for (IWorkflowExecutionRunnable workflowExecutionRunnable : workflowExecutionRunnableCollection) {
+ IWorkflowExecutionContext workflowExecutionContext =
+ workflowExecutionRunnable.getWorkflowExecutionContext();
+ final Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
+ final String workflowInstanceName = workflowExecutionContext.getWorkflowInstanceName();
+ try {
+ LogUtils.setWorkflowInstanceIdMDC(workflowInstanceId);
+ if (firingWorkflowInstanceIds.contains(workflowInstanceId)) {
+ log.debug("WorkflowExecutionRunnable: {} is already in firing", workflowInstanceName);
+ return;
+ }
+ IEventRepository workflowEventRepository = workflowExecutionRunnable.getEventRepository();
+ firingWorkflowInstanceIds.add(workflowInstanceId);
+ eventFirer.fireActiveEvents(workflowEventRepository)
+ .whenComplete((fireCount, ex) -> {
+ firingWorkflowInstanceIds.remove(workflowInstanceId);
+ if (ex != null) {
+ log.error("Fire event for WorkflowExecutionRunnable: {} error", workflowInstanceName,
+ ex);
+ } else {
+ if (fireCount > 0) {
+ log.info("Fire {} events for WorkflowExecutionRunnable: {} success", fireCount,
+ workflowInstanceName);
+ }
+ }
+ });
+ } finally {
+ LogUtils.removeWorkflowInstanceIdMDC();
+ }
+ }
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventFirer.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventFirer.java
new file mode 100644
index 0000000000..fbbc683097
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventFirer.java
@@ -0,0 +1,95 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.server.master.config.MasterConfig;
+import org.apache.dolphinscheduler.server.master.utils.ExceptionUtils;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class EventFirer implements IEventFirer {
+
+ private final IEventOperatorManager<IEvent> eventOperatorManager;
+
+ private final ThreadPoolExecutor eventFireThreadPool;
+
+ public EventFirer(IEventOperatorManager<IEvent> eventOperatorManager, MasterConfig masterConfig) {
+ this.eventOperatorManager = eventOperatorManager;
+ this.eventFireThreadPool =
+ ThreadUtils.newDaemonFixedThreadExecutor("EventFireThreadPool", masterConfig.getExecThreads());
+ }
+
+ @Override
+ public CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository) {
+ if (eventRepository.getEventSize() == 0) {
+ return CompletableFuture.completedFuture(0);
+ }
+ return CompletableFuture.supplyAsync(() -> {
+ int fireCount = 0;
+ for (;;) {
+ IEvent event = eventRepository.poolEvent();
+ if (event == null) {
+ break;
+ }
+
+ if (event instanceof IAsyncEvent) {
+ fireAsyncEvent(event);
+ fireCount++;
+ continue;
+ }
+ try {
+ fireSyncEvent(event);
+ fireCount++;
+ } catch (Exception ex) {
+ if (ExceptionUtils.isDatabaseConnectedFailedException(ex)) {
+ // If the event is failed due to cannot connect to DB, we should retry it
+ eventRepository.storeEventToHead(event);
+ }
+ throw ex;
+ }
+ }
+ return fireCount;
+ }, eventFireThreadPool);
+ }
+
+ private void fireAsyncEvent(IEvent event) {
+ CompletableFuture.runAsync(() -> {
+ log.info("Begin fire IAsyncEvent: {}", event);
+ eventOperatorManager.getEventOperator(event).handleEvent(event);
+ log.info("Success fire IAsyncEvent: {}", event);
+ }, eventFireThreadPool).exceptionally(ex -> {
+ log.error("Failed to fire IAsyncEvent: {}", event, ex);
+ return null;
+ });
+ }
+
+ private void fireSyncEvent(IEvent event) {
+ log.info("Begin fire SyncEvent: {}", event);
+ eventOperatorManager.getEventOperator(event).handleEvent(event);
+ log.info("Success fire SyncEvent: {}", event);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventOperatorManager.java
similarity index 65%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventOperatorManager.java
index ac37c94438..7a7b52d6c6 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventOperatorManager.java
@@ -15,12 +15,22 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.extern.slf4j.Slf4j;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import org.springframework.stereotype.Component;
+
+/**
+ * The event operator manager interface used to get {@link ITaskEventOperator}.
+ */
+@Slf4j
+@Component
+public class EventOperatorManager implements IEventOperatorManager<IEvent> {
+
+ @Override
+ public IEventOperator<IEvent> getEventOperator(IEvent event) {
+ return null;
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IAsyncEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IAsyncEvent.java
index ac37c94438..0d0395de6e 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IAsyncEvent.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
-
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+package org.apache.dolphinscheduler.server.master.events;
+/**
+ * Mark the event as AsyncEvent, if the event is marked as AsyncEvent, the event will be handled asynchronously and we don't .
+ */
+public interface IAsyncEvent {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IDelayEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IDelayEvent.java
index ac37c94438..c86ea4744f 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IDelayEvent.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IDelayEvent {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ long getEventCreateTime();
+
+ long getDelayTime();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEvent.java
index ac37c94438..0535bbe2c7 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEvent.java
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface IEvent {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventFirer.java
similarity index 66%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventFirer.java
index ac37c94438..f33db8ed6a 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventFirer.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.concurrent.CompletableFuture;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+/**
+ * The event firer interface used to fire event.
+ *
+ */
+public interface IEventFirer {
+
+ /**
+ * Fire all active events in the event repository
+ *
+ * @return the count of fired success events
+ */
+ CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperator.java
similarity index 75%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperator.java
index ac37c94438..23694a1ccb 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperator.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+/**
+ * The event operator interface used to handle event.
+ */
+public interface IEventOperator<E> {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * Handle the given event
+ *
+ * @param event event
+ */
+ void handleEvent(E event);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperatorManager.java
similarity index 67%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperatorManager.java
index ac37c94438..7fb2b63d8a 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperatorManager.java
@@ -15,12 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+/**
+ * The event operator manager interface used to get event operator.
+ */
+public interface IEventOperatorManager<E> {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * Get the {@link IEventOperator} for the given event.
+ *
+ * @param event event
+ * @return event operator for the given event
+ */
+ IEventOperator<E> getEventOperator(E event);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventRepository.java
similarity index 70%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventRepository.java
index ac37c94438..20e5081124 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventRepository.java
@@ -15,12 +15,23 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.List;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+/**
+ * The event repository interface used to store event.
+ */
+public interface IEventRepository {
+
+ void storeEventToTail(IEvent event);
+
+ void storeEventToHead(IEvent event);
+
+ IEvent poolEvent();
+
+ int getEventSize();
+
+ List<IEvent> getAllEvent();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ISyncEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ISyncEvent.java
index ac37c94438..5a385cc034 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ISyncEvent.java
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
-
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+package org.apache.dolphinscheduler.server.master.events;
+public interface ISyncEvent {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEvent.java
index ac37c94438..5d105df288 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEvent.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface ITaskEvent extends IEvent {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ Integer getWorkflowInstanceId();
+
+ Integer getTaskInstanceId();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEventOperator.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEventOperator.java
index ac37c94438..1aa1c28299 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEventOperator.java
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface ITaskEventOperator<E extends ITaskEvent> extends IEventOperator<E> {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEvent.java
similarity index 73%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEvent.java
index ac37c94438..7b5ae1cd66 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEvent.java
@@ -15,12 +15,15 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IWorkflowEvent extends IEvent {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * The id of WorkflowInstance which the event is related to
+ *
+ * @return workflowInstanceId, shouldn't be null
+ */
+ Integer getWorkflowInstanceId();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEventOperator.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEventOperator.java
index ac37c94438..c601cc27d3 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEventOperator.java
@@ -15,12 +15,9 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
-
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+package org.apache.dolphinscheduler.server.master.events;
+public interface IWorkflowEventOperator<E extends IWorkflowEvent>
+ extends
+ IEventOperator<E> {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/MemoryEventRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/MemoryEventRepository.java
new file mode 100644
index 0000000000..376b2e4597
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/MemoryEventRepository.java
@@ -0,0 +1,60 @@
+/*
+ * 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.server.master.events;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingDeque;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class MemoryEventRepository implements IEventRepository {
+
+ protected final LinkedBlockingDeque<IEvent> eventQueue;
+
+ public MemoryEventRepository() {
+ this.eventQueue = new LinkedBlockingDeque<>();
+ }
+
+ @Override
+ public void storeEventToTail(IEvent event) {
+ log.info("Store event to tail: {}", event);
+ eventQueue.offerLast(event);
+ }
+
+ @Override
+ public void storeEventToHead(IEvent event) {
+ eventQueue.offerFirst(event);
+ }
+
+ @Override
+ public IEvent poolEvent() {
+ return eventQueue.poll();
+ }
+
+ @Override
+ public int getEventSize() {
+ return eventQueue.size();
+ }
+
+ public List<IEvent> getAllEvent() {
+ return new ArrayList<>(eventQueue);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEvent.java
similarity index 65%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEvent.java
index ac37c94438..5e42a40bd6 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEvent.java
@@ -15,12 +15,22 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class TaskLogSendToRemoteEvent implements ITaskEvent {
+ private Integer workflowInstanceId;
+ private Integer taskInstanceId;
+
+ private String taskType;
+ private String logPath;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEventOperator.java
similarity index 51%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEventOperator.java
index ac37c94438..c75f1fcba5 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEventOperator.java
@@ -15,12 +15,24 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.common.log.remote.RemoteLogUtils;
+import org.apache.dolphinscheduler.server.master.utils.TaskUtils;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+@Slf4j
+@Component
+public class TaskLogSendToRemoteEventOperator implements ITaskEventOperator<TaskLogSendToRemoteEvent> {
+
+ @Override
+ public void handleEvent(TaskLogSendToRemoteEvent event) {
+ if (RemoteLogUtils.isRemoteLoggingEnable() && TaskUtils.isMasterTask(event.getTaskType())) {
+ RemoteLogUtils.sendRemoteLog(event.getLogPath());
+ log.info("Master sends task log {} to remote storage asynchronously.", event.getLogPath());
+ }
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEvent.java
similarity index 50%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEvent.java
index ac37c94438..165ea88053 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEvent.java
@@ -15,12 +15,32 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.server.master.dag.TaskExecutionRunnable;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class TaskOperationEvent implements ITaskEvent, ISyncEvent {
+
+ private TaskExecutionRunnable taskExecutionRunnable;
+
+ private TaskOperationType taskOperationType;
+
+ @Override
+ public Integer getWorkflowInstanceId() {
+ return taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getProcessInstanceId();
}
+ @Override
+ public Integer getTaskInstanceId() {
+ return taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId();
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEventOperator.java
new file mode 100644
index 0000000000..355d28085b
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEventOperator.java
@@ -0,0 +1,47 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.server.master.dag.TaskExecutionRunnable;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class TaskOperationEventOperator implements ITaskEventOperator<TaskOperationEvent> {
+
+ @Override
+ public void handleEvent(TaskOperationEvent event) {
+ TaskExecutionRunnable taskExecutionRunnable = event.getTaskExecutionRunnable();
+ switch (event.getTaskOperationType()) {
+ case RUN:
+ taskExecutionRunnable.dispatch();
+ break;
+ case KILL:
+ taskExecutionRunnable.kill();
+ break;
+ case PAUSE:
+ taskExecutionRunnable.pause();
+ break;
+ default:
+ log.error("Unknown TaskOperationType for event: {}", event);
+ }
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationType.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationType.java
index ac37c94438..ae72a03b01 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationType.java
@@ -15,12 +15,15 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+public enum TaskOperationType {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ FAILOVER,
+ RUN,
+ RETRY,
+ KILL,
+ PAUSE,
+ ;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEvent.java
similarity index 71%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEvent.java
index ac37c94438..a84d89069a 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEvent.java
@@ -15,12 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class TaskSuccessEvent implements ITaskEvent {
+
+ private Integer workflowInstanceId;
+
+ private Integer taskInstanceId;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEventOperator.java
new file mode 100644
index 0000000000..8ed9c2033b
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEventOperator.java
@@ -0,0 +1,47 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class TaskSuccessEventOperator implements ITaskEventOperator<TaskSuccessEvent> {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Override
+ public void handleEvent(TaskSuccessEvent event) {
+ Integer workflowInstanceId = event.getWorkflowInstanceId();
+ Integer taskInstanceId = event.getTaskInstanceId();
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ if (workflowExecutionRunnable == null) {
+ log.error("Cannot find the WorkflowExecutionRunnable, the event: {} will be dropped", event);
+ return;
+ }
+
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEvent.java
similarity index 68%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEvent.java
index ac37c94438..f07067c261 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEvent.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowFailedEvent implements IWorkflowEvent, ISyncEvent {
+
+ private Integer workflowInstanceId;
+
+ private String failedReason;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEventOperator.java
new file mode 100644
index 0000000000..b7e562b6f7
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEventOperator.java
@@ -0,0 +1,57 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao;
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowFailedEventOperator
+ implements
+ IWorkflowEventOperator<WorkflowFailedEvent> {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Autowired
+ private ProcessInstanceDao processInstanceDao;
+
+ @Override
+ public void handleEvent(WorkflowFailedEvent event) {
+ Integer workflowInstanceId = event.getWorkflowInstanceId();
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+
+ ProcessInstance workflowInstance =
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance();
+ workflowInstance.setState(WorkflowExecutionStatus.FAILURE);
+ processInstanceDao.updateById(workflowInstance);
+ log.info("Handle WorkflowExecutionRunnableFailedEvent success, set workflowInstance status to {}",
+ workflowInstance.getState());
+ workflowExecutionRunnable.storeEventToTail(new WorkflowFinalizeEvent(workflowInstanceId));
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEvent.java
similarity index 70%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEvent.java
index ac37c94438..454b755c42 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEvent.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class WorkflowFinalizeEvent implements IWorkflowEvent, ISyncEvent {
+ private Integer workflowInstanceId;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEventOperator.java
similarity index 51%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEventOperator.java
index ac37c94438..aeab8ae30c 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEventOperator.java
@@ -15,12 +15,28 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowFinalizeEventOperator
+ implements
+ IWorkflowEventOperator<WorkflowFinalizeEvent> {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Override
+ public void handleEvent(WorkflowFinalizeEvent event) {
+ Integer workflowInstanceId = event.getWorkflowInstanceId();
+ workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinishEvent.java
similarity index 63%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinishEvent.java
index ac37c94438..b58db0cc53 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinishEvent.java
@@ -15,12 +15,23 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowFinishEvent implements IWorkflowEvent, ISyncEvent {
+
+ private Integer workflowInstanceId;
+
+ private WorkflowExecutionStatus workflowExecutionStatus;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEvent.java
new file mode 100644
index 0000000000..6450067f60
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEvent.java
@@ -0,0 +1,51 @@
+/*
+ * 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.server.master.events;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+
+@Data
+@Builder
+@AllArgsConstructor
+public class WorkflowOperationEvent implements IWorkflowEvent, ISyncEvent {
+
+ private Integer workflowInstanceId;
+ private WorkflowOperationType workflowOperationType;
+
+ public static WorkflowOperationEvent of(Integer workflowInstanceId, WorkflowOperationType workflowOperationType) {
+ return WorkflowOperationEvent.builder()
+ .workflowInstanceId(workflowInstanceId)
+ .workflowOperationType(workflowOperationType)
+ .build();
+ }
+
+ public static WorkflowOperationEvent triggerEvent(Integer workflowInstanceId) {
+ return of(workflowInstanceId, WorkflowOperationType.TRIGGER);
+ }
+
+ public static WorkflowOperationEvent pauseEvent(Integer workflowInstanceId) {
+ return of(workflowInstanceId, WorkflowOperationType.PAUSE);
+ }
+
+ public static WorkflowOperationEvent killEvent(Integer workflowInstanceId) {
+ return of(workflowInstanceId, WorkflowOperationType.KILL);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventOperator.java
new file mode 100644
index 0000000000..2c8159f88f
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventOperator.java
@@ -0,0 +1,87 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionContext;
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.server.master.utils.ExceptionUtils;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowOperationEventOperator implements IWorkflowEventOperator<WorkflowOperationEvent> {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Override
+ public void handleEvent(WorkflowOperationEvent event) {
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
+ if (workflowExecutionRunnable == null) {
+ log.warn(
+ "Handle workflowExecutionRunnableKillOperationEvent: {} failed: WorkflowExecutionRunnable not found",
+ event);
+ return;
+ }
+ switch (event.getWorkflowOperationType()) {
+ case TRIGGER:
+ triggerWorkflow(workflowExecutionRunnable);
+ break;
+ case PAUSE:
+ pauseWorkflow(workflowExecutionRunnable);
+ break;
+ case KILL:
+ killWorkflow(workflowExecutionRunnable);
+ break;
+ default:
+ log.error("Unknown operationType for event: {}", event);
+ }
+ }
+
+ private void triggerWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ try {
+ workflowExecutionRunnable.start();
+ } catch (Throwable exception) {
+ if (ExceptionUtils.isDatabaseConnectedFailedException(exception)) {
+ throw exception;
+ }
+ IWorkflowExecutionContext workflowExecutionContext =
+ workflowExecutionRunnable.getWorkflowExecutionContext();
+ log.error("Trigger workflow: {} failed", workflowExecutionContext.getWorkflowInstanceName(), exception);
+ WorkflowFailedEvent workflowExecutionRunnableFailedEvent = WorkflowFailedEvent.builder()
+ .workflowInstanceId(workflowExecutionContext.getWorkflowInstanceId())
+ .failedReason(exception.getMessage())
+ .build();
+ workflowExecutionRunnable.storeEventToTail(workflowExecutionRunnableFailedEvent);
+ }
+ }
+
+ private void pauseWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ workflowExecutionRunnable.pause();
+ }
+
+ private void killWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ workflowExecutionRunnable.kill();
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationType.java
similarity index 68%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationType.java
index ac37c94438..24abbbc855 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationType.java
@@ -15,12 +15,22 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+public enum WorkflowOperationType {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * Trigger the workflow instance.
+ */
+ TRIGGER,
+ /**
+ * Pause the workflow instance, it will pause the running task instances.
+ */
+ PAUSE,
+ /**
+ * Kill the workflow instance, it will kill the running task instances.
+ */
+ KILL,
+ ;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEvent.java
similarity index 70%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEvent.java
index ac37c94438..b075d194d7 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEvent.java
@@ -15,12 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowTimeoutEvent implements IWorkflowEvent, IAsyncEvent {
+
+ private Integer workflowInstanceId;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEventOperator.java
new file mode 100644
index 0000000000..ebb43e3359
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEventOperator.java
@@ -0,0 +1,61 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.dao.entity.ProjectUser;
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.service.alert.ProcessAlertManager;
+import org.apache.dolphinscheduler.service.process.ProcessService;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowTimeoutEventOperator
+ implements
+ IEventOperator<WorkflowTimeoutEvent> {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Autowired
+ private ProcessService processService;
+
+ @Autowired
+ private ProcessAlertManager processAlertManager;
+
+ @Override
+ public void handleEvent(WorkflowTimeoutEvent event) {
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
+ if (workflowExecutionRunnable == null) {
+ log.warn("Cannot find the workflow instance by id: {}", event.getWorkflowInstanceId());
+ return;
+ }
+ // we only support timeout warning for now
+ ProcessInstance workflowInstance =
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance();
+ ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(workflowInstance.getId());
+ processAlertManager.sendProcessTimeoutAlert(workflowInstance, projectUser);
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEvent.java
similarity index 62%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEvent.java
index ac37c94438..3dfdb9e239 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEvent.java
@@ -15,12 +15,24 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowTriggerNextTaskEvent implements IWorkflowEvent, ISyncEvent {
+
+ private Integer workflowInstanceId;
+
+ /**
+ * The task name of the parent task, if it is the root task, the value is null
+ */
+ private String parentTaskNodeName;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEventOperator.java
new file mode 100644
index 0000000000..d294b84d58
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEventOperator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowTriggerNextTaskEventOperator
+ implements
+ IWorkflowEventOperator<WorkflowTriggerNextTaskEvent> {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Override
+ public void handleEvent(WorkflowTriggerNextTaskEvent event) {
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
+ workflowExecutionRunnable.getDagEngine().triggerNextTasks(event.getParentTaskNodeName());
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEvent.java
similarity index 70%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEvent.java
index ac37c94438..b07434dc29 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEvent.java
@@ -15,12 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.events;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowTriggeredEvent implements IWorkflowEvent, IAsyncEvent {
+
+ private Integer workflowInstanceId;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEventOperator.java
new file mode 100644
index 0000000000..e49b1ae70e
--- /dev/null
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEventOperator.java
@@ -0,0 +1,63 @@
+/*
+ * 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.server.master.events;
+
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.dao.entity.ProjectUser;
+import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.server.master.metrics.ProcessInstanceMetrics;
+import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
+import org.apache.dolphinscheduler.service.process.ProcessService;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkflowTriggeredEventOperator
+ implements
+ IWorkflowEventOperator<WorkflowTriggeredEvent> {
+
+ @Autowired
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ @Autowired
+ private ProcessService processService;
+
+ @Autowired
+ private ListenerEventAlertManager listenerEventAlertManager;
+
+ @Override
+ public void handleEvent(WorkflowTriggeredEvent event) {
+ int workflowInstanceId = event.getWorkflowInstanceId();
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ Long workflowDefinitionCode =
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance()
+ .getProcessDefinitionCode();
+ ProcessInstanceMetrics.incProcessInstanceByStateAndProcessDefinitionCode("submit", "" + workflowDefinitionCode);
+
+ ProcessInstance workflowInstance =
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance();
+ ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(workflowInstanceId);
+ listenerEventAlertManager.publishProcessStartListenerEvent(workflowInstance, projectUser);
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecuteRunnableNotFoundException.java
similarity index 67%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecuteRunnableNotFoundException.java
index ac37c94438..70088d4970 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecuteRunnableNotFoundException.java
@@ -17,10 +17,13 @@
package org.apache.dolphinscheduler.server.master.exception;
-public class TaskExecutionContextCreateException extends MasterException {
+public class TaskExecuteRunnableNotFoundException extends RuntimeException {
- public TaskExecutionContextCreateException(String message) {
- super(message);
+ public TaskExecuteRunnableNotFoundException(Integer workflowInstanceId) {
+ super("WorkflowExecuteRunnable not found: [id=" + workflowInstanceId + "]");
}
+ public TaskExecuteRunnableNotFoundException(String workflowInstanceName) {
+ super("WorkflowExecuteRunnable not found: [name=" + workflowInstanceName + "]");
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/WorkflowExecuteRunnableNotFoundException.java
similarity index 67%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/WorkflowExecuteRunnableNotFoundException.java
index ac37c94438..f00a8d36e9 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/WorkflowExecuteRunnableNotFoundException.java
@@ -17,10 +17,14 @@
package org.apache.dolphinscheduler.server.master.exception;
-public class TaskExecutionContextCreateException extends MasterException {
+public class WorkflowExecuteRunnableNotFoundException extends RuntimeException {
- public TaskExecutionContextCreateException(String message) {
- super(message);
+ public WorkflowExecuteRunnableNotFoundException(Integer workflowInstanceId) {
+ super("WorkflowExecuteRunnable not found: [id=" + workflowInstanceId + "]");
+ }
+
+ public WorkflowExecuteRunnableNotFoundException(String workflowInstanceName) {
+ super("WorkflowExecuteRunnable not found: [name=" + workflowInstanceName + "]");
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DefaultTaskExecuteRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DefaultTaskExecuteRunnable.java
index c1b13717bd..a1e60e0a6e 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DefaultTaskExecuteRunnable.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DefaultTaskExecuteRunnable.java
@@ -28,8 +28,7 @@ public class DefaultTaskExecuteRunnable extends PriorityDelayTaskExecuteRunnable
private final TaskExecuteRunnableOperatorManager taskExecuteRunnableOperatorManager;
- public DefaultTaskExecuteRunnable(ProcessInstance workflowInstance,
- TaskInstance taskInstance,
+ public DefaultTaskExecuteRunnable(ProcessInstance workflowInstance, TaskInstance taskInstance,
TaskExecutionContext taskExecutionContext,
TaskExecuteRunnableOperatorManager taskExecuteRunnableOperatorManager) {
super(workflowInstance, taskInstance, taskExecutionContext);
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/TaskExecutionContextFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/TaskExecutionContextFactory.java
index ab1806ff67..742c8187d1 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/TaskExecutionContextFactory.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/TaskExecutionContextFactory.java
@@ -60,7 +60,6 @@ import org.apache.dolphinscheduler.plugin.task.api.utils.MapUtils;
import org.apache.dolphinscheduler.plugin.task.spark.SparkParameters;
import org.apache.dolphinscheduler.server.master.builder.TaskExecutionContextBuilder;
import org.apache.dolphinscheduler.server.master.config.MasterConfig;
-import org.apache.dolphinscheduler.server.master.exception.TaskExecutionContextCreateException;
import org.apache.dolphinscheduler.service.expand.CuringParamsService;
import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
@@ -102,7 +101,7 @@ public class TaskExecutionContextFactory {
@Autowired
private HikariDataSource hikariDataSource;
- public TaskExecutionContext createTaskExecutionContext(TaskInstance taskInstance) throws TaskExecutionContextCreateException {
+ public TaskExecutionContext createTaskExecutionContext(TaskInstance taskInstance) {
ProcessInstance workflowInstance = taskInstance.getProcessInstance();
ResourceParametersHelper resources =
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/DefaultTaskExecuteRunnableFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/DefaultTaskExecuteRunnableFactory.java
index ab749b5861..6c1a4e8569 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/DefaultTaskExecuteRunnableFactory.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/DefaultTaskExecuteRunnableFactory.java
@@ -19,8 +19,6 @@ package org.apache.dolphinscheduler.server.master.runner.execute;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.server.master.cache.ProcessInstanceExecCacheManager;
-import org.apache.dolphinscheduler.server.master.exception.TaskExecuteRunnableCreateException;
-import org.apache.dolphinscheduler.server.master.exception.TaskExecutionContextCreateException;
import org.apache.dolphinscheduler.server.master.runner.DefaultTaskExecuteRunnable;
import org.apache.dolphinscheduler.server.master.runner.TaskExecuteRunnableFactory;
import org.apache.dolphinscheduler.server.master.runner.TaskExecutionContextFactory;
@@ -46,17 +44,13 @@ public class DefaultTaskExecuteRunnableFactory implements TaskExecuteRunnableFac
private TaskExecuteRunnableOperatorManager taskExecuteRunnableOperatorManager;
@Override
- public DefaultTaskExecuteRunnable createTaskExecuteRunnable(TaskInstance taskInstance) throws TaskExecuteRunnableCreateException {
+ public DefaultTaskExecuteRunnable createTaskExecuteRunnable(TaskInstance taskInstance) {
WorkflowExecuteRunnable workflowExecuteRunnable =
processInstanceExecCacheManager.getByProcessInstanceId(taskInstance.getProcessInstanceId());
- try {
- return new DefaultTaskExecuteRunnable(
- workflowExecuteRunnable.getWorkflowExecuteContext().getWorkflowInstance(),
- taskInstance,
- taskExecutionContextFactory.createTaskExecutionContext(taskInstance),
- taskExecuteRunnableOperatorManager);
- } catch (TaskExecutionContextCreateException ex) {
- throw new TaskExecuteRunnableCreateException("Create DefaultTaskExecuteRunnable failed", ex);
- }
+ return new DefaultTaskExecuteRunnable(
+ workflowExecuteRunnable.getWorkflowExecuteContext().getWorkflowInstance(),
+ taskInstance,
+ taskExecutionContextFactory.createTaskExecutionContext(taskInstance),
+ taskExecuteRunnableOperatorManager);
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/ExceptionUtils.java
similarity index 70%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/ExceptionUtils.java
index ac37c94438..7cb69b23f5 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/ExceptionUtils.java
@@ -15,12 +15,17 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.utils;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.experimental.UtilityClass;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import org.springframework.dao.DataAccessResourceFailureException;
+
+@UtilityClass
+public class ExceptionUtils {
+
+ public boolean isDatabaseConnectedFailedException(Throwable e) {
+ return e instanceof DataAccessResourceFailureException;
}
}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/DAGNodeTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/DAGNodeTest.java
new file mode 100644
index 0000000000..c3346bfc5d
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/DAGNodeTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.server.master.dag;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.Lists;
+
+class DAGNodeTest {
+
+ @Test
+ void buildDAGNode_EmptyNodeName() {
+ IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
+ () -> DAGNode.builder()
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .build());
+ assertEquals("nodeName cannot be empty", illegalArgumentException.getMessage());
+ }
+
+ @Test
+ void buildDAGNode_BadInDegree() {
+ IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
+ () -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName(null)
+ .toNodeName("B")
+ .build()))
+ .outDegrees(new ArrayList<>())
+ .build());
+ assertEquals(
+ "The toNodeName of inDegree should be the nodeName of the node: A, inDegree: DAGEdge(fromNodeName=null, toNodeName=B)",
+ illegalArgumentException.getMessage());
+ }
+
+ @Test
+ void buildDAGNode_NiceInDegree() {
+ assertDoesNotThrow(() -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName(null)
+ .toNodeName("A")
+ .build()))
+ .outDegrees(new ArrayList<>())
+ .build());
+ }
+
+ @Test
+ void buildDAGNode_BadOutDegree() {
+ IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
+ () -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(new ArrayList<>())
+ .outDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName("B")
+ .toNodeName(null)
+ .build()))
+ .build());
+ assertEquals(
+ "The fromNodeName of outDegree should be the nodeName of the node: A, outDegree: DAGEdge(fromNodeName=B, toNodeName=null)",
+ illegalArgumentException.getMessage());
+ }
+
+ @Test
+ void buildDAGNode_NiceOutDegree() {
+ assertDoesNotThrow(() -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(new ArrayList<>())
+ .outDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName("A")
+ .toNodeName(null)
+ .build()))
+ .build());
+ }
+
+ @Test
+ void buildDAGNode_NotSkip() {
+ DAGNode dagNode = DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .build();
+ assertFalse(dagNode.isSkip());
+ }
+
+ @Test
+ void buildDAGNode_Skip() {
+ DAGNode dagNode = DAGNode.builder()
+ .nodeName("A")
+ .skip(true)
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .build();
+ assertTrue(dagNode.isSkip());
+ }
+
+}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionContextFactory.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionContextFactory.java
new file mode 100644
index 0000000000..b067a455dd
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionContextFactory.java
@@ -0,0 +1,88 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
+import org.apache.dolphinscheduler.server.master.events.MemoryEventRepository;
+
+import java.util.Collections;
+
+class MockWorkflowExecutionContextFactory {
+
+ public static WorkflowExecutionContext createWorkflowExecutionContext() {
+ long workflowDefinitionCode = CodeGenerateUtils.getInstance().genCode();
+ int workflowDefinitionVersion = 1;
+
+ int workflowInstanceId = 1;
+ String workflowInstanceName = "MockWorkflow" + CodeGenerateUtils.getInstance().genCode();
+
+ ProcessDefinition processDefinition = ProcessDefinition.builder()
+ .id(1)
+ .name("TestWorkflow")
+ .code(workflowDefinitionCode)
+ .version(workflowDefinitionVersion)
+ .build();
+
+ ProcessInstance processInstance = ProcessInstance.builder()
+ .id(workflowInstanceId)
+ .name(workflowInstanceName)
+ .build();
+
+ WorkflowExecutionDAG workflowExecutionDAG = createWorkflowExecutionDAG();
+
+ return WorkflowExecutionContext.builder()
+ .workflowExecutionDAG(workflowExecutionDAG)
+ .eventRepository(new MemoryEventRepository())
+ .beginNodeNames(Collections.emptyList())
+ .workflowDefinition(processDefinition)
+ .workflowInstance(processInstance)
+ .build();
+ }
+
+ private static WorkflowExecutionDAG createWorkflowExecutionDAG() {
+ TaskDefinitionLog taskA = taskNode("A");
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNode(taskA)
+ .addTaskEdge(edge(null, taskA))
+ .addTaskEdge(edge(taskA, null))
+ .build();
+
+ return WorkflowExecutionDAG.builder()
+ .workflowDAG(workflowDAG)
+ .taskExecutionRunnableRepository(new TaskExecutionRunnableRepository())
+ .build();
+ }
+
+ private static TaskDefinitionLog taskNode(String nodeName) {
+ TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog();
+ taskDefinitionLog.setCode(CodeGenerateUtils.getInstance().genCode());
+ taskDefinitionLog.setName(nodeName);
+ return taskDefinitionLog;
+ }
+
+ private static ProcessTaskRelationLog edge(TaskDefinitionLog from, TaskDefinitionLog to) {
+ ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog();
+ processTaskRelationLog.setPreTaskCode(from == null ? 0 : from.getCode());
+ processTaskRelationLog.setPostTaskCode(to == null ? 0 : to.getCode());
+ return processTaskRelationLog;
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionRunnableFactory.java
similarity index 58%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionRunnableFactory.java
index ac37c94438..77745e198b 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionRunnableFactory.java
@@ -15,12 +15,17 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+class MockWorkflowExecutionRunnableFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
+ public static WorkflowExecutionRunnable createWorkflowExecuteRunnable() {
+ WorkflowExecutionContext workflowExecutionContext =
+ MockWorkflowExecutionContextFactory.createWorkflowExecutionContext();
+ IDAGEngine dagEngine = new DAGEngine(workflowExecutionContext);
+ return WorkflowExecutionRunnable.builder()
+ .workflowExecutionContext(workflowExecutionContext)
+ .dagEngine(dagEngine)
+ .build();
}
-
}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGAssertion.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGAssertion.java
new file mode 100644
index 0000000000..a03ecd9f76
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGAssertion.java
@@ -0,0 +1,171 @@
+/*
+ * 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.server.master.dag;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class WorkflowDAGAssertion {
+
+ private final IWorkflowDAG workflowDAG;
+
+ private final List<NodeAssertion> nodeAssertions;
+
+ private WorkflowDAGAssertion(IWorkflowDAG workflowDAG) {
+ this.workflowDAG = workflowDAG;
+ this.nodeAssertions = new ArrayList<>();
+ }
+
+ public static WorkflowDAGAssertion workflowDag(IWorkflowDAG workflowDAG) {
+ return new WorkflowDAGAssertion(workflowDAG);
+ }
+
+ public WorkflowDAGAssertion nodeAssertion(NodeAssertion nodeAssertion) {
+ nodeAssertions.add(nodeAssertion);
+ return this;
+ }
+
+ public void doAssertion() {
+ nodeAssertions.forEach(nodeAssertion -> nodeAssertion.doAssertion(workflowDAG));
+ }
+
+ public static class NodeAssertion {
+
+ /**
+ * node name of the assertion
+ */
+ private final String nodeName;
+
+ /**
+ * whether the node exist
+ */
+ private boolean exist;
+
+ /**
+ * whether the node is skipped
+ */
+ private boolean skip;
+
+ /**
+ * whether the node has out degree
+ */
+ private List<String> postNodes;
+
+ /**
+ * whether the node has in degree
+ */
+ private List<String> preNodes;
+
+ private NodeAssertion(String nodeName) {
+ this.nodeName = nodeName;
+ this.postNodes = new ArrayList<>();
+ this.preNodes = new ArrayList<>();
+ }
+
+ public static NodeAssertion node(String nodeName) {
+ return new NodeAssertion(nodeName);
+ }
+
+ public NodeAssertion exist() {
+ this.exist = true;
+ return this;
+ }
+
+ public NodeAssertion skip() {
+ this.skip = true;
+ return this;
+ }
+
+ public NodeAssertion noEdge() {
+ this.postNodes = new ArrayList<>();
+ this.preNodes = new ArrayList<>();
+ return this;
+ }
+
+ public NodeAssertion noInDegree() {
+ this.preNodes = new ArrayList<>();
+ return this;
+ }
+
+ public NodeAssertion inDegrees(List<String> preNodes) {
+ this.preNodes.addAll(preNodes);
+ return this;
+ }
+
+ public NodeAssertion inDegrees(String preNode) {
+ this.preNodes.add(preNode);
+ return this;
+ }
+
+ public NodeAssertion noOutDegree() {
+ this.postNodes = new ArrayList<>();
+ return this;
+ }
+
+ public NodeAssertion outDegrees(List<String> postNodes) {
+ this.postNodes.addAll(postNodes);
+ return this;
+ }
+
+ public NodeAssertion outDegrees(String postNode) {
+ this.postNodes.add(postNode);
+ return this;
+ }
+
+ private void doAssertion(IWorkflowDAG workflowDAG) {
+ if (exist) {
+ // node exist
+ assertNotNull(workflowDAG.getDAGNode(nodeName), "node " + nodeName + " does not exist");
+ } else {
+
+ assertNull(workflowDAG.getDAGNode(nodeName), "node " + nodeName + " exist");
+ }
+
+ if (skip) {
+ assertTrue(workflowDAG.getDAGNode(nodeName).isSkip(), "node " + nodeName + " is not skipped");
+ } else {
+ assertFalse(workflowDAG.getDAGNode(nodeName).isSkip(), "node " + nodeName + " is skipped");
+ }
+
+ if (CollectionUtils.isEmpty(postNodes)) {
+ assertTrue(workflowDAG.getDirectPostNodeNames(nodeName).isEmpty(),
+ "node " + nodeName + " has outDegree " + workflowDAG.getDirectPostNodes(nodeName));
+ } else {
+ postNodes
+ .forEach(postNode -> assertTrue(workflowDAG.getDirectPostNodeNames(nodeName).contains(postNode),
+ "node " + nodeName + " does has outDegree " + postNode));
+ }
+
+ if (CollectionUtils.isEmpty(preNodes)) {
+ assertTrue(workflowDAG.getDirectPreNodeNames(nodeName).isEmpty(),
+ "node " + nodeName + " has inDegree " + workflowDAG.getDirectPreNodeNames(nodeName));
+ } else {
+ preNodes.forEach(preNode -> assertTrue(workflowDAG.getDirectPreNodeNames(nodeName).contains(preNode),
+ "node " + nodeName + " does has inDegree " + preNode));
+ }
+ }
+ }
+
+}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilderTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilderTest.java
new file mode 100644
index 0000000000..a4abb8156f
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilderTest.java
@@ -0,0 +1,282 @@
+/*
+ * 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.server.master.dag;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.apache.dolphinscheduler.server.master.dag.WorkflowDAGAssertion.NodeAssertion.node;
+import static org.apache.dolphinscheduler.server.master.dag.WorkflowDAGAssertion.workflowDag;
+
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
+
+import org.junit.jupiter.api.Test;
+
+class WorkflowDAGBuilderTest {
+
+ /**
+ * Test DAG with single node:
+ * <pre>
+ * {@code
+ * Node(A)
+ * }
+ * </pre>
+ */
+ @Test
+ void build_SingleTaskNode() {
+ String nodeName = "A";
+ TaskDefinitionLog taskDefinitionLog = taskNode(nodeName);
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNode(taskDefinitionLog)
+ .build();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeName).exist().noEdge())
+ .doAssertion();
+ }
+
+ /**
+ * Test DAG with multiple nodes:
+ * <pre>
+ * {@code
+ * Node(A)
+ * Node(B)
+ * Node(C)
+ * }
+ * <pre/>
+ */
+ @Test
+ void build_MULTIPLE_NODE() {
+ String nodeNameA = "A";
+ TaskDefinitionLog taskNodeA = taskNode(nodeNameA);
+ String nodeNameB = "B";
+ TaskDefinitionLog taskNodeB = taskNode(nodeNameB);
+ String nodeNameC = "C";
+ TaskDefinitionLog taskNodeC = taskNode(nodeNameC);
+
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNode(taskNodeA)
+ .addTaskNode(taskNodeB)
+ .addTaskNode(taskNodeC)
+ .build();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA).exist().noEdge())
+ .nodeAssertion(node(nodeNameB).exist().noEdge())
+ .nodeAssertion(node(nodeNameC).exist().noEdge())
+ .doAssertion();
+ }
+
+ /**
+ * Test DAG with multiple nodes:
+ * <pre>
+ * {@code
+ * Node(A) -> Node(B1) -> Node(C1) -> Node(D)
+ * -> Node(B2) -> Node(C2) ->
+ * }
+ * <pre/>
+ */
+ @Test
+ void build_DAG() {
+ String nodeNameA = "A";
+ TaskDefinitionLog taskNodeA = taskNode(nodeNameA);
+ String nodeNameB1 = "B1";
+ TaskDefinitionLog taskNodeB1 = taskNode(nodeNameB1);
+ String nodeNameB2 = "B2";
+ TaskDefinitionLog taskNodeB2 = taskNode(nodeNameB2);
+ String nodeNameC1 = "C1";
+ TaskDefinitionLog taskNodeC1 = taskNode(nodeNameC1);
+ String nodeNameC2 = "C2";
+ TaskDefinitionLog taskNodeC2 = taskNode(nodeNameC2);
+ String nodeNameD = "D";
+ TaskDefinitionLog taskNodeD = taskNode(nodeNameD);
+
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNode(taskNodeA)
+ .addTaskNodes(newArrayList(taskNodeB1, taskNodeB2))
+ .addTaskNodes(newArrayList(taskNodeC1, taskNodeC2))
+ .addTaskNode(taskNodeD)
+ .addTaskEdge(edge(null, taskNodeA))
+ .addTaskEdge(edge(taskNodeA, taskNodeB1))
+ .addTaskEdge(edge(taskNodeA, taskNodeB2))
+ .addTaskEdge(edge(taskNodeB1, taskNodeC1))
+ .addTaskEdge(edge(taskNodeB2, taskNodeC2))
+ .addTaskEdge(edge(taskNodeC1, taskNodeD))
+ .addTaskEdge(edge(taskNodeC2, taskNodeD))
+ .addTaskEdge(edge(taskNodeD, null))
+ .build();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA)
+ .exist()
+ .noInDegree()
+ .outDegrees(newArrayList(nodeNameB1, nodeNameB2)))
+ .nodeAssertion(node(nodeNameB1)
+ .exist()
+ .inDegrees(nodeNameA)
+ .outDegrees(nodeNameC1))
+ .nodeAssertion(node(nodeNameB2)
+ .exist()
+ .inDegrees(nodeNameA)
+ .outDegrees(nodeNameC2))
+ .nodeAssertion(node(nodeNameC1)
+ .exist()
+ .inDegrees(nodeNameB1)
+ .outDegrees(nodeNameD))
+ .nodeAssertion(node(nodeNameC2)
+ .exist()
+ .inDegrees(nodeNameB2)
+ .outDegrees(nodeNameD))
+ .nodeAssertion(node(nodeNameD)
+ .exist()
+ .inDegrees(newArrayList(nodeNameC1, nodeNameC2))
+ .noOutDegree())
+ .doAssertion();
+ }
+
+ /**
+ * Test DAG with multiple sub dags:
+ * <pre>
+ * {@code
+ * Node(A1) -> Node(B1) -> Node(C1) -> Node(D1)
+ * -> Node(B2) -> Node(C2) ->
+ *
+ * Node(A2) -> Node(B3) -> Node(C3) -> Node(D2)
+ * -> Node(B4) -> Node(C4) ->
+ * }
+ * <pre/>
+ */
+ @Test
+ void build_MULTIPLE_SUB_DAG() {
+ String nodeNameA1 = "A1";
+ TaskDefinitionLog taskNodeA1 = taskNode(nodeNameA1);
+ String nodeNameA2 = "A2";
+ TaskDefinitionLog taskNodeA2 = taskNode(nodeNameA2);
+
+ String nodeNameB1 = "B1";
+ TaskDefinitionLog taskNodeB1 = taskNode(nodeNameB1);
+ String nodeNameB2 = "B2";
+ TaskDefinitionLog taskNodeB2 = taskNode(nodeNameB2);
+ String nodeNameB3 = "B3";
+ TaskDefinitionLog taskNodeB3 = taskNode(nodeNameB3);
+ String nodeNameB4 = "B4";
+ TaskDefinitionLog taskNodeB4 = taskNode(nodeNameB4);
+
+ String nodeNameC1 = "C1";
+ TaskDefinitionLog taskNodeC1 = taskNode(nodeNameC1);
+ String nodeNameC2 = "C2";
+ TaskDefinitionLog taskNodeC2 = taskNode(nodeNameC2);
+ String nodeNameC3 = "C3";
+ TaskDefinitionLog taskNodeC3 = taskNode(nodeNameC3);
+ String nodeNameC4 = "C4";
+ TaskDefinitionLog taskNodeC4 = taskNode(nodeNameC4);
+
+ String nodeNameD1 = "D1";
+ TaskDefinitionLog taskNodeD1 = taskNode(nodeNameD1);
+ String nodeNameD2 = "D2";
+ TaskDefinitionLog taskNodeD2 = taskNode(nodeNameD2);
+
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNodes(newArrayList(taskNodeA1, taskNodeA2))
+ .addTaskNodes(newArrayList(taskNodeB1, taskNodeB2, taskNodeB3, taskNodeB4))
+ .addTaskNodes(newArrayList(taskNodeC1, taskNodeC2, taskNodeC3, taskNodeC4))
+ .addTaskNodes(newArrayList(taskNodeD1, taskNodeD2))
+ .addTaskEdge(edge(null, taskNodeA1))
+ .addTaskEdge(edge(taskNodeA1, taskNodeB1))
+ .addTaskEdge(edge(taskNodeA1, taskNodeB2))
+ .addTaskEdge(edge(taskNodeB1, taskNodeC1))
+ .addTaskEdge(edge(taskNodeB2, taskNodeC2))
+ .addTaskEdge(edge(taskNodeC1, taskNodeD1))
+ .addTaskEdge(edge(taskNodeC2, taskNodeD1))
+ .addTaskEdge(edge(taskNodeD1, null))
+ .addTaskEdge(edge(null, taskNodeA2))
+ .addTaskEdge(edge(taskNodeA2, taskNodeB3))
+ .addTaskEdge(edge(taskNodeA2, taskNodeB4))
+ .addTaskEdge(edge(taskNodeB3, taskNodeC3))
+ .addTaskEdge(edge(taskNodeB4, taskNodeC4))
+ .addTaskEdge(edge(taskNodeC3, taskNodeD2))
+ .addTaskEdge(edge(taskNodeC4, taskNodeD2))
+ .addTaskEdge(edge(taskNodeD2, null))
+ .build();
+
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA1)
+ .exist()
+ .noInDegree()
+ .outDegrees(newArrayList(nodeNameB1, nodeNameB2)))
+ .nodeAssertion(node(nodeNameB1)
+ .exist()
+ .inDegrees(nodeNameA1)
+ .outDegrees(nodeNameC1))
+ .nodeAssertion(node(nodeNameB2)
+ .exist()
+ .inDegrees(nodeNameA1)
+ .outDegrees(nodeNameC2))
+ .nodeAssertion(node(nodeNameC1)
+ .exist()
+ .inDegrees(nodeNameB1)
+ .outDegrees(nodeNameD1))
+ .nodeAssertion(node(nodeNameC2)
+ .exist()
+ .inDegrees(nodeNameB2)
+ .outDegrees(nodeNameD1))
+ .nodeAssertion(node(nodeNameD1)
+ .exist()
+ .inDegrees(newArrayList(nodeNameC1, nodeNameC2))
+ .noOutDegree())
+ .doAssertion();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA2)
+ .exist()
+ .noInDegree()
+ .outDegrees(newArrayList(nodeNameB3, nodeNameB4)))
+ .nodeAssertion(node(nodeNameB3)
+ .exist()
+ .inDegrees(nodeNameA2)
+ .outDegrees(nodeNameC3))
+ .nodeAssertion(node(nodeNameB4)
+ .exist()
+ .inDegrees(nodeNameA2)
+ .outDegrees(nodeNameC4))
+ .nodeAssertion(node(nodeNameC3)
+ .exist()
+ .inDegrees(nodeNameB3)
+ .outDegrees(nodeNameD2))
+ .nodeAssertion(node(nodeNameC4)
+ .exist()
+ .inDegrees(nodeNameB4)
+ .outDegrees(nodeNameD2))
+ .nodeAssertion(node(nodeNameD2)
+ .exist()
+ .inDegrees(newArrayList(nodeNameC3, nodeNameC4))
+ .noOutDegree())
+ .doAssertion();
+ }
+
+ private TaskDefinitionLog taskNode(String nodeName) {
+ TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog();
+ taskDefinitionLog.setCode(CodeGenerateUtils.getInstance().genCode());
+ taskDefinitionLog.setName(nodeName);
+ return taskDefinitionLog;
+ }
+
+ private ProcessTaskRelationLog edge(TaskDefinitionLog from, TaskDefinitionLog to) {
+ ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog();
+ processTaskRelationLog.setPreTaskCode(from == null ? 0 : from.getCode());
+ processTaskRelationLog.setPostTaskCode(to == null ? 0 : to.getCode());
+ return processTaskRelationLog;
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineIT.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineIT.java
index ac37c94438..ede8b55a37 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineIT.java
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.server.master.dag;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public class WorkflowEngineIT {
}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineTest.java
new file mode 100644
index 0000000000..b6e5dc9db5
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.server.master.dag;
+
+import static org.apache.dolphinscheduler.server.master.dag.WorkflowExecutionRunnableAssertions.workflowExecutionRunnable;
+import static org.apache.dolphinscheduler.server.master.dag.WorkflowExecutionRunnableRepositoryAssertions.workflowExecutionRunnableRepository;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.apache.dolphinscheduler.server.master.events.WorkflowOperationEvent;
+import org.apache.dolphinscheduler.server.master.exception.WorkflowExecuteRunnableNotFoundException;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class WorkflowEngineTest {
+
+ private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+ private WorkflowEngine workflowEngine;
+
+ @BeforeEach
+ public void before() {
+ workflowExecuteRunnableRepository = new WorkflowExecuteRunnableRepository();
+ workflowEngine = new WorkflowEngine(workflowExecuteRunnableRepository);
+ }
+
+ @Test
+ void triggerWorkflow() {
+ IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
+ Integer workflowInstanceId = emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+
+ workflowEngine.triggerWorkflow(emptyWorkflowExecuteRunnable);
+ workflowExecutionRunnable(emptyWorkflowExecuteRunnable)
+ .existEvent(WorkflowOperationEvent.triggerEvent(workflowInstanceId));
+ }
+
+ @Test
+ void pauseWorkflow_WorkflowNotExist() {
+ WorkflowExecuteRunnableNotFoundException exception =
+ assertThrows(WorkflowExecuteRunnableNotFoundException.class, () -> workflowEngine.pauseWorkflow(1));
+ assertEquals("WorkflowExecuteRunnable not found: [id=1]", exception.getMessage());
+ }
+
+ @Test
+ void pauseWorkflow_WorkflowExist() {
+ IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
+ Integer workflowInstanceId =
+ emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
+
+ workflowEngine.pauseWorkflow(workflowInstanceId);
+ workflowExecutionRunnable(emptyWorkflowExecuteRunnable)
+ .existEvent(WorkflowOperationEvent.pauseEvent(workflowInstanceId));
+ }
+
+ @Test
+ void killWorkflow_WorkflowNotExist() {
+ WorkflowExecuteRunnableNotFoundException exception =
+ assertThrows(WorkflowExecuteRunnableNotFoundException.class,
+ () -> workflowEngine.killWorkflow(1));
+ assertEquals("WorkflowExecuteRunnable not found: [id=1]", exception.getMessage());
+ }
+
+ @Test
+ void killWorkflow_WorkflowExist() {
+ IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
+ Integer workflowInstanceId =
+ emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
+
+ workflowEngine.killWorkflow(workflowInstanceId);
+ workflowExecutionRunnable(emptyWorkflowExecuteRunnable)
+ .existEvent(WorkflowOperationEvent.killEvent(workflowInstanceId));
+ }
+
+ @Test
+ void finalizeWorkflow_WorkflowNotExist() {
+ workflowEngine.finalizeWorkflow(1);
+ }
+
+ @Test
+ void finalizeWorkflow_WorkflowExist() {
+ IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
+ Integer workflowInstanceId =
+ emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
+ workflowExecutionRunnableRepository(workflowExecuteRunnableRepository)
+ .existWorkflowExecutionRunnable(workflowInstanceId);
+
+ workflowEngine.finalizeWorkflow(workflowInstanceId);
+ workflowExecutionRunnableRepository(workflowExecuteRunnableRepository)
+ .notExistWorkflowExecutionRunnable(workflowInstanceId);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableAssertions.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableAssertions.java
new file mode 100644
index 0000000000..65cf7ba7cd
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableAssertions.java
@@ -0,0 +1,48 @@
+/*
+ * 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.server.master.dag;
+
+import org.apache.dolphinscheduler.server.master.events.IEvent;
+
+import org.opentest4j.AssertionFailedError;
+
+class WorkflowExecutionRunnableAssertions {
+
+ private final IWorkflowExecutionRunnable workflowExecutionRunnable;
+
+ private WorkflowExecutionRunnableAssertions(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ this.workflowExecutionRunnable = workflowExecutionRunnable;
+ }
+
+ public static WorkflowExecutionRunnableAssertions workflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ return new WorkflowExecutionRunnableAssertions(workflowExecutionRunnable);
+ }
+
+ public void existEvent(IEvent event) {
+ if (event == null) {
+ throw new IllegalArgumentException("Event cannot be null");
+ }
+ boolean exist = workflowExecutionRunnable.getEventRepository().getAllEvent()
+ .stream()
+ .anyMatch(event1 -> event1.equals(event1));
+ if (!exist) {
+ throw new AssertionFailedError("The workflowExecuteRunnable doesn't exist event: " + event);
+ }
+ }
+
+}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableRepositoryAssertions.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableRepositoryAssertions.java
new file mode 100644
index 0000000000..e979f35cb3
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableRepositoryAssertions.java
@@ -0,0 +1,43 @@
+/*
+ * 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.server.master.dag;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class WorkflowExecutionRunnableRepositoryAssertions {
+
+ private final WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ private WorkflowExecutionRunnableRepositoryAssertions(WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ }
+
+ public static WorkflowExecutionRunnableRepositoryAssertions workflowExecutionRunnableRepository(WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ return new WorkflowExecutionRunnableRepositoryAssertions(workflowExecuteRunnableRepository);
+ }
+
+ public void existWorkflowExecutionRunnable(Integer workflowInstanceId) {
+ assertNotNull(workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId));
+ }
+
+ public void notExistWorkflowExecutionRunnable(Integer workflowInstanceId) {
+ assertNull(workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId));
+ }
+
+}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableTest.java
new file mode 100644
index 0000000000..69a7f83a50
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.server.master.dag;
+
+import static org.apache.dolphinscheduler.server.master.dag.WorkflowExecutionRunnableAssertions.workflowExecutionRunnable;
+
+import org.apache.dolphinscheduler.server.master.events.WorkflowTriggeredEvent;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class WorkflowExecutionRunnableTest {
+
+ private WorkflowExecutionRunnable workflowExecutionRunnable;
+
+ @BeforeEach
+ public void before() {
+ workflowExecutionRunnable = MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
+ }
+
+ @Test
+ void start() {
+ workflowExecutionRunnable.start();
+ workflowExecutionRunnable(workflowExecutionRunnable)
+ .existEvent(new WorkflowTriggeredEvent(
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance().getId()));
+ }
+
+ @Test
+ void pause() {
+ }
+
+ @Test
+ void kill() {
+ }
+}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventTest.java
new file mode 100644
index 0000000000..00bea9f601
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.server.master.events;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+class WorkflowOperationEventTest {
+
+ @Test
+ void triggerEvent() {
+ WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.triggerEvent(1);
+ assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
+ assertEquals(WorkflowOperationType.TRIGGER, workflowOperationEvent.getWorkflowOperationType());
+ }
+
+ @Test
+ void pauseEvent() {
+ WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.pauseEvent(1);
+ assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
+ assertEquals(WorkflowOperationType.PAUSE, workflowOperationEvent.getWorkflowOperationType());
+ }
+
+ @Test
+ void killEvent() {
+ WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.killEvent(1);
+ assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
+ assertEquals(WorkflowOperationType.KILL, workflowOperationEvent.getWorkflowOperationType());
+ }
+}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/utils/ExceptionUtilsTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/utils/ExceptionUtilsTest.java
new file mode 100644
index 0000000000..440f33b474
--- /dev/null
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/utils/ExceptionUtilsTest.java
@@ -0,0 +1,18 @@
+package org.apache.dolphinscheduler.server.master.utils;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.dao.DataAccessResourceFailureException;
+
+class ExceptionUtilsTest {
+
+ @Test
+ void isDatabaseConnectedFailedException() {
+ // todo: Directly connect to database
+ assertTrue(ExceptionUtils.isDatabaseConnectedFailedException(
+ new DataAccessResourceFailureException("Database connection failed")));
+ assertFalse(ExceptionUtils.isDatabaseConnectedFailedException(new RuntimeException("runtime exception")));
+ }
+}
diff --git a/dolphinscheduler-workflow-engine/README.md b/dolphinscheduler-workflow-engine/README.md
new file mode 100644
index 0000000000..6a14acf775
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/README.md
@@ -0,0 +1,2 @@
+# Introduction
+
\ No newline at end of file
diff --git a/dolphinscheduler-workflow-engine/pom.xml b/dolphinscheduler-workflow-engine/pom.xml
new file mode 100644
index 0000000000..40a360e7c8
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <artifactId>dolphinscheduler</artifactId>
+ <version>dev-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>dolphinscheduler-workflow-engine</artifactId>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <artifactId>dolphinscheduler-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <artifactId>dolphinscheduler-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
new file mode 100644
index 0000000000..63e6370887
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
@@ -0,0 +1,146 @@
+/*
+ * 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.workflow.engine.dag;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * The Directed Acyclic Graph class.
+ * <p>
+ * The DAG is a directed graph, which contains the nodes and the edges, the nodeName is the unique identifier of the node.
+ * The nodes are the tasks, the edges are the dependencies between the tasks.
+ * The DAG is acyclic, which means there is no cycle in the graph.
+ * The DAG is a directed graph, which means the edges have direction.
+ *
+ */
+public interface DAG {
+
+ /**
+ * Get the direct post node of given dagNode, if the dagNode is null, return the nodes which doesn't have inDegrees.
+ * e.g. The DAG is:
+ * <pre>
+ * {@code
+ * 1 -> 2 -> 3
+ * 4 -> 5
+ * 6
+ * }
+ * </pre>
+ * <li> The post node of 1 is 2.
+ * <li> The post node of 3 is empty.
+ * <li> The post node of null is 1,4,6.
+ *
+ * @param dagNode the node of the DAG, can be null.
+ * @return post node list, sort by priority.
+ */
+ List<DAGNode> getDirectPostNodes(DAGNode dagNode);
+
+ /**
+ * Same with {@link #getDirectPostNodes(DAGNode)}.
+ * <p>
+ * If the dagNodeName is null, return the nodes which doesn't have inDegrees. Otherwise, return the post nodes of
+ * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return post task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<DAGNode> getDirectPostNodes(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPostNodes(dagNode);
+ }
+
+ /**
+ * Same with {@link #getDirectPostNodes(String)}. Return the post node names.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return post task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<String> getDirectPostNodeNames(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPostNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the direct pre node of given dagNode, if the dagNode is null, return the nodes which doesn't have outDegrees.
+ * e.g. The DAG is:
+ * <pre>
+ * {@code
+ * 1 -> 2 -> 3
+ * 4 -> 5
+ * 6
+ * }
+ * </pre>
+ * <li> The pre node of 1 is empty.
+ * <li> The pre node of 3 is 2.
+ * <li> The pre node of null is 3,5,6.
+ *
+ * @param dagNode the node of the DAG, can be null.
+ * @return pre node list, sort by priority.
+ */
+ List<DAGNode> getDirectPreNodes(DAGNode dagNode);
+
+ /**
+ * Same with {@link #getDirectPreNodes(DAGNode)}.
+ * <p>
+ * If the dagNodeName is null, return the nodes which doesn't have outDegrees. Otherwise, return the pre nodes of
+ * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return pre task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<DAGNode> getDirectPreNodes(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPreNodes(dagNode);
+ }
+
+ /**
+ * Same with {@link #getDirectPreNodes(String)}. Return the pre node names.
+ *
+ * @param dagNodeName task name, can be null.
+ * @return pre task name list, sort by priority.
+ * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
+ */
+ default List<String> getDirectPreNodeNames(String dagNodeName) {
+ DAGNode dagNode = getDAGNode(dagNodeName);
+ if (dagNodeName != null && dagNode == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPreNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the node of the DAG by the node name.
+ *
+ * @param nodeName the node name.
+ * @return the node of the DAG, return null if cannot find the node.
+ */
+ DAGNode getDAGNode(String nodeName);
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGEdge.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGEdge.java
new file mode 100644
index 0000000000..8e2bdc2be6
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGEdge.java
@@ -0,0 +1,53 @@
+/*
+ * 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.workflow.engine.dag;
+
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * The edge of the DAG.
+ * <p>
+ * The edge contains the fromNodeName and the toNodeName, the fromNodeName is the node name of the from node, the toNodeName is the node name of the to node.
+ * <p>
+ * The formNodeName can be null, which means the edge is from the start node of the DAG.
+ * The toNodeName can be null, which means the edge is to the end node of the DAG.
+ * The fromNodeName and the toNodeName cannot be null at the same time.
+ */
+@Data
+@Builder
+@NoArgsConstructor
+public class DAGEdge {
+
+ private String fromNodeName;
+ private String toNodeName;
+
+ public DAGEdge(String fromNodeName, String toNodeName) {
+ if (fromNodeName == null && toNodeName == null) {
+ throw new IllegalArgumentException("fromNodeName and toNodeName cannot be null at the same time"
+ + "fromNodeName: " + fromNodeName + ", toNodeName: " + toNodeName);
+ }
+ if (fromNodeName != null && fromNodeName.equals(toNodeName)) {
+ throw new IllegalArgumentException("fromNodeName and toNodeName cannot be the same"
+ + "fromNodeName: " + fromNodeName + ", toNodeName: " + toNodeName);
+ }
+ this.fromNodeName = fromNodeName;
+ this.toNodeName = toNodeName;
+ }
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNode.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNode.java
new file mode 100644
index 0000000000..2e945a5463
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNode.java
@@ -0,0 +1,92 @@
+/*
+ * 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.workflow.engine.dag;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+/**
+ * The node of the DAG.
+ * <p>
+ * The node contains the node name, the content of the node, the inDegrees and the outDegrees.
+ * The inDegrees is the edge from other nodes to the current node, the outDegrees is the edge from the current
+ * node to other nodes.
+ */
+@Getter
+@Builder
+@NoArgsConstructor
+public class DAGNode implements IDAGNode {
+
+ private String nodeName;
+
+ /**
+ * whether the node is skipped, default is false, which means the node is not skipped.
+ * If the node is skipped, the node will not be executed.
+ */
+ @Builder.Default
+ private boolean skip = false;
+
+ private List<DAGEdge> inDegrees;
+ private List<DAGEdge> outDegrees;
+
+ public DAGNode(String nodeName,
+ List<DAGEdge> inDegrees,
+ List<DAGEdge> outDegrees) {
+ this(nodeName, false, inDegrees, outDegrees);
+ }
+
+ public DAGNode(String nodeName,
+ boolean skip,
+ List<DAGEdge> inDegrees,
+ List<DAGEdge> outDegrees) {
+ if (StringUtils.isEmpty(nodeName)) {
+ throw new IllegalArgumentException("nodeName cannot be empty");
+ }
+
+ if (CollectionUtils.isNotEmpty(inDegrees)) {
+ inDegrees.forEach(dagEdge -> {
+ if (!nodeName.equals(dagEdge.getToNodeName())) {
+ throw new IllegalArgumentException(
+ "The toNodeName of inDegree should be the nodeName of the node: "
+ + nodeName + ", inDegree: " + dagEdge);
+ }
+ });
+ }
+
+ if (CollectionUtils.isNotEmpty(outDegrees)) {
+ outDegrees.forEach(dagEdge -> {
+ if (!nodeName.equals(dagEdge.getFromNodeName())) {
+ throw new IllegalArgumentException(
+ "The fromNodeName of outDegree should be the nodeName of the node: "
+ + nodeName + ", outDegree: " + dagEdge);
+ }
+ });
+ }
+
+ this.nodeName = nodeName;
+ this.inDegrees = inDegrees;
+ this.outDegrees = outDegrees;
+ this.skip = skip;
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeDefinition.java
similarity index 72%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeDefinition.java
index ac37c94438..b72d8ee6ba 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeDefinition.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class DAGNodeDefinition {
+
+ private String nodeName;
+
+ private boolean skip;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
index ac37c94438..c3d85ae3ac 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.List;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface IDAGNode {
+
+ String getNodeName();
+
+ boolean isSkip();
+
+ List<DAGEdge> getInDegrees();
+
+ List<DAGEdge> getOutDegrees();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNodeAction.java
similarity index 76%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNodeAction.java
index ac37c94438..9b6684a37f 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNodeAction.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public class TaskExecutionContextCreateException extends MasterException {
+/**
+ * The IDAGNodeAction represent the action of a DAG node.
+ */
+public interface IDAGNodeAction {
+
+ void run();
+
+ void kill();
+
+ void pause();
+
+ void success();
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ void failure();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
new file mode 100644
index 0000000000..c31749af93
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
@@ -0,0 +1,75 @@
+/*
+ * 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.workflow.engine.dag;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * The IWorkflowDAG represent the DAG of a workflow.
+ */
+public class WorkflowDAG implements DAG {
+
+ private final Map<String, DAGNode> dagNodeMap;
+
+ public WorkflowDAG(List<DAGNode> dagNodes) {
+ this.dagNodeMap = dagNodes.stream().collect(Collectors.toMap(DAGNode::getNodeName, Function.identity()));
+ }
+
+ @Override
+ public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
+ final String nodeName = dagNode.getNodeName();
+ if (!dagNodeMap.containsKey(nodeName)) {
+ return Collections.emptyList();
+ }
+ DAGNode node = dagNodeMap.get(nodeName);
+ List<DAGNode> dagNodes = new ArrayList<>();
+ for (DAGEdge edge : node.getOutDegrees()) {
+ if (dagNodeMap.containsKey(edge.getToNodeName())) {
+ dagNodes.add(dagNodeMap.get(edge.getToNodeName()));
+ }
+ }
+ return dagNodes;
+ }
+
+ @Override
+ public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
+ final String nodeName = dagNode.getNodeName();
+ if (!dagNodeMap.containsKey(nodeName)) {
+ return Collections.emptyList();
+ }
+ DAGNode node = dagNodeMap.get(nodeName);
+ List<DAGNode> dagNodes = new ArrayList<>();
+ for (DAGEdge edge : node.getInDegrees()) {
+ if (dagNodeMap.containsKey(edge.getFromNodeName())) {
+ dagNodes.add(dagNodeMap.get(edge.getFromNodeName()));
+ }
+ }
+ return dagNodes;
+ }
+
+ @Override
+ public DAGNode getDAGNode(String nodeName) {
+ return dagNodeMap.get(nodeName);
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilder.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilder.java
new file mode 100644
index 0000000000..fbf666d947
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilder.java
@@ -0,0 +1,107 @@
+/*
+ * 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.workflow.engine.dag;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Used to build WorkflowDAG, you need to add TaskNode first, then add TaskEdge.
+ * After adding all the TaskNodes and TaskEdges, you can call the build method to get the WorkflowDAG.
+ * <p>
+ * Example:
+ * <pre>
+ * {@code
+ * WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ * .addTaskNode(taskNodeA)
+ * .addTaskNode(taskNodeB)
+ * .addTaskNode(taskNodeC)
+ * .addTaskEdge(edgeAB)
+ * .addTaskEdge(edgeBC)
+ * .build();
+ * }
+ * </pre>
+ */
+public class WorkflowDAGBuilder {
+
+ private final Map<String, DAGNode> taskNameMap;
+
+ private WorkflowDAGBuilder() {
+ this.taskNameMap = new HashMap<>();
+ }
+
+ public static WorkflowDAGBuilder newBuilder() {
+ return new WorkflowDAGBuilder();
+ }
+
+ public WorkflowDAGBuilder addTaskNodes(List<DAGNodeDefinition> dagNodes) {
+ dagNodes.forEach(this::addTaskNode);
+ return this;
+ }
+
+ public WorkflowDAGBuilder addTaskNode(DAGNodeDefinition dagNodeDefinition) {
+ String nodeName = dagNodeDefinition.getNodeName();
+ if (taskNameMap.containsKey(nodeName)) {
+ throw new IllegalArgumentException("TaskNode with name " + nodeName + " already exists");
+ }
+
+ DAGNode taskNode = DAGNode.builder()
+ .nodeName(nodeName)
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .skip(dagNodeDefinition.isSkip())
+ .build();
+ taskNameMap.put(nodeName, taskNode);
+ return this;
+ }
+
+ public WorkflowDAGBuilder addTaskEdges(List<DAGEdge> processTaskRelations) {
+ processTaskRelations.forEach(this::addTaskEdge);
+ return this;
+ }
+
+ public WorkflowDAGBuilder addTaskEdge(DAGEdge dagEdge) {
+ String fromNodeName = dagEdge.getFromNodeName();
+ String toNodeName = dagEdge.getToNodeName();
+
+ if (taskNameMap.containsKey(fromNodeName)) {
+ DAGNode fromTask = taskNameMap.get(fromNodeName);
+ if (fromTask.getOutDegrees().contains(dagEdge)) {
+ throw new IllegalArgumentException(
+ "Edge from " + fromNodeName + " to " + toNodeName + " already exists");
+ }
+ fromTask.getOutDegrees().add(dagEdge);
+ }
+ if (taskNameMap.containsKey(toNodeName)) {
+ DAGNode toTask = taskNameMap.get(toNodeName);
+ if (toTask.getInDegrees().contains(dagEdge)) {
+ throw new IllegalArgumentException(
+ "Edge from " + fromNodeName + " to " + toNodeName + " already exists");
+ }
+ toTask.getInDegrees().add(dagEdge);
+ }
+ return this;
+ }
+
+ public WorkflowDAG build() {
+ return new WorkflowDAG(new ArrayList<>(taskNameMap.values()));
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
new file mode 100644
index 0000000000..d5273367ef
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
@@ -0,0 +1,171 @@
+/*
+ * 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.workflow.engine.engine;
+
+import org.apache.dolphinscheduler.workflow.engine.dag.DAGNode;
+import org.apache.dolphinscheduler.workflow.engine.event.TaskOperationEvent;
+import org.apache.dolphinscheduler.workflow.engine.event.TaskOperationType;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnableFactory;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionDAG;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DAGEngine implements IDAGEngine {
+
+ private final IWorkflowExecutionContext workflowExecutionContext;
+
+ private final ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
+
+ public DAGEngine(IWorkflowExecutionContext workflowExecutionContext,
+ ITaskExecutionRunnableFactory taskExecutionRunnableFactory) {
+ this.workflowExecutionContext = workflowExecutionContext;
+ this.taskExecutionRunnableFactory = taskExecutionRunnableFactory;
+ }
+
+ @Override
+ public void triggerNextTasks(String parentTaskNodeName) {
+ workflowExecutionContext.getWorkflowExecutionDAG()
+ .getDirectPostNodeNames(parentTaskNodeName)
+ .forEach(this::triggerTask);
+ }
+
+ @Override
+ public void triggerTask(String taskName) {
+ IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
+ DAGNode dagNode = workflowExecutionDAG.getDAGNode(taskName);
+ if (dagNode == null) {
+ log.error("Cannot find the DAGNode for task: {}", taskName);
+ return;
+ }
+
+ // todo: Use condition check?
+ // How to make sure the
+ if (!workflowExecutionDAG.isTaskAbleToBeTriggered(taskName)) {
+ log.info("The task: {} is not able to be triggered", taskName);
+ return;
+ }
+
+ if (dagNode.isSkip()) {
+ log.info("The task: {} is skipped", taskName);
+ triggerNextTasks(taskName);
+ return;
+ }
+
+ ITaskExecutionRunnable taskExecutionRunnable =
+ taskExecutionRunnableFactory.createTaskExecutionRunnable(taskName, workflowExecutionContext);
+ workflowExecutionDAG.storeTaskExecutionRunnable(taskExecutionRunnable);
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.RUN)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void failoverTask(Integer taskInstanceId) {
+ IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
+ ITaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionDAG.getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+ ITaskExecutionRunnable failoverTaskExecutionRunnable = taskExecutionRunnableFactory
+ .createFailoverTaskExecutionRunnable(taskExecutionRunnable, workflowExecutionContext);
+ workflowExecutionDAG.storeTaskExecutionRunnable(failoverTaskExecutionRunnable);
+
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.FAILOVER)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void retryTask(Integer taskInstanceId) {
+ IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
+ ITaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionDAG.getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+ ITaskExecutionRunnable retryTaskExecutionRunnable = taskExecutionRunnableFactory
+ .createRetryTaskExecutionRunnable(taskExecutionRunnable, workflowExecutionContext);
+ workflowExecutionDAG.storeTaskExecutionRunnable(retryTaskExecutionRunnable);
+
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.RETRY)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void pauseAllTask() {
+ workflowExecutionContext.getWorkflowExecutionDAG()
+ .getActiveTaskExecutionRunnable()
+ .stream()
+ .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
+ .forEach(this::pauseTask);
+ }
+
+ @Override
+ public void pauseTask(Integer taskInstanceId) {
+ ITaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.PAUSE)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+ @Override
+ public void killAllTask() {
+ workflowExecutionContext.getWorkflowExecutionDAG()
+ .getActiveTaskExecutionRunnable()
+ .stream()
+ .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
+ .forEach(this::killTask);
+ }
+
+ @Override
+ public void killTask(Integer taskInstanceId) {
+ ITaskExecutionRunnable taskExecutionRunnable =
+ workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
+ if (taskExecutionRunnable == null) {
+ log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
+ return;
+ }
+
+ TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
+ .taskExecutionRunnable(taskExecutionRunnable)
+ .taskOperationType(TaskOperationType.KILL)
+ .build();
+ workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngineFactory.java
similarity index 51%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngineFactory.java
index ac37c94438..c07ca6ffbb 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngineFactory.java
@@ -15,12 +15,24 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnableFactory;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DAGEngineFactory implements IDAGEngineFactory {
+
+ private final ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
+
+ public DAGEngineFactory(ITaskExecutionRunnableFactory taskExecutionRunnableFactory) {
+ this.taskExecutionRunnableFactory = taskExecutionRunnableFactory;
}
+ @Override
+ public IDAGEngine createDAGEngine(IWorkflowExecutionContext workflowExecutionContext) {
+ return new DAGEngine(workflowExecutionContext, taskExecutionRunnableFactory);
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngine.java
new file mode 100644
index 0000000000..0971e2a179
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngine.java
@@ -0,0 +1,72 @@
+/*
+ * 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.workflow.engine.engine;
+
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionDAG;
+
+/**
+ * The IDAGEngine is responsible for triggering, killing, pausing, and finalizing task in {@link org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG}.
+ * <p>All DAG operation should directly use the method in IDAGEngine, new {@link IWorkflowExecutionDAG} should be triggered by new IDAGEngine.
+ */
+public interface IDAGEngine {
+
+ /**
+ * Trigger the tasks which are post of the given task.
+ * <P> If there are no task after the given taskNode, will try to finish the WorkflowExecutionRunnable.
+ * <p> If the
+ *
+ * @param parentTaskNodeName the parent task name
+ */
+ void triggerNextTasks(String parentTaskNodeName);
+
+ /**
+ * Trigger the given task
+ *
+ * @param taskName task name
+ */
+ void triggerTask(String taskName);
+
+ /**
+ * Failover the given task.
+ *
+ * @param taskInstanceId taskInstanceId
+ */
+ void failoverTask(Integer taskInstanceId);
+
+ /**
+ * Retry the given task.
+ *
+ * @param taskInstanceId taskInstanceId
+ */
+ void retryTask(Integer taskInstanceId);
+
+ void pauseAllTask();
+
+ /**
+ * Pause the given task.
+ */
+ void pauseTask(Integer taskInstanceId);
+
+ void killAllTask();
+
+ /**
+ * Kill the given task.
+ */
+ void killTask(Integer taskId);
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngineFactory.java
similarity index 75%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngineFactory.java
index ac37c94438..c0d134ad5c 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngineFactory.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface IDAGEngineFactory {
+
+ IDAGEngine createDAGEngine(IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
new file mode 100644
index 0000000000..d1df4df7f5
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
@@ -0,0 +1,58 @@
+/*
+ * 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.workflow.engine.engine;
+
+import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunnableNotFoundException;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+
+/**
+ * The WorkflowEngine is responsible for starting, stopping, pausing, and finalizing workflows.
+ */
+public interface IWorkflowEngine {
+
+ /**
+ * Trigger a workflow to start.
+ *
+ * @param workflowExecuteRunnable the workflow to start
+ */
+ void triggerWorkflow(IWorkflowExecutionRunnable workflowExecuteRunnable);
+
+ /**
+ * Pause a workflow instance.
+ *
+ * @param workflowInstanceId the ID of the workflow to pause
+ * @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
+ */
+ void pauseWorkflow(Integer workflowInstanceId);
+
+ /**
+ * Kill a workflow instance.
+ *
+ * @param workflowInstanceId the ID of the workflow to stop
+ * @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
+ */
+ void killWorkflow(Integer workflowInstanceId);
+
+ /**
+ * Finalize a workflow instance. Once a workflow has been finalized, then it cannot receive new operation, and will be removed from memory.
+ *
+ * @param workflowInstanceId the ID of the workflow to finalize
+ */
+ void finalizeWorkflow(Integer workflowInstanceId);
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngineFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngineFactory.java
index ac37c94438..b011e0d16a 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngineFactory.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IWorkflowEngineFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ IWorkflowEngine createWorkflowEngine();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
new file mode 100644
index 0000000000..92bec2fe1f
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
@@ -0,0 +1,82 @@
+/*
+ * 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.workflow.engine.engine;
+
+import org.apache.dolphinscheduler.workflow.engine.event.WorkflowOperationEvent;
+import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunnableNotFoundException;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class WorkflowEngine implements IWorkflowEngine {
+
+ private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ public WorkflowEngine(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ }
+
+ @Override
+ public void triggerWorkflow(IWorkflowExecutionRunnable workflowExecuteRunnable) {
+ IWorkflowExecutionContext workflowExecutionContext = workflowExecuteRunnable.getWorkflowExecutionContext();
+ Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
+ log.info("Triggering WorkflowExecutionRunnable: {}", workflowExecutionContext.getWorkflowInstanceName());
+ workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(workflowExecuteRunnable);
+ workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.triggerEvent(workflowInstanceId));
+ }
+
+ @Override
+ public void pauseWorkflow(Integer workflowInstanceId) {
+ IWorkflowExecutionRunnable workflowExecuteRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ if (workflowExecuteRunnable == null) {
+ throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
+ }
+ log.info("Pausing WorkflowExecutionRunnable: {}",
+ workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
+ workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.pauseEvent(workflowInstanceId));
+ }
+
+ @Override
+ public void killWorkflow(Integer workflowInstanceId) {
+ IWorkflowExecutionRunnable workflowExecuteRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ if (workflowExecuteRunnable == null) {
+ throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
+ }
+ log.info("Killing WorkflowExecutionRunnable: {}",
+ workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
+ workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.killEvent(workflowInstanceId));
+ }
+
+ @Override
+ public void finalizeWorkflow(Integer workflowInstanceId) {
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ if (workflowExecutionRunnable == null) {
+ return;
+ }
+ log.info("Finalizing WorkflowExecutionRunnable: {}",
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
+ workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineFactory.java
similarity index 67%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineFactory.java
index ac37c94438..5a32510bd1 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineFactory.java
@@ -15,12 +15,14 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecuteRunnableRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public class WorkflowEngineFactory implements IWorkflowEngineFactory {
+ @Override
+ public IWorkflowEngine createWorkflowEngine() {
+ return new WorkflowEngine(SingletonWorkflowExecuteRunnableRepository.getInstance());
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventEngine.java
new file mode 100644
index 0000000000..35bfe079c5
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventEngine.java
@@ -0,0 +1,111 @@
+/*
+ * 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.workflow.engine.event;
+
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+
+import org.apache.commons.lang3.time.StopWatch;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.slf4j.MDC;
+
+@Slf4j
+public class EventEngine extends BaseDaemonThread {
+
+ private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ private final EventFirer eventFirer;
+
+ private final Set<Integer> firingWorkflowInstanceIds;
+
+ public EventEngine(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository,
+ EventFirer eventFirer) {
+ super("EventEngine");
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ this.eventFirer = eventFirer;
+ this.firingWorkflowInstanceIds = ConcurrentHashMap.newKeySet();
+ }
+
+ @Override
+ public synchronized void start() {
+ super.start();
+ log.info(getClass().getName() + " started");
+ }
+
+ @Override
+ public void run() {
+ for (;;) {
+ try {
+ StopWatch stopWatch = StopWatch.createStarted();
+ fireAllActiveEvents();
+ stopWatch.stop();
+ log.info("Fire all active events cost: {} ms", stopWatch.getTime());
+ this.wait(5_000);
+ } catch (Throwable throwable) {
+ log.error("Fire active event error", throwable);
+ ThreadUtils.sleep(3_000);
+ }
+ }
+ }
+
+ public void fireAllActiveEvents() {
+ Collection<IWorkflowExecutionRunnable> workflowExecutionRunnableCollection =
+ workflowExecuteRunnableRepository.getActiveWorkflowExecutionRunnable();
+ for (IWorkflowExecutionRunnable workflowExecutionRunnable : workflowExecutionRunnableCollection) {
+ IWorkflowExecutionContext workflowExecutionContext =
+ workflowExecutionRunnable.getWorkflowExecutionContext();
+ final Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
+ final String workflowInstanceName = workflowExecutionContext.getWorkflowInstanceName();
+ try {
+ MDC.put(Constants.WORKFLOW_INSTANCE_ID_MDC_KEY, String.valueOf(workflowInstanceId));
+ if (firingWorkflowInstanceIds.contains(workflowInstanceId)) {
+ log.debug("WorkflowExecutionRunnable: {} is already in firing", workflowInstanceName);
+ return;
+ }
+ IEventRepository workflowEventRepository = workflowExecutionRunnable.getEventRepository();
+ firingWorkflowInstanceIds.add(workflowInstanceId);
+ eventFirer.fireActiveEvents(workflowEventRepository)
+ .whenComplete((fireCount, ex) -> {
+ firingWorkflowInstanceIds.remove(workflowInstanceId);
+ if (ex != null) {
+ log.error("Fire event for WorkflowExecutionRunnable: {} error", workflowInstanceName,
+ ex);
+ } else {
+ if (fireCount > 0) {
+ log.info("Fire {} events for WorkflowExecutionRunnable: {} success", fireCount,
+ workflowInstanceName);
+ }
+ }
+ });
+ } finally {
+ MDC.remove(Constants.WORKFLOW_INSTANCE_ID_MDC_KEY);
+ }
+ }
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventFirer.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventFirer.java
new file mode 100644
index 0000000000..0026bd0c21
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventFirer.java
@@ -0,0 +1,91 @@
+/*
+ * 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.workflow.engine.event;
+
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.workflow.engine.utils.ExceptionUtils;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class EventFirer implements IEventFirer {
+
+ private final IEventOperatorManager<IEvent> eventOperatorManager;
+
+ private final ThreadPoolExecutor eventFireThreadPool;
+
+ public EventFirer(IEventOperatorManager<IEvent> eventOperatorManager, int eventFireThreadPoolSize) {
+ this.eventOperatorManager = eventOperatorManager;
+ this.eventFireThreadPool =
+ ThreadUtils.newDaemonFixedThreadExecutor("EventFireThreadPool", eventFireThreadPoolSize);
+ }
+
+ @Override
+ public CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository) {
+ if (eventRepository.getEventSize() == 0) {
+ return CompletableFuture.completedFuture(0);
+ }
+ return CompletableFuture.supplyAsync(() -> {
+ int fireCount = 0;
+ for (;;) {
+ IEvent event = eventRepository.poolEvent();
+ if (event == null) {
+ break;
+ }
+
+ if (event instanceof IAsyncEvent) {
+ fireAsyncEvent(event);
+ fireCount++;
+ continue;
+ }
+ try {
+ fireSyncEvent(event);
+ fireCount++;
+ } catch (Exception ex) {
+ if (ExceptionUtils.isDatabaseConnectedFailedException(ex)) {
+ // If the event is failed due to cannot connect to DB, we should retry it
+ eventRepository.storeEventToHead(event);
+ }
+ throw ex;
+ }
+ }
+ return fireCount;
+ }, eventFireThreadPool);
+ }
+
+ private void fireAsyncEvent(IEvent event) {
+ CompletableFuture.runAsync(() -> {
+ log.info("Begin fire IAsyncEvent: {}", event);
+ eventOperatorManager.getEventOperator(event).handleEvent(event);
+ log.info("Success fire IAsyncEvent: {}", event);
+ }, eventFireThreadPool).exceptionally(ex -> {
+ log.error("Failed to fire IAsyncEvent: {}", event, ex);
+ return null;
+ });
+ }
+
+ private void fireSyncEvent(IEvent event) {
+ log.info("Begin fire SyncEvent: {}", event);
+ eventOperatorManager.getEventOperator(event).handleEvent(event);
+ log.info("Success fire SyncEvent: {}", event);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventOperatorManager.java
similarity index 65%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventOperatorManager.java
index ac37c94438..fb0e3d0a50 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventOperatorManager.java
@@ -15,12 +15,22 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.extern.slf4j.Slf4j;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+import org.springframework.stereotype.Component;
+
+/**
+ * The event operator manager interface used to get {@link ITaskEventOperator}.
+ */
+@Slf4j
+@Component
+public class EventOperatorManager implements IEventOperatorManager<IEvent> {
+
+ @Override
+ public IEventOperator<IEvent> getEventOperator(IEvent event) {
+ return null;
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IAsyncEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IAsyncEvent.java
index ac37c94438..2de1ebb9cc 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IAsyncEvent.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
-
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+package org.apache.dolphinscheduler.workflow.engine.event;
+/**
+ * Mark the event as AsyncEvent, if the event is marked as AsyncEvent, the event will be handled asynchronously and we don't .
+ */
+public interface IAsyncEvent {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IDelayEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IDelayEvent.java
index ac37c94438..05a883d2ca 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IDelayEvent.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IDelayEvent {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ long getEventCreateTime();
+
+ long getDelayTime();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
index ac37c94438..22fd7ec940 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface IEvent {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventFirer.java
similarity index 66%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventFirer.java
index ac37c94438..131bac9412 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventFirer.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.concurrent.CompletableFuture;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+/**
+ * The event firer interface used to fire event.
+ *
+ */
+public interface IEventFirer {
+
+ /**
+ * Fire all active events in the event repository
+ *
+ * @return the count of fired success events
+ */
+ CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperator.java
similarity index 75%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperator.java
index ac37c94438..be65031c06 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperator.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+/**
+ * The event operator interface used to handle event.
+ */
+public interface IEventOperator<E> {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * Handle the given event
+ *
+ * @param event event
+ */
+ void handleEvent(E event);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperatorManager.java
similarity index 67%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperatorManager.java
index ac37c94438..68cffa4ecc 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperatorManager.java
@@ -15,12 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+/**
+ * The event operator manager interface used to get event operator.
+ */
+public interface IEventOperatorManager<E> {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * Get the {@link IEventOperator} for the given event.
+ *
+ * @param event event
+ * @return event operator for the given event
+ */
+ IEventOperator<E> getEventOperator(E event);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventRepository.java
similarity index 69%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventRepository.java
index ac37c94438..f96df57680 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventRepository.java
@@ -15,12 +15,23 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.List;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+/**
+ * The event repository interface used to store event.
+ */
+public interface IEventRepository {
+
+ void storeEventToTail(IEvent event);
+
+ void storeEventToHead(IEvent event);
+
+ IEvent poolEvent();
+
+ int getEventSize();
+
+ List<IEvent> getAllEvent();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ISyncEvent.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ISyncEvent.java
index ac37c94438..5b4ecb6162 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ISyncEvent.java
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
-
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+package org.apache.dolphinscheduler.workflow.engine.event;
+public interface ISyncEvent {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEvent.java
similarity index 76%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEvent.java
index ac37c94438..dd1f315aed 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEvent.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface ITaskEvent extends IEvent {
+
+ ITaskExecutionRunnable getTaskExecutionRunnable();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEventOperator.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEventOperator.java
index ac37c94438..f015a61e2c 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEventOperator.java
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface ITaskEventOperator<E extends ITaskEvent> extends IEventOperator<E> {
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEvent.java
similarity index 73%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEvent.java
index ac37c94438..304776b582 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEvent.java
@@ -15,12 +15,15 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IWorkflowEvent extends IEvent {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * The id of WorkflowInstance which the event is related to
+ *
+ * @return workflowInstanceId, shouldn't be null
+ */
+ Integer getWorkflowInstanceId();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEventOperator.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEventOperator.java
index ac37c94438..48dc80ee65 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEventOperator.java
@@ -15,12 +15,9 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
-
-public class TaskExecutionContextCreateException extends MasterException {
-
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+package org.apache.dolphinscheduler.workflow.engine.event;
+public interface IWorkflowEventOperator<E extends IWorkflowEvent>
+ extends
+ IEventOperator<E> {
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/MemoryEventRepository.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/MemoryEventRepository.java
new file mode 100644
index 0000000000..f6f2c239fc
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/MemoryEventRepository.java
@@ -0,0 +1,64 @@
+/*
+ * 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.workflow.engine.event;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingDeque;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class MemoryEventRepository implements IEventRepository {
+
+ private final LinkedBlockingDeque<IEvent> eventQueue;
+
+ private MemoryEventRepository() {
+ this.eventQueue = new LinkedBlockingDeque<>();
+ }
+
+ public static MemoryEventRepository newInstance() {
+ return new MemoryEventRepository();
+ }
+
+ @Override
+ public void storeEventToTail(IEvent event) {
+ log.info("Store event to tail: {}", event);
+ eventQueue.offerLast(event);
+ }
+
+ @Override
+ public void storeEventToHead(IEvent event) {
+ eventQueue.offerFirst(event);
+ }
+
+ @Override
+ public IEvent poolEvent() {
+ return eventQueue.poll();
+ }
+
+ @Override
+ public int getEventSize() {
+ return eventQueue.size();
+ }
+
+ public List<IEvent> getAllEvent() {
+ return new ArrayList<>(eventQueue);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
similarity index 62%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
index ac37c94438..1afb6ee7d8 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
@@ -15,12 +15,23 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class TaskOperationEvent implements ITaskEvent, ISyncEvent {
+
+ private ITaskExecutionRunnable taskExecutionRunnable;
+
+ private TaskOperationType taskOperationType;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventOperator.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventOperator.java
new file mode 100644
index 0000000000..e17868822c
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventOperator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.workflow.engine.event;
+
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class TaskOperationEventOperator implements ITaskEventOperator<TaskOperationEvent> {
+
+ @Override
+ public void handleEvent(TaskOperationEvent event) {
+ ITaskExecutionRunnable taskExecutionRunnable = event.getTaskExecutionRunnable();
+ switch (event.getTaskOperationType()) {
+ case RUN:
+ taskExecutionRunnable.dispatch();
+ break;
+ case KILL:
+ taskExecutionRunnable.kill();
+ break;
+ case PAUSE:
+ taskExecutionRunnable.pause();
+ break;
+ default:
+ log.error("Unknown TaskOperationType for event: {}", event);
+ }
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationType.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationType.java
index ac37c94438..094164c789 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationType.java
@@ -15,12 +15,15 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+public enum TaskOperationType {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ FAILOVER,
+ RUN,
+ RETRY,
+ KILL,
+ PAUSE,
+ ;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
similarity index 69%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
index ac37c94438..b807e726fa 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
@@ -15,12 +15,21 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowFailedEvent implements IWorkflowEvent {
+
+ private Integer workflowInstanceId;
+
+ private String failedReason;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEvent.java
similarity index 70%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEvent.java
index ac37c94438..0c23e15f2b 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEvent.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class WorkflowFinalizeEvent implements IWorkflowEvent, ISyncEvent {
+ private Integer workflowInstanceId;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEventOperator.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEventOperator.java
new file mode 100644
index 0000000000..4c64e4c62d
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEventOperator.java
@@ -0,0 +1,41 @@
+/*
+ * 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.workflow.engine.event;
+
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class WorkflowFinalizeEventOperator
+ implements
+ IWorkflowEventOperator<WorkflowFinalizeEvent> {
+
+ private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ public WorkflowFinalizeEventOperator(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ }
+
+ @Override
+ public void handleEvent(WorkflowFinalizeEvent event) {
+ Integer workflowInstanceId = event.getWorkflowInstanceId();
+ workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
similarity index 63%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
index ac37c94438..bd8a610599 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
@@ -15,12 +15,23 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkflowFinishEvent implements IWorkflowEvent, ISyncEvent {
+
+ private Integer workflowInstanceId;
+
+ private WorkflowExecutionStatus workflowExecutionStatus;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
new file mode 100644
index 0000000000..4c7e30808f
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
@@ -0,0 +1,51 @@
+/*
+ * 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.workflow.engine.event;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+
+@Data
+@Builder
+@AllArgsConstructor
+public class WorkflowOperationEvent implements IWorkflowEvent, ISyncEvent {
+
+ private Integer workflowInstanceId;
+ private WorkflowOperationType workflowOperationType;
+
+ public static WorkflowOperationEvent of(Integer workflowInstanceId, WorkflowOperationType workflowOperationType) {
+ return WorkflowOperationEvent.builder()
+ .workflowInstanceId(workflowInstanceId)
+ .workflowOperationType(workflowOperationType)
+ .build();
+ }
+
+ public static WorkflowOperationEvent triggerEvent(Integer workflowInstanceId) {
+ return of(workflowInstanceId, WorkflowOperationType.TRIGGER);
+ }
+
+ public static WorkflowOperationEvent pauseEvent(Integer workflowInstanceId) {
+ return of(workflowInstanceId, WorkflowOperationType.PAUSE);
+ }
+
+ public static WorkflowOperationEvent killEvent(Integer workflowInstanceId) {
+ return of(workflowInstanceId, WorkflowOperationType.KILL);
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
new file mode 100644
index 0000000000..59a1d62e05
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
@@ -0,0 +1,84 @@
+/*
+ * 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.workflow.engine.event;
+
+import org.apache.dolphinscheduler.workflow.engine.utils.ExceptionUtils;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class WorkflowOperationEventOperator implements IWorkflowEventOperator<WorkflowOperationEvent> {
+
+ private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+
+ public WorkflowOperationEventOperator(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ }
+
+ @Override
+ public void handleEvent(WorkflowOperationEvent event) {
+ IWorkflowExecutionRunnable workflowExecutionRunnable =
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
+ if (workflowExecutionRunnable == null) {
+ log.warn("WorkflowExecutionRunnable not found: {}", event);
+ return;
+ }
+ switch (event.getWorkflowOperationType()) {
+ case TRIGGER:
+ triggerWorkflow(workflowExecutionRunnable);
+ break;
+ case PAUSE:
+ pauseWorkflow(workflowExecutionRunnable);
+ break;
+ case KILL:
+ killWorkflow(workflowExecutionRunnable);
+ break;
+ default:
+ log.error("Unknown operationType for event: {}", event);
+ }
+ }
+
+ private void triggerWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ try {
+ workflowExecutionRunnable.start();
+ } catch (Throwable exception) {
+ if (ExceptionUtils.isDatabaseConnectedFailedException(exception)) {
+ throw exception;
+ }
+ IWorkflowExecutionContext workflowExecutionContext =
+ workflowExecutionRunnable.getWorkflowExecutionContext();
+ log.error("Trigger workflow: {} failed", workflowExecutionContext.getWorkflowInstanceName(), exception);
+ WorkflowFailedEvent workflowExecutionRunnableFailedEvent = WorkflowFailedEvent.builder()
+ .workflowInstanceId(workflowExecutionContext.getWorkflowInstanceId())
+ .failedReason(exception.getMessage())
+ .build();
+ workflowExecutionRunnable.storeEventToTail(workflowExecutionRunnableFailedEvent);
+ }
+ }
+
+ private void pauseWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ workflowExecutionRunnable.pause();
+ }
+
+ private void killWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ workflowExecutionRunnable.kill();
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationType.java
similarity index 68%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationType.java
index ac37c94438..0a1d260217 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationType.java
@@ -15,12 +15,22 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.event;
-public class TaskExecutionContextCreateException extends MasterException {
+public enum WorkflowOperationType {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ /**
+ * Trigger the workflow instance.
+ */
+ TRIGGER,
+ /**
+ * Pause the workflow instance, it will pause the running task instances.
+ */
+ PAUSE,
+ /**
+ * Kill the workflow instance, it will kill the running task instances.
+ */
+ KILL,
+ ;
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/exception/WorkflowExecuteRunnableNotFoundException.java
similarity index 62%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/exception/WorkflowExecuteRunnableNotFoundException.java
index ac37c94438..10d0b4252b 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/exception/WorkflowExecuteRunnableNotFoundException.java
@@ -15,12 +15,16 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.exception;
-public class TaskExecutionContextCreateException extends MasterException {
+public class WorkflowExecuteRunnableNotFoundException extends RuntimeException {
- public TaskExecutionContextCreateException(String message) {
- super(message);
+ public WorkflowExecuteRunnableNotFoundException(Integer workflowInstanceId) {
+ super("WorkflowExecuteRunnable not found: [id=" + workflowInstanceId + "]");
+ }
+
+ public WorkflowExecuteRunnableNotFoundException(String workflowInstanceName) {
+ super("WorkflowExecuteRunnable not found: [name=" + workflowInstanceName + "]");
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/utils/ExceptionUtils.java
similarity index 73%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/utils/ExceptionUtils.java
index ac37c94438..625ff86e8d 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/utils/ExceptionUtils.java
@@ -15,12 +15,14 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.utils;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.springframework.dao.DataAccessResourceFailureException;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+public class ExceptionUtils {
+
+ public static boolean isDatabaseConnectedFailedException(Throwable e) {
+ return e instanceof DataAccessResourceFailureException;
}
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
similarity index 61%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
index ac37c94438..08bfa53055 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
@@ -15,12 +15,20 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+public interface IEventfulExecutionRunnable {
+
+ IEventRepository getEventRepository();
+
+ default void storeEventToTail(IEvent event) {
+ getEventRepository().storeEventToTail(event);
}
+ default void storeEventToHead(IEvent event) {
+ getEventRepository().storeEventToHead(event);
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
index ac37c94438..6a2945244c 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface ITaskExecutionContext {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ ITaskInstance getTaskInstance();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContextFactory.java
similarity index 73%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContextFactory.java
index ac37c94438..2f6a0bd9b8 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContextFactory.java
@@ -15,12 +15,11 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface ITaskExecutionContextFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ ITaskExecutionContext createTaskExecutionContext(String taskName,
+ IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnable.java
new file mode 100644
index 0000000000..a3ab6cc6a6
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnable.java
@@ -0,0 +1,59 @@
+/*
+ * 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.workflow.engine.workflow;
+
+/**
+ * The TaskExecutionRunnable represent the running task, it is responsible for operate the task instance. e.g. dispatch, kill, pause.
+ */
+public interface ITaskExecutionRunnable {
+
+ /**
+ * Dispatch the task instance.
+ */
+ void dispatch();
+
+ /**
+ * Run the task instance.
+ */
+ void run();
+
+ /**
+ * Kill the task instance.
+ */
+ void kill();
+
+ /**
+ * Pause the task instance.
+ */
+ void pause();
+
+ /**
+ * Get the task execution context.
+ *
+ * @return the task execution context
+ */
+ ITaskExecutionContext getTaskExecutionContext();
+
+ /**
+ * Determine whether the current task is ready to trigger the post task node.
+ *
+ * @param taskNodeName post task name
+ * @return true if the current task can be accessed to the post task.
+ */
+ boolean isReadyToTrigger(String taskNodeName);
+}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
similarity index 52%
copy from dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
index 8bd12026f0..b23364597b 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProcessTaskRelationLogDao.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
@@ -15,25 +15,16 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.dao.repository;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
+public interface ITaskExecutionRunnableFactory {
-import org.apache.ibatis.annotations.Param;
+ ITaskExecutionRunnable createTaskExecutionRunnable(String taskName,
+ IWorkflowExecutionContext workflowExecutionContext);
-import java.util.List;
+ ITaskExecutionRunnable createFailoverTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext);
-public interface ProcessTaskRelationLogDao extends IDao<ProcessTaskRelationLog> {
-
- List<ProcessTaskRelationLog> queryByWorkflowDefinitionCode(long workflowDefinitionCode);
-
- void deleteByWorkflowDefinitionCode(long workflowDefinitionCode);
-
- /**
- * batch insert process task relation
- *
- * @param taskRelationList taskRelationList
- * @return int
- */
- int batchInsert(@Param("taskRelationList") List<ProcessTaskRelationLog> taskRelationList);
+ ITaskExecutionRunnable createRetryTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableRepository.java
similarity index 60%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableRepository.java
index ac37c94438..d78f305665 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableRepository.java
@@ -15,12 +15,20 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.Collection;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface ITaskExecutionRunnableRepository {
+
+ void storeTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable);
+
+ ITaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId);
+
+ ITaskExecutionRunnable getTaskExecutionRunnableByName(String taskInstanceName);
+
+ Collection<ITaskExecutionRunnable> getActiveTaskExecutionRunnable();
+
+ void removeTaskExecutionRunnable(Integer taskInstanceId);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
index ac37c94438..2e86662267 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface ITaskInstance {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ int getId();
+
+ String getName();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecuteRunnableRepository.java
similarity index 61%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecuteRunnableRepository.java
index ac37c94438..758cd99a27 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecuteRunnableRepository.java
@@ -15,12 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+import java.util.Collection;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+public interface IWorkflowExecuteRunnableRepository {
+ void storeWorkflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable);
+
+ IWorkflowExecutionRunnable getWorkflowExecutionRunnableById(Integer workflowInstanceId);
+
+ Collection<IWorkflowExecutionRunnable> getActiveWorkflowExecutionRunnable();
+
+ void removeWorkflowExecutionRunnable(Integer workflowInstanceId);
+
+ void clear();
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionContext.java
similarity index 61%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionContext.java
index ac37c94438..265076b4f1 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionContext.java
@@ -15,12 +15,24 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+public interface IWorkflowExecutionContext {
+
+ IWorkflowInstance getWorkflowInstance();
+
+ IWorkflowExecutionDAG getWorkflowExecutionDAG();
+
+ IEventRepository getEventRepository();
+
+ default int getWorkflowInstanceId() {
+ return getWorkflowInstance().getId();
+ }
+
+ default String getWorkflowInstanceName() {
+ return getWorkflowInstance().getName();
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
new file mode 100644
index 0000000000..d76ee1a64a
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
@@ -0,0 +1,71 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.dag.DAG;
+
+import java.util.List;
+
+/**
+ * The WorkflowExecutionDAG represent the running workflow DAG.
+ */
+public interface IWorkflowExecutionDAG extends DAG {
+
+ List<String> getStartNodeNames();
+
+ /**
+ * Get TaskExecutionRunnable by given TaskInstanceId.
+ *
+ * @param taskInstanceId taskInstanceId.
+ * @return TaskExecutionRunnable
+ */
+ ITaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId);
+
+ /**
+ * Get TaskExecutionRunnable by given taskName.
+ *
+ * @param taskName task name.
+ * @return TaskExecutionRunnable
+ */
+ ITaskExecutionRunnable getTaskExecutionRunnableByName(String taskName);
+
+ /**
+ * Get TaskExecutionRunnable which is not finished.
+ *
+ * @return TaskExecutionRunnable
+ */
+ List<ITaskExecutionRunnable> getActiveTaskExecutionRunnable();
+
+ /**
+ * Get the direct pre TaskExecutionRunnable of the given taskName.
+ *
+ * @param taskName task name.
+ * @return TaskExecutionRunnable
+ */
+ List<ITaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName);
+
+ /**
+ * Check whether the taskNode is ready to run.
+ *
+ * @param taskName taskNodeName
+ * @return true if the taskNode is ready to run.
+ */
+ boolean isTaskAbleToBeTriggered(String taskName);
+
+ void storeTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable);
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAGFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAGFactory.java
index ac37c94438..dbac2888f4 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAGFactory.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IWorkflowExecutionDAGFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ IWorkflowExecutionDAG createWorkflowExecutionDAG(IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnable.java
new file mode 100644
index 0000000000..1c6e75ba1e
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnable.java
@@ -0,0 +1,56 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.engine.IDAGEngine;
+
+/**
+ * The IWorkflowExecuteRunnable represent a running workflow instance, it is responsible for operate the workflow instance. e.g. start, kill, pause.
+ */
+public interface IWorkflowExecutionRunnable extends IEventfulExecutionRunnable {
+
+ /**
+ * Start the workflow instance.
+ */
+ void start();
+
+ /**
+ * Kill the workflow instance.
+ */
+ void kill();
+
+ /**
+ * Pause the workflow instance.
+ */
+ void pause();
+
+ /**
+ * Get the workflow execution context.
+ *
+ * @return the workflow execution context
+ */
+ IWorkflowExecutionContext getWorkflowExecutionContext();
+
+ /**
+ * Get the {@link IDAGEngine} which used to execute the dag of the workflow instance.
+ *
+ * @return dag engine.
+ */
+ IDAGEngine getDagEngine();
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableFactory.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableFactory.java
index ac37c94438..f2c5042e4f 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableFactory.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IWorkflowExecutionRunnableFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ IWorkflowExecutionRunnable createWorkflowExecutionRunnable(IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
similarity index 77%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
index ac37c94438..49944d248a 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public interface IWorkflowInstance {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ int getId();
+
+ String getName();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecuteRunnableRepository.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecuteRunnableRepository.java
new file mode 100644
index 0000000000..147f0076ba
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecuteRunnableRepository.java
@@ -0,0 +1,61 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class SingletonWorkflowExecuteRunnableRepository implements IWorkflowExecuteRunnableRepository {
+
+ private static final IWorkflowExecuteRunnableRepository INSTANCE = new SingletonWorkflowExecuteRunnableRepository();
+
+ private final Map<Integer, IWorkflowExecutionRunnable> workflowExecutionRunnableMap;
+
+ private SingletonWorkflowExecuteRunnableRepository() {
+ this.workflowExecutionRunnableMap = new ConcurrentHashMap<>();
+ }
+
+ public static IWorkflowExecuteRunnableRepository getInstance() {
+ return INSTANCE;
+ }
+
+ public void storeWorkflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ workflowExecutionRunnableMap.put(
+ workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceId(),
+ workflowExecutionRunnable);
+ }
+
+ public IWorkflowExecutionRunnable getWorkflowExecutionRunnableById(Integer workflowInstanceId) {
+ return workflowExecutionRunnableMap.get(workflowInstanceId);
+ }
+
+ public Collection<IWorkflowExecutionRunnable> getActiveWorkflowExecutionRunnable() {
+ return workflowExecutionRunnableMap.values();
+ }
+
+ public void removeWorkflowExecutionRunnable(Integer workflowInstanceId) {
+ workflowExecutionRunnableMap.remove(workflowInstanceId);
+ }
+
+ @Override
+ public void clear() {
+ workflowExecutionRunnableMap.clear();
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
similarity index 68%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
index ac37c94438..380ed8b1ee 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
@@ -15,12 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public class TaskExecutionContext implements ITaskExecutionContext {
- public TaskExecutionContextCreateException(String message) {
- super(message);
+ private final ITaskInstance taskInstance;
+
+ public TaskExecutionContext(ITaskInstance taskInstance) {
+ this.taskInstance = taskInstance;
}
+ @Override
+ public ITaskInstance getTaskInstance() {
+ return taskInstance;
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContextFactory.java
similarity index 68%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContextFactory.java
index ac37c94438..446bb2f661 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContextFactory.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public class TaskExecutionContextFactory implements ITaskExecutionContextFactory {
- public TaskExecutionContextCreateException(String message) {
- super(message);
+ @Override
+ public ITaskExecutionContext createTaskExecutionContext(String taskName,
+ IWorkflowExecutionContext workflowExecutionContext) {
+ return null;
}
-
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java
similarity index 52%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java
index ac37c94438..322cd8ee8d 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java
@@ -15,12 +15,43 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+public class TaskExecutionRunnable implements ITaskExecutionRunnable {
- public TaskExecutionContextCreateException(String message) {
- super(message);
+ public final ITaskExecutionContext taskExecutionContext;
+
+ public TaskExecutionRunnable(ITaskExecutionContext taskExecutionContext) {
+ this.taskExecutionContext = taskExecutionContext;
+ }
+
+ @Override
+ public void dispatch() {
+
+ }
+
+ @Override
+ public void run() {
+
+ }
+
+ @Override
+ public void kill() {
+
+ }
+
+ @Override
+ public void pause() {
+
+ }
+
+ @Override
+ public ITaskExecutionContext getTaskExecutionContext() {
+ return taskExecutionContext;
}
+ @Override
+ public boolean isReadyToTrigger(String taskNodeName) {
+ return false;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
new file mode 100644
index 0000000000..3e7b5ec7c2
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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.workflow.engine.workflow;
+
+public class TaskExecutionRunnableFactory implements ITaskExecutionRunnableFactory {
+
+ private ITaskExecutionContextFactory taskExecutionContextFactory;
+
+ public TaskExecutionRunnableFactory(ITaskExecutionContextFactory taskExecutionContextFactory) {
+ this.taskExecutionContextFactory = taskExecutionContextFactory;
+ }
+
+ @Override
+ public ITaskExecutionRunnable createTaskExecutionRunnable(String taskName,
+ IWorkflowExecutionContext workflowExecutionContext) {
+ ITaskExecutionContext taskExecutionContext =
+ taskExecutionContextFactory.createTaskExecutionContext(taskName, workflowExecutionContext);
+ return new TaskExecutionRunnable(taskExecutionContext);
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionContext.java
similarity index 60%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionContext.java
index ac37c94438..6cca1eced1 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionContext.java
@@ -15,12 +15,25 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class WorkflowExecutionContext implements IWorkflowExecutionContext {
+
+ private IWorkflowInstance workflowInstance;
+
+ private IWorkflowExecutionDAG workflowExecutionDAG;
+
+ private IEventRepository eventRepository;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
new file mode 100644
index 0000000000..01fafcc6b7
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
@@ -0,0 +1,124 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.dag.DAGNode;
+import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * The WorkflowExecutionDAG represent a running workflow instance DAG.
+ */
+@Slf4j
+public class WorkflowExecutionDAG implements IWorkflowExecutionDAG {
+
+ private final ITaskExecutionRunnableRepository taskExecutionRunnableRepository;
+
+ private final WorkflowDAG workflowDAG;
+
+ @Getter
+ private final Set<String> startNodeNames;
+
+ public WorkflowExecutionDAG(ITaskExecutionRunnableRepository taskExecutionRunnableRepository,
+ WorkflowDAG workflowDAG) {
+ this(taskExecutionRunnableRepository, workflowDAG, Collections.emptySet());
+ }
+
+ public WorkflowExecutionDAG(ITaskExecutionRunnableRepository taskExecutionRunnableRepository,
+ WorkflowDAG workflowDAG,
+ Set<String> startNodeNames) {
+ this.taskExecutionRunnableRepository = taskExecutionRunnableRepository;
+ this.workflowDAG = workflowDAG;
+ this.startNodeNames = startNodeNames;
+ }
+
+ @Override
+ public ITaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId) {
+ return taskExecutionRunnableRepository.getTaskExecutionRunnableById(taskInstanceId);
+ }
+
+ @Override
+ public ITaskExecutionRunnable getTaskExecutionRunnableByName(String taskName) {
+ return taskExecutionRunnableRepository.getTaskExecutionRunnableByName(taskName);
+ }
+
+ @Override
+ public List<ITaskExecutionRunnable> getActiveTaskExecutionRunnable() {
+ return new ArrayList<>(taskExecutionRunnableRepository.getActiveTaskExecutionRunnable());
+ }
+
+ @Override
+ public List<ITaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName) {
+ return getDirectPreNodeNames(taskName)
+ .stream()
+ .map(taskExecutionRunnableRepository::getTaskExecutionRunnableByName)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public boolean isTaskAbleToBeTriggered(String taskNodeName) {
+ // todo: Check whether the workflow instance is finished or ready to finish.
+ List<DAGNode> directPreNodes = getDirectPreNodes(taskNodeName);
+ if (log.isDebugEnabled()) {
+ log.debug("Begin to check whether the task {} is able to be triggered.", taskNodeName);
+ log.debug("Task {} directly dependent on the task: {}.", taskNodeName,
+ directPreNodes.stream().map(DAGNode::getNodeName).collect(Collectors.toList()));
+ }
+ for (DAGNode directPreNode : directPreNodes) {
+ if (directPreNode.isSkip()) {
+ log.debug("The task {} is skipped.", directPreNode.getNodeName());
+ continue;
+ }
+ ITaskExecutionRunnable taskExecutionRunnable = getTaskExecutionRunnableByName(directPreNode.getNodeName());
+ if (taskExecutionRunnable == null || taskExecutionRunnable.isReadyToTrigger(taskNodeName)) {
+ log.debug("The task {} is not finished or not able to access to the task {}.",
+ directPreNode.getNodeName(), taskNodeName);
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void storeTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable) {
+ taskExecutionRunnableRepository.storeTaskExecutionRunnable(taskExecutionRunnable);
+ }
+
+ @Override
+ public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
+ return workflowDAG.getDirectPostNodes(dagNode);
+ }
+
+ @Override
+ public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
+ return workflowDAG.getDirectPreNodes(dagNode);
+ }
+
+ @Override
+ public DAGNode getDAGNode(String nodeName) {
+ return workflowDAG.getDAGNode(nodeName);
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
new file mode 100644
index 0000000000..7b05d22048
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
@@ -0,0 +1,64 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.engine.IDAGEngine;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+import java.util.List;
+
+import lombok.Getter;
+
+@Getter
+public class WorkflowExecutionRunnable implements IWorkflowExecutionRunnable {
+
+ private final IWorkflowExecutionContext workflowExecutionContext;
+
+ private final IDAGEngine dagEngine;
+
+ public WorkflowExecutionRunnable(IWorkflowExecutionContext workflowExecutionContext, IDAGEngine dagEngine) {
+ this.workflowExecutionContext = workflowExecutionContext;
+ this.dagEngine = dagEngine;
+ }
+
+ public void start() {
+ List<String> workflowStartNodeNames = workflowExecutionContext.getWorkflowExecutionDAG().getStartNodeNames();
+ if (CollectionUtils.isEmpty(workflowStartNodeNames)) {
+ dagEngine.triggerNextTasks(null);
+ } else {
+ workflowStartNodeNames.forEach(dagEngine::triggerTask);
+ }
+ }
+
+ @Override
+ public void pause() {
+ dagEngine.pauseAllTask();
+ }
+
+ @Override
+ public void kill() {
+ dagEngine.killAllTask();
+ }
+
+ @Override
+ public IEventRepository getEventRepository() {
+ return workflowExecutionContext.getEventRepository();
+ }
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableFactory.java
similarity index 50%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableFactory.java
index ac37c94438..ebfb3510db 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableFactory.java
@@ -15,12 +15,22 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+import org.apache.dolphinscheduler.workflow.engine.engine.IDAGEngine;
+import org.apache.dolphinscheduler.workflow.engine.engine.IDAGEngineFactory;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+public class WorkflowExecutionRunnableFactory implements IWorkflowExecutionRunnableFactory {
+
+ private final IDAGEngineFactory dagEngineFactory;
+
+ public WorkflowExecutionRunnableFactory(IDAGEngineFactory dagEngineFactory) {
+ this.dagEngineFactory = dagEngineFactory;
}
+ @Override
+ public WorkflowExecutionRunnable createWorkflowExecutionRunnable(IWorkflowExecutionContext workflowExecutionContext) {
+ IDAGEngine dagEngine = dagEngineFactory.createDAGEngine(workflowExecutionContext);
+ return new WorkflowExecutionRunnable(workflowExecutionContext, dagEngine);
+ }
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java
similarity index 65%
copy from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java
index ac37c94438..5280e86c08 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java
@@ -15,12 +15,24 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContextCreateException extends MasterException {
+import lombok.Getter;
- public TaskExecutionContextCreateException(String message) {
- super(message);
+@Getter
+public class WorkflowInstance implements IWorkflowInstance {
+
+ private final int id;
+
+ private final String name;
+
+ public WorkflowInstance(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public static WorkflowInstance of(int id, String name) {
+ return new WorkflowInstance(id, name);
}
}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
new file mode 100644
index 0000000000..1d4553d2a7
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
@@ -0,0 +1,37 @@
+/*
+ * 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.workflow.engine.assertions;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecuteRunnableRepository;
+
+public class SingletonWorkflowExecuteRunnableRepositoryAssertions {
+
+ public static void existWorkflowExecutionRunnable(Integer workflowInstanceId) {
+ assertNotNull(SingletonWorkflowExecuteRunnableRepository.getInstance()
+ .getWorkflowExecutionRunnableById(workflowInstanceId));
+ }
+
+ public static void notExistWorkflowExecutionRunnable(Integer workflowInstanceId) {
+ assertNull(SingletonWorkflowExecuteRunnableRepository.getInstance()
+ .getWorkflowExecutionRunnableById(workflowInstanceId));
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/WorkflowDAGAssertion.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/WorkflowDAGAssertion.java
new file mode 100644
index 0000000000..3ccbc4702a
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/WorkflowDAGAssertion.java
@@ -0,0 +1,173 @@
+/*
+ * 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.workflow.engine.assertions;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class WorkflowDAGAssertion {
+
+ private final WorkflowDAG workflowDAG;
+
+ private final List<NodeAssertion> nodeAssertions;
+
+ private WorkflowDAGAssertion(WorkflowDAG workflowDAG) {
+ this.workflowDAG = workflowDAG;
+ this.nodeAssertions = new ArrayList<>();
+ }
+
+ public static WorkflowDAGAssertion workflowDag(WorkflowDAG workflowDAG) {
+ return new WorkflowDAGAssertion(workflowDAG);
+ }
+
+ public WorkflowDAGAssertion nodeAssertion(NodeAssertion nodeAssertion) {
+ nodeAssertions.add(nodeAssertion);
+ return this;
+ }
+
+ public void doAssertion() {
+ nodeAssertions.forEach(nodeAssertion -> nodeAssertion.doAssertion(workflowDAG));
+ }
+
+ public static class NodeAssertion {
+
+ /**
+ * node name of the assertion
+ */
+ private final String nodeName;
+
+ /**
+ * whether the node exist
+ */
+ private boolean exist;
+
+ /**
+ * whether the node is skipped
+ */
+ private boolean skip;
+
+ /**
+ * whether the node has out degree
+ */
+ private List<String> postNodes;
+
+ /**
+ * whether the node has in degree
+ */
+ private List<String> preNodes;
+
+ private NodeAssertion(String nodeName) {
+ this.nodeName = nodeName;
+ this.postNodes = new ArrayList<>();
+ this.preNodes = new ArrayList<>();
+ }
+
+ public static NodeAssertion node(String nodeName) {
+ return new NodeAssertion(nodeName);
+ }
+
+ public NodeAssertion exist() {
+ this.exist = true;
+ return this;
+ }
+
+ public NodeAssertion skip() {
+ this.skip = true;
+ return this;
+ }
+
+ public NodeAssertion noEdge() {
+ this.postNodes = new ArrayList<>();
+ this.preNodes = new ArrayList<>();
+ return this;
+ }
+
+ public NodeAssertion noInDegree() {
+ this.preNodes = new ArrayList<>();
+ return this;
+ }
+
+ public NodeAssertion inDegrees(List<String> preNodes) {
+ this.preNodes.addAll(preNodes);
+ return this;
+ }
+
+ public NodeAssertion inDegrees(String preNode) {
+ this.preNodes.add(preNode);
+ return this;
+ }
+
+ public NodeAssertion noOutDegree() {
+ this.postNodes = new ArrayList<>();
+ return this;
+ }
+
+ public NodeAssertion outDegrees(List<String> postNodes) {
+ this.postNodes.addAll(postNodes);
+ return this;
+ }
+
+ public NodeAssertion outDegrees(String postNode) {
+ this.postNodes.add(postNode);
+ return this;
+ }
+
+ private void doAssertion(WorkflowDAG workflowDAG) {
+ if (exist) {
+ // node exist
+ assertNotNull(workflowDAG.getDAGNode(nodeName), "node " + nodeName + " does not exist");
+ } else {
+
+ assertNull(workflowDAG.getDAGNode(nodeName), "node " + nodeName + " exist");
+ }
+
+ if (skip) {
+ assertTrue(workflowDAG.getDAGNode(nodeName).isSkip(), "node " + nodeName + " is not skipped");
+ } else {
+ assertFalse(workflowDAG.getDAGNode(nodeName).isSkip(), "node " + nodeName + " is skipped");
+ }
+
+ if (CollectionUtils.isEmpty(postNodes)) {
+ assertTrue(workflowDAG.getDirectPostNodeNames(nodeName).isEmpty(),
+ "node " + nodeName + " has outDegree " + workflowDAG.getDirectPostNodes(nodeName));
+ } else {
+ postNodes
+ .forEach(postNode -> assertTrue(workflowDAG.getDirectPostNodeNames(nodeName).contains(postNode),
+ "node " + nodeName + " does has outDegree " + postNode));
+ }
+
+ if (CollectionUtils.isEmpty(preNodes)) {
+ assertTrue(workflowDAG.getDirectPreNodeNames(nodeName).isEmpty(),
+ "node " + nodeName + " has inDegree " + workflowDAG.getDirectPreNodeNames(nodeName));
+ } else {
+ preNodes.forEach(preNode -> assertTrue(workflowDAG.getDirectPreNodeNames(nodeName).contains(preNode),
+ "node " + nodeName + " does has inDegree " + preNode));
+ }
+ }
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/WorkflowExecutionRunnableAssertions.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/WorkflowExecutionRunnableAssertions.java
new file mode 100644
index 0000000000..494e66bcd6
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/WorkflowExecutionRunnableAssertions.java
@@ -0,0 +1,49 @@
+/*
+ * 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.workflow.engine.assertions;
+
+import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+
+import org.opentest4j.AssertionFailedError;
+
+public class WorkflowExecutionRunnableAssertions {
+
+ private final IWorkflowExecutionRunnable workflowExecutionRunnable;
+
+ private WorkflowExecutionRunnableAssertions(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ this.workflowExecutionRunnable = workflowExecutionRunnable;
+ }
+
+ public static WorkflowExecutionRunnableAssertions workflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable) {
+ return new WorkflowExecutionRunnableAssertions(workflowExecutionRunnable);
+ }
+
+ public void existEvent(IEvent event) {
+ if (event == null) {
+ throw new IllegalArgumentException("Event cannot be null");
+ }
+ boolean exist = workflowExecutionRunnable.getEventRepository().getAllEvent()
+ .stream()
+ .anyMatch(event1 -> event1.equals(event1));
+ if (!exist) {
+ throw new AssertionFailedError("The workflowExecuteRunnable doesn't exist event: " + event);
+ }
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeTest.java
new file mode 100644
index 0000000000..0502450f82
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeTest.java
@@ -0,0 +1,104 @@
+package org.apache.dolphinscheduler.workflow.engine.dag;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.Lists;
+
+class DAGNodeTest {
+
+ @Test
+ void buildDAGNode_EmptyNodeName() {
+ IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
+ () -> DAGNode.builder()
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .build());
+ assertEquals("nodeName cannot be empty", illegalArgumentException.getMessage());
+ }
+
+ @Test
+ void buildDAGNode_BadInDegree() {
+ IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
+ () -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName(null)
+ .toNodeName("B")
+ .build()))
+ .outDegrees(new ArrayList<>())
+ .build());
+ assertEquals(
+ "The toNodeName of inDegree should be the nodeName of the node: A, inDegree: DAGEdge(fromNodeName=null, toNodeName=B)",
+ illegalArgumentException.getMessage());
+ }
+
+ @Test
+ void buildDAGNode_NiceInDegree() {
+ assertDoesNotThrow(() -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName(null)
+ .toNodeName("A")
+ .build()))
+ .outDegrees(new ArrayList<>())
+ .build());
+ }
+
+ @Test
+ void buildDAGNode_BadOutDegree() {
+ IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
+ () -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(new ArrayList<>())
+ .outDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName("B")
+ .toNodeName(null)
+ .build()))
+ .build());
+ assertEquals(
+ "The fromNodeName of outDegree should be the nodeName of the node: A, outDegree: DAGEdge(fromNodeName=B, toNodeName=null)",
+ illegalArgumentException.getMessage());
+ }
+
+ @Test
+ void buildDAGNode_NiceOutDegree() {
+ assertDoesNotThrow(() -> DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(new ArrayList<>())
+ .outDegrees(Lists.newArrayList(DAGEdge.builder()
+ .fromNodeName("A")
+ .toNodeName(null)
+ .build()))
+ .build());
+ }
+
+ @Test
+ void buildDAGNode_NotSkip() {
+ DAGNode dagNode = DAGNode.builder()
+ .nodeName("A")
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .build();
+ assertFalse(dagNode.isSkip());
+ }
+
+ @Test
+ void buildDAGNode_Skip() {
+ DAGNode dagNode = DAGNode.builder()
+ .nodeName("A")
+ .skip(true)
+ .inDegrees(new ArrayList<>())
+ .outDegrees(new ArrayList<>())
+ .build();
+ assertTrue(dagNode.isSkip());
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilderTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilderTest.java
new file mode 100644
index 0000000000..e37a73f32a
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilderTest.java
@@ -0,0 +1,260 @@
+package org.apache.dolphinscheduler.workflow.engine.dag;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.apache.dolphinscheduler.workflow.engine.assertions.WorkflowDAGAssertion.NodeAssertion.node;
+import static org.apache.dolphinscheduler.workflow.engine.assertions.WorkflowDAGAssertion.workflowDag;
+
+import org.junit.jupiter.api.Test;
+
+class WorkflowDAGBuilderTest {
+
+ /**
+ * Test DAG with single node:
+ * <pre>
+ * {@code
+ * Node(A)
+ * }
+ * </pre>
+ */
+ @Test
+ void build_SingleTaskNode() {
+ String nodeName = "A";
+ DAGNodeDefinition dagNodeDefinition = dagNode(nodeName);
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNode(dagNodeDefinition)
+ .build();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeName).exist().noEdge())
+ .doAssertion();
+ }
+
+ /**
+ * Test DAG with multiple nodes:
+ * <pre>
+ * {@code
+ * Node(A)
+ * Node(B)
+ * Node(C)
+ * }
+ * <pre/>
+ */
+ @Test
+ void build_MULTIPLE_NODE() {
+ String nodeNameA = "A";
+ DAGNodeDefinition taskNodeA = dagNode(nodeNameA);
+ String nodeNameB = "B";
+ DAGNodeDefinition taskNodeB = dagNode(nodeNameB);
+ String nodeNameC = "C";
+ DAGNodeDefinition taskNodeC = dagNode(nodeNameC);
+
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNode(taskNodeA)
+ .addTaskNode(taskNodeB)
+ .addTaskNode(taskNodeC)
+ .build();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA).exist().noEdge())
+ .nodeAssertion(node(nodeNameB).exist().noEdge())
+ .nodeAssertion(node(nodeNameC).exist().noEdge())
+ .doAssertion();
+ }
+
+ /**
+ * Test DAG with multiple nodes:
+ * <pre>
+ * {@code
+ * Node(A) -> Node(B1) -> Node(C1) -> Node(D)
+ * -> Node(B2) -> Node(C2) ->
+ * }
+ * <pre/>
+ */
+ @Test
+ void build_DAG() {
+ String nodeNameA = "A";
+ DAGNodeDefinition taskNodeA = dagNode(nodeNameA);
+ String nodeNameB1 = "B1";
+ DAGNodeDefinition taskNodeB1 = dagNode(nodeNameB1);
+ String nodeNameB2 = "B2";
+ DAGNodeDefinition taskNodeB2 = dagNode(nodeNameB2);
+ String nodeNameC1 = "C1";
+ DAGNodeDefinition taskNodeC1 = dagNode(nodeNameC1);
+ String nodeNameC2 = "C2";
+ DAGNodeDefinition taskNodeC2 = dagNode(nodeNameC2);
+ String nodeNameD = "D";
+ DAGNodeDefinition taskNodeD = dagNode(nodeNameD);
+
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNode(taskNodeA)
+ .addTaskNodes(newArrayList(taskNodeB1, taskNodeB2))
+ .addTaskNodes(newArrayList(taskNodeC1, taskNodeC2))
+ .addTaskNode(taskNodeD)
+ .addTaskEdge(edge(null, taskNodeA))
+ .addTaskEdge(edge(taskNodeA, taskNodeB1))
+ .addTaskEdge(edge(taskNodeA, taskNodeB2))
+ .addTaskEdge(edge(taskNodeB1, taskNodeC1))
+ .addTaskEdge(edge(taskNodeB2, taskNodeC2))
+ .addTaskEdge(edge(taskNodeC1, taskNodeD))
+ .addTaskEdge(edge(taskNodeC2, taskNodeD))
+ .addTaskEdge(edge(taskNodeD, null))
+ .build();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA)
+ .exist()
+ .noInDegree()
+ .outDegrees(newArrayList(nodeNameB1, nodeNameB2)))
+ .nodeAssertion(node(nodeNameB1)
+ .exist()
+ .inDegrees(nodeNameA)
+ .outDegrees(nodeNameC1))
+ .nodeAssertion(node(nodeNameB2)
+ .exist()
+ .inDegrees(nodeNameA)
+ .outDegrees(nodeNameC2))
+ .nodeAssertion(node(nodeNameC1)
+ .exist()
+ .inDegrees(nodeNameB1)
+ .outDegrees(nodeNameD))
+ .nodeAssertion(node(nodeNameC2)
+ .exist()
+ .inDegrees(nodeNameB2)
+ .outDegrees(nodeNameD))
+ .nodeAssertion(node(nodeNameD)
+ .exist()
+ .inDegrees(newArrayList(nodeNameC1, nodeNameC2))
+ .noOutDegree())
+ .doAssertion();
+ }
+
+ /**
+ * Test DAG with multiple sub dags:
+ * <pre>
+ * {@code
+ * Node(A1) -> Node(B1) -> Node(C1) -> Node(D1)
+ * -> Node(B2) -> Node(C2) ->
+ *
+ * Node(A2) -> Node(B3) -> Node(C3) -> Node(D2)
+ * -> Node(B4) -> Node(C4) ->
+ * }
+ * <pre/>
+ */
+ @Test
+ void build_MULTIPLE_SUB_DAG() {
+ String nodeNameA1 = "A1";
+ DAGNodeDefinition taskNodeA1 = dagNode(nodeNameA1);
+ String nodeNameA2 = "A2";
+ DAGNodeDefinition taskNodeA2 = dagNode(nodeNameA2);
+
+ String nodeNameB1 = "B1";
+ DAGNodeDefinition taskNodeB1 = dagNode(nodeNameB1);
+ String nodeNameB2 = "B2";
+ DAGNodeDefinition taskNodeB2 = dagNode(nodeNameB2);
+ String nodeNameB3 = "B3";
+ DAGNodeDefinition taskNodeB3 = dagNode(nodeNameB3);
+ String nodeNameB4 = "B4";
+ DAGNodeDefinition taskNodeB4 = dagNode(nodeNameB4);
+
+ String nodeNameC1 = "C1";
+ DAGNodeDefinition taskNodeC1 = dagNode(nodeNameC1);
+ String nodeNameC2 = "C2";
+ DAGNodeDefinition taskNodeC2 = dagNode(nodeNameC2);
+ String nodeNameC3 = "C3";
+ DAGNodeDefinition taskNodeC3 = dagNode(nodeNameC3);
+ String nodeNameC4 = "C4";
+ DAGNodeDefinition taskNodeC4 = dagNode(nodeNameC4);
+
+ String nodeNameD1 = "D1";
+ DAGNodeDefinition taskNodeD1 = dagNode(nodeNameD1);
+ String nodeNameD2 = "D2";
+ DAGNodeDefinition taskNodeD2 = dagNode(nodeNameD2);
+
+ WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
+ .addTaskNodes(newArrayList(taskNodeA1, taskNodeA2))
+ .addTaskNodes(newArrayList(taskNodeB1, taskNodeB2, taskNodeB3, taskNodeB4))
+ .addTaskNodes(newArrayList(taskNodeC1, taskNodeC2, taskNodeC3, taskNodeC4))
+ .addTaskNodes(newArrayList(taskNodeD1, taskNodeD2))
+ .addTaskEdge(edge(null, taskNodeA1))
+ .addTaskEdge(edge(taskNodeA1, taskNodeB1))
+ .addTaskEdge(edge(taskNodeA1, taskNodeB2))
+ .addTaskEdge(edge(taskNodeB1, taskNodeC1))
+ .addTaskEdge(edge(taskNodeB2, taskNodeC2))
+ .addTaskEdge(edge(taskNodeC1, taskNodeD1))
+ .addTaskEdge(edge(taskNodeC2, taskNodeD1))
+ .addTaskEdge(edge(taskNodeD1, null))
+ .addTaskEdge(edge(null, taskNodeA2))
+ .addTaskEdge(edge(taskNodeA2, taskNodeB3))
+ .addTaskEdge(edge(taskNodeA2, taskNodeB4))
+ .addTaskEdge(edge(taskNodeB3, taskNodeC3))
+ .addTaskEdge(edge(taskNodeB4, taskNodeC4))
+ .addTaskEdge(edge(taskNodeC3, taskNodeD2))
+ .addTaskEdge(edge(taskNodeC4, taskNodeD2))
+ .addTaskEdge(edge(taskNodeD2, null))
+ .build();
+
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA1)
+ .exist()
+ .noInDegree()
+ .outDegrees(newArrayList(nodeNameB1, nodeNameB2)))
+ .nodeAssertion(node(nodeNameB1)
+ .exist()
+ .inDegrees(nodeNameA1)
+ .outDegrees(nodeNameC1))
+ .nodeAssertion(node(nodeNameB2)
+ .exist()
+ .inDegrees(nodeNameA1)
+ .outDegrees(nodeNameC2))
+ .nodeAssertion(node(nodeNameC1)
+ .exist()
+ .inDegrees(nodeNameB1)
+ .outDegrees(nodeNameD1))
+ .nodeAssertion(node(nodeNameC2)
+ .exist()
+ .inDegrees(nodeNameB2)
+ .outDegrees(nodeNameD1))
+ .nodeAssertion(node(nodeNameD1)
+ .exist()
+ .inDegrees(newArrayList(nodeNameC1, nodeNameC2))
+ .noOutDegree())
+ .doAssertion();
+ workflowDag(workflowDAG)
+ .nodeAssertion(node(nodeNameA2)
+ .exist()
+ .noInDegree()
+ .outDegrees(newArrayList(nodeNameB3, nodeNameB4)))
+ .nodeAssertion(node(nodeNameB3)
+ .exist()
+ .inDegrees(nodeNameA2)
+ .outDegrees(nodeNameC3))
+ .nodeAssertion(node(nodeNameB4)
+ .exist()
+ .inDegrees(nodeNameA2)
+ .outDegrees(nodeNameC4))
+ .nodeAssertion(node(nodeNameC3)
+ .exist()
+ .inDegrees(nodeNameB3)
+ .outDegrees(nodeNameD2))
+ .nodeAssertion(node(nodeNameC4)
+ .exist()
+ .inDegrees(nodeNameB4)
+ .outDegrees(nodeNameD2))
+ .nodeAssertion(node(nodeNameD2)
+ .exist()
+ .inDegrees(newArrayList(nodeNameC3, nodeNameC4))
+ .noOutDegree())
+ .doAssertion();
+ }
+
+ private DAGNodeDefinition dagNode(String nodeName) {
+ DAGNodeDefinition dagNodeDefinition = new DAGNodeDefinition();
+ dagNodeDefinition.setNodeName(nodeName);
+ return dagNodeDefinition;
+ }
+
+ private DAGEdge edge(DAGNodeDefinition from, DAGNodeDefinition to) {
+ DAGEdge dagEdge = new DAGEdge();
+ dagEdge.setFromNodeName(from == null ? null : from.getNodeName());
+ dagEdge.setToNodeName(to == null ? null : to.getNodeName());
+ return dagEdge;
+ }
+
+}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineIT.java
similarity index 77%
rename from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
rename to dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineIT.java
index ac37c94438..0ba306f3cc 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/exception/TaskExecutionContextCreateException.java
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineIT.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.exception;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public class TaskExecutionContextCreateException extends MasterException {
+public class WorkflowEngineIT {
- public TaskExecutionContextCreateException(String message) {
- super(message);
- }
+ private WorkflowEngine workflowEngine;
}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
new file mode 100644
index 0000000000..6e35706549
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
@@ -0,0 +1,105 @@
+package org.apache.dolphinscheduler.workflow.engine.engine;
+
+import static org.apache.dolphinscheduler.workflow.engine.assertions.WorkflowExecutionRunnableAssertions.workflowExecutionRunnable;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.apache.dolphinscheduler.workflow.engine.assertions.SingletonWorkflowExecuteRunnableRepositoryAssertions;
+import org.apache.dolphinscheduler.workflow.engine.event.WorkflowOperationEvent;
+import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunnableNotFoundException;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.MockWorkflowExecutionRunnableFactory;
+import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecuteRunnableRepository;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class WorkflowEngineTest {
+
+ private WorkflowEngine workflowEngine;
+
+ @BeforeEach
+ public void before() {
+ workflowEngine = new WorkflowEngine(SingletonWorkflowExecuteRunnableRepository.getInstance());
+ }
+
+ @AfterEach
+ public void after() {
+ SingletonWorkflowExecuteRunnableRepository.getInstance().clear();
+ }
+
+ @Test
+ void triggerWorkflow() {
+ IWorkflowExecutionRunnable mockWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
+ Integer workflowInstanceId = mockWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+
+ workflowEngine.triggerWorkflow(mockWorkflowExecuteRunnable);
+ workflowExecutionRunnable(mockWorkflowExecuteRunnable)
+ .existEvent(WorkflowOperationEvent.triggerEvent(workflowInstanceId));
+ }
+
+ @Test
+ void pauseWorkflow_WorkflowNotExist() {
+ WorkflowExecuteRunnableNotFoundException exception =
+ assertThrows(WorkflowExecuteRunnableNotFoundException.class, () -> workflowEngine.pauseWorkflow(1));
+ assertEquals("WorkflowExecuteRunnable not found: [id=1]", exception.getMessage());
+ }
+
+ @Test
+ void pauseWorkflow_WorkflowExist() {
+ IWorkflowExecutionRunnable mockWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
+ Integer workflowInstanceId =
+ mockWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ SingletonWorkflowExecuteRunnableRepository.getInstance()
+ .storeWorkflowExecutionRunnable(mockWorkflowExecuteRunnable);
+
+ workflowEngine.pauseWorkflow(workflowInstanceId);
+ workflowExecutionRunnable(mockWorkflowExecuteRunnable)
+ .existEvent(WorkflowOperationEvent.pauseEvent(workflowInstanceId));
+ }
+
+ @Test
+ void killWorkflow_WorkflowNotExist() {
+ WorkflowExecuteRunnableNotFoundException exception =
+ assertThrows(WorkflowExecuteRunnableNotFoundException.class,
+ () -> workflowEngine.killWorkflow(1));
+ assertEquals("WorkflowExecuteRunnable not found: [id=1]", exception.getMessage());
+ }
+
+ @Test
+ void killWorkflow_WorkflowExist() {
+ IWorkflowExecutionRunnable mockWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
+ Integer workflowInstanceId =
+ mockWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ SingletonWorkflowExecuteRunnableRepository.getInstance()
+ .storeWorkflowExecutionRunnable(mockWorkflowExecuteRunnable);
+
+ workflowEngine.killWorkflow(workflowInstanceId);
+ workflowExecutionRunnable(mockWorkflowExecuteRunnable)
+ .existEvent(WorkflowOperationEvent.killEvent(workflowInstanceId));
+ }
+
+ @Test
+ void finalizeWorkflow_WorkflowNotExist() {
+ workflowEngine.finalizeWorkflow(-1);
+ }
+
+ @Test
+ void finalizeWorkflow_WorkflowExist() {
+ IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
+ MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
+ Integer workflowInstanceId =
+ emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ SingletonWorkflowExecuteRunnableRepository.getInstance()
+ .storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
+ SingletonWorkflowExecuteRunnableRepositoryAssertions.existWorkflowExecutionRunnable(workflowInstanceId);
+
+ workflowEngine.finalizeWorkflow(workflowInstanceId);
+ SingletonWorkflowExecuteRunnableRepositoryAssertions.notExistWorkflowExecutionRunnable(workflowInstanceId);
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventTest.java
new file mode 100644
index 0000000000..8356fbb1ac
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventTest.java
@@ -0,0 +1,30 @@
+package org.apache.dolphinscheduler.workflow.engine.event;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+class WorkflowOperationEventTest {
+
+ @Test
+ void triggerEvent() {
+ WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.triggerEvent(1);
+ assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
+ assertEquals(WorkflowOperationType.TRIGGER, workflowOperationEvent.getWorkflowOperationType());
+ }
+
+ @Test
+ void pauseEvent() {
+ WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.pauseEvent(1);
+ assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
+ assertEquals(WorkflowOperationType.PAUSE, workflowOperationEvent.getWorkflowOperationType());
+ }
+
+ @Test
+ void killEvent() {
+ WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.killEvent(1);
+ assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
+ assertEquals(WorkflowOperationType.KILL, workflowOperationEvent.getWorkflowOperationType());
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/workflow/MockWorkflowExecutionRunnableFactory.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/workflow/MockWorkflowExecutionRunnableFactory.java
new file mode 100644
index 0000000000..94ecc00316
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/workflow/MockWorkflowExecutionRunnableFactory.java
@@ -0,0 +1,46 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.engine.DAGEngineFactory;
+import org.apache.dolphinscheduler.workflow.engine.event.MemoryEventRepository;
+
+import org.apache.commons.lang3.RandomUtils;
+
+public class MockWorkflowExecutionRunnableFactory {
+
+ private static final ITaskExecutionContextFactory taskExecutionContextFactory = new TaskExecutionContextFactory();
+ private static final ITaskExecutionRunnableFactory taskExecutionRunnableFactory =
+ new TaskExecutionRunnableFactory(taskExecutionContextFactory);
+ private static final DAGEngineFactory dagEngineFactory = new DAGEngineFactory(taskExecutionRunnableFactory);
+ private static final WorkflowExecutionRunnableFactory workflowExecutionRunnableFactory =
+ new WorkflowExecutionRunnableFactory(dagEngineFactory);
+
+ public static WorkflowExecutionRunnable createWorkflowExecutionRunnable() {
+ int workflowInstanceId = RandomUtils.nextInt();
+ String workflowInstanceName = "MockWorkflowInstance-" + workflowInstanceId;
+ WorkflowInstance workflowInstance = WorkflowInstance.of(workflowInstanceId, workflowInstanceName);
+ IWorkflowExecutionContext workflowExecutionContext = WorkflowExecutionContext.builder()
+ .workflowInstance(workflowInstance)
+ .eventRepository(MemoryEventRepository.newInstance())
+ .build();
+
+ return workflowExecutionRunnableFactory.createWorkflowExecutionRunnable(workflowExecutionContext);
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 4a71741f8e..1390f531a1 100755
--- a/pom.xml
+++ b/pom.xml
@@ -57,6 +57,7 @@
<module>dolphinscheduler-storage-plugin</module>
<module>dolphinscheduler-extract</module>
<module>dolphinscheduler-dao-plugin</module>
+ <module>dolphinscheduler-workflow-engine</module>
</modules>
<properties>
(dolphinscheduler) 04/04: Add TaskExecutionRunnable in WorkflowExecutionDAG
Posted by we...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev_wenjun_refactorMaster
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
commit 6b6feb008ab956deafcf7a1c8b076625a1bbcf56
Author: Wenjun Ruan <we...@apache.org>
AuthorDate: Mon Apr 1 10:40:38 2024 +0800
Add TaskExecutionRunnable in WorkflowExecutionDAG
---
.../{workflow/IChain.java => dag/BaseDAG.java} | 4 +-
.../dolphinscheduler/workflow/engine/dag/DAG.java | 50 +----
.../IWorkflowInstance.java => dag/ITask.java} | 8 +-
.../{event/IEvent.java => dag/ITaskChain.java} | 8 +-
.../IChain.java => dag/ITaskContext.java} | 5 +-
.../ITaskInstance.java => dag/ITaskIdentify.java} | 6 +-
.../dolphinscheduler/workflow/engine/dag/Node.java | 5 -
.../TaskExecutionContext.java => dag/Task.java} | 22 ++-
.../TaskChain.java} | 25 ++-
.../{workflow/IChain.java => dag/TaskContext.java} | 4 +-
.../TaskIdentify.java} | 23 ++-
.../workflow/engine/dag/WorkflowDAG.java | 125 ++++++------
.../workflow/engine/engine/DAGEngine.java | 211 ++++++++++++---------
.../workflow/engine/engine/DAGEngineFactory.java | 2 +-
.../workflow/engine/engine/EventEngine.java | 21 +-
.../workflow/engine/engine/IDAGEngine.java | 32 ++--
.../workflow/engine/engine/IWorkflowEngine.java | 13 +-
.../workflow/engine/engine/WorkflowEngine.java | 39 ++--
.../workflow/engine/event/EventDispatcher.java | 44 +++++
.../workflow/engine/event/IEvent.java | 2 +
.../event/{IEvent.java => IEventDispatcher.java} | 4 +-
.../engine/event/{IEvent.java => IEventType.java} | 5 +-
.../workflow/engine/event/ITaskEvent.java | 4 +-
.../workflow/engine/event/IWorkflowEvent.java | 4 +-
...nt.java => TaskExecutionPlanChainEndEvent.java} | 18 +-
.../workflow/engine/event/TaskOperationEvent.java | 11 +-
.../engine/event/TaskOperationEventOperator.java | 20 +-
...rationType.java => TaskOperationEventType.java} | 4 +-
.../workflow/engine/event/WorkflowFailedEvent.java | 16 +-
.../workflow/engine/event/WorkflowFinishEvent.java | 15 +-
.../engine/event/WorkflowOperationEvent.java | 48 +++--
.../event/WorkflowOperationEventOperator.java | 10 +-
...onType.java => WorkflowOperationEventType.java} | 2 +-
.../WorkflowExecuteRunnableNotFoundException.java | 10 +-
...a => DefaultTaskExecutionRunnableDelegate.java} | 31 ++-
...efaultTaskExecutionRunnableDelegateFactory.java | 51 +++++
... DefaultWorkflowExecutionRunnableDelegate.java} | 31 ++-
...tWorkflowExecutionRunnableDelegateFactory.java} | 16 +-
.../workflow/IEventfulExecutionRunnable.java | 4 -
.../engine/workflow/ITaskExecutionContext.java | 6 +-
.../workflow/ITaskExecutionContextFactory.java | 4 +-
.../engine/workflow/ITaskExecutionPlan.java | 52 +++++
...wInstance.java => ITaskExecutionPlanChain.java} | 6 +-
.../engine/workflow/ITaskExecutionRunnable.java | 19 +-
...tance.java => ITaskExecutionRunnableChain.java} | 6 +-
...ce.java => ITaskExecutionRunnableDelegate.java} | 14 +-
... => ITaskExecutionRunnableDelegateFactory.java} | 15 +-
.../workflow/ITaskExecutionRunnableFactory.java | 4 +-
...ce.java => ITaskExecutionRunnableIdentify.java} | 8 +-
.../engine/workflow/IWorkflowExecutionContext.java | 18 +-
.../engine/workflow/IWorkflowExecutionDAG.java | 37 +---
.../workflow/IWorkflowExecutionRunnable.java | 13 +-
.../IWorkflowExecutionRunnableDelegate.java | 16 +-
...IWorkflowExecutionRunnableDelegateFactory.java} | 4 +-
...ava => IWorkflowExecutionRunnableIdentify.java} | 4 +-
.../IWorkflowExecutionRunnableRepository.java | 4 +-
...ngletonWorkflowExecutionRunnableRepository.java | 17 +-
.../engine/workflow/TaskExecutionContext.java | 10 -
.../engine/workflow/TaskExecutionPlan.java | 117 ++++++++++++
.../engine/workflow/TaskExecutionRunnable.java | 32 +++-
.../workflow/TaskExecutionRunnableFactory.java | 18 +-
...nce.java => TaskExecutionRunnableIdentify.java} | 29 ++-
.../engine/workflow/WorkflowExecutionContext.java | 26 ++-
.../engine/workflow/WorkflowExecutionDAG.java | 135 +++++++------
...tance.java => WorkflowExecutionDAGFactory.java} | 8 +-
.../engine/workflow/WorkflowExecutionRunnable.java | 59 +++---
.../workflow/WorkflowExecutionRunnableFactory.java | 12 +-
...e.java => WorkflowExecutionRunnableStatus.java} | 14 +-
...orkflowExecuteRunnableRepositoryAssertions.java | 4 +-
.../workflow/engine/engine/WorkflowEngineTest.java | 12 +-
.../engine/event/WorkflowOperationEventTest.java | 6 +-
71 files changed, 1080 insertions(+), 602 deletions(-)
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/BaseDAG.java
similarity index 90%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/BaseDAG.java
index 5c86c8b6f7..a63154c2c4 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/BaseDAG.java
@@ -15,5 +15,7 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;public interface IChain {
+package org.apache.dolphinscheduler.workflow.engine.dag;
+
+public class BaseDAG {
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
index aed6193c83..80a5d89143 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
@@ -18,7 +18,6 @@
package org.apache.dolphinscheduler.workflow.engine.dag;
import java.util.List;
-import java.util.stream.Collectors;
/**
* The Directed Acyclic Graph class.
@@ -27,9 +26,8 @@ import java.util.stream.Collectors;
* The nodes are the tasks, the edges are the dependencies between the tasks.
* The DAG is acyclic, which means there is no cycle in the graph.
* The DAG is a directed graph, which means the edges have direction.
- *
*/
-public interface DAG {
+public interface DAG<Node, NodeIdentify> {
/**
* Get the direct post node of given dagNode, if the dagNode is null, return the nodes which doesn't have inDegrees.
@@ -50,26 +48,7 @@ public interface DAG {
*/
List<Node> getDirectPostNodes(Node node);
- /**
- * Same with {@link #getDirectPostNodes(Node)}.
- * <p>
- * If the dagNodeName is null, return the nodes which doesn't have inDegrees. Otherwise, return the post nodes of
- * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
- *
- * @param dagNodeName task name, can be null.
- * @return post task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- List<Node> getDirectPostNodes(String dagNodeName);
-
- /**
- * Same with {@link #getDirectPostNodes(String)}. Return the post node names.
- *
- * @param dagNodeName task name, can be null.
- * @return post task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- List<String> getDirectPostNodeNames(String dagNodeName);
+ List<Node> getDirectPostNodesByIdentify(NodeIdentify nodeIdentify);
/**
* Get the direct pre node of given dagNode, if the dagNode is null, return the nodes which doesn't have outDegrees.
@@ -90,33 +69,14 @@ public interface DAG {
*/
List<Node> getDirectPreNodes(Node node);
- /**
- * Same with {@link #getDirectPreNodes(Node)}.
- * <p>
- * If the dagNodeName is null, return the nodes which doesn't have outDegrees. Otherwise, return the pre nodes of
- * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
- *
- * @param dagNodeName task name, can be null.
- * @return pre task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- List<Node> getDirectPreNodes(String dagNodeName);
-
- /**
- * Same with {@link #getDirectPreNodes(String)}. Return the pre node names.
- *
- * @param dagNodeName task name, can be null.
- * @return pre task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- List<String> getDirectPreNodeNames(String dagNodeName);
+ List<Node> getDirectPreNodesByIdentify(NodeIdentify nodeIdentify);
/**
* Get the node of the DAG by the node name.
*
- * @param nodeName the node name.
+ * @param nodeIdentify the node name.
* @return the node of the DAG, return null if cannot find the node.
*/
- Node getDAGNode(String nodeName);
+ Node getDAGNode(NodeIdentify nodeIdentify);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITask.java
similarity index 84%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITask.java
index 49944d248a..6d6c0c6f5f 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITask.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public interface IWorkflowInstance {
+public interface ITask {
- int getId();
+ ITaskIdentify getIdentify();
- String getName();
+ ITaskContext getContext();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskChain.java
similarity index 86%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskChain.java
index bb270dc323..ccefc085e5 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskChain.java
@@ -15,10 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.event;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public interface IEvent {
+public interface ITaskChain {
- Class getEventOperatorClass();
+ ITask getFrom();
+
+ ITask getTo();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskContext.java
similarity index 89%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskContext.java
index 5c86c8b6f7..69e4a00d42 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskContext.java
@@ -15,5 +15,8 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;public interface IChain {
+package org.apache.dolphinscheduler.workflow.engine.dag;
+
+public interface ITaskContext {
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskIdentify.java
similarity index 88%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskIdentify.java
index 2e86662267..d0968582d4 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/ITaskIdentify.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public interface ITaskInstance {
+public interface ITaskIdentify {
- int getId();
+ Long getId();
String getName();
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Node.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Node.java
index 8e8719ac7d..7c04ccd97a 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Node.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Node.java
@@ -19,11 +19,6 @@ package org.apache.dolphinscheduler.workflow.engine.dag;
import lombok.AllArgsConstructor;
import lombok.Builder;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.List;
-
import lombok.Getter;
import lombok.NoArgsConstructor;
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Task.java
similarity index 62%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Task.java
index 380ed8b1ee..bc0c80bf1d 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Task.java
@@ -15,18 +15,26 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public class TaskExecutionContext implements ITaskExecutionContext {
+public class Task implements ITask {
- private final ITaskInstance taskInstance;
+ private final TaskIdentify taskIdentify;
- public TaskExecutionContext(ITaskInstance taskInstance) {
- this.taskInstance = taskInstance;
+ private final TaskContext taskContext;
+
+ public Task(TaskIdentify taskIdentify, TaskContext taskContext) {
+ this.taskIdentify = taskIdentify;
+ this.taskContext = taskContext;
+ }
+
+ @Override
+ public TaskIdentify getIdentify() {
+ return taskIdentify;
}
@Override
- public ITaskInstance getTaskInstance() {
- return taskInstance;
+ public TaskContext getContext() {
+ return taskContext;
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskChain.java
similarity index 61%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskChain.java
index 380ed8b1ee..b47d99059f 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskChain.java
@@ -15,18 +15,29 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-public class TaskExecutionContext implements ITaskExecutionContext {
+public class TaskChain implements ITaskChain {
- private final ITaskInstance taskInstance;
+ private final Task from;
- public TaskExecutionContext(ITaskInstance taskInstance) {
- this.taskInstance = taskInstance;
+ private final Task to;
+
+ public TaskChain(Task from, Task to) {
+ if (from == null && to == null) {
+ throw new IllegalArgumentException("from and to can not be null at the same time");
+ }
+ this.from = from;
+ this.to = to;
+ }
+
+ @Override
+ public Task getFrom() {
+ return from;
}
@Override
- public ITaskInstance getTaskInstance() {
- return taskInstance;
+ public Task getTo() {
+ return to;
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskContext.java
similarity index 88%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskContext.java
index 5c86c8b6f7..8f542549db 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskContext.java
@@ -15,5 +15,7 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;public interface IChain {
+package org.apache.dolphinscheduler.workflow.engine.dag;
+
+public class TaskContext implements ITaskContext {
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskIdentify.java
similarity index 71%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskIdentify.java
index 5280e86c08..2afc1a95a7 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/TaskIdentify.java
@@ -15,24 +15,29 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;
+package org.apache.dolphinscheduler.workflow.engine.dag;
-import lombok.Getter;
+import lombok.EqualsAndHashCode;
-@Getter
-public class WorkflowInstance implements IWorkflowInstance {
-
- private final int id;
+@EqualsAndHashCode
+public class TaskIdentify implements ITaskIdentify {
+ private final Long id;
private final String name;
- public WorkflowInstance(int id, String name) {
+ public TaskIdentify(Long id, String name) {
this.id = id;
this.name = name;
}
- public static WorkflowInstance of(int id, String name) {
- return new WorkflowInstance(id, name);
+ @Override
+ public Long getId() {
+ return id;
+ }
+
+ @Override
+ public String getName() {
+ return name;
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
index 1b3cb35e40..65fed98a88 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
@@ -17,105 +17,108 @@
package org.apache.dolphinscheduler.workflow.engine.dag;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.function.Function;
+import java.util.Set;
import java.util.stream.Collectors;
/**
* The IWorkflowDAG represent the DAG of a workflow.
*/
-public class WorkflowDAG implements DAG {
+public class WorkflowDAG implements DAG<ITask, ITaskIdentify> {
- private final Map<NodeIdentify, Node> dagNodeMap;
+ private final Map<ITaskIdentify, ITask> dagNodeMap;
- private final Map<NodeIdentify, List<Node>> outdegreeMap;
+ private final Map<ITaskIdentify, Set<ITaskIdentify>> outdegreeMap;
- private final Map<NodeIdentify, List<Node>> inDegredMap;
+ private final Map<ITaskIdentify, Set<ITaskIdentify>> inDegredMap;
- public WorkflowDAG(List<Node> nodes, List<Edge> edges) {
- this.dagNodeMap = nodes.stream().collect(Collectors.toMap(Node::getNodeIdentify, Function.identity()));
+ public WorkflowDAG(List<ITask> tasks,
+ List<ITaskChain> taskChains) {
+ this.dagNodeMap = new HashMap<>();
this.outdegreeMap = new HashMap<>();
this.inDegredMap = new HashMap<>();
- // todo:
- }
- @Override
- public List<Node> getDirectPostNodes(Node dagNode) {
- NodeIdentify nodeIdentify = dagNode.getNodeIdentify();
- if (!dagNodeMap.containsKey(nodeIdentify)) {
- return Collections.emptyList();
+ for (ITask task : tasks) {
+ ITaskIdentify identify = task.getIdentify();
+ if (dagNodeMap.containsKey(identify)) {
+ throw new IllegalArgumentException("Duplicate task identify: " + identify);
+ }
+ dagNodeMap.put(identify, task);
}
- Node node = dagNodeMap.get(nodeIdentify);
- List<Node> nodes = new ArrayList<>();
- for (DAGEdge edge : node.getOutDegrees()) {
- if (dagNodeMap.containsKey(edge.getToNodeName())) {
- nodes.add(dagNodeMap.get(edge.getToNodeName()));
+ for (ITaskChain taskChain : taskChains) {
+ ITask from = taskChain.getFrom();
+ ITask to = taskChain.getTo();
+ if (from == null) {
+ continue;
+ }
+ if (to == null) {
+ continue;
}
+ ITaskIdentify fromIdentify = from.getIdentify();
+ ITaskIdentify toIdentify = to.getIdentify();
+ Set<ITaskIdentify> outDegrees = outdegreeMap.computeIfAbsent(fromIdentify, k -> new HashSet<>());
+ if (outDegrees.contains(toIdentify)) {
+ throw new IllegalArgumentException("Duplicate task chain: " + fromIdentify + " -> " + toIdentify);
+ }
+ outDegrees.add(toIdentify);
+ Set<ITaskIdentify> inDegrees = inDegredMap.computeIfAbsent(toIdentify, k -> new HashSet<>());
+ if (inDegrees.contains(fromIdentify)) {
+ throw new IllegalArgumentException("Duplicate task chain: " + fromIdentify + " -> " + toIdentify);
+ }
+ inDegrees.add(fromIdentify);
}
- return nodes;
}
@Override
- public List<Node> getDirectPostNodes(String dagNodeName) {
- Node node = getDAGNode(dagNodeName);
- if (dagNodeName != null && node == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ public List<ITask> getDirectPostNodes(ITask iTask) {
+ if (iTask == null) {
+ return getDirectPostNodesByIdentify(null);
}
- return getDirectPostNodes(node);
+ return getDirectPostNodesByIdentify(iTask.getIdentify());
}
@Override
- public List<String> getDirectPostNodeNames(String dagNodeName) {
- Node node = getDAGNode(dagNodeName);
- if (dagNodeName != null && node == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ public List<ITask> getDirectPostNodesByIdentify(ITaskIdentify taskIdentify) {
+ if (taskIdentify == null) {
+ return dagNodeMap.values()
+ .stream()
+ .filter(task -> !inDegredMap.containsKey(task.getIdentify()))
+ .collect(Collectors.toList());
}
- return getDirectPostNodes(node).stream()
- .map(Node::getNodeName)
+ return outdegreeMap.getOrDefault(taskIdentify, Collections.emptySet())
+ .stream()
+ .map(dagNodeMap::get)
.collect(Collectors.toList());
}
@Override
- public List<Node> getDirectPreNodes(Node dagNode) {
- final String nodeName = dagNode.getNodeName();
- if (!dagNodeMap.containsKey(nodeName)) {
- return Collections.emptyList();
- }
- Node node = dagNodeMap.get(nodeName);
- List<Node> nodes = new ArrayList<>();
- for (DAGEdge edge : node.getInDegrees()) {
- if (dagNodeMap.containsKey(edge.getFromNodeName())) {
- nodes.add(dagNodeMap.get(edge.getFromNodeName()));
- }
- }
- return nodes;
- }
-
- @Override
- public List<Node> getDirectPreNodes(String dagNodeName) {
- Node node = getDAGNode(dagNodeName);
- if (dagNodeName != null && node == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ public List<ITask> getDirectPreNodes(ITask iTask) {
+ if (iTask == null) {
+ return getDirectPreNodesByIdentify(null);
}
- return getDirectPreNodes(node);
+ return getDirectPreNodesByIdentify(iTask.getIdentify());
}
@Override
- public List<String> getDirectPreNodeNames(String dagNodeName) {
- Node node = getDAGNode(dagNodeName);
- if (dagNodeName != null && node == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ public List<ITask> getDirectPreNodesByIdentify(ITaskIdentify taskIdentify) {
+ if (taskIdentify == null) {
+ return dagNodeMap.values()
+ .stream()
+ .filter(task -> !outdegreeMap.containsKey(taskIdentify))
+ .collect(Collectors.toList());
}
- return getDirectPreNodes(node).stream().map(Node::getNodeName).collect(Collectors.toList());
+ return inDegredMap.getOrDefault(taskIdentify, Collections.emptySet())
+ .stream()
+ .map(dagNodeMap::get)
+ .collect(Collectors.toList());
}
@Override
- public Node getDAGNode(String nodeName) {
- return dagNodeMap.get(nodeName);
+ public ITask getDAGNode(ITaskIdentify taskIdentify) {
+ return dagNodeMap.get(taskIdentify);
}
-
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
index 0a847583b4..1bd95e43ee 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
@@ -17,13 +17,25 @@
package org.apache.dolphinscheduler.workflow.engine.engine;
-import org.apache.dolphinscheduler.workflow.engine.dag.Node;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITask;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
+import org.apache.dolphinscheduler.workflow.engine.event.TaskExecutionPlanChainEndEvent;
import org.apache.dolphinscheduler.workflow.engine.event.TaskOperationEvent;
-import org.apache.dolphinscheduler.workflow.engine.event.TaskOperationType;
+import org.apache.dolphinscheduler.workflow.engine.event.TaskOperationEventType;
+import org.apache.dolphinscheduler.workflow.engine.event.WorkflowFinishEvent;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionPlan;
import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
-import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnableFactory;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnableIdentify;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
-import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionDAG;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
+import org.apache.dolphinscheduler.workflow.engine.workflow.WorkflowExecutionDAG;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+import java.util.List;
+import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
@@ -32,138 +44,157 @@ public class DAGEngine implements IDAGEngine {
private final IWorkflowExecutionContext workflowExecutionContext;
- private final ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
+ private final IEventRepository eventRepository;
+ private final WorkflowExecutionDAG workflowExecutionDAG;
+ private final WorkflowDAG workflowDAG;
- public DAGEngine(IWorkflowExecutionContext workflowExecutionContext,
- ITaskExecutionRunnableFactory taskExecutionRunnableFactory) {
+ private final IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify;
+
+ public DAGEngine(IWorkflowExecutionContext workflowExecutionContext) {
this.workflowExecutionContext = workflowExecutionContext;
- this.taskExecutionRunnableFactory = taskExecutionRunnableFactory;
- }
- @Override
- public void triggerNextTasks(String parentTaskNodeName) {
- workflowExecutionContext.getWorkflowExecutionDAG()
- .getDirectPostNodeNames(parentTaskNodeName)
- .forEach(this::triggerTask);
+ this.workflowExecutionRunnableIdentify = workflowExecutionContext.getIdentify();
+ this.eventRepository = workflowExecutionContext.getEventRepository();
+ this.workflowDAG = workflowExecutionContext.getWorkflowDAG();
+ this.workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
}
@Override
- public void triggerTask(String taskName) {
- IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
- Node node = workflowExecutionDAG.getDAGNode(taskName);
- if (node == null) {
- log.error("Cannot find the DAGNode for task: {}", taskName);
- return;
+ public void start() {
+ List<ITaskIdentify> startTaskIdentifies = workflowExecutionContext.getStartTaskIdentifies();
+ // If the start task is empty, trigger from the beginning
+ if (CollectionUtils.isEmpty(startTaskIdentifies)) {
+ startTaskIdentifies = workflowDAG.getDirectPostNodesByIdentify(null)
+ .stream()
+ .map(ITask::getIdentify)
+ .collect(Collectors.toList());
}
- // todo: Use condition check?
- // How to make sure the
- if (!workflowExecutionDAG.isTaskAbleToBeTriggered(taskName)) {
- log.info("The task: {} is not able to be triggered", taskName);
+ if (CollectionUtils.isEmpty(startTaskIdentifies)) {
+ eventRepository.storeEventToTail(WorkflowFinishEvent.of(workflowExecutionRunnableIdentify));
return;
}
+ startTaskIdentifies.forEach(this::triggerTask);
+ }
- if (node.isSkip()) {
- log.info("The task: {} is skipped", taskName);
- triggerNextTasks(taskName);
+ @Override
+ public void triggerNextTasks(ITaskIdentify taskIdentify) {
+ List<ITaskIdentify> directPostNodeIdentifies = workflowDAG.getDirectPostNodesByIdentify(taskIdentify)
+ .stream()
+ .map(ITask::getIdentify)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(directPostNodeIdentifies)) {
+ TaskExecutionPlanChainEndEvent taskExecutionPlanChainEndEvent = TaskExecutionPlanChainEndEvent.builder()
+ .workflowExecutionRunnableIdentify(workflowExecutionRunnableIdentify)
+ .taskIdentify(taskIdentify)
+ .build();
+ eventRepository.storeEventToTail(taskExecutionPlanChainEndEvent);
return;
}
+ directPostNodeIdentifies.forEach(this::triggerTask);
+ }
- ITaskExecutionRunnable taskExecutionRunnable =
- taskExecutionRunnableFactory.createTaskExecutionRunnable(taskName, workflowExecutionContext);
- workflowExecutionDAG.storeTaskExecutionRunnable(taskExecutionRunnable);
+ @Override
+ public void triggerTask(ITaskIdentify taskIdentify) {
+ ITaskExecutionPlan taskExecutionPlan = workflowExecutionDAG.getDAGNode(taskIdentify);
+ if (taskExecutionPlan == null) {
+ throw new IllegalArgumentException("Cannot find the ITaskExecutionPlan for taskIdentify: " + taskIdentify);
+ }
TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.RUN)
+ .taskExecutionPlan(taskExecutionPlan)
+ .taskOperationEventType(TaskOperationEventType.START)
.build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ eventRepository.storeEventToTail(taskOperationEvent);
}
@Override
- public void failoverTask(Integer taskInstanceId) {
- IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
- ITaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionDAG.getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
+ public void failoverTask(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify) {
+ ITaskExecutionPlan taskExecutionPlan =
+ workflowExecutionDAG.getDAGNode(taskExecutionRunnableIdentify.getTaskIdentify());
+ if (taskExecutionPlan == null) {
+ throw new IllegalArgumentException("Cannot find the ITaskExecutionPlan for taskIdentify: "
+ + taskExecutionRunnableIdentify.getTaskIdentify());
}
- ITaskExecutionRunnable failoverTaskExecutionRunnable = taskExecutionRunnableFactory
- .createFailoverTaskExecutionRunnable(taskExecutionRunnable, workflowExecutionContext);
- workflowExecutionDAG.storeTaskExecutionRunnable(failoverTaskExecutionRunnable);
-
TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.FAILOVER)
+ .taskExecutionPlan(taskExecutionPlan)
+ .taskOperationEventType(TaskOperationEventType.FAILOVER)
.build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ eventRepository.storeEventToTail(taskOperationEvent);
}
@Override
- public void retryTask(Integer taskInstanceId) {
- IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
- ITaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionDAG.getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
+ public void retryTask(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify) {
+ ITaskExecutionPlan taskExecutionPlan =
+ workflowExecutionDAG.getDAGNode(taskExecutionRunnableIdentify.getTaskIdentify());
+ if (taskExecutionPlan == null) {
+ throw new IllegalArgumentException("Cannot find the ITaskExecutionPlan for taskIdentify: "
+ + taskExecutionRunnableIdentify.getTaskIdentify());
}
- ITaskExecutionRunnable retryTaskExecutionRunnable = taskExecutionRunnableFactory
- .createRetryTaskExecutionRunnable(taskExecutionRunnable, workflowExecutionContext);
- workflowExecutionDAG.storeTaskExecutionRunnable(retryTaskExecutionRunnable);
-
TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.RETRY)
+ .taskExecutionPlan(taskExecutionPlan)
+ .taskOperationEventType(TaskOperationEventType.RETRY)
.build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
+ eventRepository.storeEventToTail(taskOperationEvent);
}
@Override
- public void pauseAllTask() {
- workflowExecutionContext.getWorkflowExecutionDAG()
- .getActiveTaskExecutionRunnable()
- .stream()
- .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
- .forEach(this::pauseTask);
+ public void pause() {
+ List<ITaskExecutionRunnableIdentify> activeTaskExecutionIdentify =
+ workflowExecutionDAG.getActiveTaskExecutionPlan()
+ .stream()
+ .map(ITaskExecutionPlan::getActiveTaskExecutionRunnable)
+ .map(ITaskExecutionRunnable::getIdentify)
+ .collect(Collectors.toList());
+
+ if (CollectionUtils.isEmpty(activeTaskExecutionIdentify)) {
+ eventRepository.storeEventToTail(WorkflowFinishEvent.of(workflowExecutionRunnableIdentify));
+ return;
+ }
+ activeTaskExecutionIdentify.forEach(this::pauseTask);
}
@Override
- public void pauseTask(Integer taskInstanceId) {
- ITaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
+ public void pauseTask(ITaskExecutionRunnableIdentify taskExecutionIdentify) {
+ ITaskExecutionPlan taskExecutionPlan = workflowExecutionDAG.getDAGNode(taskExecutionIdentify.getTaskIdentify());
+ if (taskExecutionPlan == null) {
+ throw new IllegalArgumentException(
+ "Cannot find the ITaskExecutionPlan for taskIdentify: " + taskExecutionIdentify.getTaskIdentify());
}
TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.PAUSE)
+ .taskExecutionPlan(taskExecutionPlan)
+ .taskOperationEventType(TaskOperationEventType.PAUSE)
.build();
workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
}
@Override
- public void killAllTask() {
- workflowExecutionContext.getWorkflowExecutionDAG()
- .getActiveTaskExecutionRunnable()
- .stream()
- .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
- .forEach(this::killTask);
+ public void kill() {
+ List<ITaskExecutionRunnableIdentify> activeTaskExecutionIdentify =
+ workflowExecutionDAG.getActiveTaskExecutionPlan()
+ .stream()
+ .map(ITaskExecutionPlan::getActiveTaskExecutionRunnable)
+ .map(ITaskExecutionRunnable::getIdentify)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(activeTaskExecutionIdentify)) {
+ if (CollectionUtils.isEmpty(activeTaskExecutionIdentify)) {
+ eventRepository.storeEventToTail(WorkflowFinishEvent.of(workflowExecutionRunnableIdentify));
+ return;
+ }
+ return;
+ }
+ activeTaskExecutionIdentify.forEach(this::killTask);
}
@Override
- public void killTask(Integer taskInstanceId) {
- ITaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
+ public void killTask(ITaskExecutionRunnableIdentify taskExecutionIdentify) {
+ ITaskExecutionPlan taskExecutionPlan = workflowExecutionDAG.getDAGNode(taskExecutionIdentify.getTaskIdentify());
+ if (taskExecutionPlan == null) {
+ throw new IllegalArgumentException(
+ "Cannot find the ITaskExecutionPlan for taskIdentify: " + taskExecutionIdentify.getTaskIdentify());
}
-
TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.KILL)
+ .taskExecutionPlan(taskExecutionPlan)
+ .taskOperationEventType(TaskOperationEventType.KILL)
.build();
workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngineFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngineFactory.java
index c07ca6ffbb..78cbdabcb6 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngineFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngineFactory.java
@@ -33,6 +33,6 @@ public class DAGEngineFactory implements IDAGEngineFactory {
@Override
public IDAGEngine createDAGEngine(IWorkflowExecutionContext workflowExecutionContext) {
- return new DAGEngine(workflowExecutionContext, taskExecutionRunnableFactory);
+ return new DAGEngine(workflowExecutionContext);
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngine.java
index 10e483f0ad..70e83820fa 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngine.java
@@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
import org.apache.dolphinscheduler.common.thread.ThreadUtils;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
import org.apache.commons.collections4.CollectionUtils;
@@ -83,24 +84,22 @@ public class EventEngine extends BaseDaemonThread implements IEventEngine {
for (IWorkflowExecutionRunnable workflowExecutionRunnable : workflowExecutionRunnableList) {
IWorkflowExecutionContext workflowExecutionContext =
workflowExecutionRunnable.getWorkflowExecutionContext();
- final Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
- final String workflowInstanceName = workflowExecutionContext.getWorkflowInstanceName();
+ IWorkflowExecutionRunnableIdentify identify = workflowExecutionContext.getIdentify();
try {
- MDC.put(Constants.WORKFLOW_INSTANCE_ID_MDC_KEY, String.valueOf(workflowInstanceId));
- if (workflowExecutionRunnable.isEventFiring()) {
- log.debug("WorkflowExecutionRunnable: {} is already in firing", workflowInstanceName);
- continue;
- }
+ MDC.put(Constants.WORKFLOW_INSTANCE_ID_MDC_KEY, String.valueOf(identify.getId()));
+ // if (workflowExecutionRunnable.isEventFiring()) {
+ // log.debug("WorkflowExecutionRunnable: {} is already in firing", identify);
+ // continue;
+ // }
eventFirer.fireActiveEvents(workflowExecutionRunnable)
.whenComplete((fireCount, ex) -> {
- workflowExecutionRunnable.setEventFiring(false);
+ // workflowExecutionRunnable.setEventFiring(false);
if (ex != null) {
- log.error("Fire event for WorkflowExecutionRunnable: {} error", workflowInstanceName,
- ex);
+ log.error("Fire event for WorkflowExecutionRunnable: {} error", identify, ex);
} else {
if (fireCount > 0) {
log.info("Fire {} events for WorkflowExecutionRunnable: {} success", fireCount,
- workflowInstanceName);
+ identify);
}
}
});
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngine.java
index 0971e2a179..bea93975e0 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IDAGEngine.java
@@ -17,6 +17,8 @@
package org.apache.dolphinscheduler.workflow.engine.engine;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnableIdentify;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionDAG;
/**
@@ -25,48 +27,52 @@ import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionDA
*/
public interface IDAGEngine {
+ /**
+ * Start the DAGEngine, will trigger the start tasks.
+ */
+ void start();
+
/**
* Trigger the tasks which are post of the given task.
- * <P> If there are no task after the given taskNode, will try to finish the WorkflowExecutionRunnable.
- * <p> If the
+ * <P> If there are no task after the given taskNode, will try to finish the WorkflowExecutionRunnable(Send a task chain end event).
*
- * @param parentTaskNodeName the parent task name
+ * @param taskIdentify the parent task identify
*/
- void triggerNextTasks(String parentTaskNodeName);
+ void triggerNextTasks(ITaskIdentify taskIdentify);
/**
- * Trigger the given task
+ * Trigger the given task.
*
- * @param taskName task name
+ * @param taskIdentify task name
*/
- void triggerTask(String taskName);
+ void triggerTask(ITaskIdentify taskIdentify);
/**
* Failover the given task.
*
* @param taskInstanceId taskInstanceId
*/
- void failoverTask(Integer taskInstanceId);
+ void failoverTask(ITaskExecutionRunnableIdentify taskInstanceId);
/**
* Retry the given task.
*
* @param taskInstanceId taskInstanceId
*/
- void retryTask(Integer taskInstanceId);
+ void retryTask(ITaskExecutionRunnableIdentify taskInstanceId);
- void pauseAllTask();
+ void pause();
/**
* Pause the given task.
*/
- void pauseTask(Integer taskInstanceId);
+ void pauseTask(ITaskExecutionRunnableIdentify taskExecutionIdentify);
- void killAllTask();
+ void kill();
/**
* Kill the given task.
*/
- void killTask(Integer taskId);
+ void killTask(ITaskExecutionRunnableIdentify taskExecutionIdentify);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
index 50ccccae67..f173cae643 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.workflow.engine.engine;
import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunnableNotFoundException;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
/**
* The WorkflowEngine is responsible for starting, stopping, pausing, and finalizing {@link IWorkflowExecutionRunnable}.
@@ -41,25 +42,25 @@ public interface IWorkflowEngine {
/**
* Pause a workflow instance.
*
- * @param workflowInstanceId the ID of the workflow to pause
+ * @param workflowExecutionRunnableIdentify the ID of the workflow to pause
* @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
*/
- void pauseWorkflow(Integer workflowInstanceId);
+ void pauseWorkflow(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify);
/**
* Kill a workflow instance.
*
- * @param workflowInstanceId the ID of the workflow to stop
+ * @param workflowExecutionRunnableIdentify the ID of the workflow to stop
* @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
*/
- void killWorkflow(Integer workflowInstanceId);
+ void killWorkflow(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify);
/**
* Finalize a workflow instance. Once a workflow has been finalized, then it cannot receive new operation, and will be removed from memory.
*
- * @param workflowInstanceId the ID of the workflow to finalize
+ * @param workflowExecutionRunnableIdentify the ID of the workflow to finalize
*/
- void finalizeWorkflow(Integer workflowInstanceId);
+ void finalizeWorkflow(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify);
/**
* Shutdown the workflow engine. The workflow engine cannot be restarted after shutdown. This method will block until the workflow engine is completely shutdown.
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
index b9c2b05391..7cb566ed33 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
@@ -21,6 +21,7 @@ import org.apache.dolphinscheduler.workflow.engine.event.WorkflowOperationEvent;
import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunnableNotFoundException;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
import lombok.extern.slf4j.Slf4j;
@@ -46,47 +47,49 @@ public class WorkflowEngine implements IWorkflowEngine {
@Override
public void triggerWorkflow(IWorkflowExecutionRunnable workflowExecuteRunnable) {
IWorkflowExecutionContext workflowExecutionContext = workflowExecuteRunnable.getWorkflowExecutionContext();
- Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
- log.info("Triggering WorkflowExecutionRunnable: {}", workflowExecutionContext.getWorkflowInstanceName());
+ IWorkflowExecutionRunnableIdentify workflowExecutionIdentify = workflowExecutionContext.getIdentify();
+ log.info("Triggering WorkflowExecutionRunnable: {}", workflowExecutionIdentify);
workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(workflowExecuteRunnable);
- workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.triggerEvent(workflowInstanceId));
+ workflowExecuteRunnable
+ .storeEventToTail(WorkflowOperationEvent.triggerEvent(workflowExecutionIdentify));
}
@Override
- public void pauseWorkflow(Integer workflowInstanceId) {
+ public void pauseWorkflow(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify) {
IWorkflowExecutionRunnable workflowExecuteRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnable(workflowExecutionRunnableIdentify);
if (workflowExecuteRunnable == null) {
- throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
+ throw new WorkflowExecuteRunnableNotFoundException(workflowExecutionRunnableIdentify);
}
log.info("Pausing WorkflowExecutionRunnable: {}",
- workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
- workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.pauseEvent(workflowInstanceId));
+ workflowExecuteRunnable.getWorkflowExecutionContext().getIdentify());
+ workflowExecuteRunnable
+ .storeEventToTail(WorkflowOperationEvent.pauseEvent(workflowExecuteRunnable.getIdentity()));
}
@Override
- public void killWorkflow(Integer workflowInstanceId) {
+ public void killWorkflow(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify) {
IWorkflowExecutionRunnable workflowExecuteRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnable(workflowExecutionRunnableIdentify);
if (workflowExecuteRunnable == null) {
- throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
+ throw new WorkflowExecuteRunnableNotFoundException(workflowExecutionRunnableIdentify);
}
log.info("Killing WorkflowExecutionRunnable: {}",
- workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
- workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.killEvent(workflowInstanceId));
+ workflowExecuteRunnable.getWorkflowExecutionContext().getIdentify());
+ workflowExecuteRunnable
+ .storeEventToTail(WorkflowOperationEvent.killEvent(workflowExecuteRunnable.getIdentity()));
}
@Override
- public void finalizeWorkflow(Integer workflowInstanceId) {
+ public void finalizeWorkflow(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify) {
IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
+ workflowExecuteRunnableRepository.getWorkflowExecutionRunnable(workflowExecutionRunnableIdentify);
if (workflowExecutionRunnable == null) {
return;
}
// todo: If the workflowExecutionRunnable is not finished, we cannot finalize it.
- log.info("Finalizing WorkflowExecutionRunnable: {}",
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
- workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
+ log.info("Finalizing WorkflowExecutionRunnable: {}", workflowExecutionRunnable.getIdentity());
+ workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowExecutionRunnableIdentify);
}
@Override
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventDispatcher.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventDispatcher.java
new file mode 100644
index 0000000000..7edfa32d71
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventDispatcher.java
@@ -0,0 +1,44 @@
+/*
+ * 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.workflow.engine.event;
+
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
+
+public class EventDispatcher implements IEventDispatcher {
+
+ private final IWorkflowExecutionRunnableRepository workflowExecutionRunnableRepository;
+
+ public EventDispatcher(IWorkflowExecutionRunnableRepository workflowExecutionRunnableRepository) {
+ this.workflowExecutionRunnableRepository = workflowExecutionRunnableRepository;
+ }
+
+ // todo: Do we need to split the EventRepository from WorkflowExecutionRunnable?
+ @Override
+ public void dispatch(IEvent event) {
+ IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify;
+ if (event instanceof IWorkflowEvent) {
+ workflowExecutionRunnableIdentify = ((IWorkflowEvent) event).getWorkflowExecutionRunnableIdentify();
+ } else {
+ throw new UnsupportedOperationException("Unsupported event: " + event);
+ }
+ // todo:
+ workflowExecutionRunnableRepository.getWorkflowExecutionRunnable(workflowExecutionRunnableIdentify)
+ .getEventRepository().storeEventToTail(event);
+ }
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
index bb270dc323..aa78fcbf93 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
@@ -19,6 +19,8 @@ package org.apache.dolphinscheduler.workflow.engine.event;
public interface IEvent {
+ IEventType getEventType();
+
Class getEventOperatorClass();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventDispatcher.java
similarity index 92%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventDispatcher.java
index bb270dc323..ab01b7e54f 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventDispatcher.java
@@ -17,8 +17,8 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-public interface IEvent {
+public interface IEventDispatcher {
- Class getEventOperatorClass();
+ void dispatch(IEvent event);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventType.java
similarity index 93%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventType.java
index bb270dc323..d64beef2dd 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventType.java
@@ -17,8 +17,5 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-public interface IEvent {
-
- Class getEventOperatorClass();
-
+public interface IEventType {
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEvent.java
index dd1f315aed..4c36240d28 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/ITaskEvent.java
@@ -17,10 +17,10 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionPlan;
public interface ITaskEvent extends IEvent {
- ITaskExecutionRunnable getTaskExecutionRunnable();
+ ITaskExecutionPlan getTaskExecutionPlan();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEvent.java
index 304776b582..3c71a31182 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IWorkflowEvent.java
@@ -17,6 +17,8 @@
package org.apache.dolphinscheduler.workflow.engine.event;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
+
public interface IWorkflowEvent extends IEvent {
/**
@@ -24,6 +26,6 @@ public interface IWorkflowEvent extends IEvent {
*
* @return workflowInstanceId, shouldn't be null
*/
- Integer getWorkflowInstanceId();
+ IWorkflowExecutionRunnableIdentify getWorkflowExecutionRunnableIdentify();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskExecutionPlanChainEndEvent.java
similarity index 64%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskExecutionPlanChainEndEvent.java
index 6546bfc55e..680235eaff 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskExecutionPlanChainEndEvent.java
@@ -17,22 +17,24 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
-import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
-import lombok.NoArgsConstructor;
@Data
@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowFinishEvent implements IWorkflowEvent, ISyncEvent {
+public class TaskExecutionPlanChainEndEvent implements IEvent, ISyncEvent {
- private Integer workflowInstanceId;
+ private final IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify;
+ // If the taskIdentify is null then means there is no active TaskExecutionPlan in the workflow
+ private final ITaskIdentify taskIdentify;
- private WorkflowExecutionStatus workflowExecutionStatus;
+ @Override
+ public IEventType getEventType() {
+ return null;
+ }
@Override
public Class getEventOperatorClass() {
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
index cdeeb30d2b..9a9ced63d3 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
@@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionPlan;
import lombok.AllArgsConstructor;
import lombok.Builder;
@@ -30,9 +30,14 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class TaskOperationEvent implements ITaskEvent, ISyncEvent {
- private ITaskExecutionRunnable taskExecutionRunnable;
+ private ITaskExecutionPlan taskExecutionPlan;
- private TaskOperationType taskOperationType;
+ private TaskOperationEventType taskOperationEventType;
+
+ @Override
+ public IEventType getEventType() {
+ return taskOperationEventType;
+ }
@Override
public Class getEventOperatorClass() {
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventOperator.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventOperator.java
index e17868822c..389914d07d 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventOperator.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventOperator.java
@@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionPlan;
import lombok.extern.slf4j.Slf4j;
@@ -26,16 +26,22 @@ public class TaskOperationEventOperator implements ITaskEventOperator<TaskOperat
@Override
public void handleEvent(TaskOperationEvent event) {
- ITaskExecutionRunnable taskExecutionRunnable = event.getTaskExecutionRunnable();
- switch (event.getTaskOperationType()) {
- case RUN:
- taskExecutionRunnable.dispatch();
+ ITaskExecutionPlan taskExecutionPlan = event.getTaskExecutionPlan();
+ TaskOperationEventType eventType = (TaskOperationEventType) event.getEventType();
+ switch (eventType) {
+ case FAILOVER:
+ taskExecutionPlan.failoverTask(taskExecutionPlan.getActiveTaskExecutionRunnable().getIdentify());
break;
+ case START:
+ taskExecutionPlan.start();
+ break;
+ case RETRY:
+ taskExecutionPlan.retryTask(taskExecutionPlan.getActiveTaskExecutionRunnable().getIdentify());
case KILL:
- taskExecutionRunnable.kill();
+ taskExecutionPlan.killTask(taskExecutionPlan.getActiveTaskExecutionRunnable().getIdentify());
break;
case PAUSE:
- taskExecutionRunnable.pause();
+ taskExecutionPlan.pauseTask(taskExecutionPlan.getActiveTaskExecutionRunnable().getIdentify());
break;
default:
log.error("Unknown TaskOperationType for event: {}", event);
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationType.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventType.java
similarity index 92%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationType.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventType.java
index 094164c789..a5fec705d3 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationType.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEventType.java
@@ -17,10 +17,10 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-public enum TaskOperationType {
+public enum TaskOperationEventType implements IEventType {
FAILOVER,
- RUN,
+ START,
RETRY,
KILL,
PAUSE,
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
index 17ceed448f..9642a37950 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
@@ -17,6 +17,8 @@
package org.apache.dolphinscheduler.workflow.engine.event;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
+
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@@ -28,10 +30,20 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class WorkflowFailedEvent implements IWorkflowEvent {
- private Integer workflowInstanceId;
-
private String failedReason;
+ private IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify;
+
+ @Override
+ public IWorkflowExecutionRunnableIdentify getWorkflowExecutionRunnableIdentify() {
+ return null;
+ }
+
+ @Override
+ public IEventType getEventType() {
+ return null;
+ }
+
@Override
public Class getEventOperatorClass() {
return null;
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
index 6546bfc55e..6ca03d4baa 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
@@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
import lombok.AllArgsConstructor;
import lombok.Builder;
@@ -30,9 +30,18 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class WorkflowFinishEvent implements IWorkflowEvent, ISyncEvent {
- private Integer workflowInstanceId;
+ private IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify;
- private WorkflowExecutionStatus workflowExecutionStatus;
+ public static WorkflowFinishEvent of(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify) {
+ return WorkflowFinishEvent.builder()
+ .workflowExecutionRunnableIdentify(workflowExecutionRunnableIdentify)
+ .build();
+ }
+
+ @Override
+ public IEventType getEventType() {
+ return null;
+ }
@Override
public Class getEventOperatorClass() {
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
index 9f1ecf8db8..2e25279919 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
@@ -17,39 +17,49 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
-@Data
-@Builder
-@AllArgsConstructor
public class WorkflowOperationEvent implements IWorkflowEvent, ISyncEvent {
- private Integer workflowInstanceId;
- private WorkflowOperationType workflowOperationType;
+ private final IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify;
+ private final WorkflowOperationEventType workflowOperationEventType;
- public static WorkflowOperationEvent of(Integer workflowInstanceId, WorkflowOperationType workflowOperationType) {
- return WorkflowOperationEvent.builder()
- .workflowInstanceId(workflowInstanceId)
- .workflowOperationType(workflowOperationType)
- .build();
+ private WorkflowOperationEvent(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify,
+ WorkflowOperationEventType workflowOperationEventType) {
+ this.workflowExecutionRunnableIdentify = workflowExecutionRunnableIdentify;
+ this.workflowOperationEventType = workflowOperationEventType;
}
- public static WorkflowOperationEvent triggerEvent(Integer workflowInstanceId) {
- return of(workflowInstanceId, WorkflowOperationType.TRIGGER);
+ public static WorkflowOperationEvent of(IWorkflowExecutionRunnableIdentify workflowExecutionIdentify,
+ WorkflowOperationEventType workflowOperationEventType) {
+ return new WorkflowOperationEvent(workflowExecutionIdentify, workflowOperationEventType);
}
- public static WorkflowOperationEvent pauseEvent(Integer workflowInstanceId) {
- return of(workflowInstanceId, WorkflowOperationType.PAUSE);
+ public static WorkflowOperationEvent triggerEvent(IWorkflowExecutionRunnableIdentify workflowExecutionIdentify) {
+ return of(workflowExecutionIdentify, WorkflowOperationEventType.TRIGGER);
}
- public static WorkflowOperationEvent killEvent(Integer workflowInstanceId) {
- return of(workflowInstanceId, WorkflowOperationType.KILL);
+ public static WorkflowOperationEvent pauseEvent(IWorkflowExecutionRunnableIdentify workflowExecutionIdentify) {
+ return of(workflowExecutionIdentify, WorkflowOperationEventType.PAUSE);
+ }
+
+ public static WorkflowOperationEvent killEvent(IWorkflowExecutionRunnableIdentify workflowExecutionIdentify) {
+ return of(workflowExecutionIdentify, WorkflowOperationEventType.KILL);
+ }
+
+ @Override
+ public IEventType getEventType() {
+ return workflowOperationEventType;
}
@Override
public Class getEventOperatorClass() {
return WorkflowOperationEventOperator.class;
}
+
+ @Override
+ public IWorkflowExecutionRunnableIdentify getWorkflowExecutionRunnableIdentify() {
+ return workflowExecutionRunnableIdentify;
+ }
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
index 0822a84f85..b1a302cd59 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
@@ -36,12 +36,14 @@ public class WorkflowOperationEventOperator implements IWorkflowEventOperator<Wo
@Override
public void handleEvent(WorkflowOperationEvent event) {
IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
+ workflowExecuteRunnableRepository
+ .getWorkflowExecutionRunnable(event.getWorkflowExecutionRunnableIdentify());
if (workflowExecutionRunnable == null) {
log.warn("WorkflowExecutionRunnable not found: {}", event);
return;
}
- switch (event.getWorkflowOperationType()) {
+ WorkflowOperationEventType workflowOperationEvent = (WorkflowOperationEventType) event.getEventType();
+ switch (workflowOperationEvent) {
case TRIGGER:
triggerWorkflow(workflowExecutionRunnable);
break;
@@ -65,9 +67,9 @@ public class WorkflowOperationEventOperator implements IWorkflowEventOperator<Wo
}
IWorkflowExecutionContext workflowExecutionContext =
workflowExecutionRunnable.getWorkflowExecutionContext();
- log.error("Trigger workflow: {} failed", workflowExecutionContext.getWorkflowInstanceName(), exception);
+ log.error("Trigger workflow: {} failed", workflowExecutionContext.getIdentify(), exception);
WorkflowFailedEvent workflowExecutionRunnableFailedEvent = WorkflowFailedEvent.builder()
- .workflowInstanceId(workflowExecutionContext.getWorkflowInstanceId())
+ .workflowExecutionRunnableIdentify(workflowExecutionRunnable.getIdentity())
.failedReason(exception.getMessage())
.build();
workflowExecutionRunnable.storeEventToTail(workflowExecutionRunnableFailedEvent);
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationType.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventType.java
similarity index 94%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationType.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventType.java
index 0a1d260217..d1b45a3452 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationType.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventType.java
@@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-public enum WorkflowOperationType {
+public enum WorkflowOperationEventType implements IEventType {
/**
* Trigger the workflow instance.
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/exception/WorkflowExecuteRunnableNotFoundException.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/exception/WorkflowExecuteRunnableNotFoundException.java
index 10d0b4252b..ca8ab052c6 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/exception/WorkflowExecuteRunnableNotFoundException.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/exception/WorkflowExecuteRunnableNotFoundException.java
@@ -17,14 +17,12 @@
package org.apache.dolphinscheduler.workflow.engine.exception;
-public class WorkflowExecuteRunnableNotFoundException extends RuntimeException {
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableIdentify;
- public WorkflowExecuteRunnableNotFoundException(Integer workflowInstanceId) {
- super("WorkflowExecuteRunnable not found: [id=" + workflowInstanceId + "]");
- }
+public class WorkflowExecuteRunnableNotFoundException extends RuntimeException {
- public WorkflowExecuteRunnableNotFoundException(String workflowInstanceName) {
- super("WorkflowExecuteRunnable not found: [name=" + workflowInstanceName + "]");
+ public WorkflowExecuteRunnableNotFoundException(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify) {
+ super("WorkflowExecuteRunnable not found: " + workflowExecutionRunnableIdentify);
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultTaskExecutionRunnableDelegate.java
similarity index 70%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultTaskExecutionRunnableDelegate.java
index 380ed8b1ee..7bf466c158 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultTaskExecutionRunnableDelegate.java
@@ -17,16 +17,35 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContext implements ITaskExecutionContext {
+public class DefaultTaskExecutionRunnableDelegate implements ITaskExecutionRunnableDelegate {
- private final ITaskInstance taskInstance;
+ @Override
+ public void beforeStart() {
+
+ }
+
+ @Override
+ public void afterStart() {
+
+ }
+
+ @Override
+ public void beforePause() {
- public TaskExecutionContext(ITaskInstance taskInstance) {
- this.taskInstance = taskInstance;
}
@Override
- public ITaskInstance getTaskInstance() {
- return taskInstance;
+ public void afterPause() {
+
+ }
+
+ @Override
+ public void beforeKill() {
+
+ }
+
+ @Override
+ public void afterKill() {
+
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultTaskExecutionRunnableDelegateFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultTaskExecutionRunnableDelegateFactory.java
new file mode 100644
index 0000000000..d4b5195feb
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultTaskExecutionRunnableDelegateFactory.java
@@ -0,0 +1,51 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+
+public class DefaultTaskExecutionRunnableDelegateFactory implements ITaskExecutionRunnableDelegateFactory {
+
+ private static final DefaultTaskExecutionRunnableDelegateFactory INSTANCE =
+ new DefaultTaskExecutionRunnableDelegateFactory();
+
+ private DefaultTaskExecutionRunnableDelegateFactory() {
+ }
+
+ public static DefaultTaskExecutionRunnableDelegateFactory getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public ITaskExecutionRunnableDelegate createTaskExecutionRunnable(ITaskIdentify taskIdentify,
+ IWorkflowExecutionContext workflowExecutionContext) {
+ return new DefaultTaskExecutionRunnableDelegate();
+ }
+
+ @Override
+ public ITaskExecutionRunnableDelegate createFailoverTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext) {
+ return new DefaultTaskExecutionRunnableDelegate();
+ }
+
+ @Override
+ public ITaskExecutionRunnableDelegate createRetryTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext) {
+ return new DefaultTaskExecutionRunnableDelegate();
+ }
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultWorkflowExecutionRunnableDelegate.java
similarity index 69%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultWorkflowExecutionRunnableDelegate.java
index 380ed8b1ee..3465206545 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultWorkflowExecutionRunnableDelegate.java
@@ -17,16 +17,35 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContext implements ITaskExecutionContext {
+public class DefaultWorkflowExecutionRunnableDelegate implements IWorkflowExecutionRunnableDelegate {
- private final ITaskInstance taskInstance;
+ @Override
+ public void beforeStart() {
+
+ }
+
+ @Override
+ public void afterStart() {
+
+ }
+
+ @Override
+ public void beforePause() {
- public TaskExecutionContext(ITaskInstance taskInstance) {
- this.taskInstance = taskInstance;
}
@Override
- public ITaskInstance getTaskInstance() {
- return taskInstance;
+ public void afterPause() {
+
+ }
+
+ @Override
+ public void beforeKill() {
+
+ }
+
+ @Override
+ public void afterKill() {
+
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultWorkflowExecutionRunnableDelegateFactory.java
similarity index 58%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultWorkflowExecutionRunnableDelegateFactory.java
index 380ed8b1ee..b9487f5674 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/DefaultWorkflowExecutionRunnableDelegateFactory.java
@@ -17,16 +17,20 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public class TaskExecutionContext implements ITaskExecutionContext {
+public class DefaultWorkflowExecutionRunnableDelegateFactory implements IWorkflowExecutionRunnableDelegateFactory {
- private final ITaskInstance taskInstance;
+ private static final DefaultWorkflowExecutionRunnableDelegateFactory INSTANCE =
+ new DefaultWorkflowExecutionRunnableDelegateFactory();
- public TaskExecutionContext(ITaskInstance taskInstance) {
- this.taskInstance = taskInstance;
+ private DefaultWorkflowExecutionRunnableDelegateFactory() {
+ }
+
+ public static DefaultWorkflowExecutionRunnableDelegateFactory getInstance() {
+ return INSTANCE;
}
@Override
- public ITaskInstance getTaskInstance() {
- return taskInstance;
+ public IWorkflowExecutionRunnableDelegate createWorkflowExecutionRunnableDelegate(IWorkflowExecutionContext workflowExecutionContext) {
+ return new DefaultWorkflowExecutionRunnableDelegate();
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
index f35bf10b74..08bfa53055 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
@@ -24,10 +24,6 @@ public interface IEventfulExecutionRunnable {
IEventRepository getEventRepository();
- boolean isEventFiring();
-
- void setEventFiring(boolean eventFiring);
-
default void storeEventToTail(IEvent event) {
getEventRepository().storeEventToTail(event);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
index 6a2945244c..3f9b509401 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
@@ -17,8 +17,12 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
+
public interface ITaskExecutionContext {
- ITaskInstance getTaskInstance();
+ ITaskExecutionRunnableIdentify getIdentify();
+
+ IEventRepository getEventRepository();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContextFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContextFactory.java
index 2f6a0bd9b8..0ccbf5eeba 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContextFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContextFactory.java
@@ -17,9 +17,11 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+
public interface ITaskExecutionContextFactory {
- ITaskExecutionContext createTaskExecutionContext(String taskName,
+ ITaskExecutionContext createTaskExecutionContext(ITaskIdentify taskIdentify,
IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionPlan.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionPlan.java
new file mode 100644
index 0000000000..b6ff2c2721
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionPlan.java
@@ -0,0 +1,52 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.dag.ITask;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+
+import java.util.List;
+
+/**
+ * The task execution plan interface which represents the task with its execution plan.
+ * The task execution plan contains the task identify, task and the list of task execution runnables.
+ */
+public interface ITaskExecutionPlan {
+
+ void start();
+
+ void failoverTask(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify);
+
+ void retryTask(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify);
+
+ void pauseTask(ITaskExecutionRunnableIdentify taskExecutionIdentify);
+
+ void killTask(ITaskExecutionRunnableIdentify taskExecutionIdentify);
+
+ ITaskIdentify getTaskIdentify();
+
+ ITaskExecutionRunnable getActiveTaskExecutionRunnable();
+
+ ITask getTask();
+
+ List<ITaskExecutionRunnable> getTaskExecutionRunnableList();
+
+ ITaskExecutionRunnable getTaskExecutionRunnable(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify);
+
+ ITaskExecutionRunnable storeTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable);
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionPlanChain.java
similarity index 88%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionPlanChain.java
index 49944d248a..b97dab6390 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionPlanChain.java
@@ -17,10 +17,10 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface IWorkflowInstance {
+public interface ITaskExecutionPlanChain {
- int getId();
+ ITaskExecutionPlan getFrom();
- String getName();
+ ITaskExecutionPlan getTo();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnable.java
index a3ab6cc6a6..268b7d8aa1 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnable.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnable.java
@@ -20,17 +20,12 @@ package org.apache.dolphinscheduler.workflow.engine.workflow;
/**
* The TaskExecutionRunnable represent the running task, it is responsible for operate the task instance. e.g. dispatch, kill, pause.
*/
-public interface ITaskExecutionRunnable {
+public interface ITaskExecutionRunnable extends IEventfulExecutionRunnable {
/**
- * Dispatch the task instance.
+ * Start the task instance.
*/
- void dispatch();
-
- /**
- * Run the task instance.
- */
- void run();
+ void start();
/**
* Kill the task instance.
@@ -42,6 +37,13 @@ public interface ITaskExecutionRunnable {
*/
void pause();
+ /**
+ * Get the task execution identify.
+ *
+ * @return the task execution identify
+ */
+ ITaskExecutionRunnableIdentify getIdentify();
+
/**
* Get the task execution context.
*
@@ -56,4 +58,5 @@ public interface ITaskExecutionRunnable {
* @return true if the current task can be accessed to the post task.
*/
boolean isReadyToTrigger(String taskNodeName);
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableChain.java
similarity index 87%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableChain.java
index 2e86662267..ce47fcac73 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableChain.java
@@ -17,10 +17,10 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface ITaskInstance {
+public interface ITaskExecutionRunnableChain {
- int getId();
+ ITaskExecutionRunnable getFrom();
- String getName();
+ ITaskExecutionRunnable getTo();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableDelegate.java
similarity index 81%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableDelegate.java
index 2e86662267..09e6408353 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableDelegate.java
@@ -17,10 +17,18 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface ITaskInstance {
+public interface ITaskExecutionRunnableDelegate {
- int getId();
+ void beforeStart();
- String getName();
+ void afterStart();
+
+ void beforePause();
+
+ void afterPause();
+
+ void beforeKill();
+
+ void afterKill();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableDelegateFactory.java
similarity index 58%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableDelegateFactory.java
index b23364597b..4502b079a2 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableDelegateFactory.java
@@ -17,14 +17,17 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface ITaskExecutionRunnableFactory {
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
- ITaskExecutionRunnable createTaskExecutionRunnable(String taskName,
- IWorkflowExecutionContext workflowExecutionContext);
+public interface ITaskExecutionRunnableDelegateFactory {
- ITaskExecutionRunnable createFailoverTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ ITaskExecutionRunnableDelegate createTaskExecutionRunnable(ITaskIdentify taskIdentify,
IWorkflowExecutionContext workflowExecutionContext);
- ITaskExecutionRunnable createRetryTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
- IWorkflowExecutionContext workflowExecutionContext);
+ ITaskExecutionRunnableDelegate createFailoverTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext);
+
+ ITaskExecutionRunnableDelegate createRetryTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext);
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
index b23364597b..8a4630e156 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableFactory.java
@@ -17,9 +17,11 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+
public interface ITaskExecutionRunnableFactory {
- ITaskExecutionRunnable createTaskExecutionRunnable(String taskName,
+ ITaskExecutionRunnable createTaskExecutionRunnable(ITaskIdentify taskIdentify,
IWorkflowExecutionContext workflowExecutionContext);
ITaskExecutionRunnable createFailoverTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableIdentify.java
similarity index 83%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableIdentify.java
index 2e86662267..37c70d8036 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionRunnableIdentify.java
@@ -17,10 +17,14 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface ITaskInstance {
+import org.apache.dolphinscheduler.workflow.engine.dag.TaskIdentify;
- int getId();
+public interface ITaskExecutionRunnableIdentify {
+
+ Long getId();
String getName();
+ TaskIdentify getTaskIdentify();
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionContext.java
index 265076b4f1..3ecb75fb92 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionContext.java
@@ -17,22 +17,22 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
+import java.util.List;
+
public interface IWorkflowExecutionContext {
- IWorkflowInstance getWorkflowInstance();
+ IWorkflowExecutionRunnableIdentify getIdentify();
- IWorkflowExecutionDAG getWorkflowExecutionDAG();
+ List<ITaskIdentify> getStartTaskIdentifies();
- IEventRepository getEventRepository();
+ WorkflowDAG getWorkflowDAG();
- default int getWorkflowInstanceId() {
- return getWorkflowInstance().getId();
- }
+ WorkflowExecutionDAG getWorkflowExecutionDAG();
- default String getWorkflowInstanceName() {
- return getWorkflowInstance().getName();
- }
+ IEventRepository getEventRepository();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
index 81732181ae..f27327314c 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
@@ -24,25 +24,7 @@ import java.util.List;
/**
* The WorkflowExecutionDAG represent the running workflow DAG.
*/
-public interface IWorkflowExecutionDAG {
-
- List<String> getStartNodeNames();
-
- /**
- * Get TaskExecutionRunnable by given TaskInstanceId.
- *
- * @param taskInstanceId taskInstanceId.
- * @return TaskExecutionRunnable
- */
- ITaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId);
-
- /**
- * Get TaskExecutionRunnable by given taskName.
- *
- * @param taskName task name.
- * @return TaskExecutionRunnable
- */
- ITaskExecutionRunnable getTaskExecutionRunnableByName(String taskName);
+public interface IWorkflowExecutionDAG extends DAG<ITaskExecutionRunnable, ITaskExecutionRunnableIdentify> {
/**
* Get TaskExecutionRunnable which is not finished.
@@ -51,21 +33,4 @@ public interface IWorkflowExecutionDAG {
*/
List<ITaskExecutionRunnable> getActiveTaskExecutionRunnable();
- /**
- * Get the direct pre TaskExecutionRunnable of the given taskName.
- *
- * @param taskName task name.
- * @return TaskExecutionRunnable
- */
- List<ITaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName);
-
- /**
- * Check whether the taskNode is ready to run.
- *
- * @param taskName taskNodeName
- * @return true if the taskNode is ready to run.
- */
- boolean isTaskAbleToBeTriggered(String taskName);
-
- void storeTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnable.java
index 1c6e75ba1e..fd80892871 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnable.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnable.java
@@ -17,15 +17,15 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-import org.apache.dolphinscheduler.workflow.engine.engine.IDAGEngine;
-
/**
* The IWorkflowExecuteRunnable represent a running workflow instance, it is responsible for operate the workflow instance. e.g. start, kill, pause.
*/
public interface IWorkflowExecutionRunnable extends IEventfulExecutionRunnable {
+ IWorkflowExecutionRunnableIdentify getIdentity();
+
/**
- * Start the workflow instance.
+ * Start the workflow instance, this method will trigger the start task.
*/
void start();
@@ -46,11 +46,4 @@ public interface IWorkflowExecutionRunnable extends IEventfulExecutionRunnable {
*/
IWorkflowExecutionContext getWorkflowExecutionContext();
- /**
- * Get the {@link IDAGEngine} which used to execute the dag of the workflow instance.
- *
- * @return dag engine.
- */
- IDAGEngine getDagEngine();
-
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegate.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegate.java
index 5eae17192e..850ecb36e6 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegate.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegate.java
@@ -15,5 +15,19 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.workflow;public interface IWorkflowExecutionRunnableDelegate {
+package org.apache.dolphinscheduler.workflow.engine.workflow;
+
+public interface IWorkflowExecutionRunnableDelegate {
+
+ void beforeStart();
+
+ void afterStart();
+
+ void beforePause();
+
+ void afterPause();
+
+ void beforeKill();
+
+ void afterKill();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegateFactory.java
similarity index 81%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegateFactory.java
index 6a2945244c..14c17ad8b2 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegateFactory.java
@@ -17,8 +17,8 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface ITaskExecutionContext {
+public interface IWorkflowExecutionRunnableDelegateFactory {
- ITaskInstance getTaskInstance();
+ IWorkflowExecutionRunnableDelegate createWorkflowExecutionRunnableDelegate(IWorkflowExecutionContext workflowExecutionContext);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableIdentify.java
similarity index 92%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableIdentify.java
index 2e86662267..494de82abc 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableIdentify.java
@@ -17,9 +17,9 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface ITaskInstance {
+public interface IWorkflowExecutionRunnableIdentify {
- int getId();
+ Long getId();
String getName();
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableRepository.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableRepository.java
index 3996b02405..b2320765b6 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableRepository.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableRepository.java
@@ -23,11 +23,11 @@ public interface IWorkflowExecutionRunnableRepository {
void storeWorkflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable);
- IWorkflowExecutionRunnable getWorkflowExecutionRunnableById(Integer workflowInstanceId);
+ IWorkflowExecutionRunnable getWorkflowExecutionRunnable(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify);
Collection<IWorkflowExecutionRunnable> getActiveWorkflowExecutionRunnable();
- void removeWorkflowExecutionRunnable(Integer workflowInstanceId);
+ void removeWorkflowExecutionRunnable(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify);
void clear();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecutionRunnableRepository.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecutionRunnableRepository.java
index d28f9a4fb1..4b308ca6cb 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecutionRunnableRepository.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecutionRunnableRepository.java
@@ -26,7 +26,7 @@ public class SingletonWorkflowExecutionRunnableRepository implements IWorkflowEx
private static final IWorkflowExecutionRunnableRepository INSTANCE =
new SingletonWorkflowExecutionRunnableRepository();
- private final Map<Integer, IWorkflowExecutionRunnable> workflowExecutionRunnableMap;
+ private final Map<IWorkflowExecutionRunnableIdentify, IWorkflowExecutionRunnable> workflowExecutionRunnableMap;
private SingletonWorkflowExecutionRunnableRepository() {
this.workflowExecutionRunnableMap = new ConcurrentHashMap<>();
@@ -36,22 +36,23 @@ public class SingletonWorkflowExecutionRunnableRepository implements IWorkflowEx
return INSTANCE;
}
+ @Override
public void storeWorkflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable) {
- workflowExecutionRunnableMap.put(
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceId(),
- workflowExecutionRunnable);
+ workflowExecutionRunnableMap.put(workflowExecutionRunnable.getIdentity(), workflowExecutionRunnable);
}
- public IWorkflowExecutionRunnable getWorkflowExecutionRunnableById(Integer workflowInstanceId) {
- return workflowExecutionRunnableMap.get(workflowInstanceId);
+ @Override
+ public IWorkflowExecutionRunnable getWorkflowExecutionRunnable(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify) {
+ return workflowExecutionRunnableMap.get(workflowExecutionRunnableIdentify);
}
public Collection<IWorkflowExecutionRunnable> getActiveWorkflowExecutionRunnable() {
return workflowExecutionRunnableMap.values();
}
- public void removeWorkflowExecutionRunnable(Integer workflowInstanceId) {
- workflowExecutionRunnableMap.remove(workflowInstanceId);
+ @Override
+ public void removeWorkflowExecutionRunnable(IWorkflowExecutionRunnableIdentify workflowExecutionRunnableIdentify) {
+ workflowExecutionRunnableMap.remove(workflowExecutionRunnableIdentify);
}
@Override
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
index 380ed8b1ee..2f8b74a3f7 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionContext.java
@@ -19,14 +19,4 @@ package org.apache.dolphinscheduler.workflow.engine.workflow;
public class TaskExecutionContext implements ITaskExecutionContext {
- private final ITaskInstance taskInstance;
-
- public TaskExecutionContext(ITaskInstance taskInstance) {
- this.taskInstance = taskInstance;
- }
-
- @Override
- public ITaskInstance getTaskInstance() {
- return taskInstance;
- }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionPlan.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionPlan.java
new file mode 100644
index 0000000000..4080a80f7c
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionPlan.java
@@ -0,0 +1,117 @@
+/*
+ * 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.workflow.engine.workflow;
+
+import org.apache.dolphinscheduler.workflow.engine.dag.ITask;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+
+import java.util.List;
+import java.util.Map;
+
+public class TaskExecutionPlan implements ITaskExecutionPlan {
+
+ private ITaskIdentify taskIdentify;
+
+ private ITask task;
+
+ private IWorkflowExecutionContext workflowExecutionContext;
+
+ private ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
+
+ private Map<ITaskExecutionRunnableIdentify, ITaskExecutionRunnable> taskExecutionRunnableMap;
+
+ private ITaskExecutionRunnable activeTaskExecutionRunnable;
+
+ @Override
+ public void start() {
+ ITaskExecutionRunnable taskExecutionRunnable =
+ taskExecutionRunnableFactory.createTaskExecutionRunnable(taskIdentify, workflowExecutionContext);
+ taskExecutionRunnableMap.put(taskExecutionRunnable.getIdentify(), taskExecutionRunnable);
+ activeTaskExecutionRunnable = taskExecutionRunnable;
+ taskExecutionRunnable.start();
+ }
+
+ @Override
+ public void failoverTask(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify) {
+ ITaskExecutionRunnable taskExecutionRunnable = taskExecutionRunnableMap.get(taskExecutionRunnableIdentify);
+ // todo: check if the task can takeover
+ ITaskExecutionRunnable failoverTaskExecutionRunnable = taskExecutionRunnableFactory
+ .createFailoverTaskExecutionRunnable(taskExecutionRunnable, workflowExecutionContext);
+ taskExecutionRunnableMap.put(failoverTaskExecutionRunnable.getIdentify(), failoverTaskExecutionRunnable);
+ activeTaskExecutionRunnable = failoverTaskExecutionRunnable;
+ failoverTaskExecutionRunnable.start();
+ }
+
+ @Override
+ public void retryTask(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify) {
+ ITaskExecutionRunnable taskExecutionRunnable = taskExecutionRunnableMap.get(taskExecutionRunnableIdentify);
+ // check the retry times
+ ITaskExecutionRunnable retryTaskExecutionRunnable = taskExecutionRunnableFactory
+ .createRetryTaskExecutionRunnable(taskExecutionRunnable, workflowExecutionContext);
+ taskExecutionRunnableMap.put(retryTaskExecutionRunnable.getIdentify(), retryTaskExecutionRunnable);
+ activeTaskExecutionRunnable = retryTaskExecutionRunnable;
+
+ retryTaskExecutionRunnable.start();
+ }
+
+ @Override
+ public void pauseTask(ITaskExecutionRunnableIdentify taskExecutionIdentify) {
+ ITaskExecutionRunnable taskExecutionRunnable = taskExecutionRunnableMap.get(taskExecutionIdentify);
+ taskExecutionRunnable.pause();
+ }
+
+ @Override
+ public void killTask(ITaskExecutionRunnableIdentify taskExecutionIdentify) {
+ ITaskExecutionRunnable taskExecutionRunnable = taskExecutionRunnableMap.get(taskExecutionIdentify);
+ taskExecutionRunnable.kill();
+ }
+
+ @Override
+ public ITaskIdentify getTaskIdentify() {
+ return taskIdentify;
+ }
+
+ @Override
+ public ITaskExecutionRunnable getActiveTaskExecutionRunnable() {
+ return activeTaskExecutionRunnable;
+ }
+
+ @Override
+ public ITask getTask() {
+ return task;
+ }
+
+ @Override
+ public List<ITaskExecutionRunnable> getTaskExecutionRunnableList() {
+ return null;
+ }
+
+ @Override
+ public ITaskExecutionRunnable getTaskExecutionRunnable(ITaskExecutionRunnableIdentify taskExecutionRunnableIdentify) {
+ return taskExecutionRunnableMap.get(taskExecutionRunnableIdentify);
+ }
+
+ @Override
+ public ITaskExecutionRunnable storeTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable) {
+ if (taskExecutionRunnable == null) {
+ throw new IllegalArgumentException("taskExecutionRunnable cannot be null");
+ }
+ return taskExecutionRunnableMap.put(taskExecutionRunnable.getIdentify(), taskExecutionRunnable);
+ }
+
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java
index 322cd8ee8d..2f10ad759d 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnable.java
@@ -17,32 +17,50 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
+
public class TaskExecutionRunnable implements ITaskExecutionRunnable {
- public final ITaskExecutionContext taskExecutionContext;
+ private final ITaskExecutionContext taskExecutionContext;
+
+ private final ITaskExecutionRunnableDelegate taskExecutionRunnableDelegate;
- public TaskExecutionRunnable(ITaskExecutionContext taskExecutionContext) {
+ public TaskExecutionRunnable(ITaskExecutionContext taskExecutionContext,
+ ITaskExecutionRunnableDelegate taskExecutionRunnableDelegate) {
this.taskExecutionContext = taskExecutionContext;
+ this.taskExecutionRunnableDelegate = taskExecutionRunnableDelegate;
}
@Override
- public void dispatch() {
+ public void start() {
+ taskExecutionRunnableDelegate.beforeStart();
+
+ taskExecutionRunnableDelegate.afterStart();
}
@Override
- public void run() {
+ public void pause() {
+ taskExecutionRunnableDelegate.beforePause();
+ taskExecutionRunnableDelegate.afterPause();
}
@Override
public void kill() {
+ taskExecutionRunnableDelegate.beforeKill();
+ taskExecutionRunnableDelegate.afterKill();
}
@Override
- public void pause() {
+ public boolean isReadyToTrigger(String taskNodeName) {
+ return false;
+ }
+ @Override
+ public ITaskExecutionRunnableIdentify getIdentify() {
+ return taskExecutionContext.getIdentify();
}
@Override
@@ -51,7 +69,7 @@ public class TaskExecutionRunnable implements ITaskExecutionRunnable {
}
@Override
- public boolean isReadyToTrigger(String taskNodeName) {
- return false;
+ public IEventRepository getEventRepository() {
+ return taskExecutionContext.getEventRepository();
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
index 9b55c91639..f9c7028103 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
@@ -17,20 +17,32 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
+
public class TaskExecutionRunnableFactory implements ITaskExecutionRunnableFactory {
private final ITaskExecutionContextFactory taskExecutionContextFactory;
+ private ITaskExecutionRunnableDelegateFactory taskExecutionRunnableDelegateFactory =
+ DefaultTaskExecutionRunnableDelegateFactory.getInstance();
+
public TaskExecutionRunnableFactory(ITaskExecutionContextFactory taskExecutionContextFactory) {
this.taskExecutionContextFactory = taskExecutionContextFactory;
}
+ public TaskExecutionRunnableFactory withTaskExecutionRunnableDelegateFactory(ITaskExecutionRunnableDelegateFactory taskExecutionRunnableDelegateFactory) {
+ this.taskExecutionRunnableDelegateFactory = taskExecutionRunnableDelegateFactory;
+ return this;
+ }
+
@Override
- public ITaskExecutionRunnable createTaskExecutionRunnable(String taskName,
+ public ITaskExecutionRunnable createTaskExecutionRunnable(ITaskIdentify taskIdentify,
IWorkflowExecutionContext workflowExecutionContext) {
ITaskExecutionContext taskExecutionContext =
- taskExecutionContextFactory.createTaskExecutionContext(taskName, workflowExecutionContext);
- return new TaskExecutionRunnable(taskExecutionContext);
+ taskExecutionContextFactory.createTaskExecutionContext(taskIdentify, workflowExecutionContext);
+ ITaskExecutionRunnableDelegate taskExecutionRunnableDelegate = taskExecutionRunnableDelegateFactory
+ .createTaskExecutionRunnable(taskIdentify, workflowExecutionContext);
+ return new TaskExecutionRunnable(taskExecutionContext, taskExecutionRunnableDelegate);
}
@Override
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableIdentify.java
similarity index 60%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableIdentify.java
index 5280e86c08..8a5fbf44b2 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableIdentify.java
@@ -17,22 +17,37 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-import lombok.Getter;
+import org.apache.dolphinscheduler.workflow.engine.dag.TaskIdentify;
-@Getter
-public class WorkflowInstance implements IWorkflowInstance {
+import lombok.EqualsAndHashCode;
- private final int id;
+@EqualsAndHashCode
+public class TaskExecutionRunnableIdentify implements ITaskExecutionRunnableIdentify {
+
+ private final Long id;
private final String name;
- public WorkflowInstance(int id, String name) {
+ private final TaskIdentify taskIdentify;
+
+ public TaskExecutionRunnableIdentify(Long id, String name, TaskIdentify taskIdentify) {
this.id = id;
this.name = name;
+ this.taskIdentify = taskIdentify;
}
- public static WorkflowInstance of(int id, String name) {
- return new WorkflowInstance(id, name);
+ @Override
+ public Long getId() {
+ return id;
}
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public TaskIdentify getTaskIdentify() {
+ return taskIdentify;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionContext.java
index 6cca1eced1..129cd3d624 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionContext.java
@@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
+import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
import lombok.AllArgsConstructor;
@@ -30,10 +31,23 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class WorkflowExecutionContext implements IWorkflowExecutionContext {
- private IWorkflowInstance workflowInstance;
-
- private IWorkflowExecutionDAG workflowExecutionDAG;
-
- private IEventRepository eventRepository;
-
+ @Override
+ public IWorkflowExecutionRunnableIdentify getIdentify() {
+ return null;
+ }
+
+ @Override
+ public WorkflowDAG getWorkflowDAG() {
+ return null;
+ }
+
+ @Override
+ public WorkflowExecutionDAG getWorkflowExecutionDAG() {
+ return null;
+ }
+
+ @Override
+ public IEventRepository getEventRepository() {
+ return null;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
index 6bcd123b2a..dd3c828e7f 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
@@ -17,93 +17,114 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-import org.apache.dolphinscheduler.workflow.engine.dag.Node;
-import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
+import org.apache.dolphinscheduler.workflow.engine.dag.DAG;
+import org.apache.dolphinscheduler.workflow.engine.dag.ITaskIdentify;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
+public class WorkflowExecutionDAG implements DAG<ITaskExecutionPlan, ITaskIdentify> {
-/**
- * The WorkflowExecutionDAG represent a running workflow instance DAG.
- */
-@Slf4j
-public class WorkflowExecutionDAG implements IWorkflowExecutionDAG {
-
- private final ITaskExecutionRunnableRepository taskExecutionRunnableRepository;
+ private final Map<ITaskIdentify, ITaskExecutionPlan> taskExecutionPlanMap;
- private final WorkflowDAG workflowDAG;
+ private final Map<ITaskIdentify, List<ITaskIdentify>> outdegreeMap;
- @Getter
- private final List<String> startNodeNames;
+ private final Map<ITaskIdentify, List<ITaskIdentify>> inDegredMap;
- public WorkflowExecutionDAG(ITaskExecutionRunnableRepository taskExecutionRunnableRepository,
- WorkflowDAG workflowDAG) {
- this(taskExecutionRunnableRepository, workflowDAG, Collections.emptyList());
- }
+ public WorkflowExecutionDAG(List<ITaskExecutionPlan> tasks,
+ List<ITaskExecutionPlanChain> taskChains) {
+ this.taskExecutionPlanMap = new HashMap<>();
+ this.outdegreeMap = new HashMap<>();
+ this.inDegredMap = new HashMap<>();
- public WorkflowExecutionDAG(ITaskExecutionRunnableRepository taskExecutionRunnableRepository,
- WorkflowDAG workflowDAG,
- List<String> startNodeNames) {
- this.taskExecutionRunnableRepository = taskExecutionRunnableRepository;
- this.workflowDAG = workflowDAG;
- this.startNodeNames = startNodeNames;
+ for (ITaskExecutionPlan task : tasks) {
+ ITaskIdentify identify = task.getTaskIdentify();
+ if (taskExecutionPlanMap.containsKey(identify)) {
+ throw new IllegalArgumentException("Duplicate task identify: " + identify);
+ }
+ taskExecutionPlanMap.put(identify, task);
+ }
+ for (ITaskExecutionPlanChain taskChain : taskChains) {
+ ITaskExecutionPlan from = taskChain.getFrom();
+ ITaskExecutionPlan to = taskChain.getTo();
+ if (from == null) {
+ continue;
+ }
+ if (to == null) {
+ continue;
+ }
+ ITaskIdentify fromIdentify = from.getTaskIdentify();
+ ITaskIdentify toIdentify = to.getTaskIdentify();
+ List<ITaskIdentify> outDegrees =
+ outdegreeMap.computeIfAbsent(fromIdentify, k -> new ArrayList<>());
+ if (outDegrees.contains(toIdentify)) {
+ throw new IllegalArgumentException("Duplicate task chain: " + fromIdentify + " -> " + toIdentify);
+ }
+ outDegrees.add(toIdentify);
+ List<ITaskIdentify> inDegrees =
+ inDegredMap.computeIfAbsent(toIdentify, k -> new ArrayList<>());
+ if (inDegrees.contains(fromIdentify)) {
+ throw new IllegalArgumentException("Duplicate task chain: " + fromIdentify + " -> " + toIdentify);
+ }
+ inDegrees.add(fromIdentify);
+ }
}
@Override
- public ITaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId) {
- return taskExecutionRunnableRepository.getTaskExecutionRunnableById(taskInstanceId);
+ public List<ITaskExecutionPlan> getDirectPostNodes(ITaskExecutionPlan taskExecutionPlan) {
+ if (taskExecutionPlan == null) {
+ return getDirectPostNodesByIdentify(null);
+ }
+ return getDirectPostNodesByIdentify(taskExecutionPlan.getTaskIdentify());
}
@Override
- public ITaskExecutionRunnable getTaskExecutionRunnableByName(String taskName) {
- return taskExecutionRunnableRepository.getTaskExecutionRunnableByName(taskName);
+ public List<ITaskExecutionPlan> getDirectPostNodesByIdentify(ITaskIdentify taskIdentify) {
+ if (taskIdentify == null) {
+ return taskExecutionPlanMap.values()
+ .stream()
+ .filter(task -> !inDegredMap.containsKey(task.getTaskIdentify()))
+ .collect(Collectors.toList());
+ }
+ return inDegredMap.getOrDefault(taskIdentify, Collections.emptyList())
+ .stream()
+ .map(taskExecutionPlanMap::get)
+ .collect(Collectors.toList());
}
@Override
- public List<ITaskExecutionRunnable> getActiveTaskExecutionRunnable() {
- return new ArrayList<>(taskExecutionRunnableRepository.getActiveTaskExecutionRunnable());
+ public List<ITaskExecutionPlan> getDirectPreNodes(ITaskExecutionPlan iTaskExecutionPlan) {
+ if (iTaskExecutionPlan == null) {
+ return getDirectPreNodesByIdentify(null);
+ }
+ return getDirectPreNodesByIdentify(iTaskExecutionPlan.getTaskIdentify());
}
@Override
- public List<ITaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName) {
- return getDirectPreNodeNames(taskName)
+ public List<ITaskExecutionPlan> getDirectPreNodesByIdentify(ITaskIdentify taskIdentify) {
+ if (taskIdentify == null) {
+ return taskExecutionPlanMap.values()
+ .stream()
+ .filter(task -> !outdegreeMap.containsKey(task.getTaskIdentify()))
+ .collect(Collectors.toList());
+ }
+ return outdegreeMap.getOrDefault(taskIdentify, Collections.emptyList())
.stream()
- .map(taskExecutionRunnableRepository::getTaskExecutionRunnableByName)
+ .map(taskExecutionPlanMap::get)
.collect(Collectors.toList());
}
- @Override
- public boolean isTaskAbleToBeTriggered(String taskNodeName) {
- // todo: Check whether the workflow instance is finished or ready to finish.
- List<Node> directPreNodes = getDirectPreNodes(taskNodeName);
- if (log.isDebugEnabled()) {
- log.debug("Begin to check whether the task {} is able to be triggered.", taskNodeName);
- log.debug("Task {} directly dependent on the task: {}.", taskNodeName,
- directPreNodes.stream().map(Node::getNodeName).collect(Collectors.toList()));
- }
- for (Node directPreNode : directPreNodes) {
- if (directPreNode.isSkip()) {
- log.debug("The task {} is skipped.", directPreNode.getNodeName());
- continue;
- }
- ITaskExecutionRunnable taskExecutionRunnable = getTaskExecutionRunnableByName(directPreNode.getNodeName());
- if (taskExecutionRunnable == null || taskExecutionRunnable.isReadyToTrigger(taskNodeName)) {
- log.debug("The task {} is not finished or not able to access to the task {}.",
- directPreNode.getNodeName(), taskNodeName);
- }
- }
- return true;
+ public List<ITaskExecutionPlan> getActiveTaskExecutionPlan() {
+ return null;
}
@Override
- public void storeTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable) {
- taskExecutionRunnableRepository.storeTaskExecutionRunnable(taskExecutionRunnable);
+ public ITaskExecutionPlan getDAGNode(ITaskIdentify taskIdentify) {
+ return taskExecutionPlanMap.get(taskIdentify);
}
-
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAGFactory.java
similarity index 85%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAGFactory.java
index 2e86662267..9768ba8607 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/ITaskInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAGFactory.java
@@ -17,10 +17,10 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface ITaskInstance {
+public class WorkflowExecutionDAGFactory {
- int getId();
-
- String getName();
+ public WorkflowExecutionDAG createDAG() {
+ return new WorkflowExecutionDAG(null, null);
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
index cf609b1f15..a3cfd07375 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
@@ -20,10 +20,6 @@ package org.apache.dolphinscheduler.workflow.engine.workflow;
import org.apache.dolphinscheduler.workflow.engine.engine.IDAGEngine;
import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
-import org.apache.commons.collections4.CollectionUtils;
-
-import java.util.List;
-
import lombok.Getter;
@Getter
@@ -33,30 +29,58 @@ public class WorkflowExecutionRunnable implements IWorkflowExecutionRunnable {
private final IDAGEngine dagEngine;
- private volatile boolean eventFiring = false;
+ private final IWorkflowExecutionRunnableDelegate workflowExecutionRunnableDelegate;
- public WorkflowExecutionRunnable(IWorkflowExecutionContext workflowExecutionContext, IDAGEngine dagEngine) {
+ private WorkflowExecutionRunnableStatus workflowExecutionRunnableStatus;
+
+ public WorkflowExecutionRunnable(IWorkflowExecutionContext workflowExecutionContext,
+ IDAGEngine dagEngine,
+ IWorkflowExecutionRunnableDelegate workflowExecutionRunnableDelegate) {
this.workflowExecutionContext = workflowExecutionContext;
this.dagEngine = dagEngine;
+ this.workflowExecutionRunnableDelegate = workflowExecutionRunnableDelegate;
+ this.workflowExecutionRunnableStatus = WorkflowExecutionRunnableStatus.CREATED;
+ }
+
+ @Override
+ public IWorkflowExecutionRunnableIdentify getIdentity() {
+ return workflowExecutionContext.getIdentify();
}
public void start() {
- List<String> workflowStartNodeNames = workflowExecutionContext.getWorkflowExecutionDAG().getStartNodeNames();
- if (CollectionUtils.isEmpty(workflowStartNodeNames)) {
- dagEngine.triggerNextTasks(null);
- } else {
- workflowStartNodeNames.forEach(dagEngine::triggerTask);
+ if (workflowExecutionRunnableStatus != WorkflowExecutionRunnableStatus.CREATED) {
+ throw new UnsupportedOperationException("The current status is not CREATED, cannot start.");
}
+ workflowExecutionRunnableDelegate.beforeStart();
+ // Set the current status to RUNNING
+ workflowExecutionRunnableStatus = WorkflowExecutionRunnableStatus.RUNNING;
+ dagEngine.start();
+ workflowExecutionRunnableDelegate.afterStart();
}
@Override
public void pause() {
- dagEngine.pauseAllTask();
+ if (workflowExecutionRunnableStatus != WorkflowExecutionRunnableStatus.RUNNING) {
+ throw new UnsupportedOperationException("The current status is not RUNNING, cannot pause.");
+ }
+ workflowExecutionRunnableDelegate.beforePause();
+ // Set the current status to PAUSING
+ workflowExecutionRunnableStatus = WorkflowExecutionRunnableStatus.PAUSING;
+ dagEngine.pause();
+ workflowExecutionRunnableDelegate.afterPause();
}
@Override
public void kill() {
- dagEngine.killAllTask();
+ if (workflowExecutionRunnableStatus != WorkflowExecutionRunnableStatus.RUNNING
+ && workflowExecutionRunnableStatus != WorkflowExecutionRunnableStatus.PAUSING) {
+ throw new UnsupportedOperationException("The current status is not RUNNING, cannot kill.");
+ }
+ workflowExecutionRunnableDelegate.beforeKill();
+ // Set the current status to KILLING
+ workflowExecutionRunnableStatus = WorkflowExecutionRunnableStatus.KILLING;
+ dagEngine.kill();
+ workflowExecutionRunnableDelegate.afterKill();
}
@Override
@@ -64,13 +88,4 @@ public class WorkflowExecutionRunnable implements IWorkflowExecutionRunnable {
return workflowExecutionContext.getEventRepository();
}
- @Override
- public boolean isEventFiring() {
- return eventFiring;
- }
-
- @Override
- public void setEventFiring(boolean eventFiring) {
- this.eventFiring = eventFiring;
- }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableFactory.java
index ebfb3510db..d24c0308c8 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableFactory.java
@@ -24,13 +24,23 @@ public class WorkflowExecutionRunnableFactory implements IWorkflowExecutionRunna
private final IDAGEngineFactory dagEngineFactory;
+ private IWorkflowExecutionRunnableDelegateFactory workflowExecutionRunnableDelegateFactory =
+ DefaultWorkflowExecutionRunnableDelegateFactory.getInstance();
+
public WorkflowExecutionRunnableFactory(IDAGEngineFactory dagEngineFactory) {
this.dagEngineFactory = dagEngineFactory;
}
+ public WorkflowExecutionRunnableFactory withWorkflowExecutionRunnableDelegateFactory(IWorkflowExecutionRunnableDelegateFactory workflowExecutionRunnableDelegateFactory) {
+ this.workflowExecutionRunnableDelegateFactory = workflowExecutionRunnableDelegateFactory;
+ return this;
+ }
+
@Override
public WorkflowExecutionRunnable createWorkflowExecutionRunnable(IWorkflowExecutionContext workflowExecutionContext) {
IDAGEngine dagEngine = dagEngineFactory.createDAGEngine(workflowExecutionContext);
- return new WorkflowExecutionRunnable(workflowExecutionContext, dagEngine);
+ IWorkflowExecutionRunnableDelegate workflowExecutionRunnableDelegate = workflowExecutionRunnableDelegateFactory
+ .createWorkflowExecutionRunnableDelegate(workflowExecutionContext);
+ return new WorkflowExecutionRunnable(workflowExecutionContext, dagEngine, workflowExecutionRunnableDelegate);
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableStatus.java
similarity index 84%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableStatus.java
index 49944d248a..4d7fa4d85f 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowInstance.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnableStatus.java
@@ -17,10 +17,16 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-public interface IWorkflowInstance {
+public enum WorkflowExecutionRunnableStatus {
- int getId();
-
- String getName();
+ CREATED,
+ RUNNING,
+ PAUSING,
+ PAUSED,
+ KILLING,
+ KILLED,
+ FAILED,
+ SUCCEEDED,
+ ;
}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
index 40ac09007c..3658a174ea 100644
--- a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
@@ -26,12 +26,12 @@ public class SingletonWorkflowExecuteRunnableRepositoryAssertions {
public static void existWorkflowExecutionRunnable(Integer workflowInstanceId) {
assertNotNull(SingletonWorkflowExecutionRunnableRepository.getInstance()
- .getWorkflowExecutionRunnableById(workflowInstanceId));
+ .getWorkflowExecutionRunnable(workflowInstanceId));
}
public static void notExistWorkflowExecutionRunnable(Integer workflowInstanceId) {
assertNull(SingletonWorkflowExecutionRunnableRepository.getInstance()
- .getWorkflowExecutionRunnableById(workflowInstanceId));
+ .getWorkflowExecutionRunnable(workflowInstanceId));
}
}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
index 482299227f..70f1aadf27 100644
--- a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
@@ -70,7 +70,7 @@ class WorkflowEngineTest {
void killWorkflow_WorkflowNotExist() {
WorkflowExecuteRunnableNotFoundException exception =
assertThrows(WorkflowExecuteRunnableNotFoundException.class,
- () -> workflowEngine.killWorkflow(1));
+ () -> workflowEngine.killWorkflow(1L));
assertEquals("WorkflowExecuteRunnable not found: [id=1]", exception.getMessage());
}
@@ -78,8 +78,8 @@ class WorkflowEngineTest {
void killWorkflow_WorkflowExist() {
IWorkflowExecutionRunnable mockWorkflowExecuteRunnable =
MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
- Integer workflowInstanceId =
- mockWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ Long workflowInstanceId =
+ mockWorkflowExecuteRunnable.getWorkflowExecutionContext().getIdentify().getId();
SingletonWorkflowExecutionRunnableRepository.getInstance()
.storeWorkflowExecutionRunnable(mockWorkflowExecuteRunnable);
@@ -90,15 +90,15 @@ class WorkflowEngineTest {
@Test
void finalizeWorkflow_WorkflowNotExist() {
- workflowEngine.finalizeWorkflow(-1);
+ workflowEngine.finalizeWorkflow(-1L);
}
@Test
void finalizeWorkflow_WorkflowExist() {
IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
- Integer workflowInstanceId =
- emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
+ Long workflowInstanceId =
+ emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getIdentify().getId();
SingletonWorkflowExecutionRunnableRepository.getInstance()
.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
SingletonWorkflowExecuteRunnableRepositoryAssertions.existWorkflowExecutionRunnable(workflowInstanceId);
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventTest.java
index 8356fbb1ac..d5952d4a09 100644
--- a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventTest.java
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventTest.java
@@ -10,21 +10,21 @@ class WorkflowOperationEventTest {
void triggerEvent() {
WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.triggerEvent(1);
assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
- assertEquals(WorkflowOperationType.TRIGGER, workflowOperationEvent.getWorkflowOperationType());
+ assertEquals(WorkflowOperationEventType.TRIGGER, workflowOperationEvent.getWorkflowOperationType());
}
@Test
void pauseEvent() {
WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.pauseEvent(1);
assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
- assertEquals(WorkflowOperationType.PAUSE, workflowOperationEvent.getWorkflowOperationType());
+ assertEquals(WorkflowOperationEventType.PAUSE, workflowOperationEvent.getWorkflowOperationType());
}
@Test
void killEvent() {
WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.killEvent(1);
assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
- assertEquals(WorkflowOperationType.KILL, workflowOperationEvent.getWorkflowOperationType());
+ assertEquals(WorkflowOperationEventType.KILL, workflowOperationEvent.getWorkflowOperationType());
}
}
(dolphinscheduler) 02/04: Remove dag package in master
Posted by we...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev_wenjun_refactorMaster
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
commit bd82aecbd13692e76a64950721e91a97c22fcb34
Author: Wenjun Ruan <we...@apache.org>
AuthorDate: Sat Mar 23 12:46:18 2024 +0800
Remove dag package in master
---
.../server/master/dag/BasicDAG.java | 71 ------
.../dolphinscheduler/server/master/dag/DAG.java | 146 -----------
.../server/master/dag/DAGEdge.java | 51 ----
.../server/master/dag/DAGEngine.java | 148 -----------
.../server/master/dag/DAGEngineFactory.java | 32 ---
.../server/master/dag/DAGNode.java | 92 -------
.../server/master/dag/IDAGEngine.java | 70 -----
.../server/master/dag/IDAGEngineFactory.java | 24 --
.../server/master/dag/IDAGNodeAction.java | 35 ---
.../server/master/dag/IEventRepositoryFactory.java | 26 --
.../master/dag/IEventfulExecutionRunnable.java | 34 ---
.../master/dag/ITaskExecutionContextFactory.java | 24 --
.../server/master/dag/ITaskExecutionRunnable.java | 59 -----
.../master/dag/ITaskExecutionRunnableFactory.java | 24 --
.../dag/ITaskExecutionRunnableRepository.java | 33 ---
.../ITaskExecutionRunnableRepositoryFactory.java | 24 --
.../server/master/dag/IWorkflowDAG.java | 25 --
.../server/master/dag/IWorkflowDAGFactory.java | 35 ---
.../server/master/dag/IWorkflowEngine.java | 57 -----
.../master/dag/IWorkflowExecutionContext.java | 46 ----
.../server/master/dag/IWorkflowExecutionDAG.java | 74 ------
.../master/dag/IWorkflowExecutionDAGFactory.java | 23 --
.../master/dag/IWorkflowExecutionRunnable.java | 54 ----
.../master/dag/MemoryEventRepositoryFactory.java | 35 ---
.../server/master/dag/TaskExecutionContext.java | 35 ---
.../server/master/dag/TaskExecutionRunnable.java | 56 ----
.../dag/TaskExecutionRunnableRepository.java | 68 -----
.../TaskExecutionRunnableRepositoryFactory.java | 32 ---
.../server/master/dag/TaskExecutionValve.java | 27 --
.../server/master/dag/TaskIdentify.java | 22 --
.../server/master/dag/WorkflowDAG.java | 27 --
.../server/master/dag/WorkflowDAGBuilder.java | 125 ---------
.../server/master/dag/WorkflowDAGFactory.java | 65 -----
.../server/master/dag/WorkflowEngine.java | 82 ------
.../dag/WorkflowExecuteRunnableRepository.java | 52 ----
.../master/dag/WorkflowExecutionContext.java | 47 ----
.../dag/WorkflowExecutionContextFactory.java | 31 ---
.../server/master/dag/WorkflowExecutionDAG.java | 116 ---------
.../master/dag/WorkflowExecutionDAGFactory.java | 60 -----
.../master/dag/WorkflowExecutionRunnable.java | 64 -----
.../dag/WorkflowExecutionRunnableFactory.java | 40 ---
.../server/master/dag/WorkflowIdentify.java | 35 ---
.../server/master/events/EventEngine.java | 111 --------
.../server/master/events/EventFirer.java | 95 -------
.../server/master/events/EventOperatorManager.java | 36 ---
.../server/master/events/IAsyncEvent.java | 24 --
.../server/master/events/IEvent.java | 22 --
.../server/master/events/IEventFirer.java | 35 ---
.../server/master/events/IEventOperator.java | 32 ---
.../master/events/IEventOperatorManager.java | 33 ---
.../server/master/events/IEventRepository.java | 37 ---
.../server/master/events/ISyncEvent.java | 21 --
.../server/master/events/ITaskEvent.java | 26 --
.../server/master/events/ITaskEventOperator.java | 22 --
.../server/master/events/IWorkflowEvent.java | 29 ---
.../master/events/IWorkflowEventOperator.java | 23 --
.../master/events/MemoryEventRepository.java | 60 -----
.../master/events/TaskLogSendToRemoteEvent.java | 36 ---
.../events/TaskLogSendToRemoteEventOperator.java | 38 ---
.../server/master/events/TaskOperationEvent.java | 46 ----
.../master/events/TaskOperationEventOperator.java | 47 ----
.../server/master/events/TaskOperationType.java | 29 ---
.../server/master/events/TaskSuccessEvent.java | 33 ---
.../master/events/TaskSuccessEventOperator.java | 47 ----
.../server/master/events/WorkflowFailedEvent.java | 35 ---
.../master/events/WorkflowFailedEventOperator.java | 57 -----
.../master/events/WorkflowFinalizeEvent.java | 32 ---
.../events/WorkflowFinalizeEventOperator.java | 42 ---
.../server/master/events/WorkflowFinishEvent.java | 37 ---
.../master/events/WorkflowOperationEvent.java | 51 ----
.../events/WorkflowOperationEventOperator.java | 87 -------
.../server/master/events/WorkflowTimeoutEvent.java | 33 ---
.../events/WorkflowTimeoutEventOperator.java | 61 -----
.../events/WorkflowTriggerNextTaskEvent.java | 38 ---
.../WorkflowTriggerNextTaskEventOperator.java | 44 ----
.../master/events/WorkflowTriggeredEvent.java | 33 ---
.../events/WorkflowTriggeredEventOperator.java | 63 -----
.../server/master/dag/DAGNodeTest.java | 121 ---------
.../dag/MockWorkflowExecutionContextFactory.java | 88 -------
.../dag/MockWorkflowExecutionRunnableFactory.java | 31 ---
.../server/master/dag/WorkflowDAGAssertion.java | 171 -------------
.../server/master/dag/WorkflowDAGBuilderTest.java | 282 ---------------------
.../server/master/dag/WorkflowEngineTest.java | 114 ---------
.../dag/WorkflowExecutionRunnableAssertions.java | 48 ----
...kflowExecutionRunnableRepositoryAssertions.java | 43 ----
.../master/dag/WorkflowExecutionRunnableTest.java | 51 ----
.../master/events/WorkflowOperationEventTest.java | 46 ----
.../engine/{event => engine}/EventEngine.java | 66 +++--
.../workflow/engine/engine/EventEngineFactory.java | 72 ++++++
.../engine/{event => engine}/EventFirer.java | 16 +-
.../workflow/engine/engine/IEventAcceptor.java | 8 +-
.../workflow/engine/engine/IEventDispatcher.java | 8 +-
.../workflow/engine/engine/IEventEngine.java | 18 +-
.../engine/engine/IEventEngineFactory.java | 6 +-
.../engine/{event => engine}/IEventFirer.java | 13 +-
.../workflow/engine/engine/IWorkflowEngine.java | 13 +-
.../workflow/engine/engine/WorkflowEngine.java | 21 +-
.../engine/engine/WorkflowEngineFactory.java | 30 ++-
.../engine/event/EventOperatorManager.java | 29 ++-
.../workflow/engine/event/IEvent.java | 2 +
.../engine/event/IEventOperatorManager.java | 2 +
.../workflow/engine/event/TaskOperationEvent.java | 4 +
.../workflow/engine/event/WorkflowFailedEvent.java | 4 +
.../engine/event/WorkflowFinalizeEvent.java | 5 +
.../event/WorkflowFinalizeEventOperator.java | 6 +-
.../workflow/engine/event/WorkflowFinishEvent.java | 4 +
.../engine/event/WorkflowOperationEvent.java | 4 +
.../event/WorkflowOperationEventOperator.java | 6 +-
.../workflow/IEventfulExecutionRunnable.java | 4 +
...a => IWorkflowExecutionRunnableRepository.java} | 2 +-
...gletonWorkflowExecutionRunnableRepository.java} | 9 +-
.../workflow/TaskExecutionRunnableFactory.java | 14 +-
.../engine/workflow/WorkflowExecutionDAG.java | 7 +-
.../engine/workflow/WorkflowExecutionRunnable.java | 12 +
...orkflowExecuteRunnableRepositoryAssertions.java | 6 +-
.../workflow/engine/engine/WorkflowEngineTest.java | 19 +-
116 files changed, 321 insertions(+), 4805 deletions(-)
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/BasicDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/BasicDAG.java
deleted file mode 100644
index 26037eec17..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/BasicDAG.java
+++ /dev/null
@@ -1,71 +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.server.master.dag;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import lombok.experimental.SuperBuilder;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@SuperBuilder
-public abstract class BasicDAG implements DAG {
-
- protected Map<String, DAGNode> dagNodeMap;
-
- @Override
- public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
- final String nodeName = dagNode.getNodeName();
- if (!dagNodeMap.containsKey(nodeName)) {
- return Collections.emptyList();
- }
- DAGNode node = dagNodeMap.get(nodeName);
- List<DAGNode> dagNodes = new ArrayList<>();
- for (DAGEdge edge : node.getOutDegrees()) {
- if (dagNodeMap.containsKey(edge.getToNodeName())) {
- dagNodes.add(dagNodeMap.get(edge.getToNodeName()));
- }
- }
- return dagNodes;
- }
-
- @Override
- public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
- final String nodeName = dagNode.getNodeName();
- if (!dagNodeMap.containsKey(nodeName)) {
- return Collections.emptyList();
- }
- DAGNode node = dagNodeMap.get(nodeName);
- List<DAGNode> dagNodes = new ArrayList<>();
- for (DAGEdge edge : node.getInDegrees()) {
- if (dagNodeMap.containsKey(edge.getFromNodeName())) {
- dagNodes.add(dagNodeMap.get(edge.getFromNodeName()));
- }
- }
- return dagNodes;
- }
-
- @Override
- public DAGNode getDAGNode(String nodeName) {
- return dagNodeMap.get(nodeName);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAG.java
deleted file mode 100644
index 40dee4f119..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAG.java
+++ /dev/null
@@ -1,146 +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.server.master.dag;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * The Directed Acyclic Graph class.
- * <p>
- * The DAG is a directed graph, which contains the nodes and the edges, the nodeName is the unique identifier of the node.
- * The nodes are the tasks, the edges are the dependencies between the tasks.
- * The DAG is acyclic, which means there is no cycle in the graph.
- * The DAG is a directed graph, which means the edges have direction.
- *
- */
-public interface DAG {
-
- /**
- * Get the direct post node of given dagNode, if the dagNode is null, return the nodes which doesn't have inDegrees.
- * e.g. The DAG is:
- * <pre>
- * {@code
- * 1 -> 2 -> 3
- * 4 -> 5
- * 6
- * }
- * </pre>
- * <li> The post node of 1 is 2.
- * <li> The post node of 3 is empty.
- * <li> The post node of null is 1,4,6.
- *
- * @param dagNode the node of the DAG, can be null.
- * @return post node list, sort by priority.
- */
- List<DAGNode> getDirectPostNodes(DAGNode dagNode);
-
- /**
- * Same with {@link #getDirectPostNodes(DAGNode)}.
- * <p>
- * If the dagNodeName is null, return the nodes which doesn't have inDegrees. Otherwise, return the post nodes of
- * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
- *
- * @param dagNodeName task name, can be null.
- * @return post task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- default List<DAGNode> getDirectPostNodes(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPostNodes(dagNode);
- }
-
- /**
- * Same with {@link #getDirectPostNodes(String)}. Return the post node names.
- *
- * @param dagNodeName task name, can be null.
- * @return post task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- default List<String> getDirectPostNodeNames(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPostNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
- }
-
- /**
- * Get the direct pre node of given dagNode, if the dagNode is null, return the nodes which doesn't have outDegrees.
- * e.g. The DAG is:
- * <pre>
- * {@code
- * 1 -> 2 -> 3
- * 4 -> 5
- * 6
- * }
- * </pre>
- * <li> The pre node of 1 is empty.
- * <li> The pre node of 3 is 2.
- * <li> The pre node of null is 3,5,6.
- *
- * @param dagNode the node of the DAG, can be null.
- * @return pre node list, sort by priority.
- */
- List<DAGNode> getDirectPreNodes(DAGNode dagNode);
-
- /**
- * Same with {@link #getDirectPreNodes(DAGNode)}.
- * <p>
- * If the dagNodeName is null, return the nodes which doesn't have outDegrees. Otherwise, return the pre nodes of
- * the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
- *
- * @param dagNodeName task name, can be null.
- * @return pre task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- default List<DAGNode> getDirectPreNodes(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPreNodes(dagNode);
- }
-
- /**
- * Same with {@link #getDirectPreNodes(String)}. Return the pre node names.
- *
- * @param dagNodeName task name, can be null.
- * @return pre task name list, sort by priority.
- * @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
- */
- default List<String> getDirectPreNodeNames(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPreNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
- }
-
- /**
- * Get the node of the DAG by the node name.
- *
- * @param nodeName the node name.
- * @return the node of the DAG, return null if cannot find the node.
- */
- DAGNode getDAGNode(String nodeName);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEdge.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEdge.java
deleted file mode 100644
index d3ede91fef..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEdge.java
+++ /dev/null
@@ -1,51 +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.server.master.dag;
-
-import lombok.Builder;
-import lombok.Data;
-
-/**
- * The edge of the DAG.
- * <p>
- * The edge contains the fromNodeName and the toNodeName, the fromNodeName is the node name of the from node, the toNodeName is the node name of the to node.
- * <p>
- * The formNodeName can be null, which means the edge is from the start node of the DAG.
- * The toNodeName can be null, which means the edge is to the end node of the DAG.
- * The fromNodeName and the toNodeName cannot be null at the same time.
- */
-@Data
-@Builder
-public class DAGEdge {
-
- private String fromNodeName;
- private String toNodeName;
-
- public DAGEdge(String fromNodeName, String toNodeName) {
- if (fromNodeName == null && toNodeName == null) {
- throw new IllegalArgumentException("fromNodeName and toNodeName cannot be null at the same time"
- + "fromNodeName: " + fromNodeName + ", toNodeName: " + toNodeName);
- }
- if (fromNodeName != null && fromNodeName.equals(toNodeName)) {
- throw new IllegalArgumentException("fromNodeName and toNodeName cannot be the same"
- + "fromNodeName: " + fromNodeName + ", toNodeName: " + toNodeName);
- }
- this.fromNodeName = fromNodeName;
- this.toNodeName = toNodeName;
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngine.java
deleted file mode 100644
index cf1daca1f7..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngine.java
+++ /dev/null
@@ -1,148 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.events.TaskOperationEvent;
-import org.apache.dolphinscheduler.server.master.events.TaskOperationType;
-
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-public class DAGEngine implements IDAGEngine {
-
- private final IWorkflowExecutionContext workflowExecutionContext;
-
- public DAGEngine(IWorkflowExecutionContext workflowExecutionContext) {
- this.workflowExecutionContext = workflowExecutionContext;
- }
-
- @Override
- public void triggerNextTasks(String parentTaskNodeName) {
- workflowExecutionContext.getWorkflowExecutionDAG()
- .getDirectPostNodeNames(parentTaskNodeName)
- .forEach(this::triggerTask);
- }
-
- @Override
- public void triggerTask(String taskName) {
- IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
- DAGNode dagNode = workflowExecutionDAG.getDAGNode(taskName);
- if (dagNode == null) {
- log.error("Cannot find the DAGNode for task: {}", taskName);
- return;
- }
- // Use condition check?
- if (!workflowExecutionDAG.isTaskAbleToBeTriggered(taskName)) {
- log.info("The task: {} is not able to be triggered", taskName);
- return;
- }
-
- if (dagNode.isSkip()) {
- log.info("The task: {} is skipped", taskName);
- triggerNextTasks(taskName);
- return;
- }
-
- TaskExecutionRunnable taskExecutionRunnable = workflowExecutionDAG.triggerTask(taskName);
- TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.RUN)
- .build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
- }
-
- @Override
- public void failoverTask(Integer taskInstanceId) {
- TaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
- }
- TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.FAILOVER)
- .build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
- }
-
- @Override
- public void retryTask(Integer taskInstanceId) {
- TaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
- }
- TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.RETRY)
- .build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
- }
-
- @Override
- public void pauseAllTask() {
- workflowExecutionContext.getWorkflowExecutionDAG()
- .getActiveTaskExecutionRunnable()
- .stream()
- .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
- .forEach(this::pauseTask);
- }
-
- @Override
- public void pauseTask(Integer taskInstanceId) {
- TaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
- }
- TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.PAUSE)
- .build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
- }
-
- @Override
- public void killAllTask() {
- workflowExecutionContext.getWorkflowExecutionDAG()
- .getActiveTaskExecutionRunnable()
- .stream()
- .map(taskExecutionRunnable -> taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId())
- .forEach(this::killTask);
- }
-
- @Override
- public void killTask(Integer taskInstanceId) {
- TaskExecutionRunnable taskExecutionRunnable =
- workflowExecutionContext.getWorkflowExecutionDAG().getTaskExecutionRunnableById(taskInstanceId);
- if (taskExecutionRunnable == null) {
- log.error("Cannot find the ITaskExecutionRunnable for taskInstance: {}", taskInstanceId);
- return;
- }
-
- TaskOperationEvent taskOperationEvent = TaskOperationEvent.builder()
- .taskExecutionRunnable(taskExecutionRunnable)
- .taskOperationType(TaskOperationType.KILL)
- .build();
- workflowExecutionContext.getEventRepository().storeEventToTail(taskOperationEvent);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngineFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngineFactory.java
deleted file mode 100644
index 43b1a3e5c0..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGEngineFactory.java
+++ /dev/null
@@ -1,32 +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.server.master.dag;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class DAGEngineFactory implements IDAGEngineFactory {
-
- @Override
- public IDAGEngine createDAGEngine(IWorkflowExecutionContext workflowExecutionContext) {
- return new DAGEngine(workflowExecutionContext);
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGNode.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGNode.java
deleted file mode 100644
index 95bd6c75ba..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/DAGNode.java
+++ /dev/null
@@ -1,92 +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.server.master.dag;
-
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.List;
-
-import lombok.Builder;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-
-/**
- * The node of the DAG.
- * <p>
- * The node contains the node name, the content of the node, the inDegrees and the outDegrees.
- * The inDegrees is the edge from other nodes to the current node, the outDegrees is the edge from the current
- * node to other nodes.
- */
-@Getter
-@Builder
-@NoArgsConstructor
-public class DAGNode {
-
- private String nodeName;
-
- /**
- * whether the node is skipped, default is false, which means the node is not skipped.
- * If the node is skipped, the node will not be executed.
- */
- @Builder.Default
- private boolean skip = false;
-
- private List<DAGEdge> inDegrees;
- private List<DAGEdge> outDegrees;
-
- public DAGNode(String nodeName,
- List<DAGEdge> inDegrees,
- List<DAGEdge> outDegrees) {
- this(nodeName, false, inDegrees, outDegrees);
- }
-
- public DAGNode(String nodeName,
- boolean skip,
- List<DAGEdge> inDegrees,
- List<DAGEdge> outDegrees) {
- if (StringUtils.isEmpty(nodeName)) {
- throw new IllegalArgumentException("nodeName cannot be empty");
- }
-
- if (CollectionUtils.isNotEmpty(inDegrees)) {
- inDegrees.forEach(dagEdge -> {
- if (!nodeName.equals(dagEdge.getToNodeName())) {
- throw new IllegalArgumentException(
- "The toNodeName of inDegree should be the nodeName of the node: "
- + nodeName + ", inDegree: " + dagEdge);
- }
- });
- }
-
- if (CollectionUtils.isNotEmpty(outDegrees)) {
- outDegrees.forEach(dagEdge -> {
- if (!nodeName.equals(dagEdge.getFromNodeName())) {
- throw new IllegalArgumentException(
- "The fromNodeName of outDegree should be the nodeName of the node: "
- + nodeName + ", outDegree: " + dagEdge);
- }
- });
- }
-
- this.nodeName = nodeName;
- this.inDegrees = inDegrees;
- this.outDegrees = outDegrees;
- this.skip = skip;
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngine.java
deleted file mode 100644
index 7adc2d9a1e..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngine.java
+++ /dev/null
@@ -1,70 +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.server.master.dag;
-
-/**
- * The IDAGEngine is responsible for triggering, killing, pausing, and finalizing task in {@link IWorkflowExecutionDAG}.
- * <p>All DAG operation should directly use the method in IDAGEngine, new {@link IWorkflowExecutionDAG} should be triggered by new IDAGEngine.
- */
-public interface IDAGEngine {
-
- /**
- * Trigger the tasks which are post of the given task.
- * <P> If there are no task after the given taskNode, will try to finish the WorkflowExecutionRunnable.
- * <p> If the
- *
- * @param parentTaskNodeName the parent task name
- */
- void triggerNextTasks(String parentTaskNodeName);
-
- /**
- * Trigger the given task
- *
- * @param taskName task name
- */
- void triggerTask(String taskName);
-
- /**
- * Failover the given task.
- *
- * @param taskInstanceId taskInstanceId
- */
- void failoverTask(Integer taskInstanceId);
-
- /**
- * Retry the given task.
- *
- * @param taskInstanceId taskInstanceId
- */
- void retryTask(Integer taskInstanceId);
-
- void pauseAllTask();
-
- /**
- * Pause the given task.
- */
- void pauseTask(Integer taskInstanceId);
-
- void killAllTask();
-
- /**
- * Kill the given task.
- */
- void killTask(Integer taskId);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngineFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngineFactory.java
deleted file mode 100644
index 0ae555ea8d..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGEngineFactory.java
+++ /dev/null
@@ -1,24 +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.server.master.dag;
-
-public interface IDAGEngineFactory {
-
- IDAGEngine createDAGEngine(IWorkflowExecutionContext workflowExecutionContext);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGNodeAction.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGNodeAction.java
deleted file mode 100644
index 70148bd737..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IDAGNodeAction.java
+++ /dev/null
@@ -1,35 +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.server.master.dag;
-
-/**
- * The IDAGNodeAction represent the action of a DAG node.
- */
-public interface IDAGNodeAction {
-
- void run();
-
- void kill();
-
- void pause();
-
- void success();
-
- void failure();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventRepositoryFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventRepositoryFactory.java
deleted file mode 100644
index 630d412856..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventRepositoryFactory.java
+++ /dev/null
@@ -1,26 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.events.IEventRepository;
-
-public interface IEventRepositoryFactory {
-
- IEventRepository createEventRepository();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventfulExecutionRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventfulExecutionRunnable.java
deleted file mode 100644
index 952fa23120..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IEventfulExecutionRunnable.java
+++ /dev/null
@@ -1,34 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.events.IEvent;
-import org.apache.dolphinscheduler.server.master.events.IEventRepository;
-
-public interface IEventfulExecutionRunnable {
-
- IEventRepository getEventRepository();
-
- default void storeEventToTail(IEvent event) {
- getEventRepository().storeEventToTail(event);
- }
-
- default void storeEventToHead(IEvent event) {
- getEventRepository().storeEventToHead(event);
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContextFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContextFactory.java
deleted file mode 100644
index 7c67307371..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContextFactory.java
+++ /dev/null
@@ -1,24 +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.server.master.dag;
-
-public interface ITaskExecutionContextFactory {
-
- ITaskExecutionContext createTaskExecutionContext();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnable.java
deleted file mode 100644
index dceff535c5..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnable.java
+++ /dev/null
@@ -1,59 +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.server.master.dag;
-
-/**
- * The TaskExecutionRunnable represent the running task, it is responsible for operate the task instance. e.g. dispatch, kill, pause.
- */
-public interface ITaskExecutionRunnable {
-
- /**
- * Dispatch the task instance.
- */
- void dispatch();
-
- /**
- * Run the task instance.
- */
- void run();
-
- /**
- * Kill the task instance.
- */
- void kill();
-
- /**
- * Pause the task instance.
- */
- void pause();
-
- /**
- * Get the task execution context.
- *
- * @return the task execution context
- */
- TaskExecutionContext getTaskExecutionContext();
-
- /**
- * Determine whether the current task can be accessed to the post task.
- *
- * @param taskNodeName post task name
- * @return true if the current task can be accessed to the post task.
- */
- boolean canAccessTo(String taskNodeName);
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableFactory.java
deleted file mode 100644
index d1d2cf1ae9..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableFactory.java
+++ /dev/null
@@ -1,24 +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.server.master.dag;
-
-public interface ITaskExecutionRunnableFactory {
-
- TaskExecutionRunnable createTaskExecutionRunnable(ITaskExecutionContext taskExecutionContext);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepository.java
deleted file mode 100644
index 094b752cf1..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepository.java
+++ /dev/null
@@ -1,33 +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.server.master.dag;
-
-import java.util.Collection;
-
-public interface ITaskExecutionRunnableRepository {
-
- void storeTaskExecutionRunnable(TaskExecutionRunnable taskExecutionRunnable);
-
- TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId);
-
- TaskExecutionRunnable getTaskExecutionRunnableByName(String taskInstanceName);
-
- Collection<TaskExecutionRunnable> getActiveTaskExecutionRunnable();
-
- void removeTaskExecutionRunnable(Integer taskInstanceId);
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepositoryFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepositoryFactory.java
deleted file mode 100644
index 6e237a2b06..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionRunnableRepositoryFactory.java
+++ /dev/null
@@ -1,24 +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.server.master.dag;
-
-public interface ITaskExecutionRunnableRepositoryFactory {
-
- TaskExecutionRunnableRepository createTaskExecutionRunnableRepository();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAG.java
deleted file mode 100644
index fca3010035..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAG.java
+++ /dev/null
@@ -1,25 +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.server.master.dag;
-
-/**
- * The IWorkflowDAG represent the DAG of a workflow.
- */
-public interface IWorkflowDAG extends DAG {
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAGFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAGFactory.java
deleted file mode 100644
index 00c9e237da..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowDAGFactory.java
+++ /dev/null
@@ -1,35 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-
-/**
- * The Factory used to create {@link IWorkflowDAG}
- */
-public interface IWorkflowDAGFactory {
-
- /**
- * Create the WorkflowDAG
- *
- * @param workflowInstance workflowInstance.
- * @return workflow DAG.
- */
- IWorkflowDAG createWorkflowDAG(ProcessInstance workflowInstance);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowEngine.java
deleted file mode 100644
index 0c3f38dce9..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowEngine.java
+++ /dev/null
@@ -1,57 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.exception.WorkflowExecuteRunnableNotFoundException;
-
-/**
- * The WorkflowEngine is responsible for starting, stopping, pausing, and finalizing workflows.
- */
-public interface IWorkflowEngine {
-
- /**
- * Trigger a workflow to start.
- *
- * @param workflowExecuteRunnable the workflow to start
- */
- void triggerWorkflow(IWorkflowExecutionRunnable workflowExecuteRunnable);
-
- /**
- * Pause a workflow instance.
- *
- * @param workflowInstanceId the ID of the workflow to pause
- * @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
- */
- void pauseWorkflow(Integer workflowInstanceId);
-
- /**
- * Kill a workflow instance.
- *
- * @param workflowInstanceId the ID of the workflow to stop
- * @throws WorkflowExecuteRunnableNotFoundException if the workflow is not found
- */
- void killWorkflow(Integer workflowInstanceId);
-
- /**
- * Finalize a workflow instance. Once a workflow has been finalized, then it cannot receive new operation, and will be removed from memory.
- *
- * @param workflowInstanceId the ID of the workflow to finalize
- */
- void finalizeWorkflow(Integer workflowInstanceId);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionContext.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionContext.java
deleted file mode 100644
index 53bcf3555b..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionContext.java
+++ /dev/null
@@ -1,46 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-import org.apache.dolphinscheduler.server.master.events.IEventRepository;
-
-import java.util.List;
-
-public interface IWorkflowExecutionContext {
-
- IWorkflowExecutionDAG getWorkflowExecutionDAG();
-
- ProcessInstance getWorkflowInstance();
-
- ProcessDefinition getWorkflowDefinition();
-
- List<String> getBeginNodeNames();
-
- IEventRepository getEventRepository();
-
- default int getWorkflowInstanceId() {
- return getWorkflowInstance().getId();
- }
-
- default String getWorkflowInstanceName() {
- return getWorkflowInstance().getName();
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAG.java
deleted file mode 100644
index 33e597cf2e..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAG.java
+++ /dev/null
@@ -1,74 +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.server.master.dag;
-
-import java.util.List;
-
-/**
- * The WorkflowExecutionDAG represent the running workflow DAG.
- */
-public interface IWorkflowExecutionDAG extends DAG {
-
- /**
- * Trigger the taskNode by given taskName.
- *
- * @param taskName taskNodeName
- * @return TaskExecutionRunnable
- */
- TaskExecutionRunnable triggerTask(String taskName);
-
- /**
- * Get TaskExecutionRunnable by given TaskInstanceId.
- *
- * @param taskInstanceId taskInstanceId.
- * @return TaskExecutionRunnable
- */
- TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId);
-
- /**
- * Get TaskExecutionRunnable by given taskName.
- *
- * @param taskName task name.
- * @return TaskExecutionRunnable
- */
- TaskExecutionRunnable getTaskExecutionRunnableByName(String taskName);
-
- /**
- * Get TaskExecutionRunnable which is not finished.
- *
- * @return TaskExecutionRunnable
- */
- List<TaskExecutionRunnable> getActiveTaskExecutionRunnable();
-
- /**
- * Get the direct pre TaskExecutionRunnable of the given taskName.
- *
- * @param taskName task name.
- * @return TaskExecutionRunnable
- */
- List<TaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName);
-
- /**
- * Check whether the taskNode is ready to run.
- *
- * @param taskName taskNodeName
- * @return true if the taskNode is ready to run.
- */
- boolean isTaskAbleToBeTriggered(String taskName);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAGFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAGFactory.java
deleted file mode 100644
index 429987ca1f..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionDAGFactory.java
+++ /dev/null
@@ -1,23 +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.server.master.dag;
-
-public interface IWorkflowExecutionDAGFactory {
-
- IWorkflowExecutionDAG createWorkflowExecutionDAG();
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionRunnable.java
deleted file mode 100644
index d0a641239d..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/IWorkflowExecutionRunnable.java
+++ /dev/null
@@ -1,54 +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.server.master.dag;
-
-/**
- * The IWorkflowExecuteRunnable represent a running workflow instance, it is responsible for operate the workflow instance. e.g. start, kill, pause.
- */
-public interface IWorkflowExecutionRunnable extends IEventfulExecutionRunnable {
-
- /**
- * Start the workflow instance.
- */
- void start();
-
- /**
- * Kill the workflow instance.
- */
- void kill();
-
- /**
- * Pause the workflow instance.
- */
- void pause();
-
- /**
- * Get the workflow execution context.
- *
- * @return the workflow execution context
- */
- IWorkflowExecutionContext getWorkflowExecutionContext();
-
- /**
- * Get the {@link IDAGEngine} which used to execute the dag of the workflow instance.
- *
- * @return dag engine.
- */
- IDAGEngine getDagEngine();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/MemoryEventRepositoryFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/MemoryEventRepositoryFactory.java
deleted file mode 100644
index e61351f472..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/MemoryEventRepositoryFactory.java
+++ /dev/null
@@ -1,35 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.events.IEventRepository;
-import org.apache.dolphinscheduler.server.master.events.MemoryEventRepository;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class MemoryEventRepositoryFactory implements IEventRepositoryFactory {
-
- @Override
- public IEventRepository createEventRepository() {
- return new MemoryEventRepository();
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionContext.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionContext.java
deleted file mode 100644
index bf079e861f..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionContext.java
+++ /dev/null
@@ -1,35 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.dao.entity.TaskInstance;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class TaskExecutionContext implements ITaskExecutionContext {
-
- private TaskInstance taskInstance;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnable.java
deleted file mode 100644
index 0f21592b26..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnable.java
+++ /dev/null
@@ -1,56 +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.server.master.dag;
-
-import lombok.Builder;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@Getter
-@Builder
-public class TaskExecutionRunnable implements ITaskExecutionRunnable {
-
- private TaskExecutionContext taskExecutionContext;
-
- @Override
- public void dispatch() {
- // todo: check if the operation is valid
- }
-
- @Override
- public void run() {
-
- }
-
- @Override
- public void kill() {
- // todo: check if the operation is valid
- }
-
- @Override
- public void pause() {
- // todo: check if the operation is valid
- }
-
- @Override
- public boolean canAccessTo(String postTaskNodeName) {
- return false;
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepository.java
deleted file mode 100644
index eb8799c212..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepository.java
+++ /dev/null
@@ -1,68 +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.server.master.dag;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Collectors;
-
-/**
- * Use to store the TaskExecutionRunnable of a DAG.
- */
-public class TaskExecutionRunnableRepository implements ITaskExecutionRunnableRepository {
-
- private final Map<Integer, TaskExecutionRunnable> taskExecuteRunnableMap = new ConcurrentHashMap<>();
-
- private final Map<String, TaskExecutionRunnable> taskExecuteRunnableNameMap = new ConcurrentHashMap<>();
-
- @Override
- public void storeTaskExecutionRunnable(TaskExecutionRunnable taskExecutionRunnable) {
- taskExecuteRunnableMap.put(taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId(),
- taskExecutionRunnable);
- taskExecuteRunnableNameMap.put(taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getName(),
- taskExecutionRunnable);
- }
-
- public TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId) {
- return taskExecuteRunnableMap.get(taskInstanceId);
- }
-
- @Override
- public TaskExecutionRunnable getTaskExecutionRunnableByName(String taskInstanceName) {
- return taskExecuteRunnableNameMap.get(taskInstanceName);
- }
-
- public Collection<TaskExecutionRunnable> getActiveTaskExecutionRunnable() {
- return taskExecuteRunnableMap.values()
- .stream()
- .filter(taskExecutionRunnable -> {
- return taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getState().isRunning();
- })
- .collect(Collectors.toList());
- }
-
- public void removeTaskExecutionRunnable(Integer taskInstanceId) {
- TaskExecutionRunnable taskExecutionRunnable = taskExecuteRunnableMap.remove(taskInstanceId);
- if (taskExecutionRunnable != null) {
- taskExecuteRunnableNameMap
- .remove(taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getName());
- }
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepositoryFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepositoryFactory.java
deleted file mode 100644
index 55ff26916d..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionRunnableRepositoryFactory.java
+++ /dev/null
@@ -1,32 +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.server.master.dag;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class TaskExecutionRunnableRepositoryFactory implements ITaskExecutionRunnableRepositoryFactory {
-
- public TaskExecutionRunnableRepository createTaskExecutionRunnableRepository() {
- return new TaskExecutionRunnableRepository();
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionValve.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionValve.java
deleted file mode 100644
index 2bf015992d..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskExecutionValve.java
+++ /dev/null
@@ -1,27 +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.server.master.dag;
-
-/**
- * Used to judge whether the task can be executed.
- */
-public interface TaskExecutionValve {
-
- boolean canOpen(TaskExecutionRunnable preTask, String postTask);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskIdentify.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskIdentify.java
deleted file mode 100644
index d9dd0d0b1c..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/TaskIdentify.java
+++ /dev/null
@@ -1,22 +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.server.master.dag;
-
-public class TaskIdentify {
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAG.java
deleted file mode 100644
index c48785b795..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAG.java
+++ /dev/null
@@ -1,27 +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.server.master.dag;
-
-import lombok.experimental.SuperBuilder;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@SuperBuilder
-public class WorkflowDAG extends BasicDAG implements IWorkflowDAG {
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilder.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilder.java
deleted file mode 100644
index 1906afc7fb..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilder.java
+++ /dev/null
@@ -1,125 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.common.enums.Flag;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
-import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Used to build WorkflowDAG, you need to add TaskNode first, then add TaskEdge.
- * After adding all the TaskNodes and TaskEdges, you can call the build method to get the WorkflowDAG.
- * <p>
- * Example:
- * <pre>
- * {@code
- * WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
- * .addTaskNode(taskNodeA)
- * .addTaskNode(taskNodeB)
- * .addTaskNode(taskNodeC)
- * .addTaskEdge(edgeAB)
- * .addTaskEdge(edgeBC)
- * .build();
- * }
- * </pre>
- */
-public class WorkflowDAGBuilder {
-
- private final Map<String, DAGNode> taskNameMap;
-
- private final Map<Long, DAGNode> taskCodeMap;
-
- private WorkflowDAGBuilder() {
- this.taskCodeMap = new HashMap<>();
- this.taskNameMap = new HashMap<>();
- }
-
- public static WorkflowDAGBuilder newBuilder() {
- return new WorkflowDAGBuilder();
- }
-
- public WorkflowDAGBuilder addTaskNodes(List<TaskDefinitionLog> taskDefinitionList) {
- taskDefinitionList.forEach(this::addTaskNode);
- return this;
- }
-
- public WorkflowDAGBuilder addTaskNode(TaskDefinitionLog taskDefinition) {
- String taskName = taskDefinition.getName();
- long taskCode = taskDefinition.getCode();
- if (taskCodeMap.containsKey(taskCode)) {
- throw new IllegalArgumentException("TaskNode with code " + taskCode + " already exists");
- }
- if (taskNameMap.containsKey(taskName)) {
- throw new IllegalArgumentException("TaskNode with name " + taskName + " already exists");
- }
-
- DAGNode taskNode = DAGNode.builder()
- .nodeName(taskName)
- .inDegrees(new ArrayList<>())
- .outDegrees(new ArrayList<>())
- .skip(Flag.NO.equals(taskDefinition.getFlag()))
- .build();
- taskNameMap.put(taskName, taskNode);
- taskCodeMap.put(taskCode, taskNode);
- return this;
- }
-
- public WorkflowDAGBuilder addTaskEdges(List<ProcessTaskRelationLog> processTaskRelations) {
- processTaskRelations.forEach(this::addTaskEdge);
- return this;
- }
-
- public WorkflowDAGBuilder addTaskEdge(ProcessTaskRelationLog processTaskRelation) {
- long preTaskCode = processTaskRelation.getPreTaskCode();
- long postTaskCode = processTaskRelation.getPostTaskCode();
-
- if (taskCodeMap.containsKey(preTaskCode)) {
- DAGNode fromTask = taskCodeMap.get(preTaskCode);
- if (taskCodeMap.containsKey(postTaskCode)) {
- DAGNode toTask = taskCodeMap.get(postTaskCode);
- DAGEdge edge = DAGEdge.builder()
- .fromNodeName(fromTask.getNodeName())
- .toNodeName(toTask.getNodeName())
- .build();
- if (fromTask.getOutDegrees().contains(edge)) {
- throw new IllegalArgumentException(
- "Edge from " + fromTask.getNodeName() + " to " + toTask.getNodeName() + " already exists");
- }
- fromTask.getOutDegrees().add(edge);
- if (toTask.getInDegrees().contains(edge)) {
- throw new IllegalArgumentException(
- "Edge from " + fromTask.getNodeName() + " to " + toTask.getNodeName() + " already exists");
- }
- toTask.getInDegrees().add(edge);
- }
- }
- return this;
- }
-
- public WorkflowDAG build() {
- return WorkflowDAG.builder()
- .dagNodeMap(taskNameMap)
- .build();
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGFactory.java
deleted file mode 100644
index de743c2851..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGFactory.java
+++ /dev/null
@@ -1,65 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
-import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
-import org.apache.dolphinscheduler.dao.repository.ProcessTaskRelationLogDao;
-import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao;
-
-import java.util.List;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowDAGFactory implements IWorkflowDAGFactory {
-
- @Autowired
- private TaskDefinitionLogDao taskDefinitionLogDao;
-
- @Autowired
- private ProcessTaskRelationLogDao processTaskRelationLogDao;
-
- @Override
- public IWorkflowDAG createWorkflowDAG(ProcessInstance processInstance) {
- Long workflowDefinitionCode = processInstance.getProcessDefinitionCode();
- Integer workflowDefinitionVersion = processInstance.getProcessDefinitionVersion();
- List<TaskDefinitionLog> taskDefinitions = queryTaskNodes(workflowDefinitionCode, workflowDefinitionVersion);
- List<ProcessTaskRelationLog> taskRelations = queryTaskEdges(workflowDefinitionCode, workflowDefinitionVersion);
- return WorkflowDAGBuilder.newBuilder()
- .addTaskNodes(taskDefinitions)
- .addTaskEdges(taskRelations)
- .build();
- }
-
- private List<TaskDefinitionLog> queryTaskNodes(Long workflowDefinitionCode, Integer workflowDefinitionVersion) {
- return taskDefinitionLogDao.queryByWorkflowDefinitionCodeAndVersion(workflowDefinitionCode,
- workflowDefinitionVersion);
- }
-
- private List<ProcessTaskRelationLog> queryTaskEdges(Long workflowDefinitionCode,
- Integer workflowDefinitionVersion) {
- return processTaskRelationLogDao.queryByWorkflowDefinitionCodeAndVersion(workflowDefinitionCode,
- workflowDefinitionVersion);
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngine.java
deleted file mode 100644
index 550c837ffc..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngine.java
+++ /dev/null
@@ -1,82 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.events.WorkflowOperationEvent;
-import org.apache.dolphinscheduler.server.master.exception.WorkflowExecuteRunnableNotFoundException;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowEngine implements IWorkflowEngine {
-
- private final WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- public WorkflowEngine(WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
- this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
- }
-
- @Override
- public void triggerWorkflow(IWorkflowExecutionRunnable workflowExecuteRunnable) {
- IWorkflowExecutionContext workflowExecutionContext = workflowExecuteRunnable.getWorkflowExecutionContext();
- Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
- log.info("Triggering WorkflowExecutionRunnable: {}", workflowExecutionContext.getWorkflowInstanceName());
- workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(workflowExecuteRunnable);
- workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.triggerEvent(workflowInstanceId));
- }
-
- @Override
- public void pauseWorkflow(Integer workflowInstanceId) {
- IWorkflowExecutionRunnable workflowExecuteRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
- if (workflowExecuteRunnable == null) {
- throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
- }
- log.info("Pausing WorkflowExecutionRunnable: {}",
- workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
- workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.pauseEvent(workflowInstanceId));
- }
-
- @Override
- public void killWorkflow(Integer workflowInstanceId) {
- IWorkflowExecutionRunnable workflowExecuteRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
- if (workflowExecuteRunnable == null) {
- throw new WorkflowExecuteRunnableNotFoundException(workflowInstanceId);
- }
- log.info("Killing WorkflowExecutionRunnable: {}",
- workflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
- workflowExecuteRunnable.storeEventToTail(WorkflowOperationEvent.killEvent(workflowInstanceId));
- }
-
- @Override
- public void finalizeWorkflow(Integer workflowInstanceId) {
- IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
- if (workflowExecutionRunnable == null) {
- return;
- }
- log.info("Finalizing WorkflowExecutionRunnable: {}",
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
- workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecuteRunnableRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecuteRunnableRepository.java
deleted file mode 100644
index 78beaa44e7..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecuteRunnableRepository.java
+++ /dev/null
@@ -1,52 +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.server.master.dag;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowExecuteRunnableRepository {
-
- private final Map<Integer, IWorkflowExecutionRunnable> workflowExecutionRunnableMap = new ConcurrentHashMap<>();
-
- public void storeWorkflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable) {
- workflowExecutionRunnableMap.put(
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceId(),
- workflowExecutionRunnable);
- }
-
- public IWorkflowExecutionRunnable getWorkflowExecutionRunnableById(Integer workflowInstanceId) {
- return workflowExecutionRunnableMap.get(workflowInstanceId);
- }
-
- public Collection<IWorkflowExecutionRunnable> getActiveWorkflowExecutionRunnable() {
- return workflowExecutionRunnableMap.values();
- }
-
- public void removeWorkflowExecutionRunnable(Integer workflowInstanceId) {
- workflowExecutionRunnableMap.remove(workflowInstanceId);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContext.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContext.java
deleted file mode 100644
index be9c165882..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContext.java
+++ /dev/null
@@ -1,47 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-import org.apache.dolphinscheduler.server.master.events.IEventRepository;
-
-import java.util.List;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowExecutionContext implements IWorkflowExecutionContext {
-
- private ProcessDefinition workflowDefinition;
-
- private ProcessInstance workflowInstance;
-
- private List<String> beginNodeNames;
-
- private IWorkflowExecutionDAG workflowExecutionDAG;
-
- private IEventRepository eventRepository;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContextFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContextFactory.java
deleted file mode 100644
index 69ad93b106..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionContextFactory.java
+++ /dev/null
@@ -1,31 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.dao.entity.Command;
-
-import org.springframework.stereotype.Component;
-
-@Component
-public class WorkflowExecutionContextFactory {
-
- public WorkflowExecutionContext createWorkflowExecutionContext(Command command) {
- return null;
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAG.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAG.java
deleted file mode 100644
index 86c690d44f..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAG.java
+++ /dev/null
@@ -1,116 +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.server.master.dag;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import lombok.experimental.SuperBuilder;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * The WorkflowExecutionDAG represent a running workflow instance DAG.
- */
-@Slf4j
-@SuperBuilder
-public class WorkflowExecutionDAG implements IWorkflowExecutionDAG {
-
- private final ITaskExecutionContextFactory taskExecutionContextFactory;
-
- private final ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
-
- private final TaskExecutionRunnableRepository taskExecutionRunnableRepository;
-
- private final IWorkflowDAG workflowDAG;
-
- @Override
- public TaskExecutionRunnable triggerTask(String taskName) {
- DAGNode dagNode = getDAGNode(taskName);
- if (dagNode == null) {
- throw new IllegalArgumentException("Cannot find the DAGNode for task: " + taskName);
- }
- // Create task execution context
- taskExecutionContextFactory.createTaskExecutionContext();
- TaskExecutionRunnable taskExecutionRunnable = taskExecutionRunnableFactory.createTaskExecutionRunnable(null);
- taskExecutionRunnableRepository.storeTaskExecutionRunnable(taskExecutionRunnable);
- return taskExecutionRunnable;
- }
-
- @Override
- public TaskExecutionRunnable getTaskExecutionRunnableById(Integer taskInstanceId) {
- return taskExecutionRunnableRepository.getTaskExecutionRunnableById(taskInstanceId);
- }
-
- @Override
- public TaskExecutionRunnable getTaskExecutionRunnableByName(String taskName) {
- return taskExecutionRunnableRepository.getTaskExecutionRunnableByName(taskName);
- }
-
- @Override
- public List<TaskExecutionRunnable> getActiveTaskExecutionRunnable() {
- return new ArrayList<>(taskExecutionRunnableRepository.getActiveTaskExecutionRunnable());
- }
-
- @Override
- public List<TaskExecutionRunnable> getDirectPreTaskExecutionRunnable(String taskName) {
- return getDirectPreNodeNames(taskName)
- .stream()
- .map(taskExecutionRunnableRepository::getTaskExecutionRunnableByName)
- .collect(Collectors.toList());
- }
-
- @Override
- public boolean isTaskAbleToBeTriggered(String taskNodeName) {
- // todo: Check whether the workflow instance is finished or ready to finish.
- List<DAGNode> directPreNodes = getDirectPreNodes(taskNodeName);
- if (log.isDebugEnabled()) {
- log.debug("Begin to check whether the task {} is able to be triggered.", taskNodeName);
- log.debug("Task {} directly dependent on the task: {}.", taskNodeName,
- directPreNodes.stream().map(DAGNode::getNodeName).collect(Collectors.toList()));
- }
- for (DAGNode directPreNode : directPreNodes) {
- if (directPreNode.isSkip()) {
- log.debug("The task {} is skipped.", directPreNode.getNodeName());
- continue;
- }
- TaskExecutionRunnable taskExecutionRunnable = getTaskExecutionRunnableByName(directPreNode.getNodeName());
- if (taskExecutionRunnable == null || taskExecutionRunnable.canAccessTo(taskNodeName)) {
- log.debug("The task {} is not finished or not able to access to the task {}.",
- directPreNode.getNodeName(), taskNodeName);
- }
- }
- return true;
- }
-
- @Override
- public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
- return workflowDAG.getDirectPostNodes(dagNode);
- }
-
- @Override
- public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
- return workflowDAG.getDirectPreNodes(dagNode);
- }
-
- @Override
- public DAGNode getDAGNode(String nodeName) {
- return workflowDAG.getDAGNode(nodeName);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAGFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAGFactory.java
deleted file mode 100644
index fa1e897c20..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionDAGFactory.java
+++ /dev/null
@@ -1,60 +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.server.master.dag;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowExecutionDAGFactory implements IWorkflowExecutionDAGFactory {
-
- @Autowired
- private ITaskExecutionRunnableRepositoryFactory taskExecutionRunnableRepositoryFactory;
-
- @Autowired
- private ITaskExecutionRunnableFactory taskExecutionRunnableFactory;
-
- @Autowired
- private ITaskExecutionContextFactory taskExecutionContextFactory;
-
- @Override
- public IWorkflowExecutionDAG createWorkflowExecutionDAG() {
- // todo:
- TaskExecutionRunnableRepository taskExecutionRunnableRepository =
- taskExecutionRunnableRepositoryFactory.createTaskExecutionRunnableRepository();
- loadTheHistoryTaskExecutionRunnable()
- .forEach(taskExecutionRunnableRepository::storeTaskExecutionRunnable);
-
- return WorkflowExecutionDAG.builder()
- .taskExecutionContextFactory(taskExecutionContextFactory)
- .taskExecutionRunnableFactory(taskExecutionRunnableFactory)
- .taskExecutionRunnableRepository(taskExecutionRunnableRepository)
- .workflowDAG(null)
- .build();
- }
-
- private List<TaskExecutionRunnable> loadTheHistoryTaskExecutionRunnable() {
- return new ArrayList<>();
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnable.java
deleted file mode 100644
index 1c9b4208e7..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnable.java
+++ /dev/null
@@ -1,64 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.events.IEventRepository;
-import org.apache.dolphinscheduler.server.master.events.WorkflowTriggeredEvent;
-
-import org.apache.commons.collections4.CollectionUtils;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@Getter
-@Builder
-@AllArgsConstructor
-public class WorkflowExecutionRunnable implements IWorkflowExecutionRunnable {
-
- private final IWorkflowExecutionContext workflowExecutionContext;
-
- private final IDAGEngine dagEngine;
-
- public void start() {
- if (CollectionUtils.isEmpty(workflowExecutionContext.getBeginNodeNames())) {
- dagEngine.triggerNextTasks(null);
- } else {
- workflowExecutionContext.getBeginNodeNames().forEach(dagEngine::triggerTask);
- }
- getEventRepository()
- .storeEventToTail(new WorkflowTriggeredEvent(workflowExecutionContext.getWorkflowInstance().getId()));
- }
-
- @Override
- public void pause() {
- dagEngine.pauseAllTask();
- }
-
- @Override
- public void kill() {
- dagEngine.killAllTask();
- }
-
- @Override
- public IEventRepository getEventRepository() {
- return workflowExecutionContext.getEventRepository();
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableFactory.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableFactory.java
deleted file mode 100644
index 4d3f766725..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableFactory.java
+++ /dev/null
@@ -1,40 +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.server.master.dag;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowExecutionRunnableFactory {
-
- @Autowired
- private IDAGEngineFactory dagEngineFactory;
-
- public WorkflowExecutionRunnable createWorkflowExecuteRunnable(IWorkflowExecutionContext workflowExecutionContext) {
- IDAGEngine dagEngine = dagEngineFactory.createDAGEngine(workflowExecutionContext);
- return WorkflowExecutionRunnable.builder()
- .workflowExecutionContext(workflowExecutionContext)
- .dagEngine(dagEngine)
- .build();
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowIdentify.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowIdentify.java
deleted file mode 100644
index 0b7981199a..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/WorkflowIdentify.java
+++ /dev/null
@@ -1,35 +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.server.master.dag;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowIdentify {
-
- private long workflowCode;
-
- private int workflowVersion;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventEngine.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventEngine.java
deleted file mode 100644
index f614a59caf..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventEngine.java
+++ /dev/null
@@ -1,111 +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.server.master.events;
-
-import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
-import org.apache.dolphinscheduler.common.thread.ThreadUtils;
-import org.apache.dolphinscheduler.plugin.task.api.utils.LogUtils;
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionContext;
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-
-import org.apache.commons.lang3.time.StopWatch;
-
-import java.util.Collection;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class EventEngine extends BaseDaemonThread {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Autowired
- private EventFirer eventFirer;
-
- private final Set<Integer> firingWorkflowInstanceIds = ConcurrentHashMap.newKeySet();
-
- public EventEngine() {
- super("EventEngine");
- }
-
- @Override
- public synchronized void start() {
- super.start();
- log.info(getClass().getName() + " started");
- }
-
- @Override
- public void run() {
- for (;;) {
- try {
- StopWatch stopWatch = StopWatch.createStarted();
- fireAllActiveEvents();
- stopWatch.stop();
- log.info("Fire all active events cost: {} ms", stopWatch.getTime());
- this.wait(5_000);
- } catch (Throwable throwable) {
- log.error("Fire active event error", throwable);
- ThreadUtils.sleep(3_000);
- }
- }
- }
-
- public void fireAllActiveEvents() {
- Collection<IWorkflowExecutionRunnable> workflowExecutionRunnableCollection =
- workflowExecuteRunnableRepository.getActiveWorkflowExecutionRunnable();
- for (IWorkflowExecutionRunnable workflowExecutionRunnable : workflowExecutionRunnableCollection) {
- IWorkflowExecutionContext workflowExecutionContext =
- workflowExecutionRunnable.getWorkflowExecutionContext();
- final Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
- final String workflowInstanceName = workflowExecutionContext.getWorkflowInstanceName();
- try {
- LogUtils.setWorkflowInstanceIdMDC(workflowInstanceId);
- if (firingWorkflowInstanceIds.contains(workflowInstanceId)) {
- log.debug("WorkflowExecutionRunnable: {} is already in firing", workflowInstanceName);
- return;
- }
- IEventRepository workflowEventRepository = workflowExecutionRunnable.getEventRepository();
- firingWorkflowInstanceIds.add(workflowInstanceId);
- eventFirer.fireActiveEvents(workflowEventRepository)
- .whenComplete((fireCount, ex) -> {
- firingWorkflowInstanceIds.remove(workflowInstanceId);
- if (ex != null) {
- log.error("Fire event for WorkflowExecutionRunnable: {} error", workflowInstanceName,
- ex);
- } else {
- if (fireCount > 0) {
- log.info("Fire {} events for WorkflowExecutionRunnable: {} success", fireCount,
- workflowInstanceName);
- }
- }
- });
- } finally {
- LogUtils.removeWorkflowInstanceIdMDC();
- }
- }
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventFirer.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventFirer.java
deleted file mode 100644
index fbbc683097..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventFirer.java
+++ /dev/null
@@ -1,95 +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.server.master.events;
-
-import org.apache.dolphinscheduler.common.thread.ThreadUtils;
-import org.apache.dolphinscheduler.server.master.config.MasterConfig;
-import org.apache.dolphinscheduler.server.master.utils.ExceptionUtils;
-
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ThreadPoolExecutor;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class EventFirer implements IEventFirer {
-
- private final IEventOperatorManager<IEvent> eventOperatorManager;
-
- private final ThreadPoolExecutor eventFireThreadPool;
-
- public EventFirer(IEventOperatorManager<IEvent> eventOperatorManager, MasterConfig masterConfig) {
- this.eventOperatorManager = eventOperatorManager;
- this.eventFireThreadPool =
- ThreadUtils.newDaemonFixedThreadExecutor("EventFireThreadPool", masterConfig.getExecThreads());
- }
-
- @Override
- public CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository) {
- if (eventRepository.getEventSize() == 0) {
- return CompletableFuture.completedFuture(0);
- }
- return CompletableFuture.supplyAsync(() -> {
- int fireCount = 0;
- for (;;) {
- IEvent event = eventRepository.poolEvent();
- if (event == null) {
- break;
- }
-
- if (event instanceof IAsyncEvent) {
- fireAsyncEvent(event);
- fireCount++;
- continue;
- }
- try {
- fireSyncEvent(event);
- fireCount++;
- } catch (Exception ex) {
- if (ExceptionUtils.isDatabaseConnectedFailedException(ex)) {
- // If the event is failed due to cannot connect to DB, we should retry it
- eventRepository.storeEventToHead(event);
- }
- throw ex;
- }
- }
- return fireCount;
- }, eventFireThreadPool);
- }
-
- private void fireAsyncEvent(IEvent event) {
- CompletableFuture.runAsync(() -> {
- log.info("Begin fire IAsyncEvent: {}", event);
- eventOperatorManager.getEventOperator(event).handleEvent(event);
- log.info("Success fire IAsyncEvent: {}", event);
- }, eventFireThreadPool).exceptionally(ex -> {
- log.error("Failed to fire IAsyncEvent: {}", event, ex);
- return null;
- });
- }
-
- private void fireSyncEvent(IEvent event) {
- log.info("Begin fire SyncEvent: {}", event);
- eventOperatorManager.getEventOperator(event).handleEvent(event);
- log.info("Success fire SyncEvent: {}", event);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventOperatorManager.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventOperatorManager.java
deleted file mode 100644
index 7a7b52d6c6..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/EventOperatorManager.java
+++ /dev/null
@@ -1,36 +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.server.master.events;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-/**
- * The event operator manager interface used to get {@link ITaskEventOperator}.
- */
-@Slf4j
-@Component
-public class EventOperatorManager implements IEventOperatorManager<IEvent> {
-
- @Override
- public IEventOperator<IEvent> getEventOperator(IEvent event) {
- return null;
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IAsyncEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IAsyncEvent.java
deleted file mode 100644
index 0d0395de6e..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IAsyncEvent.java
+++ /dev/null
@@ -1,24 +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.server.master.events;
-
-/**
- * Mark the event as AsyncEvent, if the event is marked as AsyncEvent, the event will be handled asynchronously and we don't .
- */
-public interface IAsyncEvent {
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEvent.java
deleted file mode 100644
index 0535bbe2c7..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEvent.java
+++ /dev/null
@@ -1,22 +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.server.master.events;
-
-public interface IEvent {
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventFirer.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventFirer.java
deleted file mode 100644
index f33db8ed6a..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventFirer.java
+++ /dev/null
@@ -1,35 +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.server.master.events;
-
-import java.util.concurrent.CompletableFuture;
-
-/**
- * The event firer interface used to fire event.
- *
- */
-public interface IEventFirer {
-
- /**
- * Fire all active events in the event repository
- *
- * @return the count of fired success events
- */
- CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperator.java
deleted file mode 100644
index 23694a1ccb..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperator.java
+++ /dev/null
@@ -1,32 +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.server.master.events;
-
-/**
- * The event operator interface used to handle event.
- */
-public interface IEventOperator<E> {
-
- /**
- * Handle the given event
- *
- * @param event event
- */
- void handleEvent(E event);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperatorManager.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperatorManager.java
deleted file mode 100644
index 7fb2b63d8a..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventOperatorManager.java
+++ /dev/null
@@ -1,33 +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.server.master.events;
-
-/**
- * The event operator manager interface used to get event operator.
- */
-public interface IEventOperatorManager<E> {
-
- /**
- * Get the {@link IEventOperator} for the given event.
- *
- * @param event event
- * @return event operator for the given event
- */
- IEventOperator<E> getEventOperator(E event);
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventRepository.java
deleted file mode 100644
index 20e5081124..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IEventRepository.java
+++ /dev/null
@@ -1,37 +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.server.master.events;
-
-import java.util.List;
-
-/**
- * The event repository interface used to store event.
- */
-public interface IEventRepository {
-
- void storeEventToTail(IEvent event);
-
- void storeEventToHead(IEvent event);
-
- IEvent poolEvent();
-
- int getEventSize();
-
- List<IEvent> getAllEvent();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ISyncEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ISyncEvent.java
deleted file mode 100644
index 5a385cc034..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ISyncEvent.java
+++ /dev/null
@@ -1,21 +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.server.master.events;
-
-public interface ISyncEvent {
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEvent.java
deleted file mode 100644
index 5d105df288..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEvent.java
+++ /dev/null
@@ -1,26 +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.server.master.events;
-
-public interface ITaskEvent extends IEvent {
-
- Integer getWorkflowInstanceId();
-
- Integer getTaskInstanceId();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEventOperator.java
deleted file mode 100644
index 1aa1c28299..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/ITaskEventOperator.java
+++ /dev/null
@@ -1,22 +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.server.master.events;
-
-public interface ITaskEventOperator<E extends ITaskEvent> extends IEventOperator<E> {
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEvent.java
deleted file mode 100644
index 7b5ae1cd66..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEvent.java
+++ /dev/null
@@ -1,29 +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.server.master.events;
-
-public interface IWorkflowEvent extends IEvent {
-
- /**
- * The id of WorkflowInstance which the event is related to
- *
- * @return workflowInstanceId, shouldn't be null
- */
- Integer getWorkflowInstanceId();
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEventOperator.java
deleted file mode 100644
index c601cc27d3..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IWorkflowEventOperator.java
+++ /dev/null
@@ -1,23 +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.server.master.events;
-
-public interface IWorkflowEventOperator<E extends IWorkflowEvent>
- extends
- IEventOperator<E> {
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/MemoryEventRepository.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/MemoryEventRepository.java
deleted file mode 100644
index 376b2e4597..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/MemoryEventRepository.java
+++ /dev/null
@@ -1,60 +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.server.master.events;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.LinkedBlockingDeque;
-
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-public class MemoryEventRepository implements IEventRepository {
-
- protected final LinkedBlockingDeque<IEvent> eventQueue;
-
- public MemoryEventRepository() {
- this.eventQueue = new LinkedBlockingDeque<>();
- }
-
- @Override
- public void storeEventToTail(IEvent event) {
- log.info("Store event to tail: {}", event);
- eventQueue.offerLast(event);
- }
-
- @Override
- public void storeEventToHead(IEvent event) {
- eventQueue.offerFirst(event);
- }
-
- @Override
- public IEvent poolEvent() {
- return eventQueue.poll();
- }
-
- @Override
- public int getEventSize() {
- return eventQueue.size();
- }
-
- public List<IEvent> getAllEvent() {
- return new ArrayList<>(eventQueue);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEvent.java
deleted file mode 100644
index 5e42a40bd6..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEvent.java
+++ /dev/null
@@ -1,36 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class TaskLogSendToRemoteEvent implements ITaskEvent {
-
- private Integer workflowInstanceId;
- private Integer taskInstanceId;
-
- private String taskType;
- private String logPath;
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEventOperator.java
deleted file mode 100644
index c75f1fcba5..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskLogSendToRemoteEventOperator.java
+++ /dev/null
@@ -1,38 +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.server.master.events;
-
-import org.apache.dolphinscheduler.common.log.remote.RemoteLogUtils;
-import org.apache.dolphinscheduler.server.master.utils.TaskUtils;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class TaskLogSendToRemoteEventOperator implements ITaskEventOperator<TaskLogSendToRemoteEvent> {
-
- @Override
- public void handleEvent(TaskLogSendToRemoteEvent event) {
- if (RemoteLogUtils.isRemoteLoggingEnable() && TaskUtils.isMasterTask(event.getTaskType())) {
- RemoteLogUtils.sendRemoteLog(event.getLogPath());
- log.info("Master sends task log {} to remote storage asynchronously.", event.getLogPath());
- }
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEvent.java
deleted file mode 100644
index 165ea88053..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEvent.java
+++ /dev/null
@@ -1,46 +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.server.master.events;
-
-import org.apache.dolphinscheduler.server.master.dag.TaskExecutionRunnable;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class TaskOperationEvent implements ITaskEvent, ISyncEvent {
-
- private TaskExecutionRunnable taskExecutionRunnable;
-
- private TaskOperationType taskOperationType;
-
- @Override
- public Integer getWorkflowInstanceId() {
- return taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getProcessInstanceId();
- }
-
- @Override
- public Integer getTaskInstanceId() {
- return taskExecutionRunnable.getTaskExecutionContext().getTaskInstance().getId();
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEventOperator.java
deleted file mode 100644
index 355d28085b..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationEventOperator.java
+++ /dev/null
@@ -1,47 +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.server.master.events;
-
-import org.apache.dolphinscheduler.server.master.dag.TaskExecutionRunnable;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class TaskOperationEventOperator implements ITaskEventOperator<TaskOperationEvent> {
-
- @Override
- public void handleEvent(TaskOperationEvent event) {
- TaskExecutionRunnable taskExecutionRunnable = event.getTaskExecutionRunnable();
- switch (event.getTaskOperationType()) {
- case RUN:
- taskExecutionRunnable.dispatch();
- break;
- case KILL:
- taskExecutionRunnable.kill();
- break;
- case PAUSE:
- taskExecutionRunnable.pause();
- break;
- default:
- log.error("Unknown TaskOperationType for event: {}", event);
- }
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationType.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationType.java
deleted file mode 100644
index ae72a03b01..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskOperationType.java
+++ /dev/null
@@ -1,29 +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.server.master.events;
-
-public enum TaskOperationType {
-
- FAILOVER,
- RUN,
- RETRY,
- KILL,
- PAUSE,
- ;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEvent.java
deleted file mode 100644
index a84d89069a..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEvent.java
+++ /dev/null
@@ -1,33 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-public class TaskSuccessEvent implements ITaskEvent {
-
- private Integer workflowInstanceId;
-
- private Integer taskInstanceId;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEventOperator.java
deleted file mode 100644
index 8ed9c2033b..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/TaskSuccessEventOperator.java
+++ /dev/null
@@ -1,47 +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.server.master.events;
-
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class TaskSuccessEventOperator implements ITaskEventOperator<TaskSuccessEvent> {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Override
- public void handleEvent(TaskSuccessEvent event) {
- Integer workflowInstanceId = event.getWorkflowInstanceId();
- Integer taskInstanceId = event.getTaskInstanceId();
- IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
- if (workflowExecutionRunnable == null) {
- log.error("Cannot find the WorkflowExecutionRunnable, the event: {} will be dropped", event);
- return;
- }
-
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEvent.java
deleted file mode 100644
index f07067c261..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEvent.java
+++ /dev/null
@@ -1,35 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowFailedEvent implements IWorkflowEvent, ISyncEvent {
-
- private Integer workflowInstanceId;
-
- private String failedReason;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEventOperator.java
deleted file mode 100644
index b7e562b6f7..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFailedEventOperator.java
+++ /dev/null
@@ -1,57 +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.server.master.events;
-
-import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao;
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowFailedEventOperator
- implements
- IWorkflowEventOperator<WorkflowFailedEvent> {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Autowired
- private ProcessInstanceDao processInstanceDao;
-
- @Override
- public void handleEvent(WorkflowFailedEvent event) {
- Integer workflowInstanceId = event.getWorkflowInstanceId();
- IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
-
- ProcessInstance workflowInstance =
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance();
- workflowInstance.setState(WorkflowExecutionStatus.FAILURE);
- processInstanceDao.updateById(workflowInstance);
- log.info("Handle WorkflowExecutionRunnableFailedEvent success, set workflowInstance status to {}",
- workflowInstance.getState());
- workflowExecutionRunnable.storeEventToTail(new WorkflowFinalizeEvent(workflowInstanceId));
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEvent.java
deleted file mode 100644
index 454b755c42..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEvent.java
+++ /dev/null
@@ -1,32 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class WorkflowFinalizeEvent implements IWorkflowEvent, ISyncEvent {
-
- private Integer workflowInstanceId;
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEventOperator.java
deleted file mode 100644
index aeab8ae30c..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinalizeEventOperator.java
+++ /dev/null
@@ -1,42 +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.server.master.events;
-
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowFinalizeEventOperator
- implements
- IWorkflowEventOperator<WorkflowFinalizeEvent> {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Override
- public void handleEvent(WorkflowFinalizeEvent event) {
- Integer workflowInstanceId = event.getWorkflowInstanceId();
- workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinishEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinishEvent.java
deleted file mode 100644
index b58db0cc53..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowFinishEvent.java
+++ /dev/null
@@ -1,37 +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.server.master.events;
-
-import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowFinishEvent implements IWorkflowEvent, ISyncEvent {
-
- private Integer workflowInstanceId;
-
- private WorkflowExecutionStatus workflowExecutionStatus;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEvent.java
deleted file mode 100644
index 6450067f60..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEvent.java
+++ /dev/null
@@ -1,51 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-
-@Data
-@Builder
-@AllArgsConstructor
-public class WorkflowOperationEvent implements IWorkflowEvent, ISyncEvent {
-
- private Integer workflowInstanceId;
- private WorkflowOperationType workflowOperationType;
-
- public static WorkflowOperationEvent of(Integer workflowInstanceId, WorkflowOperationType workflowOperationType) {
- return WorkflowOperationEvent.builder()
- .workflowInstanceId(workflowInstanceId)
- .workflowOperationType(workflowOperationType)
- .build();
- }
-
- public static WorkflowOperationEvent triggerEvent(Integer workflowInstanceId) {
- return of(workflowInstanceId, WorkflowOperationType.TRIGGER);
- }
-
- public static WorkflowOperationEvent pauseEvent(Integer workflowInstanceId) {
- return of(workflowInstanceId, WorkflowOperationType.PAUSE);
- }
-
- public static WorkflowOperationEvent killEvent(Integer workflowInstanceId) {
- return of(workflowInstanceId, WorkflowOperationType.KILL);
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventOperator.java
deleted file mode 100644
index 2c8159f88f..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventOperator.java
+++ /dev/null
@@ -1,87 +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.server.master.events;
-
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionContext;
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-import org.apache.dolphinscheduler.server.master.utils.ExceptionUtils;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowOperationEventOperator implements IWorkflowEventOperator<WorkflowOperationEvent> {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Override
- public void handleEvent(WorkflowOperationEvent event) {
- IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
- if (workflowExecutionRunnable == null) {
- log.warn(
- "Handle workflowExecutionRunnableKillOperationEvent: {} failed: WorkflowExecutionRunnable not found",
- event);
- return;
- }
- switch (event.getWorkflowOperationType()) {
- case TRIGGER:
- triggerWorkflow(workflowExecutionRunnable);
- break;
- case PAUSE:
- pauseWorkflow(workflowExecutionRunnable);
- break;
- case KILL:
- killWorkflow(workflowExecutionRunnable);
- break;
- default:
- log.error("Unknown operationType for event: {}", event);
- }
- }
-
- private void triggerWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
- try {
- workflowExecutionRunnable.start();
- } catch (Throwable exception) {
- if (ExceptionUtils.isDatabaseConnectedFailedException(exception)) {
- throw exception;
- }
- IWorkflowExecutionContext workflowExecutionContext =
- workflowExecutionRunnable.getWorkflowExecutionContext();
- log.error("Trigger workflow: {} failed", workflowExecutionContext.getWorkflowInstanceName(), exception);
- WorkflowFailedEvent workflowExecutionRunnableFailedEvent = WorkflowFailedEvent.builder()
- .workflowInstanceId(workflowExecutionContext.getWorkflowInstanceId())
- .failedReason(exception.getMessage())
- .build();
- workflowExecutionRunnable.storeEventToTail(workflowExecutionRunnableFailedEvent);
- }
- }
-
- private void pauseWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
- workflowExecutionRunnable.pause();
- }
-
- private void killWorkflow(IWorkflowExecutionRunnable workflowExecutionRunnable) {
- workflowExecutionRunnable.kill();
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEvent.java
deleted file mode 100644
index b075d194d7..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEvent.java
+++ /dev/null
@@ -1,33 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowTimeoutEvent implements IWorkflowEvent, IAsyncEvent {
-
- private Integer workflowInstanceId;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEventOperator.java
deleted file mode 100644
index ebb43e3359..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTimeoutEventOperator.java
+++ /dev/null
@@ -1,61 +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.server.master.events;
-
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-import org.apache.dolphinscheduler.dao.entity.ProjectUser;
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-import org.apache.dolphinscheduler.service.alert.ProcessAlertManager;
-import org.apache.dolphinscheduler.service.process.ProcessService;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowTimeoutEventOperator
- implements
- IEventOperator<WorkflowTimeoutEvent> {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Autowired
- private ProcessService processService;
-
- @Autowired
- private ProcessAlertManager processAlertManager;
-
- @Override
- public void handleEvent(WorkflowTimeoutEvent event) {
- IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
- if (workflowExecutionRunnable == null) {
- log.warn("Cannot find the workflow instance by id: {}", event.getWorkflowInstanceId());
- return;
- }
- // we only support timeout warning for now
- ProcessInstance workflowInstance =
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance();
- ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(workflowInstance.getId());
- processAlertManager.sendProcessTimeoutAlert(workflowInstance, projectUser);
- }
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEvent.java
deleted file mode 100644
index 3dfdb9e239..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEvent.java
+++ /dev/null
@@ -1,38 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowTriggerNextTaskEvent implements IWorkflowEvent, ISyncEvent {
-
- private Integer workflowInstanceId;
-
- /**
- * The task name of the parent task, if it is the root task, the value is null
- */
- private String parentTaskNodeName;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEventOperator.java
deleted file mode 100644
index d294b84d58..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggerNextTaskEventOperator.java
+++ /dev/null
@@ -1,44 +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.server.master.events;
-
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowTriggerNextTaskEventOperator
- implements
- IWorkflowEventOperator<WorkflowTriggerNextTaskEvent> {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Override
- public void handleEvent(WorkflowTriggerNextTaskEvent event) {
- IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(event.getWorkflowInstanceId());
- workflowExecutionRunnable.getDagEngine().triggerNextTasks(event.getParentTaskNodeName());
- }
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEvent.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEvent.java
deleted file mode 100644
index b07434dc29..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEvent.java
+++ /dev/null
@@ -1,33 +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.server.master.events;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class WorkflowTriggeredEvent implements IWorkflowEvent, IAsyncEvent {
-
- private Integer workflowInstanceId;
-
-}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEventOperator.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEventOperator.java
deleted file mode 100644
index e49b1ae70e..0000000000
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowTriggeredEventOperator.java
+++ /dev/null
@@ -1,63 +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.server.master.events;
-
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-import org.apache.dolphinscheduler.dao.entity.ProjectUser;
-import org.apache.dolphinscheduler.server.master.dag.IWorkflowExecutionRunnable;
-import org.apache.dolphinscheduler.server.master.dag.WorkflowExecuteRunnableRepository;
-import org.apache.dolphinscheduler.server.master.metrics.ProcessInstanceMetrics;
-import org.apache.dolphinscheduler.service.alert.ListenerEventAlertManager;
-import org.apache.dolphinscheduler.service.process.ProcessService;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class WorkflowTriggeredEventOperator
- implements
- IWorkflowEventOperator<WorkflowTriggeredEvent> {
-
- @Autowired
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- @Autowired
- private ProcessService processService;
-
- @Autowired
- private ListenerEventAlertManager listenerEventAlertManager;
-
- @Override
- public void handleEvent(WorkflowTriggeredEvent event) {
- int workflowInstanceId = event.getWorkflowInstanceId();
- IWorkflowExecutionRunnable workflowExecutionRunnable =
- workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId);
- Long workflowDefinitionCode =
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance()
- .getProcessDefinitionCode();
- ProcessInstanceMetrics.incProcessInstanceByStateAndProcessDefinitionCode("submit", "" + workflowDefinitionCode);
-
- ProcessInstance workflowInstance =
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance();
- ProjectUser projectUser = processService.queryProjectWithUserByProcessInstanceId(workflowInstanceId);
- listenerEventAlertManager.publishProcessStartListenerEvent(workflowInstance, projectUser);
- }
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/DAGNodeTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/DAGNodeTest.java
deleted file mode 100644
index c3346bfc5d..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/DAGNodeTest.java
+++ /dev/null
@@ -1,121 +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.server.master.dag;
-
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.ArrayList;
-
-import org.junit.jupiter.api.Test;
-
-import com.google.common.collect.Lists;
-
-class DAGNodeTest {
-
- @Test
- void buildDAGNode_EmptyNodeName() {
- IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
- () -> DAGNode.builder()
- .inDegrees(new ArrayList<>())
- .outDegrees(new ArrayList<>())
- .build());
- assertEquals("nodeName cannot be empty", illegalArgumentException.getMessage());
- }
-
- @Test
- void buildDAGNode_BadInDegree() {
- IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
- () -> DAGNode.builder()
- .nodeName("A")
- .inDegrees(Lists.newArrayList(DAGEdge.builder()
- .fromNodeName(null)
- .toNodeName("B")
- .build()))
- .outDegrees(new ArrayList<>())
- .build());
- assertEquals(
- "The toNodeName of inDegree should be the nodeName of the node: A, inDegree: DAGEdge(fromNodeName=null, toNodeName=B)",
- illegalArgumentException.getMessage());
- }
-
- @Test
- void buildDAGNode_NiceInDegree() {
- assertDoesNotThrow(() -> DAGNode.builder()
- .nodeName("A")
- .inDegrees(Lists.newArrayList(DAGEdge.builder()
- .fromNodeName(null)
- .toNodeName("A")
- .build()))
- .outDegrees(new ArrayList<>())
- .build());
- }
-
- @Test
- void buildDAGNode_BadOutDegree() {
- IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
- () -> DAGNode.builder()
- .nodeName("A")
- .inDegrees(new ArrayList<>())
- .outDegrees(Lists.newArrayList(DAGEdge.builder()
- .fromNodeName("B")
- .toNodeName(null)
- .build()))
- .build());
- assertEquals(
- "The fromNodeName of outDegree should be the nodeName of the node: A, outDegree: DAGEdge(fromNodeName=B, toNodeName=null)",
- illegalArgumentException.getMessage());
- }
-
- @Test
- void buildDAGNode_NiceOutDegree() {
- assertDoesNotThrow(() -> DAGNode.builder()
- .nodeName("A")
- .inDegrees(new ArrayList<>())
- .outDegrees(Lists.newArrayList(DAGEdge.builder()
- .fromNodeName("A")
- .toNodeName(null)
- .build()))
- .build());
- }
-
- @Test
- void buildDAGNode_NotSkip() {
- DAGNode dagNode = DAGNode.builder()
- .nodeName("A")
- .inDegrees(new ArrayList<>())
- .outDegrees(new ArrayList<>())
- .build();
- assertFalse(dagNode.isSkip());
- }
-
- @Test
- void buildDAGNode_Skip() {
- DAGNode dagNode = DAGNode.builder()
- .nodeName("A")
- .skip(true)
- .inDegrees(new ArrayList<>())
- .outDegrees(new ArrayList<>())
- .build();
- assertTrue(dagNode.isSkip());
- }
-
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionContextFactory.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionContextFactory.java
deleted file mode 100644
index b067a455dd..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionContextFactory.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.server.master.dag;
-
-import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
-import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
-import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
-import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
-import org.apache.dolphinscheduler.server.master.events.MemoryEventRepository;
-
-import java.util.Collections;
-
-class MockWorkflowExecutionContextFactory {
-
- public static WorkflowExecutionContext createWorkflowExecutionContext() {
- long workflowDefinitionCode = CodeGenerateUtils.getInstance().genCode();
- int workflowDefinitionVersion = 1;
-
- int workflowInstanceId = 1;
- String workflowInstanceName = "MockWorkflow" + CodeGenerateUtils.getInstance().genCode();
-
- ProcessDefinition processDefinition = ProcessDefinition.builder()
- .id(1)
- .name("TestWorkflow")
- .code(workflowDefinitionCode)
- .version(workflowDefinitionVersion)
- .build();
-
- ProcessInstance processInstance = ProcessInstance.builder()
- .id(workflowInstanceId)
- .name(workflowInstanceName)
- .build();
-
- WorkflowExecutionDAG workflowExecutionDAG = createWorkflowExecutionDAG();
-
- return WorkflowExecutionContext.builder()
- .workflowExecutionDAG(workflowExecutionDAG)
- .eventRepository(new MemoryEventRepository())
- .beginNodeNames(Collections.emptyList())
- .workflowDefinition(processDefinition)
- .workflowInstance(processInstance)
- .build();
- }
-
- private static WorkflowExecutionDAG createWorkflowExecutionDAG() {
- TaskDefinitionLog taskA = taskNode("A");
- WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
- .addTaskNode(taskA)
- .addTaskEdge(edge(null, taskA))
- .addTaskEdge(edge(taskA, null))
- .build();
-
- return WorkflowExecutionDAG.builder()
- .workflowDAG(workflowDAG)
- .taskExecutionRunnableRepository(new TaskExecutionRunnableRepository())
- .build();
- }
-
- private static TaskDefinitionLog taskNode(String nodeName) {
- TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog();
- taskDefinitionLog.setCode(CodeGenerateUtils.getInstance().genCode());
- taskDefinitionLog.setName(nodeName);
- return taskDefinitionLog;
- }
-
- private static ProcessTaskRelationLog edge(TaskDefinitionLog from, TaskDefinitionLog to) {
- ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog();
- processTaskRelationLog.setPreTaskCode(from == null ? 0 : from.getCode());
- processTaskRelationLog.setPostTaskCode(to == null ? 0 : to.getCode());
- return processTaskRelationLog;
- }
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionRunnableFactory.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionRunnableFactory.java
deleted file mode 100644
index 77745e198b..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/MockWorkflowExecutionRunnableFactory.java
+++ /dev/null
@@ -1,31 +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.server.master.dag;
-
-class MockWorkflowExecutionRunnableFactory {
-
- public static WorkflowExecutionRunnable createWorkflowExecuteRunnable() {
- WorkflowExecutionContext workflowExecutionContext =
- MockWorkflowExecutionContextFactory.createWorkflowExecutionContext();
- IDAGEngine dagEngine = new DAGEngine(workflowExecutionContext);
- return WorkflowExecutionRunnable.builder()
- .workflowExecutionContext(workflowExecutionContext)
- .dagEngine(dagEngine)
- .build();
- }
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGAssertion.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGAssertion.java
deleted file mode 100644
index a03ecd9f76..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGAssertion.java
+++ /dev/null
@@ -1,171 +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.server.master.dag;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.apache.commons.collections4.CollectionUtils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class WorkflowDAGAssertion {
-
- private final IWorkflowDAG workflowDAG;
-
- private final List<NodeAssertion> nodeAssertions;
-
- private WorkflowDAGAssertion(IWorkflowDAG workflowDAG) {
- this.workflowDAG = workflowDAG;
- this.nodeAssertions = new ArrayList<>();
- }
-
- public static WorkflowDAGAssertion workflowDag(IWorkflowDAG workflowDAG) {
- return new WorkflowDAGAssertion(workflowDAG);
- }
-
- public WorkflowDAGAssertion nodeAssertion(NodeAssertion nodeAssertion) {
- nodeAssertions.add(nodeAssertion);
- return this;
- }
-
- public void doAssertion() {
- nodeAssertions.forEach(nodeAssertion -> nodeAssertion.doAssertion(workflowDAG));
- }
-
- public static class NodeAssertion {
-
- /**
- * node name of the assertion
- */
- private final String nodeName;
-
- /**
- * whether the node exist
- */
- private boolean exist;
-
- /**
- * whether the node is skipped
- */
- private boolean skip;
-
- /**
- * whether the node has out degree
- */
- private List<String> postNodes;
-
- /**
- * whether the node has in degree
- */
- private List<String> preNodes;
-
- private NodeAssertion(String nodeName) {
- this.nodeName = nodeName;
- this.postNodes = new ArrayList<>();
- this.preNodes = new ArrayList<>();
- }
-
- public static NodeAssertion node(String nodeName) {
- return new NodeAssertion(nodeName);
- }
-
- public NodeAssertion exist() {
- this.exist = true;
- return this;
- }
-
- public NodeAssertion skip() {
- this.skip = true;
- return this;
- }
-
- public NodeAssertion noEdge() {
- this.postNodes = new ArrayList<>();
- this.preNodes = new ArrayList<>();
- return this;
- }
-
- public NodeAssertion noInDegree() {
- this.preNodes = new ArrayList<>();
- return this;
- }
-
- public NodeAssertion inDegrees(List<String> preNodes) {
- this.preNodes.addAll(preNodes);
- return this;
- }
-
- public NodeAssertion inDegrees(String preNode) {
- this.preNodes.add(preNode);
- return this;
- }
-
- public NodeAssertion noOutDegree() {
- this.postNodes = new ArrayList<>();
- return this;
- }
-
- public NodeAssertion outDegrees(List<String> postNodes) {
- this.postNodes.addAll(postNodes);
- return this;
- }
-
- public NodeAssertion outDegrees(String postNode) {
- this.postNodes.add(postNode);
- return this;
- }
-
- private void doAssertion(IWorkflowDAG workflowDAG) {
- if (exist) {
- // node exist
- assertNotNull(workflowDAG.getDAGNode(nodeName), "node " + nodeName + " does not exist");
- } else {
-
- assertNull(workflowDAG.getDAGNode(nodeName), "node " + nodeName + " exist");
- }
-
- if (skip) {
- assertTrue(workflowDAG.getDAGNode(nodeName).isSkip(), "node " + nodeName + " is not skipped");
- } else {
- assertFalse(workflowDAG.getDAGNode(nodeName).isSkip(), "node " + nodeName + " is skipped");
- }
-
- if (CollectionUtils.isEmpty(postNodes)) {
- assertTrue(workflowDAG.getDirectPostNodeNames(nodeName).isEmpty(),
- "node " + nodeName + " has outDegree " + workflowDAG.getDirectPostNodes(nodeName));
- } else {
- postNodes
- .forEach(postNode -> assertTrue(workflowDAG.getDirectPostNodeNames(nodeName).contains(postNode),
- "node " + nodeName + " does has outDegree " + postNode));
- }
-
- if (CollectionUtils.isEmpty(preNodes)) {
- assertTrue(workflowDAG.getDirectPreNodeNames(nodeName).isEmpty(),
- "node " + nodeName + " has inDegree " + workflowDAG.getDirectPreNodeNames(nodeName));
- } else {
- preNodes.forEach(preNode -> assertTrue(workflowDAG.getDirectPreNodeNames(nodeName).contains(preNode),
- "node " + nodeName + " does has inDegree " + preNode));
- }
- }
- }
-
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilderTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilderTest.java
deleted file mode 100644
index a4abb8156f..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowDAGBuilderTest.java
+++ /dev/null
@@ -1,282 +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.server.master.dag;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.apache.dolphinscheduler.server.master.dag.WorkflowDAGAssertion.NodeAssertion.node;
-import static org.apache.dolphinscheduler.server.master.dag.WorkflowDAGAssertion.workflowDag;
-
-import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
-import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
-import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
-
-import org.junit.jupiter.api.Test;
-
-class WorkflowDAGBuilderTest {
-
- /**
- * Test DAG with single node:
- * <pre>
- * {@code
- * Node(A)
- * }
- * </pre>
- */
- @Test
- void build_SingleTaskNode() {
- String nodeName = "A";
- TaskDefinitionLog taskDefinitionLog = taskNode(nodeName);
- WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
- .addTaskNode(taskDefinitionLog)
- .build();
- workflowDag(workflowDAG)
- .nodeAssertion(node(nodeName).exist().noEdge())
- .doAssertion();
- }
-
- /**
- * Test DAG with multiple nodes:
- * <pre>
- * {@code
- * Node(A)
- * Node(B)
- * Node(C)
- * }
- * <pre/>
- */
- @Test
- void build_MULTIPLE_NODE() {
- String nodeNameA = "A";
- TaskDefinitionLog taskNodeA = taskNode(nodeNameA);
- String nodeNameB = "B";
- TaskDefinitionLog taskNodeB = taskNode(nodeNameB);
- String nodeNameC = "C";
- TaskDefinitionLog taskNodeC = taskNode(nodeNameC);
-
- WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
- .addTaskNode(taskNodeA)
- .addTaskNode(taskNodeB)
- .addTaskNode(taskNodeC)
- .build();
- workflowDag(workflowDAG)
- .nodeAssertion(node(nodeNameA).exist().noEdge())
- .nodeAssertion(node(nodeNameB).exist().noEdge())
- .nodeAssertion(node(nodeNameC).exist().noEdge())
- .doAssertion();
- }
-
- /**
- * Test DAG with multiple nodes:
- * <pre>
- * {@code
- * Node(A) -> Node(B1) -> Node(C1) -> Node(D)
- * -> Node(B2) -> Node(C2) ->
- * }
- * <pre/>
- */
- @Test
- void build_DAG() {
- String nodeNameA = "A";
- TaskDefinitionLog taskNodeA = taskNode(nodeNameA);
- String nodeNameB1 = "B1";
- TaskDefinitionLog taskNodeB1 = taskNode(nodeNameB1);
- String nodeNameB2 = "B2";
- TaskDefinitionLog taskNodeB2 = taskNode(nodeNameB2);
- String nodeNameC1 = "C1";
- TaskDefinitionLog taskNodeC1 = taskNode(nodeNameC1);
- String nodeNameC2 = "C2";
- TaskDefinitionLog taskNodeC2 = taskNode(nodeNameC2);
- String nodeNameD = "D";
- TaskDefinitionLog taskNodeD = taskNode(nodeNameD);
-
- WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
- .addTaskNode(taskNodeA)
- .addTaskNodes(newArrayList(taskNodeB1, taskNodeB2))
- .addTaskNodes(newArrayList(taskNodeC1, taskNodeC2))
- .addTaskNode(taskNodeD)
- .addTaskEdge(edge(null, taskNodeA))
- .addTaskEdge(edge(taskNodeA, taskNodeB1))
- .addTaskEdge(edge(taskNodeA, taskNodeB2))
- .addTaskEdge(edge(taskNodeB1, taskNodeC1))
- .addTaskEdge(edge(taskNodeB2, taskNodeC2))
- .addTaskEdge(edge(taskNodeC1, taskNodeD))
- .addTaskEdge(edge(taskNodeC2, taskNodeD))
- .addTaskEdge(edge(taskNodeD, null))
- .build();
- workflowDag(workflowDAG)
- .nodeAssertion(node(nodeNameA)
- .exist()
- .noInDegree()
- .outDegrees(newArrayList(nodeNameB1, nodeNameB2)))
- .nodeAssertion(node(nodeNameB1)
- .exist()
- .inDegrees(nodeNameA)
- .outDegrees(nodeNameC1))
- .nodeAssertion(node(nodeNameB2)
- .exist()
- .inDegrees(nodeNameA)
- .outDegrees(nodeNameC2))
- .nodeAssertion(node(nodeNameC1)
- .exist()
- .inDegrees(nodeNameB1)
- .outDegrees(nodeNameD))
- .nodeAssertion(node(nodeNameC2)
- .exist()
- .inDegrees(nodeNameB2)
- .outDegrees(nodeNameD))
- .nodeAssertion(node(nodeNameD)
- .exist()
- .inDegrees(newArrayList(nodeNameC1, nodeNameC2))
- .noOutDegree())
- .doAssertion();
- }
-
- /**
- * Test DAG with multiple sub dags:
- * <pre>
- * {@code
- * Node(A1) -> Node(B1) -> Node(C1) -> Node(D1)
- * -> Node(B2) -> Node(C2) ->
- *
- * Node(A2) -> Node(B3) -> Node(C3) -> Node(D2)
- * -> Node(B4) -> Node(C4) ->
- * }
- * <pre/>
- */
- @Test
- void build_MULTIPLE_SUB_DAG() {
- String nodeNameA1 = "A1";
- TaskDefinitionLog taskNodeA1 = taskNode(nodeNameA1);
- String nodeNameA2 = "A2";
- TaskDefinitionLog taskNodeA2 = taskNode(nodeNameA2);
-
- String nodeNameB1 = "B1";
- TaskDefinitionLog taskNodeB1 = taskNode(nodeNameB1);
- String nodeNameB2 = "B2";
- TaskDefinitionLog taskNodeB2 = taskNode(nodeNameB2);
- String nodeNameB3 = "B3";
- TaskDefinitionLog taskNodeB3 = taskNode(nodeNameB3);
- String nodeNameB4 = "B4";
- TaskDefinitionLog taskNodeB4 = taskNode(nodeNameB4);
-
- String nodeNameC1 = "C1";
- TaskDefinitionLog taskNodeC1 = taskNode(nodeNameC1);
- String nodeNameC2 = "C2";
- TaskDefinitionLog taskNodeC2 = taskNode(nodeNameC2);
- String nodeNameC3 = "C3";
- TaskDefinitionLog taskNodeC3 = taskNode(nodeNameC3);
- String nodeNameC4 = "C4";
- TaskDefinitionLog taskNodeC4 = taskNode(nodeNameC4);
-
- String nodeNameD1 = "D1";
- TaskDefinitionLog taskNodeD1 = taskNode(nodeNameD1);
- String nodeNameD2 = "D2";
- TaskDefinitionLog taskNodeD2 = taskNode(nodeNameD2);
-
- WorkflowDAG workflowDAG = WorkflowDAGBuilder.newBuilder()
- .addTaskNodes(newArrayList(taskNodeA1, taskNodeA2))
- .addTaskNodes(newArrayList(taskNodeB1, taskNodeB2, taskNodeB3, taskNodeB4))
- .addTaskNodes(newArrayList(taskNodeC1, taskNodeC2, taskNodeC3, taskNodeC4))
- .addTaskNodes(newArrayList(taskNodeD1, taskNodeD2))
- .addTaskEdge(edge(null, taskNodeA1))
- .addTaskEdge(edge(taskNodeA1, taskNodeB1))
- .addTaskEdge(edge(taskNodeA1, taskNodeB2))
- .addTaskEdge(edge(taskNodeB1, taskNodeC1))
- .addTaskEdge(edge(taskNodeB2, taskNodeC2))
- .addTaskEdge(edge(taskNodeC1, taskNodeD1))
- .addTaskEdge(edge(taskNodeC2, taskNodeD1))
- .addTaskEdge(edge(taskNodeD1, null))
- .addTaskEdge(edge(null, taskNodeA2))
- .addTaskEdge(edge(taskNodeA2, taskNodeB3))
- .addTaskEdge(edge(taskNodeA2, taskNodeB4))
- .addTaskEdge(edge(taskNodeB3, taskNodeC3))
- .addTaskEdge(edge(taskNodeB4, taskNodeC4))
- .addTaskEdge(edge(taskNodeC3, taskNodeD2))
- .addTaskEdge(edge(taskNodeC4, taskNodeD2))
- .addTaskEdge(edge(taskNodeD2, null))
- .build();
-
- workflowDag(workflowDAG)
- .nodeAssertion(node(nodeNameA1)
- .exist()
- .noInDegree()
- .outDegrees(newArrayList(nodeNameB1, nodeNameB2)))
- .nodeAssertion(node(nodeNameB1)
- .exist()
- .inDegrees(nodeNameA1)
- .outDegrees(nodeNameC1))
- .nodeAssertion(node(nodeNameB2)
- .exist()
- .inDegrees(nodeNameA1)
- .outDegrees(nodeNameC2))
- .nodeAssertion(node(nodeNameC1)
- .exist()
- .inDegrees(nodeNameB1)
- .outDegrees(nodeNameD1))
- .nodeAssertion(node(nodeNameC2)
- .exist()
- .inDegrees(nodeNameB2)
- .outDegrees(nodeNameD1))
- .nodeAssertion(node(nodeNameD1)
- .exist()
- .inDegrees(newArrayList(nodeNameC1, nodeNameC2))
- .noOutDegree())
- .doAssertion();
- workflowDag(workflowDAG)
- .nodeAssertion(node(nodeNameA2)
- .exist()
- .noInDegree()
- .outDegrees(newArrayList(nodeNameB3, nodeNameB4)))
- .nodeAssertion(node(nodeNameB3)
- .exist()
- .inDegrees(nodeNameA2)
- .outDegrees(nodeNameC3))
- .nodeAssertion(node(nodeNameB4)
- .exist()
- .inDegrees(nodeNameA2)
- .outDegrees(nodeNameC4))
- .nodeAssertion(node(nodeNameC3)
- .exist()
- .inDegrees(nodeNameB3)
- .outDegrees(nodeNameD2))
- .nodeAssertion(node(nodeNameC4)
- .exist()
- .inDegrees(nodeNameB4)
- .outDegrees(nodeNameD2))
- .nodeAssertion(node(nodeNameD2)
- .exist()
- .inDegrees(newArrayList(nodeNameC3, nodeNameC4))
- .noOutDegree())
- .doAssertion();
- }
-
- private TaskDefinitionLog taskNode(String nodeName) {
- TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog();
- taskDefinitionLog.setCode(CodeGenerateUtils.getInstance().genCode());
- taskDefinitionLog.setName(nodeName);
- return taskDefinitionLog;
- }
-
- private ProcessTaskRelationLog edge(TaskDefinitionLog from, TaskDefinitionLog to) {
- ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog();
- processTaskRelationLog.setPreTaskCode(from == null ? 0 : from.getCode());
- processTaskRelationLog.setPostTaskCode(to == null ? 0 : to.getCode());
- return processTaskRelationLog;
- }
-
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineTest.java
deleted file mode 100644
index b6e5dc9db5..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineTest.java
+++ /dev/null
@@ -1,114 +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.server.master.dag;
-
-import static org.apache.dolphinscheduler.server.master.dag.WorkflowExecutionRunnableAssertions.workflowExecutionRunnable;
-import static org.apache.dolphinscheduler.server.master.dag.WorkflowExecutionRunnableRepositoryAssertions.workflowExecutionRunnableRepository;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import org.apache.dolphinscheduler.server.master.events.WorkflowOperationEvent;
-import org.apache.dolphinscheduler.server.master.exception.WorkflowExecuteRunnableNotFoundException;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-class WorkflowEngineTest {
-
- private WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
- private WorkflowEngine workflowEngine;
-
- @BeforeEach
- public void before() {
- workflowExecuteRunnableRepository = new WorkflowExecuteRunnableRepository();
- workflowEngine = new WorkflowEngine(workflowExecuteRunnableRepository);
- }
-
- @Test
- void triggerWorkflow() {
- IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
- MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
- Integer workflowInstanceId = emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
-
- workflowEngine.triggerWorkflow(emptyWorkflowExecuteRunnable);
- workflowExecutionRunnable(emptyWorkflowExecuteRunnable)
- .existEvent(WorkflowOperationEvent.triggerEvent(workflowInstanceId));
- }
-
- @Test
- void pauseWorkflow_WorkflowNotExist() {
- WorkflowExecuteRunnableNotFoundException exception =
- assertThrows(WorkflowExecuteRunnableNotFoundException.class, () -> workflowEngine.pauseWorkflow(1));
- assertEquals("WorkflowExecuteRunnable not found: [id=1]", exception.getMessage());
- }
-
- @Test
- void pauseWorkflow_WorkflowExist() {
- IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
- MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
- Integer workflowInstanceId =
- emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
- workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
-
- workflowEngine.pauseWorkflow(workflowInstanceId);
- workflowExecutionRunnable(emptyWorkflowExecuteRunnable)
- .existEvent(WorkflowOperationEvent.pauseEvent(workflowInstanceId));
- }
-
- @Test
- void killWorkflow_WorkflowNotExist() {
- WorkflowExecuteRunnableNotFoundException exception =
- assertThrows(WorkflowExecuteRunnableNotFoundException.class,
- () -> workflowEngine.killWorkflow(1));
- assertEquals("WorkflowExecuteRunnable not found: [id=1]", exception.getMessage());
- }
-
- @Test
- void killWorkflow_WorkflowExist() {
- IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
- MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
- Integer workflowInstanceId =
- emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
- workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
-
- workflowEngine.killWorkflow(workflowInstanceId);
- workflowExecutionRunnable(emptyWorkflowExecuteRunnable)
- .existEvent(WorkflowOperationEvent.killEvent(workflowInstanceId));
- }
-
- @Test
- void finalizeWorkflow_WorkflowNotExist() {
- workflowEngine.finalizeWorkflow(1);
- }
-
- @Test
- void finalizeWorkflow_WorkflowExist() {
- IWorkflowExecutionRunnable emptyWorkflowExecuteRunnable =
- MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
- Integer workflowInstanceId =
- emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
- workflowExecuteRunnableRepository.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
- workflowExecutionRunnableRepository(workflowExecuteRunnableRepository)
- .existWorkflowExecutionRunnable(workflowInstanceId);
-
- workflowEngine.finalizeWorkflow(workflowInstanceId);
- workflowExecutionRunnableRepository(workflowExecuteRunnableRepository)
- .notExistWorkflowExecutionRunnable(workflowInstanceId);
- }
-
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableAssertions.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableAssertions.java
deleted file mode 100644
index 65cf7ba7cd..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableAssertions.java
+++ /dev/null
@@ -1,48 +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.server.master.dag;
-
-import org.apache.dolphinscheduler.server.master.events.IEvent;
-
-import org.opentest4j.AssertionFailedError;
-
-class WorkflowExecutionRunnableAssertions {
-
- private final IWorkflowExecutionRunnable workflowExecutionRunnable;
-
- private WorkflowExecutionRunnableAssertions(IWorkflowExecutionRunnable workflowExecutionRunnable) {
- this.workflowExecutionRunnable = workflowExecutionRunnable;
- }
-
- public static WorkflowExecutionRunnableAssertions workflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable) {
- return new WorkflowExecutionRunnableAssertions(workflowExecutionRunnable);
- }
-
- public void existEvent(IEvent event) {
- if (event == null) {
- throw new IllegalArgumentException("Event cannot be null");
- }
- boolean exist = workflowExecutionRunnable.getEventRepository().getAllEvent()
- .stream()
- .anyMatch(event1 -> event1.equals(event1));
- if (!exist) {
- throw new AssertionFailedError("The workflowExecuteRunnable doesn't exist event: " + event);
- }
- }
-
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableRepositoryAssertions.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableRepositoryAssertions.java
deleted file mode 100644
index e979f35cb3..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableRepositoryAssertions.java
+++ /dev/null
@@ -1,43 +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.server.master.dag;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-class WorkflowExecutionRunnableRepositoryAssertions {
-
- private final WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
-
- private WorkflowExecutionRunnableRepositoryAssertions(WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
- this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
- }
-
- public static WorkflowExecutionRunnableRepositoryAssertions workflowExecutionRunnableRepository(WorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
- return new WorkflowExecutionRunnableRepositoryAssertions(workflowExecuteRunnableRepository);
- }
-
- public void existWorkflowExecutionRunnable(Integer workflowInstanceId) {
- assertNotNull(workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId));
- }
-
- public void notExistWorkflowExecutionRunnable(Integer workflowInstanceId) {
- assertNull(workflowExecuteRunnableRepository.getWorkflowExecutionRunnableById(workflowInstanceId));
- }
-
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableTest.java
deleted file mode 100644
index 69a7f83a50..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowExecutionRunnableTest.java
+++ /dev/null
@@ -1,51 +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.server.master.dag;
-
-import static org.apache.dolphinscheduler.server.master.dag.WorkflowExecutionRunnableAssertions.workflowExecutionRunnable;
-
-import org.apache.dolphinscheduler.server.master.events.WorkflowTriggeredEvent;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-class WorkflowExecutionRunnableTest {
-
- private WorkflowExecutionRunnable workflowExecutionRunnable;
-
- @BeforeEach
- public void before() {
- workflowExecutionRunnable = MockWorkflowExecutionRunnableFactory.createWorkflowExecuteRunnable();
- }
-
- @Test
- void start() {
- workflowExecutionRunnable.start();
- workflowExecutionRunnable(workflowExecutionRunnable)
- .existEvent(new WorkflowTriggeredEvent(
- workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstance().getId()));
- }
-
- @Test
- void pause() {
- }
-
- @Test
- void kill() {
- }
-}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventTest.java
deleted file mode 100644
index 00bea9f601..0000000000
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationEventTest.java
+++ /dev/null
@@ -1,46 +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.server.master.events;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.junit.jupiter.api.Test;
-
-class WorkflowOperationEventTest {
-
- @Test
- void triggerEvent() {
- WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.triggerEvent(1);
- assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
- assertEquals(WorkflowOperationType.TRIGGER, workflowOperationEvent.getWorkflowOperationType());
- }
-
- @Test
- void pauseEvent() {
- WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.pauseEvent(1);
- assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
- assertEquals(WorkflowOperationType.PAUSE, workflowOperationEvent.getWorkflowOperationType());
- }
-
- @Test
- void killEvent() {
- WorkflowOperationEvent workflowOperationEvent = WorkflowOperationEvent.killEvent(1);
- assertEquals(1, workflowOperationEvent.getWorkflowInstanceId());
- assertEquals(WorkflowOperationType.KILL, workflowOperationEvent.getWorkflowOperationType());
- }
-}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngine.java
similarity index 63%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventEngine.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngine.java
index 35bfe079c5..10e483f0ad 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngine.java
@@ -15,57 +15,59 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.event;
+package org.apache.dolphinscheduler.workflow.engine.engine;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
import org.apache.dolphinscheduler.common.thread.ThreadUtils;
-import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.time.StopWatch;
import java.util.Collection;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
@Slf4j
-public class EventEngine extends BaseDaemonThread {
+public class EventEngine extends BaseDaemonThread implements IEventEngine {
- private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+ private final IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository;
- private final EventFirer eventFirer;
+ private final IEventFirer eventFirer;
- private final Set<Integer> firingWorkflowInstanceIds;
+ private volatile boolean stop = false;
- public EventEngine(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository,
- EventFirer eventFirer) {
+ public EventEngine(IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository,
+ IEventFirer eventFirer) {
super("EventEngine");
this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
this.eventFirer = eventFirer;
- this.firingWorkflowInstanceIds = ConcurrentHashMap.newKeySet();
}
@Override
public synchronized void start() {
+ this.stop = false;
super.start();
log.info(getClass().getName() + " started");
}
@Override
public void run() {
- for (;;) {
+ while (!stop) {
try {
- StopWatch stopWatch = StopWatch.createStarted();
- fireAllActiveEvents();
- stopWatch.stop();
- log.info("Fire all active events cost: {} ms", stopWatch.getTime());
- this.wait(5_000);
+ Collection<IWorkflowExecutionRunnable> workflowExecutionRunnableCollection =
+ workflowExecuteRunnableRepository.getActiveWorkflowExecutionRunnable();
+ if (CollectionUtils.isEmpty(workflowExecutionRunnableCollection)) {
+ log.debug("There is no active WorkflowExecutionRunnable");
+ this.wait(3_000);
+ continue;
+ }
+ fireAllActiveEvents(workflowExecutionRunnableCollection);
} catch (Throwable throwable) {
log.error("Fire active event error", throwable);
ThreadUtils.sleep(3_000);
@@ -73,25 +75,25 @@ public class EventEngine extends BaseDaemonThread {
}
}
- public void fireAllActiveEvents() {
- Collection<IWorkflowExecutionRunnable> workflowExecutionRunnableCollection =
- workflowExecuteRunnableRepository.getActiveWorkflowExecutionRunnable();
- for (IWorkflowExecutionRunnable workflowExecutionRunnable : workflowExecutionRunnableCollection) {
+ public void fireAllActiveEvents(Collection<IWorkflowExecutionRunnable> workflowExecutionRunnableList) {
+ StopWatch stopWatch = StopWatch.createStarted();
+
+ log.info("Fire all active events cost: {} ms", stopWatch.getTime());
+ stopWatch.stop();
+ for (IWorkflowExecutionRunnable workflowExecutionRunnable : workflowExecutionRunnableList) {
IWorkflowExecutionContext workflowExecutionContext =
workflowExecutionRunnable.getWorkflowExecutionContext();
final Integer workflowInstanceId = workflowExecutionContext.getWorkflowInstanceId();
final String workflowInstanceName = workflowExecutionContext.getWorkflowInstanceName();
try {
MDC.put(Constants.WORKFLOW_INSTANCE_ID_MDC_KEY, String.valueOf(workflowInstanceId));
- if (firingWorkflowInstanceIds.contains(workflowInstanceId)) {
+ if (workflowExecutionRunnable.isEventFiring()) {
log.debug("WorkflowExecutionRunnable: {} is already in firing", workflowInstanceName);
- return;
+ continue;
}
- IEventRepository workflowEventRepository = workflowExecutionRunnable.getEventRepository();
- firingWorkflowInstanceIds.add(workflowInstanceId);
- eventFirer.fireActiveEvents(workflowEventRepository)
+ eventFirer.fireActiveEvents(workflowExecutionRunnable)
.whenComplete((fireCount, ex) -> {
- firingWorkflowInstanceIds.remove(workflowInstanceId);
+ workflowExecutionRunnable.setEventFiring(false);
if (ex != null) {
log.error("Fire event for WorkflowExecutionRunnable: {} error", workflowInstanceName,
ex);
@@ -108,4 +110,14 @@ public class EventEngine extends BaseDaemonThread {
}
}
+ @Override
+ public synchronized void shutdown() {
+ if (stop) {
+ log.warn("EventEngine has already stopped");
+ return;
+ }
+ this.stop = true;
+ eventFirer.shutdown();
+ }
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngineFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngineFactory.java
new file mode 100644
index 0000000000..6438990825
--- /dev/null
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventEngineFactory.java
@@ -0,0 +1,72 @@
+/*
+ * 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.workflow.engine.engine;
+
+import org.apache.dolphinscheduler.workflow.engine.event.EventOperatorManager;
+import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventOperatorManager;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecutionRunnableRepository;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class EventEngineFactory implements IEventEngineFactory {
+
+ private static final IWorkflowExecutionRunnableRepository DEFAULT_WORKFLOW_EXECUTION_RUNNABLE_FACTORY =
+ SingletonWorkflowExecutionRunnableRepository.getInstance();
+
+ private IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository;
+
+ private static final IEventOperatorManager<IEvent> DEFAULT_EVENT_OPERATOR_MANAGER =
+ EventOperatorManager.getInstance();
+
+ private IEventOperatorManager<IEvent> eventOperatorManager = DEFAULT_EVENT_OPERATOR_MANAGER;
+
+ private static final int DEFAULT_EVENT_FIRE_THREAD_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 2;
+
+ private int eventFireThreadPoolSize = DEFAULT_EVENT_FIRE_THREAD_POOL_SIZE;
+
+ private EventEngineFactory() {
+ }
+
+ public static EventEngineFactory newEventEngineFactory() {
+ return new EventEngineFactory();
+ }
+
+ public EventEngineFactory withWorkflowExecuteRunnableRepository(IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository) {
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ return this;
+ }
+
+ public EventEngineFactory withEventOperatorManager(IEventOperatorManager<IEvent> eventOperatorManager) {
+ this.eventOperatorManager = eventOperatorManager;
+ return this;
+ }
+
+ public int withEventFireThreadPoolSize(int eventFireThreadPoolSize) {
+ this.eventFireThreadPoolSize = eventFireThreadPoolSize;
+ return this.eventFireThreadPoolSize;
+ }
+
+ @Override
+ public IEventEngine createEventEngine() {
+ EventFirer eventFirer = new EventFirer(eventOperatorManager, eventFireThreadPoolSize);
+ return new EventEngine(workflowExecuteRunnableRepository, eventFirer);
+ }
+}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventFirer.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventFirer.java
similarity index 81%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventFirer.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventFirer.java
index 0026bd0c21..ab9fecf8c3 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventFirer.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/EventFirer.java
@@ -15,10 +15,15 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.event;
+package org.apache.dolphinscheduler.workflow.engine.engine;
import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.workflow.engine.event.IAsyncEvent;
+import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventOperatorManager;
+import org.apache.dolphinscheduler.workflow.engine.event.IEventRepository;
import org.apache.dolphinscheduler.workflow.engine.utils.ExceptionUtils;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IEventfulExecutionRunnable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
@@ -39,7 +44,9 @@ public class EventFirer implements IEventFirer {
}
@Override
- public CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository) {
+ public CompletableFuture<Integer> fireActiveEvents(IEventfulExecutionRunnable eventfulExecutionRunnable) {
+ // todo: add MDC key
+ IEventRepository eventRepository = eventfulExecutionRunnable.getEventRepository();
if (eventRepository.getEventSize() == 0) {
return CompletableFuture.completedFuture(0);
}
@@ -71,6 +78,11 @@ public class EventFirer implements IEventFirer {
}, eventFireThreadPool);
}
+ @Override
+ public void shutdown() {
+ eventFireThreadPool.shutdown();
+ }
+
private void fireAsyncEvent(IEvent event) {
CompletableFuture.runAsync(() -> {
log.info("Begin fire IAsyncEvent: {}", event);
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IDelayEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventAcceptor.java
similarity index 80%
rename from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IDelayEvent.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventAcceptor.java
index c86ea4744f..f9fd9fd86c 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/IDelayEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventAcceptor.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.events;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public interface IDelayEvent {
+import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
- long getEventCreateTime();
+public interface IEventAcceptor {
- long getDelayTime();
+ void accept(IEvent event);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContext.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java
similarity index 80%
rename from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContext.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java
index 818cbd0e10..32724fefc5 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/dag/ITaskExecutionContext.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.dag;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
-public interface ITaskExecutionContext {
+public interface IEventDispatcher {
- TaskInstance getTaskInstance();
+ void dispatch(IEvent event);
}
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationType.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventEngine.java
similarity index 71%
rename from dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationType.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventEngine.java
index 24abbbc855..4b3e760ae2 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/events/WorkflowOperationType.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventEngine.java
@@ -15,22 +15,18 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.events;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public enum WorkflowOperationType {
+public interface IEventEngine {
/**
- * Trigger the workflow instance.
+ * Start the event engine.
*/
- TRIGGER,
- /**
- * Pause the workflow instance, it will pause the running task instances.
- */
- PAUSE,
+ void start();
+
/**
- * Kill the workflow instance, it will kill the running task instances.
+ * Shutdown the event engine. The event engine cannot be restarted after shutdown. This method will block until the event engine is completely shutdown.
*/
- KILL,
- ;
+ void shutdown();
}
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineIT.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventEngineFactory.java
similarity index 85%
rename from dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineIT.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventEngineFactory.java
index ede8b55a37..13f7e3ed9f 100644
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/dag/WorkflowEngineIT.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventEngineFactory.java
@@ -15,8 +15,10 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.server.master.dag;
+package org.apache.dolphinscheduler.workflow.engine.engine;
-public class WorkflowEngineIT {
+public interface IEventEngineFactory {
+
+ IEventEngine createEventEngine();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventFirer.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventFirer.java
similarity index 68%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventFirer.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventFirer.java
index 131bac9412..e32a03d9f3 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventFirer.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventFirer.java
@@ -15,12 +15,14 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.event;
+package org.apache.dolphinscheduler.workflow.engine.engine;
+
+import org.apache.dolphinscheduler.workflow.engine.workflow.IEventfulExecutionRunnable;
import java.util.concurrent.CompletableFuture;
/**
- * The event firer interface used to fire event.
+ * The event firer interface used to fire event for {@link IEventfulExecutionRunnable}.
*
*/
public interface IEventFirer {
@@ -30,6 +32,11 @@ public interface IEventFirer {
*
* @return the count of fired success events
*/
- CompletableFuture<Integer> fireActiveEvents(IEventRepository eventRepository);
+ CompletableFuture<Integer> fireActiveEvents(IEventfulExecutionRunnable eventfulExecutionRunnable);
+
+ /**
+ * Shutdown the event firer, this method will block until all firing task has been completed.
+ */
+ void shutdown();
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
index d1df4df7f5..50ccccae67 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IWorkflowEngine.java
@@ -21,10 +21,16 @@ import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunn
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
/**
- * The WorkflowEngine is responsible for starting, stopping, pausing, and finalizing workflows.
+ * The WorkflowEngine is responsible for starting, stopping, pausing, and finalizing {@link IWorkflowExecutionRunnable}.
+ * All operation on a workflow instance should be done through the WorkflowEngine.
*/
public interface IWorkflowEngine {
+ /**
+ * Start the workflow engine.
+ */
+ void start();
+
/**
* Trigger a workflow to start.
*
@@ -55,4 +61,9 @@ public interface IWorkflowEngine {
*/
void finalizeWorkflow(Integer workflowInstanceId);
+ /**
+ * Shutdown the workflow engine. The workflow engine cannot be restarted after shutdown. This method will block until the workflow engine is completely shutdown.
+ */
+ void shutdown();
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
index 92bec2fe1f..b9c2b05391 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngine.java
@@ -19,19 +19,28 @@ package org.apache.dolphinscheduler.workflow.engine.engine;
import org.apache.dolphinscheduler.workflow.engine.event.WorkflowOperationEvent;
import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunnableNotFoundException;
-import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class WorkflowEngine implements IWorkflowEngine {
- private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+ private final IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository;
- public WorkflowEngine(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ private final IEventEngine eventEngine;
+
+ public WorkflowEngine(IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository,
+ IEventEngine eventEngine) {
this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ this.eventEngine = eventEngine;
+ }
+
+ @Override
+ public void start() {
+ eventEngine.start();
}
@Override
@@ -74,9 +83,15 @@ public class WorkflowEngine implements IWorkflowEngine {
if (workflowExecutionRunnable == null) {
return;
}
+ // todo: If the workflowExecutionRunnable is not finished, we cannot finalize it.
log.info("Finalizing WorkflowExecutionRunnable: {}",
workflowExecutionRunnable.getWorkflowExecutionContext().getWorkflowInstanceName());
workflowExecuteRunnableRepository.removeWorkflowExecutionRunnable(workflowInstanceId);
}
+ @Override
+ public void shutdown() {
+ eventEngine.shutdown();
+ }
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineFactory.java
index 5a32510bd1..cc74baecdd 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineFactory.java
@@ -17,12 +17,38 @@
package org.apache.dolphinscheduler.workflow.engine.engine;
-import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecutionRunnableRepository;
public class WorkflowEngineFactory implements IWorkflowEngineFactory {
+ private static final IWorkflowExecutionRunnableRepository DEFAULT_WORKFLOW_EXECUTION_RUNNABLE_FACTORY =
+ SingletonWorkflowExecutionRunnableRepository.getInstance();
+
+ private IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository =
+ DEFAULT_WORKFLOW_EXECUTION_RUNNABLE_FACTORY;
+
+ private IEventEngine eventEngine;
+
+ private WorkflowEngineFactory() {
+ }
+
+ public static WorkflowEngineFactory newWorkflowEngineFactory() {
+ return new WorkflowEngineFactory();
+ }
+
+ public WorkflowEngineFactory withWorkflowExecuteRunnableRepository(IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository) {
+ this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
+ return this;
+ }
+
+ public WorkflowEngineFactory withEventEngine(IEventEngine eventEngine) {
+ this.eventEngine = eventEngine;
+ return this;
+ }
+
@Override
public IWorkflowEngine createWorkflowEngine() {
- return new WorkflowEngine(SingletonWorkflowExecuteRunnableRepository.getInstance());
+ return new WorkflowEngine(workflowExecuteRunnableRepository, eventEngine);
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventOperatorManager.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventOperatorManager.java
index fb0e3d0a50..f2ed5fdcd3 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventOperatorManager.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/EventOperatorManager.java
@@ -17,20 +17,41 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import lombok.extern.slf4j.Slf4j;
+import java.util.HashMap;
+import java.util.Map;
-import org.springframework.stereotype.Component;
+import lombok.extern.slf4j.Slf4j;
/**
* The event operator manager interface used to get {@link ITaskEventOperator}.
*/
@Slf4j
-@Component
public class EventOperatorManager implements IEventOperatorManager<IEvent> {
+ private static final Map<String, IEventOperator<IEvent>> EVENT_OPERATOR_MAP = new HashMap<>();
+
+ private static final EventOperatorManager INSTANCE = new EventOperatorManager();
+
+ private EventOperatorManager() {
+ }
+
+ public static EventOperatorManager getInstance() {
+ return INSTANCE;
+ }
+
+ public void registerEventOperator(IEventOperator<IEvent> eventOperator) {
+ EVENT_OPERATOR_MAP.put(eventOperator.getClass().getSimpleName(), eventOperator);
+ }
+
@Override
public IEventOperator<IEvent> getEventOperator(IEvent event) {
- return null;
+ if (event == null) {
+ throw new IllegalArgumentException("event cannot be null");
+ }
+ if (event.getEventOperatorClass() == null) {
+ throw new IllegalArgumentException("event operator class cannot be null");
+ }
+ return EVENT_OPERATOR_MAP.get(event.getEventOperatorClass().getSimpleName());
}
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
index 22fd7ec940..bb270dc323 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEvent.java
@@ -19,4 +19,6 @@ package org.apache.dolphinscheduler.workflow.engine.event;
public interface IEvent {
+ Class getEventOperatorClass();
+
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperatorManager.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperatorManager.java
index 68cffa4ecc..406e5619d1 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperatorManager.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/IEventOperatorManager.java
@@ -22,6 +22,8 @@ package org.apache.dolphinscheduler.workflow.engine.event;
*/
public interface IEventOperatorManager<E> {
+ void registerEventOperator(IEventOperator<E> eventOperator);
+
/**
* Get the {@link IEventOperator} for the given event.
*
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
index 1afb6ee7d8..cdeeb30d2b 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/TaskOperationEvent.java
@@ -34,4 +34,8 @@ public class TaskOperationEvent implements ITaskEvent, ISyncEvent {
private TaskOperationType taskOperationType;
+ @Override
+ public Class getEventOperatorClass() {
+ return TaskOperationEventOperator.class;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
index b807e726fa..17ceed448f 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFailedEvent.java
@@ -32,4 +32,8 @@ public class WorkflowFailedEvent implements IWorkflowEvent {
private String failedReason;
+ @Override
+ public Class getEventOperatorClass() {
+ return null;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEvent.java
index 0c23e15f2b..15cfc5926e 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEvent.java
@@ -29,4 +29,9 @@ import lombok.NoArgsConstructor;
public class WorkflowFinalizeEvent implements IWorkflowEvent, ISyncEvent {
private Integer workflowInstanceId;
+
+ @Override
+ public Class getEventOperatorClass() {
+ return WorkflowOperationEventOperator.class;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEventOperator.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEventOperator.java
index 4c64e4c62d..40a6e26ca9 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEventOperator.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinalizeEventOperator.java
@@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.event;
-import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
import lombok.extern.slf4j.Slf4j;
@@ -26,9 +26,9 @@ public class WorkflowFinalizeEventOperator
implements
IWorkflowEventOperator<WorkflowFinalizeEvent> {
- private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+ private final IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository;
- public WorkflowFinalizeEventOperator(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ public WorkflowFinalizeEventOperator(IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository) {
this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
index bd8a610599..6546bfc55e 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowFinishEvent.java
@@ -34,4 +34,8 @@ public class WorkflowFinishEvent implements IWorkflowEvent, ISyncEvent {
private WorkflowExecutionStatus workflowExecutionStatus;
+ @Override
+ public Class getEventOperatorClass() {
+ return null;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
index 4c7e30808f..9f1ecf8db8 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEvent.java
@@ -48,4 +48,8 @@ public class WorkflowOperationEvent implements IWorkflowEvent, ISyncEvent {
return of(workflowInstanceId, WorkflowOperationType.KILL);
}
+ @Override
+ public Class getEventOperatorClass() {
+ return WorkflowOperationEventOperator.class;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
index 59a1d62e05..0822a84f85 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/event/WorkflowOperationEventOperator.java
@@ -18,18 +18,18 @@
package org.apache.dolphinscheduler.workflow.engine.event;
import org.apache.dolphinscheduler.workflow.engine.utils.ExceptionUtils;
-import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecuteRunnableRepository;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionContext;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
+import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnableRepository;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class WorkflowOperationEventOperator implements IWorkflowEventOperator<WorkflowOperationEvent> {
- private final IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository;
+ private final IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository;
- public WorkflowOperationEventOperator(IWorkflowExecuteRunnableRepository workflowExecuteRunnableRepository) {
+ public WorkflowOperationEventOperator(IWorkflowExecutionRunnableRepository workflowExecuteRunnableRepository) {
this.workflowExecuteRunnableRepository = workflowExecuteRunnableRepository;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
index 08bfa53055..f35bf10b74 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IEventfulExecutionRunnable.java
@@ -24,6 +24,10 @@ public interface IEventfulExecutionRunnable {
IEventRepository getEventRepository();
+ boolean isEventFiring();
+
+ void setEventFiring(boolean eventFiring);
+
default void storeEventToTail(IEvent event) {
getEventRepository().storeEventToTail(event);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecuteRunnableRepository.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableRepository.java
similarity index 95%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecuteRunnableRepository.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableRepository.java
index 758cd99a27..3996b02405 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecuteRunnableRepository.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableRepository.java
@@ -19,7 +19,7 @@ package org.apache.dolphinscheduler.workflow.engine.workflow;
import java.util.Collection;
-public interface IWorkflowExecuteRunnableRepository {
+public interface IWorkflowExecutionRunnableRepository {
void storeWorkflowExecutionRunnable(IWorkflowExecutionRunnable workflowExecutionRunnable);
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecuteRunnableRepository.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecutionRunnableRepository.java
similarity index 84%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecuteRunnableRepository.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecutionRunnableRepository.java
index 147f0076ba..d28f9a4fb1 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecuteRunnableRepository.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/SingletonWorkflowExecutionRunnableRepository.java
@@ -21,17 +21,18 @@ import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-public class SingletonWorkflowExecuteRunnableRepository implements IWorkflowExecuteRunnableRepository {
+public class SingletonWorkflowExecutionRunnableRepository implements IWorkflowExecutionRunnableRepository {
- private static final IWorkflowExecuteRunnableRepository INSTANCE = new SingletonWorkflowExecuteRunnableRepository();
+ private static final IWorkflowExecutionRunnableRepository INSTANCE =
+ new SingletonWorkflowExecutionRunnableRepository();
private final Map<Integer, IWorkflowExecutionRunnable> workflowExecutionRunnableMap;
- private SingletonWorkflowExecuteRunnableRepository() {
+ private SingletonWorkflowExecutionRunnableRepository() {
this.workflowExecutionRunnableMap = new ConcurrentHashMap<>();
}
- public static IWorkflowExecuteRunnableRepository getInstance() {
+ public static IWorkflowExecutionRunnableRepository getInstance() {
return INSTANCE;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
index 3e7b5ec7c2..9b55c91639 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/TaskExecutionRunnableFactory.java
@@ -19,7 +19,7 @@ package org.apache.dolphinscheduler.workflow.engine.workflow;
public class TaskExecutionRunnableFactory implements ITaskExecutionRunnableFactory {
- private ITaskExecutionContextFactory taskExecutionContextFactory;
+ private final ITaskExecutionContextFactory taskExecutionContextFactory;
public TaskExecutionRunnableFactory(ITaskExecutionContextFactory taskExecutionContextFactory) {
this.taskExecutionContextFactory = taskExecutionContextFactory;
@@ -32,4 +32,16 @@ public class TaskExecutionRunnableFactory implements ITaskExecutionRunnableFacto
taskExecutionContextFactory.createTaskExecutionContext(taskName, workflowExecutionContext);
return new TaskExecutionRunnable(taskExecutionContext);
}
+
+ @Override
+ public ITaskExecutionRunnable createFailoverTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext) {
+ return null;
+ }
+
+ @Override
+ public ITaskExecutionRunnable createRetryTaskExecutionRunnable(ITaskExecutionRunnable taskExecutionRunnable,
+ IWorkflowExecutionContext workflowExecutionContext) {
+ return null;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
index 01fafcc6b7..9e6fa7c210 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
@@ -23,7 +23,6 @@ import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
import java.util.stream.Collectors;
import lombok.Getter;
@@ -40,16 +39,16 @@ public class WorkflowExecutionDAG implements IWorkflowExecutionDAG {
private final WorkflowDAG workflowDAG;
@Getter
- private final Set<String> startNodeNames;
+ private final List<String> startNodeNames;
public WorkflowExecutionDAG(ITaskExecutionRunnableRepository taskExecutionRunnableRepository,
WorkflowDAG workflowDAG) {
- this(taskExecutionRunnableRepository, workflowDAG, Collections.emptySet());
+ this(taskExecutionRunnableRepository, workflowDAG, Collections.emptyList());
}
public WorkflowExecutionDAG(ITaskExecutionRunnableRepository taskExecutionRunnableRepository,
WorkflowDAG workflowDAG,
- Set<String> startNodeNames) {
+ List<String> startNodeNames) {
this.taskExecutionRunnableRepository = taskExecutionRunnableRepository;
this.workflowDAG = workflowDAG;
this.startNodeNames = startNodeNames;
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
index 7b05d22048..cf609b1f15 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionRunnable.java
@@ -33,6 +33,8 @@ public class WorkflowExecutionRunnable implements IWorkflowExecutionRunnable {
private final IDAGEngine dagEngine;
+ private volatile boolean eventFiring = false;
+
public WorkflowExecutionRunnable(IWorkflowExecutionContext workflowExecutionContext, IDAGEngine dagEngine) {
this.workflowExecutionContext = workflowExecutionContext;
this.dagEngine = dagEngine;
@@ -61,4 +63,14 @@ public class WorkflowExecutionRunnable implements IWorkflowExecutionRunnable {
public IEventRepository getEventRepository() {
return workflowExecutionContext.getEventRepository();
}
+
+ @Override
+ public boolean isEventFiring() {
+ return eventFiring;
+ }
+
+ @Override
+ public void setEventFiring(boolean eventFiring) {
+ this.eventFiring = eventFiring;
+ }
}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
index 1d4553d2a7..40ac09007c 100644
--- a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/assertions/SingletonWorkflowExecuteRunnableRepositoryAssertions.java
@@ -20,17 +20,17 @@ package org.apache.dolphinscheduler.workflow.engine.assertions;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
-import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecutionRunnableRepository;
public class SingletonWorkflowExecuteRunnableRepositoryAssertions {
public static void existWorkflowExecutionRunnable(Integer workflowInstanceId) {
- assertNotNull(SingletonWorkflowExecuteRunnableRepository.getInstance()
+ assertNotNull(SingletonWorkflowExecutionRunnableRepository.getInstance()
.getWorkflowExecutionRunnableById(workflowInstanceId));
}
public static void notExistWorkflowExecutionRunnable(Integer workflowInstanceId) {
- assertNull(SingletonWorkflowExecuteRunnableRepository.getInstance()
+ assertNull(SingletonWorkflowExecutionRunnableRepository.getInstance()
.getWorkflowExecutionRunnableById(workflowInstanceId));
}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
index 6e35706549..482299227f 100644
--- a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/engine/WorkflowEngineTest.java
@@ -9,7 +9,7 @@ import org.apache.dolphinscheduler.workflow.engine.event.WorkflowOperationEvent;
import org.apache.dolphinscheduler.workflow.engine.exception.WorkflowExecuteRunnableNotFoundException;
import org.apache.dolphinscheduler.workflow.engine.workflow.IWorkflowExecutionRunnable;
import org.apache.dolphinscheduler.workflow.engine.workflow.MockWorkflowExecutionRunnableFactory;
-import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecuteRunnableRepository;
+import org.apache.dolphinscheduler.workflow.engine.workflow.SingletonWorkflowExecutionRunnableRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -17,16 +17,21 @@ import org.junit.jupiter.api.Test;
class WorkflowEngineTest {
- private WorkflowEngine workflowEngine;
+ private IWorkflowEngine workflowEngine;
@BeforeEach
public void before() {
- workflowEngine = new WorkflowEngine(SingletonWorkflowExecuteRunnableRepository.getInstance());
+ workflowEngine =
+ new WorkflowEngine(
+ SingletonWorkflowExecutionRunnableRepository.getInstance(),
+ EventEngineFactory.newEventEngineFactory().createEventEngine());
+ workflowEngine.start();
}
@AfterEach
public void after() {
- SingletonWorkflowExecuteRunnableRepository.getInstance().clear();
+ SingletonWorkflowExecutionRunnableRepository.getInstance().clear();
+ workflowEngine.shutdown();
}
@Test
@@ -53,7 +58,7 @@ class WorkflowEngineTest {
MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
Integer workflowInstanceId =
mockWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
- SingletonWorkflowExecuteRunnableRepository.getInstance()
+ SingletonWorkflowExecutionRunnableRepository.getInstance()
.storeWorkflowExecutionRunnable(mockWorkflowExecuteRunnable);
workflowEngine.pauseWorkflow(workflowInstanceId);
@@ -75,7 +80,7 @@ class WorkflowEngineTest {
MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
Integer workflowInstanceId =
mockWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
- SingletonWorkflowExecuteRunnableRepository.getInstance()
+ SingletonWorkflowExecutionRunnableRepository.getInstance()
.storeWorkflowExecutionRunnable(mockWorkflowExecuteRunnable);
workflowEngine.killWorkflow(workflowInstanceId);
@@ -94,7 +99,7 @@ class WorkflowEngineTest {
MockWorkflowExecutionRunnableFactory.createWorkflowExecutionRunnable();
Integer workflowInstanceId =
emptyWorkflowExecuteRunnable.getWorkflowExecutionContext().getWorkflowInstanceId();
- SingletonWorkflowExecuteRunnableRepository.getInstance()
+ SingletonWorkflowExecutionRunnableRepository.getInstance()
.storeWorkflowExecutionRunnable(emptyWorkflowExecuteRunnable);
SingletonWorkflowExecuteRunnableRepositoryAssertions.existWorkflowExecutionRunnable(workflowInstanceId);
(dolphinscheduler) 03/04: Rename Node and Edge
Posted by we...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev_wenjun_refactorMaster
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
commit aa9a8b943191fc988c345a301eb35b1c211e9036
Author: Wenjun Ruan <we...@apache.org>
AuthorDate: Wed Mar 27 10:57:41 2024 +0800
Rename Node and Edge
---
.../dolphinscheduler/workflow/engine/dag/DAG.java | 46 +++--------
.../workflow/engine/dag/DAGNode.java | 92 ----------------------
.../engine/dag/{IDAGNodeAction.java => Edge.java} | 22 +++---
.../engine/dag/{IDAGNode.java => Node.java} | 27 +++++--
.../engine/dag/{IDAGNode.java => NodeContext.java} | 28 ++++---
.../dag/{IDAGNode.java => NodeIdentify.java} | 19 +++--
.../workflow/engine/dag/WorkflowDAG.java | 78 ++++++++++++++----
.../workflow/engine/dag/WorkflowDAGBuilder.java | 8 +-
.../workflow/engine/engine/DAGEngine.java | 8 +-
.../IEventDispatcher.java => workflow/IChain.java} | 9 +--
.../engine/workflow/IWorkflowExecutionDAG.java | 2 +-
.../IWorkflowExecutionRunnableDelegate.java} | 9 +--
.../engine/workflow/WorkflowExecutionDAG.java | 22 +-----
.../engine/dag/{DAGNodeTest.java => NodeTest.java} | 20 ++---
14 files changed, 157 insertions(+), 233 deletions(-)
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
index 63e6370887..aed6193c83 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAG.java
@@ -45,13 +45,13 @@ public interface DAG {
* <li> The post node of 3 is empty.
* <li> The post node of null is 1,4,6.
*
- * @param dagNode the node of the DAG, can be null.
+ * @param node the node of the DAG, can be null.
* @return post node list, sort by priority.
*/
- List<DAGNode> getDirectPostNodes(DAGNode dagNode);
+ List<Node> getDirectPostNodes(Node node);
/**
- * Same with {@link #getDirectPostNodes(DAGNode)}.
+ * Same with {@link #getDirectPostNodes(Node)}.
* <p>
* If the dagNodeName is null, return the nodes which doesn't have inDegrees. Otherwise, return the post nodes of
* the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
@@ -60,13 +60,7 @@ public interface DAG {
* @return post task name list, sort by priority.
* @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
*/
- default List<DAGNode> getDirectPostNodes(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPostNodes(dagNode);
- }
+ List<Node> getDirectPostNodes(String dagNodeName);
/**
* Same with {@link #getDirectPostNodes(String)}. Return the post node names.
@@ -75,13 +69,7 @@ public interface DAG {
* @return post task name list, sort by priority.
* @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
*/
- default List<String> getDirectPostNodeNames(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPostNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
- }
+ List<String> getDirectPostNodeNames(String dagNodeName);
/**
* Get the direct pre node of given dagNode, if the dagNode is null, return the nodes which doesn't have outDegrees.
@@ -97,13 +85,13 @@ public interface DAG {
* <li> The pre node of 3 is 2.
* <li> The pre node of null is 3,5,6.
*
- * @param dagNode the node of the DAG, can be null.
+ * @param node the node of the DAG, can be null.
* @return pre node list, sort by priority.
*/
- List<DAGNode> getDirectPreNodes(DAGNode dagNode);
+ List<Node> getDirectPreNodes(Node node);
/**
- * Same with {@link #getDirectPreNodes(DAGNode)}.
+ * Same with {@link #getDirectPreNodes(Node)}.
* <p>
* If the dagNodeName is null, return the nodes which doesn't have outDegrees. Otherwise, return the pre nodes of
* the given dagNodeName. If the dagNodeName is not null and cannot find the node in DAG, throw IllegalArgumentException.
@@ -112,13 +100,7 @@ public interface DAG {
* @return pre task name list, sort by priority.
* @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
*/
- default List<DAGNode> getDirectPreNodes(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPreNodes(dagNode);
- }
+ List<Node> getDirectPreNodes(String dagNodeName);
/**
* Same with {@link #getDirectPreNodes(String)}. Return the pre node names.
@@ -127,13 +109,7 @@ public interface DAG {
* @return pre task name list, sort by priority.
* @throws IllegalArgumentException if the dagNodeName is not null and cannot find the node in DAG.
*/
- default List<String> getDirectPreNodeNames(String dagNodeName) {
- DAGNode dagNode = getDAGNode(dagNodeName);
- if (dagNodeName != null && dagNode == null) {
- throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
- }
- return getDirectPreNodes(dagNode).stream().map(DAGNode::getNodeName).collect(Collectors.toList());
- }
+ List<String> getDirectPreNodeNames(String dagNodeName);
/**
* Get the node of the DAG by the node name.
@@ -141,6 +117,6 @@ public interface DAG {
* @param nodeName the node name.
* @return the node of the DAG, return null if cannot find the node.
*/
- DAGNode getDAGNode(String nodeName);
+ Node getDAGNode(String nodeName);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNode.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNode.java
deleted file mode 100644
index 2e945a5463..0000000000
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNode.java
+++ /dev/null
@@ -1,92 +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.workflow.engine.dag;
-
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.List;
-
-import lombok.Builder;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-
-/**
- * The node of the DAG.
- * <p>
- * The node contains the node name, the content of the node, the inDegrees and the outDegrees.
- * The inDegrees is the edge from other nodes to the current node, the outDegrees is the edge from the current
- * node to other nodes.
- */
-@Getter
-@Builder
-@NoArgsConstructor
-public class DAGNode implements IDAGNode {
-
- private String nodeName;
-
- /**
- * whether the node is skipped, default is false, which means the node is not skipped.
- * If the node is skipped, the node will not be executed.
- */
- @Builder.Default
- private boolean skip = false;
-
- private List<DAGEdge> inDegrees;
- private List<DAGEdge> outDegrees;
-
- public DAGNode(String nodeName,
- List<DAGEdge> inDegrees,
- List<DAGEdge> outDegrees) {
- this(nodeName, false, inDegrees, outDegrees);
- }
-
- public DAGNode(String nodeName,
- boolean skip,
- List<DAGEdge> inDegrees,
- List<DAGEdge> outDegrees) {
- if (StringUtils.isEmpty(nodeName)) {
- throw new IllegalArgumentException("nodeName cannot be empty");
- }
-
- if (CollectionUtils.isNotEmpty(inDegrees)) {
- inDegrees.forEach(dagEdge -> {
- if (!nodeName.equals(dagEdge.getToNodeName())) {
- throw new IllegalArgumentException(
- "The toNodeName of inDegree should be the nodeName of the node: "
- + nodeName + ", inDegree: " + dagEdge);
- }
- });
- }
-
- if (CollectionUtils.isNotEmpty(outDegrees)) {
- outDegrees.forEach(dagEdge -> {
- if (!nodeName.equals(dagEdge.getFromNodeName())) {
- throw new IllegalArgumentException(
- "The fromNodeName of outDegree should be the nodeName of the node: "
- + nodeName + ", outDegree: " + dagEdge);
- }
- });
- }
-
- this.nodeName = nodeName;
- this.inDegrees = inDegrees;
- this.outDegrees = outDegrees;
- this.skip = skip;
- }
-}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNodeAction.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Edge.java
similarity index 77%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNodeAction.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Edge.java
index 9b6684a37f..bf8a81766c 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNodeAction.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Edge.java
@@ -17,19 +17,19 @@
package org.apache.dolphinscheduler.workflow.engine.dag;
-/**
- * The IDAGNodeAction represent the action of a DAG node.
- */
-public interface IDAGNodeAction {
-
- void run();
-
- void kill();
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
- void pause();
+@Getter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class Edge {
- void success();
+ private NodeIdentify from;
- void failure();
+ private NodeIdentify to;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Node.java
similarity index 58%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Node.java
index c3d85ae3ac..8e8719ac7d 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/Node.java
@@ -17,16 +17,31 @@
package org.apache.dolphinscheduler.workflow.engine.dag;
-import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
-public interface IDAGNode {
+import java.util.List;
- String getNodeName();
+import lombok.Getter;
+import lombok.NoArgsConstructor;
- boolean isSkip();
+/**
+ * The node of the DAG.
+ * <p>
+ * The node contains the node name, the content of the node, the inDegrees and the outDegrees.
+ * The inDegrees is the edge from other nodes to the current node, the outDegrees is the edge from the current
+ * node to other nodes.
+ */
+@Getter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class Node {
- List<DAGEdge> getInDegrees();
+ private NodeIdentify nodeIdentify;
- List<DAGEdge> getOutDegrees();
+ private NodeContext nodeContext;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeContext.java
similarity index 68%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeContext.java
index c3d85ae3ac..5c35b04de9 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeContext.java
@@ -17,16 +17,20 @@
package org.apache.dolphinscheduler.workflow.engine.dag;
-import java.util.List;
-
-public interface IDAGNode {
-
- String getNodeName();
-
- boolean isSkip();
-
- List<DAGEdge> getInDegrees();
-
- List<DAGEdge> getOutDegrees();
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class NodeContext {
+
+ /**
+ * whether the node is skipped, default is false, which means the node is not skipped.
+ * If the node is skipped, the node will not be executed.
+ */
+ private boolean skip = false;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeIdentify.java
similarity index 78%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeIdentify.java
index c3d85ae3ac..d7bf6034c5 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/IDAGNode.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeIdentify.java
@@ -17,16 +17,19 @@
package org.apache.dolphinscheduler.workflow.engine.dag;
-import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
-public interface IDAGNode {
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class NodeIdentify {
- String getNodeName();
+ private Long id;
- boolean isSkip();
-
- List<DAGEdge> getInDegrees();
-
- List<DAGEdge> getOutDegrees();
+ private String name;
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
index c31749af93..1b3cb35e40 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAG.java
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.workflow.engine.dag;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -29,46 +30,91 @@ import java.util.stream.Collectors;
*/
public class WorkflowDAG implements DAG {
- private final Map<String, DAGNode> dagNodeMap;
+ private final Map<NodeIdentify, Node> dagNodeMap;
- public WorkflowDAG(List<DAGNode> dagNodes) {
- this.dagNodeMap = dagNodes.stream().collect(Collectors.toMap(DAGNode::getNodeName, Function.identity()));
+ private final Map<NodeIdentify, List<Node>> outdegreeMap;
+
+ private final Map<NodeIdentify, List<Node>> inDegredMap;
+
+ public WorkflowDAG(List<Node> nodes, List<Edge> edges) {
+ this.dagNodeMap = nodes.stream().collect(Collectors.toMap(Node::getNodeIdentify, Function.identity()));
+ this.outdegreeMap = new HashMap<>();
+ this.inDegredMap = new HashMap<>();
+ // todo:
}
@Override
- public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
- final String nodeName = dagNode.getNodeName();
- if (!dagNodeMap.containsKey(nodeName)) {
+ public List<Node> getDirectPostNodes(Node dagNode) {
+ NodeIdentify nodeIdentify = dagNode.getNodeIdentify();
+ if (!dagNodeMap.containsKey(nodeIdentify)) {
return Collections.emptyList();
}
- DAGNode node = dagNodeMap.get(nodeName);
- List<DAGNode> dagNodes = new ArrayList<>();
+ Node node = dagNodeMap.get(nodeIdentify);
+ List<Node> nodes = new ArrayList<>();
for (DAGEdge edge : node.getOutDegrees()) {
if (dagNodeMap.containsKey(edge.getToNodeName())) {
- dagNodes.add(dagNodeMap.get(edge.getToNodeName()));
+ nodes.add(dagNodeMap.get(edge.getToNodeName()));
}
}
- return dagNodes;
+ return nodes;
+ }
+
+ @Override
+ public List<Node> getDirectPostNodes(String dagNodeName) {
+ Node node = getDAGNode(dagNodeName);
+ if (dagNodeName != null && node == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPostNodes(node);
+ }
+
+ @Override
+ public List<String> getDirectPostNodeNames(String dagNodeName) {
+ Node node = getDAGNode(dagNodeName);
+ if (dagNodeName != null && node == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPostNodes(node).stream()
+ .map(Node::getNodeName)
+ .collect(Collectors.toList());
}
@Override
- public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
+ public List<Node> getDirectPreNodes(Node dagNode) {
final String nodeName = dagNode.getNodeName();
if (!dagNodeMap.containsKey(nodeName)) {
return Collections.emptyList();
}
- DAGNode node = dagNodeMap.get(nodeName);
- List<DAGNode> dagNodes = new ArrayList<>();
+ Node node = dagNodeMap.get(nodeName);
+ List<Node> nodes = new ArrayList<>();
for (DAGEdge edge : node.getInDegrees()) {
if (dagNodeMap.containsKey(edge.getFromNodeName())) {
- dagNodes.add(dagNodeMap.get(edge.getFromNodeName()));
+ nodes.add(dagNodeMap.get(edge.getFromNodeName()));
}
}
- return dagNodes;
+ return nodes;
+ }
+
+ @Override
+ public List<Node> getDirectPreNodes(String dagNodeName) {
+ Node node = getDAGNode(dagNodeName);
+ if (dagNodeName != null && node == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPreNodes(node);
+ }
+
+ @Override
+ public List<String> getDirectPreNodeNames(String dagNodeName) {
+ Node node = getDAGNode(dagNodeName);
+ if (dagNodeName != null && node == null) {
+ throw new IllegalArgumentException("Cannot find the Node: " + dagNodeName + " in DAG");
+ }
+ return getDirectPreNodes(node).stream().map(Node::getNodeName).collect(Collectors.toList());
}
@Override
- public DAGNode getDAGNode(String nodeName) {
+ public Node getDAGNode(String nodeName) {
return dagNodeMap.get(nodeName);
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilder.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilder.java
index fbf666d947..d1387c0de9 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilder.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/dag/WorkflowDAGBuilder.java
@@ -41,7 +41,7 @@ import java.util.Map;
*/
public class WorkflowDAGBuilder {
- private final Map<String, DAGNode> taskNameMap;
+ private final Map<String, Node> taskNameMap;
private WorkflowDAGBuilder() {
this.taskNameMap = new HashMap<>();
@@ -62,7 +62,7 @@ public class WorkflowDAGBuilder {
throw new IllegalArgumentException("TaskNode with name " + nodeName + " already exists");
}
- DAGNode taskNode = DAGNode.builder()
+ Node taskNode = Node.builder()
.nodeName(nodeName)
.inDegrees(new ArrayList<>())
.outDegrees(new ArrayList<>())
@@ -82,7 +82,7 @@ public class WorkflowDAGBuilder {
String toNodeName = dagEdge.getToNodeName();
if (taskNameMap.containsKey(fromNodeName)) {
- DAGNode fromTask = taskNameMap.get(fromNodeName);
+ Node fromTask = taskNameMap.get(fromNodeName);
if (fromTask.getOutDegrees().contains(dagEdge)) {
throw new IllegalArgumentException(
"Edge from " + fromNodeName + " to " + toNodeName + " already exists");
@@ -90,7 +90,7 @@ public class WorkflowDAGBuilder {
fromTask.getOutDegrees().add(dagEdge);
}
if (taskNameMap.containsKey(toNodeName)) {
- DAGNode toTask = taskNameMap.get(toNodeName);
+ Node toTask = taskNameMap.get(toNodeName);
if (toTask.getInDegrees().contains(dagEdge)) {
throw new IllegalArgumentException(
"Edge from " + fromNodeName + " to " + toNodeName + " already exists");
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
index d5273367ef..0a847583b4 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/DAGEngine.java
@@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.engine;
-import org.apache.dolphinscheduler.workflow.engine.dag.DAGNode;
+import org.apache.dolphinscheduler.workflow.engine.dag.Node;
import org.apache.dolphinscheduler.workflow.engine.event.TaskOperationEvent;
import org.apache.dolphinscheduler.workflow.engine.event.TaskOperationType;
import org.apache.dolphinscheduler.workflow.engine.workflow.ITaskExecutionRunnable;
@@ -50,8 +50,8 @@ public class DAGEngine implements IDAGEngine {
@Override
public void triggerTask(String taskName) {
IWorkflowExecutionDAG workflowExecutionDAG = workflowExecutionContext.getWorkflowExecutionDAG();
- DAGNode dagNode = workflowExecutionDAG.getDAGNode(taskName);
- if (dagNode == null) {
+ Node node = workflowExecutionDAG.getDAGNode(taskName);
+ if (node == null) {
log.error("Cannot find the DAGNode for task: {}", taskName);
return;
}
@@ -63,7 +63,7 @@ public class DAGEngine implements IDAGEngine {
return;
}
- if (dagNode.isSkip()) {
+ if (node.isSkip()) {
log.info("The task: {} is skipped", taskName);
triggerNextTasks(taskName);
return;
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
similarity index 80%
copy from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java
copy to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
index 32724fefc5..5c86c8b6f7 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IChain.java
@@ -15,12 +15,5 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.engine;
-
-import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
-
-public interface IEventDispatcher {
-
- void dispatch(IEvent event);
-
+package org.apache.dolphinscheduler.workflow.engine.workflow;public interface IChain {
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
index d76ee1a64a..81732181ae 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionDAG.java
@@ -24,7 +24,7 @@ import java.util.List;
/**
* The WorkflowExecutionDAG represent the running workflow DAG.
*/
-public interface IWorkflowExecutionDAG extends DAG {
+public interface IWorkflowExecutionDAG {
List<String> getStartNodeNames();
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegate.java
similarity index 80%
rename from dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java
rename to dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegate.java
index 32724fefc5..5eae17192e 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/engine/IEventDispatcher.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/IWorkflowExecutionRunnableDelegate.java
@@ -15,12 +15,5 @@
* limitations under the License.
*/
-package org.apache.dolphinscheduler.workflow.engine.engine;
-
-import org.apache.dolphinscheduler.workflow.engine.event.IEvent;
-
-public interface IEventDispatcher {
-
- void dispatch(IEvent event);
-
+package org.apache.dolphinscheduler.workflow.engine.workflow;public interface IWorkflowExecutionRunnableDelegate {
}
diff --git a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
index 9e6fa7c210..6bcd123b2a 100644
--- a/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
+++ b/dolphinscheduler-workflow-engine/src/main/java/org/apache/dolphinscheduler/workflow/engine/workflow/WorkflowExecutionDAG.java
@@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.workflow.engine.workflow;
-import org.apache.dolphinscheduler.workflow.engine.dag.DAGNode;
+import org.apache.dolphinscheduler.workflow.engine.dag.Node;
import org.apache.dolphinscheduler.workflow.engine.dag.WorkflowDAG;
import java.util.ArrayList;
@@ -80,13 +80,13 @@ public class WorkflowExecutionDAG implements IWorkflowExecutionDAG {
@Override
public boolean isTaskAbleToBeTriggered(String taskNodeName) {
// todo: Check whether the workflow instance is finished or ready to finish.
- List<DAGNode> directPreNodes = getDirectPreNodes(taskNodeName);
+ List<Node> directPreNodes = getDirectPreNodes(taskNodeName);
if (log.isDebugEnabled()) {
log.debug("Begin to check whether the task {} is able to be triggered.", taskNodeName);
log.debug("Task {} directly dependent on the task: {}.", taskNodeName,
- directPreNodes.stream().map(DAGNode::getNodeName).collect(Collectors.toList()));
+ directPreNodes.stream().map(Node::getNodeName).collect(Collectors.toList()));
}
- for (DAGNode directPreNode : directPreNodes) {
+ for (Node directPreNode : directPreNodes) {
if (directPreNode.isSkip()) {
log.debug("The task {} is skipped.", directPreNode.getNodeName());
continue;
@@ -105,19 +105,5 @@ public class WorkflowExecutionDAG implements IWorkflowExecutionDAG {
taskExecutionRunnableRepository.storeTaskExecutionRunnable(taskExecutionRunnable);
}
- @Override
- public List<DAGNode> getDirectPostNodes(DAGNode dagNode) {
- return workflowDAG.getDirectPostNodes(dagNode);
- }
-
- @Override
- public List<DAGNode> getDirectPreNodes(DAGNode dagNode) {
- return workflowDAG.getDirectPreNodes(dagNode);
- }
-
- @Override
- public DAGNode getDAGNode(String nodeName) {
- return workflowDAG.getDAGNode(nodeName);
- }
}
diff --git a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeTest.java b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeTest.java
similarity index 89%
rename from dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeTest.java
rename to dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeTest.java
index 0502450f82..2962ce8c68 100644
--- a/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/DAGNodeTest.java
+++ b/dolphinscheduler-workflow-engine/src/test/java/org/apache/dolphinscheduler/workflow/engine/dag/NodeTest.java
@@ -12,12 +12,12 @@ import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists;
-class DAGNodeTest {
+class NodeTest {
@Test
void buildDAGNode_EmptyNodeName() {
IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
- () -> DAGNode.builder()
+ () -> Node.builder()
.inDegrees(new ArrayList<>())
.outDegrees(new ArrayList<>())
.build());
@@ -27,7 +27,7 @@ class DAGNodeTest {
@Test
void buildDAGNode_BadInDegree() {
IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
- () -> DAGNode.builder()
+ () -> Node.builder()
.nodeName("A")
.inDegrees(Lists.newArrayList(DAGEdge.builder()
.fromNodeName(null)
@@ -42,7 +42,7 @@ class DAGNodeTest {
@Test
void buildDAGNode_NiceInDegree() {
- assertDoesNotThrow(() -> DAGNode.builder()
+ assertDoesNotThrow(() -> Node.builder()
.nodeName("A")
.inDegrees(Lists.newArrayList(DAGEdge.builder()
.fromNodeName(null)
@@ -55,7 +55,7 @@ class DAGNodeTest {
@Test
void buildDAGNode_BadOutDegree() {
IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
- () -> DAGNode.builder()
+ () -> Node.builder()
.nodeName("A")
.inDegrees(new ArrayList<>())
.outDegrees(Lists.newArrayList(DAGEdge.builder()
@@ -70,7 +70,7 @@ class DAGNodeTest {
@Test
void buildDAGNode_NiceOutDegree() {
- assertDoesNotThrow(() -> DAGNode.builder()
+ assertDoesNotThrow(() -> Node.builder()
.nodeName("A")
.inDegrees(new ArrayList<>())
.outDegrees(Lists.newArrayList(DAGEdge.builder()
@@ -82,23 +82,23 @@ class DAGNodeTest {
@Test
void buildDAGNode_NotSkip() {
- DAGNode dagNode = DAGNode.builder()
+ Node node = Node.builder()
.nodeName("A")
.inDegrees(new ArrayList<>())
.outDegrees(new ArrayList<>())
.build();
- assertFalse(dagNode.isSkip());
+ assertFalse(node.isSkip());
}
@Test
void buildDAGNode_Skip() {
- DAGNode dagNode = DAGNode.builder()
+ Node node = Node.builder()
.nodeName("A")
.skip(true)
.inDegrees(new ArrayList<>())
.outDegrees(new ArrayList<>())
.build();
- assertTrue(dagNode.isSkip());
+ assertTrue(node.isSkip());
}
}