From 6c96f5e4b6aec05e9ce74bb229a317cdf95f5d40 Mon Sep 17 00:00:00 2001 From: Rohith Sharma K S Date: Wed, 27 Feb 2019 10:32:58 +0530 Subject: [PATCH] YARN-8378. ApplicationHistoryManagerImpl#getApplications doesn't honor filters. Contributed by Lantao Jin. --- .../ApplicationHistoryManagerImpl.java | 10 +++++++++ .../ApplicationHistoryStoreTestUtils.java | 6 ++++++ .../TestApplicationHistoryManagerImpl.java | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerImpl.java index 48a729496d..385b8062ff 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerImpl.java @@ -104,10 +104,20 @@ public Map getApplications(long appsNum, historyStore.getAllApplications(); HashMap applicationsReport = new HashMap(); + int count = 0; for (Entry entry : histData .entrySet()) { + if (count == appsNum) { + break; + } + long appStartTime = entry.getValue().getStartTime(); + if (appStartTime < appStartedTimeBegin + || appStartTime > appStartedTimeEnd) { + continue; + } applicationsReport.put(entry.getKey(), convertToApplicationReport(entry.getValue())); + count++; } return applicationsReport; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryStoreTestUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryStoreTestUtils.java index de4051a494..a6511de8ac 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryStoreTestUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryStoreTestUtils.java @@ -47,6 +47,12 @@ protected void writeApplicationStartData(ApplicationId appId) appId.toString(), "test type", "test queue", "test user", 0, 0)); } + protected void writeApplicationStartData(ApplicationId appId, long startTime) + throws IOException { + store.applicationStarted(ApplicationStartData.newInstance(appId, + appId.toString(), "test type", "test queue", "test user", 0, startTime)); + } + protected void writeApplicationFinishData(ApplicationId appId) throws IOException { store.applicationFinished(ApplicationFinishData.newInstance(appId, 0, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerImpl.java index fec2bf3457..da5ddc183b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerImpl.java @@ -19,6 +19,7 @@ package org.apache.hadoop.yarn.server.applicationhistoryservice; import java.io.IOException; +import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; @@ -71,4 +72,24 @@ public void testApplicationReport() throws IOException, YarnException { Assert.assertEquals("test type", appReport.getApplicationType().toString()); Assert.assertEquals("test queue", appReport.getQueue().toString()); } + + @Test + public void testApplications() throws IOException { + ApplicationId appId1 = ApplicationId.newInstance(0, 1); + ApplicationId appId2 = ApplicationId.newInstance(0, 2); + ApplicationId appId3 = ApplicationId.newInstance(0, 3); + writeApplicationStartData(appId1, 1000); + writeApplicationFinishData(appId1); + writeApplicationStartData(appId2, 3000); + writeApplicationFinishData(appId2); + writeApplicationStartData(appId3, 4000); + writeApplicationFinishData(appId3); + Map reports = + applicationHistoryManagerImpl.getApplications(2, 2000L, 5000L); + Assert.assertNotNull(reports); + Assert.assertEquals(2, reports.size()); + Assert.assertNull(reports.get("1")); + Assert.assertNull(reports.get("2")); + Assert.assertNull(reports.get("3")); + } }