datax源码阅读二:Engine流程
生活随笔
收集整理的這篇文章主要介紹了
datax源码阅读二:Engine流程
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、根據(jù)前面python文件知道,java的main函數(shù)是com.alibaba.datax.core.Engine
public static void main(String[] args) throws Exception {int exitCode = 0;try {Engine.entry(args);} catch (Throwable e) {exitCode = 1;String trace = ExceptionTracker.trace(e);String errDesc = "未知datax錯誤,參考堆棧內(nèi)容分析。";LOG.error("\n\n經(jīng)DataX智能分析,該任務(wù)最可能的錯誤原因是:\n" + trace);if (e instanceof DataXException) {DataXException tempException = (DataXException) e;ErrorCode errorCode = tempException.getErrorCode();errDesc = errorCode.getDescription();if (errorCode instanceof FrameworkErrorCode) {FrameworkErrorCode tempErrorCode = (FrameworkErrorCode) errorCode;exitCode = tempErrorCode.toExitValue();}}System.exit(exitCode);}System.exit(exitCode); }main函數(shù)主要catch了一下異常,并將異常信息打印出來,實際執(zhí)行在entry函數(shù)中
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.");BasicParser parser = new BasicParser();CommandLine cl = parser.parse(options, args);String jobPath = cl.getOptionValue("job");// 如果用戶沒有明確指定jobid, 則 datax.py 會指定 jobid 默認值為-1String jobIdString = cl.getOptionValue("jobid");RUNTIME_MODE = cl.getOptionValue("mode");Configuration configuration = ConfigParser.parse(jobPath);long jobId;if (!"-1".equalsIgnoreCase(jobIdString)) {jobId = Long.parseLong(jobIdString);} else {// only for dsc & ds & datax 3 updateString dscJobUrlPatternString = "/instance/(\\d{1,})/config.xml";String dsJobUrlPatternString = "/inner/job/(\\d{1,})/config";String dsTaskGroupUrlPatternString = "/inner/job/(\\d{1,})/taskGroup/";List<String> patternStringList = Arrays.asList(dscJobUrlPatternString,dsJobUrlPatternString, dsTaskGroupUrlPatternString);jobId = parseJobIdFromUrl(patternStringList, jobPath);}boolean isStandAloneMode = "standalone".equalsIgnoreCase(RUNTIME_MODE);if (!isStandAloneMode && jobId == -1) {// 如果不是 standalone 模式,那么 jobId 一定不能為-1throw DataXException.asDataXException(FrameworkErrorCode.CONFIG_ERROR, "非 standalone 模式必須在 URL 中提供有效的 jobId.");}configuration.set(CoreConstant.DATAX_CORE_CONTAINER_JOB_ID, jobId);//打印vmInfoVMInfo vmInfo = VMInfo.getVmInfo();if (vmInfo != null) {LOG.info(vmInfo.toString());}LOG.info("\n" + Engine.filterJobConfiguration(configuration) + "\n");LOG.debug(configuration.toJSON());ConfigurationValidate.doValidate(configuration);Engine engine = new Engine();engine.start(configuration); }entry函數(shù)主要功能:
1、解析了java命令行的三個參數(shù),分別是job、jobid和mode,其中job是用戶配置的json文件路徑,jobid和mode是python文件帶進來的,單機模式下可以忽略改參數(shù) 2、讀取用戶配置的json文件,轉(zhuǎn)化為內(nèi)部的configuration配置 3、打印相關(guān)信息,并校驗json文件的合法性 4、啟動engine執(zhí)行entry執(zhí)行完畢之后,進入start函數(shù),關(guān)鍵代碼如下:
public void start(Configuration allConf) {// 綁定column轉(zhuǎn)換信息ColumnCast.bind(allConf);/*** 初始化PluginLoader,可以獲取各種插件配置*/LoadUtil.bind(allConf);*************container = new JobContainer(allConf);*************container.start(); }start函數(shù)中主要包括:
1、列轉(zhuǎn)換默認值,即動態(tài)在configuration中注入默認值 2、初始化插件的LoadUtil,后面classLoader相關(guān)操作都會依賴這個函數(shù) 3、初始化JobContainer并啟動總結(jié)
以上是生活随笔為你收集整理的datax源码阅读二:Engine流程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一键压缩脚本
- 下一篇: Apache 服务器存在高危提权漏洞,请