knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject [30/41] knox git commit: Added HA support and URL-level dispatch for webhdfs KNOX-483
Date Thu, 12 Feb 2015 16:22:12 GMT
Added HA support and URL-level dispatch for webhdfs KNOX-483


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

Branch: refs/heads/KNOX-481
Commit: e9c54cf1d944ce35dce8188937ce81bd1c869cb1
Parents: 335b6a4
Author: Sumit Gupta <sumit@apache.org>
Authored: Tue Jan 20 11:16:00 2015 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Wed Feb 11 15:51:10 2015 -0500

----------------------------------------------------------------------
 .../ServiceDefinitionDeploymentContributor.java | 51 +++++++++++++++-----
 .../gateway/service/definition/UrlBinding.java  | 11 +++++
 2 files changed, 50 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/e9c54cf1/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 79cc4a5..755fc67 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
@@ -28,6 +28,7 @@ import org.apache.hadoop.gateway.service.definition.CustomDispatch;
 import org.apache.hadoop.gateway.service.definition.RewriteFilter;
 import org.apache.hadoop.gateway.service.definition.ServiceDefinition;
 import org.apache.hadoop.gateway.service.definition.UrlBinding;
+import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
 
 import java.net.URISyntaxException;
@@ -86,7 +87,7 @@ public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentCon
         }
       }
       try {
-        contributeResource(context, service, binding.getPattern(), filterParams);
+        contributeResource(context, service, binding, filterParams);
       } catch ( URISyntaxException e ) {
         e.printStackTrace();
       }
@@ -94,11 +95,11 @@ public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentCon
 
   }
 
-  private void contributeResource(DeploymentContext context, Service service, String pattern,
Map<String, String> filterParams) throws URISyntaxException {
+  private void contributeResource(DeploymentContext context, Service service, UrlBinding
binding, Map<String, String> filterParams) throws URISyntaxException {
     List<FilterParamDescriptor> params = new ArrayList<FilterParamDescriptor>();
     ResourceDescriptor resource = context.getGatewayDescriptor().addResource();
     resource.role(service.getRole());
-    resource.pattern(pattern);
+    resource.pattern(binding.getPattern());
     addWebAppSecFilters(context, service, resource);
     addAuthenticationFilter(context, service, resource);
     addIdentityAssertionFilter(context, service, resource);
@@ -109,20 +110,46 @@ public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentCon
       }
     }
     addRewriteFilter(context, service, resource, params);
-    CustomDispatch customDispatch = serviceDefinition.getDispatch();
-    if (customDispatch != null) {
-      String contributorName = customDispatch.getContributorName();
-      if (contributorName != null) {
-        addDispatchFilter(context, service, resource, DISPATCH_ROLE, contributorName);
+    addDispatchFilter(context, service, resource, binding);
+  }
+
+  private void addDispatchFilter(DeploymentContext context, Service service, ResourceDescriptor
resource, UrlBinding binding) {
+    CustomDispatch customDispatch = binding.getDispatch();
+    if ( customDispatch == null ) {
+      customDispatch = serviceDefinition.getDispatch();
+    }
+    if ( customDispatch != null ) {
+      boolean isHaEnabled = isHaEnabled(context);
+      if ( isHaEnabled && (customDispatch.getHaContributorName() != null) ) {
+        addDispatchFilter(context, service, resource, DISPATCH_ROLE, customDispatch.getHaContributorName());
       } else {
-        String className = customDispatch.getClassName();
-        if (className != null) {
-          FilterDescriptor filter = resource.addFilter().name( getName() ).role( DISPATCH_ROLE
).impl( GatewayDispatchFilter.class );
-          filter.param().name(DISPATCH_IMPL_PARAM).value(className);
+        String contributorName = customDispatch.getContributorName();
+        if ( contributorName != null ) {
+          addDispatchFilter(context, service, resource, DISPATCH_ROLE, contributorName);
+        } else {
+          String className = customDispatch.getClassName();
+          if ( className != null ) {
+            FilterDescriptor filter = resource.addFilter().name(getName()).role(DISPATCH_ROLE).impl(GatewayDispatchFilter.class);
+            filter.param().name(DISPATCH_IMPL_PARAM).value(className);
+          }
         }
       }
     } else {
       addDispatchFilter(context, service, resource, DISPATCH_ROLE, "http-client");
     }
   }
+
+  private boolean isHaEnabled(DeploymentContext context) {
+    Provider provider = getProviderByRole(context, "ha");
+    if ( provider != null && provider.isEnabled() ) {
+      Map<String, String> params = provider.getParams();
+      if ( params != null ) {
+        if ( params.containsKey(getRole()) ) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/e9c54cf1/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
index 3630ebf..c64658c 100644
--- a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
@@ -29,6 +29,8 @@ public class UrlBinding {
 
   private List<RewriteFilter> rewriteFilters;
 
+  private CustomDispatch dispatch;
+
   @XmlAttribute
   public String getPattern() {
     return pattern;
@@ -46,4 +48,13 @@ public class UrlBinding {
   public void setRewriteFilters(List<RewriteFilter> rewriteFilters) {
     this.rewriteFilters = rewriteFilters;
   }
+
+  @XmlElement(name = "dispatch")
+  public CustomDispatch getDispatch() {
+    return dispatch;
+  }
+
+  public void setDispatch(CustomDispatch dispatch) {
+    this.dispatch = dispatch;
+  }
 }


Mime
View raw message