Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java (date 1508293083000) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java (date 1508358322000) @@ -1797,4 +1797,10 @@ ReadLock getSchedulerReadLock() { return this.readLock; } + + @Override + public long checkAndGetApplicationLifetime(String queueName, long lifetime) { + // Lifetime is the application lifetime by default. + return lifetime; + } } Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java (date 1508293083000) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java (date 1508358322000) @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; @@ -54,6 +56,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; import org.apache.hadoop.yarn.util.Times; import org.apache.log4j.Level; import org.apache.log4j.LogManager; @@ -81,8 +84,17 @@ 3000L); } - @Test(timeout = 60000) + @Test(timeout = 120000) public void testApplicationLifetimeMonitor() throws Exception { + List schedulers = new LinkedList<>(); + schedulers.add(CapacityScheduler.class); + schedulers.add(FairScheduler.class); + for (Class scheduler : schedulers) { + testApplicationLifetimeMonitorWorker(scheduler); + } + } + + public void testApplicationLifetimeMonitorWorker(Class scheduler) throws Exception { MockRM rm = null; try { long maxLifetime = 30L; @@ -91,6 +103,7 @@ YarnConfiguration newConf = new YarnConfiguration(setUpCSQueue(maxLifetime, defaultLifetime)); conf = new YarnConfiguration(newConf); + conf.set(YarnConfiguration.RM_SCHEDULER, scheduler.getName()); rm = new MockRM(conf); rm.start(); @@ -172,17 +185,20 @@ Assert.assertTrue("Application killed before lifetime value", app2.getFinishTime() > afterUpdate); - rm.waitForState(app3.getApplicationId(), RMAppState.KILLED); + if (rm.getResourceScheduler() instanceof CapacityScheduler) { + // Supported only on capacity scheduler + rm.waitForState(app3.getApplicationId(), RMAppState.KILLED); - // app4 submitted exceeding queue max lifetime, so killed after queue max - // lifetime. - rm.waitForState(app4.getApplicationId(), RMAppState.KILLED); - long totalTimeRun = (app4.getFinishTime() - app4.getSubmitTime()) / 1000; - Assert.assertTrue("Application killed before lifetime value", - totalTimeRun > maxLifetime); - Assert.assertTrue( - "Application killed before lifetime value " + totalTimeRun, - totalTimeRun < maxLifetime + 10L); + // app4 submitted exceeding queue max lifetime, so killed after queue max + // lifetime. + rm.waitForState(app4.getApplicationId(), RMAppState.KILLED); + long totalTimeRun = (app4.getFinishTime() - app4.getSubmitTime()) / 1000; + Assert.assertTrue("Application killed before lifetime value", + totalTimeRun > maxLifetime); + Assert.assertTrue( + "Application killed before lifetime value " + totalTimeRun, + totalTimeRun < maxLifetime + 10L); + } } finally { stopRM(rm); }