Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

how to get data from Yarn Resource Manager REST API using JAVA

Solved Go to solution

how to get data from Yarn Resource Manager REST API using JAVA

Contributor

Hi All,

Could someone help me out how to start fetching data from YARN Rest API using Java. please share me some sample links.

Tanx and Regards,

MJ

1 ACCEPTED SOLUTION

Accepted Solutions

Re: how to get data from Yarn Resource Manager REST API using JAVA

Expert Contributor

@Manikandan Jeyabal

Your question is not quite clear to me. If you really want to fetch data from the YARN Resource Manager REST API in Java, all you need to do is open an HttpURLConnection and get the data from any endpoint. E.g.:

URL url = new URL("http://" + rmHost + ":8088/ws/v1/cluster/apps");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
... // read and process your data
conn.disconnect();

But there is a much easier solution to get data from the RM in Java: YarnClient, which is basically a Java API for YARN.

YarnClient yarnClient = YarnClient.createYarnClient();
Configuration conf = new YarnConfiguration();
conf.set("yarn.resourcemanager.hostname", "your RM hostname");
yarnClient.init(conf);
yarnClient.start();
for (ApplicationReport applicationReport : yarnClient.getApplications()) {
  System.out.println(applicationReport.getApplicationId());
}
2 REPLIES 2

Re: how to get data from Yarn Resource Manager REST API using JAVA

Super Guru

Re: how to get data from Yarn Resource Manager REST API using JAVA

Expert Contributor

@Manikandan Jeyabal

Your question is not quite clear to me. If you really want to fetch data from the YARN Resource Manager REST API in Java, all you need to do is open an HttpURLConnection and get the data from any endpoint. E.g.:

URL url = new URL("http://" + rmHost + ":8088/ws/v1/cluster/apps");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
... // read and process your data
conn.disconnect();

But there is a much easier solution to get data from the RM in Java: YarnClient, which is basically a Java API for YARN.

YarnClient yarnClient = YarnClient.createYarnClient();
Configuration conf = new YarnConfiguration();
conf.set("yarn.resourcemanager.hostname", "your RM hostname");
yarnClient.init(conf);
yarnClient.start();
for (ApplicationReport applicationReport : yarnClient.getApplications()) {
  System.out.println(applicationReport.getApplicationId());
}