本文整理汇总了Java中org.apache.hadoop.http.HttpServer.createDefaultChannelConnector方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServer.createDefaultChannelConnector方法的具体用法?Java HttpServer.createDefaultChannelConnector怎么用?Java HttpServer.createDefaultChannelConnector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.http.HttpServer
的用法示例。
在下文中一共展示了HttpServer.createDefaultChannelConnector方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSecureResources
import org.apache.hadoop.http.HttpServer; //导入方法依赖的package包/类
@VisibleForTesting
public static SecureResources getSecureResources(final SSLFactory sslFactory,
Configuration conf) throws Exception {
// Obtain secure port for data streaming to datanode
InetSocketAddress streamingAddr = DataNode.getStreamingAddr(conf);
int socketWriteTimeout = conf.getInt(DFSConfigKeys.DFS_DATANODE_SOCKET_WRITE_TIMEOUT_KEY,
HdfsServerConstants.WRITE_TIMEOUT);
ServerSocket ss = (socketWriteTimeout > 0) ?
ServerSocketChannel.open().socket() : new ServerSocket();
ss.bind(streamingAddr, 0);
// Check that we got the port we need
if (ss.getLocalPort() != streamingAddr.getPort()) {
throw new RuntimeException("Unable to bind on specified streaming port in secure " +
"context. Needed " + streamingAddr.getPort() + ", got " + ss.getLocalPort());
}
// Obtain secure listener for web server
Connector listener;
if (HttpConfig.isSecure()) {
try {
sslFactory.init();
} catch (GeneralSecurityException ex) {
throw new IOException(ex);
}
SslSocketConnector sslListener = new SslSocketConnector() {
@Override
protected SSLServerSocketFactory createFactory() throws Exception {
return sslFactory.createSSLServerSocketFactory();
}
};
listener = sslListener;
} else {
listener = HttpServer.createDefaultChannelConnector();
}
InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
listener.setHost(infoSocAddr.getHostName());
listener.setPort(infoSocAddr.getPort());
// Open listener here in order to bind to port as root
listener.open();
if (listener.getPort() != infoSocAddr.getPort()) {
throw new RuntimeException("Unable to bind on specified info port in secure " +
"context. Needed " + streamingAddr.getPort() + ", got " + ss.getLocalPort());
}
System.err.println("Successfully obtained privileged resources (streaming port = "
+ ss + " ) (http listener port = " + listener.getConnection() +")");
if ((ss.getLocalPort() > 1023 || listener.getPort() > 1023) &&
UserGroupInformation.isSecurityEnabled()) {
throw new RuntimeException("Cannot start secure datanode with unprivileged ports");
}
System.err.println("Opened streaming server at " + streamingAddr);
System.err.println("Opened info server at " + infoSocAddr);
return new SecureResources(ss, listener);
}
示例2: getSecureResources
import org.apache.hadoop.http.HttpServer; //导入方法依赖的package包/类
@VisibleForTesting
public static SecureResources getSecureResources(final SSLFactory sslFactory,
Configuration conf) throws Exception {
// Obtain secure port for data streaming to datanode
InetSocketAddress streamingAddr = DataNode.getStreamingAddr(conf);
int socketWriteTimeout =
conf.getInt(DFSConfigKeys.DFS_DATANODE_SOCKET_WRITE_TIMEOUT_KEY,
HdfsServerConstants.WRITE_TIMEOUT);
ServerSocket ss =
(socketWriteTimeout > 0) ? ServerSocketChannel.open().socket() :
new ServerSocket();
ss.bind(streamingAddr, 0);
// Check that we got the port we need
if (ss.getLocalPort() != streamingAddr.getPort()) {
throw new RuntimeException(
"Unable to bind on specified streaming port in secure " +
"context. Needed " + streamingAddr.getPort() + ", got " +
ss.getLocalPort());
}
// Obtain secure listener for web server
Connector listener;
if (HttpConfig2.isSecure()) {
try {
sslFactory.init();
} catch (GeneralSecurityException ex) {
throw new IOException(ex);
}
SslSocketConnector sslListener = new SslSocketConnector() {
@Override
protected SSLServerSocketFactory createFactory() throws Exception {
return sslFactory.createSSLServerSocketFactory();
}
};
listener = sslListener;
} else {
listener = HttpServer.createDefaultChannelConnector();
}
InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
listener.setHost(infoSocAddr.getHostName());
listener.setPort(infoSocAddr.getPort());
// Open listener here in order to bind to port as root
listener.open();
if (listener.getPort() != infoSocAddr.getPort()) {
throw new RuntimeException(
"Unable to bind on specified info port in secure " +
"context. Needed " + streamingAddr.getPort() + ", got " +
ss.getLocalPort());
}
System.err.println(
"Successfully obtained privileged resources (streaming port = " + ss +
" ) (http listener port = " + listener.getConnection() + ")");
if ((ss.getLocalPort() > 1023 || listener.getPort() > 1023) &&
UserGroupInformation.isSecurityEnabled()) {
throw new RuntimeException(
"Cannot start secure datanode with unprivileged ports");
}
System.err.println("Opened streaming server at " + streamingAddr);
System.err.println("Opened info server at " + infoSocAddr);
return new SecureResources(ss, listener);
}
示例3: init
import org.apache.hadoop.http.HttpServer; //导入方法依赖的package包/类
@Override
public void init(DaemonContext context) throws Exception {
System.err.println("Initializing secure datanode resources");
// We should only start up a secure datanode in a Kerberos-secured cluster
Configuration conf = new Configuration(); // Skip UGI method to not log in
if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
// Stash command-line arguments for regular datanode
args = context.getArguments();
// Obtain secure port for data streaming to datanode
InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
HdfsConstants.WRITE_TIMEOUT);
ServerSocket ss = (socketWriteTimeout > 0) ?
ServerSocketChannel.open().socket() : new ServerSocket();
ss.bind(socAddr, 0);
// Check that we got the port we need
if(ss.getLocalPort() != socAddr.getPort())
throw new RuntimeException("Unable to bind on specified streaming port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
// Obtain secure listener for web server
SelectChannelConnector listener =
(SelectChannelConnector)HttpServer.createDefaultChannelConnector();
InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
listener.setHost(infoSocAddr.getHostName());
listener.setPort(infoSocAddr.getPort());
// Open listener here in order to bind to port as root
listener.open();
if(listener.getPort() != infoSocAddr.getPort())
throw new RuntimeException("Unable to bind on specified info port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
throw new RuntimeException("Cannot start secure datanode on non-privileged "
+" ports. (streaming port = " + ss + " ) (http listener port = " +
listener.getConnection() + "). Exiting.");
System.err.println("Successfully obtained privileged resources (streaming port = "
+ ss + " ) (http listener port = " + listener.getConnection() +")");
resources = new SecureResources(ss, listener);
}
示例4: init
import org.apache.hadoop.http.HttpServer; //导入方法依赖的package包/类
@Override
public void init(DaemonContext context) throws Exception {
System.err.println("Initializing secure datanode resources");
// We should only start up a secure datanode in a Kerberos-secured cluster
Configuration conf = new Configuration(); // Skip UGI method to not log in
if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
// Stash command-line arguments for regular datanode
args = context.getArguments();
// Obtain secure port for data streaming to datanode
InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
HdfsConstants.WRITE_TIMEOUT);
ServerSocket ss = (socketWriteTimeout > 0) ?
ServerSocketChannel.open().socket() : new ServerSocket();
ss.bind(socAddr, 0);
// Check that we got the port we need
if(ss.getLocalPort() != socAddr.getPort())
throw new RuntimeException("Unable to bind on specified streaming port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
// Obtain secure listener for web server
SelectChannelConnector listener =
(SelectChannelConnector)HttpServer.createDefaultChannelConnector();
InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
listener.setHost(infoSocAddr.getHostName());
listener.setPort(infoSocAddr.getPort());
// Open listener here in order to bind to port as root
listener.open();
if(listener.getPort() != infoSocAddr.getPort())
throw new RuntimeException("Unable to bind on specified info port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
System.err.println("Successfully obtained privileged resources (streaming port = "
+ ss + " ) (http listener port = " + listener.getConnection() +")");
if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
throw new RuntimeException("Cannot start secure datanode with unprivileged ports");
resources = new SecureResources(ss, listener);
}