From 8d150067e2e4d6c15b319d250e2e1b804066b6b6 Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Thu, 4 Apr 2019 13:01:56 -0400 Subject: [PATCH] YARN-9396. Fixed duplicated RM Container created event to ATS. Contributed by Prabhu Joseph --- .../server/resourcemanager/rmcontainer/RMContainerImpl.java | 5 ++++- .../resourcemanager/rmcontainer/TestRMContainerImpl.java | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/RMContainerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/RMContainerImpl.java index 1185170953..004c170262 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/RMContainerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/RMContainerImpl.java @@ -608,7 +608,10 @@ public void transition(RMContainerImpl container, RMContainerEvent event) { container.eventHandler.handle(new RMAppRunningOnNodeEvent(container .getApplicationAttemptId().getApplicationId(), container.nodeId)); - publishNonAMContainerEventstoATS(container); + // Opportunistic containers move directly from NEW to ACQUIRED + if (container.getState() == RMContainerState.NEW) { + publishNonAMContainerEventstoATS(container); + } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java index 2dfbf2073a..256bd94197 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java @@ -150,7 +150,7 @@ public void testReleaseWhileRunning() { RMContainerEventType.LAUNCHED)); drainDispatcher.await(); assertEquals(RMContainerState.RUNNING, rmContainer.getState()); - verify(publisher, times(2)).containerCreated(any(RMContainer.class), + verify(publisher, times(1)).containerCreated(any(RMContainer.class), anyLong()); assertEquals("http://host:3465/node/containerlogs/container_1_0001_01_000001/user", rmContainer.getLogURL()); @@ -253,7 +253,7 @@ public void testExpireWhileRunning() { RMContainerEventType.ACQUIRED)); drainDispatcher.await(); assertEquals(RMContainerState.ACQUIRED, rmContainer.getState()); - verify(publisher, times(2)).containerCreated(any(RMContainer.class), + verify(publisher, times(1)).containerCreated(any(RMContainer.class), anyLong()); rmContainer.handle(new RMContainerEvent(containerId, @@ -345,7 +345,7 @@ public void testStoreAllContainerMetrics() throws Exception { // RMContainer should be publishing system metrics for all containers. // Since there is 1 AM container and 1 non-AM container, there should be 2 // container created events and 2 container finished events. - verify(publisher, times(4)).containerCreated(any(RMContainer.class), + verify(publisher, times(2)).containerCreated(any(RMContainer.class), anyLong()); verify(publisher, times(2)).containerFinished(any(RMContainer.class), anyLong()); }