Pārlūkot izejas kodu

YARN-9553. Fix NPE in EntityGroupFSTimelineStore#getEntityTimelines. Contributed by Prabhu Joseph.

Giovanni Matteo Fumarola 6 gadi atpakaļ
vecāks
revīzija
f1552f6edb

+ 5 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java

@@ -1115,6 +1115,11 @@ public class EntityGroupFSTimelineStore extends CompositeService
     LOG.debug("getEntityTimelines type={} ids={}", entityType, entityIds);
     TimelineEvents returnEvents = new TimelineEvents();
     List<EntityCacheItem> relatedCacheItems = new ArrayList<>();
+
+    if (entityIds == null || entityIds.isEmpty()) {
+      return returnEvents;
+    }
+
     for (String entityId : entityIds) {
       LOG.debug("getEntityTimeline type={} id={}", entityType, entityId);
       List<TimelineStore> stores

+ 11 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java

@@ -41,6 +41,7 @@ import org.apache.hadoop.yarn.server.timeline.EntityGroupFSTimelineStore.AppStat
 import org.apache.hadoop.yarn.server.timeline.TimelineReader.Field;
 import org.apache.hadoop.yarn.util.ConverterUtils;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -379,6 +380,16 @@ public class TestEntityGroupFSTimelineStore extends TimelineStoreTestUtils {
     assertFalse(fs.exists(clusterTimeStampDir1));
   }
 
+  @Test
+  public void testNullCheckGetEntityTimelines() throws Exception {
+    try {
+      store.getEntityTimelines("YARN_APPLICATION", null, null, null, null,
+          null);
+    } catch (NullPointerException e) {
+      Assert.fail("NPE when getEntityTimelines called with Null EntityIds");
+    }
+  }
+
   @Test
   public void testPluginRead() throws Exception {
     // Verify precondition