|
@@ -19,6 +19,9 @@
|
|
|
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.metrics2.MetricsSource;
|
|
|
+import org.apache.hadoop.metrics2.MetricsSystem;
|
|
|
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
|
|
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
|
|
|
import org.apache.hadoop.yarn.LocalConfigurationProvider;
|
|
|
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
|
|
@@ -32,6 +35,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.placement.PlacementManager;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
|
import org.apache.hadoop.yarn.util.YarnVersionInfo;
|
|
|
import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
|
|
@@ -425,6 +429,98 @@ public class TestCapacitySchedulerConfigValidator {
|
|
|
Assert.assertTrue(isValidConfig);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testValidateDoesNotModifyTheDefaultMetricsSystem() throws Exception {
|
|
|
+ try {
|
|
|
+ YarnConfiguration conf = new YarnConfiguration(CapacitySchedulerConfigGeneratorForTest
|
|
|
+ .createBasicCSConfiguration());
|
|
|
+ conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
|
|
|
+ ResourceScheduler.class);
|
|
|
+ mockRM = new MockRM(conf);
|
|
|
+
|
|
|
+ cs = (CapacityScheduler) mockRM.getResourceScheduler();
|
|
|
+ mockRM.start();
|
|
|
+ cs.start();
|
|
|
+ RMContext rmContext = mockRM.getRMContext();
|
|
|
+ Configuration oldConfig = cs.getConfig();
|
|
|
+
|
|
|
+ final Map<String, QueueMetrics> cache = QueueMetrics.getQueueMetrics();
|
|
|
+ final MetricsSystem ms = DefaultMetricsSystem.instance();
|
|
|
+
|
|
|
+ QueueMetrics origQM1 = cache.get("root.test1");
|
|
|
+ QueueMetrics origQM2 = cache.get("root.test2");
|
|
|
+ Assert.assertNotNull("Original queues should be found in the cache", origQM1);
|
|
|
+ Assert.assertNotNull("Original queues should be found in the cache", origQM2);
|
|
|
+
|
|
|
+ QueueMetrics origPQM1 = cache.get("default.root.test1");
|
|
|
+ QueueMetrics origPQM2 = cache.get("default.root.test2");
|
|
|
+ Assert.assertNotNull("Original queues should be found in the cache (PartitionQueueMetrics)",
|
|
|
+ origPQM1);
|
|
|
+ Assert.assertNotNull("Original queues should be found in the cache (PartitionQueueMetrics)",
|
|
|
+ origPQM2);
|
|
|
+
|
|
|
+ MetricsSource origMS1 =
|
|
|
+ ms.getSource("QueueMetrics,q0=root,q1=test1");
|
|
|
+ MetricsSource origMS2 =
|
|
|
+ ms.getSource("QueueMetrics,q0=root,q1=test2");
|
|
|
+ Assert.assertNotNull("Original queues should be found in the Metrics System",
|
|
|
+ origMS1);
|
|
|
+ Assert.assertNotNull("Original queues should be found in the Metrics System",
|
|
|
+ origMS2);
|
|
|
+
|
|
|
+ MetricsSource origPMS1 = ms
|
|
|
+ .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test1");
|
|
|
+ MetricsSource origPMS2 = ms
|
|
|
+ .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test2");
|
|
|
+ Assert.assertNotNull(
|
|
|
+ "Original queues should be found in Metrics System (PartitionQueueMetrics)", origPMS1);
|
|
|
+ Assert.assertNotNull(
|
|
|
+ "Original queues should be found in Metrics System (PartitionQueueMetrics)", origPMS2);
|
|
|
+
|
|
|
+ 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");
|
|
|
+
|
|
|
+ boolean isValidConfig = CapacitySchedulerConfigValidator
|
|
|
+ .validateCSConfiguration(oldConfig, newConfig, rmContext);
|
|
|
+ Assert.assertTrue(isValidConfig);
|
|
|
+
|
|
|
+ Assert.assertFalse("Validated new queue should not be in the cache",
|
|
|
+ cache.containsKey("root.test3"));
|
|
|
+ Assert.assertFalse("Validated new queue should not be in the cache (PartitionQueueMetrics)",
|
|
|
+ cache.containsKey("default.root.test3"));
|
|
|
+ Assert.assertNull("Validated new queue should not be in the Metrics System",
|
|
|
+ ms.getSource("QueueMetrics,q0=root,q1=test3"));
|
|
|
+ Assert.assertNull(
|
|
|
+ "Validated new queue should not be in Metrics System (PartitionQueueMetrics)",
|
|
|
+ ms
|
|
|
+ .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test3"));
|
|
|
+
|
|
|
+ // Config validation should not change the existing
|
|
|
+ // objects in the cache and the metrics system
|
|
|
+ Assert.assertEquals(origQM1, cache.get("root.test1"));
|
|
|
+ Assert.assertEquals(origQM2, cache.get("root.test2"));
|
|
|
+ Assert.assertEquals(origPQM1, cache.get("default.root.test1"));
|
|
|
+ Assert.assertEquals(origPQM1, cache.get("default.root.test1"));
|
|
|
+ Assert.assertEquals(origMS1,
|
|
|
+ ms.getSource("QueueMetrics,q0=root,q1=test1"));
|
|
|
+ Assert.assertEquals(origMS2,
|
|
|
+ ms.getSource("QueueMetrics,q0=root,q1=test2"));
|
|
|
+ Assert.assertEquals(origPMS1,
|
|
|
+ ms.getSource("PartitionQueueMetrics,partition=,q0=root,q1=test1"));
|
|
|
+ Assert.assertEquals(origPMS2,
|
|
|
+ ms.getSource("PartitionQueueMetrics,partition=,q0=root,q1=test2"));
|
|
|
+ } finally {
|
|
|
+ mockRM.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Delete a running queue.
|
|
|
*/
|