http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-oozie/src/main/resources/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor/rewrite.xml ---------------------------------------------------------------------- diff --git a/gateway-service-oozie/src/main/resources/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor/rewrite.xml b/gateway-service-oozie/src/main/resources/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor/rewrite.xml deleted file mode 100644 index d3c52bb..0000000 --- a/gateway-service-oozie/src/main/resources/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor/rewrite.xml +++ /dev/null @@ -1,122 +0,0 @@ -<!-- - 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="OOZIE/oozie/root" pattern="*://*:*/**/oozie/{**}?{**}"> - <rewrite template="{$serviceUrl[OOZIE]}/{**}?{**}"/> - </rule> - - <rule dir="IN" name="OOZIE/oozie/v1" pattern="*://*:*/**/oozie/v1/{**}?{**}"> - <rewrite template="{$serviceUrl[OOZIE]}/v1/{**}?{**}"/> - </rule> - - <rule dir="IN" name="OOZIE/oozie/v2" pattern="*://*:*/**/oozie/v2/{**}?{**}"> - <rewrite template="{$serviceUrl[OOZIE]}/v2/{**}?{**}"/> - </rule> - - <rule name="OOZIE/oozie/user-name"> - <rewrite template="{$username}"/> - </rule> - - <rule name="OOZIE/oozie/name-node-url"> - <rewrite template="hdfs://{$serviceMappedAddr[NAMENODE]}"/> - </rule> - - <rule name="OOZIE/oozie/job-tracker-address"> - <rewrite template="{$serviceMappedAddr[JOBTRACKER]}"/> - </rule> - - <rule name="OOZIE/oozie/hdfs-path" flow="OR"> - <match pattern="/~"> - <rewrite template="hdfs://{$serviceMappedHost[NAMENODE]}:{$servicePort[NAMENODE]}/user/{$username}"/> - </match> - <match pattern="/~/{path=**}"> - <rewrite template="hdfs://{$serviceMappedHost[NAMENODE]}:{$servicePort[NAMENODE]}/user/{$username}/{path=**}"/> - </match> - <match pattern="{path=**}"> - <rewrite template="hdfs://{$serviceMappedHost[NAMENODE]}:{$servicePort[NAMENODE]}/{path=**}"/> - </match> - </rule> - - <filter name="OOZIE/oozie/configuration"> - <content type="*/xml"> - <buffer path="/configuration/property"> - <detect path="name" value="user.name"> - <apply path="value" rule="OOZIE/oozie/user-name"/> - </detect> - <detect path="name" value="nameNode"> - <apply path="value" rule="OOZIE/oozie/name-node-url"/> - </detect> - <detect path="name" value="jobTracker"> - <apply path="value" rule="OOZIE/oozie/job-tracker-address"/> - </detect> - <detect path="name" value="fs.default.name"> - <apply path="value" rule="OOZIE/oozie/name-node-url"/> - </detect> - <detect path="name" value="fs.defaultFS"> - <apply path="value" rule="OOZIE/oozie/name-node-url"/> - </detect> - <detect path="name" value="oozie.wf.application.path"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - <detect path="name" value="oozie.coord.application.path"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - <detect path="name" value="oozie.bundle.application.path"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - <detect path="name" value="oozie.libpath"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - <detect path="name" value="mapreduce.job.user.name"> - <apply path="value" rule="OOZIE/oozie/user-name"/> - </detect> - <detect path="name" value="mapred.job.tracker"> - <apply path="value" rule="OOZIE/oozie/job-tracker-address"/> - </detect> - <detect path="name" value="mapred.input.dir"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - <detect path="name" value="inputDir"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - <detect path="name" value="mapred.output.dir"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - <detect path="name" value="outputDir"> - <apply path="value" rule="OOZIE/oozie/hdfs-path"/> - </detect> - </buffer> - </content> - <content type="*/json"> - <apply path="$[user.name]" rule="OOZIE/oozie/user-name"/> - <apply path="$[nameNode]" rule="OOZIE/oozie/name-node-url"/> - <apply path="$[jobTracker]" rule="OOZIE/oozie/job-tracker-addr"/> - <apply path="$[fs.default.name]" rule="OOZIE/oozie/name-node-url"/> - <apply path="$[fs.defaultFS]" rule="OOZIE/oozie/name-node-url"/> - <apply path="$[oozie.wf.application.path]" rule="OOZIE/oozie/hdfs-path"/> - <apply path="$[oozie.coord.application.path]" rule="OOZIE/oozie/hdfs-path"/> - <apply path="$[oozie.bundle.application.path]" rule="OOZIE/oozie/hdfs-path"/> - <apply path="$[oozie.libpath]" rule="OOZIE/oozie/hdfs-path"/> - <apply path="$[mapreduce.job.user.name]" rule="OOZIE/oozie/user-name"/> - <apply path="$[mapred.job.tracker]" rule="OOZIE/oozie/job-tracker-address"/> - <apply path="$[mapred.input.dir]" rule="OOZIE/oozie/hdfs-path"/> - <apply path="$[mapred.output.dir]" rule="OOZIE/oozie/hdfs-path"/> - </content> - </filter> - -</rules> \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-oozie/src/test/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributorTest.java ---------------------------------------------------------------------- diff --git a/gateway-service-oozie/src/test/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributorTest.java b/gateway-service-oozie/src/test/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributorTest.java deleted file mode 100644 index fad79f0..0000000 --- a/gateway-service-oozie/src/test/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributorTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * 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.oozie; - -import org.apache.hadoop.gateway.deploy.DeploymentContext; -import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor; -import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteRulesDescriptorImpl; -import org.apache.hadoop.gateway.topology.Service; -import org.easymock.EasyMock; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Test; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Iterator; -import java.util.ServiceLoader; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.fail; - -public class OozieDeploymentContributorTest { - - @Test - public void testServiceLoader() throws Exception { - ServiceLoader loader = ServiceLoader.load( ServiceDeploymentContributor.class ); - Iterator iterator = loader.iterator(); - assertThat( "Service iterator empty.", iterator.hasNext() ); - while( iterator.hasNext() ) { - Object object = iterator.next(); - if( object instanceof OozieDeploymentContributor ) { - return; - } - } - fail( "Failed to find " + OozieDeploymentContributor.class.getName() + " via service loader." ); - } - - @Test - public void testLoadRulesFromTemplate() throws IOException, URISyntaxException { - WebArchive webArchive = ShrinkWrap.create( WebArchive.class, "test-archive" ); - - UrlRewriteRulesDescriptorImpl clusterRules = new UrlRewriteRulesDescriptorImpl(); - - DeploymentContext context = EasyMock.createNiceMock( DeploymentContext.class ); - EasyMock.expect( context.getDescriptor( "rewrite" ) ).andReturn( clusterRules ).anyTimes(); - EasyMock.expect( context.getWebArchive() ).andReturn( webArchive ).anyTimes(); - - Service service = EasyMock.createNiceMock( Service.class ); - EasyMock.expect( service.getRole() ).andReturn( "OOZIE" ).anyTimes(); - EasyMock.expect( service.getName() ).andReturn( null ).anyTimes(); - EasyMock.expect( service.getUrl() ).andReturn( "http://test-host:777" ).anyTimes(); - - EasyMock.replay( context, service ); - - OozieDeploymentContributor contributor = new OozieDeploymentContributor(); - - UrlRewriteRulesDescriptor oozieRules = contributor.loadRulesFromTemplate(); - - assertThat( oozieRules, notNullValue() ); - assertThat( oozieRules.getFilter( "OOZIE/oozie/configuration" ), notNullValue() ); - } - -// @Test -// public void testDeployment() throws Exception { -// WebArchive webArchive = ShrinkWrap.create( WebArchive.class, "test-archive" ); -// -// UrlRewriteRulesDescriptorImpl rewriteRules = new UrlRewriteRulesDescriptorImpl(); -// -// Map<String,String> serviceParams = new HashMap<String, String>(); -// Service service = new Service(); -// service.setRole( "OOZIE" ); -// service.setName( "oozie" ); -// service.setUrl( "http://test-host:42/test-path" ); -// service.setParams( serviceParams ); -// -// Topology topology = new Topology(); -// topology.setName( "test-topology" ); -// topology.addService( service ); -// -// GatewayDescriptor gateway = EasyMock.createNiceMock( GatewayDescriptor.class ); -// DeploymentContext context = EasyMock.createNiceMock( DeploymentContext.class ); -// EasyMock.expect( context.getWebArchive() ).andReturn( webArchive ).anyTimes(); -// EasyMock.expect( context.getDescriptor( "rewrite" ) ).andReturn( rewriteRules ).anyTimes(); -// EasyMock.expect( context.getWebAppDescriptor() ).andReturn( Descriptors.create( WebAppDescriptor.class ) ).anyTimes(); -// EasyMock.expect( context.getTopology() ).andReturn( topology ).anyTimes(); -// EasyMock.expect( context.getGatewayDescriptor() ).andReturn( gateway ).anyTimes(); -// Capture<Service> capturedService = new Capture<Service>(); -// Capture<ResourceDescriptor> capturedResource = new Capture<ResourceDescriptor>(); -// Capture<String> capturedRole = new Capture<String>(); -// Capture<String> capturedName = new Capture<String>(); -// Capture<List<FilterParamDescriptor>> capturedParams = new Capture<List<FilterParamDescriptor>>(); -// context.contributeFilter( capture(capturedService) , capture(capturedResource), capture(capturedRole), capture(capturedName), capture(capturedParams) ); -// EasyMock.expectLastCall().anyTimes(); -// EasyMock.replay( gateway, context ); -// -// OozieDeploymentContributor contributor = new OozieDeploymentContributor(); -// -// assertThat( contributor.getRole(), CoreMatchers.is( "OOZIE" ) ); -// assertThat( contributor.getName(), CoreMatchers.is( "oozie" ) ); -// -// // Just make sure it doesn't blow up. -// contributor.initializeContribution( context ); -// -// contributor.contributeService( context, service ); -// -// // Just make sure it doesn't blow up. -// contributor.finalizeContribution( context ); -// -// assertThat( capturedRole.getValue(), is( "dispatch" ) ); -// assertThat( capturedName.getValue(), is( "http-client" ) ); -// } - -} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhcat/pom.xml ---------------------------------------------------------------------- diff --git a/gateway-service-webhcat/pom.xml b/gateway-service-webhcat/pom.xml deleted file mode 100644 index 3f81cc4..0000000 --- a/gateway-service-webhcat/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.knox</groupId> - <artifactId>gateway</artifactId> - <version>0.6.0-SNAPSHOT</version> - </parent> - <artifactId>gateway-service-webhcat</artifactId> - - <name>gateway-service-webhcat</name> - <description>The extension to the gateway for supporting WebHCat.</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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/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 deleted file mode 100644 index 9ee7a9a..0000000 --- a/gateway-service-webhcat/src/main/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * 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.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.UrlRewriteRulesDescriptor; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory; -import org.apache.hadoop.gateway.topology.Service; - -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 - public String getRole() { - return "WEBHCAT"; - } - - @Override - public String getName() { - return "webhcat"; - } - - @Override - 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 ); - } - - 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; - } - - 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", "http-client", null ); - } -} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhcat/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor ---------------------------------------------------------------------- diff --git a/gateway-service-webhcat/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor b/gateway-service-webhcat/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor deleted file mode 100644 index 1b74d89..0000000 --- a/gateway-service-webhcat/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor +++ /dev/null @@ -1,19 +0,0 @@ -########################################################################## -# 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.webhcat.WebHCatDeploymentContributor \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/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 deleted file mode 100644 index 558abb4..0000000 --- a/gateway-service-webhcat/src/main/resources/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributor/rewrite.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?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> http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java index c7b3ff9..d43cf1b 100644 --- a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java +++ b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java @@ -19,8 +19,11 @@ package org.apache.hadoop.gateway.hdfs; import org.apache.hadoop.gateway.deploy.DeploymentContext; import org.apache.hadoop.gateway.deploy.ProviderDeploymentContributorBase; +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.hdfs.dispatch.WebHdfsHaDispatchFilter; import org.apache.hadoop.gateway.hdfs.dispatch.WebHdfsHaHttpClientDispatch; import org.apache.hadoop.gateway.topology.Provider; import org.apache.hadoop.gateway.topology.Service; @@ -35,7 +38,9 @@ public class NameNodeHaDispatchDeploymentContributor extends ProviderDeploymentC private static final String NAME = "ha-hdfs"; - @Override + private static final String DISPATCH_IMPL_PARAM = "dispatch-impl"; + + @Override public String getRole() { return ROLE; } @@ -50,11 +55,12 @@ public class NameNodeHaDispatchDeploymentContributor extends ProviderDeploymentC if (params == null) { params = new ArrayList<FilterParamDescriptor>(); } - params.add(resource.createFilterParam().name(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE).value(resource.role())); +// params.add(resource.createFilterParam().name(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE).value(resource.role())); Map<String, String> providerParams = provider.getParams(); for (Map.Entry<String, String> entry : providerParams.entrySet()) { params.add(resource.createFilterParam().name(entry.getKey().toLowerCase()).value(entry.getValue())); } - resource.addFilter().name(getName()).role(getRole()).impl(WebHdfsHaHttpClientDispatch.class).params(params); + FilterDescriptor filter = resource.addFilter().name(getName()).role(getRole()).impl(WebHdfsHaDispatchFilter.class).params(params); + filter.param().name(DISPATCH_IMPL_PARAM).value(WebHdfsHaHttpClientDispatch.class.getName()); } } http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDeploymentContributor.java ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDeploymentContributor.java b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDeploymentContributor.java deleted file mode 100644 index 0e63597..0000000 --- a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDeploymentContributor.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * 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.hdfs; - -import org.apache.hadoop.gateway.deploy.DeploymentContext; -import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributorBase; -import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor; -import org.apache.hadoop.gateway.descriptor.ResourceDescriptor; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter; -import org.apache.hadoop.gateway.topology.Provider; -import org.apache.hadoop.gateway.topology.Service; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class WebHdfsDeploymentContributor extends ServiceDeploymentContributorBase { - - private static final String RULES_RESOURCE = WebHdfsDeploymentContributor.class.getName().replace( '.', '/' ) + "/rewrite.xml"; - private static final String WEBHDFS_EXTERNAL_PATH = "/webhdfs/v1"; - private static final String DATANODE_EXTERNAL_PATH = "/webhdfs/data/v1"; - - @Override - public String getRole() { - return "WEBHDFS"; - } - - @Override - public String getName() { - return "webhdfs"; - } - - @Override - public void contributeService( DeploymentContext context, Service service ) throws Exception { - contributeRewriteRules( context, service ); - contributeNameNodeResource( context, service ); - contributeDataNodeResource( context, service ); - } - - private void contributeRewriteRules( DeploymentContext context, Service service ) throws URISyntaxException, IOException { - UrlRewriteRulesDescriptor serviceRules = loadRulesFromClassPath(); - UrlRewriteRulesDescriptor clusterRules = context.getDescriptor( "rewrite" ); - clusterRules.addRules( serviceRules ); - } - - public void contributeNameNodeResource( DeploymentContext context, Service service ) throws URISyntaxException { - List<FilterParamDescriptor> params; - ResourceDescriptor rootResource = context.getGatewayDescriptor().addResource(); - rootResource.role( service.getRole() ); - rootResource.pattern( WEBHDFS_EXTERNAL_PATH + "/?**" ); - addWebAppSecFilters(context, service, rootResource); - addAuthenticationFilter( context, service, rootResource ); - params = new ArrayList<FilterParamDescriptor>(); - params.add( rootResource.createFilterParam(). - name( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM ).value( getQualifiedName() + "/inbound/namenode/root" ) ); - addRewriteFilter( context, service, rootResource, params ); - addIdentityAssertionFilter( context, service, rootResource ); - addAuthorizationFilter( context, service, rootResource ); - String dispatchName = getDispatchNameForNN( context ); - String dispatchRole = "dispatch"; - addDispatchFilter( context, service, rootResource, dispatchRole, dispatchName ); - - ResourceDescriptor fileResource = context.getGatewayDescriptor().addResource(); - fileResource.role( service.getRole() ); - fileResource.pattern( WEBHDFS_EXTERNAL_PATH + "/**?**" ); - addWebAppSecFilters(context, service, fileResource); - addAuthenticationFilter( context, service, fileResource ); - params = new ArrayList<FilterParamDescriptor>(); - params.add( fileResource.createFilterParam(). - name( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM ).value( getQualifiedName() + "/inbound/namenode/file" ) ); - params.add( fileResource.createFilterParam(). - name( UrlRewriteServletFilter.RESPONSE_HEADERS_FILTER_PARAM ).value( getQualifiedName() + "/outbound/namenode/headers" ) ); - addRewriteFilter( context, service, fileResource, params ); - addIdentityAssertionFilter( context, service, fileResource ); - addAuthorizationFilter( context, service, fileResource ); - addDispatchFilter( context, service, fileResource, dispatchRole, dispatchName ); - - ResourceDescriptor homeResource = context.getGatewayDescriptor().addResource(); - homeResource.role( service.getRole() ); - homeResource.pattern( WEBHDFS_EXTERNAL_PATH + "/~?**" ); - addWebAppSecFilters(context, service, homeResource); - addAuthenticationFilter( context, service, homeResource ); - params = new ArrayList<FilterParamDescriptor>(); - params.add( homeResource.createFilterParam(). - name( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM ).value( getQualifiedName() + "/inbound/namenode/home" ) ); - addRewriteFilter( context, service, homeResource, params ); - addIdentityAssertionFilter( context, service, homeResource ); - addAuthorizationFilter( context, service, homeResource ); - addDispatchFilter( context, service, homeResource, dispatchRole, dispatchName ); - - ResourceDescriptor homeFileResource = context.getGatewayDescriptor().addResource(); - homeFileResource.role( service.getRole() ); - homeFileResource.pattern( WEBHDFS_EXTERNAL_PATH + "/~/**?**" ); - addWebAppSecFilters(context, service, homeFileResource); - addAuthenticationFilter( context, service, homeFileResource ); - params = new ArrayList<FilterParamDescriptor>(); - params.add( homeFileResource.createFilterParam(). - name( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM ).value( getQualifiedName() + "/inbound/namenode/home/file" ) ); - params.add( homeFileResource.createFilterParam(). - name( UrlRewriteServletFilter.RESPONSE_HEADERS_FILTER_PARAM ).value( getQualifiedName() + "/outbound/namenode/headers" ) ); - addRewriteFilter( context, service, homeFileResource, params ); - addIdentityAssertionFilter( context, service, homeFileResource ); - addAuthorizationFilter( context, service, homeFileResource ); - addDispatchFilter( context, service, homeFileResource, dispatchRole, dispatchName ); - } - - public void contributeDataNodeResource( DeploymentContext context, Service service ) throws URISyntaxException { - List<FilterParamDescriptor> params; - ResourceDescriptor fileResource = context.getGatewayDescriptor().addResource(); - fileResource.role( service.getRole() ); - fileResource.pattern( DATANODE_EXTERNAL_PATH + "/**?**" ); - addWebAppSecFilters(context, service, fileResource); - addAuthenticationFilter( context, service, fileResource ); - addIdentityAssertionFilter( context, service, fileResource ); - addAuthorizationFilter( context, service, fileResource ); - params = new ArrayList<FilterParamDescriptor>(); - params.add( fileResource.createFilterParam(). - name( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM ).value( getQualifiedName() + "/inbound/datanode" ) ); - addRewriteFilter( context, service, fileResource, params ); - addDispatchFilter( context, service, fileResource, "dispatch", "http-client" ); - } - - String getQualifiedName() { - return getRole() + "/" + getName(); - } - - UrlRewriteRulesDescriptor loadRulesFromClassPath() 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; - } - - /** - * Returns the name of the dispatch to use by checking to see if 'HA' is enabled. - */ - private String getDispatchNameForNN(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 "ha-hdfs"; - } - } - } - return "hdfs"; - } -} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDispatchDeploymentContributor.java ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDispatchDeploymentContributor.java b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDispatchDeploymentContributor.java deleted file mode 100644 index 78353d1..0000000 --- a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/WebHdfsDispatchDeploymentContributor.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.hdfs; - -import org.apache.hadoop.gateway.deploy.DeploymentContext; -import org.apache.hadoop.gateway.deploy.ProviderDeploymentContributorBase; -import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor; -import org.apache.hadoop.gateway.descriptor.ResourceDescriptor; -import org.apache.hadoop.gateway.hdfs.dispatch.HdfsDispatch; -import org.apache.hadoop.gateway.topology.Provider; -import org.apache.hadoop.gateway.topology.Service; - -import java.util.List; - -public class WebHdfsDispatchDeploymentContributor extends ProviderDeploymentContributorBase { - - @Override - public String getRole() { - return "dispatch"; - } - - @Override - public String getName() { - return "hdfs"; - } - - @Override - public void contributeFilter( DeploymentContext context, Provider provider, Service service, ResourceDescriptor resource, List<FilterParamDescriptor> params ) { - resource.addFilter().role( getRole() ).name( getName() ).impl( HdfsDispatch.class ).params(params); - } - -} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java new file mode 100644 index 0000000..be0fe18 --- /dev/null +++ b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java @@ -0,0 +1,36 @@ +/** + * 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.hdfs.dispatch; + +import org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter; +import org.apache.hadoop.gateway.ha.provider.HaProvider; +import org.apache.hadoop.gateway.ha.provider.HaServletContextListener; + +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; + +public class WebHdfsHaDispatchFilter extends GatewayDispatchFilter { + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + super.init(filterConfig); + HaProvider haProvider = HaServletContextListener.getHaProvider(filterConfig.getServletContext()); + ((WebHdfsHaHttpClientDispatch)getDispatch()).setHaProvider(haProvider); + getDispatch().init(); + } +} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java index a0aa014..f21b6e9 100644 --- a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java +++ b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java @@ -17,10 +17,12 @@ */ package org.apache.hadoop.gateway.hdfs.dispatch; +import org.apache.hadoop.gateway.config.Configure; import org.apache.hadoop.gateway.filter.AbstractGatewayFilter; import org.apache.hadoop.gateway.ha.provider.HaProvider; import org.apache.hadoop.gateway.ha.provider.HaServiceConfig; import org.apache.hadoop.gateway.ha.provider.HaServletContextListener; +import org.apache.hadoop.gateway.ha.provider.impl.HaServiceConfigConstants; import org.apache.hadoop.gateway.hdfs.i18n.WebHdfsMessages; import org.apache.hadoop.gateway.i18n.messages.MessagesFactory; import org.apache.http.HttpResponse; @@ -43,19 +45,17 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch { private static final String RETRY_COUNTER_ATTRIBUTE = "dispatch.ha.retry.counter"; - public static final String RESOURCE_ROLE_ATTRIBUTE = "resource.role"; + public static final String RESOURCE_ROLE = "WEBHDFS"; private static final WebHdfsMessages LOG = MessagesFactory.get(WebHdfsMessages.class); - private int maxFailoverAttempts; + private int maxFailoverAttempts = HaServiceConfigConstants.DEFAULT_MAX_FAILOVER_ATTEMPTS; - private int failoverSleep; + private int failoverSleep = HaServiceConfigConstants.DEFAULT_FAILOVER_SLEEP; - private int maxRetryAttempts; + private int maxRetryAttempts = HaServiceConfigConstants.DEFAULT_MAX_RETRY_ATTEMPTS; - private int retrySleep; - - private String resourceRole; + private int retrySleep = HaServiceConfigConstants.DEFAULT_RETRY_SLEEP; private HaProvider haProvider; @@ -67,19 +67,27 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch { } @Override - public void init(FilterConfig filterConfig) throws ServletException { - super.init(filterConfig); - resourceRole = filterConfig.getInitParameter(RESOURCE_ROLE_ATTRIBUTE); - LOG.initializingForResourceRole(resourceRole); - haProvider = HaServletContextListener.getHaProvider(filterConfig.getServletContext()); - HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(resourceRole); - maxFailoverAttempts = serviceConfig.getMaxFailoverAttempts(); - failoverSleep = serviceConfig.getFailoverSleep(); - maxRetryAttempts = serviceConfig.getMaxRetryAttempts(); - retrySleep = serviceConfig.getRetrySleep(); + public void init() { + super.init(); + if (haProvider != null) { + HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(RESOURCE_ROLE); + maxFailoverAttempts = serviceConfig.getMaxFailoverAttempts(); + failoverSleep = serviceConfig.getFailoverSleep(); + maxRetryAttempts = serviceConfig.getMaxRetryAttempts(); + retrySleep = serviceConfig.getRetrySleep(); + } } - @Override + public HaProvider getHaProvider() { + return haProvider; + } + + @Configure + public void setHaProvider(HaProvider haProvider) { + this.haProvider = haProvider; + } + + @Override protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws IOException { HttpResponse inboundResponse = null; try { @@ -126,7 +134,7 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch { } inboundRequest.setAttribute(FAILOVER_COUNTER_ATTRIBUTE, counter); if (counter.incrementAndGet() <= maxFailoverAttempts) { - haProvider.markFailedURL(resourceRole, outboundRequest.getURI().toString()); + haProvider.markFailedURL(RESOURCE_ROLE, outboundRequest.getURI().toString()); //null out target url so that rewriters run again inboundRequest.setAttribute(AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME, null); URI uri = getDispatchUrl(inboundRequest); @@ -135,12 +143,12 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch { try { Thread.sleep(failoverSleep); } catch (InterruptedException e) { - LOG.failoverSleepFailed(resourceRole, e); + LOG.failoverSleepFailed(RESOURCE_ROLE, e); } } executeRequest(outboundRequest, inboundRequest, outboundResponse); } else { - LOG.maxFailoverAttemptsReached(maxFailoverAttempts, resourceRole); + LOG.maxFailoverAttemptsReached(maxFailoverAttempts, RESOURCE_ROLE); if (inboundResponse != null) { writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse); } else { @@ -161,12 +169,12 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch { try { Thread.sleep(retrySleep); } catch (InterruptedException e) { - LOG.retrySleepFailed(resourceRole, e); + LOG.retrySleepFailed(RESOURCE_ROLE, e); } } executeRequest(outboundRequest, inboundRequest, outboundResponse); } else { - LOG.maxRetryAttemptsReached(maxRetryAttempts, resourceRole, outboundRequest.getURI().toString()); + LOG.maxRetryAttemptsReached(maxRetryAttempts, RESOURCE_ROLE, outboundRequest.getURI().toString()); if (inboundResponse != null) { writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse); } else { @@ -174,4 +182,16 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch { } } } + + private static URI getDispatchUrl(HttpServletRequest request) { + StringBuffer str = request.getRequestURL(); + String query = request.getQueryString(); + if ( query != null ) { + str.append('?'); + str.append(query); + } + URI url = URI.create(str.toString()); + return url; + } + } http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor b/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor index 6fde03f..fc4074d 100644 --- a/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor +++ b/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor @@ -17,4 +17,3 @@ ########################################################################## org.apache.hadoop.gateway.hdfs.NameNodeHaDispatchDeploymentContributor -org.apache.hadoop.gateway.hdfs.WebHdfsDispatchDeploymentContributor http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor b/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor index 0a3d6ee..d918906 100644 --- a/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor +++ b/gateway-service-webhdfs/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor @@ -16,6 +16,5 @@ # limitations under the License. ########################################################################## -org.apache.hadoop.gateway.hdfs.WebHdfsDeploymentContributor org.apache.hadoop.gateway.hdfs.NameNodeDeploymentContributor org.apache.hadoop.gateway.hdfs.JobTrackerDeploymentContributor \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java ---------------------------------------------------------------------- diff --git a/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java b/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java index ae861a9..757288f 100644 --- a/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java +++ b/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java @@ -27,6 +27,7 @@ import org.apache.hadoop.gateway.ha.provider.impl.DefaultHaServiceConfig; import org.apache.hadoop.gateway.ha.provider.impl.HaDescriptorFactory; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.BasicHttpParams; import org.easymock.EasyMock; import org.easymock.IAnswer; @@ -69,12 +70,11 @@ public class WebHdfsHaHttpClientDispatchTest { EasyMock.expect(context.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes(); FilterConfig config = EasyMock.createNiceMock( FilterConfig.class ); EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes(); - EasyMock.expect(config.getInitParameter( WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE )).andReturn("test-role").anyTimes(); EasyMock.expect(config.getInitParameter(EasyMock.anyObject(String.class))).andReturn(null).anyTimes(); InstrumentedWebHdfsHaHttpClientDispatch dispatch = new InstrumentedWebHdfsHaHttpClientDispatch(); EasyMock.replay(context,config); - dispatch.init(config); + dispatch.init(); assertThat( dispatch.getAppCookieManager(), notNullValue() ); } @@ -94,7 +94,6 @@ public class WebHdfsHaHttpClientDispatchTest { FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class); ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); - EasyMock.expect(filterConfig.getInitParameter(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE)).andReturn(serviceName).anyTimes(); EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes(); EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(provider).anyTimes(); @@ -125,7 +124,9 @@ public class WebHdfsHaHttpClientDispatchTest { EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse); Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName)); WebHdfsHaHttpClientDispatch dispatch = new WebHdfsHaHttpClientDispatch(); - dispatch.init(filterConfig); + dispatch.setHttpClient(new DefaultHttpClient()); + dispatch.setHaProvider(provider); + dispatch.init(); long startTime = System.currentTimeMillis(); try { dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse); http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-yarn-rm/pom.xml ---------------------------------------------------------------------- diff --git a/gateway-service-yarn-rm/pom.xml b/gateway-service-yarn-rm/pom.xml deleted file mode 100644 index fc9db48..0000000 --- a/gateway-service-yarn-rm/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ -<?xml version="1.0"?> -<!-- - 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. ---> -<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.knox</groupId> - <artifactId>gateway</artifactId> - <version>0.6.0-SNAPSHOT</version> - </parent> - <artifactId>gateway-service-yarn-rm</artifactId> - <name>gateway-service-yarn-rm</name> - <description>The extension to the gateway for supporting YARN Resource Manager REST API.</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>${gateway-group}</groupId> - <artifactId>gateway-test-utils</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-yarn-rm/src/main/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor.java ---------------------------------------------------------------------- diff --git a/gateway-service-yarn-rm/src/main/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor.java b/gateway-service-yarn-rm/src/main/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor.java deleted file mode 100644 index 21e1b2e..0000000 --- a/gateway-service-yarn-rm/src/main/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * 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.yarn.rm; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.hadoop.gateway.deploy.DeploymentContext; -import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributorBase; -import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor; -import org.apache.hadoop.gateway.descriptor.ResourceDescriptor; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory; -import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter; -import org.apache.hadoop.gateway.topology.Service; - -public class ResourceManagerDeploymentContributor extends - ServiceDeploymentContributorBase { - private static final String RULES_RESOURCE = ResourceManagerDeploymentContributor.class - .getName().replace( '.', '/' ) + "/rewrite.xml"; - private static final String EXTERNAL_PATH = "/resourcemanager"; - private static final String PROXY_PATH = "/resourcemanager/proxy"; - - @Override - public String getRole() { - return "RESOURCEMANAGER"; - } - - @Override - public String getName() { - return "resourcemanager"; - } - - @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, IOException { - UrlRewriteRulesDescriptor serviceRules = loadRulesFromClassPath(); - UrlRewriteRulesDescriptor clusterRules = context.getDescriptor( "rewrite" ); - clusterRules.addRules( serviceRules ); - } - - private UrlRewriteRulesDescriptor loadRulesFromClassPath() 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; - } - - private void contributeResources(DeploymentContext context, Service service) - throws URISyntaxException { - Map<String, String> filterParams = new HashMap<String, String>(); - - contributeResource( context, service, EXTERNAL_PATH + "/v1/cluster/", null ); - - contributeResource( context, service, EXTERNAL_PATH + "/v1/cluster/**?**", null ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/apps/outbound" ); - contributeResource( context, service, EXTERNAL_PATH + "/v1/cluster/apps?**", filterParams ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/app/outbound" ); - contributeResource( context, service, EXTERNAL_PATH + "/v1/cluster/apps/*?**", filterParams ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/appattempts/outbound" ); - contributeResource( context, service, EXTERNAL_PATH + "/v1/cluster/apps/*/appattempts?**", filterParams ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/nodes/outbound" ); - contributeResource( context, service, EXTERNAL_PATH + "/v1/cluster/nodes?**", filterParams ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM, getQualifiedName() + "/nodeId/inbound" ); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/node/outbound" ); - contributeResource( context, service, EXTERNAL_PATH + "/v1/cluster/nodes/*?**", filterParams ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.REQUEST_URL_RULE_PARAM, getQualifiedName() + "/inbound/proxy" ); - contributeResource( context, service, PROXY_PATH + "/*/ws/v1/**?**", filterParams ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/proxy/jobattempts/outbound" ); - contributeResource( context, service, PROXY_PATH + "/*/ws/v1/mapreduce/jobs/*/jobattempts", filterParams ); - - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/proxy/taskattempts/outbound" ); - contributeResource( context, service, PROXY_PATH + "/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts", filterParams ); - - filterParams.clear(); - filterParams.put( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM, getQualifiedName() + "/proxy/taskattempt/outbound" ); - contributeResource( context, service, PROXY_PATH + "/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts/*", filterParams ); - } - - 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 != null ) { - for( 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" ); - } - - private String getQualifiedName() { - return getRole() + "/" + getName(); - } -} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-yarn-rm/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor ---------------------------------------------------------------------- diff --git a/gateway-service-yarn-rm/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor b/gateway-service-yarn-rm/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor deleted file mode 100644 index 3db76c7..0000000 --- a/gateway-service-yarn-rm/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor +++ /dev/null @@ -1,19 +0,0 @@ -########################################################################## -# 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.yarn.rm.ResourceManagerDeploymentContributor \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-yarn-rm/src/main/resources/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor/rewrite.xml ---------------------------------------------------------------------- diff --git a/gateway-service-yarn-rm/src/main/resources/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor/rewrite.xml b/gateway-service-yarn-rm/src/main/resources/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor/rewrite.xml deleted file mode 100644 index 95ce2a3..0000000 --- a/gateway-service-yarn-rm/src/main/resources/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributor/rewrite.xml +++ /dev/null @@ -1,193 +0,0 @@ -<?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="RESOURCEMANAGER/resourcemanager/inbound/root" pattern="*://*:*/**/resourcemanager/v1/?{**}"> - <rewrite template="{$serviceUrl[RESOURCEMANAGER]}/v1/?{**}"/> - </rule> - - <rule dir="IN" name="RESOURCEMANAGER/resourcemanager/inbound/path" pattern="*://*:*/**/resourcemanager/v1/{path=**}?{**}"> - <rewrite template="{$serviceUrl[RESOURCEMANAGER]}/v1/{path=**}/?{**}"/> - </rule> - - <rule dir="IN" name="RESOURCEMANAGER/resourcemanager/inbound/proxy" pattern="*://*:*/**/resourcemanager/proxy/{appid=*}/ws/v1/{path=**}?{**}"> - <decrypt-query/> - <match pattern="*://*:*/**/resourcemanager/proxy/{appid=*}/ws/v1/{path=**}?{scheme}?{host}?{port}?{**}"/> - <rewrite template="{scheme}://{host}:{port}/proxy/{appid=*}/ws/v1/{path=**}?{**}"/> - </rule> - - <rule dir="OUT" name="RESOURCEMANAGER/resourcemanager/url/outbound"> - <match pattern="*://*:*/**?**"/> - <rewrite template=""/> - </rule> - <rule dir="OUT" name="RESOURCEMANAGER/resourcemanager/trackingUrlHistory/outbound"> - <match pattern="{scheme}://{host}:{port}/proxy/{appid=*}/jobhistory/job/**"/> - <rewrite template=""/> - </rule> - <rule dir="OUT" name="RESOURCEMANAGER/resourcemanager/trackingUrlAM/outbound"> - <match pattern="{scheme}://{host}:{port}/proxy/{appid=*}"/> - <rewrite template="{$frontend[url]}/resourcemanager/proxy/{appid=*}?{scheme}?host={$hostmap(host)}?{port}?{**}"/> - <encrypt-query/> - </rule> - <rule dir="OUT" name="RESOURCEMANAGER/resourcemanager/hostport/outbound"> - <match pattern="*:*"/> - <rewrite template=""/> - </rule> - <rule dir="OUT" name="RESOURCEMANAGER/resourcemanager/logsLink/outbound"> - <match pattern="//*:*/**?**"/> - <rewrite template=""/> - </rule> - <rule dir="OUT" name="RESOURCEMANAGER/resourcemanager/host/outbound"> - <rewrite template=""/> - </rule> - <rule dir="OUT" name="RESOURCEMANAGER/resourcemanager/nodeId/outbound"> - <match pattern="{host=*}:{port=*}"/> - <encrypt template="{host}:{port}" param="encaddr"/> - <rewrite template="{encaddr}"/> - </rule> - <rule dir="IN" name="RESOURCEMANAGER/resourcemanager/nodeId/inbound"> - <match pattern="*://*:*/**/resourcemanager/v1/cluster/nodes/{addr=*}?{**}"/> - <decrypt param="addr"/> - <rewrite template="{$serviceUrl[RESOURCEMANAGER]}/v1/cluster/nodes/{addr}?{**}"/> - </rule> - - <filter name="RESOURCEMANAGER/resourcemanager/apps/outbound"> - <content type="*/json"> - <buffer path="$.apps.app[*]"> - <detect path="$.trackingUI" value="History"> - <apply path="$.trackingUrl" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - </detect> - <detect path="$.trackingUI" value="ApplicationMaster"> - <apply path="$.trackingUrl" rule="RESOURCEMANAGER/resourcemanager/trackingUrlAM/outbound"/> - </detect> - <apply path="$.amContainerLogs" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - <apply path="$.amHostHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </buffer> - </content> - <content type="*/xml"> - <buffer path="/apps/app"> - <detect path="trackingUI" value="History"> - <apply path="trackingUrl" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - </detect> - <detect path="trackingUI" value="ApplicationMaster"> - <apply path="trackingUrl" rule="RESOURCEMANAGER/resourcemanager/trackingUrlAM/outbound"/> - </detect> - <apply path="amContainerLogs" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - <apply path="amHostHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </buffer> - </content> - </filter> - - <filter name="RESOURCEMANAGER/resourcemanager/app/outbound"> - <content type="*/json"> - <buffer path="$.app"> - <detect path="$.trackingUI" value="History"> - <apply path="$.trackingUrl" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - </detect> - <detect path="$.trackingUI" value="ApplicationMaster"> - <apply path="$.trackingUrl" rule="RESOURCEMANAGER/resourcemanager/trackingUrlAM/outbound"/> - </detect> - <apply path="$.amContainerLogs" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - <apply path="$.amHostHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </buffer> - </content> - <content type="*/xml"> - <buffer path="/app"> - <detect path="trackingUI" value="History"> - <apply path="trackingUrl" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - </detect> - <detect path="trackingUI" value="ApplicationMaster"> - <apply path="trackingUrl" rule="RESOURCEMANAGER/resourcemanager/trackingUrlAM/outbound"/> - </detect> - <apply path="amContainerLogs" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - <apply path="amHostHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </buffer> - </content> - </filter> - - <filter name="RESOURCEMANAGER/resourcemanager/appattempts/outbound"> - <content type="*/json"> - <apply path="$.appAttempts.appAttempt[*].nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="$.appAttempts.appAttempt[*].logsLink" rule="RESOURCEMANAGER/resourcemanager/logsLink/outbound"/> - <apply path="$.appAttempts.appAttempt[*].nodeId" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - </content> - <content type="*/xml"> - <apply path="/appAttempts/appAttempt/nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="/appAttempts/appAttempt/logsLink" rule="RESOURCEMANAGER/resourcemanager/logsLink/outbound"/> - <apply path="/appAttempts/appAttempt/nodeId" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - </content> - </filter> - - <filter name="RESOURCEMANAGER/resourcemanager/nodes/outbound"> - <content type="*/json"> - <apply path="$.nodes.node[*].nodeHTTPAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="$.nodes.node[*].nodeHostName" rule="RESOURCEMANAGER/resourcemanager/host/outbound"/> - <apply path="$.nodes.node[*].id" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - </content> - <content type="*/xml"> - <apply path="/nodes/node/nodeHTTPAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="/nodes/node/nodeHostName" rule="RESOURCEMANAGER/resourcemanager/host/outbound"/> - <apply path="/nodes/node/id" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - </content> - </filter> - - <filter name="RESOURCEMANAGER/resourcemanager/node/outbound"> - <content type="*/json"> - <apply path="$.node.nodeHTTPAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="$.node.nodeHostName" rule="RESOURCEMANAGER/resourcemanager/host/outbound"/> - <apply path="$.node.id" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - </content> - <content type="*/xml"> - <apply path="/node/nodeHTTPAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="/node/nodeHostName" rule="RESOURCEMANAGER/resourcemanager/host/outbound"/> - <apply path="/node/id" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - </content> - </filter> - - <filter name="RESOURCEMANAGER/resourcemanager/proxy/jobattempts/outbound"> - <content type="*/json"> - <apply path="$.jobAttempts.jobAttempt[*].nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="$.jobAttempts.jobAttempt[*].nodeId" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - <apply path="$.jobAttempts.jobAttempt[*].logsLink" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - </content> - <content type="*/xml"> - <apply path="/jobAttempts/jobAttempt/nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - <apply path="/jobAttempts/jobAttempt/nodeId" rule="RESOURCEMANAGER/resourcemanager/nodeId/outbound"/> - <apply path="/jobAttempts/jobAttempt/logsLink" rule="RESOURCEMANAGER/resourcemanager/url/outbound"/> - </content> - </filter> - - <filter name="RESOURCEMANAGER/resourcemanager/proxy/taskattempts/outbound"> - <content type="*/json"> - <apply path="$.taskAttempts.taskAttempt[*].nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </content> - <content type="*/xml"> - <apply path="/taskAttempts/taskAttempt/nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </content> - </filter> - - <filter name="RESOURCEMANAGER/resourcemanager/proxy/taskattempt/outbound"> - <content type="*/json"> - <apply path="$.taskAttempt.nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </content> - <content type="*/xml"> - <apply path="/taskAttempt/nodeHttpAddress" rule="RESOURCEMANAGER/resourcemanager/hostport/outbound"/> - </content> - </filter> - -</rules> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-yarn-rm/src/test/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributorTest.java ---------------------------------------------------------------------- diff --git a/gateway-service-yarn-rm/src/test/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributorTest.java b/gateway-service-yarn-rm/src/test/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributorTest.java deleted file mode 100644 index 485e1f2..0000000 --- a/gateway-service-yarn-rm/src/test/java/org/apache/hadoop/gateway/yarn/rm/ResourceManagerDeploymentContributorTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.yarn.rm; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.fail; - -import java.util.Iterator; -import java.util.ServiceLoader; - -import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor; -import org.junit.Test; - -public class ResourceManagerDeploymentContributorTest { - - @SuppressWarnings("rawtypes") - @Test - public void testServiceLoader() throws Exception { - ServiceLoader loader = ServiceLoader.load( ServiceDeploymentContributor.class ); - Iterator iterator = loader.iterator(); - assertThat( "Service iterator empty.", iterator.hasNext() ); - while( iterator.hasNext() ) { - Object object = iterator.next(); - if( object instanceof ResourceManagerDeploymentContributor ) { - return; - } - } - fail( "Failed to find " + ResourceManagerDeploymentContributor.class.getName() + " via service loader." ); - } -} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/pom.xml ---------------------------------------------------------------------- diff --git a/gateway-spi/pom.xml b/gateway-spi/pom.xml index 506f4a0..11ddda7 100644 --- a/gateway-spi/pom.xml +++ b/gateway-spi/pom.xml @@ -48,6 +48,10 @@ </dependency> <dependency> <groupId>${gateway-group}</groupId> + <artifactId>gateway-util-configinjector</artifactId> + </dependency> + <dependency> + <groupId>${gateway-group}</groupId> <artifactId>gateway-util-urltemplate</artifactId> </dependency> @@ -91,7 +95,11 @@ <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> </dependency> - + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapter.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapter.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapter.java new file mode 100644 index 0000000..0bf1e6f --- /dev/null +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapter.java @@ -0,0 +1,39 @@ +/** + * 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.config; + + +import javax.servlet.FilterConfig; + +public class FilterConfigurationAdapter implements ConfigurationAdapter { + + private FilterConfig config; + + public FilterConfigurationAdapter(FilterConfig config) { + this.config = config; + } + + @Override + public Object getConfigurationValue(String name) throws ConfigurationException { + Object value = config.getInitParameter(name); + if (value == null) { + value = config.getServletContext().getAttribute(name); + } + return value; + } +} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapterDescriptor.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapterDescriptor.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapterDescriptor.java new file mode 100644 index 0000000..4d106e1 --- /dev/null +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/FilterConfigurationAdapterDescriptor.java @@ -0,0 +1,29 @@ +/** + * 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.config; + +import org.apache.hadoop.gateway.config.spi.AbstractConfigurationAdapterDescriptor; + +import javax.servlet.FilterConfig; + +public class FilterConfigurationAdapterDescriptor extends AbstractConfigurationAdapterDescriptor { + + public FilterConfigurationAdapterDescriptor() { + add(FilterConfig.class, FilterConfigurationAdapter.class); + } +} http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java index 010e25d..7d20e1a 100644 --- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java @@ -52,6 +52,12 @@ public interface GatewayConfig { */ String getGatewayDataDir(); + /** + * The location of the gateway stack definitions + * @return The location of the gateway stacks top level directory. + */ + String getGatewayStacksDir(); + String getHadoopConfDir(); String getGatewayHost(); http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributor.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributor.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributor.java index ba21928..19bc1d6 100644 --- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributor.java +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributor.java @@ -18,6 +18,7 @@ package org.apache.hadoop.gateway.deploy; import org.apache.hadoop.gateway.topology.Service; +import org.apache.hadoop.gateway.topology.Version; public interface ServiceDeploymentContributor { @@ -27,6 +28,8 @@ public interface ServiceDeploymentContributor { // The name of this service deployment contributor. Not used yet. String getName(); + Version getVersion(); + // Called after provider initializeContribution methods and in arbitrary order relative to other service contributors. void initializeContribution( DeploymentContext context ); http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributorBase.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributorBase.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributorBase.java index 4d33fa8..f82bad5 100644 --- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributorBase.java +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/deploy/ServiceDeploymentContributorBase.java @@ -21,6 +21,7 @@ import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor; import org.apache.hadoop.gateway.descriptor.ResourceDescriptor; import org.apache.hadoop.gateway.topology.Provider; import org.apache.hadoop.gateway.topology.Service; +import org.apache.hadoop.gateway.topology.Version; import java.net.URISyntaxException; import java.util.Collection; @@ -28,6 +29,11 @@ import java.util.List; public abstract class ServiceDeploymentContributorBase extends DeploymentContributorBase implements ServiceDeploymentContributor { + @Override + public Version getVersion() { + return new Version(); + } + public void initializeContribution( DeploymentContext context ) { // Noop. }