private static String getMyAddress() { try { return DNS.getDefaultHost("default", "default"); } catch (UnknownHostException uhe) { LOG.error("cannot determine my address", uhe); return null; } }
/** * Wrapper around DNS.getDefaultHost(String, String), calling * DNS.getDefaultHost(String, String, boolean) when available. * * @param strInterface The network interface to query. * @param nameserver The DNS host name. * @return The default host names associated with IPs bound to the network interface. */ public static String getDefaultHost(String strInterface, String nameserver) throws UnknownHostException { if (HAS_NEW_DNS_GET_DEFAULT_HOST_API) { try { // Hadoop-2.8 includes a String, String, boolean variant of getDefaultHost // which properly handles multi-homed systems with Kerberos. return (String) GET_DEFAULT_HOST_METHOD.invoke(null, strInterface, nameserver, true); } catch (Exception e) { // If we can't invoke the method as it should exist, throw an exception throw new RuntimeException("Failed to invoke DNS.getDefaultHost via reflection", e); } } else { return org.apache.hadoop.net.DNS.getDefaultHost(strInterface, nameserver); } } }
/** * Returns the default (first) host name associated by the default * nameserver with the address bound to the specified network interface * * @param strInterface * The name of the network interface to query (e.g. eth0). * Must not be null. * @return The default host name associated with IPs bound to the network * interface * @throws UnknownHostException * If one is encountered while querying the default interface */ public static String getDefaultHost(@Nullable String strInterface) throws UnknownHostException { return getDefaultHost(strInterface, null, false); }
/** * Retrieve the name of the current host. Multihomed hosts may restrict the * hostname lookup to a specific interface and nameserver with {@link * org.apache.hadoop.fs.CommonConfigurationKeysPublic#HADOOP_SECURITY_DNS_INTERFACE_KEY} * and {@link org.apache.hadoop.fs.CommonConfigurationKeysPublic#HADOOP_SECURITY_DNS_NAMESERVER_KEY} * * @param conf Configuration object. May be null. * @return * @throws UnknownHostException */ static String getLocalHostName(@Nullable Configuration conf) throws UnknownHostException { if (conf != null) { String dnsInterface = conf.get(HADOOP_SECURITY_DNS_INTERFACE_KEY); String nameServer = conf.get(HADOOP_SECURITY_DNS_NAMESERVER_KEY); if (dnsInterface != null) { return DNS.getDefaultHost(dnsInterface, nameServer, true); } else if (nameServer != null) { throw new IllegalArgumentException(HADOOP_SECURITY_DNS_NAMESERVER_KEY + " requires " + HADOOP_SECURITY_DNS_INTERFACE_KEY + ". Check your" + "configuration."); } } // Fallback to querying the default hostname as we did before. return InetAddress.getLocalHost().getCanonicalHostName(); }
/** * Returns the default (first) host name associated by the provided * nameserver with the address bound to the specified network interface. * * @param strInterface * The name of the network interface to query (e.g. eth0) * @param nameserver * The DNS host name * @throws UnknownHostException * If one is encountered while querying the default interface */ public static String getDefaultHost(@Nullable String strInterface, @Nullable String nameserver) throws UnknownHostException { return getDefaultHost(strInterface, nameserver, false); }
} else { try { hostName = DNS.getDefaultHost( conf.getString("dfs.datanode.dns.interface", "default"), conf.getString("dfs.datanode.dns.nameserver", "default"));
Strings.domainNamePointerToHostName(DNS.getDefaultHost("default", "default")); int port = 0;
private static String getMyAddress() { try { return DNS.getDefaultHost("default", "default"); } catch (UnknownHostException uhe) { LOG.error("cannot determine my address", uhe); return null; } }
name = DNS.getDefaultHost(dnsInterface, nameServer, fallbackToHosts);
hostname = Strings.domainNamePointerToHostName(DNS.getDefaultHost( getConf().get(QueryServices.QUERY_SERVER_DNS_INTERFACE_ATTRIB, "default"), getConf().get(QueryServices.QUERY_SERVER_DNS_NAMESERVER_ATTRIB, "default")));
private static String getMyAddress() { try { return DNS.getDefaultHost("default", "default"); } catch (UnknownHostException uhe) { LOG.error("cannot determine my address", uhe); return null; } }
private InetAddress getLocalIPAddr() throws UnknownHostException { String hostname = DNS.getDefaultHost(DEFAULT); InetAddress localhost = InetAddress.getByName(hostname); return localhost; }
@Override public String get() { try { final String dnsInterface = hbaseConfig.get("hbase.regionserver.dns.interface", DEFAULT_DNS_INTERFACE); String hostname = Strings.domainNamePointerToHostName(DNS.getDefaultHost(dnsInterface)); return hostname; } catch( UnknownHostException ukhe) { throw new RuntimeException(ukhe); } } }
/** * Test that asking for the default hostname works * @throws Exception if hostname lookups fail */ public void testGetLocalHost() throws Exception { String hostname = DNS.getDefaultHost(DEFAULT); assertNotNull(hostname); }
private InetAddress getLocalIPAddr() throws UnknownHostException { String hostname = DNS.getDefaultHost(DEFAULT); InetAddress localhost = InetAddress.getByName(hostname); return localhost; }
/** * Get the local hostname on the given interface. * * @return The local hostname * @throws UnknownHostException */ public String getLocalHostname() throws UnknownHostException { return DNS.getDefaultHost( GiraphConstants.DNS_INTERFACE.get(this), GiraphConstants.DNS_NAMESERVER.get(this)).toLowerCase(); }
private InetAddress getLocalIPAddr() throws UnknownHostException { String hostname = DNS.getDefaultHost(DEFAULT); InetAddress localhost = InetAddress.getByName(hostname); return localhost; }
public static RpcProgramNfs3 createRpcProgramNfs3(NfsConfiguration config, DatagramSocket registrationSocket, boolean allowInsecurePorts) throws IOException { DefaultMetricsSystem.initialize("Nfs3"); String displayName = DNS.getDefaultHost("default", "default") + config.getInt(NfsConfigKeys.DFS_NFS_SERVER_PORT_KEY, NfsConfigKeys.DFS_NFS_SERVER_PORT_DEFAULT); metrics = Nfs3Metrics.create(config, displayName); return new RpcProgramNfs3(config, registrationSocket, allowInsecurePorts); }
/** * Test that asking for the default hostname works * @throws Exception if hostname lookups fail */ @Test public void testGetLocalHost() throws Exception { String hostname = DNS.getDefaultHost(DEFAULT); assertNotNull(hostname); }
/** * Test that asking for the default hostname works * @throws Exception if hostname lookups fail */ @Test public void testGetLocalHost() throws Exception { String hostname = DNS.getDefaultHost(DEFAULT); assertNotNull(hostname); }