diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java index 90175153fc4..75342176168 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java @@ -3188,7 +3188,8 @@ public class CapacityScheduler extends // check only for maximum, that's enough because default can't // exceed maximum if (maximumApplicationLifetime <= 0) { - return lifetimeRequestedByApp; + return (lifetimeRequestedByApp <= 0) ? defaultApplicationLifetime : + lifetimeRequestedByApp; } if (lifetimeRequestedByApp <= 0) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java index a6c78e5accd..fdf04ebc1cb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/LeafQueue.java @@ -263,7 +263,8 @@ public class LeafQueue extends AbstractCSQueue { conf.getMaximumLifetimePerQueue((getQueuePath())); defaultApplicationLifetime = conf.getDefaultLifetimePerQueue((getQueuePath())); - if (defaultApplicationLifetime > maxApplicationLifetime) { + if (maxApplicationLifetime > 0 && + defaultApplicationLifetime > maxApplicationLifetime) { throw new YarnRuntimeException( "Default lifetime" + defaultApplicationLifetime + " can't exceed maximum lifetime " + maxApplicationLifetime); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java index 5572960be95..6c5ecc5453a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java @@ -4891,7 +4891,8 @@ public class TestCapacityScheduler extends CapacitySchedulerTestBase { Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1)); - Assert.assertEquals(0, cs.checkAndGetApplicationLifetime("default", 0)); + Assert.assertEquals(defaultLifetime, + cs.checkAndGetApplicationLifetime("default", 0)); Assert.assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); @@ -4911,8 +4912,10 @@ public class TestCapacityScheduler extends CapacitySchedulerTestBase { defaultLifetime = 0; cs = setUpCSQueue(maxLifetime, defaultLifetime); Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100)); - Assert.assertEquals(-1, cs.checkAndGetApplicationLifetime("default", -1)); - Assert.assertEquals(0, cs.checkAndGetApplicationLifetime("default", 0)); + Assert.assertEquals(defaultLifetime, + cs.checkAndGetApplicationLifetime("default", -1)); + Assert.assertEquals(defaultLifetime, + cs.checkAndGetApplicationLifetime("default", 0)); maxLifetime = 10; defaultLifetime = -1; @@ -4933,6 +4936,16 @@ public class TestCapacityScheduler extends CapacitySchedulerTestBase { Assert.assertTrue( ye.getMessage().contains("can't exceed maximum lifetime")); } + + maxLifetime = -1; + defaultLifetime = 10; + cs = setUpCSQueue(maxLifetime, defaultLifetime); + Assert.assertEquals(100, + cs.checkAndGetApplicationLifetime("default", 100)); + Assert.assertEquals(defaultLifetime, + cs.checkAndGetApplicationLifetime("default", -1)); + Assert.assertEquals(defaultLifetime, + cs.checkAndGetApplicationLifetime("default", 0)); } private CapacityScheduler setUpCSQueue(long maxLifetime,