You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mk...@apache.org on 2014/02/06 15:51:00 UTC
git commit: Added missing rewrite rule for WebHCat root path
Updated Branches:
refs/heads/master bfc23acde -> 705c0a61c
Added missing rewrite rule for WebHCat root path
Project: http://git-wip-us.apache.org/repos/asf/incubator-knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-knox/commit/705c0a61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-knox/tree/705c0a61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-knox/diff/705c0a61
Branch: refs/heads/master
Commit: 705c0a61c9b3405567bb4528b42844beff1d2fc6
Parents: bfc23ac
Author: Maksim Kononenko <mk...@hortonworks.com>
Authored: Thu Feb 6 06:45:11 2014 -0800
Committer: Maksim Kononenko <mk...@hortonworks.com>
Committed: Thu Feb 6 06:45:11 2014 -0800
----------------------------------------------------------------------
.../apache/hadoop/gateway/GatewayFilter.java | 1 +
.../apache/hadoop/gateway/GatewayMessages.java | 3 +
.../webhcat/WebHCatDeploymentContributor.java | 77 +++++++++++++-------
.../WebHCatDeploymentContributor/rewrite.xml | 28 +++++++
4 files changed, 82 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/705c0a61/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
index 7b9281a..bdd019a 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
@@ -148,6 +148,7 @@ public class GatewayFilter implements Filter {
throw new ServletException( e );
}
} else {
+ LOG.failedToMatchPath( path );
httpResponse.setStatus( HttpServletResponse.SC_NOT_FOUND );
auditor.audit( Action.ACCESS, pathWithContext, ResourceType.URI, ActionOutcome.SUCCESS, RES.responseStatus( HttpServletResponse.SC_NOT_FOUND ) );
}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/705c0a61/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index 31d46d5..174a353 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -294,4 +294,7 @@ public interface GatewayMessages {
@Message( level = MessageLevel.ERROR, text = "Failed to remove alias for cluster: {0} {1}." )
void failedToRemoveCredentialForCluster(String clusterName,
KeystoreServiceException e);
+
+ @Message( level = MessageLevel.WARN, text = "Failed to match path {0}" )
+ void failedToMatchPath( String path );
}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/705c0a61/gateway-service-webhcat/src/main/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-service-webhcat/src/main/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor.java b/gateway-service-webhcat/src/main/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor.java
index b62f5c3..946a4f6 100644
--- a/gateway-service-webhcat/src/main/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor.java
+++ b/gateway-service-webhcat/src/main/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor.java
@@ -17,18 +17,22 @@
*/
package org.apache.hadoop.gateway.webhcat;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URISyntaxException;
+
import org.apache.hadoop.gateway.deploy.DeploymentContext;
import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributorBase;
import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory;
import org.apache.hadoop.gateway.topology.Service;
-import java.net.URISyntaxException;
-
public class WebHCatDeploymentContributor extends ServiceDeploymentContributorBase {
+ private static final String RULES_RESOURCE = WebHCatDeploymentContributor.class.getName().replace( '.', '/' ) + "/rewrite.xml";
private static final String WEBHCAT_EXTERNAL_PATH = "/templeton/v1";
@Override
@@ -42,31 +46,50 @@ public class WebHCatDeploymentContributor extends ServiceDeploymentContributorBa
}
@Override
- public void contributeService( DeploymentContext context, Service service ) throws URISyntaxException {
- UrlRewriteRulesDescriptor rules = context.getDescriptor( "rewrite" );
- UrlRewriteRuleDescriptor rule;
- UrlRewriteActionRewriteDescriptorExt rewrite;
+ public void contributeService( DeploymentContext context, Service service ) throws Exception {
+ contributeRewriteRules( context, service );
+ contributeResources( context, service );
+ }
+
+ private void contributeRewriteRules( DeploymentContext context, Service service ) throws IOException {
+ UrlRewriteRulesDescriptor hbaseRules = loadRulesFromTemplate();
+ UrlRewriteRulesDescriptor clusterRules = context.getDescriptor( "rewrite" );
+ clusterRules.addRules( hbaseRules );
+ }
- rule = rules.addRule( getRole() + "/" + getName() + "/request" )
- .directions( "request" )
- .pattern( "*://*:*/**" + WEBHCAT_EXTERNAL_PATH + "/{path=**}?{**}" );
- rewrite = rule.addStep( "rewrite" );
- rewrite.template( service.getUrl() + "/v1/{path=**}?{**}" );
+ private UrlRewriteRulesDescriptor loadRulesFromTemplate() throws IOException {
+ InputStream stream = this.getClass().getClassLoader().getResourceAsStream( RULES_RESOURCE );
+ Reader reader = new InputStreamReader( stream );
+ UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.load( "xml", reader );
+ reader.close();
+ stream.close();
+ return rules;
+ }
- ResourceDescriptor resource = context.getGatewayDescriptor().addResource();
- resource.role( service.getRole() );
- resource.pattern( WEBHCAT_EXTERNAL_PATH + "/**?**" );
- addWebAppSecFilters(context, service, resource);
- if (topologyContainsProviderType(context, "authentication")) {
- context.contributeFilter( service, resource, "authentication", null, null );
- }
- if (topologyContainsProviderType(context, "federation")) {
- context.contributeFilter( service, resource, "federation", null, null );
- }
- context.contributeFilter( service, resource, "rewrite", null, null );
- context.contributeFilter( service, resource, "identity-assertion", null, null );
- addAuthorizationFilter(context, service, resource);
- context.contributeFilter( service, resource, "dispatch", null, null );
+ private void contributeResources( DeploymentContext context, Service service ) throws URISyntaxException {
+ ResourceDescriptor rootResource = context.getGatewayDescriptor().addResource();
+ rootResource.role( service.getRole() );
+ rootResource.pattern( WEBHCAT_EXTERNAL_PATH + "/?**" );
+ addWebAppSecFilters( context, service, rootResource );
+ addAuthenticationFilter( context, service, rootResource );
+ addRewriteFilter( context, service, rootResource, null );
+ addIdentityAssertionFilter( context, service, rootResource );
+ addAuthorizationFilter( context, service, rootResource );
+ addDispatchFilter( context, service, rootResource );
+
+ ResourceDescriptor pathResource = context.getGatewayDescriptor().addResource();
+ pathResource.role( service.getRole() );
+ pathResource.pattern( WEBHCAT_EXTERNAL_PATH + "/**?**" );
+ addWebAppSecFilters( context, service, pathResource );
+ addAuthenticationFilter( context, service, pathResource );
+ addRewriteFilter( context, service, pathResource, null );
+ addIdentityAssertionFilter( context, service, pathResource );
+ addAuthorizationFilter( context, service, pathResource );
+ addDispatchFilter( context, service, pathResource );
}
+ private void addDispatchFilter(
+ DeploymentContext context, Service service, ResourceDescriptor resource ) {
+ context.contributeFilter( service, resource, "dispatch", null, null );
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/705c0a61/gateway-service-webhcat/src/main/resources/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-webhcat/src/main/resources/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor/rewrite.xml b/gateway-service-webhcat/src/main/resources/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor/rewrite.xml
new file mode 100644
index 0000000..558abb4
--- /dev/null
+++ b/gateway-service-webhcat/src/main/resources/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor/rewrite.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ 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.
+-->
+<rules>
+
+ <rule dir="IN" name="WEBHCAT/webhcat/root/inbound" pattern="*://*:*/**/templeton/v1/?{**}">
+ <rewrite template="{$serviceUrl[WEBHCAT]}/v1/?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHCAT/webhcat/path/inbound" pattern="*://*:*/**/templeton/v1/{path=**}?{**}">
+ <rewrite template="{$serviceUrl[WEBHCAT]}/v1/{path=**}?{**}"/>
+ </rule>
+
+</rules>