knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject knox git commit: KNOX-928 - Support Default Topology Feature and some misc fixes
Date Fri, 26 May 2017 22:22:28 GMT
Repository: knox
Updated Branches:
  refs/heads/master 5022bb43a -> 39a552772


KNOX-928 - Support Default Topology Feature and some misc fixes


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

Branch: refs/heads/master
Commit: 39a552772c7f03fd4af17e14b7460f74f9ab1bbf
Parents: 5022bb4
Author: Sandeep More <more@apache.org>
Authored: Fri May 26 18:22:22 2017 -0400
Committer: Sandeep More <more@apache.org>
Committed: Fri May 26 18:22:22 2017 -0400

----------------------------------------------------------------------
 .../apache/hadoop/gateway/GatewayServer.java    |  22 +--
 .../gateway/filter/DefaultTopologyHandler.java  | 104 -------------
 .../gateway/filter/GatewayHelloFilter.java      |  45 ------
 .../filter/PortMappingHelperHandler.java        |  64 +++++++-
 .../gateway/GatewayPortMappingFailTest.java     | 150 +++++++++++++++++++
 .../gateway/GatewayPortMappingFuncTest.java     |  73 ++++-----
 .../hadoop/gateway/GatewayTestConfig.java       |  10 +-
 7 files changed, 257 insertions(+), 211 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/39a55277/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 0c4d1ea..a379af5 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
@@ -35,7 +35,6 @@ import org.apache.hadoop.gateway.config.impl.GatewayConfigImpl;
 import org.apache.hadoop.gateway.deploy.DeploymentException;
 import org.apache.hadoop.gateway.deploy.DeploymentFactory;
 import org.apache.hadoop.gateway.filter.CorrelationHandler;
-import org.apache.hadoop.gateway.filter.DefaultTopologyHandler;
 import org.apache.hadoop.gateway.filter.PortMappingHelperHandler;
 import org.apache.hadoop.gateway.filter.RequestUpdateHandler;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
@@ -429,10 +428,6 @@ public class GatewayServer {
     final PortMappingHelperHandler portMappingHandler = new PortMappingHelperHandler(config);
     portMappingHandler.setHandler(gzipHandler);
 
-    DefaultTopologyHandler defaultTopoHandler = new DefaultTopologyHandler(
-        config, services, contexts);
-
-
      // If topology to port mapping feature is enabled then we add new Handler {RequestForwardHandler}
      // to the chain, this handler listens on the configured port (in gateway-site.xml)
      // and simply forwards requests to the correct context path.
@@ -460,7 +455,6 @@ public class GatewayServer {
 
     }
 
-    handlers.addHandler(defaultTopoHandler);
     handlers.addHandler(logHandler);
 
     if (config.isWebsocketEnabled()) {      
@@ -502,10 +496,15 @@ public class GatewayServer {
 
     // if topology name is blank which means we have all topologies listening on this port
     if (StringUtils.isBlank(topologyName)) {
-      if (config.getGatewayPortMappings().containsValue(new Integer(port))) {
+      // If we have Default Topology old and new configuration (Port Mapping) throw error.
+      if (config.getGatewayPortMappings().containsValue(new Integer(port))
+          && !StringUtils.isBlank(config.getDefaultTopologyName())) {
         log.portAlreadyInUse(port);
-        throw new IOException(
-            String.format(" Cannot use port %d, it has to be unique. ", port));
+        throw new IOException(String.format(
+            " Please map port %d using either \"gateway.port.mapping.sandbox\" or "
+                + "\"default.app.topology.name\" property, "
+                + "specifying both is not a valid configuration. ",
+            port));
       }
     } else {
       // Topology name is not blank so check amongst other ports if we have a conflict
@@ -533,7 +532,7 @@ public class GatewayServer {
     contexts = new ContextHandlerCollection();
 
      // A map to keep track of current deployments by cluster name.
-    deployments = new ConcurrentHashMap<String, WebAppContext>();
+    deployments = new ConcurrentHashMap<>();
 
     // Start Jetty.
     jetty = new Server( new QueuedThreadPool( config.getThreadPoolMax() ) );
@@ -579,7 +578,8 @@ public class GatewayServer {
     if (config.isGatewayPortMappingEnabled()) {
       for (Map.Entry<String, Integer> entry : topologyPortMap.entrySet()) {
         // Add connector for only valid topologies, i.e. deployed topologies.
-        if(deployedTopologyList.contains(entry.getKey())) {
+        // and NOT for Default Topology listening on standard gateway port.
+        if(deployedTopologyList.contains(entry.getKey()) && (entry.getValue().intValue()
!= config.getGatewayPort()) ) {
           log.createJettyConnector(entry.getKey().toLowerCase(), entry.getValue());
           jetty.addConnector(createConnector(jetty, config, entry.getValue(),
               entry.getKey().toLowerCase()));

http://git-wip-us.apache.org/repos/asf/knox/blob/39a55277/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/DefaultTopologyHandler.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/DefaultTopologyHandler.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/DefaultTopologyHandler.java
deleted file mode 100644
index 2b91b19..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/DefaultTopologyHandler.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- */
-package org.apache.hadoop.gateway.filter;
-
-import java.io.IOException;
-import java.util.Collection;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.hadoop.gateway.GatewayMessages;
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.services.GatewayServices;
-import org.apache.hadoop.gateway.services.topology.TopologyService;
-import org.apache.hadoop.gateway.topology.Topology;
-import org.eclipse.jetty.server.Handler;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.handler.HandlerWrapper;
-
-public class DefaultTopologyHandler extends HandlerWrapper {
-
-  private static final GatewayMessages LOG = MessagesFactory.get(GatewayMessages.class);
-
-  private GatewayConfig config;
-  private GatewayServices services;
-  private String staticRedirectContext = null;
-
-  public DefaultTopologyHandler( GatewayConfig config, GatewayServices services, Handler
delegate ) {
-    if( config == null ) {
-      throw new IllegalArgumentException( "config==null" );
-    }
-    if( services == null ) {
-      throw new IllegalArgumentException( "services==null" );
-    }
-    this.config = config;
-    this.services = services;
-    String defaultTopologyName = config.getDefaultTopologyName();
-    if( defaultTopologyName != null ) {
-      staticRedirectContext = config.getDefaultAppRedirectPath();
-      if( staticRedirectContext != null && staticRedirectContext.trim().isEmpty()
) {
-        staticRedirectContext = null;
-      }
-    }
-    if( staticRedirectContext != null ) {
-      LOG.defaultTopologySetup( defaultTopologyName, staticRedirectContext );
-    }
-    setHandler( delegate );
-  }
-
-  @Override
-  public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse
response ) throws IOException, ServletException {
-    if( !baseRequest.isHandled() ) {
-      String redirectContext = staticRedirectContext;
-      if( redirectContext == null ) {
-        TopologyService topologies = services.getService( GatewayServices.TOPOLOGY_SERVICE
);
-        if( topologies != null ) {
-          Collection<Topology> candidates = topologies.getTopologies();
-          if( candidates != null && candidates.size() == 1 ) {
-            Topology topology = candidates.iterator().next();
-            redirectContext = "/" + config.getGatewayPath() + "/" + topology.getName();
-          }
-        }
-      }
-      if( redirectContext != null ) {
-        String newTarget = redirectContext + target;
-        ForwardedRequest newRequest = new ForwardedRequest( request, newTarget );
-        LOG.defaultTopologyForward( target, newTarget );
-        super.handle( newTarget, baseRequest, newRequest, response );
-      }
-    }
-  }
-
-  static class ForwardedRequest extends HttpServletRequestWrapper {
-
-    private String contextPath;
-
-    public ForwardedRequest( HttpServletRequest request, String contextPath ) {
-      super( request );
-      this.contextPath = contextPath;
-    }
-
-    public String getContextPath() {
-      return contextPath;
-    }
-
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/39a55277/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/GatewayHelloFilter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/GatewayHelloFilter.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/GatewayHelloFilter.java
deleted file mode 100644
index ab56a34..0000000
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/GatewayHelloFilter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- */
-package org.apache.hadoop.gateway.filter;
-
-import java.io.IOException;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-public class GatewayHelloFilter implements Filter {
-
-  @Override
-  public void init( FilterConfig filterConfig ) throws ServletException {
-    System.out.println( "GatewayHelloFilter.init" );
-  }
-
-  @Override
-  public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain
) throws IOException, ServletException {
-    System.out.println( "GatewayHelloFilter.doFilter" );
-    chain.doFilter( request, response );
-  }
-
-  @Override
-  public void destroy() {
-    System.out.println( "GatewayHelloFilter.destroy" );
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/39a55277/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/PortMappingHelperHandler.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/PortMappingHelperHandler.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/PortMappingHelperHandler.java
index ace4c11..ea3efc4 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/PortMappingHelperHandler.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/filter/PortMappingHelperHandler.java
@@ -11,6 +11,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.Map;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -34,6 +35,13 @@ import java.io.IOException;
  * This is a helper handler that adjusts the "target" patch of the request.
  * Used when Topology Port Mapping feature is used.
  * See KNOX-928
+ * <p>
+ * This class also handles the Default Topology Feature
+ * where, any one of the topologies can be set to "default"
+ * and can listen on the standard Knox port (8443) and
+ * will not need /gateway/{topology} context.
+ * Basically Topology Port Mapping for standard port.
+ * Backwards compatible to Default Topology Feature.
  *
  */
 public class PortMappingHelperHandler extends HandlerWrapper {
@@ -43,9 +51,43 @@ public class PortMappingHelperHandler extends HandlerWrapper {
 
   final GatewayConfig config;
 
+  private String defaultTopologyRedirectContext = null;
+
   public PortMappingHelperHandler(final GatewayConfig config) {
 
     this.config = config;
+    //Set up context for default topology feature.
+    String defaultTopologyName = config.getDefaultTopologyName();
+
+    // default topology feature can also be enabled using port mapping feature
+    // config e.g. gateway.port.mapping.{defaultTopologyName}
+
+    if(defaultTopologyName == null && config.getGatewayPortMappings().values().contains(config.getGatewayPort()))
{
+
+      for(final Map.Entry<String, Integer> entry: config.getGatewayPortMappings().entrySet())
{
+
+        if(entry.getValue().intValue() == config.getGatewayPort()) {
+          defaultTopologyRedirectContext = "/" + config.getGatewayPath() + "/" + entry.getKey();
+          break;
+        }
+
+      }
+
+
+    }
+
+    if (defaultTopologyName != null) {
+      defaultTopologyRedirectContext = config.getDefaultAppRedirectPath();
+      if (defaultTopologyRedirectContext != null
+          && defaultTopologyRedirectContext.trim().isEmpty()) {
+        defaultTopologyRedirectContext = null;
+      }
+    }
+    if (defaultTopologyRedirectContext != null) {
+      LOG.defaultTopologySetup(defaultTopologyName,
+          defaultTopologyRedirectContext);
+    }
+
   }
 
   @Override
@@ -53,11 +95,13 @@ public class PortMappingHelperHandler extends HandlerWrapper {
       final HttpServletRequest request, final HttpServletResponse response)
       throws IOException, ServletException {
 
+    String newTarget = target;
+    String baseURI = baseRequest.getUri().toString();
+
     // If Port Mapping feature enabled
     if (config.isGatewayPortMappingEnabled()) {
       int targetIndex;
       String context = "";
-      String baseURI = baseRequest.getUri().toString();
 
       // extract the gateway specific part i.e. {/gatewayName/}
       String originalContextPath = "";
@@ -89,9 +133,23 @@ public class PortMappingHelperHandler extends HandlerWrapper {
         LOG.topologyPortMappingAddContext(target, context + target);
       }
       // Move on to the next handler in chain with updated path
-      super.handle(context + target, baseRequest, request, response);
+      newTarget = context + target;
+    }
+
+    //Backwards compatibility for default topology feature
+    if (defaultTopologyRedirectContext != null && !baseURI
+        .startsWith("/" + config.getGatewayPath())) {
+      newTarget = defaultTopologyRedirectContext + target;
+
+      final RequestUpdateHandler.ForwardedRequest newRequest = new RequestUpdateHandler.ForwardedRequest(
+          request, defaultTopologyRedirectContext, newTarget);
+
+      LOG.defaultTopologyForward(target, newTarget);
+      super.handle(newTarget, baseRequest, newRequest, response);
+
     } else {
-      super.handle(target, baseRequest, request, response);
+
+      super.handle(newTarget, baseRequest, request, response);
     }
 
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/39a55277/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFailTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFailTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFailTest.java
new file mode 100644
index 0000000..6a58fd0
--- /dev/null
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFailTest.java
@@ -0,0 +1,150 @@
+package org.apache.hadoop.gateway;
+
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.hadoop.test.TestUtils;
+import org.apache.hadoop.test.category.ReleaseTest;
+import org.apache.hadoop.test.mock.MockServer;
+import org.apache.http.HttpStatus;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static com.jayway.restassured.RestAssured.given;
+import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
+import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
+
+/**
+ * Test the fail cases for the Port Mapping Feature
+ */
+@Category(ReleaseTest.class)
+public class GatewayPortMappingFailTest {
+
+  // Specifies if the test requests should go through the gateway or directly to the services.
+  // This is frequently used to verify the behavior of the test both with and without the
gateway.
+  private static final boolean USE_GATEWAY = true;
+
+  // Specifies if the test requests should be sent to mock services or the real services.
+  // This is frequently used to verify the behavior of the test both with and without mock
services.
+  private static final boolean USE_MOCK_SERVICES = true;
+
+  private static GatewayFuncTestDriver driver = new GatewayFuncTestDriver();
+
+  private static MockServer masterServer;
+
+  private static int eeriePort;
+
+  /**
+   * Create an instance
+   */
+  public GatewayPortMappingFailTest() {
+    super();
+  }
+
+  /**
+   * Creates a deployment of a gateway instance that all test methods will share.  This method
also creates a
+   * registry of sorts for all of the services that will be used by the test methods.
+   * The createTopology method is used to create the topology file that would normally be
read from disk.
+   * The driver.setupGateway invocation is where the creation of GATEWAY_HOME occurs.
+   * <p/>
+   * This would normally be done once for this suite but the failure tests start affecting
each other depending
+   * on the state the last 'active' url
+   *
+   * @throws Exception Thrown if any failure occurs.
+   */
+  @BeforeClass
+  public static void setup() throws Exception {
+    LOG_ENTER();
+
+    eeriePort = GatewayPortMappingFuncTest.getAvailablePort(1240, 49151);
+
+    ConcurrentHashMap<String, Integer> topologyPortMapping = new ConcurrentHashMap<String,
Integer>();
+    topologyPortMapping.put("eerie", eeriePort);
+
+    masterServer = new MockServer("master", true);
+    GatewayTestConfig config = new GatewayTestConfig();
+    config.setGatewayPath("gateway");
+    config.setTopologyPortMapping(topologyPortMapping);
+
+    driver.setResourceBase(WebHdfsHaFuncTest.class);
+    driver.setupLdap(0);
+
+    driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs", "/eerie/webhdfs", USE_MOCK_SERVICES);
+
+    driver.setupGateway(config, "eerie", GatewayPortMappingFuncTest.createTopology("WEBHDFS",
driver.getLdapUrl(), masterServer.getPort()), USE_GATEWAY);
+
+    LOG_EXIT();
+  }
+
+  @AfterClass
+  public static void cleanup() throws Exception {
+    LOG_ENTER();
+    driver.cleanup();
+    driver.reset();
+    masterServer.reset();
+    LOG_EXIT();
+  }
+
+
+  /**
+   * Fail when trying to use this feature on the standard port.
+   * Here we do not have Default Topology Feature not enabled.
+   *
+   * http://localhost:{gatewayPort}/webhdfs/v1
+   *
+   * @throws IOException
+   */
+  @Test(timeout = TestUtils.MEDIUM_TIMEOUT )
+  public void testMultiPortOperationFail() throws IOException {
+    LOG_ENTER();
+    final String url = "http://localhost:" + driver.getGatewayPort() + "/webhdfs" ;
+
+    String password = "hdfs-password";
+    String username = "hdfs";
+
+    masterServer.expect()
+        .method("GET")
+        .pathInfo("/webhdfs/v1/")
+        .queryParam("op", "LISTSTATUS")
+        .queryParam("user.name", username)
+        .respond()
+        .status(HttpStatus.SC_OK)
+        .content(driver.getResourceBytes("webhdfs-liststatus-success.json"))
+        .contentType("application/json");
+
+    given()
+        .auth().preemptive().basic(username, password)
+        .header("X-XSRF-Header", "jksdhfkhdsf")
+        .queryParam("op", "LISTSTATUS")
+        .expect()
+        //.log().ifError()
+        .statusCode(HttpStatus.SC_NOT_FOUND)
+        //.content("FileStatuses.FileStatus[0].pathSuffix", is("app-logs"))
+        .when().get(url + "/v1/");
+    masterServer.isEmpty();
+
+    LOG_EXIT();
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/39a55277/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFuncTest.java
index 41e583b..d74ba63 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayPortMappingFuncTest.java
@@ -25,7 +25,9 @@ import org.apache.hadoop.test.category.ReleaseTest;
 import org.apache.hadoop.test.mock.MockServer;
 import org.apache.http.HttpStatus;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -57,7 +59,7 @@ public class GatewayPortMappingFuncTest {
 
   private static MockServer masterServer;
 
-  private int eeriePort;
+  private static int eeriePort;
 
   public GatewayPortMappingFuncTest() {
     super();
@@ -74,8 +76,8 @@ public class GatewayPortMappingFuncTest {
    *
    * @throws Exception Thrown if any failure occurs.
    */
-  @Before
-  public void setup() throws Exception {
+  @BeforeClass
+  public static void setup() throws Exception {
     LOG_ENTER();
 
     eeriePort = getAvailablePort(1240, 49151);
@@ -88,18 +90,21 @@ public class GatewayPortMappingFuncTest {
     config.setGatewayPath("gateway");
     config.setTopologyPortMapping(topologyPortMapping);
 
+    // Enable default topology
+    config.setDefaultTopologyName("eerie");
+
     driver.setResourceBase(WebHdfsHaFuncTest.class);
     driver.setupLdap(0);
 
     driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs", "/eerie/webhdfs", USE_MOCK_SERVICES);
 
-    driver.setupGateway(config, "eerie", createTopology("WEBHDFS"), USE_GATEWAY);
+    driver.setupGateway(config, "eerie", createTopology("WEBHDFS", driver.getLdapUrl(), masterServer.getPort()),
USE_GATEWAY);
 
     LOG_EXIT();
   }
 
-  @After
-  public void cleanup() throws Exception {
+  @AfterClass
+  public static void cleanup() throws Exception {
     LOG_ENTER();
     driver.cleanup();
     driver.reset();
@@ -121,69 +126,45 @@ public class GatewayPortMappingFuncTest {
   }
 
   /**
-   * Test the multi port scenario.
+   * Test the Default Topology Feature, activated by property
+   * "default.app.topology.name"
    *
-   * http://localhost:{eeriePort}/webhdfs/v1
+   * http://localhost:{eeriePort}/gateway/eerie/webhdfs/v1
    *
    * @throws IOException
    */
   @Test(timeout = TestUtils.MEDIUM_TIMEOUT )
-  public void testMultiPortOperation() throws IOException {
+  public void testDefaultTopologyFeature() throws IOException {
     LOG_ENTER();
-    test("http://localhost:" + eeriePort + "/webhdfs" );
+    test("http://localhost:" + driver.getGatewayPort() + "/webhdfs" );
     LOG_EXIT();
   }
 
   /**
-   * Test the multi port scenario when gateway path is included.
+   * Test the multi port scenario.
    *
-   * http://localhost:{eeriePort}/gateway/eerie/webhdfs/v1
+   * http://localhost:{eeriePort}/webhdfs/v1
    *
    * @throws IOException
    */
   @Test(timeout = TestUtils.MEDIUM_TIMEOUT )
-  public void testMultiPortWithGatewayPath() throws IOException {
+  public void testMultiPortOperation() throws IOException {
     LOG_ENTER();
-    test("http://localhost:" + eeriePort + "/gateway/eerie" + "/webhdfs" );
+    test("http://localhost:" + eeriePort + "/webhdfs" );
     LOG_EXIT();
   }
 
   /**
-   * Fail when trying to use this feature on the standard port.
+   * Test the multi port scenario when gateway path is included.
    *
-   * http://localhost:{gatewayPort}/webhdfs/v1
+   * http://localhost:{eeriePort}/gateway/eerie/webhdfs/v1
    *
    * @throws IOException
    */
   @Test(timeout = TestUtils.MEDIUM_TIMEOUT )
-  public void testMultiPortOperationFail() throws IOException {
+  public void testMultiPortWithGatewayPath() throws IOException {
     LOG_ENTER();
-    final String url = "http://localhost:" + driver.getGatewayPort() + "/webhdfs" ;
-
-    String password = "hdfs-password";
-    String username = "hdfs";
-
-    masterServer.expect()
-        .method("GET")
-        .pathInfo("/webhdfs/v1/")
-        .queryParam("op", "LISTSTATUS")
-        .queryParam("user.name", username)
-        .respond()
-        .status(HttpStatus.SC_OK)
-        .content(driver.getResourceBytes("webhdfs-liststatus-success.json"))
-        .contentType("application/json");
-
-    given()
-        .auth().preemptive().basic(username, password)
-        .header("X-XSRF-Header", "jksdhfkhdsf")
-        .queryParam("op", "LISTSTATUS")
-        .expect()
-        //.log().ifError()
-        .statusCode(HttpStatus.SC_NOT_FOUND)
-        //.content("FileStatuses.FileStatus[0].pathSuffix", is("app-logs"))
-        .when().get(url + "/v1/");
-    masterServer.isEmpty();
-
+    test("http://localhost:" + eeriePort + "/gateway/eerie" + "/webhdfs" );
     LOG_EXIT();
   }
 
@@ -221,7 +202,7 @@ public class GatewayPortMappingFuncTest {
    *
    * @return A populated XML structure for a topology file.
    */
-  private static XMLTag createTopology(final String role) {
+  public static XMLTag createTopology(final String role, final String ldapURL, final int
gatewayPort ) {
     XMLTag xml = XMLDoc.newDocument(true)
         .addRoot("topology")
         .addTag("gateway")
@@ -244,7 +225,7 @@ public class GatewayPortMappingFuncTest {
         .addTag("value").addText("uid={0},ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.url")
-        .addTag("value").addText(driver.getLdapUrl()).gotoParent()
+        .addTag("value").addText(ldapURL).gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.authenticationMechanism")
         .addTag("value").addText("simple").gotoParent()
@@ -272,7 +253,7 @@ public class GatewayPortMappingFuncTest {
         .gotoRoot()
         .addTag("service")
         .addTag("role").addText(role)
-        .addTag("url").addText("http://localhost:" + masterServer.getPort() + "/webhdfs")
+        .addTag("url").addText("http://localhost:" + gatewayPort + "/webhdfs")
         .gotoRoot();
     return xml;
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/39a55277/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 dd29d33..cff7924 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
@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.gateway;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.gateway.config.GatewayConfig;
 
@@ -199,8 +200,13 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig
{
    */
   @Override
   public String getDefaultAppRedirectPath() {
-    // TODO Auto-generated method stub
-    return "/gateway/sandbox";
+
+    if(StringUtils.isBlank(this.defaultTopologyName)) {
+      return "/gateway/sandbox";
+    } else {
+      return "/gateway/"+this.defaultTopologyName;
+    }
+
   }
 
   /* (non-Javadoc)


Mime
View raw message