knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject [19/24] knox git commit: Added versions to service definitions for deployment and topology KNOX-481
Date Fri, 30 Jan 2015 02:03:57 GMT
Added versions to service definitions for deployment and topology KNOX-481


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

Branch: refs/heads/KNOX-481
Commit: d4812d645651bbd2cfb620222c9b6495b54e403c
Parents: bb06e16
Author: Sumit Gupta <sumit@apache.org>
Authored: Tue Jan 27 10:56:37 2015 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Thu Jan 29 16:51:04 2015 -0500

----------------------------------------------------------------------
 .../gateway/deploy/DeploymentFactory.java       | 109 ++++++++++---------
 .../ServiceDefinitionDeploymentContributor.java |   6 +
 2 files changed, 62 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/d4812d64/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 9dfb808..48fd8f0 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
@@ -19,18 +19,17 @@ package org.apache.hadoop.gateway.deploy;
 
 import org.apache.hadoop.gateway.GatewayMessages;
 import org.apache.hadoop.gateway.GatewayForwardingServlet;
-import org.apache.hadoop.gateway.GatewayResources;
 import org.apache.hadoop.gateway.GatewayServlet;
 import org.apache.hadoop.gateway.config.GatewayConfig;
 import org.apache.hadoop.gateway.descriptor.GatewayDescriptor;
 import org.apache.hadoop.gateway.descriptor.GatewayDescriptorFactory;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
 import org.apache.hadoop.gateway.services.GatewayServices;
 import org.apache.hadoop.gateway.services.registry.ServiceRegistry;
 import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
 import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.topology.Version;
 import org.apache.hadoop.gateway.util.ServiceDefinitionsLoader;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.asset.Asset;
@@ -44,26 +43,16 @@ import java.beans.Statement;
 import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
-import java.util.LinkedHashMap;
+import java.util.*;
 
 public abstract class DeploymentFactory {
 
   private static final String DEFAULT_APP_REDIRECT_CONTEXT_PATH = "redirectTo";
   private static final String STACKS_SERVICES_DIRECTORY = "services";
-  private static GatewayResources res = ResourcesFactory.get( GatewayResources.class );
   private static GatewayMessages log = MessagesFactory.get( GatewayMessages.class );
   private static GatewayServices gatewayServices = null;
 
-  //private static Set<ServiceDeploymentContributor> SERVICE_CONTRIBUTORS;
-  private static Map<String,Map<String,ServiceDeploymentContributor>> SERVICE_CONTRIBUTOR_MAP;
+  private static Map<String,Map<String,Map<Version, ServiceDeploymentContributor>>>
SERVICE_CONTRIBUTOR_MAP;
   static {
     loadServiceContributors();
   }
@@ -73,7 +62,7 @@ public abstract class DeploymentFactory {
   static {
     loadProviderContributors();
   }
-  
+
   public static void setGatewayServices(GatewayServices services) {
     DeploymentFactory.gatewayServices = services;
   }
@@ -84,7 +73,7 @@ public abstract class DeploymentFactory {
     String stacks = config.getGatewayStacksDir();
     File stacksDir = new File(stacks, STACKS_SERVICES_DIRECTORY);
     Set<ServiceDeploymentContributor> deploymentContributors = ServiceDefinitionsLoader.loadServiceDefinitions(stacksDir);
-    addServiceDeploymentContributors(SERVICE_CONTRIBUTOR_MAP, deploymentContributors.iterator());
+    addServiceDeploymentContributors(deploymentContributors.iterator());
 
     Map<String,List<ProviderDeploymentContributor>> providers = selectContextProviders(
topology );
     Map<String,List<ServiceDeploymentContributor>> services = selectContextServices(
topology );
@@ -196,7 +185,7 @@ public abstract class DeploymentFactory {
         = new HashMap<String,List<ServiceDeploymentContributor>>();
     for( Service service : topology.getServices() ) {
       String role = service.getRole();
-      ServiceDeploymentContributor contributor = getServiceContributor( role, service.getName()
);
+      ServiceDeploymentContributor contributor = getServiceContributor( role, service.getName(),
service.getVersion() );
       if( contributor != null ) {
         List<ServiceDeploymentContributor> list = defaults.get( role );
         if( list == null ) {
@@ -252,12 +241,12 @@ public abstract class DeploymentFactory {
       }
     }
   }
-  
+
   private static void injectServices(Object contributor) {
     if (gatewayServices != null) {
       Statement stmt = null;
       for(String serviceName : gatewayServices.getServiceNames()) {
-        
+
         try {
           // TODO: this is just a temporary injection solution
           // TODO: test for the existence of the setter before attempting it
@@ -293,12 +282,12 @@ public abstract class DeploymentFactory {
       }
     }
     for( Service service : topology.getServices() ) {
-      ServiceDeploymentContributor contributor = getServiceContributor( service.getRole(),
null );
+      ServiceDeploymentContributor contributor = getServiceContributor( service.getRole(),
service.getName(), service.getVersion() );
       if( contributor != null ) {
         try {
           contributor.contributeService( context, service );
           if (gatewayServices != null) {
-            ServiceRegistry sr = (ServiceRegistry) gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
+            ServiceRegistry sr = gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
             if (sr != null) {
               String regCode = sr.getRegistrationCode(topology.getName());
               sr.registerService(regCode, topology.getName(), service.getRole(), service.getUrls()
);
@@ -326,14 +315,22 @@ public abstract class DeploymentFactory {
     return contributor;
   }
 
-  public static ServiceDeploymentContributor getServiceContributor( String role, String name
) {
+  public static ServiceDeploymentContributor getServiceContributor( String role, String name,
Version version ) {
     ServiceDeploymentContributor contributor = null;
-    Map<String,ServiceDeploymentContributor> nameMap = SERVICE_CONTRIBUTOR_MAP.get(
role );
-    if( nameMap != null ) {
-      if( name == null ) {
-        contributor = nameMap.values().iterator().next();
-      } else if ( !nameMap.isEmpty() ) {
-        contributor = nameMap.get( name );
+    Map<String,Map<Version, ServiceDeploymentContributor>> nameMap = SERVICE_CONTRIBUTOR_MAP.get(
role );
+    if( nameMap != null && !nameMap.isEmpty()) {
+      Map<Version, ServiceDeploymentContributor> versionMap = null;
+      if ( name == null ) {
+        versionMap = nameMap.values().iterator().next();
+      } else {
+        versionMap = nameMap.get( name );
+      }
+      if ( versionMap != null && !versionMap.isEmpty()) {
+        if( version == null ) {
+          contributor = ((TreeMap<Version, ServiceDeploymentContributor>) versionMap).firstEntry().getValue();
+        } else {
+          contributor = versionMap.get( version );
+        }
       }
     }
     return contributor;
@@ -404,19 +401,16 @@ public abstract class DeploymentFactory {
       }
     }
     return null;
-  }  
-  
-  private static void loadServiceContributors() {
-    Map<String,Map<String,ServiceDeploymentContributor>> roleMap
-        = new HashMap<String,Map<String,ServiceDeploymentContributor>>();
+  }
 
+  private static void loadServiceContributors() {
+    SERVICE_CONTRIBUTOR_MAP = new HashMap<String, Map<String, Map<Version, ServiceDeploymentContributor>>>();
     ServiceLoader<ServiceDeploymentContributor> loader = ServiceLoader.load( ServiceDeploymentContributor.class
);
     Iterator<ServiceDeploymentContributor> contributors = loader.iterator();
-     addServiceDeploymentContributors(roleMap, contributors);
-     SERVICE_CONTRIBUTOR_MAP = roleMap;
+    addServiceDeploymentContributors(contributors);
   }
 
-   private static void addServiceDeploymentContributors(Map<String, Map<String, ServiceDeploymentContributor>>
roleMap, Iterator<ServiceDeploymentContributor> contributors) {
+   private static void addServiceDeploymentContributors(Iterator<ServiceDeploymentContributor>
contributors) {
       while( contributors.hasNext() ) {
         ServiceDeploymentContributor contributor = contributors.next();
         if( contributor.getName() == null ) {
@@ -427,12 +421,21 @@ public abstract class DeploymentFactory {
           log.ignoringServiceContributorWithMissingRole( contributor.getClass().getName()
);
           continue;
         }
-        Map nameMap = roleMap.get( contributor.getRole() );
+        if( contributor.getVersion() == null ) {
+          log.ignoringServiceContributorWithMissingVersion(contributor.getClass().getName());
+          continue;
+        }
+        Map<String,Map<Version, ServiceDeploymentContributor>> nameMap = SERVICE_CONTRIBUTOR_MAP.get(
contributor.getRole() );
         if( nameMap == null ) {
-          nameMap = new HashMap<String,ServiceDeploymentContributor>();
-          roleMap.put( contributor.getRole(), nameMap );
+          nameMap = new HashMap<String,Map<Version, ServiceDeploymentContributor>>();
+          SERVICE_CONTRIBUTOR_MAP.put( contributor.getRole(), nameMap );
+        }
+        Map<Version, ServiceDeploymentContributor> versionMap = nameMap.get(contributor.getName());
+        if (versionMap == null) {
+          versionMap = new TreeMap<Version, ServiceDeploymentContributor>();
+          nameMap.put(contributor.getName(), versionMap);
         }
-        nameMap.put( contributor.getName(), contributor );
+        versionMap.put( contributor.getVersion(), contributor );
       }
    }
 
@@ -479,18 +482,18 @@ public abstract class DeploymentFactory {
     return contributor;
   }
 
-  static ServiceDeploymentContributor getServiceContributor(
-      Map<String,List<ServiceDeploymentContributor>> services, String role, String
name ) {
-    ServiceDeploymentContributor contributor = null;
-    if( name == null ) {
-      List<ServiceDeploymentContributor> list = services.get( role );
-      if( !list.isEmpty() ) {
-        contributor = list.get( 0 );
-      }
-    } else {
-      contributor = getServiceContributor( role, name );
-    }
-    return contributor;
-  }
+//  static ServiceDeploymentContributor getServiceContributor(
+//      Map<String,List<ServiceDeploymentContributor>> services, String role,
String name ) {
+//    ServiceDeploymentContributor contributor = null;
+//    if( name == null ) {
+//      List<ServiceDeploymentContributor> list = services.get( role );
+//      if( !list.isEmpty() ) {
+//        contributor = list.get( 0 );
+//      }
+//    } else {
+//      contributor = getServiceContributor( role, name );
+//    }
+//    return contributor;
+//  }
 
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/d4812d64/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
index 7220cdd..789a221 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
 import org.apache.hadoop.gateway.service.definition.*;
 import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
+import org.apache.hadoop.gateway.topology.Version;
 
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -60,6 +61,11 @@ public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentCon
   }
 
   @Override
+  public Version getVersion() {
+    return new Version(serviceDefinition.getVersion());
+  }
+
+  @Override
   public void contributeService(DeploymentContext context, Service service) throws Exception
{
     contributeRewriteRules(context, service);
     contributeResources(context, service);


Mime
View raw message