你好,游客 登录 注册 搜索
背景:
阅读新闻

Hadoop源码浅析——Job提交相关

[日期:2013-02-16] 来源:Linux社区  作者:andyelvis [字体: ]

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;
  }

linux
相关资讯       Hadoop源码 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款