|
24 | 24 | import org.apache.hadoop.hdfs.DFSUtil;
|
25 | 25 | import org.apache.hadoop.hdfs.server.common.JspHelper;
|
26 | 26 | import org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer;
|
| 27 | +import org.apache.hadoop.http.HttpConfig; |
27 | 28 | import org.apache.hadoop.http.HttpServer2;
|
| 29 | +import org.apache.hadoop.net.NetUtils; |
28 | 30 | import org.apache.hadoop.service.AbstractService;
|
29 | 31 |
|
30 | 32 | import javax.servlet.ServletContext;
|
31 | 33 |
|
| 34 | +import org.slf4j.Logger; |
| 35 | +import org.slf4j.LoggerFactory; |
| 36 | + |
32 | 37 | /**
|
33 | 38 | * Web interface for the {@link Router}. It exposes the Web UI and the WebHDFS
|
34 | 39 | * methods from {@link RouterWebHdfsMethods}.
|
35 | 40 | */
|
36 | 41 | public class RouterHttpServer extends AbstractService {
|
37 | 42 |
|
| 43 | + private static final Logger LOG = LoggerFactory.getLogger(RouterHttpServer.class); |
| 44 | + |
38 | 45 | protected static final String NAMENODE_ATTRIBUTE_KEY = "name.node";
|
39 | 46 |
|
40 | 47 |
|
@@ -82,6 +89,7 @@ protected void serviceInit(Configuration configuration) throws Exception {
|
82 | 89 | protected void serviceStart() throws Exception {
|
83 | 90 | // Build and start server
|
84 | 91 | String webApp = "router";
|
| 92 | + HttpConfig.Policy policy = DFSUtil.getHttpPolicy(conf); |
85 | 93 | HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(
|
86 | 94 | this.conf, this.httpAddress, this.httpsAddress, webApp,
|
87 | 95 | RBFConfigKeys.DFS_ROUTER_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
|
@@ -109,10 +117,26 @@ protected void serviceStart() throws Exception {
|
109 | 117 | this.httpServer.start();
|
110 | 118 |
|
111 | 119 | // The server port can be ephemeral... ensure we have the correct info
|
112 |
| - InetSocketAddress listenAddress = this.httpServer.getConnectorAddress(0); |
113 |
| - if (listenAddress != null) { |
114 |
| - this.httpAddress = new InetSocketAddress(this.httpAddress.getHostName(), |
115 |
| - listenAddress.getPort()); |
| 120 | + int curIndex = 0; |
| 121 | + if (policy.isHttpEnabled()) { |
| 122 | + InetSocketAddress httpListenAddress = this.httpServer.getConnectorAddress(curIndex++); |
| 123 | + if (httpListenAddress != null) { |
| 124 | + this.httpAddress = |
| 125 | + new InetSocketAddress(this.httpAddress.getHostName(), httpListenAddress.getPort()); |
| 126 | + conf.set(RBFConfigKeys.DFS_ROUTER_HTTP_ADDRESS_KEY, |
| 127 | + NetUtils.getHostPortString(httpAddress)); |
| 128 | + LOG.info("Listening HTTP traffic on {}", httpAddress); |
| 129 | + } |
| 130 | + } |
| 131 | + if (policy.isHttpsEnabled()) { |
| 132 | + InetSocketAddress httpsListenAddress = this.httpServer.getConnectorAddress(curIndex); |
| 133 | + if (httpsListenAddress != null) { |
| 134 | + this.httpsAddress = |
| 135 | + new InetSocketAddress(this.httpsAddress.getHostName(), httpsListenAddress.getPort()); |
| 136 | + conf.set(RBFConfigKeys.DFS_ROUTER_HTTPS_ADDRESS_KEY, |
| 137 | + NetUtils.getHostPortString(httpsAddress)); |
| 138 | + LOG.info("Listening HTTPS traffic on {}", httpsAddress); |
| 139 | + } |
116 | 140 | }
|
117 | 141 | super.serviceStart();
|
118 | 142 | }
|
|
0 commit comments