@Test public void testGroupContainsPeriod() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("<queuePlacementPolicy>"); sb.append(" <rule name='specified' create='false' />"); sb.append(" <rule name='nestedUserQueue'>"); sb.append(" <rule name='primaryGroup'/>"); sb.append(" </rule>"); sb.append(" <rule name='default' />"); sb.append("</queuePlacementPolicy>"); conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, PeriodGroupsMapping.class, GroupMappingServiceProvider.class); // User queue would be created under primary group queue, and the period // in the group name should be converted into _dot_ QueuePlacementPolicy policy = parse(sb.toString()); assertEquals("root.user1_dot_group.user1", policy.assignAppToQueue("root.default", "user1")); conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); }
@Before public void init() throws HadoopIllegalArgumentException, IOException { conf = new JobConf(); conf.set(JHAdminConfig.JHS_ADMIN_ADDRESS, "0.0.0.0:0"); conf.setClass("hadoop.security.group.mapping", MockUnixGroupsMapping.class, GroupMappingServiceProvider.class); conf.setLong("hadoop.security.groups.cache.secs", groupRefreshTimeoutSec); Groups.getUserToGroupsMappingService(conf); jobHistoryService = mock(JobHistory.class); alds = mock(AggregatedLogDeletionService.class); hsAdminServer = new HSAdminServer(alds, jobHistoryService) { @Override protected Configuration createConf() { return conf; } }; hsAdminServer.init(conf); hsAdminServer.start(); conf.setSocketAddr(JHAdminConfig.JHS_ADMIN_ADDRESS, hsAdminServer.clientRpcServer.getListenerAddress()); hsAdminClient = new HSAdmin(conf); }
@Before public void init() throws HadoopIllegalArgumentException, IOException { conf = new Configuration(); conf.set(JHAdminConfig.JHS_ADMIN_ADDRESS, "0.0.0.0:0"); conf.setClass("hadoop.security.group.mapping", MockUnixGroupsMapping.class, GroupMappingServiceProvider.class); conf.setLong("hadoop.security.groups.cache.secs", groupRefreshTimeoutSec); Groups.getUserToGroupsMappingService(conf); jobHistoryService = mock(JobHistory.class); alds = mock(AggregatedLogDeletionService.class); hsAdminServer = new HSAdminServer(alds, jobHistoryService) { @Override protected Configuration createConf() { return conf; } }; hsAdminServer.init(conf); hsAdminServer.start(); conf.setSocketAddr(JHAdminConfig.JHS_ADMIN_ADDRESS, hsAdminServer.clientRpcServer.getListenerAddress()); hsAdminClient = new HSAdmin(conf); }
@Test public void testNestedUserQueue() throws IOException { conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE); conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE)); out.println("<?xml version=\"1.0\"?>"); out.println("<allocations>"); out.println("<queue name=\"user1group\" type=\"parent\">"); out.println("<minResources>1024mb,0vcores,0gcores</minResources>"); out.println("</queue>"); out.println("<queuePlacementPolicy>"); out.println("<rule name=\"specified\" create=\"false\" />"); out.println("<rule name=\"nestedUserQueue\">"); out.println(" <rule name=\"primaryGroup\" create=\"false\" />"); out.println("</rule>"); out.println("<rule name=\"default\" />"); out.println("</queuePlacementPolicy>"); out.println("</allocations>"); out.close(); scheduler.init(conf); scheduler.start(); scheduler.reinitialize(conf, resourceManager.getRMContext()); RMApp rmApp1 = new MockRMApp(0, 0, RMAppState.NEW); FSLeafQueue user1Leaf = scheduler.assignToQueue(rmApp1, "root.default", "user1"); assertEquals("root.user1group.user1", user1Leaf.getName()); }
@Test public void testSteadyFairShareWithQueueCreatedRuntime() throws Exception { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); conf.set(FairSchedulerConfiguration.USER_AS_DEFAULT_QUEUE, "true"); scheduler.init(conf); scheduler.start(); scheduler.reinitialize(conf, resourceManager.getRMContext()); // Add one node RMNode node1 = MockNodes .newNodeInfo(1, Resources.createResource(6144), 1, "127.0.0.1"); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1); scheduler.handle(nodeEvent1); assertEquals(6144, scheduler.getClusterResource().getMemory()); assertEquals(6144, scheduler.getQueueManager().getRootQueue() .getSteadyFairShare().getMemory()); assertEquals(6144, scheduler.getQueueManager() .getLeafQueue("default", false).getSteadyFairShare().getMemory()); // Submit one application ApplicationAttemptId appAttemptId1 = createAppAttemptId(1, 1); createApplicationWithAMResource(appAttemptId1, "default", "user1", null); assertEquals(3072, scheduler.getQueueManager() .getLeafQueue("default", false).getSteadyFairShare().getMemory()); assertEquals(3072, scheduler.getQueueManager() .getLeafQueue("user1", false).getSteadyFairShare().getMemory()); }
@Before public void init() throws HadoopIllegalArgumentException, IOException { conf = new JobConf(); conf.set(JHAdminConfig.JHS_ADMIN_ADDRESS, "0.0.0.0:0"); conf.setClass("hadoop.security.group.mapping", MockUnixGroupsMapping.class, GroupMappingServiceProvider.class); conf.setLong("hadoop.security.groups.cache.secs", groupRefreshTimeoutSec); conf.setBoolean( CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, securityEnabled); Groups.getUserToGroupsMappingService(conf); jobHistoryService = mock(JobHistory.class); alds = mock(AggregatedLogDeletionService.class); hsAdminServer = new HSAdminServer(alds, jobHistoryService) { @Override protected Configuration createConf() { return conf; } }; hsAdminServer.init(conf); hsAdminServer.start(); conf.setSocketAddr(JHAdminConfig.JHS_ADMIN_ADDRESS, hsAdminServer.clientRpcServer.getListenerAddress()); hsAdminClient = new HSAdmin(conf); }
@Test public void testNestedUserQueue() throws IOException { conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE); conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE)); out.println("<?xml version=\"1.0\"?>"); out.println("<allocations>"); out.println("<queue name=\"user1group\" type=\"parent\">"); out.println("<minResources>1024mb,0vcores</minResources>"); out.println("</queue>"); out.println("<queuePlacementPolicy>"); out.println("<rule name=\"specified\" create=\"false\" />"); out.println("<rule name=\"nestedUserQueue\">"); out.println(" <rule name=\"primaryGroup\" create=\"false\" />"); out.println("</rule>"); out.println("<rule name=\"default\" />"); out.println("</queuePlacementPolicy>"); out.println("</allocations>"); out.close(); scheduler.init(conf); scheduler.start(); scheduler.reinitialize(conf, resourceManager.getRMContext()); RMApp rmApp1 = new MockRMApp(0, 0, RMAppState.NEW); FSLeafQueue user1Leaf = scheduler.assignToQueue(rmApp1, "root.default", "user1"); assertEquals("root.user1group.user1", user1Leaf.getName()); }
@Test public void testSteadyFairShareWithQueueCreatedRuntime() throws Exception { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); conf.set(FairSchedulerConfiguration.USER_AS_DEFAULT_QUEUE, "true"); scheduler.init(conf); scheduler.start(); scheduler.reinitialize(conf, resourceManager.getRMContext()); // Add one node RMNode node1 = MockNodes .newNodeInfo(1, Resources.createResource(6144), 1, "127.0.0.1"); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1); scheduler.handle(nodeEvent1); assertEquals(6144, scheduler.getClusterResource().getMemorySize()); assertEquals(6144, scheduler.getQueueManager().getRootQueue() .getSteadyFairShare().getMemorySize()); assertEquals(6144, scheduler.getQueueManager() .getLeafQueue("default", false).getSteadyFairShare().getMemorySize()); // Submit one application ApplicationAttemptId appAttemptId1 = createAppAttemptId(1, 1); createApplicationWithAMResource(appAttemptId1, "default", "user1", null); assertEquals(3072, scheduler.getQueueManager() .getLeafQueue("default", false).getSteadyFairShare().getMemorySize()); assertEquals(3072, scheduler.getQueueManager() .getLeafQueue("user1", false).getSteadyFairShare().getMemorySize()); }
@Test public void testRefreshUserToGroupsMappingsWithFileSystemBasedConfigurationProvider() throws IOException, YarnException { configuration.set(YarnConfiguration.RM_CONFIGURATION_PROVIDER_CLASS, "org.apache.hadoop.yarn.FileSystemBasedConfigurationProvider"); String[] defaultTestUserGroups = {"dummy_group1", "dummy_group2"}; UserGroupInformation ugi = UserGroupInformation.createUserForTesting ("dummyUser", defaultTestUserGroups); String user = ugi.getUserName(); List<String> groupWithInit = new ArrayList<String>(2); for(int i = 0; i < ugi.getGroupNames().length; i++ ) { groupWithInit.add(ugi.getGroupNames()[i]); } // upload default configurations uploadDefaultConfiguration(); Configuration conf = new Configuration(); conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, MockUnixGroupsMapping.class, GroupMappingServiceProvider.class); uploadConfiguration(conf, "core-site.xml"); try { rm = new MockRM(configuration); rm.init(configuration); rm.start(); } catch (Exception ex) { fail("Should not get any exceptions"); } // Make sure RM will use the updated GroupMappingServiceProvider List<String> groupBefore = new ArrayList<String>(Groups.getUserToGroupsMappingService( configuration).getGroups(user)); Assert.assertTrue(groupBefore.contains("test_group_A") && groupBefore.contains("test_group_B") && groupBefore.contains("test_group_C") && groupBefore.size() == 3); Assert.assertTrue(groupWithInit.size() != groupBefore.size()); Assert.assertFalse(groupWithInit.contains("test_group_A") || groupWithInit.contains("test_group_B") || groupWithInit.contains("test_group_C")); // update the groups MockUnixGroupsMapping.updateGroups(); rm.adminService .refreshUserToGroupsMappings(RefreshUserToGroupsMappingsRequest .newInstance()); List<String> groupAfter = Groups.getUserToGroupsMappingService(configuration).getGroups(user); // should get the updated groups Assert.assertTrue(groupAfter.contains("test_group_D") && groupAfter.contains("test_group_E") && groupAfter.contains("test_group_F") && groupAfter.size() == 3); }
@Test public void testQueuePlacementWithPolicy() throws Exception { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); scheduler.init(conf); scheduler.start(); scheduler.reinitialize(conf, resourceManager.getRMContext()); ApplicationAttemptId appId; List<QueuePlacementRule> rules = new ArrayList<QueuePlacementRule>(); rules.add(new QueuePlacementRule.Specified().initialize(true, null)); rules.add(new QueuePlacementRule.User().initialize(false, null)); rules.add(new QueuePlacementRule.PrimaryGroup().initialize(false, null)); rules.add(new QueuePlacementRule.SecondaryGroupExistingQueue().initialize(false, null)); rules.add(new QueuePlacementRule.Default().initialize(true, null)); Set<String> queues = Sets.newHashSet("root.user1", "root.user3group", "root.user4subgroup1", "root.user4subgroup2" , "root.user5subgroup2"); Map<FSQueueType, Set<String>> configuredQueues = new HashMap<FSQueueType, Set<String>>(); configuredQueues.put(FSQueueType.LEAF, queues); configuredQueues.put(FSQueueType.PARENT, new HashSet<String>()); scheduler.getAllocationConfiguration().placementPolicy = new QueuePlacementPolicy(rules, configuredQueues, conf); appId = createSchedulingRequest(1024, "somequeue", "user1"); assertEquals("root.somequeue", scheduler.getSchedulerApp(appId).getQueueName()); appId = createSchedulingRequest(1024, "default", "user1"); assertEquals("root.user1", scheduler.getSchedulerApp(appId).getQueueName()); appId = createSchedulingRequest(1024, "default", "user3"); assertEquals("root.user3group", scheduler.getSchedulerApp(appId).getQueueName()); appId = createSchedulingRequest(1024, "default", "user4"); assertEquals("root.user4subgroup1", scheduler.getSchedulerApp(appId).getQueueName()); appId = createSchedulingRequest(1024, "default", "user5"); assertEquals("root.user5subgroup2", scheduler.getSchedulerApp(appId).getQueueName()); appId = createSchedulingRequest(1024, "default", "otheruser"); assertEquals("root.default", scheduler.getSchedulerApp(appId).getQueueName()); // test without specified as first rule rules = new ArrayList<QueuePlacementRule>(); rules.add(new QueuePlacementRule.User().initialize(false, null)); rules.add(new QueuePlacementRule.Specified().initialize(true, null)); rules.add(new QueuePlacementRule.Default().initialize(true, null)); scheduler.getAllocationConfiguration().placementPolicy = new QueuePlacementPolicy(rules, configuredQueues, conf); appId = createSchedulingRequest(1024, "somequeue", "user1"); assertEquals("root.user1", scheduler.getSchedulerApp(appId).getQueueName()); appId = createSchedulingRequest(1024, "somequeue", "otheruser"); assertEquals("root.somequeue", scheduler.getSchedulerApp(appId).getQueueName()); appId = createSchedulingRequest(1024, "default", "otheruser"); assertEquals("root.default", scheduler.getSchedulerApp(appId).getQueueName()); }
@BeforeClass public static void setup() { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); }
@Before public void setup() { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); }
public void testPoolPlacementWithPolicy() throws Exception { Configuration placementPolicyConfig = new Configuration(); placementPolicyConfig.setClass("hadoop.security.group.mapping", SimpleGroupsMapping.class, GroupMappingServiceProvider.class); List<PoolPlacementRule> rules = new ArrayList<PoolPlacementRule>(); rules.add(new PoolPlacementRule.Specified().initialize(true, null)); rules.add(new PoolPlacementRule.User().initialize(false, null)); rules.add(new PoolPlacementRule.PrimaryGroup().initialize(false, null)); rules.add(new PoolPlacementRule.Default().initialize(true, null)); Set<String> pools = new HashSet(); pools.add("user1"); pools.add("user3group"); placementPolicyConfig.set("user.name", "user1"); PoolManager poolManager = scheduler.getPoolManager(); poolManager.placementPolicy = new PoolPlacementPolicy( rules, pools, placementPolicyConfig); JobInProgress job1 = submitJob(JobStatus.RUNNING, 2, 1); job1.getJobConf().set("user.name", "user1"); poolManager.setPool(job1, "somepool"); assertEquals("somepool", poolManager.getPoolName(job1)); poolManager.setPool(job1, "default"); assertEquals("user1", poolManager.getPoolName(job1)); job1.getJobConf().set("user.name", "user3"); poolManager.setPool(job1, "default"); assertEquals("user3group", poolManager.getPoolName(job1)); job1.getJobConf().set("user.name", "otheruser"); poolManager.setPool(job1, "default"); assertEquals("default", poolManager.getPoolName(job1)); // test without specified as first rule rules = new ArrayList<PoolPlacementRule>(); rules.add(new PoolPlacementRule.User().initialize(false, null)); rules.add(new PoolPlacementRule.Specified().initialize(true, null)); rules.add(new PoolPlacementRule.Default().initialize(true, null)); poolManager.placementPolicy = new PoolPlacementPolicy( rules, pools, conf); job1.getJobConf().set("user.name", "user1"); poolManager.setPool(job1, "somepool"); assertEquals("user1", poolManager.getPoolName(job1)); job1.getJobConf().set("user.name", "otheruser"); poolManager.setPool(job1, "somepool"); assertEquals("somepool", poolManager.getPoolName(job1)); poolManager.setPool(job1, "default"); assertEquals("default", poolManager.getPoolName(job1)); }
@BeforeClass public static void setup() { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); configuredPools.add("someuser"); }