本文整理匯總了Java中org.apache.hadoop.yarn.client.api.YarnClient.getContainers方法的典型用法代碼示例。如果您正苦於以下問題:Java YarnClient.getContainers方法的具體用法?Java YarnClient.getContainers怎麽用?Java YarnClient.getContainers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.yarn.client.api.YarnClient
的用法示例。
在下文中一共展示了YarnClient.getContainers方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLiveContainerIdsFromRM
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
public static HashSet<String> getLiveContainerIdsFromRM(String attemptId, String amContainerId) throws Exception {
HashSet<String> containerIds = new HashSet<>();
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
List<ContainerReport> containerReports = yarnClient.getContainers(ConverterUtils.toApplicationAttemptId(attemptId));
yarnClient.stop();
// Since we at least has AM container, so we check whether the containerReports is reliable
if (containerReports == null) {
throw new Exception(
String.format("Container reports of attempt %s is empty , but AM container exists",
attemptId));
}
for (ContainerReport containerReport : containerReports) {
if (containerReport.getContainerState() == ContainerState.COMPLETE) {
continue;
}
containerIds.add(containerReport.getContainerId().toString());
}
if (!containerIds.contains(amContainerId)) {
throw new Exception(
String.format("Container reports of attempt %s does not contain AM container %s",
attemptId, amContainerId));
}
containerIds.remove(amContainerId);
return containerIds;
}
示例2: testGetContainers
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
@Test(timeout = 10000)
public void testGetContainers() throws YarnException, IOException {
Configuration conf = new Configuration();
conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
true);
final YarnClient client = new MockYarnClient();
client.init(conf);
client.start();
ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
applicationId, 1);
List<ContainerReport> reports = client.getContainers(appAttemptId);
Assert.assertNotNull(reports);
Assert.assertEquals(reports.get(0).getContainerId(),
(ContainerId.newContainerId(appAttemptId, 1)));
Assert.assertEquals(reports.get(1).getContainerId(),
(ContainerId.newContainerId(appAttemptId, 2)));
Assert.assertEquals(reports.get(2).getContainerId(),
(ContainerId.newContainerId(appAttemptId, 3)));
//First2 containers should come from RM with updated state information and
// 3rd container is not there in RM and should
Assert.assertEquals(ContainerState.RUNNING,
(reports.get(0).getContainerState()));
Assert.assertEquals(ContainerState.RUNNING,
(reports.get(1).getContainerState()));
Assert.assertEquals(ContainerState.COMPLETE,
(reports.get(2).getContainerState()));
client.stop();
}