| 114 | } |
| 115 | |
| 116 | public static void entry(final String[] args) throws Throwable { |
| 117 | Options options = new Options(); |
| 118 | options.addOption("job", true, "Job config."); |
| 119 | options.addOption("jobid", true, "Job unique id."); |
| 120 | options.addOption("mode", true, "Job runtime mode."); |
| 121 | |
| 122 | BasicParser parser = new BasicParser(); |
| 123 | CommandLine cl = parser.parse(options, args); |
| 124 | |
| 125 | String jobPath = cl.getOptionValue("job"); |
| 126 | |
| 127 | // 如果用户没有明确指定jobid, 则 datax.py 会指定 jobid 默认值为-1 |
| 128 | String jobIdString = cl.getOptionValue("jobid"); |
| 129 | RUNTIME_MODE = cl.getOptionValue("mode"); |
| 130 | |
| 131 | Configuration configuration = ConfigParser.parse(jobPath); |
| 132 | // 绑定i18n信息 |
| 133 | MessageSource.init(configuration); |
| 134 | MessageSource.reloadResourceBundle(Configuration.class); |
| 135 | |
| 136 | long jobId; |
| 137 | if (!"-1".equalsIgnoreCase(jobIdString)) { |
| 138 | jobId = Long.parseLong(jobIdString); |
| 139 | } else { |
| 140 | // only for dsc & ds & datax 3 update |
| 141 | String dscJobUrlPatternString = "/instance/(\\d{1,})/config.xml"; |
| 142 | String dsJobUrlPatternString = "/inner/job/(\\d{1,})/config"; |
| 143 | String dsTaskGroupUrlPatternString = "/inner/job/(\\d{1,})/taskGroup/"; |
| 144 | List<String> patternStringList = Arrays.asList(dscJobUrlPatternString, |
| 145 | dsJobUrlPatternString, dsTaskGroupUrlPatternString); |
| 146 | jobId = parseJobIdFromUrl(patternStringList, jobPath); |
| 147 | } |
| 148 | |
| 149 | boolean isStandAloneMode = "standalone".equalsIgnoreCase(RUNTIME_MODE); |
| 150 | if (!isStandAloneMode && jobId == -1) { |
| 151 | // 如果不是 standalone 模式,那么 jobId 一定不能为-1 |
| 152 | throw DataXException.asDataXException(FrameworkErrorCode.CONFIG_ERROR, "非 standalone 模式必须在 URL 中提供有效的 jobId."); |
| 153 | } |
| 154 | configuration.set(CoreConstant.DATAX_CORE_CONTAINER_JOB_ID, jobId); |
| 155 | |
| 156 | //打印vmInfo |
| 157 | VMInfo vmInfo = VMInfo.getVmInfo(); |
| 158 | if (vmInfo != null) { |
| 159 | LOG.info(vmInfo.toString()); |
| 160 | } |
| 161 | |
| 162 | LOG.info("\n" + Engine.filterJobConfiguration(configuration) + "\n"); |
| 163 | |
| 164 | LOG.debug(configuration.toJSON()); |
| 165 | |
| 166 | ConfigurationValidate.doValidate(configuration); |
| 167 | Engine engine = new Engine(); |
| 168 | engine.start(configuration); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /** |