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/CapacitySchedulerConfiguration.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/CapacitySchedulerConfiguration.java index 0a49224..a42bf54 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/CapacitySchedulerConfiguration.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/CapacitySchedulerConfiguration.java @@ -260,7 +260,7 @@ public CapacitySchedulerConfiguration(Configuration configuration, } } - private String getQueuePrefix(String queue) { + static String getQueuePrefix(String queue) { String queueName = PREFIX + queue + DOT; return queueName; } @@ -538,6 +538,14 @@ public void setAcls(String queue, Map acls) { public String[] getQueues(String queue) { LOG.debug("CSConf - getQueues called for: queuePrefix=" + getQueuePrefix(queue)); String[] queues = getStrings(getQueuePrefix(queue) + QUEUES); + List trimmedQueueNames = new ArrayList(); + if (null != queues) { + for (String s : queues) { + trimmedQueueNames.add(s.trim()); + } + queues = trimmedQueueNames.toArray(new String[0]); + } + LOG.debug("CSConf - getQueues: queuePrefix=" + getQueuePrefix(queue) + ", queues=" + ((queues == null) ? "" : StringUtils.arrayToString(queues))); return queues; 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/TestQueueParsing.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/TestQueueParsing.java index cf2e5ce..5a9fbe1 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/TestQueueParsing.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/TestQueueParsing.java @@ -82,6 +82,56 @@ public void testQueueParsing() throws Exception { ServiceOperations.stopQuietly(capacityScheduler); } + private void setupQueueConfigurationWithSpacesShouldBeTrimmed( + CapacitySchedulerConfiguration conf) { + // Define top-level queues + conf.set( + CapacitySchedulerConfiguration + .getQueuePrefix(CapacitySchedulerConfiguration.ROOT) + + CapacitySchedulerConfiguration.QUEUES, " a ,b, c"); + + final String A = CapacitySchedulerConfiguration.ROOT + ".a"; + conf.setCapacity(A, 10); + conf.setMaximumCapacity(A, 15); + + final String B = CapacitySchedulerConfiguration.ROOT + ".b"; + conf.setCapacity(B, 20); + + final String C = CapacitySchedulerConfiguration.ROOT + ".c"; + conf.setCapacity(C, 70); + conf.setMaximumCapacity(C, 70); + } + + private void setupNestedQueueConfigurationWithSpacesShouldBeTrimmed( + CapacitySchedulerConfiguration conf) { + // Define top-level queues + conf.set( + CapacitySchedulerConfiguration + .getQueuePrefix(CapacitySchedulerConfiguration.ROOT) + + CapacitySchedulerConfiguration.QUEUES, " a ,b, c"); + + final String A = CapacitySchedulerConfiguration.ROOT + ".a"; + conf.setCapacity(A, 10); + conf.setMaximumCapacity(A, 15); + + final String B = CapacitySchedulerConfiguration.ROOT + ".b"; + conf.setCapacity(B, 20); + + final String C = CapacitySchedulerConfiguration.ROOT + ".c"; + conf.setCapacity(C, 70); + conf.setMaximumCapacity(C, 70); + + // sub queues for A + conf.set(CapacitySchedulerConfiguration.getQueuePrefix(A) + + CapacitySchedulerConfiguration.QUEUES, "a1, a2 "); + + final String A1 = CapacitySchedulerConfiguration.ROOT + ".a.a1"; + conf.setCapacity(A1, 60); + + final String A2 = CapacitySchedulerConfiguration.ROOT + ".a.a2"; + conf.setCapacity(A2, 40); + } + private void setupQueueConfiguration(CapacitySchedulerConfiguration conf) { // Define top-level queues @@ -659,4 +709,64 @@ public void testQueueParsingWithUnusedLabels() throws IOException { DELTA); capacityScheduler.stop(); } + + @Test + public void testQueueParsingShouldTrimSpaces() throws Exception { + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + setupQueueConfigurationWithSpacesShouldBeTrimmed(csConf); + YarnConfiguration conf = new YarnConfiguration(csConf); + + CapacityScheduler capacityScheduler = new CapacityScheduler(); + capacityScheduler.setConf(conf); + capacityScheduler.setRMContext(TestUtils.getMockRMContext()); + capacityScheduler.init(conf); + capacityScheduler.start(); + capacityScheduler.reinitialize(conf, TestUtils.getMockRMContext()); + + CSQueue a = capacityScheduler.getQueue("a"); + Assert.assertNotNull(a); + Assert.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); + Assert.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); + + CSQueue c = capacityScheduler.getQueue("c"); + Assert.assertNotNull(c); + Assert.assertEquals(0.70, c.getAbsoluteCapacity(), DELTA); + Assert.assertEquals(0.70, c.getAbsoluteMaximumCapacity(), DELTA); + } + + @Test + public void testNestedQueueParsingShouldTrimSpaces() throws Exception { + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + setupNestedQueueConfigurationWithSpacesShouldBeTrimmed(csConf); + YarnConfiguration conf = new YarnConfiguration(csConf); + + CapacityScheduler capacityScheduler = new CapacityScheduler(); + capacityScheduler.setConf(conf); + capacityScheduler.setRMContext(TestUtils.getMockRMContext()); + capacityScheduler.init(conf); + capacityScheduler.start(); + capacityScheduler.reinitialize(conf, TestUtils.getMockRMContext()); + + CSQueue a = capacityScheduler.getQueue("a"); + Assert.assertNotNull(a); + Assert.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); + Assert.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); + + CSQueue c = capacityScheduler.getQueue("c"); + Assert.assertNotNull(c); + Assert.assertEquals(0.70, c.getAbsoluteCapacity(), DELTA); + Assert.assertEquals(0.70, c.getAbsoluteMaximumCapacity(), DELTA); + + CSQueue a1 = capacityScheduler.getQueue("a1"); + Assert.assertNotNull(a1); + Assert.assertEquals(0.10 * 0.6, a1.getAbsoluteCapacity(), DELTA); + Assert.assertEquals(0.15, a1.getAbsoluteMaximumCapacity(), DELTA); + + CSQueue a2 = capacityScheduler.getQueue("a2"); + Assert.assertNotNull(a2); + Assert.assertEquals(0.10 * 0.4, a2.getAbsoluteCapacity(), DELTA); + Assert.assertEquals(0.15, a2.getAbsoluteMaximumCapacity(), DELTA); + } }