运行命令 yarn application -list
在我的 hadoop 集群上,它返回正在运行的应用程序列表。
我想使用 Java 获取此列表。
目前我正在使用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()
行并且不会前进。
最佳答案
当我的 YarnConfiguration 未正确配置时,我的代码卡在 #getApplications()
上。默认情况下,它使用 0.0.0.0:8032
作为 Yarn 资源管理器地址。我必须用正确的地址覆盖它:
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 的默认值也相同(请参阅 sources )。
关于java - 通过java列出hadoop集群中所有yarn应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52717163/