YARN-8169. Cleanup RackResolver.java
Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
parent
e4c39f3247
commit
351e509a47
@ -18,11 +18,9 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.yarn.util;
|
package org.apache.hadoop.yarn.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
@ -34,23 +32,30 @@ import org.apache.hadoop.net.Node;
|
|||||||
import org.apache.hadoop.net.NodeBase;
|
import org.apache.hadoop.net.NodeBase;
|
||||||
import org.apache.hadoop.net.ScriptBasedMapping;
|
import org.apache.hadoop.net.ScriptBasedMapping;
|
||||||
import org.apache.hadoop.util.ReflectionUtils;
|
import org.apache.hadoop.util.ReflectionUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
@InterfaceAudience.LimitedPrivate({"YARN", "MAPREDUCE"})
|
@InterfaceAudience.LimitedPrivate({"YARN", "MAPREDUCE"})
|
||||||
public class RackResolver {
|
public final class RackResolver {
|
||||||
private static DNSToSwitchMapping dnsToSwitchMapping;
|
private static DNSToSwitchMapping dnsToSwitchMapping;
|
||||||
private static boolean initCalled = false;
|
private static boolean initCalled = false;
|
||||||
private static final Log LOG = LogFactory.getLog(RackResolver.class);
|
private static final Logger LOG = LoggerFactory.getLogger(RackResolver.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide the default constructor for utility class.
|
||||||
|
*/
|
||||||
|
private RackResolver() {
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized static void init(Configuration conf) {
|
public synchronized static void init(Configuration conf) {
|
||||||
if (initCalled) {
|
if (initCalled) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
initCalled = true;
|
|
||||||
}
|
}
|
||||||
|
initCalled = true;
|
||||||
Class<? extends DNSToSwitchMapping> dnsToSwitchMappingClass =
|
Class<? extends DNSToSwitchMapping> dnsToSwitchMappingClass =
|
||||||
conf.getClass(
|
conf.getClass(
|
||||||
CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
|
CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
|
||||||
ScriptBasedMapping.class,
|
ScriptBasedMapping.class,
|
||||||
DNSToSwitchMapping.class);
|
DNSToSwitchMapping.class);
|
||||||
@ -96,31 +101,25 @@ public class RackResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Node coreResolve(String hostName) {
|
private static Node coreResolve(String hostName) {
|
||||||
List <String> tmpList = new ArrayList<String>(1);
|
List <String> tmpList = Collections.singletonList(hostName);
|
||||||
tmpList.add(hostName);
|
|
||||||
List <String> rNameList = dnsToSwitchMapping.resolve(tmpList);
|
List <String> rNameList = dnsToSwitchMapping.resolve(tmpList);
|
||||||
String rName = null;
|
String rName = NetworkTopology.DEFAULT_RACK;
|
||||||
if (rNameList == null || rNameList.get(0) == null) {
|
if (rNameList == null || rNameList.get(0) == null) {
|
||||||
rName = NetworkTopology.DEFAULT_RACK;
|
LOG.debug("Could not resolve {}. Falling back to {}", hostName,
|
||||||
if (LOG.isDebugEnabled()) {
|
NetworkTopology.DEFAULT_RACK);
|
||||||
LOG.debug("Couldn't resolve " + hostName + ". Falling back to "
|
|
||||||
+ NetworkTopology.DEFAULT_RACK);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rName = rNameList.get(0);
|
rName = rNameList.get(0);
|
||||||
if (LOG.isDebugEnabled()) {
|
LOG.debug("Resolved {} to {}", hostName, rName);
|
||||||
LOG.debug("Resolved " + hostName + " to " + rName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new NodeBase(hostName, rName);
|
return new NodeBase(hostName, rName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used by tests
|
* Only used by tests.
|
||||||
*/
|
*/
|
||||||
@Private
|
@Private
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static DNSToSwitchMapping getDnsToSwitchMapping(){
|
static DNSToSwitchMapping getDnsToSwitchMapping() {
|
||||||
return dnsToSwitchMapping;
|
return dnsToSwitchMapping;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user