From 751b5a1ac871734c46cb934d100a5367f1dbf791 Mon Sep 17 00:00:00 2001 From: Abhishek Modi Date: Sun, 1 Sep 2019 22:40:40 +0530 Subject: [PATCH] YARN-9791. Queue Mutation API does not allow to remove a config. Contributed by Prabhu Joseph. --- .../conf/MutableCSConfigurationProvider.java | 8 ++-- .../TestMutableCSConfigurationProvider.java | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) 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 6a13d2d911..0677bd8e43 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 @@ -280,12 +280,14 @@ private void updateQueue(QueueConfigInfo updateInfo, String keyPrefix = CapacitySchedulerConfiguration.PREFIX + queuePath + CapacitySchedulerConfiguration.DOT; for (Map.Entry kv : updateInfo.getParams().entrySet()) { - if (kv.getValue() == null) { + String keyValue = kv.getValue(); + if (keyValue == null || keyValue.isEmpty()) { + keyValue = null; proposedConf.unset(keyPrefix + kv.getKey()); } 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); } } } 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 81bc7a71ee..64fc80c110 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 @@ -106,6 +106,43 @@ public void testInMemoryBackedProvider() throws Exception { "yarn.scheduler.capacity.root.a.badKey")); } + @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 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")); + } + @Test public void testHDFSBackedProvider() throws Exception { File testSchedulerConfigurationDir = new File(