Browse Source

Check whether the key exists when "start param to overwrite global param" (#15676) (#15677)

Co-authored-by: Rick Cheng <rickchengx@gmail.com>
dev_wenjun_refactorMaster
Frank-Liao 9 months ago committed by GitHub
parent
commit
e97f6a41ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
  2. 29
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java

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

@ -601,11 +601,14 @@ public class ProcessServiceImpl implements ProcessService {
if (MapUtils.isNotEmpty(startParamMap) && globalMap != null) { if (MapUtils.isNotEmpty(startParamMap) && globalMap != null) {
// start param to overwrite global param // start param to overwrite global param
for (Map.Entry<String, String> param : globalMap.entrySet()) { for (Map.Entry<String, String> param : globalMap.entrySet()) {
String val = startParamMap.get(param.getKey()).getValue(); String globalKey = param.getKey();
if (startParamMap.containsKey(globalKey)) {
String val = startParamMap.get(globalKey).getValue();
if (val != null) { if (val != null) {
param.setValue(val); param.setValue(val);
} }
} }
}
// start param to create new global param if global not exist // start param to create new global param if global not exist
for (Entry<String, Property> startParam : startParamMap.entrySet()) { for (Entry<String, Property> startParam : startParamMap.entrySet()) {
if (!globalMap.containsKey(startParam.getKey())) { if (!globalMap.containsKey(startParam.getKey())) {

29
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java

@ -71,11 +71,13 @@ import org.apache.dolphinscheduler.dao.repository.TaskDefinitionDao;
import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao; import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao;
import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
import org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager; import org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager;
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.DataType; import org.apache.dolphinscheduler.plugin.task.api.enums.dp.DataType;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.DqTaskState; import org.apache.dolphinscheduler.plugin.task.api.enums.dp.DqTaskState;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.ExecuteSqlType; import org.apache.dolphinscheduler.plugin.task.api.enums.dp.ExecuteSqlType;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.InputType; import org.apache.dolphinscheduler.plugin.task.api.enums.dp.InputType;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.OptionSourceType; import org.apache.dolphinscheduler.plugin.task.api.enums.dp.OptionSourceType;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo; import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.apache.dolphinscheduler.service.cron.CronUtilsTest; import org.apache.dolphinscheduler.service.cron.CronUtilsTest;
import org.apache.dolphinscheduler.service.exceptions.CronParseException; import org.apache.dolphinscheduler.service.exceptions.CronParseException;
@ -89,6 +91,7 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -612,6 +615,32 @@ public class ProcessServiceTest {
return list; return list;
} }
@Test
public void testSetGlobalParamIfCommanded() {
ProcessDefinition processDefinition = new ProcessDefinition();
String globalParams =
"[{\"prop\":\"global_param\",\"value\":\"4\",\"direct\":\"IN\",\"type\":\"VARCHAR\"},{\"prop\":\"O_ERRCODE\",\"value\":\"\",\"direct\":\"OUT\",\"type\":\"VARCHAR\"}]";
processDefinition.setGlobalParams(globalParams);
Map<String, String> globalParamMap = processDefinition.getGlobalParamMap();
Assertions.assertTrue(globalParamMap.size() == 2);
Assertions.assertTrue(processDefinition.getGlobalParamList().size() == 2);
HashMap<String, String> startParams = new HashMap<>();
String expectValue = "6";
startParams.put("global_param", expectValue);
HashMap<String, String> commandParams = new HashMap<>();
commandParams.put(CMD_PARAM_START_PARAMS, JSONUtils.toJsonString(startParams));
Map<String, Property> mockStartParams = new HashMap<>();
mockStartParams.put("global_param", new Property("global_param", Direct.IN,
org.apache.dolphinscheduler.plugin.task.api.enums.DataType.VARCHAR, startParams.get("global_param")));
when(curingGlobalParamsService.parseWorkflowStartParam(commandParams)).thenReturn(mockStartParams);
processService.setGlobalParamIfCommanded(processDefinition, commandParams);
Assertions.assertTrue(globalParamMap.get("global_param").equals(expectValue));
Assertions.assertTrue(globalParamMap.containsKey("O_ERRCODE"));
}
@Test @Test
public void testSaveTaskDefine() { public void testSaveTaskDefine() {
User operator = new User(); User operator = new User();

Loading…
Cancel
Save