【问题标题】:Launch mapreduce job on hadoop 2.2 (Yarn) from java application从 java 应用程序在 hadoop 2.2 (Yarn) 上启动 mapreduce 作业
【发布时间】:2014-08-14 19:02:57
【问题描述】:

我正在尝试从 Java 应用程序调用 mapreduce 作业。在以前的 hadoop 版本(1.x)中,我创建了一个 Configuration 对象和一个 Job 对象,在 Configuration 中设置 mapred.job.tracker 和 fs.default.name 并运行 Job。

现在,在 hadoop 2.x 中,作业跟踪器不再存在,也没有任何关于如何以编程方式运行 MR 作业的文档。有什么想法吗?

我正在寻找的是这里给出的解释:call mapreduce from a java program

【问题讨论】:

  • 好点,我会更新答案。

标签: java hadoop mapreduce hadoop-yarn resourcemanager


【解决方案1】:

你需要三样东西:

// this should be like defined in your yarn-site.xml
conf.set("yarn.resourcemanager.address", "yarn-manager.com:50001"); 

// framework is now "yarn", should be defined like this in mapred-site.xm
conf.set("mapreduce.framework.name", "yarn");

// like defined in hdfs-site.xml
conf.set("fs.default.name", "hdfs://namenode.com:9000");

Here is a more detailed explanation in the Hadoop 2.2.0 documentation.

【讨论】:

  • 谢谢@Thomas Jungblut。
【解决方案2】:

您需要编写扩展 org.apache.hadoop.conf.Configuration 并实现 org.apache.hadoop.util.Tool 的 Driver 类。

这里是 Driver 类的示例实现。请注意,您需要在 classpath 中有 hdfs-site.xml 和其他配置文件。

@Override
public int run(String[] args) throws Exception {

  Configuration conf = super.getConf();
  Job job = new Job(conf);
  .....
}


public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    conf.addResource("core-site.xml");
    conf.addResource("hdfs-site.xml");
    conf.addResource("hive-site.xml");
    int res = ToolRunner.run(conf, new EtlTool(), args);
    System.exit(res);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多