Support Questions

Find answers, ask questions, and share your expertise

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

avatar
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

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

View solution in original post

2 REPLIES 2

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