From 6f9d7a146d5940a9e8a7913c19b43b265d6bfa32 Mon Sep 17 00:00:00 2001 From: Billie Rinaldi Date: Mon, 20 Nov 2017 07:37:04 -0800 Subject: [PATCH] YARN-7529. TestYarnNativeServices#testRecoverComponentsAfterRMRestart() fails intermittently. Contributed by Chandni Singh --- .../yarn/service/TestYarnNativeServices.java | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java index f98d90a6f3..1c517d941b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java @@ -176,7 +176,8 @@ public void testRecoverComponentsAfterRMRestart() throws Exception { ServiceClient client = createClient(); Service exampleApp = createExampleApplication(); client.actionCreate(exampleApp); - waitForAllCompToBeReady(client, exampleApp); + Multimap containersBeforeFailure = + waitForAllCompToBeReady(client, exampleApp); LOG.info("Restart the resource manager"); getYarnCluster().restartResourceManager( @@ -191,9 +192,6 @@ public void testRecoverComponentsAfterRMRestart() throws Exception { ApplicationAttemptId applicationAttemptId = client.getYarnClient() .getApplicationReport(exampleAppId).getCurrentApplicationAttemptId(); - Multimap containersBeforeFailure = getContainersForAllComp( - client, exampleApp); - LOG.info("Fail the application attempt {}", applicationAttemptId); client.getYarnClient().failApplicationAttempt(applicationAttemptId); //wait until attempt 2 is running @@ -208,7 +206,7 @@ public void testRecoverComponentsAfterRMRestart() throws Exception { } }, 2000, 200000); - Multimap containersAfterFailure = getContainersForAllComp( + Multimap containersAfterFailure = waitForAllCompToBeReady( client, exampleApp); Assert.assertEquals("component container affected by restart", containersBeforeFailure, containersAfterFailure); @@ -318,14 +316,26 @@ private void waitForOneCompToBeReady(ServiceClient client, }, 2000, 200000); } - // wait until all the containers for all components become ready state - private void waitForAllCompToBeReady(ServiceClient client, + /** + * Wait until all the containers for all components become ready state. + * + * @param client + * @param exampleApp + * @return all ready containers of a service. + * @throws TimeoutException + * @throws InterruptedException + */ + private Multimap waitForAllCompToBeReady(ServiceClient client, Service exampleApp) throws TimeoutException, InterruptedException { int expectedTotalContainers = countTotalContainers(exampleApp); + + Multimap allContainers = HashMultimap.create(); + GenericTestUtils.waitFor(() -> { try { Service retrievedApp = client.getStatus(exampleApp.getName()); int totalReadyContainers = 0; + allContainers.clear(); LOG.info("Num Components " + retrievedApp.getComponents().size()); for (Component component : retrievedApp.getComponents()) { LOG.info("looking for " + component.getName()); @@ -339,6 +349,7 @@ private void waitForAllCompToBeReady(ServiceClient client, + component.getName()); if (container.getState() == ContainerState.READY) { totalReadyContainers++; + allContainers.put(component.getName(), container.getId()); LOG.info("Found 1 ready container " + container.getId()); } } @@ -358,23 +369,6 @@ private void waitForAllCompToBeReady(ServiceClient client, return false; } }, 2000, 200000); - } - - /** - * Get all containers of a service. - */ - private Multimap getContainersForAllComp(ServiceClient client, - Service example) throws IOException, YarnException { - - Multimap allContainers = HashMultimap.create(); - Service retrievedApp = client.getStatus(example.getName()); - retrievedApp.getComponents().forEach(component -> { - if (component.getContainers() != null) { - component.getContainers().forEach(container -> { - allContainers.put(component.getName(), container.getId()); - }); - } - }); return allContainers; }