YARN-10109. Allow stop and convert from leaf to parent queue in a single Mutation API call. Contributed by Prabhu Joseph

(cherry picked from commit 28f730b317)
This commit is contained in:
Sunil G 2020-02-09 21:14:53 +05:30
parent 7be104a9be
commit 95b1cbcbd4
2 changed files with 45 additions and 9 deletions

View File

@ -122,18 +122,20 @@ public final class CapacitySchedulerConfigValidator {
String queueName = e.getKey(); String queueName = e.getKey();
CSQueue oldQueue = e.getValue(); CSQueue oldQueue = e.getValue();
CSQueue newQueue = newQueues.get(queueName); CSQueue newQueue = newQueues.get(queueName);
if (null == newQueue) { String configPrefix = newConf.getQueuePrefix(
// old queue doesn't exist in the new XML oldQueue.getQueuePath());
String configPrefix = newConf.getQueuePrefix( String state = newConf.get(configPrefix + "state");
oldQueue.getQueuePath()); QueueState newQueueState = null;
QueueState newQueueState = null; if (state != null) {
try { try {
newQueueState = QueueState.valueOf( newQueueState = QueueState.valueOf(state);
newConf.get(configPrefix + "state"));
} catch (Exception ex) { } catch (Exception ex) {
LOG.warn("Not a valid queue state for queue " 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 || if (oldQueue.getState() == QueueState.STOPPED ||
newQueueState == QueueState.STOPPED) { newQueueState == QueueState.STOPPED) {
LOG.info("Deleting Queue " + queueName + ", as it is not" LOG.info("Deleting Queue " + queueName + ", as it is not"
@ -169,7 +171,8 @@ public final class CapacitySchedulerConfigValidator {
+ " is set to true"); + " is set to true");
} else if (oldQueue instanceof LeafQueue } else if (oldQueue instanceof LeafQueue
&& newQueue instanceof ParentQueue) { && newQueue instanceof ParentQueue) {
if (oldQueue.getState() == QueueState.STOPPED) { if (oldQueue.getState() == QueueState.STOPPED ||
newQueueState == QueueState.STOPPED) {
LOG.info("Converting the leaf queue: " + oldQueue.getQueuePath() LOG.info("Converting the leaf queue: " + oldQueue.getQueuePath()
+ " to parent queue."); + " to parent queue.");
} else{ } else{

View File

@ -458,6 +458,39 @@ public class TestRMWebServicesConfigurationMutation extends JerseyTestBase {
assertEquals("a1", newCSConf.getQueues("root.a")[0]); 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<String, String> stoppedParam = new HashMap<>();
stoppedParam.put(CapacitySchedulerConfiguration.STATE,
QueueState.STOPPED.toString());
QueueConfigInfo stoppedInfo = new QueueConfigInfo("root.b",
stoppedParam);
updateInfo.getUpdateQueueInfo().add(stoppedInfo);
Map<String, String> 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 @Test
public void testRemoveParentQueue() throws Exception { public void testRemoveParentQueue() throws Exception {
WebResource r = resource(); WebResource r = resource();