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/conf/MutableCSConfigurationProvider.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/conf/MutableCSConfigurationProvider.java index 5f262be83d..b74414b93c 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/conf/MutableCSConfigurationProvider.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/conf/MutableCSConfigurationProvider.java @@ -68,10 +68,18 @@ public MutableCSConfigurationProvider(RMContext rmContext) { this.rmContext = rmContext; } + // Unit test can overwrite this method + protected Configuration getInitSchedulerConfig() { + Configuration initialSchedConf = new Configuration(false); + initialSchedConf. + addResource(YarnConfiguration.CS_CONFIGURATION_FILE); + return initialSchedConf; + } + @Override public void init(Configuration config) throws IOException { this.confStore = YarnConfigurationStoreFactory.getStore(config); - Configuration initialSchedConf = new Configuration(false); + Configuration initialSchedConf = getInitSchedulerConfig(); initialSchedConf.addResource(YarnConfiguration.CS_CONFIGURATION_FILE); this.schedConf = new Configuration(false); // We need to explicitly set the key-values in schedConf, otherwise @@ -231,7 +239,7 @@ private List getSiblingQueues(String queuePath, Configuration conf) { String childQueuesKey = CapacitySchedulerConfiguration.PREFIX + parentQueue + CapacitySchedulerConfiguration.DOT + CapacitySchedulerConfiguration.QUEUES; - return new ArrayList<>(conf.getStringCollection(childQueuesKey)); + return new ArrayList<>(conf.getTrimmedStringCollection(childQueuesKey)); } private Map constructKeyValueConfUpdate( 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/conf/TestMutableCSConfigurationProvider.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/conf/TestMutableCSConfigurationProvider.java index 0c9a312056..aec2c21956 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/conf/TestMutableCSConfigurationProvider.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/conf/TestMutableCSConfigurationProvider.java @@ -217,6 +217,39 @@ public void testHDFSBackedProvider() throws Exception { } + @Test + public void testAddRemoveQueueWithSpacesInConfig() throws Exception { + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + csConf.setQueues(CapacitySchedulerConfiguration.ROOT, + new String[] {" a , b, c" }); + + final String a = CapacitySchedulerConfiguration.ROOT + ".a"; + final String b = CapacitySchedulerConfiguration.ROOT + ".b"; + final String c = CapacitySchedulerConfiguration.ROOT + ".c"; + csConf.setCapacity(a, 0); + csConf.setCapacity(b, 50); + csConf.setCapacity(c, 50); + + confProvider = new MutableCSConfigurationProvider(rmContext) { + @Override + protected Configuration getInitSchedulerConfig() { + return csConf; + } + }; + + Configuration conf = new Configuration(); + conf.set(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS, + YarnConfiguration.MEMORY_CONFIGURATION_STORE); + confProvider.init(conf); + + SchedConfUpdateInfo update = new SchedConfUpdateInfo(); + update.getRemoveQueueInfo().add("root.a"); + + confProvider.logAndApplyMutation(UserGroupInformation + .getCurrentUser(), update); + } + private void writeConf(Configuration conf, String storePath) throws IOException { FileSystem fileSystem = FileSystem.get(new Configuration(conf));