knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject git commit: KNOX-361 - implicitly deploy the _default app for forwarding to the default topology
Date Fri, 02 May 2014 15:41:44 GMT
Repository: knox
Updated Branches:
  refs/heads/master 712c80ef8 -> e5cb26aef


KNOX-361 - implicitly deploy the _default app for forwarding to the default topology

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

Branch: refs/heads/master
Commit: e5cb26aef001931e56792486bafbe19599643547
Parents: 712c80e
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Fri May 2 11:41:20 2014 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Fri May 2 11:41:20 2014 -0400

----------------------------------------------------------------------
 .../apache/hadoop/gateway/GatewayServer.java    | 82 +++++++++++---------
 .../gateway/config/impl/GatewayConfigImpl.java  |  2 +-
 .../gateway/deploy/DeploymentFactory.java       | 25 +++---
 .../hadoop/gateway/GatewayGlobalConfigTest.java |  2 +-
 4 files changed, 61 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/e5cb26ae/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 651cff6..c9c5717 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
@@ -371,7 +371,7 @@ public class GatewayServer {
     errorHandler.setShowStacks(false);
     WebAppContext context = new WebAppContext();
     context.setDefaultsDescriptor( null );
-    if (!name.equals(config.getDefaultTopologyName())) {
+    if (!name.equals("_default")) {
       context.setContextPath( "/" + config.getGatewayPath() + "/" + name );
     }
     else {
@@ -416,46 +416,58 @@ public class GatewayServer {
           Topology topology = event.getTopology();
           File deployDir = calculateAbsoluteDeploymentsDir();
           if( event.getType().equals( TopologyEvent.Type.DELETED ) ) {
-            File[] files = deployDir.listFiles( new WarDirFilter( topology.getName() + "\\.war\\.[0-9A-Fa-f]+"
) );
-            if( files != null ) {
-              for( File file : files ) {
-                auditor.audit( Action.UNDEPLOY, topology.getName(), ResourceType.TOPOLOGY,
ActionOutcome.UNAVAILABLE );
-                log.deletingDeployment( file.getAbsolutePath() );
-                internalUndeploy( topology );
-                FileUtils.deleteQuietly( file );
-              }
-            }
+            handleDeleteDeployment(topology, deployDir);
           } else {
-            try {
-              File warDir = calculateDeploymentDir( topology );
-              if( !warDir.exists() ) {
-                auditor.audit( Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY,
ActionOutcome.UNAVAILABLE );
-                log.deployingTopology( topology.getName(), warDir.getAbsolutePath() );
-                internalUndeploy( topology ); // KNOX-152
-                WebArchive war = null;
-                war = DeploymentFactory.createDeployment( config, topology );
-                if( !deployDir.exists() ) {
-                  deployDir.mkdirs();
-                }
-                File tmp = war.as( ExplodedExporter.class ).exportExploded( deployDir, warDir.getName()
+ ".tmp" );
-                tmp.renameTo( warDir );
-                internalDeploy( topology, warDir );
-                //log.deployedTopology( topology.getName());
-              } else {
-                auditor.audit( Action.REDEPLOY, topology.getName(), ResourceType.TOPOLOGY,
ActionOutcome.UNAVAILABLE );
-                log.redeployingTopology( topology.getName(), warDir.getAbsolutePath() );
-                internalDeploy( topology, warDir );
-                //log.redeployedTopology( topology.getName() );
-              }
-            } catch( Throwable e ) {
-              auditor.audit( Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE
);
-              log.failedToDeployTopology( topology.getName(), e );
-            }
+            handleCreateDeployment(topology, deployDir);
           }
         }
       }
     }
 
+    private void handleDeleteDeployment(Topology topology, File deployDir) {
+      File[] files = deployDir.listFiles( new WarDirFilter( topology.getName() + "\\.war\\.[0-9A-Fa-f]+"
) );
+      if( files != null ) {
+        for( File file : files ) {
+          auditor.audit( Action.UNDEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.UNAVAILABLE
);
+          log.deletingDeployment( file.getAbsolutePath() );
+          internalUndeploy( topology );
+          FileUtils.deleteQuietly( file );
+        }
+      }
+    }
+
+    private void handleCreateDeployment(Topology topology, File deployDir) {
+      try {
+        File warDir = calculateDeploymentDir( topology );
+        if( !warDir.exists() ) {
+          auditor.audit( Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.UNAVAILABLE
);
+          log.deployingTopology( topology.getName(), warDir.getAbsolutePath() );
+          internalUndeploy( topology ); // KNOX-152
+          WebArchive war = null;
+          war = DeploymentFactory.createDeployment( config, topology );
+          if( !deployDir.exists() ) {
+            deployDir.mkdirs();
+          }
+          File tmp = war.as( ExplodedExporter.class ).exportExploded( deployDir, warDir.getName()
+ ".tmp" );
+          tmp.renameTo( warDir );
+          internalDeploy( topology, warDir );
+          //log.deployedTopology( topology.getName());
+          if (topology.getName().equals(config.getDefaultTopologyName())) {
+            topology.setName("_default");
+            handleCreateDeployment(topology, deployDir);
+          }
+        } else {
+          auditor.audit( Action.REDEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.UNAVAILABLE
);
+          log.redeployingTopology( topology.getName(), warDir.getAbsolutePath() );
+          internalDeploy( topology, warDir );
+          //log.redeployedTopology( topology.getName() );
+        }
+      } catch( Throwable e ) {
+        auditor.audit( Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE
);
+        log.failedToDeployTopology( topology.getName(), e );
+      }
+    }
+
   }
 
   private static File calculateAbsoluteTopologiesDir( GatewayConfig config ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/e5cb26ae/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 d7aab45..c446b20 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
@@ -67,7 +67,7 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   private static final String DEFAULT_APP_REDIRECT_PATH_PARAM = "default.app.redirect.path";
   private static final String DEFAULT_APP_REDIRECT_PATH = "/sandbox";
   private static final String GATEWAY_DEFAULT_TOPOLOGY_NAME_PARAM = "default.app.topology.name";
-  private static final String GATEWAY_DEFAULT_TOPOLOGY_NAME = "_default";
+  private static final String GATEWAY_DEFAULT_TOPOLOGY_NAME = "sandbox";
 
   private static GatewayMessages log = MessagesFactory.get( GatewayMessages.class );
 

http://git-wip-us.apache.org/repos/asf/knox/blob/e5cb26ae/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
index 82d7689..99ce32c 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
@@ -76,15 +76,14 @@ public abstract class DeploymentFactory {
 
   public static WebArchive createDeployment( GatewayConfig config, Topology topology ) {
     DeploymentContext context = null;
-    if (!config.getDefaultTopologyName().equals(topology.getName())) {
-      Map<String,List<ProviderDeploymentContributor>> providers = selectContextProviders(
topology );
-      Map<String,List<ServiceDeploymentContributor>> services = selectContextServices(
topology );
-      context = createDeploymentContext( config, topology, providers, services );
-      initialize( context, providers, services );
-      contribute( context, providers, services );
-      finalize( context, providers, services );
-    }
-    else {
+    Map<String,List<ProviderDeploymentContributor>> providers = selectContextProviders(
topology );
+    Map<String,List<ServiceDeploymentContributor>> services = selectContextServices(
topology );
+    context = createDeploymentContext( config, topology.getName(), topology, providers, services
);
+    initialize( context, providers, services );
+    contribute( context, providers, services );
+    finalize( context, providers, services );
+    if (topology.getName().equals("_default")) {
+      // if this is the default topology then add the forwarding webapp as well
       context = deployDefaultTopology(config, topology);
     }
     return context.getWebArchive();
@@ -99,7 +98,7 @@ public abstract class DeploymentFactory {
     DeploymentContext context;
     Map<String,List<ProviderDeploymentContributor>> providers = new HashMap<String,List<ProviderDeploymentContributor>>();
     Map<String,List<ServiceDeploymentContributor>> services = new HashMap<String,List<ServiceDeploymentContributor>>();
-    context = createDeploymentContext( config, topology, providers, services);
+    context = createDeploymentContext( config, "forward", topology, providers, services);
     WebAppDescriptor wad = context.getWebAppDescriptor();
     String servletName = context.getTopology().getName();
     String servletClass = GatewayForwardingServlet.class.getName();
@@ -108,16 +107,16 @@ public abstract class DeploymentFactory {
     ServletType<WebAppDescriptor> servlet = findServlet( context, context.getTopology().getName()
);
     servlet.createInitParam()
       .paramName( DEFAULT_APP_REDIRECT_CONTEXT_PATH )
-    .  paramValue( config.getDefaultAppRedirectPath() );
+      .paramValue( config.getDefaultAppRedirectPath() );
     writeDeploymentDescriptor(context);
     return context;
   }
 
   private static DeploymentContext createDeploymentContext(
-      GatewayConfig config, Topology topology,
+      GatewayConfig config, String archiveName, Topology topology,
       Map<String,List<ProviderDeploymentContributor>> providers,
       Map<String,List<ServiceDeploymentContributor>> services ) {
-    WebArchive webArchive = ShrinkWrap.create( WebArchive.class, topology.getName() );
+    WebArchive webArchive = ShrinkWrap.create( WebArchive.class, archiveName );
     WebAppDescriptor webAppDesc = Descriptors.create( WebAppDescriptor.class );
     GatewayDescriptor gateway = GatewayDescriptorFactory.create();
     DeploymentContext context = new DeploymentContextImpl(

http://git-wip-us.apache.org/repos/asf/knox/blob/e5cb26ae/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
b/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
index 7abb043..27b8207 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
@@ -64,7 +64,7 @@ public class GatewayGlobalConfigTest {
   @Test
   public void testDefaultTopologyName() {
     GatewayConfig config = new GatewayConfigImpl();
-    assertThat( config.getDefaultTopologyName(), is( "_default" ) );
+    assertThat( config.getDefaultTopologyName(), is( "sandbox" ) );
   }
 
   @Test


Mime
View raw message