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-596: Add diagnostics to topology depoloyment
Date Thu, 10 Sep 2015 21:54:26 GMT
Repository: knox
Updated Branches:
  refs/heads/master 0450f8420 -> ccfe33d5d


KNOX-596: Add diagnostics to topology depoloyment


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

Branch: refs/heads/master
Commit: ccfe33d5dea846a6255639945269163ee47d2079
Parents: 0450f84
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Thu Sep 10 17:49:38 2015 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Thu Sep 10 17:49:38 2015 -0400

----------------------------------------------------------------------
 CHANGES                                         |  1 +
 .../apache/hadoop/gateway/GatewayMessages.java  | 18 +++++++++++
 .../gateway/deploy/DeploymentFactory.java       | 32 ++++++++++++++++++++
 .../hadoop/gateway/GatewayDeployFuncTest.java   |  9 +++---
 4 files changed, 56 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/ccfe33d5/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 553755e..dc44187 100644
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,7 @@ Release Notes - Apache Knox - Version 0.7.0
     * [KNOX-564] - Topology deployment fails for no configured providers
     * [KNOX-590] - CLI sys-user-auth-test and user-auth-test have improved messages and work
for more Shiro configs
     * [KNOX-597] - Improve diagnostic logging of HTTP traffic
+    * [KNOX-596] - Add diagnostics to topology depoloyment
 
 ** Bug
     * [KNOX-554] - Fixed support for gateway.path change + added support for X-Forward-*
headers in admin topology API.

http://git-wip-us.apache.org/repos/asf/knox/blob/ccfe33d5/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index 88d1294..0069f7a 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -332,6 +332,24 @@ public interface GatewayMessages {
   @Message( level = MessageLevel.INFO, text = "Computed roles/groups: {0} for principal:
{1}" )
   void lookedUpUserRoles(Set<String> roleNames, String userName);
 
+  @Message( level = MessageLevel.DEBUG, text = "Initialize provider: {1}/{0}" )
+  void initializeProvider( String name, String role );
+
+  @Message( level = MessageLevel.DEBUG, text = "Initialize service: {1}/{0}" )
+  void initializeService( String name, String role );
+
+  @Message( level = MessageLevel.DEBUG, text = "Contribute provider: {1}/{0}" )
+  void contributeProvider( String name, String role );
+
+  @Message( level = MessageLevel.DEBUG, text = "Contribute service: {1}/{0}" )
+  void contributeService( String name, String role );
+
+  @Message( level = MessageLevel.DEBUG, text = "Finalize provider: {1}/{0}" )
+  void finalizeProvider( String name, String role );
+
+  @Message( level = MessageLevel.DEBUG, text = "Finalize service: {1}/{0}" )
+  void finalizeService( String name, String role );
+
   @Message( level = MessageLevel.INFO, text = "Configured services directory is {0}" )
   void usingServicesDirectory(String path);
 

http://git-wip-us.apache.org/repos/asf/knox/blob/ccfe33d5/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 026aa53..67af3ab 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
@@ -39,6 +39,9 @@ import org.jboss.shrinkwrap.descriptor.api.Descriptors;
 import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
 import org.jboss.shrinkwrap.descriptor.api.webcommon30.ServletType;
 
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
 import java.beans.Statement;
 import java.io.File;
 import java.io.IOException;
@@ -94,9 +97,32 @@ public abstract class DeploymentFactory {
       // if this is the default topology then add the forwarding webapp as well
       context = deployDefaultTopology(config, topology);
     }
+    storeTopology( context, topology );
     return context.getWebArchive();
   }
 
+  private static void storeTopology( DeploymentContext context, Topology topology ) {
+    StringWriter writer = new StringWriter();
+    String xml;
+    try {
+      Map<String,Object> properties = new HashMap<String,Object>(2);
+      properties.put( "eclipselink-oxm-xml", "org/apache/hadoop/gateway/topology/topology_binding-xml.xml"
);
+      properties.put( "eclipselink.media-type", "application/xml" );
+      JAXBContext jaxbContext = JAXBContext.newInstance( Topology.class.getPackage().getName(),
Topology.class.getClassLoader() , properties );
+      Marshaller marshaller = jaxbContext.createMarshaller();
+      marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
+      marshaller.marshal( topology, writer );
+      writer.close();
+      xml = writer.toString();
+    } catch (IOException e) {
+      throw new DeploymentException( "Failed to marshall topology.", e );
+    } catch (JAXBException e) {
+      throw new DeploymentException( "Failed to marshall topology.", e );
+    }
+    StringAsset asset = new StringAsset( xml );
+    context.getWebArchive().addAsWebInfResource( asset, "topology.xml" );
+  }
+
   private static DeploymentContext deployDefaultTopology(GatewayConfig config,
       Topology topology) {
     // this is the "default" topology which does some specialized
@@ -278,6 +304,7 @@ public abstract class DeploymentFactory {
       ProviderDeploymentContributor contributor = getProviderContributor( providers, provider.getRole(),
provider.getName() );
       if( contributor != null && provider.isEnabled() ) {
         try {
+          log.contributeProvider( provider.getName(), provider.getRole() );
           contributor.contributeProvider( context, provider );
         } catch( Exception e ) {
           // Maybe it makes sense to throw exception
@@ -290,6 +317,7 @@ public abstract class DeploymentFactory {
       ServiceDeploymentContributor contributor = getServiceContributor( service.getRole(),
service.getName(), service.getVersion() );
       if( contributor != null ) {
         try {
+          log.contributeService( service.getName(), service.getRole() );
           contributor.contributeService( context, service );
           if (gatewayServices != null) {
             ServiceRegistry sr = gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
@@ -298,6 +326,7 @@ public abstract class DeploymentFactory {
               sr.registerService(regCode, topology.getName(), service.getRole(), service.getUrls()
);
             }
           }
+          log.initializeProvider( contributor.getName(), contributor.getRole() );
         } catch( Exception e ) {
           // Maybe it makes sense to throw exception
           log.failedToContributeService( service.getName(), service.getRole(), e );
@@ -365,17 +394,20 @@ public abstract class DeploymentFactory {
       for( String role : providers.keySet() ) {
         for( ProviderDeploymentContributor contributor : providers.get( role ) ) {
           try {
+            log.finalizeProvider( contributor.getName(), contributor.getRole() );
             contributor.finalizeContribution( context );
           } catch( Exception e ) {
             // Maybe it makes sense to throw exception
             log.failedToFinalizeContribution( e );
             throw new DeploymentException("Failed to finalize contribution.", e);
           }
+          log.initializeService( contributor.getName(), contributor.getRole() );
         }
       }
       for( String role : services.keySet() ) {
         for( ServiceDeploymentContributor contributor : services.get( role ) ) {
           try {
+            log.finalizeService( contributor.getName(), contributor.getRole() );
             contributor.finalizeContribution( context );
           } catch( Exception e ) {
             // Maybe it makes sense to throw exception

http://git-wip-us.apache.org/repos/asf/knox/blob/ccfe33d5/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
index fc2fd70..7a907c7 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
@@ -205,6 +205,7 @@ public class GatewayDeployFuncTest {
   @Test( timeout = 30*1000 )
   public void testDeployRedeployUndeploy() throws InterruptedException, IOException {
     long sleep = 200;
+    int numFilesInWar = 5;
     String username = "guest";
     String password = "guest-password";
     String serviceUrl =  clusterUrl + "/test-service-path/test-service-resource";
@@ -212,7 +213,7 @@ public class GatewayDeployFuncTest {
 
     File topoDir = new File( config.getGatewayTopologyDir() );
     File deployDir = new File( config.getGatewayDeploymentDir() );
-    File warDir = null;
+    File warDir;
 
     // Make sure deployment directory is empty.
     assertThat( topoDir.listFiles().length, is( 0 ) );
@@ -223,7 +224,7 @@ public class GatewayDeployFuncTest {
 
     warDir = waitForFiles( deployDir, "test-cluster.war\\.[0-9A-Fa-f]+", 1, 0, sleep );
     for( File webInfDir : warDir.listFiles() ) {
-      waitForFiles( webInfDir, ".*", 4, 0, sleep );
+      waitForFiles( webInfDir, ".*", numFilesInWar, 0, sleep );
     }
     waitForAccess( serviceUrl, username, password, sleep );
 
@@ -240,7 +241,7 @@ public class GatewayDeployFuncTest {
     // Check to make sure there are two war directories with the same root.
     warDir = waitForFiles( deployDir, "test-cluster.war\\.[0-9A-Fa-f]+", 2, 1, sleep );
     for( File webInfDir : warDir.listFiles() ) {
-      waitForFiles( webInfDir, ".*", 4, 0, sleep );
+      waitForFiles( webInfDir, ".*", numFilesInWar, 0, sleep );
     }
     waitForAccess( serviceUrl, username, password, sleep );
 
@@ -257,7 +258,7 @@ public class GatewayDeployFuncTest {
     // Check to make sure there are two war directories with the same root.
     warDir = waitForFiles( deployDir, "test-cluster.war\\.[0-9A-Fa-f]+", 3, 2, sleep );
     for( File webInfDir : warDir.listFiles() ) {
-      waitForFiles( webInfDir, ".*", 4, 0, sleep );
+      waitForFiles( webInfDir, ".*", numFilesInWar, 0, sleep );
     }
     waitForAccess( serviceUrl, username, password, sleep );
 


Mime
View raw message