This is an automated email from the ASF dual-hosted git repository.
xincheng pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new e97f6a41ed Check whether the key exists when "start param to overwrite
global param" (#15676) (#15677)
e97f6a41ed is described below
commit e97f6a41edd361d719f22d4952c392873eee4b15
Author: Frank-Liao <[email protected]>
AuthorDate: Fri Mar 15 17:33:18 2024 +0800
Check whether the key exists when "start param to overwrite global param"
(#15676) (#15677)
Co-authored-by: Rick Cheng <[email protected]>
---
.../service/process/ProcessServiceImpl.java | 9 ++++---
.../service/process/ProcessServiceTest.java | 29 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 3 deletions(-)
diff --git
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
index fc906491d1..261637529a 100644
---
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
+++
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
@@ -601,9 +601,12 @@ public class ProcessServiceImpl implements ProcessService {
if (MapUtils.isNotEmpty(startParamMap) && globalMap != null) {
// start param to overwrite global param
for (Map.Entry<String, String> param : globalMap.entrySet()) {
- String val = startParamMap.get(param.getKey()).getValue();
- if (val != null) {
- param.setValue(val);
+ String globalKey = param.getKey();
+ if (startParamMap.containsKey(globalKey)) {
+ String val = startParamMap.get(globalKey).getValue();
+ if (val != null) {
+ param.setValue(val);
+ }
}
}
// start param to create new global param if global not exist
diff --git
a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java
b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java
index 5e20c5ea2b..509f9a4cf1 100644
---
a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java
+++
b/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.TaskInstanceDao;
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.DqTaskState;
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.OptionSourceType;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.apache.dolphinscheduler.service.cron.CronUtilsTest;
import org.apache.dolphinscheduler.service.exceptions.CronParseException;
@@ -89,6 +91,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -612,6 +615,32 @@ public class ProcessServiceTest {
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
public void testSaveTaskDefine() {
User operator = new User();