YARN-9791. Queue Mutation API does not allow to remove a config. Contributed by Prabhu Joseph.

(cherry picked from commit 751b5a1ac8)
This commit is contained in:
Abhishek Modi 2019-09-01 13:33:09 +05:30 committed by prabhujoseph
parent dab4cc6320
commit 96e07b7e97
2 changed files with 42 additions and 3 deletions

View File

@ -332,12 +332,14 @@ public class MutableCSConfigurationProvider implements CSConfigurationProvider,
String keyPrefix = CapacitySchedulerConfiguration.PREFIX String keyPrefix = CapacitySchedulerConfiguration.PREFIX
+ queuePath + CapacitySchedulerConfiguration.DOT; + queuePath + CapacitySchedulerConfiguration.DOT;
for (Map.Entry<String, String> kv : updateInfo.getParams().entrySet()) { for (Map.Entry<String, String> kv : updateInfo.getParams().entrySet()) {
if (kv.getValue() == null) { String keyValue = kv.getValue();
if (keyValue == null || keyValue.isEmpty()) {
keyValue = null;
proposedConf.unset(keyPrefix + kv.getKey()); proposedConf.unset(keyPrefix + kv.getKey());
} else { } else {
proposedConf.set(keyPrefix + kv.getKey(), kv.getValue()); proposedConf.set(keyPrefix + kv.getKey(), keyValue);
} }
confUpdate.put(keyPrefix + kv.getKey(), kv.getValue()); confUpdate.put(keyPrefix + kv.getKey(), keyValue);
} }
} }
} }

View File

@ -103,4 +103,41 @@ public class TestMutableCSConfigurationProvider {
assertNull(confProvider.loadConfiguration(conf) assertNull(confProvider.loadConfiguration(conf)
.get("yarn.scheduler.capacity.root.a.goodKey")); .get("yarn.scheduler.capacity.root.a.goodKey"));
} }
@Test
public void testRemoveQueueConfig() throws Exception {
Configuration conf = new Configuration();
conf.set(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
YarnConfiguration.MEMORY_CONFIGURATION_STORE);
confProvider.init(conf);
SchedConfUpdateInfo updateInfo = new SchedConfUpdateInfo();
Map<String, String> updateMap = new HashMap<>();
updateMap.put("testkey1", "testval1");
updateMap.put("testkey2", "testval2");
QueueConfigInfo queueConfigInfo = new
QueueConfigInfo("root.a", updateMap);
updateInfo.getUpdateQueueInfo().add(queueConfigInfo);
confProvider.logAndApplyMutation(TEST_USER, updateInfo);
confProvider.confirmPendingMutation(true);
assertEquals("testval1", confProvider.loadConfiguration(conf)
.get("yarn.scheduler.capacity.root.a.testkey1"));
assertEquals("testval2", confProvider.loadConfiguration(conf)
.get("yarn.scheduler.capacity.root.a.testkey2"));
// Unset testkey1.
updateInfo = new SchedConfUpdateInfo();
updateMap.put("testkey1", "");
queueConfigInfo = new QueueConfigInfo("root.a", updateMap);
updateInfo.getUpdateQueueInfo().add(queueConfigInfo);
confProvider.logAndApplyMutation(TEST_USER, updateInfo);
confProvider.confirmPendingMutation(true);
assertNull("Failed to remove config",
confProvider.loadConfiguration(conf)
.get("yarn.scheduler.capacity.root.a.testkey1"));
assertEquals("testval2", confProvider.loadConfiguration(conf)
.get("yarn.scheduler.capacity.root.a.testkey2"));
}
} }