hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rohithsharm...@apache.org
Subject [hadoop] 02/02: YARN-8378. ApplicationHistoryManagerImpl#getApplications doesn't honor filters. Contributed by Lantao Jin.
Date Wed, 27 Feb 2019 05:11:37 GMT
This is an automated email from the ASF dual-hosted git repository.

rohithsharmaks pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git

commit 6c96f5e4b6aec05e9ce74bb229a317cdf95f5d40
Author: Rohith Sharma K S <rohithsharmaks@apache.org>
AuthorDate: Wed Feb 27 10:32:58 2019 +0530

    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 48a7294..385b806 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 class ApplicationHistoryManagerImpl extends AbstractService implements
         historyStore.getAllApplications();
     HashMap<ApplicationId, ApplicationReport> applicationsReport =
         new HashMap<ApplicationId, ApplicationReport>();
+    int count = 0;
     for (Entry<ApplicationId, ApplicationHistoryData> 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 de4051a..a6511de 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 @@ public class ApplicationHistoryStoreTestUtils {
       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 fec2bf3..da5ddc1 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 class TestApplicationHistoryManagerImpl extends
     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<ApplicationId, ApplicationReport> 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"));
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message