Example usage for org.apache.hadoop.security SecurityUtil getByName

List of usage examples for org.apache.hadoop.security SecurityUtil getByName

Introduction

In this page you can find the example usage for org.apache.hadoop.security SecurityUtil getByName.

Prototype

@InterfaceAudience.Private
public static InetAddress getByName(String hostname) throws UnknownHostException 

Source Link

Document

Resolves a host subject to the security requirements determined by hadoop.security.token.service.use_ip.

Usage

From source file:org.apache.hama.util.BSPNetUtils.java

License:Apache License

/**
 * Create a socket address with the given host and port. The hostname might be
 * replaced with another host that was set via
 * {@link NetUtils#addStaticResolution(String, String)}. The value of
 * hadoop.security.token.service.use_ip will determine whether the standard
 * java host resolver is used, or if the fully qualified resolver is used.
 * /*from w ww  .  j a  va  2 s  . c  om*/
 * @param host the hostname or IP use to instantiate the object
 * @param port the port number
 * @return InetSocketAddress
 */
public static InetSocketAddress makeSocketAddr(String host, int port) {
    String staticHost = getStaticResolution(host);
    String resolveHost = (staticHost != null) ? staticHost : host;

    InetSocketAddress addr;
    try {
        InetAddress iaddr = SecurityUtil.getByName(resolveHost);
        // if there is a static entry for the host, make the returned
        // address look like the original given host
        if (staticHost != null) {
            iaddr = InetAddress.getByAddress(host, iaddr.getAddress());
        }
        addr = new InetSocketAddress(iaddr, port);
    } catch (UnknownHostException e) {
        addr = InetSocketAddress.createUnresolved(host, port);
    }
    return addr;
}