knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject [14/24] knox git commit: Separated dispatch from filters and added custom dispatch config KNOX-483
Date Fri, 30 Jan 2015 02:03:52 GMT
Separated dispatch from filters and added custom dispatch config KNOX-483


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

Branch: refs/heads/KNOX-481
Commit: 0c3c6321f44569814fa7bd8682f47991b2fd1525
Parents: 1f9c8dc
Author: Sumit Gupta <sumit@apache.org>
Authored: Thu Jan 15 23:46:01 2015 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Thu Jan 29 16:49:05 2015 -0500

----------------------------------------------------------------------
 .../ServiceDefinitionDeploymentContributor.java | 131 +++++++++++--------
 .../service/definition/ServiceDefinition.java   |  11 ++
 .../services/yarn-rm/2.5.0/service.xml          |   3 +
 .../definition/ServiceDefinitionTest.java       |   4 +
 4 files changed, 94 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/0c3c6321/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 4cff585..79cc4a5 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
@@ -19,9 +19,12 @@ package org.apache.hadoop.gateway.deploy.impl;
 
 import org.apache.hadoop.gateway.deploy.DeploymentContext;
 import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributorBase;
+import org.apache.hadoop.gateway.descriptor.FilterDescriptor;
 import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
 import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
+import org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter;
 import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
+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;
@@ -35,73 +38,91 @@ import java.util.Map;
 
 public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentContributorBase
{
 
-    private ServiceDefinition serviceDefinition;
+  private static final String DISPATCH_ROLE = "dispatch";
 
-    private UrlRewriteRulesDescriptor serviceRules;
+  private static final String DISPATCH_IMPL_PARAM = "dispatch-impl";
 
-    public ServiceDefinitionDeploymentContributor(ServiceDefinition serviceDefinition, UrlRewriteRulesDescriptor
serviceRules) {
-        this.serviceDefinition = serviceDefinition;
-        this.serviceRules = serviceRules;
-    }
+  private ServiceDefinition serviceDefinition;
 
-    @Override
-    public String getRole() {
-        return serviceDefinition.getRole();
-    }
+  private UrlRewriteRulesDescriptor serviceRules;
 
-    @Override
-    public String getName() {
-        return serviceDefinition.getName();
-    }
+  public ServiceDefinitionDeploymentContributor(ServiceDefinition serviceDefinition, UrlRewriteRulesDescriptor
serviceRules) {
+    this.serviceDefinition = serviceDefinition;
+    this.serviceRules = serviceRules;
+  }
+
+  @Override
+  public String getRole() {
+    return serviceDefinition.getRole();
+  }
 
-    @Override
-    public void contributeService(DeploymentContext context, Service service) throws Exception
{
-        contributeRewriteRules(context, service);
-        contributeResources(context, service);
+  @Override
+  public String getName() {
+    return serviceDefinition.getName();
+  }
+
+  @Override
+  public void contributeService(DeploymentContext context, Service service) throws Exception
{
+    contributeRewriteRules(context, service);
+    contributeResources(context, service);
+  }
+
+  private void contributeRewriteRules(DeploymentContext context, Service service) {
+    if ( serviceRules != null ) {
+      UrlRewriteRulesDescriptor clusterRules = context.getDescriptor("rewrite");
+      clusterRules.addRules(serviceRules);
     }
+  }
 
-    private void contributeRewriteRules(DeploymentContext context, Service service) {
-        if (serviceRules != null) {
-            UrlRewriteRulesDescriptor clusterRules = context.getDescriptor("rewrite");
-            clusterRules.addRules(serviceRules);
+  private void contributeResources(DeploymentContext context, Service service) {
+    Map<String, String> filterParams = new HashMap<String, String>();
+    List<UrlBinding> bindings = serviceDefinition.getUrlBindings();
+    for ( UrlBinding binding : bindings ) {
+      List<RewriteFilter> filters = binding.getRewriteFilters();
+      if ( filters != null && !filters.isEmpty() ) {
+        filterParams.clear();
+        for ( RewriteFilter filter : filters ) {
+          filterParams.put(filter.getApplyTo(), filter.getRef());
         }
+      }
+      try {
+        contributeResource(context, service, binding.getPattern(), filterParams);
+      } catch ( URISyntaxException e ) {
+        e.printStackTrace();
+      }
     }
 
-    private void contributeResources(DeploymentContext context, Service service) {
-        Map<String, String> filterParams = new HashMap<String, String>();
-        List<UrlBinding> bindings = serviceDefinition.getUrlBindings();
-        for (UrlBinding binding : bindings) {
-            List<RewriteFilter> filters = binding.getRewriteFilters();
-            if (filters != null && !filters.isEmpty()) {
-                filterParams.clear();
-                for (RewriteFilter filter : filters) {
-                    filterParams.put(filter.getApplyTo(), filter.getRef());
-                }
-            }
-            try {
-                contributeResource(context, service, binding.getPattern(), filterParams);
-            } catch (URISyntaxException e) {
-                e.printStackTrace();
-            }
-        }
+  }
 
+  private void contributeResource(DeploymentContext context, Service service, String pattern,
Map<String, String> filterParams) throws URISyntaxException {
+    List<FilterParamDescriptor> params = new ArrayList<FilterParamDescriptor>();
+    ResourceDescriptor resource = context.getGatewayDescriptor().addResource();
+    resource.role(service.getRole());
+    resource.pattern(pattern);
+    addWebAppSecFilters(context, service, resource);
+    addAuthenticationFilter(context, service, resource);
+    addIdentityAssertionFilter(context, service, resource);
+    addAuthorizationFilter(context, service, resource);
+    if ( !filterParams.isEmpty() ) {
+      for ( Map.Entry<String, String> filterParam : filterParams.entrySet() ) {
+        params.add(resource.createFilterParam().name(filterParam.getKey()).value(filterParam.getValue()));
+      }
     }
-
-    private void contributeResource(DeploymentContext context, Service service, String pattern,
Map<String, String> filterParams) throws URISyntaxException {
-        List<FilterParamDescriptor> params = new ArrayList<FilterParamDescriptor>();
-        ResourceDescriptor resource = context.getGatewayDescriptor().addResource();
-        resource.role(service.getRole());
-        resource.pattern(pattern);
-        addWebAppSecFilters(context, service, resource);
-        addAuthenticationFilter(context, service, resource);
-        addIdentityAssertionFilter(context, service, resource);
-        addAuthorizationFilter(context, service, resource);
-        if (!filterParams.isEmpty()) {
-            for (Map.Entry<String, String> filterParam : filterParams.entrySet()) {
-                params.add(resource.createFilterParam().name(filterParam.getKey()).value(filterParam.getValue()));
-            }
+    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);
+      } 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);
         }
-        addRewriteFilter( context, service, resource, params );
-        addDispatchFilter( context, service, resource, "dispatch", "http-client" );
+      }
+    } else {
+      addDispatchFilter(context, service, resource, DISPATCH_ROLE, "http-client");
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/0c3c6321/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
index 9bb5679..3185941 100644
--- a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
@@ -34,6 +34,8 @@ public class ServiceDefinition {
 
   private List<UrlBinding> urlBindings;
 
+  private CustomDispatch dispatch;
+
   @XmlAttribute
   public String getName() {
     return name;
@@ -70,4 +72,13 @@ public class ServiceDefinition {
   public void setUrlBindings(List<UrlBinding> urlBindings) {
     this.urlBindings = urlBindings;
   }
+
+  @XmlElement(name = "dispatch")
+  public CustomDispatch getDispatch() {
+    return dispatch;
+  }
+
+  public void setDispatch(CustomDispatch dispatch) {
+    this.dispatch = dispatch;
+  }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/0c3c6321/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
b/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
index 8b53cca..61a77f0 100644
--- a/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
+++ b/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
@@ -16,11 +16,13 @@
    limitations under the License.
 -->
 <service role="RESOURCEMANAGER" name="resourcemanager" version="2.5.0">
+    <policies></policies>
     <urls>
         <url pattern="/resourcemanager/v1/cluster/"/>
         <url pattern="/resourcemanager/v1/cluster/**?**"/>
         <url pattern="/resourcemanager/v1/cluster/apps?**">
             <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/apps/outbound" apply-to="response.body"/>
+            <policies></policies>
         </url>
         <url pattern="/resourcemanager/v1/cluster/apps?**">
             <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/apps/outbound" apply-to="response.body"/>
@@ -50,5 +52,6 @@
         <url pattern="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts/*">
             <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/proxy/taskattempt/outbound"
apply-to="response.body"/>
         </url>
+
     </urls>
 </service>

http://git-wip-us.apache.org/repos/asf/knox/blob/0c3c6321/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
b/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
index 4f82af2..9d4488a 100644
--- a/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
+++ b/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
@@ -42,5 +42,9 @@ public class ServiceDefinitionTest {
     assertNotNull(bindings);
     assertEquals(12, bindings.size());
     assertNotNull(bindings.get(0).getPattern());
+    url = ClassLoader.getSystemResource("services/hbase/0.98.0/service.xml");
+    definition = (ServiceDefinition) unmarshaller.unmarshal(url.openStream());
+    assertNotNull(definition.getDispatch());
+    assertEquals("hbase", definition.getDispatch().getContributorName());
   }
 }


Mime
View raw message