[Bug-9608] Serialize the task definition failed (#9622)
* BugFix: serialize the task definition failed * Remove a comment Co-authored-by: lipandong <pandong.lpd@alibaba-inc.com>dependabot/maven/org.springframework-spring-core-5.3.19
parent
a863c6f8f1
commit
10f8c9d983
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,\\\"prop\\\":\\\"key\\\"}],\\\"Name\\\":\\\"create_table_as_select_nation\\\",\\\"FailRetryTimes\\\":0,\\\"dbClusterId\\\":\\\"amv-bp10o45925jpx959\\\",\\\"sendEmail\\\":false,\\\"displayRows\\\":10,\\\"limit\\\":10000,\\\"agentSource\\\":\\\"Workflow\\\",\\\"agentVersion\\\":\\\"Unkown\\\"}\",\"timeout\":\"0\",\"taskType\":\"ADB_MYSQL\",\"timeoutFlag\":\"CLOSE\",\"projectCode\":\"5191800302720\",\"name\":\"create_table_as_select_nation\",\"delayTime\":\"0\",\"workerGroup\":\"default\"}";
|
||||
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_as_select_nation\\\",\\\"FailRetryTimes\\\":0,\\\"dbClusterId\\\":\\\"amv-bp10o45925jpx959\\\",\\\"sendEmail\\\":false,\\\"displayRows\\\":10,\\\"limit\\\":10000,\\\"agentSource\\\":\\\"Workflow\\\",\\\"agentVersion\\\":\\\"Unkown\\\"}\",\"timeout\":\"0\",\"taskType\":\"ADB_MYSQL\",\"timeoutFlag\":\"CLOSE\",\"projectCode\":\"5191800302720\",\"name\":\"create_table_as_select_nation\",\"delayTime\":\"0\",\"workerGroup\":\"default\"}";
|
||||
TaskDefinition definition = JSONUtils.parseObject(definitionJson, TaskDefinition.class);
|
||||
|
||||
Assert.assertNull("Serialize the task definition success", definition.getTaskParamMap());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue