通过Java列出hadoop集群中的所有yarn应用程序 [英] List all yarn application in hadoop cluster through java

查看:146
本文介绍了通过Java列出hadoop集群中的所有yarn应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的hadoop集群上运行命令 yarn application -list 时,它返回正在运行的应用程序列表.

On running command yarn application -list on my hadoop cluster, it returns list of applications running.

我想使用Java获取此列表.

I want to fetch this list using Java.

当前我正在使用yarnClient API

Currently I am using yarnClient API

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>2.7.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-yarn-client</artifactId>
        <version>2.7.0</version>
    </dependency>

我的代码如下:

    YarnConfiguration conf = new YarnConfiguration();
    YarnClient yarnClient = YarnClient.createYarnClient();
    yarnClient.init(conf);
    yarnClient.start();
    List<ApplicationReport> list =  yarnClient.getApplications();
    System.out.print(list.size());
    yarnClient.stop();

但这被挂在行 List< ApplicationReport>list = yarnClient.getApplications(),并且不会向前移动.

But this gets hanged at line List<ApplicationReport> list = yarnClient.getApplications() and doesn't move forward.

推荐答案

当我的YarnConfiguration配置不正确时,我的代码挂在了 #getApplications()上.默认情况下,它使用 0.0.0.0:8032 作为纱线资源管理器地址.我必须用正确的地址覆盖它:

I had my code hang on #getApplications() when my YarnConfiguration wasn't properly configured. By default it uses 0.0.0.0:8032 as Yarn Resource Manager address. I had to overwrite this with correct address:

YarnConfiguration conf = new YarnConfiguration();
conf.set("yarn.resourcemanager.address", "<hostname>:<port>");
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();

我在Hadoop 2.6.0上进行了测试,但看起来2.7.0的默认设置也相同(请参见

I tested this with Hadoop 2.6.0, but looks like defaults are the same for 2.7.0 as well (see sources).

这篇关于通过Java列出hadoop集群中的所有yarn应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆