|
@@ -105,6 +105,7 @@ import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper;
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
|
|
|
import org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper;
|
|
|
+import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao;
|
|
|
import org.apache.dolphinscheduler.dao.utils.DagHelper;
|
|
|
import org.apache.dolphinscheduler.dao.utils.DqRuleUtils;
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
|
|
@@ -180,9 +181,13 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
@Autowired
|
|
|
private ProcessDefinitionLogMapper processDefineLogMapper;
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private ProcessInstanceMapper processInstanceMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProcessInstanceDao processInstanceDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DataSourceMapper dataSourceMapper;
|
|
|
|
|
@@ -301,7 +306,7 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
return null;
|
|
|
}
|
|
|
} else {
|
|
|
- saveProcessInstance(processInstance);
|
|
|
+ processInstanceDao.upsertProcessInstance(processInstance);
|
|
|
}
|
|
|
setSubProcessParam(processInstance);
|
|
|
deleteCommandWithCheck(command.getId());
|
|
@@ -309,10 +314,10 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
}
|
|
|
|
|
|
protected void saveSerialProcess(ProcessInstance processInstance, ProcessDefinition processDefinition) {
|
|
|
- processInstance.setState(WorkflowExecutionStatus.SERIAL_WAIT);
|
|
|
- saveProcessInstance(processInstance);
|
|
|
-
|
|
|
-
|
|
|
+ processInstance.setStateWithDesc(WorkflowExecutionStatus.SERIAL_WAIT, "wait by serial_wait strategy");
|
|
|
+ processInstanceDao.upsertProcessInstance(processInstance);
|
|
|
+
|
|
|
+
|
|
|
if (processDefinition.getExecutionType().typeIsSerialWait()) {
|
|
|
List<ProcessInstance> runningProcessInstances =
|
|
|
this.processInstanceMapper.queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId(
|
|
@@ -320,8 +325,8 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
processInstance.getProcessDefinitionVersion(), Constants.RUNNING_PROCESS_STATE,
|
|
|
processInstance.getId());
|
|
|
if (CollectionUtils.isEmpty(runningProcessInstances)) {
|
|
|
- processInstance.setState(WorkflowExecutionStatus.SUBMITTED_SUCCESS);
|
|
|
- saveProcessInstance(processInstance);
|
|
|
+ processInstance.setStateWithDesc(WorkflowExecutionStatus.SUBMITTED_SUCCESS, "submit from serial_wait strategy");
|
|
|
+ processInstanceDao.upsertProcessInstance(processInstance);
|
|
|
}
|
|
|
} else if (processDefinition.getExecutionType().typeIsSerialDiscard()) {
|
|
|
List<ProcessInstance> runningProcessInstances =
|
|
@@ -330,12 +335,12 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
processInstance.getProcessDefinitionVersion(), Constants.RUNNING_PROCESS_STATE,
|
|
|
processInstance.getId());
|
|
|
if (CollectionUtils.isNotEmpty(runningProcessInstances)) {
|
|
|
- processInstance.setState(WorkflowExecutionStatus.STOP);
|
|
|
- saveProcessInstance(processInstance);
|
|
|
+ processInstance.setStateWithDesc(WorkflowExecutionStatus.STOP, "stop by serial_discard strategy");
|
|
|
+ processInstanceDao.upsertProcessInstance(processInstance);
|
|
|
return;
|
|
|
}
|
|
|
- processInstance.setState(WorkflowExecutionStatus.SUBMITTED_SUCCESS);
|
|
|
- saveProcessInstance(processInstance);
|
|
|
+ processInstance.setStateWithDesc(WorkflowExecutionStatus.SUBMITTED_SUCCESS, "submit from serial_discard strategy");
|
|
|
+ processInstanceDao.upsertProcessInstance(processInstance);
|
|
|
} else if (processDefinition.getExecutionType().typeIsSerialPriority()) {
|
|
|
List<ProcessInstance> runningProcessInstances =
|
|
|
this.processInstanceMapper.queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId(
|
|
@@ -345,8 +350,8 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
for (ProcessInstance info : runningProcessInstances) {
|
|
|
info.setCommandType(CommandType.STOP);
|
|
|
info.addHistoryCmd(CommandType.STOP);
|
|
|
- info.setState(WorkflowExecutionStatus.READY_STOP);
|
|
|
- int update = updateProcessInstance(info);
|
|
|
+ info.setStateWithDesc(WorkflowExecutionStatus.READY_STOP, "ready stop by serial_priority strategy");
|
|
|
+ int update = processInstanceDao.updateProcessInstance(info);
|
|
|
|
|
|
if (update > 0) {
|
|
|
WorkflowStateEventChangeCommand workflowStateEventChangeCommand =
|
|
@@ -360,8 +365,8 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- processInstance.setState(WorkflowExecutionStatus.SUBMITTED_SUCCESS);
|
|
|
- saveProcessInstance(processInstance);
|
|
|
+ processInstance.setStateWithDesc(WorkflowExecutionStatus.SUBMITTED_SUCCESS, "submit by serial_priority strategy");
|
|
|
+ processInstanceDao.upsertProcessInstance(processInstance);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -742,7 +747,7 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
ProcessInstance processInstance = new ProcessInstance(processDefinition);
|
|
|
processInstance.setProcessDefinitionCode(processDefinition.getCode());
|
|
|
processInstance.setProcessDefinitionVersion(processDefinition.getVersion());
|
|
|
- processInstance.setState(WorkflowExecutionStatus.RUNNING_EXECUTION);
|
|
|
+ processInstance.setStateWithDesc(WorkflowExecutionStatus.RUNNING_EXECUTION, "init running");
|
|
|
processInstance.setRecovery(Flag.NO);
|
|
|
processInstance.setStartTime(new Date());
|
|
|
|
|
@@ -1046,7 +1051,7 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- processInstance.setState(runStatus);
|
|
|
+ processInstance.setStateWithDesc(runStatus, commandType.getDescp());
|
|
|
return processInstance;
|
|
|
}
|
|
|
|
|
@@ -1158,7 +1163,7 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
paramMap.put(CMD_PARAM_SUB_PROCESS, String.valueOf(subProcessInstance.getId()));
|
|
|
subProcessInstance.setCommandParam(JSONUtils.toJsonString(paramMap));
|
|
|
subProcessInstance.setIsSubProcess(Flag.YES);
|
|
|
- this.saveProcessInstance(subProcessInstance);
|
|
|
+ processInstanceDao.upsertProcessInstance(subProcessInstance);
|
|
|
}
|
|
|
|
|
|
String parentInstanceId = paramMap.get(CMD_PARAM_SUB_PROCESS_PARENT_INSTANCE_ID);
|
|
@@ -1169,7 +1174,7 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
joinGlobalParams(parentInstance.getGlobalParams(), subProcessInstance.getGlobalParams()));
|
|
|
subProcessInstance
|
|
|
.setVarPool(joinVarPool(parentInstance.getVarPool(), subProcessInstance.getVarPool()));
|
|
|
- this.saveProcessInstance(subProcessInstance);
|
|
|
+ processInstanceDao.upsertProcessInstance(subProcessInstance);
|
|
|
} else {
|
|
|
logger.error("sub process command params error, cannot find parent instance: {} ", cmdParam);
|
|
|
}
|
|
@@ -1510,8 +1515,8 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
*/
|
|
|
private void initSubInstanceState(ProcessInstance childInstance) {
|
|
|
if (childInstance != null) {
|
|
|
- childInstance.setState(WorkflowExecutionStatus.RUNNING_EXECUTION);
|
|
|
- updateProcessInstance(childInstance);
|
|
|
+ childInstance.setStateWithDesc(WorkflowExecutionStatus.RUNNING_EXECUTION, "init sub workflow instance");
|
|
|
+ processInstanceDao.updateProcessInstance(childInstance);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1640,24 +1645,6 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * insert or update work process instance to data base
|
|
|
- *
|
|
|
- * @param processInstance processInstance
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void saveProcessInstance(ProcessInstance processInstance) {
|
|
|
- if (processInstance == null) {
|
|
|
- logger.error("save error, process instance is null!");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (processInstance.getId() != 0) {
|
|
|
- processInstanceMapper.updateById(processInstance);
|
|
|
- } else {
|
|
|
- processInstanceMapper.insert(processInstance);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* insert or update command
|
|
|
*
|
|
@@ -1940,17 +1927,6 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
return processInstance;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * update process instance
|
|
|
- *
|
|
|
- * @param processInstance processInstance
|
|
|
- * @return update process instance result
|
|
|
- */
|
|
|
- @Override
|
|
|
- public int updateProcessInstance(ProcessInstance processInstance) {
|
|
|
- return processInstanceMapper.updateById(processInstance);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* for show in page of taskInstance
|
|
|
*/
|
|
@@ -2121,20 +2097,6 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
return dataSourceMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * update process instance state by id
|
|
|
- *
|
|
|
- * @param processInstanceId processInstanceId
|
|
|
- * @param executionStatus executionStatus
|
|
|
- * @return update process result
|
|
|
- */
|
|
|
- @Override
|
|
|
- public int updateProcessInstanceState(Integer processInstanceId, WorkflowExecutionStatus executionStatus) {
|
|
|
- ProcessInstance instance = processInstanceMapper.selectById(processInstanceId);
|
|
|
- instance.setState(executionStatus);
|
|
|
- return processInstanceMapper.updateById(instance);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* find process instance by the task id
|
|
|
*
|
|
@@ -3190,8 +3152,8 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
.filter(instance -> instance.getState().isFailure() || instance.getState().isKill())
|
|
|
.map(TaskInstance::getId).collect(Collectors.toList());
|
|
|
if (failTaskList.size() == 1 && failTaskList.contains(taskInstanceId)) {
|
|
|
- processInstance.setState(WorkflowExecutionStatus.SUCCESS);
|
|
|
- updateProcessInstance(processInstance);
|
|
|
+ processInstance.setStateWithDesc(WorkflowExecutionStatus.SUCCESS, "success by task force success");
|
|
|
+ processInstanceDao.updateProcessInstance(processInstance);
|
|
|
}
|
|
|
}
|
|
|
}
|