|
@@ -18,12 +18,18 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
|
|
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
|
|
|
|
|
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
|
|
+import org.apache.hadoop.security.GroupMappingServiceProvider;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.placement.ApplicationPlacementContext;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.placement.PlacementRule;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.placement.PlacementRule;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMappingEntity;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMappingEntity;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping;
|
|
|
|
+import org.apache.hadoop.yarn.util.Records;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -32,7 +38,7 @@ import java.util.List;
|
|
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.getQueueMapping;
|
|
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.getQueueMapping;
|
|
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.setupQueueConfiguration;
|
|
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.setupQueueConfiguration;
|
|
import static org.hamcrest.CoreMatchers.hasItems;
|
|
import static org.hamcrest.CoreMatchers.hasItems;
|
|
-import static org.junit.Assert.assertThat;
|
|
|
|
|
|
+import static org.junit.Assert.*;
|
|
|
|
|
|
public class TestCapacitySchedulerQueueMappingFactory {
|
|
public class TestCapacitySchedulerQueueMappingFactory {
|
|
|
|
|
|
@@ -125,4 +131,123 @@ public class TestCapacitySchedulerQueueMappingFactory {
|
|
assertThat(placementRuleNames, hasItems(QUEUE_MAPPING_RULE_USER_GROUP));
|
|
assertThat(placementRuleNames, hasItems(QUEUE_MAPPING_RULE_USER_GROUP));
|
|
assertThat(placementRuleNames, hasItems(QUEUE_MAPPING_RULE_APP_NAME));
|
|
assertThat(placementRuleNames, hasItems(QUEUE_MAPPING_RULE_APP_NAME));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testNestedUserQueueWithDynamicParentQueue() throws Exception {
|
|
|
|
+
|
|
|
|
+ CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
|
|
|
|
+ setupQueueConfiguration(conf);
|
|
|
|
+ conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
|
|
|
|
+ ResourceScheduler.class);
|
|
|
|
+ conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
|
|
|
|
+ SimpleGroupsMapping.class, GroupMappingServiceProvider.class);
|
|
|
|
+
|
|
|
|
+ List<String> queuePlacementRules = new ArrayList<>();
|
|
|
|
+ queuePlacementRules.add(QUEUE_MAPPING_RULE_USER_GROUP);
|
|
|
|
+ conf.setQueuePlacementRules(queuePlacementRules);
|
|
|
|
+
|
|
|
|
+ List<UserGroupMappingPlacementRule.QueueMapping> existingMappingsForUG =
|
|
|
|
+ conf.getQueueMappings();
|
|
|
|
+
|
|
|
|
+ // set queue mapping
|
|
|
|
+ List<UserGroupMappingPlacementRule.QueueMapping> queueMappingsForUG =
|
|
|
|
+ new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // u:%user:%primary_group.%user
|
|
|
|
+ UserGroupMappingPlacementRule.QueueMapping userQueueMapping =
|
|
|
|
+ new UserGroupMappingPlacementRule.QueueMapping(
|
|
|
|
+ UserGroupMappingPlacementRule.QueueMapping.MappingType.USER,
|
|
|
|
+ "%user", getQueueMapping("%primary_group", "%user"));
|
|
|
|
+ queueMappingsForUG.add(userQueueMapping);
|
|
|
|
+
|
|
|
|
+ existingMappingsForUG.addAll(queueMappingsForUG);
|
|
|
|
+ conf.setQueueMappings(existingMappingsForUG);
|
|
|
|
+
|
|
|
|
+ // override with queue mappings
|
|
|
|
+ conf.setOverrideWithQueueMappings(true);
|
|
|
|
+
|
|
|
|
+ mockRM = new MockRM(conf);
|
|
|
|
+ CapacityScheduler cs = (CapacityScheduler) mockRM.getResourceScheduler();
|
|
|
|
+ cs.updatePlacementRules();
|
|
|
|
+ mockRM.start();
|
|
|
|
+ cs.start();
|
|
|
|
+
|
|
|
|
+ ApplicationSubmissionContext asc =
|
|
|
|
+ Records.newRecord(ApplicationSubmissionContext.class);
|
|
|
|
+ asc.setQueue("default");
|
|
|
|
+ String inputUser = "a";
|
|
|
|
+
|
|
|
|
+ List<PlacementRule> rules =
|
|
|
|
+ cs.getRMContext().getQueuePlacementManager().getPlacementRules();
|
|
|
|
+
|
|
|
|
+ UserGroupMappingPlacementRule r =
|
|
|
|
+ (UserGroupMappingPlacementRule) rules.get(0);
|
|
|
|
+ ApplicationPlacementContext ctx = r.getPlacementForApp(asc, inputUser);
|
|
|
|
+ assertEquals("Queue", "a", ctx.getQueue());
|
|
|
|
+ assertEquals("Group", "agroup", ctx.getParentQueue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testNestedUserQueueWithStaticParentQueue() throws Exception {
|
|
|
|
+
|
|
|
|
+ CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
|
|
|
|
+ setupQueueConfiguration(conf);
|
|
|
|
+ conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
|
|
|
|
+ ResourceScheduler.class);
|
|
|
|
+ conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
|
|
|
|
+ SimpleGroupsMapping.class, GroupMappingServiceProvider.class);
|
|
|
|
+
|
|
|
|
+ List<String> queuePlacementRules = new ArrayList<>();
|
|
|
|
+ queuePlacementRules.add(QUEUE_MAPPING_RULE_USER_GROUP);
|
|
|
|
+ conf.setQueuePlacementRules(queuePlacementRules);
|
|
|
|
+
|
|
|
|
+ List<UserGroupMappingPlacementRule.QueueMapping> existingMappingsForUG =
|
|
|
|
+ conf.getQueueMappings();
|
|
|
|
+
|
|
|
|
+ // set queue mapping
|
|
|
|
+ List<UserGroupMappingPlacementRule.QueueMapping> queueMappingsForUG =
|
|
|
|
+ new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // u:user1:b1
|
|
|
|
+ UserGroupMappingPlacementRule.QueueMapping userQueueMapping1 =
|
|
|
|
+ new UserGroupMappingPlacementRule.QueueMapping(
|
|
|
|
+ UserGroupMappingPlacementRule.QueueMapping.MappingType.USER, "user1",
|
|
|
|
+ "b1");
|
|
|
|
+ // u:%user:parentqueue.%user
|
|
|
|
+ UserGroupMappingPlacementRule.QueueMapping userQueueMapping2 =
|
|
|
|
+ new UserGroupMappingPlacementRule.QueueMapping(
|
|
|
|
+ UserGroupMappingPlacementRule.QueueMapping.MappingType.USER, "%user",
|
|
|
|
+ getQueueMapping("c", "%user"));
|
|
|
|
+ queueMappingsForUG.add(userQueueMapping1);
|
|
|
|
+ queueMappingsForUG.add(userQueueMapping2);
|
|
|
|
+
|
|
|
|
+ existingMappingsForUG.addAll(queueMappingsForUG);
|
|
|
|
+ conf.setQueueMappings(existingMappingsForUG);
|
|
|
|
+
|
|
|
|
+ // override with queue mappings
|
|
|
|
+ conf.setOverrideWithQueueMappings(true);
|
|
|
|
+
|
|
|
|
+ mockRM = new MockRM(conf);
|
|
|
|
+ CapacityScheduler cs = (CapacityScheduler) mockRM.getResourceScheduler();
|
|
|
|
+ cs.updatePlacementRules();
|
|
|
|
+ mockRM.start();
|
|
|
|
+ cs.start();
|
|
|
|
+
|
|
|
|
+ ApplicationSubmissionContext asc =
|
|
|
|
+ Records.newRecord(ApplicationSubmissionContext.class);
|
|
|
|
+ asc.setQueue("default");
|
|
|
|
+
|
|
|
|
+ List<PlacementRule> rules =
|
|
|
|
+ cs.getRMContext().getQueuePlacementManager().getPlacementRules();
|
|
|
|
+
|
|
|
|
+ UserGroupMappingPlacementRule r =
|
|
|
|
+ (UserGroupMappingPlacementRule) rules.get(0);
|
|
|
|
+
|
|
|
|
+ ApplicationPlacementContext ctx = r.getPlacementForApp(asc, "user1");
|
|
|
|
+ assertEquals("Queue", "b1", ctx.getQueue());
|
|
|
|
+
|
|
|
|
+ ApplicationPlacementContext ctx2 = r.getPlacementForApp(asc, "user2");
|
|
|
|
+ assertEquals("Queue", "user2", ctx2.getQueue());
|
|
|
|
+ assertEquals("Queue", "c", ctx2.getParentQueue());
|
|
|
|
+ }
|
|
}
|
|
}
|