You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by aa...@apache.org on 2018/04/19 07:43:39 UTC
hadoop git commit: YARN-8169. Cleanup RackResolver.java
Repository: hadoop
Updated Branches:
refs/heads/trunk e4c39f324 -> 351e509a4
YARN-8169. Cleanup RackResolver.java
Signed-off-by: Akira Ajisaka <aa...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/351e509a
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/351e509a
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/351e509a
Branch: refs/heads/trunk
Commit: 351e509a47ad5f6a1601e2345d890796ecde0e62
Parents: e4c39f3
Author: BELUGA BEHR <da...@gmail.com>
Authored: Thu Apr 19 16:07:14 2018 +0900
Committer: Akira Ajisaka <aa...@apache.org>
Committed: Thu Apr 19 16:07:14 2018 +0900
----------------------------------------------------------------------
.../apache/hadoop/yarn/util/RackResolver.java | 49 ++++++++++----------
1 file changed, 24 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/351e509a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
index c44c2cf..a854701 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java
@@ -18,11 +18,9 @@
package org.apache.hadoop.yarn.util;
-import java.util.ArrayList;
+import java.util.Collections;
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.Private;
import org.apache.hadoop.conf.Configuration;
@@ -34,24 +32,31 @@ import org.apache.hadoop.net.Node;
import org.apache.hadoop.net.NodeBase;
import org.apache.hadoop.net.ScriptBasedMapping;
import org.apache.hadoop.util.ReflectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
@InterfaceAudience.LimitedPrivate({"YARN", "MAPREDUCE"})
-public class RackResolver {
+public final class RackResolver {
private static DNSToSwitchMapping dnsToSwitchMapping;
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) {
if (initCalled) {
return;
- } else {
- initCalled = true;
}
+ initCalled = true;
Class<? extends DNSToSwitchMapping> dnsToSwitchMappingClass =
- conf.getClass(
- CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
+ conf.getClass(
+ CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
ScriptBasedMapping.class,
DNSToSwitchMapping.class);
try {
@@ -67,10 +72,10 @@ public class RackResolver {
throw new RuntimeException(e);
}
}
-
+
/**
* Utility method for getting a hostname resolved to a node in the
- * network topology. This method initializes the class with the
+ * network topology. This method initializes the class with the
* right resolver implementation.
* @param conf
* @param hostName
@@ -94,33 +99,27 @@ public class RackResolver {
}
return coreResolve(hostName);
}
-
+
private static Node coreResolve(String hostName) {
- List <String> tmpList = new ArrayList<String>(1);
- tmpList.add(hostName);
+ List <String> tmpList = Collections.singletonList(hostName);
List <String> rNameList = dnsToSwitchMapping.resolve(tmpList);
- String rName = null;
+ String rName = NetworkTopology.DEFAULT_RACK;
if (rNameList == null || rNameList.get(0) == null) {
- rName = NetworkTopology.DEFAULT_RACK;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Couldn't resolve " + hostName + ". Falling back to "
- + NetworkTopology.DEFAULT_RACK);
- }
+ LOG.debug("Could not resolve {}. Falling back to {}", hostName,
+ NetworkTopology.DEFAULT_RACK);
} else {
rName = rNameList.get(0);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Resolved " + hostName + " to " + rName);
- }
+ LOG.debug("Resolved {} to {}", hostName, rName);
}
return new NodeBase(hostName, rName);
}
/**
- * Only used by tests
+ * Only used by tests.
*/
@Private
@VisibleForTesting
- static DNSToSwitchMapping getDnsToSwitchMapping(){
+ static DNSToSwitchMapping getDnsToSwitchMapping() {
return dnsToSwitchMapping;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org