Abhinav
Abhinav

Reputation: 63

List all yarn application in hadoop cluster through java

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.

Upvotes: 2

Views: 2180

Answers (1)

arghtype
arghtype

Reputation: 4544

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).

Upvotes: 2

Related Questions