|
@@ -17,19 +17,12 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
|
|
|
|
-import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_ADMIN;
|
|
|
|
-import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_METRICS_SESSION_ID_KEY;
|
|
|
|
-import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_DEFAULT;
|
|
|
|
-import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY;
|
|
|
|
-import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY;
|
|
|
|
-import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_SECONDARY_NAMENODE_USER_NAME_KEY;
|
|
|
|
import static org.apache.hadoop.util.ExitUtil.terminate;
|
|
import static org.apache.hadoop.util.ExitUtil.terminate;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FilenameFilter;
|
|
import java.io.FilenameFilter;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
-import java.net.MalformedURLException;
|
|
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.security.PrivilegedAction;
|
|
import java.security.PrivilegedAction;
|
|
@@ -71,6 +64,7 @@ import org.apache.hadoop.hdfs.server.namenode.NNStorageRetentionManager.StorageP
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
|
|
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLog;
|
|
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLog;
|
|
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest;
|
|
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest;
|
|
|
|
+import org.apache.hadoop.http.HttpConfig;
|
|
import org.apache.hadoop.http.HttpServer;
|
|
import org.apache.hadoop.http.HttpServer;
|
|
import org.apache.hadoop.io.MD5Hash;
|
|
import org.apache.hadoop.io.MD5Hash;
|
|
import org.apache.hadoop.ipc.RemoteException;
|
|
import org.apache.hadoop.ipc.RemoteException;
|
|
@@ -79,7 +73,6 @@ import org.apache.hadoop.metrics2.source.JvmMetrics;
|
|
import org.apache.hadoop.net.NetUtils;
|
|
import org.apache.hadoop.net.NetUtils;
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
-import org.apache.hadoop.security.authorize.AccessControlList;
|
|
|
|
import org.apache.hadoop.util.Daemon;
|
|
import org.apache.hadoop.util.Daemon;
|
|
import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.util.Time;
|
|
import org.apache.hadoop.util.Time;
|
|
@@ -121,8 +114,7 @@ public class SecondaryNameNode implements Runnable {
|
|
private InetSocketAddress nameNodeAddr;
|
|
private InetSocketAddress nameNodeAddr;
|
|
private volatile boolean shouldRun;
|
|
private volatile boolean shouldRun;
|
|
private HttpServer infoServer;
|
|
private HttpServer infoServer;
|
|
- private int infoPort;
|
|
|
|
- private String infoBindAddress;
|
|
|
|
|
|
+ private URL imageListenURL;
|
|
|
|
|
|
private Collection<URI> checkpointDirs;
|
|
private Collection<URI> checkpointDirs;
|
|
private List<URI> checkpointEditsDirs;
|
|
private List<URI> checkpointEditsDirs;
|
|
@@ -210,8 +202,8 @@ public class SecondaryNameNode implements Runnable {
|
|
|
|
|
|
public static InetSocketAddress getHttpAddress(Configuration conf) {
|
|
public static InetSocketAddress getHttpAddress(Configuration conf) {
|
|
return NetUtils.createSocketAddr(conf.get(
|
|
return NetUtils.createSocketAddr(conf.get(
|
|
- DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY,
|
|
|
|
- DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_DEFAULT));
|
|
|
|
|
|
+ DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY,
|
|
|
|
+ DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_DEFAULT));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -221,17 +213,19 @@ public class SecondaryNameNode implements Runnable {
|
|
private void initialize(final Configuration conf,
|
|
private void initialize(final Configuration conf,
|
|
CommandLineOpts commandLineOpts) throws IOException {
|
|
CommandLineOpts commandLineOpts) throws IOException {
|
|
final InetSocketAddress infoSocAddr = getHttpAddress(conf);
|
|
final InetSocketAddress infoSocAddr = getHttpAddress(conf);
|
|
- infoBindAddress = infoSocAddr.getHostName();
|
|
|
|
|
|
+ final String infoBindAddress = infoSocAddr.getHostName();
|
|
UserGroupInformation.setConfiguration(conf);
|
|
UserGroupInformation.setConfiguration(conf);
|
|
if (UserGroupInformation.isSecurityEnabled()) {
|
|
if (UserGroupInformation.isSecurityEnabled()) {
|
|
- SecurityUtil.login(conf, DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY,
|
|
|
|
- DFS_SECONDARY_NAMENODE_USER_NAME_KEY, infoBindAddress);
|
|
|
|
|
|
+ SecurityUtil.login(conf,
|
|
|
|
+ DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY,
|
|
|
|
+ DFSConfigKeys.DFS_SECONDARY_NAMENODE_USER_NAME_KEY, infoBindAddress);
|
|
}
|
|
}
|
|
// initiate Java VM metrics
|
|
// initiate Java VM metrics
|
|
DefaultMetricsSystem.initialize("SecondaryNameNode");
|
|
DefaultMetricsSystem.initialize("SecondaryNameNode");
|
|
JvmMetrics.create("SecondaryNameNode",
|
|
JvmMetrics.create("SecondaryNameNode",
|
|
- conf.get(DFS_METRICS_SESSION_ID_KEY), DefaultMetricsSystem.instance());
|
|
|
|
-
|
|
|
|
|
|
+ conf.get(DFSConfigKeys.DFS_METRICS_SESSION_ID_KEY),
|
|
|
|
+ DefaultMetricsSystem.instance());
|
|
|
|
+
|
|
// Create connection to the namenode.
|
|
// Create connection to the namenode.
|
|
shouldRun = true;
|
|
shouldRun = true;
|
|
nameNodeAddr = NameNode.getServiceAddress(conf, true);
|
|
nameNodeAddr = NameNode.getServiceAddress(conf, true);
|
|
@@ -256,19 +250,19 @@ public class SecondaryNameNode implements Runnable {
|
|
// Initialize other scheduling parameters from the configuration
|
|
// Initialize other scheduling parameters from the configuration
|
|
checkpointConf = new CheckpointConf(conf);
|
|
checkpointConf = new CheckpointConf(conf);
|
|
|
|
|
|
- // initialize the webserver for uploading files.
|
|
|
|
- int tmpInfoPort = infoSocAddr.getPort();
|
|
|
|
- URI httpEndpoint = URI.create("http://" + NetUtils.getHostPortString(infoSocAddr));
|
|
|
|
|
|
+ final InetSocketAddress httpAddr = infoSocAddr;
|
|
|
|
+
|
|
|
|
+ final String httpsAddrString = conf.get(
|
|
|
|
+ DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTPS_ADDRESS_KEY,
|
|
|
|
+ DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTPS_ADDRESS_DEFAULT);
|
|
|
|
+ InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);
|
|
|
|
|
|
- infoServer = new HttpServer.Builder().setName("secondary")
|
|
|
|
- .addEndpoint(httpEndpoint)
|
|
|
|
- .setFindPort(tmpInfoPort == 0).setConf(conf).setACL(
|
|
|
|
- new AccessControlList(conf.get(DFS_ADMIN, " ")))
|
|
|
|
- .setSecurityEnabled(UserGroupInformation.isSecurityEnabled())
|
|
|
|
- .setUsernameConfKey(
|
|
|
|
- DFSConfigKeys.DFS_SECONDARY_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY)
|
|
|
|
- .setKeytabConfKey(DFSUtil.getSpnegoKeytabKey(conf,
|
|
|
|
- DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY)).build();
|
|
|
|
|
|
+ HttpServer.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
|
|
|
|
+ httpAddr, httpsAddr, "secondary",
|
|
|
|
+ DFSConfigKeys.DFS_SECONDARY_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY,
|
|
|
|
+ DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY);
|
|
|
|
+
|
|
|
|
+ infoServer = builder.build();
|
|
|
|
|
|
infoServer.setAttribute("secondary.name.node", this);
|
|
infoServer.setAttribute("secondary.name.node", this);
|
|
infoServer.setAttribute("name.system.image", checkpointImage);
|
|
infoServer.setAttribute("name.system.image", checkpointImage);
|
|
@@ -278,14 +272,25 @@ public class SecondaryNameNode implements Runnable {
|
|
infoServer.start();
|
|
infoServer.start();
|
|
|
|
|
|
LOG.info("Web server init done");
|
|
LOG.info("Web server init done");
|
|
|
|
+ imageListenURL = new URL(DFSUtil.getHttpClientScheme(conf) + "://"
|
|
|
|
+ + NetUtils.getHostPortString(infoServer.getConnectorAddress(0)));
|
|
|
|
|
|
- // The web-server port can be ephemeral... ensure we have the correct info
|
|
|
|
- infoPort = infoServer.getConnectorAddress(0).getPort();
|
|
|
|
|
|
+ HttpConfig.Policy policy = DFSUtil.getHttpPolicy(conf);
|
|
|
|
+ int connIdx = 0;
|
|
|
|
+ if (policy.isHttpEnabled()) {
|
|
|
|
+ InetSocketAddress httpAddress = infoServer.getConnectorAddress(connIdx++);
|
|
|
|
+ conf.set(DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY,
|
|
|
|
+ NetUtils.getHostPortString(httpAddress));
|
|
|
|
+ }
|
|
|
|
|
|
- conf.set(DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY, infoBindAddress + ":" + infoPort);
|
|
|
|
- LOG.info("Secondary Web-server up at: " + infoBindAddress + ":" + infoPort);
|
|
|
|
- LOG.info("Checkpoint Period :" + checkpointConf.getPeriod() + " secs " +
|
|
|
|
- "(" + checkpointConf.getPeriod() / 60 + " min)");
|
|
|
|
|
|
+ if (policy.isHttpsEnabled()) {
|
|
|
|
+ InetSocketAddress httpsAddress = infoServer.getConnectorAddress(connIdx);
|
|
|
|
+ conf.set(DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTPS_ADDRESS_KEY,
|
|
|
|
+ NetUtils.getHostPortString(httpsAddress));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LOG.info("Checkpoint Period :" + checkpointConf.getPeriod() + " secs "
|
|
|
|
+ + "(" + checkpointConf.getPeriod() / 60 + " min)");
|
|
LOG.info("Log Size Trigger :" + checkpointConf.getTxnCount() + " txns");
|
|
LOG.info("Log Size Trigger :" + checkpointConf.getTxnCount() + " txns");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -487,15 +492,7 @@ public class SecondaryNameNode implements Runnable {
|
|
* for image transfers
|
|
* for image transfers
|
|
*/
|
|
*/
|
|
private URL getImageListenAddress() {
|
|
private URL getImageListenAddress() {
|
|
- StringBuilder sb = new StringBuilder()
|
|
|
|
- .append(DFSUtil.getHttpClientScheme(conf)).append("://")
|
|
|
|
- .append(infoBindAddress).append(":").append(infoPort);
|
|
|
|
- try {
|
|
|
|
- return new URL(sb.toString());
|
|
|
|
- } catch (MalformedURLException e) {
|
|
|
|
- // Unreachable
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
- }
|
|
|
|
|
|
+ return imageListenURL;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|