knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject knox git commit: KNOX-624: Expose configuration for Jetty's request and response buffer sizes
Date Thu, 12 Nov 2015 23:19:14 GMT
Repository: knox
Updated Branches:
  refs/heads/master eda2fa5e7 -> 43bb06d66


KNOX-624: Expose configuration for Jetty's request and response buffer sizes


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/43bb06d6
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/43bb06d6
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/43bb06d6

Branch: refs/heads/master
Commit: 43bb06d66b35d6cdc00a7d8a8f8c1305efc993ed
Parents: eda2fa5
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Thu Nov 12 18:19:08 2015 -0500
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Thu Nov 12 18:19:08 2015 -0500

----------------------------------------------------------------------
 CHANGES                                         |  1 +
 .../apache/hadoop/gateway/GatewayServer.java    | 72 ++++++++------------
 .../gateway/config/impl/GatewayConfigImpl.java  | 28 ++++++++
 .../config/impl/GatewayConfigImplTest.groovy    | 56 +++++++++++++++
 .../hadoop/gateway/config/GatewayConfig.java    |  8 +++
 .../hadoop/gateway/GatewayTestConfig.java       | 21 ++++++
 6 files changed, 144 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/43bb06d6/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index c0c5d42..85ef05f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@ Release Notes - Apache Knox - Version 0.7.0
     * [KNOX-602] - JWT/SSO Cookie Based Federation Provider
     * [KNOX-604] - Expose configuration of HttpClient's max connections per route setting
     * [KNOX-611] - Expose configuration for Jetty's thread pool and connection queue
+    * [KNOX-624] - Expose configuration for Jetty's request and response buffer sizes
 
 ** Improvement
     * [KNOX-553] - Added topology validation from KnoxCLI to TopologyService deployment.

http://git-wip-us.apache.org/repos/asf/knox/blob/43bb06d6/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
index 159a329..9074a90 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
@@ -51,6 +51,7 @@ import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
 import org.eclipse.jetty.server.handler.HandlerCollection;
 import org.eclipse.jetty.server.handler.RequestLogHandler;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.eclipse.jetty.webapp.WebAppContext;
 import org.jboss.shrinkwrap.api.exporter.ExplodedExporter;
@@ -66,6 +67,7 @@ import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.UnknownHostException;
 import java.security.ProviderException;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -263,57 +265,31 @@ public class GatewayServer {
       this.listener = new InternalTopologyListener();
   }
 
-//  private void setupSslExample() throws Exception {
-//    SslContextFactory sslContextFactory = new SslContextFactory( true );
-//    sslContextFactory.setCertAlias( "server" );
-//    sslContextFactory.setKeyStorePath( "target/test-classes/server-keystore.jks" );
-//    sslContextFactory.setKeyStorePassword( "password" );
-//    //sslContextFactory.setKeyManagerPassword( "password" );
-//    sslContextFactory.setTrustStore( "target/test-classes/server-truststore.jks" );
-//    sslContextFactory.setTrustStorePassword( "password" );
-//    sslContextFactory.setNeedClientAuth( false );
-//    sslContextFactory.setTrustAll( true );
-//    SslConnector sslConnector = new SslSelectChannelConnector( sslContextFactory );
-//
-//    ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS
);
-//    context.setContextPath( "/" );
-//    ServletHolder servletHolder = new ServletHolder( new MockServlet() );
-//    context.addServlet( servletHolder, "/*" );
-//
-//    jetty = new Server();
-//    jetty.addConnector( sslConnector );
-//    jetty.setHandler( context );
-//    jetty.start();
-//  }
-
-
-  private synchronized void start() throws Exception {
-
-    // Create the global context handler.
-    contexts = new ContextHandlerCollection();
-     // A map to keep track of current deployments by cluster name.
-    deployments = new ConcurrentHashMap<String, WebAppContext>();
+  private static Connector createConnector( final GatewayConfig config ) throws IOException
{
+    Connector connector;
 
     // Determine the socket address and check availability.
     InetSocketAddress address = config.getGatewayAddress();
     checkAddressAvailability( address );
 
-    // Start Jetty.
-    if (config.isSSLEnabled()) {
-      jetty = new Server();
-    }
-    else {
-      jetty = new Server(address);
-    }
     if (config.isSSLEnabled()) {
       SSLService ssl = services.getService("SSLService");
       String keystoreFileName = config.getGatewaySecurityDir() + File.separatorChar + "keystores"
+ File.separatorChar + "gateway.jks";
-      Connector connector = (Connector) ssl.buildSSlConnector(keystoreFileName);
-      connector.setHost(address.getHostName());
-      connector.setPort(address.getPort());
-      jetty.addConnector(connector);
+      connector = (Connector) ssl.buildSSlConnector(keystoreFileName);
+    } else {
+      connector = new SelectChannelConnector();
     }
+    connector.setHost( address.getHostName() );
+    connector.setPort( address.getPort() );
+    connector.setRequestHeaderSize( config.getHttpServerRequestHeaderBuffer() );
+    connector.setRequestBufferSize( config.getHttpServerRequestBuffer() );
+    connector.setResponseHeaderSize( config.getHttpServerResponseHeaderBuffer() );
+    connector.setResponseBufferSize( config.getHttpServerResponseBuffer() );
+
+    return connector;
+  }
 
+  private static HandlerCollection createHandlers( final GatewayConfig config, final ContextHandlerCollection
contexts ) {
     HandlerCollection handlers = new HandlerCollection();
     RequestLogHandler logHandler = new RequestLogHandler();
     logHandler.setRequestLog( new AccessHandler() );
@@ -326,8 +302,20 @@ public class GatewayServer {
     correlationHandler.setHandler( traceHandler );
 
     handlers.setHandlers( new Handler[]{ correlationHandler, logHandler } );
-    jetty.setHandler( handlers );
+    return handlers;
+  }
 
+  private synchronized void start() throws Exception {
+
+    // Create the global context handler.
+    contexts = new ContextHandlerCollection();
+     // A map to keep track of current deployments by cluster name.
+    deployments = new ConcurrentHashMap<String, WebAppContext>();
+
+    // Start Jetty.
+    jetty = new Server();
+    jetty.addConnector( createConnector( config ) );
+    jetty.setHandler( createHandlers( config, contexts ) );
     jetty.setThreadPool( new QueuedThreadPool( config.getThreadPoolMax() ) );
 
     try {

http://git-wip-us.apache.org/repos/asf/knox/blob/43bb06d6/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
index 65e43a7..0b3b106 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
@@ -114,6 +114,10 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   private static final String EPHEMERAL_DH_KEY_SIZE = GATEWAY_CONFIG_FILE_PREFIX + ".jdk.tls.ephemeralDHKeySize";
   private static final String HTTP_CLIENT_MAX_CONNECTION = GATEWAY_CONFIG_FILE_PREFIX + ".httpclient.maxConnections";
   private static final String THREAD_POOL_MAX = GATEWAY_CONFIG_FILE_PREFIX + ".threadpool.max";
+  public static final String HTTP_SERVER_REQUEST_BUFFER = GATEWAY_CONFIG_FILE_PREFIX + "httpserver.requestBuffer";
+  public static final String HTTP_SERVER_REQUEST_HEADER_BUFFER = GATEWAY_CONFIG_FILE_PREFIX
+ "httpserver.requestHeaderBuffer";
+  public static final String HTTP_SERVER_RESPONSE_BUFFER = GATEWAY_CONFIG_FILE_PREFIX + "httpserver.responseBuffer";
+  public static final String HTTP_SERVER_RESPONSE_HEADER_BUFFER = GATEWAY_CONFIG_FILE_PREFIX
+ "httpserver.responseHeaderBuffer";
 
   // These config property names are not inline with the convention of using the
   // GATEWAY_CONFIG_FILE_PREFIX as is done by those above. These are left for
@@ -469,4 +473,28 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
     return i;
   }
 
+  @Override
+  public int getHttpServerRequestBuffer() {
+    int i = getInt( HTTP_SERVER_REQUEST_BUFFER, 16 * 1024 );
+    return i;
+  }
+
+  @Override
+  public int getHttpServerRequestHeaderBuffer() {
+    int i = getInt( HTTP_SERVER_REQUEST_HEADER_BUFFER, 8 * 1024 );
+    return i;
+  }
+
+  @Override
+  public int getHttpServerResponseBuffer() {
+    int i = getInt( HTTP_SERVER_RESPONSE_BUFFER, 32 * 1024 );
+    return i;
+  }
+
+  @Override
+  public int getHttpServerResponseHeaderBuffer() {
+    int i = getInt( HTTP_SERVER_RESPONSE_HEADER_BUFFER, 8 * 1024 );
+    return i;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/43bb06d6/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.groovy
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.groovy
b/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.groovy
new file mode 100644
index 0000000..1902b03
--- /dev/null
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.groovy
@@ -0,0 +1,56 @@
+package org.apache.hadoop.gateway.config.impl
+
+import org.junit.Test
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat
+
+/**
+ * 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.
+ */
+public class GatewayConfigImplTest {
+
+  @Test
+  public void testHttpServerSettings() {
+    GatewayConfigImpl config = new GatewayConfigImpl();
+
+    // Check the defaults.
+    assertThat( config.getHttpServerRequestBuffer(), is( 16*1024 ) );
+    assertThat( config.getHttpServerRequestHeaderBuffer(), is( 8*1024 ) );
+    assertThat( config.getHttpServerResponseBuffer(), is( 32*1024 ) );
+    assertThat( config.getHttpServerResponseHeaderBuffer(), is( 8*1024 ) );
+
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_REQUEST_BUFFER, 32*1024 );
+    assertThat( config.getHttpServerRequestBuffer(), is( 32*1024 ) );
+
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_REQUEST_HEADER_BUFFER, 4*1024 );
+    assertThat( config.getHttpServerRequestHeaderBuffer(), is( 4*1024 ) );
+
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_RESPONSE_BUFFER, 16*1024 );
+    assertThat( config.getHttpServerResponseBuffer(), is( 16*1024 ) );
+
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_RESPONSE_HEADER_BUFFER, 6*1024 );
+    assertThat( config.getHttpServerResponseHeaderBuffer(), is( 6*1024 ) );
+
+    // Restore the defaults.
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_REQUEST_BUFFER, 16*1024 );
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_REQUEST_HEADER_BUFFER, 8*1024 );
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_RESPONSE_BUFFER, 32*1024 );
+    config.setInt( GatewayConfigImpl.HTTP_SERVER_RESPONSE_HEADER_BUFFER, 8*1024 );
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/43bb06d6/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
index 70fabba..7e30b72 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
@@ -111,4 +111,12 @@ public interface GatewayConfig {
 
   int getThreadPoolMax();
 
+  int getHttpServerRequestBuffer();
+
+  int getHttpServerRequestHeaderBuffer();
+
+  int getHttpServerResponseBuffer();
+
+  int getHttpServerResponseHeaderBuffer();
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/43bb06d6/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index cba3f15..37d1f6f 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -268,4 +268,25 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig
{
   public int getThreadPoolMax() {
     return 16;
   }
+
+  @Override
+  public int getHttpServerRequestBuffer() {
+    return 16*1024;
+  }
+
+  @Override
+  public int getHttpServerRequestHeaderBuffer() {
+    return 8*1024;
+  }
+
+  @Override
+  public int getHttpServerResponseBuffer() {
+    return 32*1024;
+  }
+
+  @Override
+  public int getHttpServerResponseHeaderBuffer() {
+    return 8*1024;
+  }
+
 }


Mime
View raw message