|
@@ -31,6 +31,9 @@ import org.apache.hadoop.net.DNSToSwitchMapping;
|
|
import org.apache.hadoop.net.Node;
|
|
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 com.google.common.annotations.VisibleForTesting;
|
|
|
|
|
|
public class RackResolver {
|
|
public class RackResolver {
|
|
private static DNSToSwitchMapping dnsToSwitchMapping;
|
|
private static DNSToSwitchMapping dnsToSwitchMapping;
|
|
@@ -49,10 +52,8 @@ public class RackResolver {
|
|
ScriptBasedMapping.class,
|
|
ScriptBasedMapping.class,
|
|
DNSToSwitchMapping.class);
|
|
DNSToSwitchMapping.class);
|
|
try {
|
|
try {
|
|
- Constructor<? extends DNSToSwitchMapping> dnsToSwitchMappingConstructor
|
|
|
|
- = dnsToSwitchMappingClass.getConstructor();
|
|
|
|
- DNSToSwitchMapping newInstance =
|
|
|
|
- dnsToSwitchMappingConstructor.newInstance();
|
|
|
|
|
|
+ DNSToSwitchMapping newInstance = ReflectionUtils.newInstance(
|
|
|
|
+ dnsToSwitchMappingClass, conf);
|
|
// Wrap around the configured class with the Cached implementation so as
|
|
// Wrap around the configured class with the Cached implementation so as
|
|
// to save on repetitive lookups.
|
|
// to save on repetitive lookups.
|
|
// Check if the impl is already caching, to avoid double caching.
|
|
// Check if the impl is already caching, to avoid double caching.
|
|
@@ -99,4 +100,12 @@ public class RackResolver {
|
|
LOG.info("Resolved " + hostName + " to " + rName);
|
|
LOG.info("Resolved " + hostName + " to " + rName);
|
|
return new NodeBase(hostName, rName);
|
|
return new NodeBase(hostName, rName);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Only used by tests
|
|
|
|
+ */
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ static DNSToSwitchMapping getDnsToSwitchMapping(){
|
|
|
|
+ return dnsToSwitchMapping;
|
|
|
|
+ }
|
|
}
|
|
}
|