Skip to content

Commit ef26fe2

Browse files
committed
Fix workflow can be deleted which contains failover instance
1 parent 590d16f commit ef26fe2

26 files changed

Lines changed: 150 additions & 353 deletions

File tree

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/PauseWorkflowInstanceExecutorDelegate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public Void execute(PauseWorkflowInstanceOperation workflowInstanceControlReques
5555

5656
private void exceptionIfWorkflowInstanceCannotPause(WorkflowInstance workflowInstance) {
5757
WorkflowExecutionStatus workflowInstanceState = workflowInstance.getState();
58-
if (workflowInstanceState.canPause()) {
58+
if (workflowInstanceState.isCanPause()) {
5959
return;
6060
}
6161
throw new ServiceException(
@@ -64,7 +64,7 @@ private void exceptionIfWorkflowInstanceCannotPause(WorkflowInstance workflowIns
6464
}
6565

6666
private boolean ifWorkflowInstanceCanDirectPauseInDB(WorkflowInstance workflowInstance) {
67-
return workflowInstance.getState().canDirectPauseInDB();
67+
return workflowInstance.getState().isCanDirectPauseInDB();
6868
}
6969

7070
private void directPauseInDB(WorkflowInstance workflowInstance) {

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/RecoverSuspendedWorkflowInstanceExecutorDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class RecoverSuspendedWorkflowInstanceExecutorDelegate
4242
@Override
4343
public Void execute(RecoverSuspendedWorkflowInstanceOperation workflowInstanceControlRequest) {
4444
final WorkflowInstance workflowInstance = workflowInstanceControlRequest.workflowInstance;
45-
if (!workflowInstance.getState().isPause() && !workflowInstance.getState().isStop()) {
45+
if (!workflowInstance.getState().isPaused() && !workflowInstance.getState().isStopped()) {
4646
throw new ServiceException(
4747
String.format("The workflow instance: %s state is %s, cannot recovery", workflowInstance.getName(),
4848
workflowInstance.getState()));

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/RepeatRunningWorkflowInstanceExecutorDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class RepeatRunningWorkflowInstanceExecutorDelegate
4242
@Override
4343
public Void execute(RepeatRunningWorkflowInstanceOperation workflowInstanceControlRequest) {
4444
final WorkflowInstance workflowInstance = workflowInstanceControlRequest.workflowInstance;
45-
if (workflowInstance.getState() == null || !workflowInstance.getState().isFinished()) {
45+
if (workflowInstance.getState() == null || !workflowInstance.getState().isFinalState()) {
4646
throw new ServiceException(
4747
String.format("The workflow instance: %s status is %s, cannot repeat running",
4848
workflowInstance.getName(), workflowInstance.getState()));

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/executor/workflow/StopWorkflowInstanceExecutorDelegate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Void execute(StopWorkflowInstanceOperation workflowInstanceControlRequest
5656

5757
void exceptionIfWorkflowInstanceCannotStop(WorkflowInstance workflowInstance) {
5858
final WorkflowExecutionStatus workflowInstanceState = workflowInstance.getState();
59-
if (workflowInstanceState.canStop()) {
59+
if (workflowInstanceState.isCanStop()) {
6060
return;
6161
}
6262
throw new ServiceException(
@@ -65,7 +65,7 @@ void exceptionIfWorkflowInstanceCannotStop(WorkflowInstance workflowInstance) {
6565
}
6666

6767
boolean ifWorkflowInstanceCanDirectStopInDB(WorkflowInstance workflowInstance) {
68-
return workflowInstance.getState().canDirectStopInDB();
68+
return workflowInstance.getState().isCanDirectStopInDB();
6969
}
7070

7171
void directStopInDB(WorkflowInstance workflowInstance) {

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public WorkflowExecuteResponse executeTask(User loginUser,
329329
WorkflowInstance workflowInstance = processService.findWorkflowInstanceDetailById(workflowInstanceId)
330330
.orElseThrow(() -> new ServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, workflowInstanceId));
331331

332-
if (!workflowInstance.getState().isFinished()) {
332+
if (!workflowInstance.getState().isFinalState()) {
333333
log.error("Can not execute task for workflow instance which is not finished, workflowInstanceId:{}.",
334334
workflowInstanceId);
335335
putMsg(response, Status.WORKFLOW_INSTANCE_IS_NOT_FINISHED);

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void forceTaskSuccess(User loginUser, long projectCode, Integer taskInsta
218218
WorkflowInstance workflowInstance = workflowInstanceDao.queryOptionalById(task.getWorkflowInstanceId())
219219
.orElseThrow(
220220
() -> new ServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, task.getWorkflowInstanceId()));
221-
if (!workflowInstance.getState().isFinished()) {
221+
if (!workflowInstance.getState().isFinalState()) {
222222
throw new ServiceException("The workflow instance is not finished: " + workflowInstance.getState()
223223
+ " cannot force start task instance");
224224
}

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public void deleteTenantById(User loginUser, int id) throws Exception {
258258
private List<WorkflowInstance> getWorkflowInstancesByTenant(Tenant tenant) {
259259
return workflowInstanceMapper.queryByTenantCodeAndStatus(
260260
tenant.getTenantCode(),
261-
WorkflowExecutionStatus.getNotTerminalStatus());
261+
WorkflowExecutionStatus.NOT_TERMINAL_STATES);
262262
}
263263

264264
/**

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public Map<String, Object> deleteWorkerGroupById(User loginUser, Integer id) {
346346
}
347347
List<WorkflowInstance> workflowInstances = workflowInstanceMapper.queryByWorkerGroupNameAndStatus(
348348
workerGroup.getName(),
349-
WorkflowExecutionStatus.getNotTerminalStatus());
349+
WorkflowExecutionStatus.NOT_TERMINAL_STATES);
350350
if (CollectionUtils.isNotEmpty(workflowInstances)) {
351351
List<Integer> workflowInstanceIds =
352352
workflowInstances.stream().map(WorkflowInstance::getId).collect(Collectors.toList());

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ private void workflowDefinitionUsedInOtherTaskValid(WorkflowDefinition workflowD
10541054

10551055
// check workflow instances is already running
10561056
List<WorkflowInstance> workflowInstances = workflowInstanceService.queryByWorkflowDefinitionCodeAndStatus(
1057-
workflowDefinition.getCode(), WorkflowExecutionStatus.getNotTerminalStatus());
1057+
workflowDefinition.getCode(), WorkflowExecutionStatus.NOT_TERMINAL_STATES);
10581058
if (CollectionUtils.isNotEmpty(workflowInstances)) {
10591059
throw new ServiceException(Status.DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL, workflowInstances.size());
10601060
}
@@ -2405,7 +2405,7 @@ public void deleteWorkflowDefinitionVersion(User loginUser,
24052405
List<WorkflowInstance> workflowInstances = workflowInstanceService.queryByWorkflowCodeVersionStatus(
24062406
code,
24072407
version,
2408-
WorkflowExecutionStatus.getNotTerminalStatus());
2408+
WorkflowExecutionStatus.NOT_TERMINAL_STATES);
24092409
if (CollectionUtils.isNotEmpty(workflowInstances)) {
24102410
throw new ServiceException(Status.DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL, workflowInstances.size());
24112411
}

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ public Map<String, Object> updateWorkflowInstance(User loginUser, long projectCo
655655
return result;
656656
}
657657
// check workflow instance status
658-
if (!workflowInstance.getState().isFinished()) {
658+
if (!workflowInstance.getState().isFinalState()) {
659659
log.warn("workflow Instance state is {} so can not update workflow instance, workflowInstanceId:{}.",
660-
workflowInstance.getState().getDesc(), workflowInstanceId);
660+
workflowInstance.getState().name(), workflowInstanceId);
661661
putMsg(result, WORKFLOW_INSTANCE_STATE_OPERATION_ERROR,
662662
workflowInstance.getName(), workflowInstance.getState().toString(), "update");
663663
return result;
@@ -835,9 +835,9 @@ public void deleteWorkflowInstanceById(User loginUser, Integer workflowInstanceI
835835
projectService.checkProjectAndAuthThrowException(loginUser, project,
836836
ApiFuncIdentificationConstant.INSTANCE_DELETE);
837837
// check workflow instance status
838-
if (!workflowInstance.getState().isFinished()) {
838+
if (!workflowInstance.getState().isFinalState()) {
839839
log.warn("workflow Instance state is {} so can not delete workflow instance, workflowInstanceId:{}.",
840-
workflowInstance.getState().getDesc(), workflowInstanceId);
840+
workflowInstance.getState().name(), workflowInstanceId);
841841
throw new ServiceException(WORKFLOW_INSTANCE_STATE_OPERATION_ERROR, workflowInstance.getName(),
842842
workflowInstance.getState(), "delete");
843843
}
@@ -1076,7 +1076,7 @@ public void deleteWorkflowInstanceByWorkflowDefinitionCode(long workflowDefiniti
10761076
}
10771077
log.info("Begin to delete workflow instance, workflow definition code: {}", workflowDefinitionCode);
10781078
for (WorkflowInstance workflowInstance : workflowInstances) {
1079-
if (!workflowInstance.getState().isFinished()) {
1079+
if (!workflowInstance.getState().isFinalState()) {
10801080
log.warn("Workflow instance is not finished cannot delete, workflow instance id:{}",
10811081
workflowInstance.getId());
10821082
throw new ServiceException(WORKFLOW_INSTANCE_STATE_OPERATION_ERROR, workflowInstance.getName(),

0 commit comments

Comments
 (0)