Search in sources :

Example 1 with GetUserMappingsProtocol

use of org.apache.hadoop.tools.GetUserMappingsProtocol in project hadoop by apache.

the class HSAdmin method getGroups.

private int getGroups(String[] usernames) throws IOException {
    // Get groups users belongs to
    if (usernames.length == 0) {
        usernames = new String[] { UserGroupInformation.getCurrentUser().getUserName() };
    }
    // Get the current configuration
    Configuration conf = getConf();
    InetSocketAddress address = conf.getSocketAddr(JHAdminConfig.JHS_ADMIN_ADDRESS, JHAdminConfig.DEFAULT_JHS_ADMIN_ADDRESS, JHAdminConfig.DEFAULT_JHS_ADMIN_PORT);
    GetUserMappingsProtocol getUserMappingProtocol = HSProxies.createProxy(conf, address, GetUserMappingsProtocol.class, UserGroupInformation.getCurrentUser());
    for (String username : usernames) {
        StringBuilder sb = new StringBuilder();
        sb.append(username + " :");
        for (String group : getUserMappingProtocol.getGroupsForUser(username)) {
            sb.append(" ");
            sb.append(group);
        }
        System.out.println(sb);
    }
    return 0;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) GetUserMappingsProtocol(org.apache.hadoop.tools.GetUserMappingsProtocol) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 Configuration (org.apache.hadoop.conf.Configuration)1 GetUserMappingsProtocol (org.apache.hadoop.tools.GetUserMappingsProtocol)1