You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by km...@apache.org on 2013/06/07 21:55:19 UTC
git commit: KNOX-8: Support HBase via HBase/Stargate
Updated Branches:
refs/heads/master 187ab8170 -> 31deadb64
KNOX-8: Support HBase via HBase/Stargate
Project: http://git-wip-us.apache.org/repos/asf/incubator-knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-knox/commit/31deadb6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-knox/tree/31deadb6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-knox/diff/31deadb6
Branch: refs/heads/master
Commit: 31deadb643eb618c4b5fbd2d919daf57fe9d7d70
Parents: 187ab81
Author: Kevin Minder <ke...@hortonworks.com>
Authored: Fri Jun 7 15:55:12 2013 -0400
Committer: Kevin Minder <ke...@hortonworks.com>
Committed: Fri Jun 7 15:55:12 2013 -0400
----------------------------------------------------------------------
.../filter/rewrite/impl/xml/XmlFilterReader.java | 2 +-
gateway-release/home/conf/users.ldif | 11 ++
gateway-release/pom.xml | 4 +
.../gateway/dispatch/HttpClientDispatch.java | 4 +
gateway-service-hbase/pom.xml | 39 +++++
.../gateway/hbase/HbaseDeploymentContributor.java | 119 +++++++++++++++
...oop.gateway.deploy.ServiceDeploymentContributor | 19 +++
gateway-spi/pom.xml | 5 +-
.../gateway/dispatch/AbstractGatewayDispatch.java | 18 +++
pom.xml | 6 +
10 files changed, 225 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
index 7eca699..b9704c9 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
@@ -128,7 +128,7 @@ public abstract class XmlFilterReader extends Reader {
if( "<".equals( tag.getTagType().getStartDelimiter() ) ) {
stack.push( new Element( tag ) );
writer.write( "<" );
- writer.write( tag.getName() );
+ writer.write( tag.getNameSegment().toString() );
Attributes attributes = tag.getAttributes();
if( !attributes.isEmpty() ) {
for( Attribute attribute : attributes ) {
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-release/home/conf/users.ldif
----------------------------------------------------------------------
diff --git a/gateway-release/home/conf/users.ldif b/gateway-release/home/conf/users.ldif
index 66eac6d..f3ef800 100644
--- a/gateway-release/home/conf/users.ldif
+++ b/gateway-release/home/conf/users.ldif
@@ -61,6 +61,16 @@ sn: HCat
uid: hcat
userPassword:hcat-password
+dn: uid=hbase,ou=people,dc=hadoop,dc=apache,dc=org
+objectclass:top
+objectclass:person
+objectclass:organizationalPerson
+objectclass:inetOrgPerson
+cn: HBase
+sn: Hbase
+uid: hbase
+userPassword:hbase-password
+
# entry for a sample user
#dn: uid=bob,ou=people,dc=hadoop,dc=apache,dc=org
#objectclass:top
@@ -71,3 +81,4 @@ userPassword:hcat-password
#sn: Smith
#uid: bob
#userPassword:bob-password
+
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-release/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-release/pom.xml b/gateway-release/pom.xml
index 6af3da3..73a43b3 100644
--- a/gateway-release/pom.xml
+++ b/gateway-release/pom.xml
@@ -115,6 +115,10 @@
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
+ <artifactId>gateway-service-hbase</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${gateway-group}</groupId>
<artifactId>gateway-service-hdfs</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
index c92bcee..dc6bc97 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
@@ -155,6 +155,7 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
public void doGet( URI url, HttpServletRequest request, HttpServletResponse response )
throws IOException, URISyntaxException {
HttpGet method = new HttpGet( url );
+ copyRequestHeaderFields( method, request );
executeRequest( method, request, response );
}
@@ -171,6 +172,7 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
HttpPut method = new HttpPut( url );
HttpEntity entity = createRequestEntity( request );
method.setEntity( entity );
+ copyRequestHeaderFields( method, request );
executeRequest( method, request, response );
}
@@ -180,6 +182,7 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
HttpPost method = new HttpPost( url );
HttpEntity entity = createRequestEntity( request );
method.setEntity( entity );
+ copyRequestHeaderFields( method, request );
executeRequest( method, request, response );
}
@@ -187,6 +190,7 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
public void doDelete( URI url, HttpServletRequest request, HttpServletResponse response )
throws IOException, URISyntaxException {
HttpDelete method = new HttpDelete( url );
+ copyRequestHeaderFields( method, request );
executeRequest( method, request, response );
}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-service-hbase/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/pom.xml b/gateway-service-hbase/pom.xml
new file mode 100644
index 0000000..4d4b3ac
--- /dev/null
+++ b/gateway-service-hbase/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>gateway</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>gateway-service-hbase</artifactId>
+ <name>gateway-service-hbase</name>
+ <description>The extensions to the gateway for supporting Hbase.</description>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <dependencies>
+ <dependency>
+ <groupId>${gateway-group}</groupId>
+ <artifactId>gateway-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${gateway-group}</groupId>
+ <artifactId>gateway-provider-rewrite</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HbaseDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HbaseDeploymentContributor.java b/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HbaseDeploymentContributor.java
new file mode 100644
index 0000000..a155999
--- /dev/null
+++ b/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HbaseDeploymentContributor.java
@@ -0,0 +1,119 @@
+/**
+ * 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.hbase;
+
+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.ext.UrlRewriteMatchDescriptor;
+import org.apache.hadoop.gateway.topology.Service;
+
+public class HbaseDeploymentContributor extends ServiceDeploymentContributorBase {
+
+ private static final String EXTERNAL_PATH = "/hbase/api";
+
+ @Override
+ public String getRole() {
+ return "HBASE";
+ }
+
+ @Override
+ public String getName() {
+ return "hbase";
+ }
+
+ @Override
+ public void contributeService( DeploymentContext context, Service service ) throws Exception {
+ contributeRewriteRules( context, service );
+ contributeResources( context, service );
+ }
+
+ private void contributeRewriteRules( DeploymentContext context, Service service ) throws URISyntaxException {
+ UrlRewriteRulesDescriptor rules = context.getDescriptor( "rewrite" );
+ UrlRewriteRuleDescriptor rule;
+ UrlRewriteActionRewriteDescriptorExt rewrite;
+ UrlRewriteMatchDescriptor match;
+
+ rule = rules.addRule( getRole() + "/" + getName() + "/root/inbound" )
+ .directions( "inbound" )
+ .pattern( "*://*:*/**" + EXTERNAL_PATH + "/?{**}" );
+ rewrite = rule.addStep( "rewrite" );
+ rewrite.template( service.getUrl().toExternalForm() + "/?{**}" );
+
+ rule = rules.addRule( getRole() + "/" + getName() + "/root/inbound" )
+ .directions( "inbound" )
+ .pattern( "*://*:*/**" + EXTERNAL_PATH + "/{**}?{**}" );
+ rewrite = rule.addStep( "rewrite" );
+ rewrite.template( service.getUrl().toExternalForm() + "/{**}?{**}" );
+
+ rule = rules.addRule( getRole() + "/" + getName() + "/hbase/outbound" )
+ .directions( "outbound" )
+ .pattern( "*://*:*/**?**" );
+ match = rule.addStep( "match" );
+ match.pattern( "*://{host}:{port}/{path=**}?{**}" );
+ rewrite = rule.addStep( "rewrite" );
+ rewrite.template( service.getUrl().toExternalForm() + "/{path=**}" );
+ }
+
+ private void contributeResources( DeploymentContext context, Service service ) throws URISyntaxException {
+ ResourceDescriptor rootResource = context.getGatewayDescriptor().addResource();
+ rootResource.role( service.getRole() );
+ rootResource.pattern( EXTERNAL_PATH + "/?**" );
+ addAuthenticationFilter( context, service, rootResource );
+ addRewriteFilter( context, service, rootResource );
+ addIdentityAssertionFilter( context, service, rootResource );
+ addDispatchFilter( context, service, rootResource );
+
+ ResourceDescriptor fileResource = context.getGatewayDescriptor().addResource();
+ fileResource.role( service.getRole() );
+ fileResource.pattern( EXTERNAL_PATH + "/**?**" );
+ addAuthenticationFilter( context, service, fileResource );
+ addRewriteFilter( context, service, fileResource );
+ addIdentityAssertionFilter( context, service, fileResource );
+ addDispatchFilter( context, service, fileResource );
+ }
+
+ private void addAuthenticationFilter( DeploymentContext context, Service service, ResourceDescriptor resource ) {
+ if (topologyContainsProviderType( context, "authentication" )) {
+ context.contributeFilter( service, resource, "authentication", null, null );
+ }
+ if ( topologyContainsProviderType( context, "federation" ) ) {
+ context.contributeFilter( service, resource, "federation", null, null );
+ }
+ }
+
+ private void addRewriteFilter(
+ DeploymentContext context, Service service, ResourceDescriptor resource ) throws URISyntaxException {
+ context.contributeFilter( service, resource, "rewrite", null, null );
+ }
+
+ private void addIdentityAssertionFilter(DeploymentContext context, Service service, ResourceDescriptor resource) {
+ context.contributeFilter( service, resource, "identity-assertion", null, null );
+ }
+
+ private void addDispatchFilter(
+ DeploymentContext context, Service service, ResourceDescriptor resource ) {
+ context.contributeFilter( service, resource, "dispatch", null, null );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor b/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor
new file mode 100644
index 0000000..3b95831
--- /dev/null
+++ b/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor
@@ -0,0 +1,19 @@
+##########################################################################
+# 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.
+##########################################################################
+
+org.apache.hadoop.gateway.hbase.HbaseDeploymentContributor
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-spi/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-spi/pom.xml b/gateway-spi/pom.xml
index ff5c5d1..d6dadb6 100644
--- a/gateway-spi/pom.xml
+++ b/gateway-spi/pom.xml
@@ -89,7 +89,10 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
index e04dcc3..6af5d9a 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.gateway.dispatch;
import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
import org.apache.hadoop.gateway.filter.GatewayResponse;
import org.apache.hadoop.io.IOUtils;
+import org.apache.http.client.methods.HttpUriRequest;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@@ -30,14 +31,18 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public abstract class AbstractGatewayDispatch extends AbstractGatewayFilter implements Dispatch {
private static Map<String,Adapter> METHOD_ADAPTERS = createMethodAdapters();
private static int STREAM_COPY_BUFFER_SIZE = 4096;
+ private static final List<String> EXCLUDE_HEADERS = Arrays.asList( "Content-Length" );
private static Map<String,Adapter> createMethodAdapters() {
Map<String,Adapter> map = new HashMap<String,Adapter>();
@@ -157,5 +162,18 @@ public abstract class AbstractGatewayDispatch extends AbstractGatewayFilter impl
dispatch.doOptions( getDispatchUrl( request ), request, response );
}
}
+
+ public static void copyRequestHeaderFields(HttpUriRequest outboundRequest,
+ HttpServletRequest inboundRequest) {
+ Enumeration<String> headerNames = inboundRequest.getHeaderNames();
+ while( headerNames.hasMoreElements() ) {
+ String name = (String) headerNames.nextElement();
+ if ( !outboundRequest.containsHeader( name )
+ && !EXCLUDE_HEADERS.contains( name ) ) {
+ String vaule = inboundRequest.getHeader( name );
+ outboundRequest.addHeader( name, vaule );
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/31deadb6/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0dcc310..f5bd4e6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,7 @@
<module>gateway-provider-security-shiro</module>
<module>gateway-provider-identity-assertion-pseudo</module>
<module>gateway-service-as</module>
+ <module>gateway-service-hbase</module>
<module>gateway-service-hdfs</module>
<module>gateway-service-oozie</module>
<module>gateway-service-templeton</module>
@@ -338,6 +339,11 @@
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
+ <artifactId>gateway-service-hbase</artifactId>
+ <version>${gateway-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${gateway-group}</groupId>
<artifactId>gateway-service-hdfs</artifactId>
<version>${gateway-version}</version>
</dependency>