|
|
@ -20,6 +20,7 @@ import cn.escheduler.common.Constants; |
|
|
|
import cn.escheduler.common.enums.*; |
|
|
|
import cn.escheduler.common.enums.*; |
|
|
|
import cn.escheduler.common.model.DateInterval; |
|
|
|
import cn.escheduler.common.model.DateInterval; |
|
|
|
import cn.escheduler.common.model.TaskNode; |
|
|
|
import cn.escheduler.common.model.TaskNode; |
|
|
|
|
|
|
|
import cn.escheduler.common.process.Property; |
|
|
|
import cn.escheduler.common.queue.ITaskQueue; |
|
|
|
import cn.escheduler.common.queue.ITaskQueue; |
|
|
|
import cn.escheduler.common.queue.TaskQueueFactory; |
|
|
|
import cn.escheduler.common.queue.TaskQueueFactory; |
|
|
|
import cn.escheduler.common.task.subprocess.SubProcessParameters; |
|
|
|
import cn.escheduler.common.task.subprocess.SubProcessParameters; |
|
|
@ -41,6 +42,7 @@ import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import static cn.escheduler.common.Constants.*; |
|
|
|
import static cn.escheduler.common.Constants.*; |
|
|
|
import static cn.escheduler.dao.datasource.ConnectionFactory.getMapper; |
|
|
|
import static cn.escheduler.dao.datasource.ConnectionFactory.getMapper; |
|
|
@ -689,41 +691,62 @@ public class ProcessDao extends AbstractBaseDao { |
|
|
|
* handle sub work process instance, update relation table and command parameters |
|
|
|
* handle sub work process instance, update relation table and command parameters |
|
|
|
* set sub work process flag, extends parent work process command parameters. |
|
|
|
* set sub work process flag, extends parent work process command parameters. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessInstance setSubProcessParam(ProcessInstance processInstance){ |
|
|
|
public ProcessInstance setSubProcessParam(ProcessInstance subProcessInstance){ |
|
|
|
String cmdParam = processInstance.getCommandParam(); |
|
|
|
String cmdParam = subProcessInstance.getCommandParam(); |
|
|
|
if(StringUtils.isEmpty(cmdParam)){ |
|
|
|
if(StringUtils.isEmpty(cmdParam)){ |
|
|
|
return processInstance; |
|
|
|
return subProcessInstance; |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String, String> paramMap = JSONUtils.toMap(cmdParam); |
|
|
|
Map<String, String> paramMap = JSONUtils.toMap(cmdParam); |
|
|
|
// write sub process id into cmd param.
|
|
|
|
// write sub process id into cmd param.
|
|
|
|
if(paramMap.containsKey(CMDPARAM_SUB_PROCESS) |
|
|
|
if(paramMap.containsKey(CMDPARAM_SUB_PROCESS) |
|
|
|
&& CMDPARAM_EMPTY_SUB_PROCESS.equals(paramMap.get(CMDPARAM_SUB_PROCESS))){ |
|
|
|
&& CMDPARAM_EMPTY_SUB_PROCESS.equals(paramMap.get(CMDPARAM_SUB_PROCESS))){ |
|
|
|
paramMap.remove(CMDPARAM_SUB_PROCESS); |
|
|
|
paramMap.remove(CMDPARAM_SUB_PROCESS); |
|
|
|
paramMap.put(CMDPARAM_SUB_PROCESS, String.valueOf(processInstance.getId())); |
|
|
|
paramMap.put(CMDPARAM_SUB_PROCESS, String.valueOf(subProcessInstance.getId())); |
|
|
|
processInstance.setCommandParam(JSONUtils.toJson(paramMap)); |
|
|
|
subProcessInstance.setCommandParam(JSONUtils.toJson(paramMap)); |
|
|
|
processInstance.setIsSubProcess(Flag.YES); |
|
|
|
subProcessInstance.setIsSubProcess(Flag.YES); |
|
|
|
this.saveProcessInstance(processInstance); |
|
|
|
this.saveProcessInstance(subProcessInstance); |
|
|
|
} |
|
|
|
} |
|
|
|
// copy parent instance user def params to sub process..
|
|
|
|
// copy parent instance user def params to sub process..
|
|
|
|
String parentInstanceId = paramMap.get(CMDPARAM_SUB_PROCESS_PARENT_INSTANCE_ID); |
|
|
|
String parentInstanceId = paramMap.get(CMDPARAM_SUB_PROCESS_PARENT_INSTANCE_ID); |
|
|
|
if(StringUtils.isNotEmpty(parentInstanceId)){ |
|
|
|
if(StringUtils.isNotEmpty(parentInstanceId)){ |
|
|
|
ProcessInstance parentInstance = findProcessInstanceDetailById(Integer.parseInt(parentInstanceId)); |
|
|
|
ProcessInstance parentInstance = findProcessInstanceDetailById(Integer.parseInt(parentInstanceId)); |
|
|
|
if(parentInstance != null){ |
|
|
|
if(parentInstance != null){ |
|
|
|
processInstance.setGlobalParams(parentInstance.getGlobalParams()); |
|
|
|
subProcessInstance.setGlobalParams( |
|
|
|
this.saveProcessInstance(processInstance); |
|
|
|
joinGlobalParams(parentInstance.getGlobalParams(), subProcessInstance.getGlobalParams())); |
|
|
|
|
|
|
|
this.saveProcessInstance(subProcessInstance); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
logger.error("sub process command params error, cannot find parent instance: {} ", cmdParam); |
|
|
|
logger.error("sub process command params error, cannot find parent instance: {} ", cmdParam); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ProcessInstanceMap processInstanceMap = JSONUtils.parseObject(cmdParam, ProcessInstanceMap.class); |
|
|
|
ProcessInstanceMap processInstanceMap = JSONUtils.parseObject(cmdParam, ProcessInstanceMap.class); |
|
|
|
if(processInstanceMap == null || processInstanceMap.getParentProcessInstanceId() == 0){ |
|
|
|
if(processInstanceMap == null || processInstanceMap.getParentProcessInstanceId() == 0){ |
|
|
|
return processInstance; |
|
|
|
return subProcessInstance; |
|
|
|
} |
|
|
|
} |
|
|
|
// update sub process id to process map table
|
|
|
|
// update sub process id to process map table
|
|
|
|
processInstanceMap.setProcessInstanceId(processInstance.getId()); |
|
|
|
processInstanceMap.setProcessInstanceId(subProcessInstance.getId()); |
|
|
|
|
|
|
|
|
|
|
|
this.updateWorkProcessInstanceMap(processInstanceMap); |
|
|
|
this.updateWorkProcessInstanceMap(processInstanceMap); |
|
|
|
return processInstance; |
|
|
|
return subProcessInstance; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* join parent global params into sub process. |
|
|
|
|
|
|
|
* only the keys doesn't in sub process global would be joined. |
|
|
|
|
|
|
|
* @param parentGlobalParams |
|
|
|
|
|
|
|
* @param subGlobalParams |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String joinGlobalParams(String parentGlobalParams, String subGlobalParams){ |
|
|
|
|
|
|
|
List<Property> parentPropertyList = JSONUtils.toList(parentGlobalParams, Property.class); |
|
|
|
|
|
|
|
List<Property> subPropertyList = JSONUtils.toList(subGlobalParams, Property.class); |
|
|
|
|
|
|
|
Map<String,String> subMap = subPropertyList.stream().collect(Collectors.toMap(Property::getProp, Property::getValue)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(Property parent : parentPropertyList){ |
|
|
|
|
|
|
|
if(!subMap.containsKey(parent.getProp())){ |
|
|
|
|
|
|
|
subPropertyList.add(parent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return JSONUtils.toJson(subPropertyList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -898,7 +921,11 @@ public class ProcessDao extends AbstractBaseDao { |
|
|
|
taskInstance.setFlag(Flag.NO); |
|
|
|
taskInstance.setFlag(Flag.NO); |
|
|
|
updateTaskInstance(taskInstance); |
|
|
|
updateTaskInstance(taskInstance); |
|
|
|
// crate new task instance
|
|
|
|
// crate new task instance
|
|
|
|
taskInstance.setRetryTimes(taskInstance.getRetryTimes() + 1 ); |
|
|
|
if(taskInstance.getState() != ExecutionStatus.NEED_FAULT_TOLERANCE){ |
|
|
|
|
|
|
|
taskInstance.setRetryTimes(taskInstance.getRetryTimes() + 1 ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
taskInstance.setEndTime(null); |
|
|
|
|
|
|
|
taskInstance.setStartTime(new Date()); |
|
|
|
taskInstance.setFlag(Flag.YES); |
|
|
|
taskInstance.setFlag(Flag.YES); |
|
|
|
taskInstance.setHost(null); |
|
|
|
taskInstance.setHost(null); |
|
|
|
taskInstance.setId(0); |
|
|
|
taskInstance.setId(0); |
|
|
|