歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Hadoop源碼淺析——Job提交相關

Hadoop源碼淺析——Job提交相關

日期:2017/3/1 10:01:38   编辑:Linux編程

Configuration類是用來訪問Hadoop的配置參數的。

Configuration類首先會通過靜態代碼段加載hadoop的配置文件core-default.xml和和core-site.xml,相關代碼如下:

static{
//print deprecation warning if hadoop-site.xml is found in classpath
ClassLoader cL = Thread.currentThread().getContextClassLoader();
if (cL == null) {
cL = Configuration.class.getClassLoader();
}
if(cL.getResource("hadoop-site.xml")!=null) {
LOG.warn("DEPRECATED: hadoop-site.xml found in the classpath. " +
"Usage of hadoop-site.xml is deprecated. Instead use core-site.xml, "
+ "mapred-site.xml and hdfs-site.xml to override properties of " +
"core-default.xml, mapred-default.xml and hdfs-default.xml " +
"respectively");
}
addDefaultResource("core-default.xml");
addDefaultResource("core-site.xml");
}

defaultResources是一個ArrayList,用來保存默認的配置文件路徑。如果一個默認的配置文件路徑不在defaultResource裡面,就添加進去,這個邏輯是在

addDefaultResource方法中實現的。

properties是一個Properties對象,保存從配置文件中解析出來的配置屬性,如果多個配置文件有相同的key,後者會覆蓋前者的值。

JobConf類用來配置Map/Reduce作業信息的,繼承自Configuration類。

JobConf類首先會通過靜態代碼段加載mapred-default.xml和mapred-site.xml配置屬性文件。

DEFAULT_MAPRED_TASK_JAVA_OPTS=“-Xmx200m”,默認情況下Map/Reduce任務的JAVA命令行選項指定的JAVA虛擬機最大內存是200M。

JobClient類是用戶與JobTracker交互的主要接口,通過它可以提交jobs,追蹤job的進度,訪問task組件的日志,查詢集群的狀態信息等。

提交job是通過runJob方法實現的,相關代碼如下:

public static RunningJob runJob(JobConf job) throws IOException {
JobClient jc = new JobClient(job);
RunningJob rj = jc.submitJob(job);
try {
if (!jc.monitorAndPrintJob(job, rj)) {
LOG.info("Job Failed: " + rj.getFailureInfo());
throw new IOException("Job failed!");
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
return rj;
}

Copyright © Linux教程網 All Rights Reserved