List all yarn application in hadoop cluster through java

纵饮孤独 提交于 2019-12-11 09:48:43

问题


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

I want to fetch this list using Java.

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>

My code looks like :

    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();

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


回答1:


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();

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



来源:https://stackoverflow.com/questions/52717163/list-all-yarn-application-in-hadoop-cluster-through-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!