You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by su...@apache.org on 2015/02/13 03:17:51 UTC
[37/47] knox git commit: Added versions to service definitions for
deployment and topology KNOX-481
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/a242454e
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/a242454e
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/a242454e
Branch: refs/heads/KNOX-481
Commit: a242454e32b52599bedfafa4387d4e572bbec896
Parents: 1f66028
Author: Sumit Gupta <su...@apache.org>
Authored: Tue Jan 27 10:56:37 2015 -0500
Committer: Sumit Gupta <su...@apache.org>
Committed: Thu Feb 12 17:16:08 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/a242454e/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 a0cc6cb..16d188a 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 ) {
@@ -248,12 +237,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
@@ -289,12 +278,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() );
@@ -322,14 +311,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;
@@ -400,19 +397,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 ) {
@@ -423,12 +417,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 );
}
}
@@ -475,18 +478,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/a242454e/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);