From 199598f37861f2a77b1ee9cef1f7213a97577fc4 Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Thu, 30 May 2019 14:46:42 +0530 Subject: [PATCH] YARN-9553. Fix NPE from TimelineWebService getEvents. --- .../yarn/server/timeline/EntityGroupFSTimelineStore.java | 5 +++++ .../yarn/server/timeline/TestEntityGroupFSTimelineStore.java | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java index 498230a..a5e5b41 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/main/java/org/apache/hadoop/yarn/server/timeline/EntityGroupFSTimelineStore.java +++ b/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 TimelineEvents getEntityTimelines(String entityType, LOG.debug("getEntityTimelines type={} ids={}", entityType, entityIds); TimelineEvents returnEvents = new TimelineEvents(); List relatedCacheItems = new ArrayList<>(); + + if (entityIds == null || entityIds.isEmpty()) { + return returnEvents; + } + for (String entityId : entityIds) { LOG.debug("getEntityTimeline type={} id={}", entityType, entityId); List stores diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java index dc10912..8fcc696 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timeline-pluginstorage/src/test/java/org/apache/hadoop/yarn/server/timeline/TestEntityGroupFSTimelineStore.java +++ b/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.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; @@ -380,6 +381,16 @@ public void testCleanBuckets() throws Exception { } @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 assertEquals(EntityGroupPlugInForTest.class.getName(), -- 2.7.4 (Apple Git-66)