未验证 提交 fe302662 编写于 作者: B BoYiZhang 提交者: GitHub

[Feature-3985][Datax] Datax supports setting up running memory (#3986)

* Datax supports setting up running memory

* Datax supports setting up running memory

* Datax supports setting up running memory

* When running a task, the resource file is lost, which results in an error

* add unit test

* add unit test

* add unit test

* add test unit

* add test unit

* add test unit

* fix code smell

* add test unit

* add test unit
上级 89f1e93b
...@@ -14,15 +14,16 @@ ...@@ -14,15 +14,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.common.task.datax;
import java.util.ArrayList; package org.apache.dolphinscheduler.common.task.datax;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.process.ResourceInfo; import org.apache.dolphinscheduler.common.process.ResourceInfo;
import org.apache.dolphinscheduler.common.task.AbstractParameters; import org.apache.dolphinscheduler.common.task.AbstractParameters;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import java.util.ArrayList;
import java.util.List;
/** /**
* DataX parameter * DataX parameter
...@@ -89,6 +90,16 @@ public class DataxParameters extends AbstractParameters { ...@@ -89,6 +90,16 @@ public class DataxParameters extends AbstractParameters {
*/ */
private int jobSpeedRecord; private int jobSpeedRecord;
/**
* Xms memory
*/
private int xms;
/**
* Xmx memory
*/
private int xmx;
public int getCustomConfig() { public int getCustomConfig() {
return customConfig; return customConfig;
} }
...@@ -185,6 +196,22 @@ public class DataxParameters extends AbstractParameters { ...@@ -185,6 +196,22 @@ public class DataxParameters extends AbstractParameters {
this.jobSpeedRecord = jobSpeedRecord; this.jobSpeedRecord = jobSpeedRecord;
} }
public int getXms() {
return xms;
}
public void setXms(int xms) {
this.xms = xms;
}
public int getXmx() {
return xmx;
}
public void setXmx(int xmx) {
this.xmx = xmx;
}
@Override @Override
public boolean checkParameters() { public boolean checkParameters() {
if (customConfig == Flag.NO.ordinal()) { if (customConfig == Flag.NO.ordinal()) {
...@@ -204,19 +231,21 @@ public class DataxParameters extends AbstractParameters { ...@@ -204,19 +231,21 @@ public class DataxParameters extends AbstractParameters {
@Override @Override
public String toString() { public String toString() {
return "DataxParameters{" + return "DataxParameters{"
"customConfig=" + customConfig + + "customConfig=" + customConfig
", json='" + json + '\'' + + ", json='" + json + '\''
", dsType='" + dsType + '\'' + + ", dsType='" + dsType + '\''
", dataSource=" + dataSource + + ", dataSource=" + dataSource
", dtType='" + dtType + '\'' + + ", dtType='" + dtType + '\''
", dataTarget=" + dataTarget + + ", dataTarget=" + dataTarget
", sql='" + sql + '\'' + + ", sql='" + sql + '\''
", targetTable='" + targetTable + '\'' + + ", targetTable='" + targetTable + '\''
", preStatements=" + preStatements + + ", preStatements=" + preStatements
", postStatements=" + postStatements + + ", postStatements=" + postStatements
", jobSpeedByte=" + jobSpeedByte + + ", jobSpeedByte=" + jobSpeedByte
", jobSpeedRecord=" + jobSpeedRecord + + ", jobSpeedRecord=" + jobSpeedRecord
'}'; + ", xms=" + xms
+ ", xmx=" + xmx
+ '}';
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.common.task;
import org.apache.dolphinscheduler.common.task.datax.DataxParameters;
import org.junit.Assert;
import org.junit.Test;
public class DataxParametersTest {
/**
* jvm parameters
*/
public static final String JVM_EVN = " --jvm=\"-Xms%sG -Xmx%sG\" ";
@Test
public void testLoadJvmEnv() {
DataxParameters dataxParameters = new DataxParameters();
dataxParameters.setXms(0);
dataxParameters.setXmx(-100);
String actual = loadJvmEnvTest(dataxParameters);
String except = " --jvm=\"-Xms1G -Xmx1G\" ";
Assert.assertEquals(except,actual);
dataxParameters.setXms(13);
dataxParameters.setXmx(14);
actual = loadJvmEnvTest(dataxParameters);
except = " --jvm=\"-Xms13G -Xmx14G\" ";
Assert.assertEquals(except,actual);
}
@Test
public void testToString() {
DataxParameters dataxParameters = new DataxParameters();
dataxParameters.setCustomConfig(0);
dataxParameters.setXms(0);
dataxParameters.setXmx(-100);
dataxParameters.setDataSource(1);
dataxParameters.setDataTarget(1);
dataxParameters.setDsType("MYSQL");
dataxParameters.setDtType("MYSQL");
dataxParameters.setJobSpeedByte(1);
dataxParameters.setJobSpeedRecord(1);
dataxParameters.setJson("json");
String expected = "DataxParameters"
+ "{"
+ "customConfig=0, "
+ "json='json', "
+ "dsType='MYSQL', "
+ "dataSource=1, "
+ "dtType='MYSQL', "
+ "dataTarget=1, "
+ "sql='null', "
+ "targetTable='null', "
+ "preStatements=null, "
+ "postStatements=null, "
+ "jobSpeedByte=1, "
+ "jobSpeedRecord=1, "
+ "xms=0, "
+ "xmx=-100"
+ "}";
Assert.assertEquals(expected,dataxParameters.toString());
}
public String loadJvmEnvTest(DataxParameters dataXParameters) {
int xms = dataXParameters.getXms() < 1 ? 1 : dataXParameters.getXms();
int xmx = dataXParameters.getXmx() < 1 ? 1 : dataXParameters.getXmx();
return String.format(JVM_EVN, xms, xmx);
}
}
...@@ -14,27 +14,18 @@ ...@@ -14,27 +14,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.server.worker.task.datax;
package org.apache.dolphinscheduler.server.worker.task.datax;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.ast.statement.*;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.io.FileUtils;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.DbType; import org.apache.dolphinscheduler.common.enums.DbType;
import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.process.Property; import org.apache.dolphinscheduler.common.process.Property;
import org.apache.dolphinscheduler.common.task.AbstractParameters; import org.apache.dolphinscheduler.common.task.AbstractParameters;
import org.apache.dolphinscheduler.common.task.datax.DataxParameters; import org.apache.dolphinscheduler.common.task.datax.DataxParameters;
import org.apache.dolphinscheduler.common.utils.CollectionUtils; import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.common.utils.*; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils; import org.apache.dolphinscheduler.common.utils.OSUtils;
import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.datasource.BaseDataSource; import org.apache.dolphinscheduler.dao.datasource.BaseDataSource;
...@@ -46,7 +37,8 @@ import org.apache.dolphinscheduler.server.utils.ParamUtils; ...@@ -46,7 +37,8 @@ import org.apache.dolphinscheduler.server.utils.ParamUtils;
import org.apache.dolphinscheduler.server.worker.task.AbstractTask; import org.apache.dolphinscheduler.server.worker.task.AbstractTask;
import org.apache.dolphinscheduler.server.worker.task.CommandExecuteResult; import org.apache.dolphinscheduler.server.worker.task.CommandExecuteResult;
import org.apache.dolphinscheduler.server.worker.task.ShellCommandExecutor; import org.apache.dolphinscheduler.server.worker.task.ShellCommandExecutor;
import org.slf4j.Logger;
import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
...@@ -56,25 +48,48 @@ import java.nio.file.StandardOpenOption; ...@@ -56,25 +48,48 @@ import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
import java.sql.*; import java.sql.Connection;
import java.util.*; import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/** /**
* DataX task * DataX task
*/ */
public class DataxTask extends AbstractTask { public class DataxTask extends AbstractTask {
/**
* jvm parameters
*/
public static final String JVM_EVN = " --jvm=\"-Xms%sG -Xmx%sG\" ";
/** /**
* python process(datax only supports version 2.7 by default) * python process(datax only supports version 2.7 by default)
*/ */
private static final String DATAX_PYTHON = "python2.7"; private static final String DATAX_PYTHON = "python2.7";
/** /**
* datax home path * datax home path
*/ */
private static final String DATAX_HOME_EVN = "${DATAX_HOME}"; private static final String DATAX_HOME_EVN = "${DATAX_HOME}";
/** /**
* datax channel count * datax channel count
*/ */
...@@ -97,6 +112,7 @@ public class DataxTask extends AbstractTask { ...@@ -97,6 +112,7 @@ public class DataxTask extends AbstractTask {
/** /**
* constructor * constructor
*
* @param taskExecutionContext taskExecutionContext * @param taskExecutionContext taskExecutionContext
* @param logger logger * @param logger logger
*/ */
...@@ -104,9 +120,8 @@ public class DataxTask extends AbstractTask { ...@@ -104,9 +120,8 @@ public class DataxTask extends AbstractTask {
super(taskExecutionContext, logger); super(taskExecutionContext, logger);
this.taskExecutionContext = taskExecutionContext; this.taskExecutionContext = taskExecutionContext;
this.shellCommandExecutor = new ShellCommandExecutor(this::logHandle, this.shellCommandExecutor = new ShellCommandExecutor(this::logHandle,
taskExecutionContext,logger); taskExecutionContext, logger);
} }
/** /**
...@@ -149,9 +164,7 @@ public class DataxTask extends AbstractTask { ...@@ -149,9 +164,7 @@ public class DataxTask extends AbstractTask {
setExitStatusCode(commandExecuteResult.getExitStatusCode()); setExitStatusCode(commandExecuteResult.getExitStatusCode());
setAppIds(commandExecuteResult.getAppIds()); setAppIds(commandExecuteResult.getAppIds());
setProcessId(commandExecuteResult.getProcessId()); setProcessId(commandExecuteResult.getProcessId());
} } catch (Exception e) {
catch (Exception e) {
logger.error("datax task failure", e);
setExitStatusCode(Constants.EXIT_CODE_FAILURE); setExitStatusCode(Constants.EXIT_CODE_FAILURE);
throw e; throw e;
} }
...@@ -189,9 +202,9 @@ public class DataxTask extends AbstractTask { ...@@ -189,9 +202,9 @@ public class DataxTask extends AbstractTask {
return fileName; return fileName;
} }
if (dataXParameters.getCustomConfig() == Flag.YES.ordinal()){ if (dataXParameters.getCustomConfig() == Flag.YES.ordinal()) {
json = dataXParameters.getJson().replaceAll("\\r\\n", "\n"); json = dataXParameters.getJson().replaceAll("\\r\\n", "\n");
}else { } else {
ObjectNode job = JSONUtils.createObjectNode(); ObjectNode job = JSONUtils.createObjectNode();
job.putArray("content").addAll(buildDataxJobContentJson()); job.putArray("content").addAll(buildDataxJobContentJson());
job.set("setting", buildDataxJobSettingJson()); job.set("setting", buildDataxJobSettingJson());
...@@ -248,7 +261,6 @@ public class DataxTask extends AbstractTask { ...@@ -248,7 +261,6 @@ public class DataxTask extends AbstractTask {
readerParam.put("password", dataSourceCfg.getPassword()); readerParam.put("password", dataSourceCfg.getPassword());
readerParam.putArray("connection").addAll(readerConnArr); readerParam.putArray("connection").addAll(readerConnArr);
ObjectNode reader = JSONUtils.createObjectNode(); ObjectNode reader = JSONUtils.createObjectNode();
reader.put("name", DataxUtils.getReaderPluginName(DbType.of(dataxTaskExecutionContext.getSourcetype()))); reader.put("name", DataxUtils.getReaderPluginName(DbType.of(dataxTaskExecutionContext.getSourcetype())));
reader.set("parameter", readerParam); reader.set("parameter", readerParam);
...@@ -277,7 +289,6 @@ public class DataxTask extends AbstractTask { ...@@ -277,7 +289,6 @@ public class DataxTask extends AbstractTask {
} }
writerParam.putArray("connection").addAll(writerConnArr); writerParam.putArray("connection").addAll(writerConnArr);
if (CollectionUtils.isNotEmpty(dataXParameters.getPreStatements())) { if (CollectionUtils.isNotEmpty(dataXParameters.getPreStatements())) {
ArrayNode preSqlArr = writerParam.putArray("preSql"); ArrayNode preSqlArr = writerParam.putArray("preSql");
for (String preSql : dataXParameters.getPreStatements()) { for (String preSql : dataXParameters.getPreStatements()) {
...@@ -368,7 +379,7 @@ public class DataxTask extends AbstractTask { ...@@ -368,7 +379,7 @@ public class DataxTask extends AbstractTask {
* @throws Exception if error throws Exception * @throws Exception if error throws Exception
*/ */
private String buildShellCommandFile(String jobConfigFilePath, Map<String, Property> paramsMap) private String buildShellCommandFile(String jobConfigFilePath, Map<String, Property> paramsMap)
throws Exception { throws Exception {
// generate scripts // generate scripts
String fileName = String.format("%s/%s_node.%s", String fileName = String.format("%s/%s_node.%s",
taskExecutionContext.getExecutePath(), taskExecutionContext.getExecutePath(),
...@@ -387,6 +398,7 @@ public class DataxTask extends AbstractTask { ...@@ -387,6 +398,7 @@ public class DataxTask extends AbstractTask {
sbr.append(" "); sbr.append(" ");
sbr.append(DATAX_HOME_EVN); sbr.append(DATAX_HOME_EVN);
sbr.append(" "); sbr.append(" ");
sbr.append(loadJvmEnv(dataXParameters));
sbr.append(jobConfigFilePath); sbr.append(jobConfigFilePath);
// replace placeholder // replace placeholder
...@@ -409,17 +421,19 @@ public class DataxTask extends AbstractTask { ...@@ -409,17 +421,19 @@ public class DataxTask extends AbstractTask {
return fileName; return fileName;
} }
public String loadJvmEnv(DataxParameters dataXParameters) {
int xms = dataXParameters.getXms() < 1 ? 1 : dataXParameters.getXms();
int xmx = dataXParameters.getXmx() < 1 ? 1 : dataXParameters.getXmx();
return String.format(JVM_EVN, xms, xmx);
}
/** /**
* parsing synchronized column names in SQL statements * parsing synchronized column names in SQL statements
* *
* @param dsType * @param dsType the database type of the data source
* the database type of the data source * @param dtType the database type of the data target
* @param dtType * @param dataSourceCfg the database connection parameters of the data source
* the database type of the data target * @param sql sql for data synchronization
* @param dataSourceCfg
* the database connection parameters of the data source
* @param sql
* sql for data synchronization
* @return Keyword converted column names * @return Keyword converted column names
*/ */
private String[] parsingSqlColumnNames(DbType dsType, DbType dtType, BaseDataSource dataSourceCfg, String sql) { private String[] parsingSqlColumnNames(DbType dsType, DbType dtType, BaseDataSource dataSourceCfg, String sql) {
...@@ -438,10 +452,8 @@ public class DataxTask extends AbstractTask { ...@@ -438,10 +452,8 @@ public class DataxTask extends AbstractTask {
/** /**
* try grammatical parsing column * try grammatical parsing column
* *
* @param dbType * @param dbType database type
* database type * @param sql sql for data synchronization
* @param sql
* sql for data synchronization
* @return column name array * @return column name array
* @throws RuntimeException if error throws RuntimeException * @throws RuntimeException if error throws RuntimeException
*/ */
...@@ -453,16 +465,16 @@ public class DataxTask extends AbstractTask { ...@@ -453,16 +465,16 @@ public class DataxTask extends AbstractTask {
notNull(parser, String.format("database driver [%s] is not support", dbType.toString())); notNull(parser, String.format("database driver [%s] is not support", dbType.toString()));
SQLStatement sqlStatement = parser.parseStatement(); SQLStatement sqlStatement = parser.parseStatement();
SQLSelectStatement sqlSelectStatement = (SQLSelectStatement)sqlStatement; SQLSelectStatement sqlSelectStatement = (SQLSelectStatement) sqlStatement;
SQLSelect sqlSelect = sqlSelectStatement.getSelect(); SQLSelect sqlSelect = sqlSelectStatement.getSelect();
List<SQLSelectItem> selectItemList = null; List<SQLSelectItem> selectItemList = null;
if (sqlSelect.getQuery() instanceof SQLSelectQueryBlock) { if (sqlSelect.getQuery() instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock block = (SQLSelectQueryBlock)sqlSelect.getQuery(); SQLSelectQueryBlock block = (SQLSelectQueryBlock) sqlSelect.getQuery();
selectItemList = block.getSelectList(); selectItemList = block.getSelectList();
} else if (sqlSelect.getQuery() instanceof SQLUnionQuery) { } else if (sqlSelect.getQuery() instanceof SQLUnionQuery) {
SQLUnionQuery unionQuery = (SQLUnionQuery)sqlSelect.getQuery(); SQLUnionQuery unionQuery = (SQLUnionQuery) sqlSelect.getQuery();
SQLSelectQueryBlock block = (SQLSelectQueryBlock)unionQuery.getRight(); SQLSelectQueryBlock block = (SQLSelectQueryBlock) unionQuery.getRight();
selectItemList = block.getSelectList(); selectItemList = block.getSelectList();
} }
...@@ -470,7 +482,7 @@ public class DataxTask extends AbstractTask { ...@@ -470,7 +482,7 @@ public class DataxTask extends AbstractTask {
String.format("select query type [%s] is not support", sqlSelect.getQuery().toString())); String.format("select query type [%s] is not support", sqlSelect.getQuery().toString()));
columnNames = new String[selectItemList.size()]; columnNames = new String[selectItemList.size()];
for (int i = 0; i < selectItemList.size(); i++ ) { for (int i = 0; i < selectItemList.size(); i++) {
SQLSelectItem item = selectItemList.get(i); SQLSelectItem item = selectItemList.get(i);
String columnName = null; String columnName = null;
...@@ -479,10 +491,10 @@ public class DataxTask extends AbstractTask { ...@@ -479,10 +491,10 @@ public class DataxTask extends AbstractTask {
columnName = item.getAlias(); columnName = item.getAlias();
} else if (item.getExpr() != null) { } else if (item.getExpr() != null) {
if (item.getExpr() instanceof SQLPropertyExpr) { if (item.getExpr() instanceof SQLPropertyExpr) {
SQLPropertyExpr expr = (SQLPropertyExpr)item.getExpr(); SQLPropertyExpr expr = (SQLPropertyExpr) item.getExpr();
columnName = expr.getName(); columnName = expr.getName();
} else if (item.getExpr() instanceof SQLIdentifierExpr) { } else if (item.getExpr() instanceof SQLIdentifierExpr) {
SQLIdentifierExpr expr = (SQLIdentifierExpr)item.getExpr(); SQLIdentifierExpr expr = (SQLIdentifierExpr) item.getExpr();
columnName = expr.getName(); columnName = expr.getName();
} }
} else { } else {
...@@ -497,8 +509,7 @@ public class DataxTask extends AbstractTask { ...@@ -497,8 +509,7 @@ public class DataxTask extends AbstractTask {
columnNames[i] = columnName; columnNames[i] = columnName;
} }
} } catch (Exception e) {
catch (Exception e) {
logger.warn(e.getMessage(), e); logger.warn(e.getMessage(), e);
return null; return null;
} }
...@@ -509,10 +520,8 @@ public class DataxTask extends AbstractTask { ...@@ -509,10 +520,8 @@ public class DataxTask extends AbstractTask {
/** /**
* try to execute sql to resolve column names * try to execute sql to resolve column names
* *
* @param baseDataSource * @param baseDataSource the database connection parameters
* the database connection parameters * @param sql sql for data synchronization
* @param sql
* sql for data synchronization
* @return column name array * @return column name array
*/ */
public String[] tryExecuteSqlResolveColumnNames(BaseDataSource baseDataSource, String sql) { public String[] tryExecuteSqlResolveColumnNames(BaseDataSource baseDataSource, String sql) {
...@@ -529,11 +538,10 @@ public class DataxTask extends AbstractTask { ...@@ -529,11 +538,10 @@ public class DataxTask extends AbstractTask {
ResultSetMetaData md = resultSet.getMetaData(); ResultSetMetaData md = resultSet.getMetaData();
int num = md.getColumnCount(); int num = md.getColumnCount();
columnNames = new String[num]; columnNames = new String[num];
for (int i = 1; i <= num; i++ ) { for (int i = 1; i <= num; i++) {
columnNames[i - 1] = md.getColumnName(i); columnNames[i - 1] = md.getColumnName(i);
} }
} } catch (SQLException e) {
catch (SQLException e) {
logger.warn(e.getMessage(), e); logger.warn(e.getMessage(), e);
return null; return null;
} }
......
...@@ -14,19 +14,13 @@ ...@@ -14,19 +14,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.dolphinscheduler.server.worker.task.datax;
package org.apache.dolphinscheduler.server.worker.task.datax;
import java.lang.reflect.Method; import static org.apache.dolphinscheduler.common.enums.CommandType.START_PROCESS;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.dolphinscheduler.common.enums.DbType; import org.apache.dolphinscheduler.common.enums.DbType;
import org.apache.dolphinscheduler.common.task.datax.DataxParameters;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.datasource.BaseDataSource; import org.apache.dolphinscheduler.dao.datasource.BaseDataSource;
import org.apache.dolphinscheduler.dao.datasource.DataSourceFactory; import org.apache.dolphinscheduler.dao.datasource.DataSourceFactory;
...@@ -39,6 +33,13 @@ import org.apache.dolphinscheduler.server.worker.task.ShellCommandExecutor; ...@@ -39,6 +33,13 @@ import org.apache.dolphinscheduler.server.worker.task.ShellCommandExecutor;
import org.apache.dolphinscheduler.server.worker.task.TaskProps; import org.apache.dolphinscheduler.server.worker.task.TaskProps;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.dolphinscheduler.service.process.ProcessService;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -49,7 +50,8 @@ import org.slf4j.Logger; ...@@ -49,7 +50,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import static org.apache.dolphinscheduler.common.enums.CommandType.START_PROCESS; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/** /**
* DataxTask Tester. * DataxTask Tester.
...@@ -58,7 +60,13 @@ public class DataxTaskTest { ...@@ -58,7 +60,13 @@ public class DataxTaskTest {
private static final Logger logger = LoggerFactory.getLogger(DataxTaskTest.class); private static final Logger logger = LoggerFactory.getLogger(DataxTaskTest.class);
private static final String CONNECTION_PARAMS = "{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:mysql://127.0.0.1:3306\",\"database\":\"test\",\"jdbcUrl\":\"jdbc:mysql://127.0.0.1:3306/test\"}"; private static final String CONNECTION_PARAMS = " {\n"
+ " \"user\":\"root\",\n"
+ " \"password\":\"123456\",\n"
+ " \"address\":\"jdbc:mysql://127.0.0.1:3306\",\n"
+ " \"database\":\"test\",\n"
+ " \"jdbcUrl\":\"jdbc:mysql://127.0.0.1:3306/test\"\n"
+ "}";
private DataxTask dataxTask; private DataxTask dataxTask;
...@@ -69,7 +77,7 @@ public class DataxTaskTest { ...@@ -69,7 +77,7 @@ public class DataxTaskTest {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
private TaskExecutionContext taskExecutionContext; private TaskExecutionContext taskExecutionContext;
private TaskProps props = new TaskProps(); private final TaskProps props = new TaskProps();
@Before @Before
public void before() public void before()
...@@ -97,12 +105,40 @@ public class DataxTaskTest { ...@@ -97,12 +105,40 @@ public class DataxTaskTest {
props.setTaskTimeout(0); props.setTaskTimeout(0);
if (customConfig == 1) { if (customConfig == 1) {
props.setTaskParams( props.setTaskParams(
"{\"customConfig\":1, \"localParams\":[{\"prop\":\"test\",\"value\":\"38294729\"}],\"json\":\"{\\\"job\\\":{\\\"setting\\\":{\\\"speed\\\":{\\\"byte\\\":1048576},\\\"errorLimit\\\":{\\\"record\\\":0,\\\"percentage\\\":0.02}},\\\"content\\\":[{\\\"reader\\\":{\\\"name\\\":\\\"rdbmsreader\\\",\\\"parameter\\\":{\\\"username\\\":\\\"xxx\\\",\\\"password\\\":\\\"${test}\\\",\\\"column\\\":[\\\"id\\\",\\\"name\\\"],\\\"splitPk\\\":\\\"pk\\\",\\\"connection\\\":[{\\\"querySql\\\":[\\\"SELECT * from dual\\\"],\\\"jdbcUrl\\\":[\\\"jdbc:dm://ip:port/database\\\"]}],\\\"fetchSize\\\":1024,\\\"where\\\":\\\"1 = 1\\\"}},\\\"writer\\\":{\\\"name\\\":\\\"streamwriter\\\",\\\"parameter\\\":{\\\"print\\\":true}}}]}}\"}"); "{\n"
+ " \"customConfig\":1,\n"
+ " \"localParams\":[\n"
+ " {\n"
+ " \"prop\":\"test\",\n"
+ " \"value\":\"38294729\"\n"
+ " }\n"
+ " ],\n"
+ " \"json\":\""
+ "{\"job\":{\"setting\":{\"speed\":{\"byte\":1048576},\"errorLimit\":{\"record\":0,\"percentage\":0.02}},\"content\":["
+ "{\"reader\":{\"name\":\"rdbmsreader\",\"parameter\":{\"username\":\"xxx\",\"password\":\"${test}\",\"column\":[\"id\",\"name\"],\"splitPk\":\"pk\",\""
+ "connection\":[{\"querySql\":[\"SELECT * from dual\"],\"jdbcUrl\":[\"jdbc:dm://ip:port/database\"]}],\"fetchSize\":1024,\"where\":\"1 = 1\"}},\""
+ "writer\":{\"name\":\"streamwriter\",\"parameter\":{\"print\":true}}}]}}\"\n"
+ "}");
// "{\"customConfig\":1,\"json\":\"{\\\"job\\\":{\\\"setting\\\":{\\\"speed\\\":{\\\"byte\\\":1048576},\\\"errorLimit\\\":{\\\"record\\\":0,\\\"percentage\\\":0.02}},\\\"content\\\":[{\\\"reader\\\":{\\\"name\\\":\\\"rdbmsreader\\\",\\\"parameter\\\":{\\\"username\\\":\\\"xxx\\\",\\\"password\\\":\\\"xxx\\\",\\\"column\\\":[\\\"id\\\",\\\"name\\\"],\\\"splitPk\\\":\\\"pk\\\",\\\"connection\\\":[{\\\"querySql\\\":[\\\"SELECT * from dual\\\"],\\\"jdbcUrl\\\":[\\\"jdbc:dm://ip:port/database\\\"]}],\\\"fetchSize\\\":1024,\\\"where\\\":\\\"1 = 1\\\"}},\\\"writer\\\":{\\\"name\\\":\\\"streamwriter\\\",\\\"parameter\\\":{\\\"print\\\":true}}}]}}\"}");
} else { } else {
props.setTaskParams( props.setTaskParams(
"{\"customConfig\":0,\"targetTable\":\"test\",\"postStatements\":[],\"jobSpeedByte\":1024,\"jobSpeedRecord\":1000,\"dtType\":\"MYSQL\",\"dataSource\":1,\"dsType\":\"MYSQL\",\"dataTarget\":2,\"jobSpeedByte\":0,\"sql\":\"select 1 as test from dual\",\"preStatements\":[\"delete from test\"],\"postStatements\":[\"delete from test\"]}"); "{\n"
+ " \"customConfig\":0,\n"
+ " \"targetTable\":\"test\",\n"
+ " \"postStatements\":[\n"
+ " \"delete from test\"\n"
+ " ],\n"
+ " \"jobSpeedByte\":0,\n"
+ " \"jobSpeedRecord\":1000,\n"
+ " \"dtType\":\"MYSQL\",\n"
+ " \"dataSource\":1,\n"
+ " \"dsType\":\"MYSQL\",\n"
+ " \"dataTarget\":2,\n"
+ " \"sql\":\"select 1 as test from dual\",\n"
+ " \"preStatements\":[\n"
+ " \"delete from test\"\n"
+ " ]\n"
+ "}");
} }
taskExecutionContext = Mockito.mock(TaskExecutionContext.class); taskExecutionContext = Mockito.mock(TaskExecutionContext.class);
...@@ -114,7 +150,6 @@ public class DataxTaskTest { ...@@ -114,7 +150,6 @@ public class DataxTaskTest {
Mockito.when(taskExecutionContext.getTaskTimeout()).thenReturn(10000); Mockito.when(taskExecutionContext.getTaskTimeout()).thenReturn(10000);
Mockito.when(taskExecutionContext.getLogPath()).thenReturn("/tmp/dx"); Mockito.when(taskExecutionContext.getLogPath()).thenReturn("/tmp/dx");
DataxTaskExecutionContext dataxTaskExecutionContext = new DataxTaskExecutionContext(); DataxTaskExecutionContext dataxTaskExecutionContext = new DataxTaskExecutionContext();
dataxTaskExecutionContext.setSourcetype(0); dataxTaskExecutionContext.setSourcetype(0);
dataxTaskExecutionContext.setTargetType(0); dataxTaskExecutionContext.setTargetType(0);
...@@ -126,7 +161,6 @@ public class DataxTaskTest { ...@@ -126,7 +161,6 @@ public class DataxTaskTest {
dataxTask.init(); dataxTask.init();
props.setCmdTypeIfComplement(START_PROCESS); props.setCmdTypeIfComplement(START_PROCESS);
Mockito.when(processService.findDataSourceById(1)).thenReturn(getDataSource()); Mockito.when(processService.findDataSourceById(1)).thenReturn(getDataSource());
Mockito.when(processService.findDataSourceById(2)).thenReturn(getDataSource()); Mockito.when(processService.findDataSourceById(2)).thenReturn(getDataSource());
Mockito.when(processService.findProcessInstanceByTaskId(1)).thenReturn(getProcessInstance()); Mockito.when(processService.findProcessInstanceByTaskId(1)).thenReturn(getProcessInstance());
...@@ -138,7 +172,6 @@ public class DataxTaskTest { ...@@ -138,7 +172,6 @@ public class DataxTaskTest {
e.printStackTrace(); e.printStackTrace();
} }
dataxTask = PowerMockito.spy(new DataxTask(taskExecutionContext, logger)); dataxTask = PowerMockito.spy(new DataxTask(taskExecutionContext, logger));
dataxTask.init(); dataxTask.init();
} }
...@@ -405,4 +438,23 @@ public class DataxTaskTest { ...@@ -405,4 +438,23 @@ public class DataxTaskTest {
} }
} }
@Test
public void testLoadJvmEnv() {
DataxTask dataxTask = new DataxTask(null,null);
DataxParameters dataxParameters = new DataxParameters();
dataxParameters.setXms(0);
dataxParameters.setXmx(-100);
String actual = dataxTask.loadJvmEnv(dataxParameters);
String except = " --jvm=\"-Xms1G -Xmx1G\" ";
Assert.assertEquals(except,actual);
dataxParameters.setXms(13);
dataxParameters.setXmx(14);
actual = dataxTask.loadJvmEnv(dataxParameters);
except = " --jvm=\"-Xms13G -Xmx14G\" ";
Assert.assertEquals(except,actual);
}
} }
...@@ -144,6 +144,22 @@ ...@@ -144,6 +144,22 @@
</div> </div>
</m-list-box> </m-list-box>
</div> </div>
<div class="clearfix list">
<div class="text-box">
<span>{{$t('Running Memory')}}</span>
</div>
<div class="cont-box">
<span >{{$t('Min Memory')}}</span>
<m-select-input v-model="xms" :list="[1,2,3,4]">
</m-select-input>
<span>&nbsp;&nbsp;&nbsp;G &nbsp;&nbsp;</span>
<span >{{$t('Max Memory')}}</span>
<m-select-input v-model="xmx" :list="[1,2,3,4]">
</m-select-input>
<span>&nbsp;&nbsp;&nbsp;G</span>
</div>
</div>
</div> </div>
</template> </template>
<script> <script>
...@@ -196,6 +212,10 @@ ...@@ -196,6 +212,10 @@
// Custom parameter // Custom parameter
localParams: [], localParams: [],
customConfig: 0, customConfig: 0,
//jvm memory xms
xms: 1,
//jvm memory xms
xmx: 1,
} }
}, },
mixins: [disabledState], mixins: [disabledState],
...@@ -324,7 +344,9 @@ ...@@ -324,7 +344,9 @@
this.$emit('on-params', { this.$emit('on-params', {
customConfig: this.customConfig, customConfig: this.customConfig,
json: jsonEditor.getValue(), json: jsonEditor.getValue(),
localParams: this.localParams localParams: this.localParams,
xms:+this.xms,
xmx:+this.xmx
}) })
return true return true
} else { } else {
...@@ -358,6 +380,7 @@ ...@@ -358,6 +380,7 @@
return false return false
} }
debugger
// storage // storage
this.$emit('on-params', { this.$emit('on-params', {
customConfig: this.customConfig, customConfig: this.customConfig,
...@@ -370,7 +393,9 @@ ...@@ -370,7 +393,9 @@
jobSpeedByte: this.jobSpeedByte * 1024, jobSpeedByte: this.jobSpeedByte * 1024,
jobSpeedRecord: this.jobSpeedRecord, jobSpeedRecord: this.jobSpeedRecord,
preStatements: this.preStatements, preStatements: this.preStatements,
postStatements: this.postStatements postStatements: this.postStatements,
xms:+this.xms,
xmx:+this.xmx
}) })
return true return true
} }
...@@ -445,7 +470,9 @@ ...@@ -445,7 +470,9 @@
jobSpeedByte: this.jobSpeedByte * 1024, jobSpeedByte: this.jobSpeedByte * 1024,
jobSpeedRecord: this.jobSpeedRecord, jobSpeedRecord: this.jobSpeedRecord,
preStatements: this.preStatements, preStatements: this.preStatements,
postStatements: this.postStatements postStatements: this.postStatements,
xms: +this.xms,
xmx: +this.xmx,
}); });
}, },
_destroyEditor () { _destroyEditor () {
...@@ -468,6 +495,10 @@ ...@@ -468,6 +495,10 @@
// Non-null objects represent backfill // Non-null objects represent backfill
if (!_.isEmpty(o)) { if (!_.isEmpty(o)) {
// set jvm memory
this.xms = o.params.xms || 1 ;
this.xmx = o.params.xmx || 1 ;
// backfill // backfill
if(o.params.customConfig == 0) { if(o.params.customConfig == 0) {
this.customConfig = 0 this.customConfig = 0
...@@ -544,4 +575,4 @@ ...@@ -544,4 +575,4 @@
right: -12px; right: -12px;
top: -16px; top: -16px;
} }
</style> </style>
\ No newline at end of file
...@@ -661,5 +661,8 @@ export default { ...@@ -661,5 +661,8 @@ export default {
'Batch move': 'Batch move', 'Batch move': 'Batch move',
Version: 'Version', Version: 'Version',
'Pre tasks': 'Pre tasks', 'Pre tasks': 'Pre tasks',
'Running Memory':'Running Memory',
'Max Memory':'Max Memory',
'Min Memory':'Min Memory',
'The workflow canvas is abnormal and cannot be saved, please recreate': 'The workflow canvas is abnormal and cannot be saved, please recreate' 'The workflow canvas is abnormal and cannot be saved, please recreate': 'The workflow canvas is abnormal and cannot be saved, please recreate'
} }
...@@ -657,5 +657,8 @@ export default { ...@@ -657,5 +657,8 @@ export default {
'Batch move': '批量移动', 'Batch move': '批量移动',
Version: '版本', Version: '版本',
'Pre tasks': '前置任务', 'Pre tasks': '前置任务',
'Running Memory':'运行内存',
'Max Memory':'最大内存',
'Min Memory':'最小内存',
'The workflow canvas is abnormal and cannot be saved, please recreate': '该工作流画布异常,无法保存,请重新创建' 'The workflow canvas is abnormal and cannot be saved, please recreate': '该工作流画布异常,无法保存,请重新创建'
} }
...@@ -758,6 +758,7 @@ ...@@ -758,6 +758,7 @@
<include>**/common/os/OshiTest.java</include> <include>**/common/os/OshiTest.java</include>
<include>**/common/os/OSUtilsTest.java</include> <include>**/common/os/OSUtilsTest.java</include>
<include>**/common/shell/ShellExecutorTest.java</include> <include>**/common/shell/ShellExecutorTest.java</include>
<include>**/common/task/DataxParametersTest.java</include>
<include>**/common/task/EntityTestUtils.java</include> <include>**/common/task/EntityTestUtils.java</include>
<include>**/common/task/FlinkParametersTest.java</include> <include>**/common/task/FlinkParametersTest.java</include>
<include>**/common/task/HttpParametersTest.java</include> <include>**/common/task/HttpParametersTest.java</include>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册