CapacitySchedulerConfigValidator { public static boolean validateCSConfiguration( final Configuration oldConf, final Configuration newConf, final RMContext rmContext) throws IOException { CapacityScheduler newCs = new CapacityScheduler(); try { newCs.setConf(oldConf); newCs.setRMContext(rmContext); newCs.init(oldConf); newCs.reinitialize(newConf, rmContext, true); return true; } finally { newCs.stop(); } } private  CapacitySchedulerConfigValidator(); static boolean validateCSConfiguration(
          final Configuration oldConf, final Configuration newConf,
          final RMContext rmContext); static Set<String> validatePlacementRules(
          Collection<String> placementRuleStrs); static void validateMemoryAllocation(Configuration conf); static void validateVCores(Configuration conf); static void validateQueueHierarchy(
      CSQueueStore queues,
      CSQueueStore newQueues,
      CapacitySchedulerConfiguration newConf);  }
@Test public void testValidateCSConfigInvalidCapacity() { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig .set("yarn.scheduler.capacity.root.test1.capacity", "500"); RMContext rmContext = prepareRMContext(); try { CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity"); } catch (IOException e) { Assert.assertTrue(e.getCause().getMessage() .startsWith("Illegal capacity")); } }
@Test public void testValidateCSConfigStopALeafQueue() throws IOException { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig .set("yarn.scheduler.capacity.root.test1.state", "STOPPED"); RMContext rmContext = prepareRMContext(); Boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); Assert.assertTrue(isValidConfig); }
@Test public void testValidateCSConfigStopANonLeafQueueInvalid() { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig .set("yarn.scheduler.capacity.root.state", "STOPPED"); RMContext rmContext = prepareRMContext(); try { CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("There are child queues in running state"); } catch (IOException e) { Assert.assertTrue(e.getCause().getMessage() .contains("The parent queue:root cannot be STOPPED")); } }
@Test public void testValidateCSConfigStopANonLeafQueue() throws IOException { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig .set("yarn.scheduler.capacity.root.state", "STOPPED"); newConfig .set("yarn.scheduler.capacity.root.test1.state", "STOPPED"); newConfig .set("yarn.scheduler.capacity.root.test2.state", "STOPPED"); RMContext rmContext = prepareRMContext(); Boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); Assert.assertTrue(isValidConfig); }
@Test public void testValidateCSConfigAddALeafQueueInvalid() { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig .set("yarn.scheduler.capacity.root.queues", "test1, test2, test3"); newConfig .set("yarn.scheduler.capacity.root.test3.state", "RUNNING"); newConfig .set("yarn.scheduler.capacity.root.test3.capacity", "30"); RMContext rmContext = prepareRMContext(); try { CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity for children of queue root"); } catch (IOException e) { Assert.assertTrue(e.getCause().getMessage() .startsWith("Illegal capacity")); } }
@Test public void testValidateCSConfigAddALeafQueueValid() throws IOException { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig .set("yarn.scheduler.capacity.root.queues", "test1, test2, test3"); newConfig .set("yarn.scheduler.capacity.root.test3.state", "RUNNING"); newConfig .set("yarn.scheduler.capacity.root.test3.capacity", "30"); newConfig .set("yarn.scheduler.capacity.root.test1.capacity", "20"); RMContext rmContext = prepareRMContext(); Boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); Assert.assertTrue(isValidConfig); }
@Test public void testValidateCSConfigInvalidQueueDeletion() { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig.set("yarn.scheduler.capacity.root.queues", "test1"); newConfig.set("yarn.scheduler.capacity.root.test1.capacity", "100"); newConfig.unset("yarn.scheduler.capacity.root.test2.maximum-capacity"); newConfig.unset("yarn.scheduler.capacity.root.test2.state"); newConfig.set("yarn.scheduler.capacity.queue-mappings", "u:test1:test1"); RMContext rmContext = prepareRMContext(); try { CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity for children of queue root"); } catch (IOException e) { Assert.assertTrue(e.getCause().getMessage() .contains("root.test2 cannot be deleted")); Assert.assertTrue(e.getCause().getMessage() .contains("the queue is not yet in stopped state")); } }
@Test public void testValidateCSConfigInvalidQueueDeletion2() { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); Configuration newConfig = new Configuration(oldConfig); newConfig.set("yarn.scheduler.capacity.root.queues", "test1"); newConfig.unset("yarn.scheduler.capacity.root.test2.maximum-capacity"); newConfig.unset("yarn.scheduler.capacity.root.test2.state"); newConfig.set("yarn.scheduler.capacity.queue-mappings", "u:test1:test1"); RMContext rmContext = prepareRMContext(); try { CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity for children of queue root"); } catch (IOException e) { Assert.assertTrue(e.getCause().getMessage() .contains("Illegal capacity")); } }
@Test public void testValidateCSConfigValidQueueDeletion() throws IOException { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); oldConfig.set("yarn.scheduler.capacity.root.test2.state", "STOPPED"); Configuration newConfig = new Configuration(oldConfig); newConfig.set("yarn.scheduler.capacity.root.queues", "test1"); newConfig.set("yarn.scheduler.capacity.root.test1.capacity", "100"); newConfig.unset("yarn.scheduler.capacity.root.test2.maximum-capacity"); newConfig.unset("yarn.scheduler.capacity.root.test2.state"); newConfig.set("yarn.scheduler.capacity.queue-mappings", "u:test1:test1"); RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); Assert.assertTrue(isValidConfig); }
@Test public void testAddQueueToALeafQueue() throws IOException { Configuration oldConfig = CapacitySchedulerConfigGeneratorForTest .createBasicCSConfiguration(); oldConfig.set("yarn.scheduler.capacity.root.test1.state", "STOPPED"); Configuration newConfig = new Configuration(oldConfig); newConfig.set("yarn.scheduler.capacity.root.test1.queues", "newQueue"); newConfig .set("yarn.scheduler.capacity.root.test1.newQueue.capacity", "100"); newConfig.set("yarn.scheduler.capacity.queue-mappings", "u:test1:test2"); RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); Assert.assertTrue(isValidConfig); }