forked from apache/hadoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDFS-17657. The balancer service supports httpserver. (apache#7242) C…
…ontribtued by Zhaobo Huang. Reviewed-by: Tao Li <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
- Loading branch information
1 parent
0d72896
commit 0432761
Showing
19 changed files
with
702 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
.../hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerHttpServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hdfs.server.balancer; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hdfs.DFSConfigKeys; | ||
import org.apache.hadoop.hdfs.DFSUtil; | ||
import org.apache.hadoop.hdfs.server.common.JspHelper; | ||
import org.apache.hadoop.http.HttpConfig; | ||
import org.apache.hadoop.http.HttpServer2; | ||
import org.apache.hadoop.net.NetUtils; | ||
|
||
public class BalancerHttpServer { | ||
|
||
private static final String BALANCER_ATTRIBUTE_KEY = "current.balancer"; | ||
|
||
private final Configuration conf; | ||
private InetSocketAddress httpAddress; | ||
private InetSocketAddress httpsAddress; | ||
private HttpServer2 httpServer; | ||
|
||
public BalancerHttpServer(Configuration conf) { | ||
this.conf = conf; | ||
} | ||
|
||
public void start() throws IOException { | ||
String webApp = "balancer"; | ||
// Get HTTP address | ||
httpAddress = conf.getSocketAddr(DFSConfigKeys.DFS_BALANCER_HTTP_BIND_HOST_KEY, | ||
DFSConfigKeys.DFS_BALANCER_HTTP_ADDRESS_KEY, | ||
DFSConfigKeys.DFS_BALANCER_HTTP_ADDRESS_DEFAULT, | ||
DFSConfigKeys.DFS_BALANCER_HTTP_PORT_DEFAULT); | ||
|
||
// Get HTTPs address | ||
httpsAddress = conf.getSocketAddr(DFSConfigKeys.DFS_BALANCER_HTTPS_BIND_HOST_KEY, | ||
DFSConfigKeys.DFS_BALANCER_HTTPS_ADDRESS_KEY, | ||
DFSConfigKeys.DFS_BALANCER_HTTPS_ADDRESS_DEFAULT, | ||
DFSConfigKeys.DFS_BALANCER_HTTPS_PORT_DEFAULT); | ||
|
||
HttpServer2.Builder builder = | ||
DFSUtil.getHttpServerTemplate(conf, httpAddress, httpsAddress, webApp, | ||
DFSConfigKeys.DFS_BALANCER_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY, | ||
DFSConfigKeys.DFS_BALANCER_KEYTAB_FILE_KEY); | ||
|
||
final boolean xFrameEnabled = conf.getBoolean(DFSConfigKeys.DFS_XFRAME_OPTION_ENABLED, | ||
DFSConfigKeys.DFS_XFRAME_OPTION_ENABLED_DEFAULT); | ||
|
||
final String xFrameOptionValue = conf.getTrimmed(DFSConfigKeys.DFS_XFRAME_OPTION_VALUE, | ||
DFSConfigKeys.DFS_XFRAME_OPTION_VALUE_DEFAULT); | ||
|
||
builder.configureXFrame(xFrameEnabled).setXFrameOption(xFrameOptionValue); | ||
|
||
httpServer = builder.build(); | ||
httpServer.setAttribute(JspHelper.CURRENT_CONF, conf); | ||
httpServer.start(); | ||
|
||
HttpConfig.Policy policy = DFSUtil.getHttpPolicy(conf); | ||
int connIdx = 0; | ||
if (policy.isHttpEnabled()) { | ||
httpAddress = httpServer.getConnectorAddress(connIdx++); | ||
if (httpAddress != null) { | ||
conf.set(DFSConfigKeys.DFS_BALANCER_HTTP_ADDRESS_KEY, | ||
NetUtils.getHostPortString(httpAddress)); | ||
} | ||
} | ||
if (policy.isHttpsEnabled()) { | ||
httpsAddress = httpServer.getConnectorAddress(connIdx); | ||
if (httpsAddress != null) { | ||
conf.set(DFSConfigKeys.DFS_BALANCER_HTTPS_ADDRESS_KEY, | ||
NetUtils.getHostPortString(httpsAddress)); | ||
} | ||
} | ||
} | ||
|
||
public void setBalancerAttribute(Balancer balancer) { | ||
httpServer.setAttribute(BALANCER_ATTRIBUTE_KEY, balancer); | ||
} | ||
|
||
public void stop() throws IOException { | ||
if (httpServer != null) { | ||
try { | ||
httpServer.stop(); | ||
} catch (Exception e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} | ||
|
||
public InetSocketAddress getHttpAddress() { | ||
return httpAddress; | ||
} | ||
|
||
public InetSocketAddress getHttpsAddress() { | ||
return httpsAddress; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ject/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerMXBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hdfs.server.balancer; | ||
|
||
public interface BalancerMXBean { | ||
|
||
/** | ||
* Gets the version of Hadoop. | ||
* | ||
* @return the version of Hadoop | ||
*/ | ||
String getVersion(); | ||
|
||
/** | ||
* Get the version of software running on the Balancer. | ||
* | ||
* @return a string representing the version. | ||
*/ | ||
String getSoftwareVersion(); | ||
|
||
/** | ||
* Get the compilation information which contains date, user and branch. | ||
* | ||
* @return the compilation information, as a JSON string. | ||
*/ | ||
String getCompileInfo(); | ||
|
||
} |
Oops, something went wrong.