-
Notifications
You must be signed in to change notification settings - Fork 5k
[Fix-17454] The "Workflow execute type" in workflow definition and the "Mode of execution" when executing workflows are unavailable #17458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...olphinscheduler/server/master/engine/command/handler/RecoverSerialWaitCommandHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * 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.engine.command.handler; | ||
|
|
||
| import org.apache.dolphinscheduler.common.enums.CommandType; | ||
| import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; | ||
| import org.apache.dolphinscheduler.dao.entity.Command; | ||
| import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; | ||
| import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; | ||
| import org.apache.dolphinscheduler.server.master.engine.graph.IWorkflowGraph; | ||
| import org.apache.dolphinscheduler.server.master.engine.graph.WorkflowExecutionGraph; | ||
| import org.apache.dolphinscheduler.server.master.engine.graph.WorkflowGraphTopologyLogicalVisitor; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.TaskExecutionRunnable; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.TaskExecutionRunnableBuilder; | ||
| import org.apache.dolphinscheduler.server.master.runner.WorkflowExecuteContext.WorkflowExecuteContextBuilder; | ||
|
|
||
| import java.util.Set; | ||
| import java.util.function.BiConsumer; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.ApplicationContext; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * This handler used to handle {@link CommandType#RECOVER_SERIAL_WAIT}. | ||
| * Will recover a workflow instance from serial wait state to running state. | ||
| */ | ||
| @Slf4j | ||
| @Component | ||
| public class RecoverSerialWaitCommandHandler extends AbstractCommandHandler { | ||
|
|
||
| @Autowired | ||
| private WorkflowInstanceDao workflowInstanceDao; | ||
|
|
||
| @Autowired | ||
| private ApplicationContext applicationContext; | ||
|
|
||
| /** | ||
| * Generate the recover workflow instance from serial wait state. | ||
| * Will use the origin workflow instance, but will update the following fields: | ||
| * <ul> | ||
| * <li>state: from SERIAL_WAIT to RUNNING_EXECUTION</li> | ||
| * <li>command type</li> | ||
| * <li>start time</li> | ||
| * <li>restart time</li> | ||
| * </ul> | ||
| */ | ||
| @Override | ||
| protected void assembleWorkflowInstance(final WorkflowExecuteContextBuilder workflowExecuteContextBuilder) { | ||
| final Command command = workflowExecuteContextBuilder.getCommand(); | ||
| final int workflowInstanceId = command.getWorkflowInstanceId(); | ||
|
|
||
| log.info("Recovering workflow instance from SERIAL_WAIT state, instance id: {}", workflowInstanceId); | ||
|
|
||
| final WorkflowInstance workflowInstance = workflowInstanceDao.queryOptionalById(workflowInstanceId) | ||
| .orElseThrow(() -> new IllegalArgumentException("Cannot find WorkflowInstance:" + workflowInstanceId)); | ||
|
|
||
| log.info("Found workflow instance: {} (id: {}), current state: {}", | ||
| workflowInstance.getName(), workflowInstance.getId(), workflowInstance.getState()); | ||
|
|
||
| // Check if the workflow instance is in SERIAL_WAIT state | ||
| if (workflowInstance.getState() != WorkflowExecutionStatus.SERIAL_WAIT) { | ||
| log.warn("Workflow instance {} is not in SERIAL_WAIT state, current state: {}", | ||
| workflowInstance.getName(), workflowInstance.getState()); | ||
| throw new IllegalStateException("Workflow instance is not in SERIAL_WAIT state"); | ||
| } | ||
|
|
||
| workflowInstance.setStateWithDesc(WorkflowExecutionStatus.RUNNING_EXECUTION, command.getCommandType().name()); | ||
| workflowInstance.setCommandType(command.getCommandType()); | ||
| workflowInstanceDao.updateById(workflowInstance); | ||
|
|
||
| log.info("Successfully recovered workflow instance {} from SERIAL_WAIT to RUNNING_EXECUTION", | ||
| workflowInstance.getName()); | ||
| workflowExecuteContextBuilder.setWorkflowInstance(workflowInstance); | ||
| } | ||
|
|
||
| @Override | ||
| protected void assembleWorkflowExecutionGraph(final WorkflowExecuteContextBuilder workflowExecuteContextBuilder) { | ||
| // For serial wait recovery, we need to create the workflow execution graph from the beginning | ||
| // This is similar to RunWorkflowCommandHandler | ||
| final IWorkflowGraph workflowGraph = workflowExecuteContextBuilder.getWorkflowGraph(); | ||
| final WorkflowExecutionGraph workflowExecutionGraph = new WorkflowExecutionGraph(); | ||
| final BiConsumer<String, Set<String>> taskExecutionRunnableCreator = (task, successors) -> { | ||
| final TaskExecutionRunnableBuilder taskExecutionRunnableBuilder = | ||
| TaskExecutionRunnableBuilder | ||
| .builder() | ||
| .workflowExecutionGraph(workflowExecutionGraph) | ||
| .workflowDefinition(workflowExecuteContextBuilder.getWorkflowDefinition()) | ||
| .project(workflowExecuteContextBuilder.getProject()) | ||
| .workflowInstance(workflowExecuteContextBuilder.getWorkflowInstance()) | ||
| .taskDefinition(workflowGraph.getTaskNodeByName(task)) | ||
| .workflowEventBus(workflowExecuteContextBuilder.getWorkflowEventBus()) | ||
| .applicationContext(applicationContext) | ||
| .build(); | ||
| workflowExecutionGraph.addNode(new TaskExecutionRunnable(taskExecutionRunnableBuilder)); | ||
| workflowExecutionGraph.addEdge(task, successors); | ||
| }; | ||
|
|
||
| final WorkflowGraphTopologyLogicalVisitor workflowGraphTopologyLogicalVisitor = | ||
| WorkflowGraphTopologyLogicalVisitor.builder() | ||
| .taskDependType(workflowExecuteContextBuilder.getWorkflowInstance().getTaskDependType()) | ||
| .onWorkflowGraph(workflowGraph) | ||
| .fromTask(parseStartNodesFromWorkflowInstance(workflowExecuteContextBuilder)) | ||
| .doVisitFunction(taskExecutionRunnableCreator) | ||
| .build(); | ||
| workflowGraphTopologyLogicalVisitor.visit(); | ||
|
|
||
| workflowExecuteContextBuilder.setWorkflowExecutionGraph(workflowExecutionGraph); | ||
| } | ||
|
|
||
| @Override | ||
| public CommandType commandType() { | ||
| return CommandType.RECOVER_SERIAL_WAIT; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...hinscheduler/server/master/engine/workflow/strategy/WorkflowExecutionStrategyService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.engine.workflow.strategy; | ||
|
|
||
| import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; | ||
| import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; | ||
|
|
||
| public interface WorkflowExecutionStrategyService { | ||
|
|
||
| boolean checkAndApplyExecutionStrategy(WorkflowDefinition workflowDefinition, | ||
| WorkflowInstance workflowInstance); | ||
|
|
||
| boolean handleParallelStrategy(WorkflowDefinition workflowDefinition, | ||
| WorkflowInstance workflowInstance); | ||
|
|
||
| boolean handleSerialWaitStrategy(WorkflowDefinition workflowDefinition, | ||
| WorkflowInstance workflowInstance); | ||
|
|
||
| boolean handleSerialDiscardStrategy(WorkflowDefinition workflowDefinition, | ||
| WorkflowInstance workflowInstance); | ||
|
|
||
| boolean handleSerialPriorityStrategy(WorkflowDefinition workflowDefinition, | ||
| WorkflowInstance workflowInstance); | ||
|
|
||
| void killWorkflowInstance(WorkflowInstance workflowInstance); | ||
|
|
||
| void checkAndWakeUpNextSerialInstance(WorkflowInstance completedInstance); | ||
|
|
||
| void wakeUpSerialWaitingInstance(WorkflowInstance waitingInstance); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Useless parameter Note