From 9e4e31983d3e6c3a68526c012aec1dc692d0210f Mon Sep 17 00:00:00 2001 From: huzekang <1040080742@qq.com> Date: Wed, 17 Apr 2019 12:12:11 +0800 Subject: [PATCH] =?UTF-8?q?change=EF=BC=9A=201.=E5=86=99=E6=AD=BB=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=8F=82=E6=95=B0=EF=BC=8C=E6=96=B9=E4=BE=BF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20add:=201.=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/datax/core/Engine.java | 44 ++++++++++++++----- core/src/test/java/Test.java | 15 +++++++ 2 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 core/src/test/java/Test.java diff --git a/core/src/main/java/com/alibaba/datax/core/Engine.java b/core/src/main/java/com/alibaba/datax/core/Engine.java index 5c4f71c5..6828bc89 100755 --- a/core/src/main/java/com/alibaba/datax/core/Engine.java +++ b/core/src/main/java/com/alibaba/datax/core/Engine.java @@ -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; + } + } + + } + } + } diff --git a/core/src/test/java/Test.java b/core/src/test/java/Test.java new file mode 100644 index 00000000..0e282db2 --- /dev/null +++ b/core/src/test/java/Test.java @@ -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(); + } +}