瀏覽代碼

YARN-4152. NodeManager crash with NPE when LogAggregationService#stopContainer called for absent container. (Bibin A Chundatt via rohithsharmaks)

Rohith Sharma K S 9 年之前
父節點
當前提交
8ed0d4b744

+ 3 - 0
hadoop-yarn-project/CHANGES.txt

@@ -896,6 +896,9 @@ Release 2.8.0 - UNRELEASED
 
     YARN-4171. Fix findbugs warnings in YARN-1197 branch. (Wangda Tan via jianhe)
 
+    YARN-4152. NodeManager crash with NPE when LogAggregationService#stopContainer called for 
+    absent container. (Bibin A Chundatt via rohithsharmaks)
+
 Release 2.7.2 - UNRELEASED
 
   INCOMPATIBLE CHANGES

+ 9 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/LogAggregationService.java

@@ -56,6 +56,7 @@ import org.apache.hadoop.yarn.server.nodemanager.DeletionService;
 import org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService;
 import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent;
 import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEventType;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
 import org.apache.hadoop.yarn.server.nodemanager.containermanager.loghandler.LogHandler;
 import org.apache.hadoop.yarn.server.nodemanager.containermanager.loghandler.event.LogHandlerAppFinishedEvent;
 import org.apache.hadoop.yarn.server.nodemanager.containermanager.loghandler.event.LogHandlerAppStartedEvent;
@@ -423,8 +424,14 @@ public class LogAggregationService extends AbstractService implements
           + ", did it fail to start?");
       return;
     }
-    ContainerType containerType = context.getContainers().get(
-        containerId).getContainerTokenIdentifier().getContainerType();
+    Container container = context.getContainers().get(containerId);
+    if (null == container) {
+      LOG.warn("Log aggregation cannot be started for " + containerId
+          + ", as its an absent container");
+      return;
+    }
+    ContainerType containerType =
+        container.getContainerTokenIdentifier().getContainerType();
     aggregator.startContainerLogAggregation(
         new ContainerLogContext(containerId, containerType, exitCode));
   }

+ 19 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java

@@ -1509,6 +1509,25 @@ public class TestLogAggregationService extends BaseContainerManagerTest {
     verifyLogAggFinishEvent(appId);
   }
 
+  @Test(timeout = 50000)
+  public void testLogAggregationAbsentContainer() throws Exception {
+    ApplicationId appId = createApplication();
+    LogAggregationService logAggregationService =
+        createLogAggregationService(appId,
+            FailedOrKilledContainerLogAggregationPolicy.class, null);
+    ApplicationAttemptId appAttemptId1 =
+        BuilderUtils.newApplicationAttemptId(appId, 1);
+    ContainerId containerId = BuilderUtils.newContainerId(appAttemptId1, 2l);
+    try {
+      logAggregationService.handle(new LogHandlerContainerFinishedEvent(
+          containerId, 100));
+      assertTrue("Should skip when null containerID", true);
+    } catch (Exception e) {
+      Assert.assertFalse("Exception not expected should skip null containerid",
+          true);
+    }
+  }
+
   @Test (timeout = 50000)
   @SuppressWarnings("unchecked")
   public void testAMOnlyContainerPolicy() throws Exception {