Example usage for org.apache.hadoop.net DNS reverseDns

List of usage examples for org.apache.hadoop.net DNS reverseDns

Introduction

In this page you can find the example usage for org.apache.hadoop.net DNS reverseDns.

Prototype

public static String reverseDns(InetAddress hostIp, @Nullable String ns) throws NamingException 

Source Link

Document

Returns the hostname associated with the specified IP address by the provided nameserver.

Usage

From source file:org.apache.kudu.mapreduce.KuduTableInputFormat.java

License:Apache License

/**
 * This method might seem alien, but we do this in order to resolve the hostnames the same way
 * Hadoop does. This ensures we get locality if Kudu is running along MR/YARN.
 * @param host hostname we got from the master
 * @param port port we got from the master
 * @return reverse DNS'd address//from   www . ja  va  2 s  .  co m
 */
private String reverseDNS(String host, Integer port) {
    String location = this.reverseDNSCacheMap.get(host);
    if (location != null) {
        return location;
    }
    // The below InetSocketAddress creation does a name resolution.
    InetSocketAddress isa = new InetSocketAddress(host, port);
    if (isa.isUnresolved()) {
        LOG.warn("Failed address resolve for: " + isa);
    }
    InetAddress tabletInetAddress = isa.getAddress();
    try {
        location = domainNamePointerToHostName(DNS.reverseDns(tabletInetAddress, this.nameServer));
        this.reverseDNSCacheMap.put(host, location);
    } catch (NamingException e) {
        LOG.warn("Cannot resolve the host name for " + tabletInetAddress + " because of " + e);
        location = host;
    }
    return location;
}

From source file:org.apache.phoenix.hive.util.PhoenixStorageHandlerUtil.java

License:Apache License

private static String reverseDNS(InetAddress ipAddress) throws NamingException, UnknownHostException {
    String hostName = reverseDNSCacheMap.get(ipAddress);

    if (hostName == null) {
        String ipAddressString = null;
        try {//www . j  av  a  2 s.c  o m
            ipAddressString = DNS.reverseDns(ipAddress, null);
        } catch (Exception e) {
            // We can use InetAddress in case the jndi failed to pull up the reverse DNS entry
            // from the name service. Also, in case of ipv6, we need to use the InetAddress
            // since resolving reverse DNS using jndi doesn't work well with ipv6 addresses.
            ipAddressString = InetAddress.getByName(ipAddress.getHostAddress()).getHostName();
        }

        if (ipAddressString == null) {
            throw new UnknownHostException("No host found for " + ipAddress);
        }

        hostName = Strings.domainNamePointerToHostName(ipAddressString);
        reverseDNSCacheMap.put(ipAddress, hostName);
    }

    return hostName;
}

From source file:org.cloudgraph.hbase.mapreduce.GraphInputFormat.java

License:Apache License

/**
 * Uses {@link InetAddress} in case of {@link DNS} lookup failure.
 * /*from   w  ww  .  java 2 s  . com*/
 * @param ipAddr
 *          the address
 * @return the reverse address
 * @throws NamingException
 * @throws UnknownHostException
 */
public String reverseDNS(InetAddress ipAddr) throws NamingException, UnknownHostException {
    String hostName = this.reverseDNSCache.get(ipAddr);
    if (hostName == null) {
        String ipAddressString = null;
        try {
            ipAddressString = DNS.reverseDns(ipAddr, null);
        } catch (Exception e) {
            ipAddressString = InetAddress.getByName(ipAddr.getHostAddress()).getHostName();
        }
        if (ipAddressString == null)
            throw new UnknownHostException("No host found for " + ipAddr);
        hostName = Strings.domainNamePointerToHostName(ipAddressString);
        this.reverseDNSCache.put(ipAddr, hostName);
    }
    return hostName;
}