use of org.eclipse.jetty.server.LowResourceMonitor in project hive by apache.
the class Main method runServer.
public Server runServer(int port) throws Exception {
// Authenticate using keytab
if (UserGroupInformation.isSecurityEnabled()) {
String serverPrincipal = SecurityUtil.getServerPrincipal(conf.kerberosPrincipal(), "0.0.0.0");
UserGroupInformation.loginUserFromKeytab(serverPrincipal, conf.kerberosKeytab());
}
// Create the Jetty server. If jetty conf file exists, use that to create server
// to have more control.
Server server = null;
if (StringUtils.isEmpty(conf.jettyConfiguration())) {
server = new Server(port);
} else {
FileInputStream jettyConf = new FileInputStream(conf.jettyConfiguration());
XmlConfiguration configuration = new XmlConfiguration(jettyConf);
server = (Server) configuration.configure();
}
ServletContextHandler root = new ServletContextHandler(server, "/");
// Add the Auth filter
FilterHolder fHolder = makeAuthFilter();
EnumSet<DispatcherType> dispatches = EnumSet.of(DispatcherType.REQUEST);
/*
* We add filters for each of the URIs supported by templeton.
* If we added the entire sub-structure using '/*', the mapreduce
* notification cannot give the callback to templeton in secure mode.
* This is because mapreduce does not use secure credentials for
* callbacks. So jetty would fail the request as unauthorized.
*/
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/ddl/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/pig/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/hive/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/sqoop/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/queue/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/jobs/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/mapreduce/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/status/*", dispatches);
root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/version/*", dispatches);
if (conf.getBoolean(AppConfig.XSRF_FILTER_ENABLED, false)) {
root.addFilter(makeXSRFFilter(), "/" + SERVLET_PATH + "/*", dispatches);
LOG.debug("XSRF filter enabled");
} else {
LOG.warn("XSRF filter disabled");
}
root.addFilter(makeFrameOptionFilter(), "/" + SERVLET_PATH + "/*", dispatches);
// Connect Jersey
ServletHolder h = new ServletHolder(new ServletContainer(makeJerseyConfig()));
root.addServlet(h, "/" + SERVLET_PATH + "/*");
// Add any redirects
addRedirects(server);
// Set handling for low resource conditions.
final LowResourceMonitor low = new LowResourceMonitor(server);
low.setLowResourcesIdleTimeout(10000);
server.addBean(low);
server.addConnector(createChannelConnector());
// Start the server
server.start();
this.server = server;
return server;
}
use of org.eclipse.jetty.server.LowResourceMonitor in project pentaho-kettle by pentaho.
the class WebServerTest method testJettyOption_LowResourceMaxIdleTimeSetUp.
@Test
public void testJettyOption_LowResourceMaxIdleTimeSetUp() throws Exception {
LowResourceMonitor lowResourceMonitor = webServer.getServer().getBean(LowResourceMonitor.class);
assertNotNull(lowResourceMonitor);
assertEquals(EXPECTED_RES_MAX_IDLE_TIME, lowResourceMonitor.getLowResourcesIdleTimeout());
}
use of org.eclipse.jetty.server.LowResourceMonitor in project pentaho-kettle by pentaho.
the class WebServer method getServerConnector.
private ServerConnector getServerConnector() {
ServerConnector serverConnector = null;
int jettyAcceptors = -1;
// Check if there's configuration for the number of acceptors to use
if (validProperty(Const.KETTLE_CARTE_JETTY_ACCEPTORS)) {
jettyAcceptors = Integer.parseInt(System.getProperty(Const.KETTLE_CARTE_JETTY_ACCEPTORS));
log.logBasic(BaseMessages.getString(PKG, "WebServer.Log.ConfigOptions", "acceptors", jettyAcceptors));
}
// Create the server with the configurated number of acceptors
if (sslConfig != null) {
log.logBasic(BaseMessages.getString(PKG, "WebServer.Log.SslModeUsing"));
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(sslConfig.getKeyStore());
sslContextFactory.setKeyStorePassword(sslConfig.getKeyStorePassword());
sslContextFactory.setKeyManagerPassword(sslConfig.getKeyPassword());
sslContextFactory.setKeyStoreType(sslConfig.getKeyStoreType());
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
serverConnector = new ServerConnector(server, jettyAcceptors, -1, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https));
} else {
serverConnector = new ServerConnector(server, jettyAcceptors, -1);
}
// Low resources options
if (validProperty(Const.KETTLE_CARTE_JETTY_ACCEPT_QUEUE_SIZE)) {
serverConnector.setAcceptQueueSize(Integer.parseInt(System.getProperty(Const.KETTLE_CARTE_JETTY_ACCEPT_QUEUE_SIZE)));
log.logBasic(BaseMessages.getString(PKG, "WebServer.Log.ConfigOptions", "acceptQueueSize", serverConnector.getAcceptQueueSize()));
}
if (validProperty(Const.KETTLE_CARTE_JETTY_RES_MAX_IDLE_TIME)) {
LowResourceMonitor lowResourceMonitor = new LowResourceMonitor(server);
lowResourceMonitor.setLowResourcesIdleTimeout(Integer.parseInt(System.getProperty(Const.KETTLE_CARTE_JETTY_RES_MAX_IDLE_TIME)));
server.addBean(lowResourceMonitor);
log.logBasic(BaseMessages.getString(PKG, "WebServer.Log.ConfigOptions", "lowResourcesMaxIdleTime", lowResourceMonitor.getLowResourcesIdleTimeout()));
}
return serverConnector;
}
use of org.eclipse.jetty.server.LowResourceMonitor in project jetty.project by eclipse.
the class LikeJettyXml method main.
public static void main(String[] args) throws Exception {
// Path to as-built jetty-distribution directory
String jettyHomeBuild = "../../jetty-distribution/target/distribution";
// Find jetty home and base directories
String homePath = System.getProperty("jetty.home", jettyHomeBuild);
File start_jar = new File(homePath, "start.jar");
if (!start_jar.exists()) {
homePath = jettyHomeBuild = "jetty-distribution/target/distribution";
start_jar = new File(homePath, "start.jar");
if (!start_jar.exists())
throw new FileNotFoundException(start_jar.toString());
}
File homeDir = new File(homePath);
String basePath = System.getProperty("jetty.base", homeDir + "/demo-base");
File baseDir = new File(basePath);
if (!baseDir.exists()) {
throw new FileNotFoundException(baseDir.getAbsolutePath());
}
// Configure jetty.home and jetty.base system properties
String jetty_home = homeDir.getAbsolutePath();
String jetty_base = baseDir.getAbsolutePath();
System.setProperty("jetty.home", jetty_home);
System.setProperty("jetty.base", jetty_base);
// === jetty.xml ===
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(500);
// Server
Server server = new Server(threadPool);
// Scheduler
server.addBean(new ScheduledExecutorScheduler());
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(8443);
http_config.setOutputBufferSize(32768);
http_config.setRequestHeaderSize(8192);
http_config.setResponseHeaderSize(8192);
http_config.setSendServerVersion(true);
http_config.setSendDateHeader(false);
// httpConfig.addCustomizer(new ForwardedRequestCustomizer());
// Handler Structure
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });
server.setHandler(handlers);
// Extra options
server.setDumpAfterStart(false);
server.setDumpBeforeStop(false);
server.setStopAtShutdown(true);
// === jetty-jmx.xml ===
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
// === jetty-http.xml ===
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
http.setPort(8080);
http.setIdleTimeout(30000);
server.addConnector(http);
// === jetty-https.xml ===
// SSL Context Factory
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(jetty_home + "/../../../jetty-server/src/test/config/etc/keystore");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setTrustStorePath(jetty_home + "/../../../jetty-server/src/test/config/etc/keystore");
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
// SSL HTTP Configuration
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
// SSL Connector
ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
sslConnector.setPort(8443);
server.addConnector(sslConnector);
// === jetty-deploy.xml ===
DeploymentManager deployer = new DeploymentManager();
DebugListener debug = new DebugListener(System.err, true, true, true);
server.addBean(debug);
deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
deployer.setContexts(contexts);
deployer.setContextAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/servlet-api-[^/]*\\.jar$");
WebAppProvider webapp_provider = new WebAppProvider();
webapp_provider.setMonitoredDirName(jetty_base + "/webapps");
webapp_provider.setDefaultsDescriptor(jetty_home + "/etc/webdefault.xml");
webapp_provider.setScanInterval(1);
webapp_provider.setExtractWars(true);
webapp_provider.setConfigurationManager(new PropertiesConfigurationManager());
deployer.addAppProvider(webapp_provider);
server.addBean(deployer);
// === setup jetty plus ==
Configuration.ClassList.setServerDefault(server).addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
// === jetty-stats.xml ===
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(server.getHandler());
server.setHandler(stats);
ServerConnectionStatistics.addToAllConnectors(server);
// === Rewrite Handler
RewriteHandler rewrite = new RewriteHandler();
rewrite.setHandler(server.getHandler());
server.setHandler(rewrite);
// === jetty-requestlog.xml ===
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename(jetty_home + "/logs/yyyy_mm_dd.request.log");
requestLog.setFilenameDateFormat("yyyy_MM_dd");
requestLog.setRetainDays(90);
requestLog.setAppend(true);
requestLog.setExtended(true);
requestLog.setLogCookies(false);
requestLog.setLogTimeZone("GMT");
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
handlers.addHandler(requestLogHandler);
// === jetty-lowresources.xml ===
LowResourceMonitor lowResourcesMonitor = new LowResourceMonitor(server);
lowResourcesMonitor.setPeriod(1000);
lowResourcesMonitor.setLowResourcesIdleTimeout(200);
lowResourcesMonitor.setMonitorThreads(true);
lowResourcesMonitor.setMaxConnections(0);
lowResourcesMonitor.setMaxMemory(0);
lowResourcesMonitor.setMaxLowResourcesTime(5000);
server.addBean(lowResourcesMonitor);
// === test-realm.xml ===
HashLoginService login = new HashLoginService();
login.setName("Test Realm");
login.setConfig(jetty_base + "/etc/realm.properties");
login.setHotReload(false);
server.addBean(login);
// Start the server
server.start();
server.join();
}
use of org.eclipse.jetty.server.LowResourceMonitor in project qi4j-sdk by Qi4j.
the class JettyConfigurationHelper method configureServer.
static void configureServer(Server server, JettyConfiguration config) {
// Shutdown
Integer gracefullShudownTimeout = config.gracefullShutdownTimeout().get();
if (gracefullShudownTimeout != null) {
server.setStopTimeout(gracefullShudownTimeout);
}
// Low resource max idle time
Integer lowResourceMaxIdleTime = config.lowResourceMaxIdleTime().get();
if (lowResourceMaxIdleTime != null) {
LowResourceMonitor lowResourceMonitor = new LowResourceMonitor(server);
lowResourceMonitor.setLowResourcesIdleTimeout(lowResourceMaxIdleTime);
server.addBean(lowResourceMonitor);
}
// Statistics
if (config.statistics().get()) {
server.addBean(new ConnectorStatistics());
}
}
Aggregations