@Test
 public void testRefreshUserToGroupsMappingsWithLocalConfigurationProvider() {
   rm = new MockRM(configuration);
   rm.init(configuration);
   rm.start();
   try {
     rm.adminService.refreshUserToGroupsMappings(RefreshUserToGroupsMappingsRequest.newInstance());
   } catch (Exception ex) {
     fail("Using localConfigurationProvider. Should not get any exception.");
   }
 }
Ejemplo n.º 2
0
 private void refreshAll() throws ServiceFailedException {
   try {
     refreshQueues(RefreshQueuesRequest.newInstance());
     refreshNodes(RefreshNodesRequest.newInstance());
     refreshSuperUserGroupsConfiguration(RefreshSuperUserGroupsConfigurationRequest.newInstance());
     refreshUserToGroupsMappings(RefreshUserToGroupsMappingsRequest.newInstance());
     if (getConfig()
         .getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) {
       refreshServiceAcls(RefreshServiceAclsRequest.newInstance());
     }
   } catch (YarnException ex) {
     throw new ServiceFailedException(ex.getMessage());
   } catch (IOException ex) {
     throw new ServiceFailedException(ex.getMessage());
   }
 }
  @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);
  }