|
|
|
@ -208,13 +208,12 @@ public class ProcessService {
|
|
|
|
|
* |
|
|
|
|
* @param logger logger |
|
|
|
|
* @param host host |
|
|
|
|
* @param validThreadNum validThreadNum |
|
|
|
|
* @param command found command |
|
|
|
|
* @param processDefinitionCacheMaps |
|
|
|
|
* @return process instance |
|
|
|
|
*/ |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public ProcessInstance handleCommand(Logger logger, String host, int validThreadNum, Command command) { |
|
|
|
|
ProcessInstance processInstance = constructProcessInstance(command, host); |
|
|
|
|
public ProcessInstance handleCommand(Logger logger, String host, Command command, HashMap<String, ProcessDefinition> processDefinitionCacheMaps) { |
|
|
|
|
ProcessInstance processInstance = constructProcessInstance(command, host, processDefinitionCacheMaps); |
|
|
|
|
// cannot construct process instance, return null
|
|
|
|
|
if (processInstance == null) { |
|
|
|
|
logger.error("scan command, command parameter is error: {}", command); |
|
|
|
@ -235,7 +234,6 @@ public class ProcessService {
|
|
|
|
|
* @param command command |
|
|
|
|
* @param message message |
|
|
|
|
*/ |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void moveToErrorCommand(Command command, String message) { |
|
|
|
|
ErrorCommand errorCommand = new ErrorCommand(command, message); |
|
|
|
|
this.errorCommandMapper.insert(errorCommand); |
|
|
|
@ -286,15 +284,6 @@ public class ProcessService {
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* find one command from queue list |
|
|
|
|
* |
|
|
|
|
* @return command |
|
|
|
|
*/ |
|
|
|
|
public Command findOneCommand() { |
|
|
|
|
return commandMapper.getOneToRun(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* get command page |
|
|
|
|
* |
|
|
|
@ -547,7 +536,9 @@ public class ProcessService {
|
|
|
|
|
processInstance.getWorkerGroup(), |
|
|
|
|
processInstance.getEnvironmentCode(), |
|
|
|
|
processInstance.getProcessInstancePriority(), |
|
|
|
|
processInstance.getDryRun() |
|
|
|
|
processInstance.getDryRun(), |
|
|
|
|
processInstance.getId(), |
|
|
|
|
processInstance.getProcessDefinitionVersion() |
|
|
|
|
); |
|
|
|
|
saveCommand(command); |
|
|
|
|
return; |
|
|
|
@ -746,39 +737,28 @@ public class ProcessService {
|
|
|
|
|
* |
|
|
|
|
* @param command command |
|
|
|
|
* @param host host |
|
|
|
|
* @param processDefinitionCacheMaps |
|
|
|
|
* @return process instance |
|
|
|
|
*/ |
|
|
|
|
private ProcessInstance constructProcessInstance(Command command, String host) { |
|
|
|
|
private ProcessInstance constructProcessInstance(Command command, String host, HashMap<String, ProcessDefinition> processDefinitionCacheMaps) { |
|
|
|
|
ProcessInstance processInstance; |
|
|
|
|
ProcessDefinition processDefinition; |
|
|
|
|
CommandType commandType = command.getCommandType(); |
|
|
|
|
Map<String, String> cmdParam = JSONUtils.toMap(command.getCommandParam()); |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinitionByCommand(command.getProcessDefinitionCode(), cmdParam); |
|
|
|
|
String key = String.format("%d-%d", command.getProcessDefinitionCode(), command.getProcessDefinitionVersion()); |
|
|
|
|
if (processDefinitionCacheMaps.containsKey(key)) { |
|
|
|
|
processDefinition = processDefinitionCacheMaps.get(key); |
|
|
|
|
} else { |
|
|
|
|
processDefinition = this.findProcessDefinition(command.getProcessDefinitionCode(), command.getProcessDefinitionVersion()); |
|
|
|
|
if (processDefinition != null) { |
|
|
|
|
processDefinitionCacheMaps.put(key, processDefinition); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (processDefinition == null) { |
|
|
|
|
logger.error("cannot find the work process define! define code : {}", command.getProcessDefinitionCode()); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (cmdParam != null) { |
|
|
|
|
int processInstanceId = 0; |
|
|
|
|
// recover from failure or pause tasks
|
|
|
|
|
if (cmdParam.containsKey(Constants.CMD_PARAM_RECOVER_PROCESS_ID_STRING)) { |
|
|
|
|
String processId = cmdParam.get(Constants.CMD_PARAM_RECOVER_PROCESS_ID_STRING); |
|
|
|
|
processInstanceId = Integer.parseInt(processId); |
|
|
|
|
if (processInstanceId == 0) { |
|
|
|
|
logger.error("command parameter is error, [ ProcessInstanceId ] is 0"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} else if (cmdParam.containsKey(Constants.CMD_PARAM_SUB_PROCESS)) { |
|
|
|
|
// sub process map
|
|
|
|
|
String pId = cmdParam.get(Constants.CMD_PARAM_SUB_PROCESS); |
|
|
|
|
processInstanceId = Integer.parseInt(pId); |
|
|
|
|
} else if (cmdParam.containsKey(Constants.CMD_PARAM_RECOVERY_WAITING_THREAD)) { |
|
|
|
|
// waiting thread command
|
|
|
|
|
String pId = cmdParam.get(Constants.CMD_PARAM_RECOVERY_WAITING_THREAD); |
|
|
|
|
processInstanceId = Integer.parseInt(pId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Map<String, String> cmdParam = JSONUtils.toMap(command.getCommandParam()); |
|
|
|
|
int processInstanceId = command.getProcessInstanceId(); |
|
|
|
|
if (processInstanceId == 0) { |
|
|
|
|
processInstance = generateNewProcessInstance(processDefinition, command, cmdParam); |
|
|
|
|
} else { |
|
|
|
@ -786,8 +766,9 @@ public class ProcessService {
|
|
|
|
|
if (processInstance == null) { |
|
|
|
|
return processInstance; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (cmdParam != null) { |
|
|
|
|
CommandType commandTypeIfComplement = getCommandTypeIfComplement(processInstance, command); |
|
|
|
|
|
|
|
|
|
// reset global params while repeat running is needed by cmdParam
|
|
|
|
|
if (commandTypeIfComplement == CommandType.REPEAT_RUNNING) { |
|
|
|
|
setGlobalParamIfCommanded(processDefinition, cmdParam); |
|
|
|
@ -814,20 +795,14 @@ public class ProcessService {
|
|
|
|
|
if (cmdParam.containsKey(Constants.CMD_PARAM_SUB_PROCESS)) { |
|
|
|
|
processInstance.setCommandParam(command.getCommandParam()); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// generate one new process instance
|
|
|
|
|
processInstance = generateNewProcessInstance(processDefinition, command, cmdParam); |
|
|
|
|
} |
|
|
|
|
if (Boolean.FALSE.equals(checkCmdParam(command, cmdParam))) { |
|
|
|
|
logger.error("command parameter check failed!"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (command.getScheduleTime() != null) { |
|
|
|
|
processInstance.setScheduleTime(command.getScheduleTime()); |
|
|
|
|
} |
|
|
|
|
processInstance.setHost(host); |
|
|
|
|
|
|
|
|
|
ExecutionStatus runStatus = ExecutionStatus.RUNNING_EXECUTION; |
|
|
|
|
int runTime = processInstance.getRunTimes(); |
|
|
|
|
switch (commandType) { |
|
|
|
@ -1274,7 +1249,7 @@ public class ProcessService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
String processParam = getSubWorkFlowParam(instanceMap, parentProcessInstance, fatherParams); |
|
|
|
|
|
|
|
|
|
int subProcessInstanceId = childInstance == null ? 0 : childInstance.getId(); |
|
|
|
|
return new Command( |
|
|
|
|
commandType, |
|
|
|
|
TaskDependType.TASK_POST, |
|
|
|
@ -1288,7 +1263,9 @@ public class ProcessService {
|
|
|
|
|
task.getWorkerGroup(), |
|
|
|
|
task.getEnvironmentCode(), |
|
|
|
|
parentProcessInstance.getProcessInstancePriority(), |
|
|
|
|
parentProcessInstance.getDryRun() |
|
|
|
|
parentProcessInstance.getDryRun(), |
|
|
|
|
subProcessInstanceId, |
|
|
|
|
parentProcessInstance.getProcessDefinitionVersion() |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1886,6 +1863,8 @@ public class ProcessService {
|
|
|
|
|
//2 insert into recover command
|
|
|
|
|
Command cmd = new Command(); |
|
|
|
|
cmd.setProcessDefinitionCode(processDefinition.getCode()); |
|
|
|
|
cmd.setProcessDefinitionVersion(processDefinition.getVersion()); |
|
|
|
|
cmd.setProcessInstanceId(processInstance.getId()); |
|
|
|
|
cmd.setCommandParam(String.format("{\"%s\":%d}", Constants.CMD_PARAM_RECOVER_PROCESS_ID_STRING, processInstance.getId())); |
|
|
|
|
cmd.setExecutorId(processInstance.getExecutorId()); |
|
|
|
|
cmd.setCommandType(CommandType.RECOVER_TOLERANCE_FAULT_PROCESS); |
|
|
|
|