Browse Source

[Improvement][Master] Construct processInstance may NPE when master handling command (#12056)

* [Improvement][Master] Construct processInstance may NPE when master handling command

* use an enpty map

Co-authored-by: xuhaihui <xuhaihui@cmss.chinamobile.com>
3.2.0-release
xuhhui 2 years ago committed by GitHub
parent
commit
6466cc7c41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java

17
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java

@ -169,6 +169,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.micrometer.core.annotation.Counted; import io.micrometer.core.annotation.Counted;
/** /**
@ -938,6 +939,9 @@ public class ProcessServiceImpl implements ProcessService {
throw new IllegalArgumentException("Cannot find the process definition for this workflowInstance"); throw new IllegalArgumentException("Cannot find the process definition for this workflowInstance");
} }
Map<String, String> cmdParam = JSONUtils.toMap(command.getCommandParam()); Map<String, String> cmdParam = JSONUtils.toMap(command.getCommandParam());
if(cmdParam == null){
cmdParam = new HashMap<>();
}
int processInstanceId = command.getProcessInstanceId(); int processInstanceId = command.getProcessInstanceId();
if (processInstanceId == 0) { if (processInstanceId == 0) {
processInstance = generateNewProcessInstance(processDefinition, command, cmdParam); processInstance = generateNewProcessInstance(processDefinition, command, cmdParam);
@ -947,7 +951,7 @@ public class ProcessServiceImpl implements ProcessService {
return null; return null;
} }
} }
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) {
@ -965,18 +969,19 @@ public class ProcessServiceImpl implements ProcessService {
processInstance.getScheduleTime(), timezoneId); processInstance.getScheduleTime(), timezoneId);
processInstance.setGlobalParams(globalParams); processInstance.setGlobalParams(globalParams);
processInstance.setProcessDefinition(processDefinition); processInstance.setProcessDefinition(processDefinition);
}
// reset command parameter // reset command parameter
if (processInstance.getCommandParam() != null) { if (processInstance.getCommandParam() != null) {
Map<String, String> processCmdParam = JSONUtils.toMap(processInstance.getCommandParam()); Map<String, String> processCmdParam = JSONUtils.toMap(processInstance.getCommandParam());
Map<String, String> finalCmdParam = cmdParam;
processCmdParam.forEach((key, value) -> { processCmdParam.forEach((key, value) -> {
if (!cmdParam.containsKey(key)) { if (!finalCmdParam.containsKey(key)) {
cmdParam.put(key, value); finalCmdParam.put(key, value);
} }
}); });
} }
// reset command parameter if sub process // reset command parameter if sub process
if (cmdParam != null && cmdParam.containsKey(Constants.CMD_PARAM_SUB_PROCESS)) { if (cmdParam.containsKey(Constants.CMD_PARAM_SUB_PROCESS)) {
processInstance.setCommandParam(command.getCommandParam()); processInstance.setCommandParam(command.getCommandParam());
} }
if (Boolean.FALSE.equals(checkCmdParam(command, cmdParam))) { if (Boolean.FALSE.equals(checkCmdParam(command, cmdParam))) {
@ -1027,7 +1032,7 @@ public class ProcessServiceImpl implements ProcessService {
initTaskInstance(this.findTaskInstanceById(taskId)); initTaskInstance(this.findTaskInstanceById(taskId));
} }
cmdParam.put(Constants.CMD_PARAM_RECOVERY_START_NODE_STRING, cmdParam.put(Constants.CMD_PARAM_RECOVERY_START_NODE_STRING,
String.join(",", convertIntListToString(stopNodeList))); String.join(Constants.COMMA, convertIntListToString(stopNodeList)));
processInstance.setCommandParam(JSONUtils.toJsonString(cmdParam)); processInstance.setCommandParam(JSONUtils.toJsonString(cmdParam));
processInstance.setRunTimes(runTime + 1); processInstance.setRunTimes(runTime + 1);
break; break;

Loading…
Cancel
Save