knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject [42/47] knox git commit: KNOX-483 initial commit for loading service definitions
Date Fri, 13 Feb 2015 02:17:56 GMT
KNOX-483 initial commit for loading service definitions


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

Branch: refs/heads/KNOX-481
Commit: 8cbd9fe802e7c0d1bb41a1b013a9ec5061a8512c
Parents: 4aee123
Author: Sumit Gupta <sumit@apache.org>
Authored: Tue Jan 6 12:07:29 2015 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Thu Feb 12 17:16:08 2015 -0500

----------------------------------------------------------------------
 .../gateway/deploy/DeploymentFactory.java       | 109 +++++------
 .../ServiceDefinitionDeploymentContributor.java | 194 ++++++-------------
 .../service/definition/PolicyBinding.java       |  21 ++
 .../service/definition/RewriteFilter.java       |  47 +++++
 .../service/definition/ServiceDefinition.java   |  37 +---
 .../gateway/service/definition/UrlBinding.java  |  49 +++++
 .../services/yarn-rm/2.5.0/service.xml          |  70 +++----
 .../definition/ServiceDefinitionTest.java       |  18 +-
 8 files changed, 270 insertions(+), 275 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/8cbd9fe8/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 16d188a..a0cc6cb 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,17 +19,18 @@ 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;
@@ -43,16 +44,26 @@ import java.beans.Statement;
 import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
-import java.util.*;
+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;
 
 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 Map<String,Map<String,Map<Version, ServiceDeploymentContributor>>>
SERVICE_CONTRIBUTOR_MAP;
+  //private static Set<ServiceDeploymentContributor> SERVICE_CONTRIBUTORS;
+  private static Map<String,Map<String,ServiceDeploymentContributor>> SERVICE_CONTRIBUTOR_MAP;
   static {
     loadServiceContributors();
   }
@@ -62,7 +73,7 @@ public abstract class DeploymentFactory {
   static {
     loadProviderContributors();
   }
-
+  
   public static void setGatewayServices(GatewayServices services) {
     DeploymentFactory.gatewayServices = services;
   }
@@ -73,7 +84,7 @@ public abstract class DeploymentFactory {
     String stacks = config.getGatewayStacksDir();
     File stacksDir = new File(stacks, STACKS_SERVICES_DIRECTORY);
     Set<ServiceDeploymentContributor> deploymentContributors = ServiceDefinitionsLoader.loadServiceDefinitions(stacksDir);
-    addServiceDeploymentContributors(deploymentContributors.iterator());
+    addServiceDeploymentContributors(SERVICE_CONTRIBUTOR_MAP, deploymentContributors.iterator());
 
     Map<String,List<ProviderDeploymentContributor>> providers = selectContextProviders(
topology );
     Map<String,List<ServiceDeploymentContributor>> services = selectContextServices(
topology );
@@ -185,7 +196,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(),
service.getVersion() );
+      ServiceDeploymentContributor contributor = getServiceContributor( role, service.getName()
);
       if( contributor != null ) {
         List<ServiceDeploymentContributor> list = defaults.get( role );
         if( list == null ) {
@@ -237,12 +248,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
@@ -278,12 +289,12 @@ public abstract class DeploymentFactory {
       }
     }
     for( Service service : topology.getServices() ) {
-      ServiceDeploymentContributor contributor = getServiceContributor( service.getRole(),
service.getName(), service.getVersion() );
+      ServiceDeploymentContributor contributor = getServiceContributor( service.getRole(),
null );
       if( contributor != null ) {
         try {
           contributor.contributeService( context, service );
           if (gatewayServices != null) {
-            ServiceRegistry sr = gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
+            ServiceRegistry sr = (ServiceRegistry) gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
             if (sr != null) {
               String regCode = sr.getRegistrationCode(topology.getName());
               sr.registerService(regCode, topology.getName(), service.getRole(), service.getUrls()
);
@@ -311,22 +322,14 @@ public abstract class DeploymentFactory {
     return contributor;
   }
 
-  public static ServiceDeploymentContributor getServiceContributor( String role, String name,
Version version ) {
+  public static ServiceDeploymentContributor getServiceContributor( String role, String name
) {
     ServiceDeploymentContributor contributor = null;
-    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 );
-        }
+    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 );
       }
     }
     return contributor;
@@ -397,16 +400,19 @@ public abstract class DeploymentFactory {
       }
     }
     return null;
-  }
-
+  }  
+  
   private static void loadServiceContributors() {
-    SERVICE_CONTRIBUTOR_MAP = new HashMap<String, Map<String, Map<Version, ServiceDeploymentContributor>>>();
+    Map<String,Map<String,ServiceDeploymentContributor>> roleMap
+        = new HashMap<String,Map<String,ServiceDeploymentContributor>>();
+
     ServiceLoader<ServiceDeploymentContributor> loader = ServiceLoader.load( ServiceDeploymentContributor.class
);
     Iterator<ServiceDeploymentContributor> contributors = loader.iterator();
-    addServiceDeploymentContributors(contributors);
+     addServiceDeploymentContributors(roleMap, contributors);
+     SERVICE_CONTRIBUTOR_MAP = roleMap;
   }
 
-   private static void addServiceDeploymentContributors(Iterator<ServiceDeploymentContributor>
contributors) {
+   private static void addServiceDeploymentContributors(Map<String, Map<String, ServiceDeploymentContributor>>
roleMap, Iterator<ServiceDeploymentContributor> contributors) {
       while( contributors.hasNext() ) {
         ServiceDeploymentContributor contributor = contributors.next();
         if( contributor.getName() == null ) {
@@ -417,21 +423,12 @@ public abstract class DeploymentFactory {
           log.ignoringServiceContributorWithMissingRole( contributor.getClass().getName()
);
           continue;
         }
-        if( contributor.getVersion() == null ) {
-          log.ignoringServiceContributorWithMissingVersion(contributor.getClass().getName());
-          continue;
-        }
-        Map<String,Map<Version, ServiceDeploymentContributor>> nameMap = SERVICE_CONTRIBUTOR_MAP.get(
contributor.getRole() );
+        Map nameMap = roleMap.get( contributor.getRole() );
         if( nameMap == null ) {
-          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 = new HashMap<String,ServiceDeploymentContributor>();
+          roleMap.put( contributor.getRole(), nameMap );
         }
-        versionMap.put( contributor.getVersion(), contributor );
+        nameMap.put( contributor.getName(), contributor );
       }
    }
 
@@ -478,18 +475,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/8cbd9fe8/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 789a221..dd2a4c9 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,15 +19,13 @@ 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.*;
-import org.apache.hadoop.gateway.topology.Provider;
+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.Service;
-import org.apache.hadoop.gateway.topology.Version;
 
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -37,154 +35,74 @@ import java.util.Map;
 
 public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentContributorBase
{
 
-  private static final String DISPATCH_ROLE = "dispatch";
+    private ServiceDefinition serviceDefinition;
 
-  private static final String DISPATCH_IMPL_PARAM = "dispatch-impl";
+    private UrlRewriteRulesDescriptor serviceRules;
 
-  private ServiceDefinition serviceDefinition;
-
-  private UrlRewriteRulesDescriptor serviceRules;
-
-  public ServiceDefinitionDeploymentContributor(ServiceDefinition serviceDefinition, UrlRewriteRulesDescriptor
serviceRules) {
-    this.serviceDefinition = serviceDefinition;
-    this.serviceRules = serviceRules;
-  }
-
-  @Override
-  public String getRole() {
-    return serviceDefinition.getRole();
-  }
-
-  @Override
-  public String getName() {
-    return serviceDefinition.getName();
-  }
-
-  @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);
-  }
-
-  private void contributeRewriteRules(DeploymentContext context, Service service) {
-    if ( serviceRules != null ) {
-      UrlRewriteRulesDescriptor clusterRules = context.getDescriptor("rewrite");
-      clusterRules.addRules(serviceRules);
+    public ServiceDefinitionDeploymentContributor(ServiceDefinition serviceDefinition, UrlRewriteRulesDescriptor
serviceRules) {
+        this.serviceDefinition = serviceDefinition;
+        this.serviceRules = serviceRules;
     }
-  }
 
-  private void contributeResources(DeploymentContext context, Service service) {
-    Map<String, String> filterParams = new HashMap<String, String>();
-    List<Route> bindings = serviceDefinition.getRoutes();
-    for ( Route binding : bindings ) {
-      List<Rewrite> filters = binding.getRewrites();
-      if ( filters != null && !filters.isEmpty() ) {
-        filterParams.clear();
-        for ( Rewrite filter : filters ) {
-          filterParams.put(filter.getTo(), filter.getApply());
-        }
-      }
-      try {
-        contributeResource(context, service, binding, filterParams);
-      } catch ( URISyntaxException e ) {
-        e.printStackTrace();
-      }
+    @Override
+    public String getRole() {
+        return serviceDefinition.getRole();
     }
 
-  }
-
-  private void contributeResource(DeploymentContext context, Service service, Route binding,
Map<String, String> filterParams) throws URISyntaxException {
-    List<FilterParamDescriptor> params = new ArrayList<FilterParamDescriptor>();
-    ResourceDescriptor resource = context.getGatewayDescriptor().addResource();
-    resource.role(service.getRole());
-    resource.pattern(binding.getPath());
-    List<Policy> policyBindings = binding.getPolicies();
-    if (policyBindings == null) {
-      policyBindings = serviceDefinition.getPolicies();
-    }
-    if (policyBindings == null) {
-      //add default set
-      addDefaultPolicies(context, service, filterParams, params, resource);
-    } else {
-      addPolicies(context, service, filterParams, params, resource, policyBindings);
+    @Override
+    public String getName() {
+        return serviceDefinition.getName();
     }
-    addDispatchFilter(context, service, resource, binding);
-  }
 
-  private void addPolicies(DeploymentContext context, Service service, Map<String, String>
filterParams, List<FilterParamDescriptor> params, ResourceDescriptor resource, List<Policy>
policyBindings) throws URISyntaxException {
-    for (Policy policyBinding : policyBindings) {
-      String role = policyBinding.getRole();
-      if (role == null) {
-        throw new IllegalArgumentException("Policy defined has no role for service " + service.getName());
-      }
-      role = role.trim().toLowerCase();
-      if (role.equals("rewrite")) {
-        addRewriteFilter(context, service, filterParams, params, resource);
-      } else if (topologyContainsProviderType(context, role)) {
-        context.contributeFilter( service, resource, role, policyBinding.getName(), null
);
-      }
+    @Override
+    public void contributeService(DeploymentContext context, Service service) throws Exception
{
+        System.out.println("contributing service def");
+        contributeRewriteRules(context, service);
+        contributeResources(context, service);
     }
-  }
 
-  private void addDefaultPolicies(DeploymentContext context, Service service, Map<String,
String> filterParams, List<FilterParamDescriptor> params, ResourceDescriptor resource)
throws URISyntaxException {
-    addWebAppSecFilters(context, service, resource);
-    addAuthenticationFilter(context, service, resource);
-    addIdentityAssertionFilter(context, service, resource);
-    addAuthorizationFilter(context, service, resource);
-    addRewriteFilter(context, service, filterParams, params, resource);
-  }
-
-  private void addRewriteFilter(DeploymentContext context, Service service, Map<String,
String> filterParams, List<FilterParamDescriptor> params, ResourceDescriptor resource)
throws URISyntaxException {
-    if ( !filterParams.isEmpty() ) {
-      for ( Map.Entry<String, String> filterParam : filterParams.entrySet() ) {
-        params.add(resource.createFilterParam().name(filterParam.getKey()).value(filterParam.getValue()));
-      }
+    private void contributeRewriteRules(DeploymentContext context, Service service) {
+        if (serviceRules != null) {
+            UrlRewriteRulesDescriptor clusterRules = context.getDescriptor("rewrite");
+            clusterRules.addRules(serviceRules);
+        }
     }
-    addRewriteFilter(context, service, resource, params);
-  }
 
-  private void addDispatchFilter(DeploymentContext context, Service service, ResourceDescriptor
resource, Route 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 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);
-          }
+    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();
+            }
         }
-      }
-    } 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;
+    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 );
+        addDispatchFilter( context, service, resource, "dispatch", "http-client" );
     }
-    return false;
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/8cbd9fe8/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/PolicyBinding.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/PolicyBinding.java
b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/PolicyBinding.java
new file mode 100644
index 0000000..ad6b0a6
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/PolicyBinding.java
@@ -0,0 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+public class PolicyBinding {
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/8cbd9fe8/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/RewriteFilter.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/RewriteFilter.java
b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/RewriteFilter.java
new file mode 100644
index 0000000..4b0dccc
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/RewriteFilter.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType(name = "rewrite-filter")
+public class RewriteFilter {
+
+  private String ref;
+
+  private String applyTo;
+
+  @XmlAttribute
+  public String getRef() {
+    return ref;
+  }
+
+  public void setRef(String ref) {
+    this.ref = ref;
+  }
+
+  @XmlAttribute(name = "apply-to")
+  public String getApplyTo() {
+    return applyTo;
+  }
+
+  public void setApplyTo(String applyTo) {
+    this.applyTo = applyTo;
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/8cbd9fe8/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 6cb14c4..682f2fc 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
@@ -32,11 +32,7 @@ public class ServiceDefinition {
 
   private String version;
 
-  private List<Route> routes;
-
-  private List<Policy> policies;
-
-  private CustomDispatch dispatch;
+  private List<UrlBinding> urlBindings;
 
   private List<PolicyBinding> policyBindings;
 
@@ -69,33 +65,14 @@ public class ServiceDefinition {
     this.version = version;
   }
 
-  @XmlElement(name = "route")
-  @XmlElementWrapper(name = "routes")
-  public List<Route> getRoutes() {
-    return routes;
-  }
-
-  public void setRoutes(List<Route> routes) {
-    this.routes = routes;
-  }
-
-  @XmlElement(name = "policy")
-  @XmlElementWrapper(name = "policies")
-  public List<Policy> getPolicies() {
-    return policies;
-  }
-
-  public void setPolicies(List<Policy> policies) {
-    this.policies = policies;
+  @XmlElement(name = "url")
+  @XmlElementWrapper(name = "urls")
+  public List<UrlBinding> getUrlBindings() {
+    return urlBindings;
   }
 
-  @XmlElement(name = "dispatch")
-  public CustomDispatch getDispatch() {
-    return dispatch;
-  }
-
-  public void setDispatch(CustomDispatch dispatch) {
-    this.dispatch = dispatch;
+  public void setUrlBindings(List<UrlBinding> urlBindings) {
+    this.urlBindings = urlBindings;
   }
 
   @XmlElement(name = "policy")

http://git-wip-us.apache.org/repos/asf/knox/blob/8cbd9fe8/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
new file mode 100644
index 0000000..3630ebf
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import java.util.List;
+
+@XmlType(name = "url")
+public class UrlBinding {
+
+  private String pattern;
+
+  private List<RewriteFilter> rewriteFilters;
+
+  @XmlAttribute
+  public String getPattern() {
+    return pattern;
+  }
+
+  public void setPattern(String pattern) {
+    this.pattern = pattern;
+  }
+
+  @XmlElement(name = "rewrite-filter")
+  public List<RewriteFilter> getRewriteFilters() {
+    return rewriteFilters;
+  }
+
+  public void setRewriteFilters(List<RewriteFilter> rewriteFilters) {
+    this.rewriteFilters = rewriteFilters;
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/8cbd9fe8/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 73fb771..8b53cca 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,39 +16,39 @@
    limitations under the License.
 -->
 <service role="RESOURCEMANAGER" name="resourcemanager" version="2.5.0">
-    <routes>
-        <route path="/resourcemanager/v1/cluster/"/>
-        <route path="/resourcemanager/v1/cluster/**?**"/>
-        <route path="/resourcemanager/v1/cluster/apps?**">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/apps/outbound" to="response.body"/>
-        </route>
-        <route path="/resourcemanager/v1/cluster/apps?**">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/apps/outbound" to="response.body"/>
-        </route>
-        <route path="/resourcemanager/v1/cluster/apps/*?**">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/app/outbound" to="response.body"/>
-        </route>
-        <route path="/resourcemanager/v1/cluster/apps/*/appattempts?**">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/appattempts/outbound" to="response.body"/>
-        </route>
-        <route path="/resourcemanager/v1/cluster/nodes?**">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/nodes/outbound" to="response.body"/>
-        </route>
-        <route path="/resourcemanager/v1/cluster/nodes/*?**">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/nodeId/inbound" to="request.url"/>
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/node/outbound" to="response.body"/>
-        </route>
-        <route path="/resourcemanager/proxy/*/ws/v1/**?**">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/inbound/proxy" to="request.url"/>
-        </route>
-        <route path="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/jobattempts">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/proxy/jobattempts/outbound"
to="response.body"/>
-        </route>
-        <route path="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/proxy/taskattempts/outbound"
to="response.body"/>
-        </route>
-        <route path="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts/*">
-            <rewrite apply="RESOURCEMANAGER/resourcemanager/proxy/taskattempt/outbound"
to="response.body"/>
-        </route>
-    </routes>
+    <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"/>
+        </url>
+        <url pattern="/resourcemanager/v1/cluster/apps?**">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/apps/outbound" apply-to="response.body"/>
+        </url>
+        <url pattern="/resourcemanager/v1/cluster/apps/*?**">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/app/outbound" apply-to="response.body"/>
+        </url>
+        <url pattern="/resourcemanager/v1/cluster/apps/*/appattempts?**">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/appattempts/outbound"
apply-to="response.body"/>
+        </url>
+        <url pattern="/resourcemanager/v1/cluster/nodes?**">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/nodes/outbound" apply-to="response.body"/>
+        </url>
+        <url pattern="/resourcemanager/v1/cluster/nodes/*?**">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/nodeId/inbound" apply-to="request.url"/>
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/node/outbound" apply-to="response.body"/>
+        </url>
+        <url pattern="/resourcemanager/proxy/*/ws/v1/**?**">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/inbound/proxy" apply-to="request.url"/>
+        </url>
+        <url pattern="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/jobattempts">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/proxy/jobattempts/outbound"
apply-to="response.body"/>
+        </url>
+        <url pattern="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts">
+            <rewrite-filter ref="RESOURCEMANAGER/resourcemanager/proxy/taskattempts/outbound"
apply-to="response.body"/>
+        </url>
+        <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/8cbd9fe8/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 d5bec8a..4f82af2 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
@@ -26,7 +26,6 @@ import java.util.List;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 
 public class ServiceDefinitionTest {
 
@@ -39,22 +38,9 @@ public class ServiceDefinitionTest {
     assertEquals("resourcemanager", definition.getName());
     assertEquals("RESOURCEMANAGER", definition.getRole());
     assertEquals("2.5.0", definition.getVersion());
-    List<Route> bindings = definition.getRoutes();
+    List<UrlBinding> bindings = definition.getUrlBindings();
     assertNotNull(bindings);
     assertEquals(12, bindings.size());
-    assertNotNull(bindings.get(0).getPath());
-    url = ClassLoader.getSystemResource("services/hbase/0.98.0/service.xml");
-    definition = (ServiceDefinition) unmarshaller.unmarshal(url.openStream());
-    assertNotNull(definition.getDispatch());
-    assertEquals("hbase", definition.getDispatch().getContributorName());
-    url = ClassLoader.getSystemResource("services/webhdfs/2.4.0/service.xml");
-    definition = (ServiceDefinition) unmarshaller.unmarshal(url.openStream());
-    assertNotNull(definition.getDispatch());
-    assertEquals("hdfs", definition.getDispatch().getContributorName());
-    assertEquals("ha-hdfs", definition.getDispatch().getHaContributorName());
-    List<Policy> policyBindings = definition.getPolicies();
-    assertNotNull(policyBindings);
-    assertEquals("webappsec", policyBindings.get(0).getRole());
-    assertNull(policyBindings.get(0).getName());
+    assertNotNull(bindings.get(0).getPattern());
   }
 }


Mime
View raw message