Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class PauseWorkflowInstanceExecutorDelegate
public Void execute(PauseWorkflowInstanceOperation workflowInstanceControlRequest) {
final WorkflowInstance workflowInstance = workflowInstanceControlRequest.workflowInstance;
exceptionIfWorkflowInstanceCannotPause(workflowInstance);
if (ifWorkflowInstanceCanDirectPauseInDB(workflowInstance)) {
if (workflowInstance.getState().isCanDirectPauseInDB()) {
directPauseInDB(workflowInstance);
} else {
pauseInMaster(workflowInstance);
Expand All @@ -55,18 +55,14 @@ public Void execute(PauseWorkflowInstanceOperation workflowInstanceControlReques

private void exceptionIfWorkflowInstanceCannotPause(WorkflowInstance workflowInstance) {
WorkflowExecutionStatus workflowInstanceState = workflowInstance.getState();
if (workflowInstanceState.canPause()) {
if (workflowInstanceState.isCanPause()) {
return;
}
throw new ServiceException(
"The workflow instance: " + workflowInstance.getName() + " status is " + workflowInstanceState
+ ", can not pause");
}

private boolean ifWorkflowInstanceCanDirectPauseInDB(WorkflowInstance workflowInstance) {
return workflowInstance.getState().canDirectPauseInDB();
}

private void directPauseInDB(WorkflowInstance workflowInstance) {
workflowInstanceDao.updateWorkflowInstanceState(
workflowInstance.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class RecoverSuspendedWorkflowInstanceExecutorDelegate
@Override
public Void execute(RecoverSuspendedWorkflowInstanceOperation workflowInstanceControlRequest) {
final WorkflowInstance workflowInstance = workflowInstanceControlRequest.workflowInstance;
if (!workflowInstance.getState().isPause() && !workflowInstance.getState().isStop()) {
if (!workflowInstance.getState().isPaused() && !workflowInstance.getState().isStopped()) {
throw new ServiceException(
String.format("The workflow instance: %s state is %s, cannot recovery", workflowInstance.getName(),
workflowInstance.getState()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class RepeatRunningWorkflowInstanceExecutorDelegate
@Override
public Void execute(RepeatRunningWorkflowInstanceOperation workflowInstanceControlRequest) {
final WorkflowInstance workflowInstance = workflowInstanceControlRequest.workflowInstance;
if (workflowInstance.getState() == null || !workflowInstance.getState().isFinished()) {
if (workflowInstance.getState() == null || !workflowInstance.getState().isFinalState()) {
throw new ServiceException(
String.format("The workflow instance: %s status is %s, cannot repeat running",
workflowInstance.getName(), workflowInstance.getState()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Void execute(StopWorkflowInstanceOperation workflowInstanceControlRequest
final WorkflowInstance workflowInstance = workflowInstanceControlRequest.workflowInstance;
exceptionIfWorkflowInstanceCannotStop(workflowInstance);

if (ifWorkflowInstanceCanDirectStopInDB(workflowInstance)) {
if (workflowInstance.getState().isCanDirectStopInDB()) {
directStopInDB(workflowInstance);
} else {
stopInMaster(workflowInstance);
Expand All @@ -56,18 +56,14 @@ public Void execute(StopWorkflowInstanceOperation workflowInstanceControlRequest

void exceptionIfWorkflowInstanceCannotStop(WorkflowInstance workflowInstance) {
final WorkflowExecutionStatus workflowInstanceState = workflowInstance.getState();
if (workflowInstanceState.canStop()) {
if (workflowInstanceState.isCanStop()) {
return;
}
throw new ServiceException(
"The workflow instance: " + workflowInstance.getName() + " status is " + workflowInstanceState
+ ", can not stop");
}

boolean ifWorkflowInstanceCanDirectStopInDB(WorkflowInstance workflowInstance) {
return workflowInstance.getState().canDirectStopInDB();
}

void directStopInDB(WorkflowInstance workflowInstance) {
workflowInstanceDao.updateWorkflowInstanceState(
workflowInstance.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public WorkflowExecuteResponse executeTask(User loginUser,
WorkflowInstance workflowInstance = processService.findWorkflowInstanceDetailById(workflowInstanceId)
.orElseThrow(() -> new ServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, workflowInstanceId));

if (!workflowInstance.getState().isFinished()) {
if (!workflowInstance.getState().isFinalState()) {
log.error("Can not execute task for workflow instance which is not finished, workflowInstanceId:{}.",
workflowInstanceId);
putMsg(response, Status.WORKFLOW_INSTANCE_IS_NOT_FINISHED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void forceTaskSuccess(User loginUser, long projectCode, Integer taskInsta
WorkflowInstance workflowInstance = workflowInstanceDao.queryOptionalById(task.getWorkflowInstanceId())
.orElseThrow(
() -> new ServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, task.getWorkflowInstanceId()));
if (!workflowInstance.getState().isFinished()) {
if (!workflowInstance.getState().isFinalState()) {
throw new ServiceException("The workflow instance is not finished: " + workflowInstance.getState()
+ " cannot force start task instance");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void deleteTenantById(User loginUser, int id) throws Exception {
private List<WorkflowInstance> getWorkflowInstancesByTenant(Tenant tenant) {
return workflowInstanceMapper.queryByTenantCodeAndStatus(
tenant.getTenantCode(),
WorkflowExecutionStatus.getNotTerminalStatus());
WorkflowExecutionStatus.NOT_TERMINAL_STATES);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public Map<String, Object> deleteWorkerGroupById(User loginUser, Integer id) {
}
List<WorkflowInstance> workflowInstances = workflowInstanceMapper.queryByWorkerGroupNameAndStatus(
workerGroup.getName(),
WorkflowExecutionStatus.getNotTerminalStatus());
WorkflowExecutionStatus.NOT_TERMINAL_STATES);
if (CollectionUtils.isNotEmpty(workflowInstances)) {
List<Integer> workflowInstanceIds =
workflowInstances.stream().map(WorkflowInstance::getId).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ private void workflowDefinitionUsedInOtherTaskValid(WorkflowDefinition workflowD

// check workflow instances is already running
List<WorkflowInstance> workflowInstances = workflowInstanceService.queryByWorkflowDefinitionCodeAndStatus(
workflowDefinition.getCode(), WorkflowExecutionStatus.getNotTerminalStatus());
workflowDefinition.getCode(), WorkflowExecutionStatus.NOT_TERMINAL_STATES);
if (CollectionUtils.isNotEmpty(workflowInstances)) {
throw new ServiceException(Status.DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL, workflowInstances.size());
}
Expand Down Expand Up @@ -2405,7 +2405,7 @@ public void deleteWorkflowDefinitionVersion(User loginUser,
List<WorkflowInstance> workflowInstances = workflowInstanceService.queryByWorkflowCodeVersionStatus(
code,
version,
WorkflowExecutionStatus.getNotTerminalStatus());
WorkflowExecutionStatus.NOT_TERMINAL_STATES);
if (CollectionUtils.isNotEmpty(workflowInstances)) {
throw new ServiceException(Status.DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL, workflowInstances.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ public Map<String, Object> updateWorkflowInstance(User loginUser, long projectCo
return result;
}
// check workflow instance status
if (!workflowInstance.getState().isFinished()) {
if (!workflowInstance.getState().isFinalState()) {
log.warn("workflow Instance state is {} so can not update workflow instance, workflowInstanceId:{}.",
workflowInstance.getState().getDesc(), workflowInstanceId);
workflowInstance.getState().name(), workflowInstanceId);
putMsg(result, WORKFLOW_INSTANCE_STATE_OPERATION_ERROR,
workflowInstance.getName(), workflowInstance.getState().toString(), "update");
return result;
Expand Down Expand Up @@ -835,9 +835,9 @@ public void deleteWorkflowInstanceById(User loginUser, Integer workflowInstanceI
projectService.checkProjectAndAuthThrowException(loginUser, project,
ApiFuncIdentificationConstant.INSTANCE_DELETE);
// check workflow instance status
if (!workflowInstance.getState().isFinished()) {
if (!workflowInstance.getState().isFinalState()) {
log.warn("workflow Instance state is {} so can not delete workflow instance, workflowInstanceId:{}.",
workflowInstance.getState().getDesc(), workflowInstanceId);
workflowInstance.getState().name(), workflowInstanceId);
throw new ServiceException(WORKFLOW_INSTANCE_STATE_OPERATION_ERROR, workflowInstance.getName(),
workflowInstance.getState(), "delete");
}
Expand Down Expand Up @@ -1076,7 +1076,7 @@ public void deleteWorkflowInstanceByWorkflowDefinitionCode(long workflowDefiniti
}
log.info("Begin to delete workflow instance, workflow definition code: {}", workflowDefinitionCode);
for (WorkflowInstance workflowInstance : workflowInstances) {
if (!workflowInstance.getState().isFinished()) {
if (!workflowInstance.getState().isFinalState()) {
log.warn("Workflow instance is not finished cannot delete, workflow instance id:{}",
workflowInstance.getId());
throw new ServiceException(WORKFLOW_INSTANCE_STATE_OPERATION_ERROR, workflowInstance.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void testDeleteById() throws Exception {
workerGroup.setName("测试");
Mockito.when(workerGroupDao.queryById(12)).thenReturn(workerGroup);
Mockito.when(workflowInstanceMapper.queryByWorkerGroupNameAndStatus("测试",
WorkflowExecutionStatus.getNotTerminalStatus()))
WorkflowExecutionStatus.NOT_TERMINAL_STATES))
.thenReturn(null);
Mockito.when(workerGroupDao.deleteById(12)).thenReturn(true);
Mockito.when(workflowInstanceMapper.updateWorkflowInstanceByWorkerGroupName("测试", "")).thenReturn(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,13 @@ void exceptionIfWorkflowInstanceCannotStop_canNotStop(WorkflowExecutionStatus wo
@EnumSource(value = WorkflowExecutionStatus.class, names = {
"SERIAL_WAIT"})
void ifWorkflowInstanceCanDirectStopInDB_canDirectStopInDB(WorkflowExecutionStatus workflowExecutionStatus) {
WorkflowInstance workflowInstance = new WorkflowInstance();
workflowInstance.setName("Workflow-1");
workflowInstance.setState(workflowExecutionStatus);
Assertions
.assertTrue(stopWorkflowInstanceExecutorDelegate.ifWorkflowInstanceCanDirectStopInDB(workflowInstance));
Assertions.assertTrue(workflowExecutionStatus.isCanDirectStopInDB());
}

@ParameterizedTest
@EnumSource(value = WorkflowExecutionStatus.class, names = {
"SERIAL_WAIT"}, mode = EnumSource.Mode.EXCLUDE)
void ifWorkflowInstanceCanDirectStopInDB_canNotDirectStopInDB(WorkflowExecutionStatus workflowExecutionStatus) {
WorkflowInstance workflowInstance = new WorkflowInstance();
workflowInstance.setName("Workflow-1");
workflowInstance.setState(workflowExecutionStatus);
Assertions.assertFalse(
stopWorkflowInstanceExecutorDelegate.ifWorkflowInstanceCanDirectStopInDB(workflowInstance));
Assertions.assertFalse(workflowExecutionStatus.isCanDirectStopInDB());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void testDeleteTenantById() {
baseServiceLogger)).thenReturn(true);
when(tenantMapper.queryById(1)).thenReturn(getTenant());
when(workflowInstanceMapper.queryByTenantCodeAndStatus(tenantCode,
WorkflowExecutionStatus.getNotTerminalStatus()))
WorkflowExecutionStatus.NOT_TERMINAL_STATES))
.thenReturn(getInstanceList());
when(scheduleMapper.queryScheduleListByTenant(tenantCode)).thenReturn(getScheduleList());
when(userMapper.queryUserListByTenant(3)).thenReturn(getUserList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void giveRunningProcess_whenDeleteWorkerGroupById_expectFailed() {
List<WorkflowInstance> workflowInstances = new ArrayList<WorkflowInstance>();
workflowInstances.add(workflowInstance);
when(workflowInstanceMapper.queryByWorkerGroupNameAndStatus(workerGroup.getName(),
WorkflowExecutionStatus.getNotTerminalStatus()))
WorkflowExecutionStatus.NOT_TERMINAL_STATES))
.thenReturn(workflowInstances);

Map<String, Object> deleteFailed = workerGroupService.deleteWorkerGroupById(loginUser, 1);
Expand All @@ -255,7 +255,7 @@ public void giveValidParams_whenDeleteWorkerGroupById_expectSuccess() {
WorkerGroup workerGroup = getWorkerGroup(1);
when(workerGroupDao.queryById(1)).thenReturn(workerGroup);
when(workflowInstanceMapper.queryByWorkerGroupNameAndStatus(workerGroup.getName(),
WorkflowExecutionStatus.getNotTerminalStatus())).thenReturn(null);
WorkflowExecutionStatus.NOT_TERMINAL_STATES)).thenReturn(null);

when(workerGroupDao.deleteById(1)).thenReturn(true);

Expand Down
Loading
Loading