use of org.eclipse.jetty.util.thread.ExecutorThreadPool in project hive by apache.
the class ThriftHttpCLIService method run.
/**
* Configure Jetty to serve http requests. Example of a client connection URL:
* http://localhost:10000/servlets/thrifths2/ A gateway may cause actual target URL to differ,
* e.g. http://gateway:port/hive2/servlets/thrifths2/
*/
@Override
public void run() {
try {
// Server thread pool
// Start with minWorkerThreads, expand till maxWorkerThreads and reject subsequent requests
String threadPoolName = "HiveServer2-HttpHandler-Pool";
ExecutorService executorService = new ThreadPoolExecutorWithOomHook(minWorkerThreads, maxWorkerThreads, workerKeepAliveTime, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactoryWithGarbageCleanup(threadPoolName), oomHook);
ExecutorThreadPool threadPool = new ExecutorThreadPool(executorService);
// HTTP Server
httpServer = new Server(threadPool);
ServerConnector connector;
final HttpConfiguration conf = new HttpConfiguration();
// Configure header size
int requestHeaderSize = hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_REQUEST_HEADER_SIZE);
int responseHeaderSize = hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_RESPONSE_HEADER_SIZE);
conf.setRequestHeaderSize(requestHeaderSize);
conf.setResponseHeaderSize(responseHeaderSize);
final HttpConnectionFactory http = new HttpConnectionFactory(conf);
boolean useSsl = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_USE_SSL);
String schemeName = useSsl ? "https" : "http";
// Change connector if SSL is used
if (useSsl) {
String keyStorePath = hiveConf.getVar(ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PATH).trim();
String keyStorePassword = ShimLoader.getHadoopShims().getPassword(hiveConf, HiveConf.ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PASSWORD.varname);
if (keyStorePath.isEmpty()) {
throw new IllegalArgumentException(ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PATH.varname + " Not configured for SSL connection");
}
SslContextFactory sslContextFactory = new SslContextFactory();
String[] excludedProtocols = hiveConf.getVar(ConfVars.HIVE_SSL_PROTOCOL_BLACKLIST).split(",");
LOG.info("HTTP Server SSL: adding excluded protocols: " + Arrays.toString(excludedProtocols));
sslContextFactory.addExcludeProtocols(excludedProtocols);
LOG.info("HTTP Server SSL: SslContextFactory.getExcludeProtocols = " + Arrays.toString(sslContextFactory.getExcludeProtocols()));
sslContextFactory.setKeyStorePath(keyStorePath);
sslContextFactory.setKeyStorePassword(keyStorePassword);
connector = new ServerConnector(httpServer, sslContextFactory, http);
} else {
connector = new ServerConnector(httpServer, http);
}
connector.setPort(portNum);
// Linux:yes, Windows:no
connector.setReuseAddress(true);
int maxIdleTime = (int) hiveConf.getTimeVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_MAX_IDLE_TIME, TimeUnit.MILLISECONDS);
connector.setIdleTimeout(maxIdleTime);
httpServer.addConnector(connector);
// Thrift configs
hiveAuthFactory = new HiveAuthFactory(hiveConf);
TProcessor processor = new TCLIService.Processor<Iface>(this);
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
// Set during the init phase of HiveServer2 if auth mode is kerberos
// UGI for the hive/_HOST (kerberos) principal
UserGroupInformation serviceUGI = cliService.getServiceUGI();
// UGI for the http/_HOST (SPNego) principal
UserGroupInformation httpUGI = cliService.getHttpUGI();
String authType = hiveConf.getVar(ConfVars.HIVE_SERVER2_AUTHENTICATION);
TServlet thriftHttpServlet = new ThriftHttpServlet(processor, protocolFactory, authType, serviceUGI, httpUGI, hiveAuthFactory);
// Context handler
final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
if (hiveConf.getBoolean(ConfVars.HIVE_SERVER2_XSRF_FILTER_ENABLED.varname, false)) {
// context.addFilter(Utils.getXSRFFilterHolder(null, null), "/" ,
// FilterMapping.REQUEST);
// Filtering does not work here currently, doing filter in ThriftHttpServlet
LOG.debug("XSRF filter enabled");
} else {
LOG.warn("XSRF filter disabled");
}
final String httpPath = getHttpPath(hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_HTTP_PATH));
if (HiveConf.getBoolVar(hiveConf, ConfVars.HIVE_SERVER2_THRIFT_HTTP_COMPRESSION_ENABLED)) {
final GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(context);
gzipHandler.addIncludedMethods(HttpMethod.POST);
gzipHandler.addIncludedMimeTypes(APPLICATION_THRIFT);
httpServer.setHandler(gzipHandler);
} else {
httpServer.setHandler(context);
}
context.addServlet(new ServletHolder(thriftHttpServlet), httpPath);
// TODO: check defaults: maxTimeout, keepalive, maxBodySize, bodyRecieveDuration, etc.
// Finally, start the server
httpServer.start();
String msg = "Started " + ThriftHttpCLIService.class.getSimpleName() + " in " + schemeName + " mode on port " + portNum + " path=" + httpPath + " with " + minWorkerThreads + "..." + maxWorkerThreads + " worker threads";
LOG.info(msg);
httpServer.join();
} catch (Throwable t) {
LOG.error("Error starting HiveServer2: could not start " + ThriftHttpCLIService.class.getSimpleName(), t);
System.exit(-1);
}
}
use of org.eclipse.jetty.util.thread.ExecutorThreadPool in project xxl-job by xuxueli.
the class JettyServer method start.
public void start(final int port, final String ip, final String appName) throws Exception {
thread = new Thread(new Runnable() {
@Override
public void run() {
// The Server
// 非阻塞
server = new Server(new ExecutorThreadPool());
// HTTP connector
ServerConnector connector = new ServerConnector(server);
if (ip != null && ip.trim().length() > 0) {
// The network interface this connector binds to as an IP address or a hostname. If null or 0.0.0.0, then bind to all interfaces.
connector.setHost(ip);
}
connector.setPort(port);
server.setConnectors(new Connector[] { connector });
// Set a handler
HandlerCollection handlerc = new HandlerCollection();
handlerc.setHandlers(new Handler[] { new JettyServerHandler() });
server.setHandler(handlerc);
try {
// Start server
server.start();
logger.info(">>>>>>>>>>> xxl-job jetty server start success at port:{}.", port);
// Start Registry-Server
ExecutorRegistryThread.getInstance().start(port, ip, appName);
// Start Callback-Server
TriggerCallbackThread.getInstance().start();
// block until thread stopped
server.join();
logger.info(">>>>>>>>>>> xxl-rpc server join success, netcon={}, port={}", JettyServer.class.getName(), port);
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
// destroy();
}
}
});
// daemon, service jvm, user thread leave >>> daemon leave >>> jvm leave
thread.setDaemon(true);
thread.start();
}
use of org.eclipse.jetty.util.thread.ExecutorThreadPool in project qpid-broker-j by apache.
the class HttpManagement method createServer.
private Server createServer(Collection<HttpPort<?>> ports) {
LOGGER.debug("Starting up web server on {}", ports);
_jettyServerExecutor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("Jetty-Server-Thread"));
Server server = new Server(new ExecutorThreadPool(_jettyServerExecutor));
int lastPort = -1;
for (HttpPort<?> port : ports) {
ServerConnector connector = createConnector(port, server);
connector.addBean(new ConnectionTrackingListener());
server.addConnector(connector);
_portConnectorMap.put(port, connector);
lastPort = port.getPort();
}
ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
root.setContextPath("/");
root.setCompactPath(true);
server.setHandler(root);
final ErrorHandler errorHandler = new ErrorHandler() {
@Override
protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException {
String uri = request.getRequestURI();
writeErrorPageMessage(request, writer, code, message, uri);
for (int i = 0; i < 20; i++) writer.write("<br/> \n");
}
};
root.setErrorHandler(errorHandler);
// set servlet context attributes for broker and configuration
root.getServletContext().setAttribute(HttpManagementUtil.ATTR_BROKER, getBroker());
root.getServletContext().setAttribute(HttpManagementUtil.ATTR_MANAGEMENT_CONFIGURATION, this);
root.addFilter(new FilterHolder(new ExceptionHandlingFilter()), "/*", EnumSet.allOf(DispatcherType.class));
FilterHolder corsFilter = new FilterHolder(new CrossOriginFilter());
corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, getCorsAllowOrigins());
corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, Joiner.on(",").join(getCorsAllowMethods()));
corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, getCorsAllowHeaders());
corsFilter.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(getCorsAllowCredentials()));
root.addFilter(corsFilter, "/*", EnumSet.of(DispatcherType.REQUEST));
root.addFilter(new FilterHolder(new MethodFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
addFiltersAndServletsForRest(root);
if (!Boolean.TRUE.equals(getContextValue(Boolean.class, DISABLE_UI_CONTEXT_NAME))) {
addFiltersAndServletsForUserInterfaces(root);
}
root.getSessionHandler().getSessionCookieConfig().setName(JSESSIONID_COOKIE_PREFIX + lastPort);
root.getSessionHandler().getSessionCookieConfig().setHttpOnly(true);
root.getSessionHandler().setMaxInactiveInterval(getSessionTimeout());
return server;
}
use of org.eclipse.jetty.util.thread.ExecutorThreadPool in project ANNIS by korpling.
the class AnnisServiceRunner method createWebServer.
private void createWebServer() {
// create beans
ctx = new GenericXmlApplicationContext();
ctx.setValidating(false);
AnnisXmlContextHelper.prepareContext(ctx);
ctx.load("file:" + Utils.getAnnisFile("conf/spring/Service.xml").getAbsolutePath());
ctx.refresh();
ResourceConfig rc = new PackagesResourceConfig("annis.service.internal", "annis.provider", "annis.rest.provider");
final IoCComponentProviderFactory factory = new SpringComponentProviderFactory(rc, ctx);
int port = overridePort == null ? ctx.getBean(QueryServiceImpl.class).getPort() : overridePort;
try {
// only allow connections from localhost
// if the administrator wants to allow external acccess he *has* to
// use a HTTP proxy which also should use SSL encryption
InetSocketAddress addr = new InetSocketAddress("localhost", port);
server = new Server(addr);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
server.setHandler(context);
server.setThreadPool(new ExecutorThreadPool());
ServletContainer jerseyContainer = new ServletContainer(rc) {
@Override
protected void initiate(ResourceConfig rc, WebApplication wa) {
wa.initiate(rc, factory);
}
};
ServletHolder holder = new ServletHolder(jerseyContainer);
context.addServlet(holder, "/*");
context.setInitParameter(EnvironmentLoader.ENVIRONMENT_CLASS_PARAM, MultipleIniWebEnvironment.class.getName());
if (useAuthentification) {
log.info("Using authentification");
context.setInitParameter(EnvironmentLoader.CONFIG_LOCATIONS_PARAM, "file:" + System.getProperty("annis.home") + "/conf/shiro.ini," + "file:" + System.getProperty("annis.home") + "/conf/develop_shiro.ini");
} else {
log.warn("*NOT* using authentification, your ANNIS service *IS NOT SECURED*");
context.setInitParameter(EnvironmentLoader.CONFIG_LOCATIONS_PARAM, "file:" + System.getProperty("annis.home") + "/conf/shiro_no_security.ini");
}
EnumSet<DispatcherType> gzipDispatcher = EnumSet.of(DispatcherType.REQUEST);
context.addFilter(GzipFilter.class, "/*", gzipDispatcher);
// configure Apache Shiro with the web application
context.addEventListener(new EnvironmentLoaderListener());
EnumSet<DispatcherType> shiroDispatchers = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ERROR);
context.addFilter(ShiroFilter.class, "/*", shiroDispatchers);
} catch (IllegalArgumentException ex) {
log.error("IllegalArgumentException at ANNIS service startup", ex);
isShutdownRequested = true;
errorCode = 101;
} catch (NullPointerException ex) {
log.error("NullPointerException at ANNIS service startup", ex);
isShutdownRequested = true;
errorCode = 101;
} catch (AnnisRunnerException ex) {
errorCode = ex.getExitCode();
}
}
use of org.eclipse.jetty.util.thread.ExecutorThreadPool in project hive by apache.
the class ThriftHttpCLIService method initServer.
/**
* Configure Jetty to serve http requests. Example of a client connection URL:
* http://localhost:10000/servlets/thrifths2/ A gateway may cause actual target
* URL to differ, e.g. http://gateway:port/hive2/servlets/thrifths2/
*/
@Override
protected void initServer() {
try {
// Server thread pool
// Start with minWorkerThreads, expand till maxWorkerThreads and reject
// subsequent requests
String threadPoolName = "HiveServer2-HttpHandler-Pool";
ThreadPoolExecutor executorService = new ThreadPoolExecutor(minWorkerThreads, maxWorkerThreads, workerKeepAliveTime, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactoryWithGarbageCleanup(threadPoolName));
ExecutorThreadPool threadPool = new ExecutorThreadPool(executorService);
// HTTP Server
server = new Server(threadPool);
ServerConnector connector;
final HttpConfiguration conf = new HttpConfiguration();
// Configure header size
int requestHeaderSize = hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_REQUEST_HEADER_SIZE);
int responseHeaderSize = hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_RESPONSE_HEADER_SIZE);
conf.setRequestHeaderSize(requestHeaderSize);
conf.setResponseHeaderSize(responseHeaderSize);
final HttpConnectionFactory http = new HttpConnectionFactory(conf) {
public Connection newConnection(Connector connector, EndPoint endPoint) {
Connection connection = super.newConnection(connector, endPoint);
connection.addListener(new Connection.Listener() {
public void onOpened(Connection connection) {
openConnection();
}
public void onClosed(Connection connection) {
closeConnection();
}
});
return connection;
}
};
boolean useSsl = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_USE_SSL);
String schemeName = useSsl ? "https" : "http";
// Change connector if SSL is used
if (useSsl) {
String keyStorePath = hiveConf.getVar(ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PATH).trim();
String keyStorePassword = ShimLoader.getHadoopShims().getPassword(hiveConf, HiveConf.ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PASSWORD.varname);
if (keyStorePath.isEmpty()) {
throw new IllegalArgumentException(ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PATH.varname + " Not configured for SSL connection");
}
String keyStoreType = hiveConf.getVar(ConfVars.HIVE_SERVER2_SSL_KEYSTORE_TYPE).trim();
if (keyStoreType.isEmpty()) {
keyStoreType = KeyStore.getDefaultType();
}
String keyStoreAlgorithm = hiveConf.getVar(ConfVars.HIVE_SERVER2_SSL_KEYMANAGERFACTORY_ALGORITHM).trim();
if (keyStoreAlgorithm.isEmpty()) {
keyStoreAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
}
SslContextFactory sslContextFactory = new SslContextFactory();
String[] excludedProtocols = hiveConf.getVar(ConfVars.HIVE_SSL_PROTOCOL_BLACKLIST).split(",");
LOG.info("HTTP Server SSL: adding excluded protocols: " + Arrays.toString(excludedProtocols));
sslContextFactory.addExcludeProtocols(excludedProtocols);
LOG.info("HTTP Server SSL: SslContextFactory.getExcludeProtocols = " + Arrays.toString(sslContextFactory.getExcludeProtocols()));
sslContextFactory.setKeyStorePath(keyStorePath);
sslContextFactory.setKeyStorePassword(keyStorePassword);
sslContextFactory.setKeyStoreType(keyStoreType);
sslContextFactory.setKeyManagerFactoryAlgorithm(keyStoreAlgorithm);
String excludeCiphersuites = hiveConf.getVar(ConfVars.HIVE_SERVER2_SSL_HTTP_EXCLUDE_CIPHERSUITES).trim();
if (!excludeCiphersuites.trim().isEmpty()) {
Set<String> excludeCS = Sets.newHashSet(Splitter.on(",").trimResults().omitEmptyStrings().split(excludeCiphersuites.trim()));
int eSize = excludeCS.size();
if (eSize > 0) {
sslContextFactory.setExcludeCipherSuites(excludeCS.toArray(new String[eSize]));
}
}
connector = new ServerConnector(server, sslContextFactory, http);
} else {
connector = new ServerConnector(server, http);
}
connector.setPort(portNum);
// Linux:yes, Windows:no
connector.setReuseAddress(true);
int maxIdleTime = (int) hiveConf.getTimeVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_MAX_IDLE_TIME, TimeUnit.MILLISECONDS);
connector.setIdleTimeout(maxIdleTime);
connector.setAcceptQueueSize(maxWorkerThreads);
server.addConnector(connector);
// Thrift configs
hiveAuthFactory = new HiveAuthFactory(hiveConf);
TProcessor processor = new TCLIService.Processor<Iface>(this);
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
// Set during the init phase of HiveServer2 if auth mode is kerberos
// UGI for the hive/_HOST (kerberos) principal
UserGroupInformation serviceUGI = cliService.getServiceUGI();
// UGI for the http/_HOST (SPNego) principal
UserGroupInformation httpUGI = cliService.getHttpUGI();
String authType = hiveConf.getVar(ConfVars.HIVE_SERVER2_AUTHENTICATION);
TServlet thriftHttpServlet = new ThriftHttpServlet(processor, protocolFactory, authType, serviceUGI, httpUGI, hiveAuthFactory, hiveConf);
// Context handler
final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
if (hiveConf.getBoolean(ConfVars.HIVE_SERVER2_XSRF_FILTER_ENABLED.varname, false)) {
// context.addFilter(Utils.getXSRFFilterHolder(null, null), "/" ,
// FilterMapping.REQUEST);
// Filtering does not work here currently, doing filter in ThriftHttpServlet
LOG.debug("XSRF filter enabled");
} else {
LOG.warn("XSRF filter disabled");
}
final String httpPath = getHttpPath(hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_HTTP_PATH));
if (HiveConf.getBoolVar(hiveConf, ConfVars.HIVE_SERVER2_THRIFT_HTTP_COMPRESSION_ENABLED)) {
final GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(context);
gzipHandler.addIncludedMethods(HttpMethod.POST);
gzipHandler.addIncludedMimeTypes(APPLICATION_THRIFT);
server.setHandler(gzipHandler);
} else {
server.setHandler(context);
}
context.addServlet(new ServletHolder(thriftHttpServlet), httpPath);
if (HiveSamlUtils.isSamlAuthMode(authType)) {
String ssoPath = HiveSamlUtils.getCallBackPath(hiveConf);
context.addServlet(new ServletHolder(new HiveSamlHttpServlet(hiveConf)), ssoPath);
}
constrainHttpMethods(context, false);
// TODO: check defaults: maxTimeout, keepalive, maxBodySize,
// bodyRecieveDuration, etc.
// Finally, start the server
server.start();
String msg = "Started " + ThriftHttpCLIService.class.getSimpleName() + " in " + schemeName + " mode on port " + portNum + " path=" + httpPath + " with " + minWorkerThreads + "..." + maxWorkerThreads + " worker threads";
LOG.info(msg);
} catch (Exception e) {
throw new RuntimeException("Failed to init HttpServer", e);
}
}
Aggregations