org.apache.hadoop.tools.GetUserMappingsProtocol Java Examples

The following examples show how to use org.apache.hadoop.tools.GetUserMappingsProtocol. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NameNode.java    From big-c with Apache License 2.0 6 votes vote down vote up
public long getProtocolVersion(String protocol, 
                               long clientVersion) throws IOException {
  if (protocol.equals(ClientProtocol.class.getName())) {
    return ClientProtocol.versionID; 
  } else if (protocol.equals(DatanodeProtocol.class.getName())){
    return DatanodeProtocol.versionID;
  } else if (protocol.equals(NamenodeProtocol.class.getName())){
    return NamenodeProtocol.versionID;
  } else if (protocol.equals(RefreshAuthorizationPolicyProtocol.class.getName())){
    return RefreshAuthorizationPolicyProtocol.versionID;
  } else if (protocol.equals(RefreshUserMappingsProtocol.class.getName())){
    return RefreshUserMappingsProtocol.versionID;
  } else if (protocol.equals(RefreshCallQueueProtocol.class.getName())) {
    return RefreshCallQueueProtocol.versionID;
  } else if (protocol.equals(GetUserMappingsProtocol.class.getName())){
    return GetUserMappingsProtocol.versionID;
  } else if (protocol.equals(TraceAdminProtocol.class.getName())){
    return TraceAdminProtocol.versionID;
  } else {
    throw new IOException("Unknown protocol to name node: " + protocol);
  }
}
 
Example #2
Source File: HSProxies.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T createProxy(Configuration conf, InetSocketAddress hsaddr,
    Class<T> xface, UserGroupInformation ugi) throws IOException {

  T proxy;
  if (xface == RefreshUserMappingsProtocol.class) {
    proxy = (T) createHSProxyWithRefreshUserMappingsProtocol(hsaddr, conf,
        ugi);
  } else if (xface == GetUserMappingsProtocol.class) {
    proxy = (T) createHSProxyWithGetUserMappingsProtocol(hsaddr, conf, ugi);
  } else if (xface == HSAdminRefreshProtocol.class) {
    proxy = (T) createHSProxyWithHSAdminRefreshProtocol(hsaddr, conf, ugi);
  } else {
    String message = "Unsupported protocol found when creating the proxy "
        + "connection to History server: "
        + ((xface != null) ? xface.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }
  return proxy;
}
 
Example #3
Source File: NameNode.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public long getProtocolVersion(String protocol, 
                               long clientVersion) throws IOException {
  if (protocol.equals(ClientProtocol.class.getName())) {
    return ClientProtocol.versionID; 
  } else if (protocol.equals(DatanodeProtocol.class.getName())){
    return DatanodeProtocol.versionID;
  } else if (protocol.equals(NamenodeProtocol.class.getName())){
    return NamenodeProtocol.versionID;
  } else if (protocol.equals(RefreshAuthorizationPolicyProtocol.class.getName())){
    return RefreshAuthorizationPolicyProtocol.versionID;
  } else if (protocol.equals(RefreshUserMappingsProtocol.class.getName())){
    return RefreshUserMappingsProtocol.versionID;
  } else if (protocol.equals(RefreshCallQueueProtocol.class.getName())) {
    return RefreshCallQueueProtocol.versionID;
  } else if (protocol.equals(GetUserMappingsProtocol.class.getName())){
    return GetUserMappingsProtocol.versionID;
  } else if (protocol.equals(TraceAdminProtocol.class.getName())){
    return TraceAdminProtocol.versionID;
  } else {
    throw new IOException("Unknown protocol to name node: " + protocol);
  }
}
 
Example #4
Source File: HSProxies.java    From big-c with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T createProxy(Configuration conf, InetSocketAddress hsaddr,
    Class<T> xface, UserGroupInformation ugi) throws IOException {

  T proxy;
  if (xface == RefreshUserMappingsProtocol.class) {
    proxy = (T) createHSProxyWithRefreshUserMappingsProtocol(hsaddr, conf,
        ugi);
  } else if (xface == GetUserMappingsProtocol.class) {
    proxy = (T) createHSProxyWithGetUserMappingsProtocol(hsaddr, conf, ugi);
  } else if (xface == HSAdminRefreshProtocol.class) {
    proxy = (T) createHSProxyWithHSAdminRefreshProtocol(hsaddr, conf, ugi);
  } else {
    String message = "Unsupported protocol found when creating the proxy "
        + "connection to History server: "
        + ((xface != null) ? xface.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }
  return proxy;
}
 
Example #5
Source File: TestIsMethodSupported.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUserMappingsProtocol() throws IOException {
  GetUserMappingsProtocolClientSideTranslatorPB translator = 
      (GetUserMappingsProtocolClientSideTranslatorPB)
      NameNodeProxies.createNonHAProxy(conf, nnAddress,
          GetUserMappingsProtocol.class, UserGroupInformation.getCurrentUser(),
          true).getProxy();
  assertTrue(translator.isMethodSupported("getGroupsForUser"));
}
 
Example #6
Source File: NameNodeProxies.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static GetUserMappingsProtocol createNNProxyWithGetUserMappingsProtocol(
    InetSocketAddress address, Configuration conf, UserGroupInformation ugi)
    throws IOException {
  GetUserMappingsProtocolPB proxy = (GetUserMappingsProtocolPB)
      createNameNodeProxy(address, conf, ugi, GetUserMappingsProtocolPB.class);
  return new GetUserMappingsProtocolClientSideTranslatorPB(proxy);
}
 
Example #7
Source File: NameNodeProxies.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an explicitly non-HA-enabled proxy object. Most of the time you
 * don't want to use this, and should instead use {@link NameNodeProxies#createProxy}.
 *
 * @param conf the configuration object
 * @param nnAddr address of the remote NN to connect to
 * @param xface the IPC interface which should be created
 * @param ugi the user who is making the calls on the proxy object
 * @param withRetries certain interfaces have a non-standard retry policy
 * @param fallbackToSimpleAuth - set to true or false during this method to
 *   indicate if a secure client falls back to simple auth
 * @return an object containing both the proxy and the associated
 *         delegation token service it corresponds to
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static <T> ProxyAndInfo<T> createNonHAProxy(
    Configuration conf, InetSocketAddress nnAddr, Class<T> xface,
    UserGroupInformation ugi, boolean withRetries,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {
  Text dtService = SecurityUtil.buildTokenService(nnAddr);

  T proxy;
  if (xface == ClientProtocol.class) {
    proxy = (T) createNNProxyWithClientProtocol(nnAddr, conf, ugi,
        withRetries, fallbackToSimpleAuth);
  } else if (xface == JournalProtocol.class) {
    proxy = (T) createNNProxyWithJournalProtocol(nnAddr, conf, ugi);
  } else if (xface == NamenodeProtocol.class) {
    proxy = (T) createNNProxyWithNamenodeProtocol(nnAddr, conf, ugi,
        withRetries);
  } else if (xface == GetUserMappingsProtocol.class) {
    proxy = (T) createNNProxyWithGetUserMappingsProtocol(nnAddr, conf, ugi);
  } else if (xface == RefreshUserMappingsProtocol.class) {
    proxy = (T) createNNProxyWithRefreshUserMappingsProtocol(nnAddr, conf, ugi);
  } else if (xface == RefreshAuthorizationPolicyProtocol.class) {
    proxy = (T) createNNProxyWithRefreshAuthorizationPolicyProtocol(nnAddr,
        conf, ugi);
  } else if (xface == RefreshCallQueueProtocol.class) {
    proxy = (T) createNNProxyWithRefreshCallQueueProtocol(nnAddr, conf, ugi);
  } else {
    String message = "Unsupported protocol found when creating the proxy " +
        "connection to NameNode: " +
        ((xface != null) ? xface.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }

  return new ProxyAndInfo<T>(proxy, dtService, nnAddr);
}
 
Example #8
Source File: HSAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #9
Source File: HSProxies.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static GetUserMappingsProtocol createHSProxyWithGetUserMappingsProtocol(
    InetSocketAddress address, Configuration conf, UserGroupInformation ugi)
    throws IOException {
  GetUserMappingsProtocolPB proxy = (GetUserMappingsProtocolPB) createHSProxy(
      address, conf, ugi, GetUserMappingsProtocolPB.class, 0);
  return new GetUserMappingsProtocolClientSideTranslatorPB(proxy);
}
 
Example #10
Source File: GetGroupsForTesting.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected GetUserMappingsProtocol getUgmProtocol() throws IOException {
  Configuration conf = getConf();
  
  final InetSocketAddress addr = conf.getSocketAddr(
      YarnConfiguration.RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_PORT);
  final YarnRPC rpc = YarnRPC.create(conf);
  
  ResourceManagerAdministrationProtocol adminProtocol = (ResourceManagerAdministrationProtocol) rpc.getProxy(
      ResourceManagerAdministrationProtocol.class, addr, getConf());

  return adminProtocol;
}
 
Example #11
Source File: TestIsMethodSupported.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUserMappingsProtocol() throws IOException {
  GetUserMappingsProtocolClientSideTranslatorPB translator = 
      (GetUserMappingsProtocolClientSideTranslatorPB)
      NameNodeProxies.createNonHAProxy(conf, nnAddress,
          GetUserMappingsProtocol.class, UserGroupInformation.getCurrentUser(),
          true).getProxy();
  assertTrue(translator.isMethodSupported("getGroupsForUser"));
}
 
Example #12
Source File: ContextCommands.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    try {
        final HdfsConfiguration conf = new HdfsConfiguration();
        userMappingsProtocol = NameNodeProxies.createProxy(conf, FileSystem.getDefaultUri(conf),
                GetUserMappingsProtocol.class).getProxy();
    } catch (Exception e) {
        logger.error("Failed to create proxy to get user groups", e);
    }
}
 
Example #13
Source File: NameNodeProxies.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static GetUserMappingsProtocol createNNProxyWithGetUserMappingsProtocol(
    InetSocketAddress address, Configuration conf, UserGroupInformation ugi)
    throws IOException {
  GetUserMappingsProtocolPB proxy = (GetUserMappingsProtocolPB)
      createNameNodeProxy(address, conf, ugi, GetUserMappingsProtocolPB.class);
  return new GetUserMappingsProtocolClientSideTranslatorPB(proxy);
}
 
Example #14
Source File: NameNodeProxies.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an explicitly non-HA-enabled proxy object. Most of the time you
 * don't want to use this, and should instead use {@link NameNodeProxies#createProxy}.
 *
 * @param conf the configuration object
 * @param nnAddr address of the remote NN to connect to
 * @param xface the IPC interface which should be created
 * @param ugi the user who is making the calls on the proxy object
 * @param withRetries certain interfaces have a non-standard retry policy
 * @param fallbackToSimpleAuth - set to true or false during this method to
 *   indicate if a secure client falls back to simple auth
 * @return an object containing both the proxy and the associated
 *         delegation token service it corresponds to
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static <T> ProxyAndInfo<T> createNonHAProxy(
    Configuration conf, InetSocketAddress nnAddr, Class<T> xface,
    UserGroupInformation ugi, boolean withRetries,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {
  Text dtService = SecurityUtil.buildTokenService(nnAddr);

  T proxy;
  if (xface == ClientProtocol.class) {
    proxy = (T) createNNProxyWithClientProtocol(nnAddr, conf, ugi,
        withRetries, fallbackToSimpleAuth);
  } else if (xface == JournalProtocol.class) {
    proxy = (T) createNNProxyWithJournalProtocol(nnAddr, conf, ugi);
  } else if (xface == NamenodeProtocol.class) {
    proxy = (T) createNNProxyWithNamenodeProtocol(nnAddr, conf, ugi,
        withRetries);
  } else if (xface == GetUserMappingsProtocol.class) {
    proxy = (T) createNNProxyWithGetUserMappingsProtocol(nnAddr, conf, ugi);
  } else if (xface == RefreshUserMappingsProtocol.class) {
    proxy = (T) createNNProxyWithRefreshUserMappingsProtocol(nnAddr, conf, ugi);
  } else if (xface == RefreshAuthorizationPolicyProtocol.class) {
    proxy = (T) createNNProxyWithRefreshAuthorizationPolicyProtocol(nnAddr,
        conf, ugi);
  } else if (xface == RefreshCallQueueProtocol.class) {
    proxy = (T) createNNProxyWithRefreshCallQueueProtocol(nnAddr, conf, ugi);
  } else {
    String message = "Unsupported protocol found when creating the proxy " +
        "connection to NameNode: " +
        ((xface != null) ? xface.getClass().getName() : "null");
    LOG.error(message);
    throw new IllegalStateException(message);
  }

  return new ProxyAndInfo<T>(proxy, dtService, nnAddr);
}
 
Example #15
Source File: HSAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #16
Source File: HSProxies.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static GetUserMappingsProtocol createHSProxyWithGetUserMappingsProtocol(
    InetSocketAddress address, Configuration conf, UserGroupInformation ugi)
    throws IOException {
  GetUserMappingsProtocolPB proxy = (GetUserMappingsProtocolPB) createHSProxy(
      address, conf, ugi, GetUserMappingsProtocolPB.class, 0);
  return new GetUserMappingsProtocolClientSideTranslatorPB(proxy);
}
 
Example #17
Source File: GetGroupsForTesting.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected GetUserMappingsProtocol getUgmProtocol() throws IOException {
  Configuration conf = getConf();
  
  final InetSocketAddress addr = conf.getSocketAddr(
      YarnConfiguration.RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS,
      YarnConfiguration.DEFAULT_RM_ADMIN_PORT);
  final YarnRPC rpc = YarnRPC.create(conf);
  
  ResourceManagerAdministrationProtocol adminProtocol = (ResourceManagerAdministrationProtocol) rpc.getProxy(
      ResourceManagerAdministrationProtocol.class, addr, getConf());

  return adminProtocol;
}
 
Example #18
Source File: GetUserMappingsProtocolServerSideTranslatorPB.java    From big-c with Apache License 2.0 4 votes vote down vote up
public GetUserMappingsProtocolServerSideTranslatorPB(
    GetUserMappingsProtocol impl) {
  this.impl = impl;
}
 
Example #19
Source File: GetGroups.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
protected GetUserMappingsProtocol getUgmProtocol() throws IOException {
  return NameNodeProxies.createProxy(getConf(), FileSystem.getDefaultUri(getConf()),
      GetUserMappingsProtocol.class).getProxy();
}
 
Example #20
Source File: GetUserMappingsProtocolServerSideTranslatorPB.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public GetUserMappingsProtocolServerSideTranslatorPB(
    GetUserMappingsProtocol impl) {
  this.impl = impl;
}
 
Example #21
Source File: GetGroups.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
protected GetUserMappingsProtocol getUgmProtocol() throws IOException {
  return NameNodeProxies.createProxy(getConf(), FileSystem.getDefaultUri(getConf()),
      GetUserMappingsProtocol.class).getProxy();
}