|
@@ -42,8 +42,10 @@ import org.apache.hadoop.security.ssl.SSLFactory;
|
|
|
|
|
|
import java.io.Closeable;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.BindException;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.SocketAddress;
|
|
|
+import java.net.SocketException;
|
|
|
import java.nio.channels.ServerSocketChannel;
|
|
|
import java.security.GeneralSecurityException;
|
|
|
|
|
@@ -142,19 +144,41 @@ public class DatanodeHttpServer implements Closeable {
|
|
|
return httpsAddress;
|
|
|
}
|
|
|
|
|
|
- public void start() {
|
|
|
+ public void start() throws IOException {
|
|
|
if (httpServer != null) {
|
|
|
- ChannelFuture f = httpServer.bind(DataNode.getInfoAddr(conf));
|
|
|
- f.syncUninterruptibly();
|
|
|
+ InetSocketAddress infoAddr = DataNode.getInfoAddr(conf);
|
|
|
+ ChannelFuture f = httpServer.bind(infoAddr);
|
|
|
+ try {
|
|
|
+ f.syncUninterruptibly();
|
|
|
+ } catch (Throwable e) {
|
|
|
+ if (e instanceof BindException) {
|
|
|
+ throw NetUtils.wrapException(null, 0, infoAddr.getHostName(),
|
|
|
+ infoAddr.getPort(), (SocketException) e);
|
|
|
+ } else {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
httpAddress = (InetSocketAddress) f.channel().localAddress();
|
|
|
LOG.info("Listening HTTP traffic on " + httpAddress);
|
|
|
}
|
|
|
|
|
|
if (httpsServer != null) {
|
|
|
- InetSocketAddress secInfoSocAddr = NetUtils.createSocketAddr(conf.getTrimmed(
|
|
|
- DFS_DATANODE_HTTPS_ADDRESS_KEY, DFS_DATANODE_HTTPS_ADDRESS_DEFAULT));
|
|
|
+ InetSocketAddress secInfoSocAddr =
|
|
|
+ NetUtils.createSocketAddr(conf.getTrimmed(
|
|
|
+ DFS_DATANODE_HTTPS_ADDRESS_KEY,
|
|
|
+ DFS_DATANODE_HTTPS_ADDRESS_DEFAULT));
|
|
|
ChannelFuture f = httpsServer.bind(secInfoSocAddr);
|
|
|
- f.syncUninterruptibly();
|
|
|
+
|
|
|
+ try {
|
|
|
+ f.syncUninterruptibly();
|
|
|
+ } catch (Throwable e) {
|
|
|
+ if (e instanceof BindException) {
|
|
|
+ throw NetUtils.wrapException(null, 0, secInfoSocAddr.getHostName(),
|
|
|
+ secInfoSocAddr.getPort(), (SocketException) e);
|
|
|
+ } else {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
httpsAddress = (InetSocketAddress) f.channel().localAddress();
|
|
|
LOG.info("Listening HTTPS traffic on " + httpsAddress);
|
|
|
}
|