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(); + } +}