|
@@ -41,6 +41,7 @@ import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
|
|
import org.apache.hadoop.hdfs.tools.DFSHAAdmin;
|
|
import org.apache.hadoop.hdfs.tools.DFSHAAdmin;
|
|
import org.apache.hadoop.hdfs.tools.NNHAServiceTarget;
|
|
import org.apache.hadoop.hdfs.tools.NNHAServiceTarget;
|
|
import org.apache.hadoop.hdfs.web.URLConnectionFactory;
|
|
import org.apache.hadoop.hdfs.web.URLConnectionFactory;
|
|
|
|
+import org.apache.hadoop.net.NetUtils;
|
|
import org.codehaus.jettison.json.JSONArray;
|
|
import org.codehaus.jettison.json.JSONArray;
|
|
import org.codehaus.jettison.json.JSONException;
|
|
import org.codehaus.jettison.json.JSONException;
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
@@ -94,6 +95,9 @@ public class NamenodeHeartbeatService extends PeriodicService {
|
|
private URLConnectionFactory connectionFactory;
|
|
private URLConnectionFactory connectionFactory;
|
|
/** URL scheme to use for JMX calls. */
|
|
/** URL scheme to use for JMX calls. */
|
|
private String scheme;
|
|
private String scheme;
|
|
|
|
+
|
|
|
|
+ private String resolvedHost;
|
|
|
|
+ private String originalNnId;
|
|
/**
|
|
/**
|
|
* Create a new Namenode status updater.
|
|
* Create a new Namenode status updater.
|
|
* @param resolver Namenode resolver service to handle NN registration.
|
|
* @param resolver Namenode resolver service to handle NN registration.
|
|
@@ -110,6 +114,28 @@ public class NamenodeHeartbeatService extends PeriodicService {
|
|
|
|
|
|
this.nameserviceId = nsId;
|
|
this.nameserviceId = nsId;
|
|
this.namenodeId = nnId;
|
|
this.namenodeId = nnId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Create a new Namenode status updater.
|
|
|
|
+ *
|
|
|
|
+ * @param resolver Namenode resolver service to handle NN registration.
|
|
|
|
+ * @param nsId Identifier of the nameservice.
|
|
|
|
+ * @param nnId Identifier of the namenode in HA.
|
|
|
|
+ * @param resolvedHost resolvedHostname for this specific namenode.
|
|
|
|
+ */
|
|
|
|
+ public NamenodeHeartbeatService(
|
|
|
|
+ ActiveNamenodeResolver resolver, String nsId, String nnId, String resolvedHost) {
|
|
|
|
+ super(getNnHeartBeatServiceName(nsId, nnId));
|
|
|
|
+
|
|
|
|
+ this.resolver = resolver;
|
|
|
|
+
|
|
|
|
+ this.nameserviceId = nsId;
|
|
|
|
+ // Concat a uniq id from original nnId and resolvedHost
|
|
|
|
+ this.namenodeId = nnId + "-" + resolvedHost;
|
|
|
|
+ this.resolvedHost = resolvedHost;
|
|
|
|
+ // Same the original nnid to get the ports from config.
|
|
|
|
+ this.originalNnId = nnId;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -120,40 +146,59 @@ public class NamenodeHeartbeatService extends PeriodicService {
|
|
|
|
|
|
String nnDesc = nameserviceId;
|
|
String nnDesc = nameserviceId;
|
|
if (this.namenodeId != null && !this.namenodeId.isEmpty()) {
|
|
if (this.namenodeId != null && !this.namenodeId.isEmpty()) {
|
|
- this.localTarget = new NNHAServiceTarget(
|
|
|
|
- conf, nameserviceId, namenodeId);
|
|
|
|
nnDesc += "-" + namenodeId;
|
|
nnDesc += "-" + namenodeId;
|
|
} else {
|
|
} else {
|
|
this.localTarget = null;
|
|
this.localTarget = null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (originalNnId == null) {
|
|
|
|
+ originalNnId = namenodeId;
|
|
|
|
+ }
|
|
// Get the RPC address for the clients to connect
|
|
// Get the RPC address for the clients to connect
|
|
- this.rpcAddress = getRpcAddress(conf, nameserviceId, namenodeId);
|
|
|
|
- LOG.info("{} RPC address: {}", nnDesc, rpcAddress);
|
|
|
|
|
|
+ this.rpcAddress = getRpcAddress(conf, nameserviceId, originalNnId);
|
|
|
|
|
|
// Get the Service RPC address for monitoring
|
|
// Get the Service RPC address for monitoring
|
|
this.serviceAddress =
|
|
this.serviceAddress =
|
|
- DFSUtil.getNamenodeServiceAddr(conf, nameserviceId, namenodeId);
|
|
|
|
|
|
+ DFSUtil.getNamenodeServiceAddr(conf, nameserviceId, originalNnId);
|
|
if (this.serviceAddress == null) {
|
|
if (this.serviceAddress == null) {
|
|
LOG.error("Cannot locate RPC service address for NN {}, " +
|
|
LOG.error("Cannot locate RPC service address for NN {}, " +
|
|
"using RPC address {}", nnDesc, this.rpcAddress);
|
|
"using RPC address {}", nnDesc, this.rpcAddress);
|
|
this.serviceAddress = this.rpcAddress;
|
|
this.serviceAddress = this.rpcAddress;
|
|
}
|
|
}
|
|
- LOG.info("{} Service RPC address: {}", nnDesc, serviceAddress);
|
|
|
|
|
|
|
|
// Get the Lifeline RPC address for faster monitoring
|
|
// Get the Lifeline RPC address for faster monitoring
|
|
this.lifelineAddress =
|
|
this.lifelineAddress =
|
|
- DFSUtil.getNamenodeLifelineAddr(conf, nameserviceId, namenodeId);
|
|
|
|
|
|
+ DFSUtil.getNamenodeLifelineAddr(conf, nameserviceId, originalNnId);
|
|
if (this.lifelineAddress == null) {
|
|
if (this.lifelineAddress == null) {
|
|
this.lifelineAddress = this.serviceAddress;
|
|
this.lifelineAddress = this.serviceAddress;
|
|
}
|
|
}
|
|
- LOG.info("{} Lifeline RPC address: {}", nnDesc, lifelineAddress);
|
|
|
|
|
|
|
|
// Get the Web address for UI
|
|
// Get the Web address for UI
|
|
this.webAddress =
|
|
this.webAddress =
|
|
- DFSUtil.getNamenodeWebAddr(conf, nameserviceId, namenodeId);
|
|
|
|
|
|
+ DFSUtil.getNamenodeWebAddr(conf, nameserviceId, originalNnId);
|
|
|
|
+
|
|
|
|
+ if (resolvedHost != null) {
|
|
|
|
+ // Get the addresses from resolvedHost plus the configured ports.
|
|
|
|
+ rpcAddress = resolvedHost + ":"
|
|
|
|
+ + NetUtils.getPortFromHostPortString(rpcAddress);
|
|
|
|
+ serviceAddress = resolvedHost + ":"
|
|
|
|
+ + NetUtils.getPortFromHostPortString(serviceAddress);
|
|
|
|
+ lifelineAddress = resolvedHost + ":"
|
|
|
|
+ + NetUtils.getPortFromHostPortString(lifelineAddress);
|
|
|
|
+ webAddress = resolvedHost + ":"
|
|
|
|
+ + NetUtils.getPortFromHostPortString(webAddress);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LOG.info("{} RPC address: {}", nnDesc, rpcAddress);
|
|
|
|
+ LOG.info("{} Service RPC address: {}", nnDesc, serviceAddress);
|
|
|
|
+ LOG.info("{} Lifeline RPC address: {}", nnDesc, lifelineAddress);
|
|
LOG.info("{} Web address: {}", nnDesc, webAddress);
|
|
LOG.info("{} Web address: {}", nnDesc, webAddress);
|
|
|
|
|
|
|
|
+ if (this.namenodeId != null && !this.namenodeId.isEmpty()) {
|
|
|
|
+ this.localTarget = new NNHAServiceTarget(
|
|
|
|
+ conf, nameserviceId, namenodeId, serviceAddress, lifelineAddress);
|
|
|
|
+ }
|
|
|
|
+
|
|
this.connectionFactory =
|
|
this.connectionFactory =
|
|
URLConnectionFactory.newDefaultURLConnectionFactory(conf);
|
|
URLConnectionFactory.newDefaultURLConnectionFactory(conf);
|
|
|
|
|
|
@@ -336,6 +381,12 @@ public class NamenodeHeartbeatService extends PeriodicService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static String getNnHeartBeatServiceName(String nsId, String nnId) {
|
|
|
|
+ return NamenodeHeartbeatService.class.getSimpleName() +
|
|
|
|
+ (nsId == null ? "" : " " + nsId) +
|
|
|
|
+ (nnId == null ? "" : " " + nnId);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Get the parameters for a Namenode from JMX and add them to the report.
|
|
* Get the parameters for a Namenode from JMX and add them to the report.
|
|
* @param address Web interface of the Namenode to monitor.
|
|
* @param address Web interface of the Namenode to monitor.
|