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