You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ca...@apache.org on 2022/04/21 03:38:48 UTC
[dolphinscheduler] branch dev updated: [Bug-9608] Serialize the task definition failed (#9622)
This is an automated email from the ASF dual-hosted git repository.
caishunfeng 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 10f8c9d983 [Bug-9608] Serialize the task definition failed (#9622)
10f8c9d983 is described below
commit 10f8c9d983528fe57c01a975e3e98d36fff7a4ff
Author: naziD <li...@gmail.com>
AuthorDate: Thu Apr 21 11:38:41 2022 +0800
[Bug-9608] Serialize the task definition failed (#9622)
* BugFix: serialize the task definition failed
* Remove a comment
Co-authored-by: lipandong <pa...@alibaba-inc.com>
---
.../dao/entity/TaskDefinition.java | 16 +++++++++++----
.../dao/mapper/TaskDefinitionMapperTest.java | 24 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java
index 7ebc415617..58e416e5ef 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskDefinition.java
@@ -26,12 +26,12 @@ import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.commons.lang.StringUtils;
-
+import org.apache.commons.collections4.CollectionUtils;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.stream.Collectors;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.IdType;
@@ -309,9 +309,17 @@ public class TaskDefinition {
public Map<String, String> getTaskParamMap() {
if (taskParamMap == null && StringUtils.isNotEmpty(taskParams)) {
JsonNode localParams = JSONUtils.parseObject(taskParams).findValue("localParams");
- if (localParams != null) {
+
+ //If a jsonNode is null, not only use !=null, but also it should use the isNull method to be estimated.
+ if (localParams != null && !localParams.isNull()) {
List<Property> propList = JSONUtils.toList(localParams.toString(), Property.class);
- taskParamMap = propList.stream().collect(Collectors.toMap(Property::getProp, Property::getValue));
+
+ if (CollectionUtils.isNotEmpty(propList)) {
+ taskParamMap = new HashMap<>();
+ for (Property property : propList) {
+ taskParamMap.put(property.getProp(), property.getValue());
+ }
+ }
}
}
return taskParamMap;
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java
index 03131c0b8c..757f751dd2 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java
@@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.dao.mapper;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
@@ -132,4 +133,27 @@ public class TaskDefinitionMapperTest extends BaseDaoTest {
}
+ @Test
+ public void testNullPropertyValueOfLocalParams() {
+ String definitionJson = "{\"failRetryTimes\":\"0\",\"timeoutNotifyStrategy\":\"\",\"code\":\"5195043558720\",\"flag\":\"YES\",\"environmentCode\":\"-1\",\"taskDefinitionIndex\":2,\"taskPriority\":\"MEDIUM\",\"taskParams\":\"{\\\"preStatements\\\":null,\\\"postStatements\\\":null,\\\"type\\\":\\\"ADB_MYSQL\\\",\\\"database\\\":\\\"lijia\\\",\\\"sql\\\":\\\"create table nation_${random_serial_number} as select * from nation\\\",\\\"localParams\\\":[{\\\"direct\\\":2,\\\"type\\\":3, [...]
+ TaskDefinition definition = JSONUtils.parseObject(definitionJson, TaskDefinition.class);
+
+ Map<String, String> taskParamsMap = definition.getTaskParamMap();
+ if (taskParamsMap != null) {
+ Assert.assertNull(taskParamsMap.get("key"));
+ } else {
+ Assert.fail("Deserialize the task definition failed");
+ }
+
+ String newDefinitionJson = JSONUtils.toJsonString(definition);
+ Assert.assertNotNull("Serialize the task definition success", newDefinitionJson);
+ }
+
+ @Test
+ public void testNullLocalParamsOfTaskParams() {
+ String definitionJson = "{\"failRetryTimes\":\"0\",\"timeoutNotifyStrategy\":\"\",\"code\":\"5195043558720\",\"flag\":\"YES\",\"environmentCode\":\"-1\",\"taskDefinitionIndex\":2,\"taskPriority\":\"MEDIUM\",\"taskParams\":\"{\\\"preStatements\\\":null,\\\"postStatements\\\":null,\\\"type\\\":\\\"ADB_MYSQL\\\",\\\"database\\\":\\\"lijia\\\",\\\"sql\\\":\\\"create table nation_${random_serial_number} as select * from nation\\\",\\\"localParams\\\":null,\\\"Name\\\":\\\"create_table [...]
+ TaskDefinition definition = JSONUtils.parseObject(definitionJson, TaskDefinition.class);
+
+ Assert.assertNull("Serialize the task definition success", definition.getTaskParamMap());
+ }
}