gabrywu commented on a change in pull request #2872:
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/2872#discussion_r438106960
##########
File path:
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java
##########
@@ -152,7 +153,8 @@ public void run() {
// global params string
String globalParamsStr = taskExecutionContext.getGlobalParams();
if (globalParamsStr != null) {
- List<Property> globalParamsList =
JSONObject.parseArray(globalParamsStr, Property.class);
+ List<Property> globalParamsList = new ArrayList<>();
Review comment:
why not assign the result of JSONUtils.toList to globalParamsList
directly
##########
File path:
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
##########
@@ -205,16 +206,16 @@ public Boolean verifyIsNeedCreateCommand(Command command){
CommandType commandType = command.getCommandType();
if(cmdTypeMap.containsKey(commandType)){
- JSONObject cmdParamObj = (JSONObject)
JSON.parse(command.getCommandParam());
- JSONObject tempObj;
- int processInstanceId =
cmdParamObj.getInteger(CMDPARAM_RECOVER_PROCESS_ID_STRING);
+ ObjectNode cmdParamObj =
JSONUtils.parseObject(command.getCommandParam());
+ ObjectNode tempObj;
+ int processInstanceId =
cmdParamObj.path(CMDPARAM_RECOVER_PROCESS_ID_STRING).asInt();
List<Command> commands = commandMapper.selectList(null);
// for all commands
for (Command tmpCommand:commands){
if(cmdTypeMap.containsKey(tmpCommand.getCommandType())){
- tempObj = (JSONObject)
JSON.parse(tmpCommand.getCommandParam());
- if(tempObj != null && processInstanceId ==
tempObj.getInteger(CMDPARAM_RECOVER_PROCESS_ID_STRING)){
+ tempObj =
JSONUtils.parseObject(tmpCommand.getCommandParam());
Review comment:
do you mind move tempObj definition to this position ?
##########
File path:
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/datax/DataxTask.java
##########
@@ -236,64 +222,90 @@ private String buildDataxJsonFile()
/**
* build datax job config
- *
+ *
* @return collection of datax job config JSONObject
* @throws SQLException if error throws SQLException
*/
- private List<JSONObject> buildDataxJobContentJson() throws SQLException {
- DataxTaskExecutionContext dataxTaskExecutionContext =
taskExecutionContext.getDataxTaskExecutionContext();
+ private List<ObjectNode> buildDataxJobContentJson() throws SQLException {
+ DataxTaskExecutionContext dataxTaskExecutionContext =
taskExecutionContext.getDataxTaskExecutionContext();
BaseDataSource dataSourceCfg =
DataSourceFactory.getDatasource(DbType.of(dataxTaskExecutionContext.getSourcetype()),
dataxTaskExecutionContext.getSourceConnectionParams());
BaseDataSource dataTargetCfg =
DataSourceFactory.getDatasource(DbType.of(dataxTaskExecutionContext.getTargetType()),
dataxTaskExecutionContext.getTargetConnectionParams());
- List<JSONObject> readerConnArr = new ArrayList<>();
- JSONObject readerConn = new JSONObject();
- readerConn.put("querySql", new String[] {dataXParameters.getSql()});
- readerConn.put("jdbcUrl", new String[] {dataSourceCfg.getJdbcUrl()});
+ List<ObjectNode> readerConnArr = new ArrayList<>();
+ ObjectNode readerConn = JSONUtils.createObjectNode();
+
+ ArrayNode sqlArr = readerConn.putArray("querySql");
+ for (String sql : new String[]{dataXParameters.getSql()}) {
+ sqlArr.add(sql);
+ }
+
+ ArrayNode urlArr = readerConn.putArray("jdbcUrl");
+ for (String url : new String[]{dataSourceCfg.getJdbcUrl()}) {
+ urlArr.add(url);
+ }
+
readerConnArr.add(readerConn);
- JSONObject readerParam = new JSONObject();
+ ObjectNode readerParam = JSONUtils.createObjectNode();
readerParam.put("username", dataSourceCfg.getUser());
readerParam.put("password", dataSourceCfg.getPassword());
- readerParam.put("connection", readerConnArr);
+ readerParam.putArray("connection").addAll(readerConnArr);
- JSONObject reader = new JSONObject();
+
+ ObjectNode reader = JSONUtils.createObjectNode();
reader.put("name",
DataxUtils.getReaderPluginName(DbType.of(dataxTaskExecutionContext.getSourcetype())));
- reader.put("parameter", readerParam);
+ reader.set("parameter", readerParam);
+
+ List<ObjectNode> writerConnArr = new ArrayList<>();
+ ObjectNode writerConn = JSONUtils.createObjectNode();
+ ArrayNode tableArr = writerConn.putArray("table");
+ for (String table : new String[]{dataXParameters.getTargetTable()}) {
+ tableArr.add(table);
+ }
- List<JSONObject> writerConnArr = new ArrayList<>();
- JSONObject writerConn = new JSONObject();
- writerConn.put("table", new String[]
{dataXParameters.getTargetTable()});
writerConn.put("jdbcUrl", dataTargetCfg.getJdbcUrl());
writerConnArr.add(writerConn);
- JSONObject writerParam = new JSONObject();
+ ObjectNode writerParam = JSONUtils.createObjectNode();
writerParam.put("username", dataTargetCfg.getUser());
writerParam.put("password", dataTargetCfg.getPassword());
- writerParam.put("column",
-
parsingSqlColumnNames(DbType.of(dataxTaskExecutionContext.getSourcetype()),
- DbType.of(dataxTaskExecutionContext.getTargetType()),
- dataSourceCfg, dataXParameters.getSql()));
- writerParam.put("connection", writerConnArr);
+
+ String[] columns =
parsingSqlColumnNames(DbType.of(dataxTaskExecutionContext.getSourcetype()),
+ DbType.of(dataxTaskExecutionContext.getTargetType()),
+ dataSourceCfg, dataXParameters.getSql());
+ ArrayNode columnArr = writerParam.putArray("column");
Review comment:
ok
##########
File path:
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
##########
@@ -107,11 +121,13 @@ public static String toJson(Object object) {
if (StringUtils.isEmpty(json)) {
return new ArrayList<>();
Review comment:
better use Collections.EMPTY_LIST
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]