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/CapacitySchedulerConfigValidator.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/CapacitySchedulerConfigValidator.java index 525ea43ba66..3957c5fcab1 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/CapacitySchedulerConfigValidator.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/CapacitySchedulerConfigValidator.java @@ -122,18 +122,20 @@ public final class CapacitySchedulerConfigValidator { String queueName = e.getKey(); CSQueue oldQueue = e.getValue(); CSQueue newQueue = newQueues.get(queueName); - if (null == newQueue) { - // old queue doesn't exist in the new XML - String configPrefix = newConf.getQueuePrefix( - oldQueue.getQueuePath()); - QueueState newQueueState = null; + String configPrefix = newConf.getQueuePrefix( + oldQueue.getQueuePath()); + String state = newConf.get(configPrefix + "state"); + QueueState newQueueState = null; + if (state != null) { try { - newQueueState = QueueState.valueOf( - newConf.get(configPrefix + "state")); + newQueueState = QueueState.valueOf(state); } catch (Exception ex) { LOG.warn("Not a valid queue state for queue " - + oldQueue.getQueuePath()); + + oldQueue.getQueuePath()); } + } + if (null == newQueue) { + // old queue doesn't exist in the new XML if (oldQueue.getState() == QueueState.STOPPED || newQueueState == QueueState.STOPPED) { LOG.info("Deleting Queue " + queueName + ", as it is not" @@ -169,7 +171,8 @@ public final class CapacitySchedulerConfigValidator { + " is set to true"); } else if (oldQueue instanceof LeafQueue && newQueue instanceof ParentQueue) { - if (oldQueue.getState() == QueueState.STOPPED) { + if (oldQueue.getState() == QueueState.STOPPED || + newQueueState == QueueState.STOPPED) { LOG.info("Converting the leaf queue: " + oldQueue.getQueuePath() + " to parent queue."); } else{ diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesConfigurationMutation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesConfigurationMutation.java index b92fbfb40f4..4bb50eab9c9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesConfigurationMutation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesConfigurationMutation.java @@ -490,6 +490,39 @@ public class TestRMWebServicesConfigurationMutation extends JerseyTestBase { assertEquals("a1", newCSConf.getQueues("root.a")[0]); } + @Test + public void testStopWithConvertLeafToParentQueue() throws Exception { + WebResource r = resource(); + ClientResponse response; + + // Set state of queues to STOPPED. + SchedConfUpdateInfo updateInfo = new SchedConfUpdateInfo(); + Map stoppedParam = new HashMap<>(); + stoppedParam.put(CapacitySchedulerConfiguration.STATE, + QueueState.STOPPED.toString()); + QueueConfigInfo stoppedInfo = new QueueConfigInfo("root.b", + stoppedParam); + updateInfo.getUpdateQueueInfo().add(stoppedInfo); + + Map b1Capacity = new HashMap<>(); + b1Capacity.put(CapacitySchedulerConfiguration.CAPACITY, "100"); + QueueConfigInfo b1 = new QueueConfigInfo("root.b.b1", b1Capacity); + updateInfo.getAddQueueInfo().add(b1); + + response = r.path("ws").path("v1").path("cluster") + .path("scheduler-conf").queryParam("user.name", userName) + .accept(MediaType.APPLICATION_JSON) + .entity(YarnWebServiceUtils.toJson(updateInfo, + SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON) + .put(ClientResponse.class); + + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + CapacitySchedulerConfiguration newCSConf = + ((CapacityScheduler) rm.getResourceScheduler()).getConfiguration(); + assertEquals(1, newCSConf.getQueues("root.b").length); + assertEquals("b1", newCSConf.getQueues("root.b")[0]); + } + @Test public void testRemoveParentQueue() throws Exception { WebResource r = resource();