change:

1.写死作业参数,方便测试
add:
1.增加测试类
This commit is contained in:
huzekang 2019-04-17 12:12:11 +08:00
parent c4ed5595c1
commit 9e4e31983d
2 changed files with 47 additions and 12 deletions

View File

@ -120,20 +120,22 @@ public class Engine {
return configuration;
}
public static void entry(final String[] args) throws Throwable {
Options options = new Options();
options.addOption("job", true, "Job config.");
options.addOption("jobid", true, "Job unique id.");
options.addOption("mode", true, "Job runtime mode.");
public static void entry() throws Throwable {
// Options options = new Options();
// options.addOption("job", true, "Job config.");
// options.addOption("jobid", true, "Job unique id.");
// options.addOption("mode", true, "Job runtime mode.");
//
// DefaultParser parser = new DefaultParser();
// CommandLine cl = parser.parse(options, args);
DefaultParser parser = new DefaultParser();
CommandLine cl = parser.parse(options, args);
String jobPath = cl.getOptionValue("job");
// 指定作业配置json
String jobPath = "/Users/huzekang/openSource/DataX/job-sample/oracle2mysql.json";
// 如果用户没有明确指定jobid, datax.py 会指定 jobid 默认值为-1
String jobIdString = cl.getOptionValue("jobid");
RUNTIME_MODE = cl.getOptionValue("mode");
String jobIdString = "-1";
// 指定单机还是分布式模式运行
RUNTIME_MODE = "standalone";
Configuration configuration = ConfigParser.parse(jobPath);
@ -203,7 +205,7 @@ public class Engine {
//要断点手动去除idea默认加入的参数才开正常运行
int exitCode = 0;
try {
Engine.entry(args);
Engine.entry();
} catch (Throwable e) {
exitCode = 1;
LOG.error("\n\n经DataX智能分析,该任务最可能的错误原因是:\n" + ExceptionTracker.trace(e));
@ -222,4 +224,22 @@ public class Engine {
System.exit(exitCode);
}
public static void startJob() {
try {
Engine.entry();
} catch (Throwable e) {
LOG.error("\n\n经DataX智能分析,该任务最可能的错误原因是:\n" + ExceptionTracker.trace(e));
if (e instanceof DataXException) {
DataXException tempException = (DataXException) e;
ErrorCode errorCode = tempException.getErrorCode();
if (errorCode instanceof FrameworkErrorCode) {
FrameworkErrorCode tempErrorCode = (FrameworkErrorCode) errorCode;
}
}
}
}
}

View File

@ -0,0 +1,15 @@
import com.alibaba.datax.core.Engine;
/**
* @program: datax-all
* @description:
* @author: huzekang
* @create: 2019-04-17 11:37
**/
public class Test {
@org.junit.Test
public void test() {
Engine.startJob();
}
}