Search in sources :

Example 1 with DNSToSwitchMapping

use of org.apache.hadoop.net.DNSToSwitchMapping in project hadoop by apache.

the class ClientContext method initTopologyResolution.

private void initTopologyResolution(Configuration config) {
    topologyResolutionEnabled = config.getBoolean(FS_CLIENT_TOPOLOGY_RESOLUTION_ENABLED, FS_CLIENT_TOPOLOGY_RESOLUTION_ENABLED_DEFAULT);
    if (!topologyResolutionEnabled) {
        return;
    }
    DNSToSwitchMapping dnsToSwitchMapping = ReflectionUtils.newInstance(config.getClass(CommonConfigurationKeys.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY, ScriptBasedMapping.class, DNSToSwitchMapping.class), config);
    String clientHostName = NetUtils.getLocalHostname();
    List<String> nodes = new ArrayList<>();
    nodes.add(clientHostName);
    List<String> resolvedHosts = dnsToSwitchMapping.resolve(nodes);
    if (resolvedHosts != null && !resolvedHosts.isEmpty() && !resolvedHosts.get(0).equals(NetworkTopology.DEFAULT_RACK)) {
        // The client machine is able to resolve its own network location.
        this.clientNode = new NodeBase(clientHostName, resolvedHosts.get(0));
    }
}
Also used : NodeBase(org.apache.hadoop.net.NodeBase) ScriptBasedMapping(org.apache.hadoop.net.ScriptBasedMapping) ArrayList(java.util.ArrayList) DNSToSwitchMapping(org.apache.hadoop.net.DNSToSwitchMapping)

Example 2 with DNSToSwitchMapping

use of org.apache.hadoop.net.DNSToSwitchMapping in project hadoop by apache.

the class RackResolver method init.

public static synchronized void init(Configuration conf) {
    if (initCalled) {
        return;
    } else {
        initCalled = true;
    }
    Class<? extends DNSToSwitchMapping> dnsToSwitchMappingClass = conf.getClass(CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY, ScriptBasedMapping.class, DNSToSwitchMapping.class);
    try {
        DNSToSwitchMapping newInstance = ReflectionUtils.newInstance(dnsToSwitchMappingClass, conf);
        // Wrap around the configured class with the Cached implementation so as
        // to save on repetitive lookups.
        // Check if the impl is already caching, to avoid double caching.
        dnsToSwitchMapping = ((newInstance instanceof CachedDNSToSwitchMapping) ? newInstance : new CachedDNSToSwitchMapping(newInstance));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DNSToSwitchMapping(org.apache.hadoop.net.DNSToSwitchMapping) CachedDNSToSwitchMapping(org.apache.hadoop.net.CachedDNSToSwitchMapping) CachedDNSToSwitchMapping(org.apache.hadoop.net.CachedDNSToSwitchMapping)

Aggregations

DNSToSwitchMapping (org.apache.hadoop.net.DNSToSwitchMapping)2 ArrayList (java.util.ArrayList)1 CachedDNSToSwitchMapping (org.apache.hadoop.net.CachedDNSToSwitchMapping)1 NodeBase (org.apache.hadoop.net.NodeBase)1 ScriptBasedMapping (org.apache.hadoop.net.ScriptBasedMapping)1