You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by su...@apache.org on 2015/02/12 18:49:46 UTC
[1/6] knox git commit: Combined commits done for KNOX-481, KNOX-483,
KNOX-487
Repository: knox
Updated Branches:
refs/heads/KNOX-481 9e0e3e8ce -> a1d43564d
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapter.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapter.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapter.java
new file mode 100755
index 0000000..6240d44
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapter.java
@@ -0,0 +1,38 @@
+/**
+ * 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.impl;
+
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+import org.apache.hadoop.gateway.config.ConfigurationException;
+
+import java.util.Properties;
+
+public class PropertiesConfigurationAdapter implements ConfigurationAdapter {
+
+ private Properties properties;
+
+ public PropertiesConfigurationAdapter( Properties properties ) {
+ this.properties = properties;
+ }
+
+ @Override
+ public Object getConfigurationValue( String name ) throws ConfigurationException {
+ return properties.getProperty( name );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapterDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapterDescriptor.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapterDescriptor.java
new file mode 100755
index 0000000..b93e49a
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/PropertiesConfigurationAdapterDescriptor.java
@@ -0,0 +1,30 @@
+/**
+ * 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.impl;
+
+import org.apache.hadoop.gateway.config.spi.AbstractConfigurationAdapterDescriptor;
+
+import java.util.Properties;
+
+public class PropertiesConfigurationAdapterDescriptor extends AbstractConfigurationAdapterDescriptor {
+
+ public PropertiesConfigurationAdapterDescriptor() {
+ add( Properties.class, PropertiesConfigurationAdapter.class );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/AbstractConfigurationAdapterDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/AbstractConfigurationAdapterDescriptor.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/AbstractConfigurationAdapterDescriptor.java
new file mode 100755
index 0000000..5372911
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/AbstractConfigurationAdapterDescriptor.java
@@ -0,0 +1,42 @@
+/**
+ * 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.spi;
+
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public abstract class AbstractConfigurationAdapterDescriptor implements ConfigurationAdapterDescriptor {
+
+ private static Map<Class<?>, Class<? extends ConfigurationAdapter>> ADAPTERS =
+ new HashMap<Class<?>, Class<? extends ConfigurationAdapter>>();
+
+ protected AbstractConfigurationAdapterDescriptor() {
+ }
+
+ protected void add( Class<?> configType, Class<? extends ConfigurationAdapter> adapterType ) {
+ ADAPTERS.put( configType, adapterType );
+ }
+
+ @Override
+ public Map<Class<?>, Class<? extends ConfigurationAdapter>> providedConfigurationAdapters() {
+ return ADAPTERS;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationAdapterDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationAdapterDescriptor.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationAdapterDescriptor.java
new file mode 100755
index 0000000..3e304d4
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationAdapterDescriptor.java
@@ -0,0 +1,28 @@
+/**
+ * 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.spi;
+
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+
+import java.util.Map;
+
+public interface ConfigurationAdapterDescriptor {
+
+ Map<Class<?>,Class<? extends ConfigurationAdapter>> providedConfigurationAdapters();
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationInjector.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationInjector.java
new file mode 100755
index 0000000..0bbd1d9
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/spi/ConfigurationInjector.java
@@ -0,0 +1,27 @@
+/**
+ * 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.spi;
+
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+import org.apache.hadoop.gateway.config.ConfigurationBinding;
+
+public interface ConfigurationInjector {
+
+ void configure(Object target, ConfigurationAdapter adapter, ConfigurationBinding binding);
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor b/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor
new file mode 100755
index 0000000..5a240e0
--- /dev/null
+++ b/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor
@@ -0,0 +1,20 @@
+##########################################################################
+# 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.config.impl.MapConfigurationAdapterDescriptor
+org.apache.hadoop.gateway.config.impl.PropertiesConfigurationAdapterDescriptor
+org.apache.hadoop.gateway.config.impl.BeanConfigurationAdapterDescriptor
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationInjector
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationInjector b/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationInjector
new file mode 100755
index 0000000..e3a0d65
--- /dev/null
+++ b/gateway-util-configinjector/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationInjector
@@ -0,0 +1,18 @@
+##########################################################################
+# 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.config.impl.DefaultConfigurationInjector
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/AdapterSampleTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/AdapterSampleTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/AdapterSampleTest.java
new file mode 100755
index 0000000..f3e392e
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/AdapterSampleTest.java
@@ -0,0 +1,57 @@
+/**
+ * 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.junit.Test;
+
+import java.util.Hashtable;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class AdapterSampleTest {
+
+ public static class Target {
+ @Configure
+ private String username = null;
+ }
+
+ public static class Adapter implements ConfigurationAdapter {
+ private Hashtable config;
+ public Adapter( Hashtable config ) {
+ this.config = config;
+ }
+ @Override
+ public Object getConfigurationValue( String name ) throws ConfigurationException {
+ Object value = config.get( name.toUpperCase() );
+ return value == null ? null : value.toString();
+ }
+ }
+
+ static Hashtable config = new Hashtable();
+ static{ config.put( "USERNAME", "somebody" ); }
+
+ @Test
+ public void sample() {
+ Target target = new Target();
+ Adapter adapter = new Adapter( config );
+ ConfigurationInjectorBuilder.configuration().target( target ).source( adapter ).inject();
+ assertThat( target.username, is( "somebody" ) );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/FuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/FuncTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/FuncTest.java
new file mode 100755
index 0000000..f4898ac
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/FuncTest.java
@@ -0,0 +1,379 @@
+/**
+ * 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.impl.MappedConfigurationBinding;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.core.AllOf.allOf;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.fail;
+
+import static org.apache.hadoop.gateway.config.ConfigurationInjectorBuilder.*;
+
+public class FuncTest {
+
+ public static class TestBean {
+ @Configure
+ String stringMember = "stringDefault";
+
+ @Configure
+ int intMember = 1;
+
+ @Configure
+ Integer integerMember = Integer.valueOf( 1 );
+
+ @Configure
+ public void setStringProp( String s ) {
+ stringPropField = s;
+ }
+ protected String stringPropField = "stringDefault";
+
+ @Configure
+ @Alias("altStringProp")
+ public void setNamedStringProp( String s ) {
+ stringPropFieldAlt = s;
+ }
+ protected String stringPropFieldAlt = "stringDefault";
+
+ @Configure
+ public void setNamedArgMethod( @Configure @Alias("altArgStringProp") String s ) {
+ stringPropFieldAltArg = s;
+ }
+ protected String stringPropFieldAltArg = "stringDefault";
+
+ @Configure
+ public void setMultiArgs(
+ @Configure @Alias("multiArg1") String s,
+ @Configure @Alias("multiArg2") Integer i,
+ @Configure @Alias("multiArg3") int n ) {
+ multiArgStringField = s;
+ multiArgIntegerField = i;
+ multiArgIntField = n;
+ }
+ String multiArgStringField = "default";
+ Integer multiArgIntegerField = 0;
+ int multiArgIntField = 0;
+
+ }
+
+ @Test
+ public void testMapOfStrings() {
+
+ Map<String,String> testConfig = new HashMap<String,String>();
+ testConfig.put( "stringMember", "stringValue" );
+ testConfig.put( "intMember", "2" );
+ testConfig.put( "integerMember", "2" );
+ testConfig.put( "stringProp", "stringValue" );
+ testConfig.put( "altStringProp", "stringValue" );
+ testConfig.put( "altArgStringProp", "stringValue" );
+ testConfig.put( "multiArg1", "stringValue" );
+ testConfig.put( "multiArg2", "42" );
+ testConfig.put( "multiArg3", "42" );
+
+ TestBean testBean = new TestBean();
+
+ configuration().target( testBean ).source( testConfig ).inject();
+
+ assertThat( testBean.stringMember, is( "stringValue" ) );
+ assertThat( testBean.intMember, is( 2 ) );
+ assertThat( testBean.integerMember, is( new Integer(2) ) );
+ assertThat( testBean.stringPropField, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );
+ assertThat( testBean.multiArgStringField, is( "stringValue" ) );
+ assertThat( testBean.multiArgIntegerField, is( 42 ) );
+ assertThat( testBean.multiArgIntField, is( 42 ) );
+ }
+
+ @Test
+ public void testProperties() {
+
+ Properties testConfig = new Properties();
+ testConfig.put( "stringMember", "stringValue" );
+ testConfig.put( "intMember", "2" );
+ testConfig.put( "integerMember", "2" );
+ testConfig.put( "stringProp", "stringValue" );
+ testConfig.put( "altStringProp", "stringValue" );
+ testConfig.put( "altArgStringProp", "stringValue" );
+ testConfig.put( "multiArg1", "stringValue" );
+ testConfig.put( "multiArg2", "42" );
+ testConfig.put( "multiArg3", "42" );
+
+ TestBean testBean = new TestBean();
+
+ configuration().target( testBean ).source( testConfig ).inject();
+
+ assertThat( testBean.stringMember, is( "stringValue" ) );
+ assertThat( testBean.intMember, is( 2 ) );
+ assertThat( testBean.integerMember, is( new Integer(2) ) );
+ assertThat( testBean.stringPropField, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );
+ assertThat( testBean.multiArgStringField, is( "stringValue" ) );
+ assertThat( testBean.multiArgIntegerField, is( 42 ) );
+ assertThat( testBean.multiArgIntField, is( 42 ) );
+ }
+
+ public static class TestAdapter implements ConfigurationAdapter {
+
+ private Map<String,String> config;
+
+ public TestAdapter( Map<String,String> config ) {
+ this.config = config;
+ }
+
+ @Override
+ public String getConfigurationValue( String name ) {
+ return config.get( name );
+ }
+
+ }
+
+ @Test
+ public void testExplicitProvider() {
+
+ Map<String,String> testConfig = new HashMap<String,String>();
+ testConfig.put( "stringMember", "stringValue" );
+ testConfig.put( "intMember", "2" );
+ testConfig.put( "integerMember", "2" );
+ testConfig.put( "stringProp", "stringValue" );
+ testConfig.put( "altStringProp", "stringValue" );
+ testConfig.put( "altArgStringProp", "stringValue" );
+ testConfig.put( "multiArg1", "stringValue" );
+ testConfig.put( "multiArg2", "42" );
+ testConfig.put( "multiArg3", "42" );
+
+ TestBean testBean = new TestBean();
+
+ configuration().target( testBean ).source( new TestAdapter( testConfig ) ).inject();
+
+ assertThat( testBean.stringMember, is( "stringValue" ) );
+ assertThat( testBean.intMember, is( 2 ) );
+ assertThat( testBean.integerMember, is( new Integer(2) ) );
+ assertThat( testBean.stringPropField, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );
+ assertThat( testBean.multiArgStringField, is( "stringValue" ) );
+ assertThat( testBean.multiArgIntegerField, is( 42 ) );
+ assertThat( testBean.multiArgIntField, is( 42 ) );
+ }
+
+ @Test
+ public void testMapOfObjects() {
+
+ Map<Object,Object> testConfig = new HashMap<Object,Object>();
+ testConfig.put( "stringMember", "stringValue" );
+ testConfig.put( "intMember", 42 );
+ testConfig.put( "integerMember", new Integer(42) );
+ testConfig.put( "stringProp", "stringValue" );
+ testConfig.put( "altStringProp", "stringValue" );
+ testConfig.put( "altArgStringProp", "stringValue" );
+ testConfig.put( "multiArg1", "stringValue" );
+ testConfig.put( "multiArg2", new Integer(42) );
+ testConfig.put( "multiArg3", "42" );
+
+ TestBean testBean = new TestBean();
+
+ configuration().target( testBean ).source( testConfig ).inject();
+
+ assertThat( testBean.stringMember, is( "stringValue" ) );
+ assertThat( testBean.intMember, is( 42 ) );
+ assertThat( testBean.integerMember, is( new Integer(42) ) );
+ assertThat( testBean.stringPropField, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAlt, is( "stringValue" ) );
+ assertThat( testBean.stringPropFieldAltArg, is( "stringValue" ) );
+ assertThat( testBean.multiArgStringField, is( "stringValue" ) );
+ assertThat( testBean.multiArgIntegerField, is( 42 ) );
+ assertThat( testBean.multiArgIntField, is( 42 ) );
+ }
+
+ public class Target {
+ @Configure @Alias("user.name")
+ private String user;
+ }
+
+ public class Adapter implements ConfigurationAdapter {
+ @Override
+ public Object getConfigurationValue( String name ) throws ConfigurationException {
+ return System.getProperty( name );
+ }
+ }
+
+ @Test
+ public void testFactoryConfigurationDirect() {
+ Target target = new Target();
+ configuration().target( target ).source( System.getProperties() ).inject();
+ assertThat( target.user, is( System.getProperty( "user.name" ) ) );
+ }
+
+ @Test
+ public void testFactoryConfigurationAdapter() {
+ Target target = new Target();
+ configuration().target( target ).source( new Adapter() ).inject();
+ assertThat( target.user, is( System.getProperty( "user.name" ) ) );
+ }
+
+ @Test
+ public void testMissingRequiredFieldConfiguration() {
+ class RequiredFieldTarget {
+ @Configure
+ private String required;
+ }
+ RequiredFieldTarget target = new RequiredFieldTarget();
+ try {
+ configuration().target( target ).source( System.getProperties() ).inject();
+ fail( "Expected an exception because the configuration values could not be populated." );
+ } catch ( ConfigurationException e ) {
+ assertThat( e.getMessage(), allOf(containsString("Failed"),containsString( "find" ),containsString( "required" )) );
+ }
+ }
+
+ @Test
+ public void testMissingOptionalFieldConfiguration() {
+ class OptionalFieldTarget {
+ @Configure
+ @Optional
+ private String optional = "default";
+ }
+ OptionalFieldTarget target = new OptionalFieldTarget();
+ configuration().target( target ).source( System.getProperties() ).inject();
+ assertThat( target.optional, is("default") );
+ }
+
+ @Test
+ public void testMissingRequiredConfigurationParameter() {
+ class Target {
+ private String field;
+ @Configure
+ public void setRequired(String value) {
+ field = value;
+ }
+ }
+ Target target = new Target();
+ try {
+ configuration().target( target ).source( System.getProperties() ).inject();
+ fail( "Expected an exception because the configuration values could not be populated." );
+ } catch ( ConfigurationException e ) {
+ assertThat( e.getMessage(), allOf(containsString("Failed"),containsString( "find" ),containsString( "required" )) );
+ }
+ }
+
+ @Test
+ public void testMissingRequiredConfigurationParameterWithDefault() {
+ class Target {
+ private String field;
+ @Configure
+ public void setRequired(@Default("default")String value) {
+ field = value;
+ }
+ }
+ Target target = new Target();
+ configuration().target( target ).source( System.getProperties() ).inject();
+ assertThat( target.field, is( "default" ) );
+ }
+
+ @Test
+ public void testTwoMissingRequiredConfigurationParameterWithDefault() {
+ class Target {
+ private String field1;
+ private String field2;
+ @Configure
+ public void setRequired(@Default("default1")String value1, @Default("default2")String value2) {
+ field1 = value1;
+ field2 = value2;
+ }
+ }
+ Target target = new Target();
+ configuration().target( target ).source( System.getProperties() ).inject();
+ assertThat( target.field1, is( "default1" ) );
+ assertThat( target.field2, is("default2") );
+ }
+
+ @Test
+ public void testFieldBinding() {
+ class Target {
+ @Configure
+ private String user;
+ }
+ class Binding extends MappedConfigurationBinding {
+ Binding() {
+ bind("user","user.name");
+ }
+ }
+ Target target = new Target();
+ Properties source = System.getProperties();
+ ConfigurationBinding binding = new Binding();
+ configuration().target( target ).source( source ).binding( binding ).inject();
+ assertThat( target.user, is(System.getProperty("user.name")));
+
+ }
+
+ @Test
+ public void testFieldBindingUsingBuilderBinding() {
+ class Target {
+ @Configure
+ private String user;
+ }
+ Target target = new Target();
+ Properties source = System.getProperties();
+ configuration().target( target ).source( source ).bind( "user", "user.name" ).inject();
+ assertThat( target.user, is(System.getProperty("user.name")));
+
+ }
+
+ @Test
+ public void testFieldBindingUsingBuilderBindingFactory() {
+ class Target {
+ @Configure
+ private String user;
+ }
+ Target target = new Target();
+ Properties source = System.getProperties();
+ ConfigurationBinding binding = configuration().bind( "user", "user.name" ).binding();
+ configuration().target( target ).source( source ).binding( binding ).inject();
+ assertThat( target.user, is( System.getProperty( "user.name" ) ) );
+
+ }
+
+ public static class UserBean {
+ public String getPrincipal() {
+ return "test-user";
+ }
+ }
+
+ @Test
+ public void testBeanAdapter() {
+ Target target = new Target();
+ UserBean bean = new UserBean();
+ configuration()
+ .target( target )
+ .source( bean )
+ .bind( "user.name", "principal" )
+ .inject();
+ assertThat( target.user, is( "test-user" ) );
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapFieldSampleTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapFieldSampleTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapFieldSampleTest.java
new file mode 100755
index 0000000..b9336b5
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapFieldSampleTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class MapFieldSampleTest {
+
+ public static class Target {
+ @Configure
+ private int retryLimit = 3;
+ }
+
+ static Map<String,String> config = new HashMap<String,String>();
+ static { config.put( "retryLimit", "5" ); }
+
+ @Test
+ public void sample() {
+ Target target = new Target();
+ ConfigurationInjectorBuilder.configuration().target( target ).source( config ).inject();
+ assertThat( target.retryLimit, is(5) );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapMethodSampleTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapMethodSampleTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapMethodSampleTest.java
new file mode 100755
index 0000000..96f46ec
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/MapMethodSampleTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.config;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class MapMethodSampleTest {
+
+ public static class Target {
+ private int limit = 3;
+
+ @Configure
+ public void setRetryLimit( int value ) {
+ limit = value;
+ }
+ }
+
+ static Map<String,String> config = new HashMap<String,String>();
+ static { config.put( "retryLimit", "5" ); }
+
+ @Test
+ public void sample() {
+ Target target = new Target();
+ ConfigurationInjectorBuilder.configuration().target( target ).source( config ).inject();
+ assertThat( target.limit, is( 5 ) );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFactorySampleTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFactorySampleTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFactorySampleTest.java
new file mode 100755
index 0000000..2adbe72
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFactorySampleTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.junit.Test;
+
+import static org.apache.hadoop.gateway.config.ConfigurationInjectorBuilder.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class PropertiesFactorySampleTest {
+
+ public static class Target {
+ @Configure @Alias("user.name")
+ private String user = "nobody";
+ }
+
+ @Test
+ public void sampleDirect() {
+ Target target = new Target();
+ configuration().target( target ).source( System.getProperties() ).inject();
+ assertThat( target.user, is( System.getProperty( "user.name" ) ) );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFieldSampleTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFieldSampleTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFieldSampleTest.java
new file mode 100755
index 0000000..db0af61
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesFieldSampleTest.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 org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class PropertiesFieldSampleTest {
+
+ public static class Target {
+ @Configure @Alias("user.name")
+ private String user = "nobody";
+ }
+
+ @Test
+ public void sample() {
+ Target target = new Target();
+ ConfigurationInjectorBuilder.configuration().target( target ).source( System.getProperties() ).inject();
+ assertThat( target.user, is( System.getProperty( "user.name" ) ) );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesMethodSampleTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesMethodSampleTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesMethodSampleTest.java
new file mode 100755
index 0000000..4b72e3b
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/PropertiesMethodSampleTest.java
@@ -0,0 +1,57 @@
+/**
+ * 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.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class PropertiesMethodSampleTest {
+
+ public static class Target {
+
+ private String user = "nobody";
+ private String home = "nowhere";
+ private String temp = "nowhere";
+
+ @Configure
+ @Alias("user.name")
+ public void setUser( String value ) {
+ user = value;
+ }
+
+ @Configure
+ public void setDirs(
+ @Alias("user.dir") String home,
+ @Alias("java.io.tmpdir") String temp ) {
+ this.home = home;
+ this.temp = temp;
+ }
+ }
+
+ @Test
+ public void sample() {
+ Target target = new Target();
+ ConfigurationInjectorBuilder.configuration().target( target ).source( System.getProperties() ).inject();
+ assertThat( target.user, is( System.getProperty( "user.name" ) ) );
+ assertThat( target.home, is( System.getProperty( "user.dir" ) ) );
+ assertThat( target.temp, is( System.getProperty( "java.io.tmpdir" ) ) );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/UsageTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/UsageTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/UsageTest.java
new file mode 100755
index 0000000..2fe963a
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/UsageTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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.junit.Test;
+import static org.apache.hadoop.gateway.config.ConfigurationInjectorBuilder.configuration;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class UsageTest {
+
+ class Target {
+ @Configure
+ private String user;
+ }
+
+ @Test
+ public void usage() {
+ Target target = new Target();
+ configuration()
+ .target( target )
+ .source( System.getProperties() )
+ .bind( "user", "user.name" )
+ .inject();
+ assertThat( target.user, is(System.getProperty("user.name")));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
new file mode 100755
index 0000000..80913e2
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptorTest.java
@@ -0,0 +1,57 @@
+/**
+ * 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.impl;
+
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+import org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor;
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+import static junit.framework.TestCase.fail;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasKey;
+
+public class BeanConfigurationAdapterDescriptorTest {
+
+ @Test
+ public void testServiceLoader() {
+ ServiceLoader<ConfigurationAdapterDescriptor> loader = ServiceLoader.load( ConfigurationAdapterDescriptor.class );
+ Iterator<ConfigurationAdapterDescriptor> i = loader.iterator();
+ while( i.hasNext() ) {
+ if( i.next() instanceof BeanConfigurationAdapterDescriptor ) {
+ return;
+ }
+ }
+ fail( "Failed to load BeanConfigurationAdapterDescriptor" );
+ }
+
+ @Test
+ public void testDescriptor() {
+ ConfigurationAdapterDescriptor descriptor = new BeanConfigurationAdapterDescriptor();
+ Map<Class<?>,Class<? extends ConfigurationAdapter>> map = descriptor.providedConfigurationAdapters();
+ assertThat( map, hasKey( (Class)Object.class ) );
+ Class<? extends ConfigurationAdapter> type = map.get( Object.class );
+ assertThat(
+ "Descriptor didn't return " + BeanConfigurationAdapter.class.getName(),
+ type == BeanConfigurationAdapter.class );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterTest.java b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterTest.java
new file mode 100755
index 0000000..0d36eb6
--- /dev/null
+++ b/gateway-util-configinjector/src/test/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.impl;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class BeanConfigurationAdapterTest {
+
+ public static class Bean {
+ public String getValue() {
+ return "beanValue";
+ };
+ }
+
+ @Test
+ public void test() {
+ Bean bean = new Bean();
+ BeanConfigurationAdapter adapter = new BeanConfigurationAdapter( bean );
+ assertThat( adapter.getConfigurationValue( "value" ).toString(), is( "beanValue" ) );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/hsso-release/pom.xml
----------------------------------------------------------------------
diff --git a/hsso-release/pom.xml b/hsso-release/pom.xml
index df85c52..c5abf8e 100644
--- a/hsso-release/pom.xml
+++ b/hsso-release/pom.xml
@@ -119,21 +119,13 @@
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-oozie</artifactId>
- </dependency>
- <dependency>
- <groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-webhcat</artifactId>
+ <artifactId>gateway-service-definitions</artifactId>
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
<artifactId>gateway-service-tgs</artifactId>
</dependency>
<dependency>
- <groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-yarn-rm</artifactId>
- </dependency>
- <dependency>
<groupId>${gateway-group}</groupId>
<artifactId>gateway-provider-rewrite</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e121942..f980c97 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,7 @@
<modules>
<module>gateway-test-utils</module>
<module>gateway-util-common</module>
+ <module>gateway-util-configinjector</module>
<module>gateway-util-launcher</module>
<module>gateway-util-urltemplate</module>
<module>gateway-test-ldap</module>
@@ -65,10 +66,8 @@
<module>gateway-service-hbase</module>
<module>gateway-service-hive</module>
<module>gateway-service-webhdfs</module>
- <module>gateway-service-oozie</module>
- <module>gateway-service-webhcat</module>
<module>gateway-service-tgs</module>
- <module>gateway-service-yarn-rm</module>
+ <module>gateway-service-definitions</module>
<module>gateway-shell</module>
<module>gateway-shell-launcher</module>
<module>knox-cli-launcher</module>
@@ -351,6 +350,11 @@
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
+ <artifactId>gateway-util-configinjector</artifactId>
+ <version>${gateway-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${gateway-group}</groupId>
<artifactId>gateway-util-launcher</artifactId>
<version>${gateway-version}</version>
</dependency>
@@ -486,17 +490,7 @@
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-webhcat</artifactId>
- <version>${gateway-version}</version>
- </dependency>
- <dependency>
- <groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-yarn-rm</artifactId>
- <version>${gateway-version}</version>
- </dependency>
- <dependency>
- <groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-oozie</artifactId>
+ <artifactId>gateway-service-definitions</artifactId>
<version>${gateway-version}</version>
</dependency>
<dependency>
@@ -608,7 +602,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.2.5</version>
+ <version>4.3.6</version>
</dependency>
<!--
@@ -818,7 +812,11 @@
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
-
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-digester3</artifactId>
[4/6] knox git commit: Combined commits done for KNOX-481, KNOX-483,
KNOX-487
Posted by su...@apache.org.
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml
new file mode 100644
index 0000000..d3c52bb
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml
@@ -0,0 +1,122 @@
+<!--
+ 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-definitions/src/main/resources/services/oozie/4.0.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/service.xml b/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/service.xml
new file mode 100644
index 0000000..7bc7eb3
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/service.xml
@@ -0,0 +1,30 @@
+<?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.
+-->
+<service role="OOZIE" name="oozie" version="4.0.0">
+ <routes>
+ <route path="/oozie/**?**">
+ <rewrite apply="OOZIE/oozie/configuration" to="request.body"/>
+ </route>
+ <route path="/oozie/v1/**?**">
+ <rewrite apply="OOZIE/oozie/configuration" to="request.body"/>
+ </route>
+ <route path="/oozie/v2/**?**">
+ <rewrite apply="OOZIE/oozie/configuration" to="request.body"/>
+ </route>
+ </routes>
+</service>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/rewrite.xml
new file mode 100644
index 0000000..558abb4
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/rewrite.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<rules>
+
+ <rule dir="IN" name="WEBHCAT/webhcat/root/inbound" pattern="*://*:*/**/templeton/v1/?{**}">
+ <rewrite template="{$serviceUrl[WEBHCAT]}/v1/?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHCAT/webhcat/path/inbound" pattern="*://*:*/**/templeton/v1/{path=**}?{**}">
+ <rewrite template="{$serviceUrl[WEBHCAT]}/v1/{path=**}?{**}"/>
+ </rule>
+
+</rules>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/service.xml b/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/service.xml
new file mode 100644
index 0000000..c550dc1
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/webhcat/0.13.0/service.xml
@@ -0,0 +1,23 @@
+<?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.
+-->
+<service role="WEBHCAT" name="webhcat" version="0.13.0">
+ <routes>
+ <route path="/templeton/v1/?**"/>
+ <route path="/templeton/v1/**?**"/>
+ </routes>
+</service>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/rewrite.xml
new file mode 100644
index 0000000..efbd93d
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/rewrite.xml
@@ -0,0 +1,70 @@
+<?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="OUT" name="WEBHDFS/webhdfs/outbound" pattern="hdfs://*:*/{path=**}?{**}">
+ <rewrite template="{$frontend[url]}/webhdfs/v1/{path=**}?{**}"/>
+ </rule>
+
+ <rule dir="OUT" name="WEBHDFS/webhdfs/outbound" pattern="webhdfs://*:*/{path=**}?{**}">
+ <rewrite template="{$frontend[url]}/webhdfs/v1/{path=**}?{**}"/>
+ </rule>
+
+ <rule dir="OUT" name="WEBHDFS/webhdfs/outbound/namenode/headers/location">
+ <match pattern="{scheme}://{host}:{port}/{path=**}?{**}"/>
+ <rewrite template="{$frontend[url]}/webhdfs/data/v1/{path=**}?{scheme}?host={$hostmap(host)}?{port}?{**}"/>
+ <encrypt-query/>
+ </rule>
+
+ <rule dir="IN" name="WEBHDFS/webhdfs/inbound/hdfs" pattern="hdfs:/{path=**}?{**}">
+ <rewrite template="{$serviceMappedUrl[NAMENODE]}/{path=**}?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHDFS/webhdfs/inbound/webhdfs" pattern="webhdfs:/{path=**}?{**}">
+ <rewrite template="{$serviceUrl[WEBHDFS]}/{path=**}?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHDFS/webhdfs/inbound/namenode/root" pattern="*://*:*/**/webhdfs/{version}/?{**}">
+ <rewrite template="{$serviceUrl[WEBHDFS]}/{version}/?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHDFS/webhdfs/inbound/namenode/file" pattern="*://*:*/**/webhdfs/{version}/{path=**}?{**}">
+ <rewrite template="{$serviceUrl[WEBHDFS]}/{version}/{path=**}?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHDFS/webhdfs/inbound/namenode/home" pattern="*://*:*/**/webhdfs/{version}/~?{**}">
+ <rewrite template="{$serviceUrl[WEBHDFS]}/{version}/user/{$username}?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHDFS/webhdfs/inbound/namenode/home/file" pattern="*://*:*/**/webhdfs/{version}/~/{path=**}?{**}">
+ <rewrite template="{$serviceUrl[WEBHDFS]}/{version}/user/{$username}/{path=**}?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHDFS/webhdfs/inbound/datanode">
+ <decrypt-query/>
+ <match pattern="*://*:*/**/webhdfs/data/*/{path=**}?{scheme}?{host}?{port}?{**}"/>
+ <rewrite template="{scheme}://{host}:{port}/{path=**}?{**}"/>
+ </rule>
+
+ <filter name="WEBHDFS/webhdfs/outbound/namenode/headers">
+ <content type="application/x-http-headers">
+ <apply path="Location" rule="WEBHDFS/webhdfs/outbound/namenode/headers/location"/>
+ </content>
+ </filter>
+
+</rules>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml b/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
new file mode 100644
index 0000000..2470175
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
@@ -0,0 +1,40 @@
+<?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.
+-->
+<service role="WEBHDFS" name="webhdfs" version="2.4.0">
+ <routes>
+ <route path="/webhdfs/v1/?**">
+ <rewrite apply="WEBHDFS/webhdfs/inbound/namenode/root" to="request.url"/>
+ </route>
+ <route path="/webhdfs/v1/**?**">
+ <rewrite apply="WEBHDFS/webhdfs/inbound/namenode/file" to="request.url"/>
+ <rewrite apply="WEBHDFS/webhdfs/outbound/namenode/headers" to="response.headers"/>
+ </route>
+ <route path="/webhdfs/v1/~?**">
+ <rewrite apply="WEBHDFS/webhdfs/inbound/namenode/home" to="request.url"/>
+ </route>
+ <route path="/webhdfs/v1/~/**?**">
+ <rewrite apply="WEBHDFS/webhdfs/inbound/namenode/home/file" to="request.url"/>
+ <rewrite apply="WEBHDFS/webhdfs/outbound/namenode/headers" to="response.headers"/>
+ </route>
+ <route path="/webhdfs/data/v1/**?**">
+ <rewrite apply="WEBHDFS/webhdfs/inbound/datanode" to="request.url"/>
+ <dispatch contributor-name="http-client" />
+ </route>
+ </routes>
+ <dispatch classname="org.apache.hadoop.gateway.hdfs.dispatch.HdfsDispatch" ha-classname="org.apache.hadoop.gateway.hdfs.dispatch.WebHdfsHaHttpClientDispatch"/>
+</service>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/rewrite.xml
new file mode 100644
index 0000000..95ce2a3
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/rewrite.xml
@@ -0,0 +1,193 @@
+<?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-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml b/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
new file mode 100644
index 0000000..73fb771
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/yarn-rm/2.5.0/service.xml
@@ -0,0 +1,54 @@
+<?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.
+-->
+<service role="RESOURCEMANAGER" name="resourcemanager" version="2.5.0">
+ <routes>
+ <route path="/resourcemanager/v1/cluster/"/>
+ <route path="/resourcemanager/v1/cluster/**?**"/>
+ <route path="/resourcemanager/v1/cluster/apps?**">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/apps/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/v1/cluster/apps?**">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/apps/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/v1/cluster/apps/*?**">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/app/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/v1/cluster/apps/*/appattempts?**">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/appattempts/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/v1/cluster/nodes?**">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/nodes/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/v1/cluster/nodes/*?**">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/nodeId/inbound" to="request.url"/>
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/node/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/proxy/*/ws/v1/**?**">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/inbound/proxy" to="request.url"/>
+ </route>
+ <route path="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/jobattempts">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/proxy/jobattempts/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/proxy/taskattempts/outbound" to="response.body"/>
+ </route>
+ <route path="/resourcemanager/proxy/*/ws/v1/mapreduce/jobs/*/tasks/*/attempts/*">
+ <rewrite apply="RESOURCEMANAGER/resourcemanager/proxy/taskattempt/outbound" to="response.body"/>
+ </route>
+ </routes>
+</service>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java b/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
new file mode 100644
index 0000000..62fb23e
--- /dev/null
+++ b/gateway-service-definitions/src/test/java/org/apache/hadoop/gateway/service/definition/ServiceDefinitionTest.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import org.junit.Test;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import java.net.URL;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class ServiceDefinitionTest {
+
+ @Test
+ public void testUnmarshalling() throws Exception {
+ JAXBContext context = JAXBContext.newInstance(ServiceDefinition.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ URL url = ClassLoader.getSystemResource("services/yarn-rm/2.5.0/service.xml");
+ ServiceDefinition definition = (ServiceDefinition) unmarshaller.unmarshal(url.openStream());
+ assertEquals("resourcemanager", definition.getName());
+ assertEquals("RESOURCEMANAGER", definition.getRole());
+ assertEquals("2.5.0", definition.getVersion());
+ List<Route> bindings = definition.getRoutes();
+ assertNotNull(bindings);
+ assertEquals(12, bindings.size());
+ assertNotNull(bindings.get(0).getPath());
+ url = ClassLoader.getSystemResource("services/hbase/0.98.0/service.xml");
+ definition = (ServiceDefinition) unmarshaller.unmarshal(url.openStream());
+ assertNotNull(definition.getDispatch());
+ assertEquals("org.apache.hadoop.gateway.hbase.HBaseHttpClientDispatch", definition.getDispatch().getClassName());
+ url = ClassLoader.getSystemResource("services/webhdfs/2.4.0/service.xml");
+ definition = (ServiceDefinition) unmarshaller.unmarshal(url.openStream());
+ assertNotNull(definition.getDispatch());
+ assertEquals("org.apache.hadoop.gateway.hdfs.dispatch.HdfsDispatch", definition.getDispatch().getClassName());
+ assertEquals("org.apache.hadoop.gateway.hdfs.dispatch.WebHdfsHaHttpClientDispatch", definition.getDispatch().getHaClassName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/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
deleted file mode 100644
index 15372ec..0000000
--- a/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseDeploymentContributor.java
+++ /dev/null
@@ -1,133 +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.hbase;
-
-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.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;
-
-public class HBaseDeploymentContributor extends ServiceDeploymentContributorBase {
-
- private static final String RULES_RESOURCE = HBaseDeploymentContributor.class.getName().replace( '.', '/' ) + "/rewrite.xml";
- private static final String EXTERNAL_PATH = "/hbase";
-
- @Override
- public String getRole() {
- return "WEBHBASE";
- }
-
- @Override
- public String getName() {
- return "webhbase";
- }
-
- @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 hbaseRules = loadRulesFromTemplate();
- UrlRewriteRulesDescriptor clusterRules = context.getDescriptor( "rewrite" );
- clusterRules.addRules( hbaseRules );
- }
-
- private void contributeResources( DeploymentContext context, Service service ) throws URISyntaxException {
- List<FilterParamDescriptor> params;
-
- ResourceDescriptor rootResource = context.getGatewayDescriptor().addResource();
- rootResource.role( service.getRole() );
- rootResource.pattern( EXTERNAL_PATH + "/?**" );
- addWebAppSecFilters(context, service, rootResource);
- addAuthenticationFilter( context, service, rootResource );
- params = new ArrayList<FilterParamDescriptor>();
- params.add( rootResource.createFilterParam().name( "response.headers" ).value( getQualifiedName() + "/headers/outbound" ) );
- addRewriteFilter( context, service, rootResource, params );
- addIdentityAssertionFilter( context, service, rootResource );
- addAuthorizationFilter(context, service, rootResource);
- addDispatchFilter( context, service, rootResource );
-
- ResourceDescriptor pathResource = context.getGatewayDescriptor().addResource();
- pathResource.role( service.getRole() );
- pathResource.pattern( EXTERNAL_PATH + "/**?**" );
- addWebAppSecFilters(context, service, pathResource);
- addAuthenticationFilter( context, service, pathResource );
- params = new ArrayList<FilterParamDescriptor>();
- params.add( rootResource.createFilterParam().name( "response.headers" ).value( getQualifiedName() + "/headers/outbound" ) );
- addRewriteFilter( context, service, pathResource, params );
- addIdentityAssertionFilter( context, service, pathResource );
- addAuthorizationFilter(context, service, pathResource);
- addDispatchFilter( context, service, pathResource );
-
- ResourceDescriptor statusResource = context.getGatewayDescriptor().addResource();
- statusResource.role( service.getRole() );
- statusResource.pattern( EXTERNAL_PATH + "/status/cluster?**" );
- addWebAppSecFilters(context, service, statusResource);
- addAuthenticationFilter( context, service, statusResource );
- params = new ArrayList<FilterParamDescriptor>();
- params.add( statusResource.createFilterParam().name( "response.body" ).value( getQualifiedName() + "/status/outbound" ) );
- addRewriteFilter( context, service, statusResource, params );
- addIdentityAssertionFilter( context, service, statusResource );
- addAuthorizationFilter(context, service, statusResource);
- addDispatchFilter( context, service, statusResource );
-
- ResourceDescriptor regionResource = context.getGatewayDescriptor().addResource();
- regionResource.role( service.getRole() );
- regionResource.pattern( EXTERNAL_PATH + "/*/regions?**" );
- addWebAppSecFilters(context, service, regionResource);
- addAuthenticationFilter( context, service, regionResource );
- params = new ArrayList<FilterParamDescriptor>();
- params.add( regionResource.createFilterParam().name( "response.body" ).value( getQualifiedName() + "/regions/outbound" ) );
- addRewriteFilter( context, service, regionResource, params );
- addIdentityAssertionFilter( context, service, regionResource );
- addAuthorizationFilter(context, service, regionResource);
- addDispatchFilter( context, service, regionResource );
- }
-
- private void addDispatchFilter(
- DeploymentContext context, Service service, ResourceDescriptor resource ) {
- context.contributeFilter( service, resource, "dispatch", "hbase", null );
- }
-
- private String getQualifiedName() {
- return getRole() + "/" + getName();
- }
-
- 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributor.java b/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributor.java
deleted file mode 100644
index d2b4ce0..0000000
--- a/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributor.java
+++ /dev/null
@@ -1,70 +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.hbase;
-
-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.topology.Provider;
-import org.apache.hadoop.gateway.topology.Service;
-
-import java.util.List;
-import java.util.Map;
-
-public class HBaseDispatchDeploymentContributor extends ProviderDeploymentContributorBase {
-
- private static final String REPLAY_BUFFER_SIZE_PARAM = "replayBufferSize";
-
- // Default global replay buffer size in KB
- public static final String DEFAULT_REPLAY_BUFFER_SIZE = "8";
-
- @Override
- public String getRole() {
- return "dispatch";
- }
-
- @Override
- public String getName() {
- return "hbase";
- }
-
- @Override
- public void contributeFilter( DeploymentContext context, Provider provider, Service service, ResourceDescriptor resource, List<FilterParamDescriptor> params ) {
- FilterDescriptor filter = resource.addFilter().name( getName() ).role( getRole() ).impl( HBaseHttpClientDispatch.class );
-
- FilterParamDescriptor filterParam = filter.param().name( REPLAY_BUFFER_SIZE_PARAM ).value( DEFAULT_REPLAY_BUFFER_SIZE );
- for ( Map.Entry<String,String> serviceParam : service.getParams().entrySet() ) {
- if ( REPLAY_BUFFER_SIZE_PARAM.equals( serviceParam.getKey() ) ) {
- filterParam.value( serviceParam.getValue() );
- }
- }
- if ( params != null ) {
- for ( FilterParamDescriptor customParam : params ) {
- if ( REPLAY_BUFFER_SIZE_PARAM.equals( customParam.name() ) ) {
- filterParam.value( customParam.value() );
- }
- }
- }
-
- if( context.getGatewayConfig().isHadoopKerberosSecured() ) {
- filter.param().name("kerberos").value("true");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseHttpClientDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseHttpClientDispatch.java b/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseHttpClientDispatch.java
index a569692..0d39950 100644
--- a/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseHttpClientDispatch.java
+++ b/gateway-service-hbase/src/main/java/org/apache/hadoop/gateway/hbase/HBaseHttpClientDispatch.java
@@ -29,8 +29,9 @@ import javax.servlet.ServletException;
public class HBaseHttpClientDispatch extends HttpClientDispatch {
@Override
- public void init( FilterConfig filterConfig ) throws ServletException {
- super.init( filterConfig, new HBaseCookieManager() );
+ public void init() {
+ super.init();
+ setAppCookieManager(new HBaseCookieManager());
}
}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor b/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
deleted file mode 100644
index 610bfbb..0000000
--- a/gateway-service-hbase/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
+++ /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.hbase.HBaseDispatchDeploymentContributor
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/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
deleted file mode 100644
index 5fc751f..0000000
--- a/gateway-service-hbase/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.hbase.HBaseDeploymentContributor
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDeploymentContributorTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDeploymentContributorTest.java b/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDeploymentContributorTest.java
deleted file mode 100644
index 3c8c1b1..0000000
--- a/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDeploymentContributorTest.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.hbase;
-
-import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor;
-import org.junit.Test;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.fail;
-
-public class HBaseDeploymentContributorTest {
-
- @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 HBaseDeploymentContributor ) {
- return;
- }
- }
- fail( "Failed to find " + HBaseDeploymentContributor.class.getName() + " via service loader." );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributorTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributorTest.java b/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributorTest.java
deleted file mode 100644
index e2b4d10..0000000
--- a/gateway-service-hbase/src/test/java/org/apache/hadoop/gateway/hbase/HBaseDispatchDeploymentContributorTest.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.hbase;
-
-import org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor;
-import org.junit.Test;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.fail;
-
-public class HBaseDispatchDeploymentContributorTest {
-
- @Test
- public void testServiceLoader() throws Exception {
- ServiceLoader loader = ServiceLoader.load( ProviderDeploymentContributor.class );
- Iterator iterator = loader.iterator();
- assertThat( "Service iterator empty.", iterator.hasNext() );
- while( iterator.hasNext() ) {
- Object object = iterator.next();
- if( object instanceof HBaseDispatchDeploymentContributor ) {
- return;
- }
- }
- fail( "Failed to find " + HBaseDispatchDeploymentContributor.class.getName() + " via service loader." );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDeploymentContributor.java b/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDeploymentContributor.java
deleted file mode 100644
index eb3779f..0000000
--- a/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDeploymentContributor.java
+++ /dev/null
@@ -1,84 +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.hive;
-
-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.topology.Service;
-
-import java.net.URISyntaxException;
-
-public class HiveDeploymentContributor extends ServiceDeploymentContributorBase {
-
- private static final String ROLE = "HIVE";
- private static final String NAME = "hive";
- private static final String EXTERNAL_PATH = "/hive";
-
- @Override
- public String getRole() {
- return ROLE;
- }
-
- @Override
- public String getName() {
- return NAME;
- }
-
- @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;
-
- rule = rules.addRule( getRole() + "/" + getName() + "/inbound" )
- .directions( "inbound" )
- .pattern( "*://*:*/**" + EXTERNAL_PATH );
- rewrite = rule.addStep( "rewrite" );
- rewrite.template( service.getUrl() );
- }
-
- public void contributeResources( DeploymentContext context, Service service ) throws URISyntaxException {
- ResourceDescriptor rootResource = context.getGatewayDescriptor().addResource();
- rootResource.role( service.getRole() );
- rootResource.pattern( EXTERNAL_PATH );
- addWebAppSecFilters(context, service, rootResource);
- addAuthenticationFilter( context, service, rootResource );
- addRewriteFilter( context, service, rootResource );
- addIdentityAssertionFilter( context, service, rootResource );
- addAuthorizationFilter(context, service, rootResource);
- addDispatchFilter( context, service, rootResource );
- }
-
- private void addRewriteFilter(
- DeploymentContext context, Service service, ResourceDescriptor resource ) throws URISyntaxException {
- context.contributeFilter( service, resource, "rewrite", null, null );
- }
-
- private void addDispatchFilter( DeploymentContext context, Service service, ResourceDescriptor resource ) {
- context.contributeFilter( service, resource, "dispatch", "hive", null );
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributor.java b/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributor.java
deleted file mode 100644
index 00b13d9..0000000
--- a/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributor.java
+++ /dev/null
@@ -1,75 +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.hive;
-
-import java.util.List;
-import java.util.Map;
-
-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.topology.Provider;
-import org.apache.hadoop.gateway.topology.Service;
-
-/**
- *
- */
-public class HiveDispatchDeploymentContributor extends ProviderDeploymentContributorBase {
-
- private static final String REPLAY_BUFFER_SIZE_PARAM = "replayBufferSize";
-
- // Default global replay buffer size in KB
- public static final String DEFAULT_REPLAY_BUFFER_SIZE = "8";
-
- @Override
- public String getRole() {
- return "dispatch";
- }
-
- @Override
- public String getName() {
- return "hive";
- }
-
- @Override
- public void contributeFilter( DeploymentContext context, Provider provider, Service service, ResourceDescriptor resource, List<FilterParamDescriptor> params ) {
- FilterDescriptor filter = resource.addFilter().name( getName() ).role( getRole() ).impl( HiveHttpClientDispatch.class );
-
- FilterParamDescriptor filterParam = filter.param().name( REPLAY_BUFFER_SIZE_PARAM ).value( DEFAULT_REPLAY_BUFFER_SIZE );
- for ( Map.Entry<String,String> serviceParam : service.getParams().entrySet() ) {
- if ( REPLAY_BUFFER_SIZE_PARAM.equals( serviceParam.getKey() ) ) {
- filterParam.value( serviceParam.getValue() );
- }
- }
- if ( params != null ) {
- for ( FilterParamDescriptor customParam : params ) {
- if ( REPLAY_BUFFER_SIZE_PARAM.equals( customParam.name() ) ) {
- filterParam.value( customParam.value() );
- }
- }
- }
-
- if( context.getGatewayConfig().isHadoopKerberosSecured() ) {
- filter.param().name("kerberos").value("true");
- } else {
- filter.param().name("basicAuthPreemptive").value("true");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveHttpClientDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveHttpClientDispatch.java b/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveHttpClientDispatch.java
index 21d39ba..b19b03d 100644
--- a/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveHttpClientDispatch.java
+++ b/gateway-service-hive/src/main/java/org/apache/hadoop/gateway/hive/HiveHttpClientDispatch.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.gateway.hive;
+import org.apache.hadoop.gateway.config.Configure;
import org.apache.hadoop.gateway.dispatch.HttpClientDispatch;
import org.apache.hadoop.gateway.security.PrimaryPrincipal;
import org.apache.http.Header;
@@ -46,18 +47,14 @@ import java.security.Principal;
* default HttpClientDispatch.
*/
public class HiveHttpClientDispatch extends HttpClientDispatch {
- private static final String BASIC_AUTH_PREEMPTIVE_PARAM = "basicAuthPreemptive";
private static final String PASSWORD_PLACEHOLDER = "*";
private boolean basicAuthPreemptive = false;
+ private boolean kerberos = false;
private static final EmptyJaasCredentials EMPTY_JAAS_CREDENTIALS = new EmptyJaasCredentials();
@Override
- public void init( FilterConfig filterConfig ) throws ServletException {
- super.init( filterConfig );
- String basicAuthPreemptiveString = filterConfig.getInitParameter( BASIC_AUTH_PREEMPTIVE_PARAM );
- if( basicAuthPreemptiveString != null ) {
- setBasicAuthPreemptive( Boolean.parseBoolean( basicAuthPreemptiveString ) );
- }
+ public void init() {
+ super.init();
}
protected Principal getPrimaryPrincipal() {
@@ -82,6 +79,7 @@ public class HiveHttpClientDispatch extends HttpClientDispatch {
}
}
+ @Configure
public void setBasicAuthPreemptive( boolean basicAuthPreemptive ) {
this.basicAuthPreemptive = basicAuthPreemptive;
}
@@ -89,7 +87,16 @@ public class HiveHttpClientDispatch extends HttpClientDispatch {
public boolean isBasicAuthPreemptive() {
return basicAuthPreemptive;
}
-
+
+ public boolean isKerberos() {
+ return kerberos;
+ }
+
+ @Configure
+ public void setKerberos(boolean kerberos) {
+ this.kerberos = kerberos;
+ }
+
protected HttpResponse executeKerberosDispatch(HttpUriRequest outboundRequest,
DefaultHttpClient client) throws IOException, ClientProtocolException {
//DefaultHttpClient client = new DefaultHttpClient();
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hive/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
----------------------------------------------------------------------
diff --git a/gateway-service-hive/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor b/gateway-service-hive/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
deleted file mode 100644
index 3762427..0000000
--- a/gateway-service-hive/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
+++ /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.hive.HiveDispatchDeploymentContributor
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hive/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor
----------------------------------------------------------------------
diff --git a/gateway-service-hive/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor b/gateway-service-hive/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor
deleted file mode 100644
index 3898804..0000000
--- a/gateway-service-hive/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.hive.HiveDeploymentContributor
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-hive/src/test/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributorTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-hive/src/test/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributorTest.java b/gateway-service-hive/src/test/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributorTest.java
deleted file mode 100644
index d748ea4..0000000
--- a/gateway-service-hive/src/test/java/org/apache/hadoop/gateway/hive/HiveDispatchDeploymentContributorTest.java
+++ /dev/null
@@ -1,44 +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.hive;
-
-import org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor;
-import org.junit.Test;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.fail;
-
-public class HiveDispatchDeploymentContributorTest {
-
- @Test
- public void testServiceLoader() throws Exception {
- ServiceLoader loader = ServiceLoader.load( ProviderDeploymentContributor.class );
- Iterator iterator = loader.iterator();
- assertThat( "Service iterator empty.", iterator.hasNext() );
- while( iterator.hasNext() ) {
- Object object = iterator.next();
- if( object instanceof HiveDispatchDeploymentContributor ) {
- return;
- }
- }
- fail( "Failed to find " + HiveDispatchDeploymentContributor.class.getName() + " via service loader." );
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-oozie/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-service-oozie/pom.xml b/gateway-service-oozie/pom.xml
deleted file mode 100644
index 00f8cc3..0000000
--- a/gateway-service-oozie/pom.xml
+++ /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.
--->
-<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>
- <artifactId>gateway</artifactId>
- <groupId>org.apache.knox</groupId>
- <version>0.6.0-SNAPSHOT</version>
- </parent>
- <artifactId>gateway-service-oozie</artifactId>
-
- <name>gateway-service-oozie</name>
- <description>The extensions to the gateway for supporting Oozie.</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>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-api</artifactId>
- <version>1.0.1</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-impl-base</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap.descriptors</groupId>
- <artifactId>shrinkwrap-descriptors-api-javaee</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap.descriptors</groupId>
- <artifactId>shrinkwrap-descriptors-impl-javaee</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>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</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-oozie/src/main/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-service-oozie/src/main/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor.java b/gateway-service-oozie/src/main/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor.java
deleted file mode 100644
index 0e9ffae..0000000
--- a/gateway-service-oozie/src/main/java/org/apache/hadoop/gateway/oozie/OozieDeploymentContributor.java
+++ /dev/null
@@ -1,121 +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 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 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.topology.Service;
-
-public class OozieDeploymentContributor extends ServiceDeploymentContributorBase {
-
- private static final String RULES_RESOURCE = OozieDeploymentContributor.class.getName().replace( '.', '/' ) + "/rewrite.xml";
- private static final String EXTERNAL_PATH = "/oozie";
-
- private static final String REPLAY_BUFFER_SIZE_PARAM = "replayBufferSize";
-
- // Oozie replay buffer size in KB
- private static final String DEFAULT_REPLAY_BUFFER_SIZE = "8";
-
- @Override
- public String getRole() {
- return "OOZIE";
- }
-
- @Override
- public String getName() {
- return "oozie";
- }
-
- @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 oozieRules = loadRulesFromTemplate();
- UrlRewriteRulesDescriptor clusterRules = context.getDescriptor( "rewrite" );
- clusterRules.addRules( oozieRules );
- }
-
- public void contributeResources( DeploymentContext context, Service service ) throws URISyntaxException {
- ResourceDescriptor rootResource = context.getGatewayDescriptor().addResource();
- rootResource.role( service.getRole() );
- rootResource.pattern( EXTERNAL_PATH + "/**?**" );
- addWebAppSecFilters(context, service, rootResource);
- addAuthenticationFilter( context, service, rootResource );
- addRewriteFilter( context, service, rootResource );
- addIdentityAssertionFilter( context, service, rootResource );
- addAuthorizationFilter(context, service, rootResource);
- addDispatchFilter( context, service, rootResource );
-
- ResourceDescriptor v1Resource = context.getGatewayDescriptor().addResource();
- v1Resource.role( service.getRole() );
- v1Resource.pattern( EXTERNAL_PATH + "/v1/**?**" );
- addWebAppSecFilters(context, service, v1Resource);
- addAuthenticationFilter( context, service, v1Resource );
- addRewriteFilter( context, service, v1Resource );
- addIdentityAssertionFilter( context, service, v1Resource );
- addAuthorizationFilter(context, service, v1Resource);
- addDispatchFilter( context, service, v1Resource );
-
- ResourceDescriptor v2Resource = context.getGatewayDescriptor().addResource();
- v2Resource.role( service.getRole() );
- v2Resource.pattern( EXTERNAL_PATH + "/v2/**?**" );
- addWebAppSecFilters(context, service, v2Resource);
- addAuthenticationFilter( context, service, v2Resource );
- addRewriteFilter( context, service, v2Resource );
- addIdentityAssertionFilter( context, service, v2Resource );
- addAuthorizationFilter(context, service, v2Resource);
- addDispatchFilter( context, service, v2Resource );
- }
-
- private void addRewriteFilter(
- DeploymentContext context, Service service, ResourceDescriptor resource ) throws URISyntaxException {
- List<FilterParamDescriptor> params = new ArrayList<FilterParamDescriptor>();
- params.add( resource.createFilterParam().name( "request.body" ).value( "OOZIE/oozie/configuration" ) );
- context.contributeFilter( service, resource, "rewrite", null, params );
- }
-
- private void addDispatchFilter(DeploymentContext context, Service service,
- ResourceDescriptor resource) {
- context.contributeFilter(service, resource, "dispatch", "http-client", null );
- }
-
- 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;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-oozie/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor
----------------------------------------------------------------------
diff --git a/gateway-service-oozie/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor b/gateway-service-oozie/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor
deleted file mode 100644
index cba4689..0000000
--- a/gateway-service-oozie/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.oozie.OozieDeploymentContributor
[5/6] knox git commit: Combined commits done for KNOX-481, KNOX-483,
KNOX-487
Posted by su...@apache.org.
Combined commits done for KNOX-481, KNOX-483, KNOX-487
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/ea28bf22
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/ea28bf22
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/ea28bf22
Branch: refs/heads/KNOX-481
Commit: ea28bf220574e52717e1424f730536acf988bbcc
Parents: 5abdde8
Author: Sumit Gupta <su...@apache.org>
Authored: Tue Jan 6 12:07:29 2015 -0500
Committer: Sumit Gupta <su...@apache.org>
Committed: Thu Feb 12 12:45:11 2015 -0500
----------------------------------------------------------------------
.../ha/provider/HaServletContextListener.java | 2 +-
gateway-release/pom.xml | 43 ++-
gateway-release/src/assembly.xml | 7 +
gateway-server/pom.xml | 8 +
.../apache/hadoop/gateway/GatewayMessages.java | 6 +
.../gateway/config/impl/GatewayConfigImpl.java | 16 +
.../gateway/deploy/DeploymentFactory.java | 147 +++----
.../impl/DispatchDeploymentContributor.java | 9 +-
.../ServiceDefinitionDeploymentContributor.java | 216 +++++++++++
.../gateway/dispatch/UrlConnectionDispatch.java | 29 +-
.../interpreter/ServicePropertyInterpreter.java | 3 +-
.../xml/KnoxFormatXmlTopologyRules.java | 3 +
.../gateway/util/ServiceDefinitionsLoader.java | 95 +++++
.../src/main/resources/build.properties | 2 +-
.../apache/hadoop/gateway/AuditLoggingTest.java | 2 +
.../topology/xml/TopologyRulesModuleTest.java | 17 +-
.../xml/service-param-topology-knox-format.xml | 1 +
.../xml/simple-topology-knox-format.xml | 1 +
gateway-service-definitions/pom.xml | 39 ++
.../service/definition/CustomDispatch.java | 69 ++++
.../gateway/service/definition/Policy.java | 45 +++
.../gateway/service/definition/Rewrite.java | 47 +++
.../gateway/service/definition/Route.java | 73 ++++
.../service/definition/ServiceDefinition.java | 142 +++++++
.../resources/services/hbase/0.98.0/rewrite.xml | 62 +++
.../resources/services/hbase/0.98.0/service.xml | 33 ++
.../resources/services/hive/0.13.0/rewrite.xml | 21 +
.../resources/services/hive/0.13.0/service.xml | 22 ++
.../resources/services/oozie/4.0.0/rewrite.xml | 122 ++++++
.../resources/services/oozie/4.0.0/service.xml | 30 ++
.../services/webhcat/0.13.0/rewrite.xml | 28 ++
.../services/webhcat/0.13.0/service.xml | 23 ++
.../services/webhdfs/2.4.0/rewrite.xml | 70 ++++
.../services/webhdfs/2.4.0/service.xml | 40 ++
.../services/yarn-rm/2.5.0/rewrite.xml | 193 ++++++++++
.../services/yarn-rm/2.5.0/service.xml | 54 +++
.../definition/ServiceDefinitionTest.java | 56 +++
.../hbase/HBaseDeploymentContributor.java | 133 -------
.../HBaseDispatchDeploymentContributor.java | 70 ----
.../gateway/hbase/HBaseHttpClientDispatch.java | 5 +-
...gateway.deploy.ProviderDeploymentContributor | 19 -
....gateway.deploy.ServiceDeploymentContributor | 19 -
.../hbase/HBaseDeploymentContributorTest.java | 45 ---
.../HBaseDispatchDeploymentContributorTest.java | 45 ---
.../gateway/hive/HiveDeploymentContributor.java | 84 ----
.../hive/HiveDispatchDeploymentContributor.java | 75 ----
.../gateway/hive/HiveHttpClientDispatch.java | 23 +-
...gateway.deploy.ProviderDeploymentContributor | 19 -
....gateway.deploy.ServiceDeploymentContributor | 19 -
.../HiveDispatchDeploymentContributorTest.java | 44 ---
gateway-service-oozie/pom.xml | 95 -----
.../oozie/OozieDeploymentContributor.java | 121 ------
....gateway.deploy.ServiceDeploymentContributor | 19 -
.../OozieDeploymentContributor/rewrite.xml | 122 ------
.../oozie/OozieDeploymentContributorTest.java | 130 -------
gateway-service-webhcat/pom.xml | 57 ---
.../webhcat/WebHCatDeploymentContributor.java | 95 -----
....gateway.deploy.ServiceDeploymentContributor | 19 -
.../WebHCatDeploymentContributor/rewrite.xml | 28 --
...NameNodeHaDispatchDeploymentContributor.java | 12 +-
.../hdfs/WebHdfsDeploymentContributor.java | 173 ---------
.../WebHdfsDispatchDeploymentContributor.java | 47 ---
.../hdfs/dispatch/WebHdfsHaDispatchFilter.java | 36 ++
.../dispatch/WebHdfsHaHttpClientDispatch.java | 66 ++--
...gateway.deploy.ProviderDeploymentContributor | 1 -
....gateway.deploy.ServiceDeploymentContributor | 1 -
.../WebHdfsHaHttpClientDispatchTest.java | 9 +-
gateway-service-yarn-rm/pom.xml | 61 ---
.../ResourceManagerDeploymentContributor.java | 150 --------
....gateway.deploy.ServiceDeploymentContributor | 19 -
.../rewrite.xml | 193 ----------
...esourceManagerDeploymentContributorTest.java | 45 ---
gateway-spi/pom.xml | 10 +-
.../config/FilterConfigurationAdapter.java | 39 ++
.../FilterConfigurationAdapterDescriptor.java | 29 ++
.../hadoop/gateway/config/GatewayConfig.java | 6 +
.../deploy/ServiceDeploymentContributor.java | 3 +
.../ServiceDeploymentContributorBase.java | 6 +
.../dispatch/AbstractGatewayDispatch.java | 91 +----
.../hadoop/gateway/dispatch/Dispatch.java | 10 +
.../gateway/dispatch/GatewayDispatchFilter.java | 152 ++++++++
.../gateway/dispatch/HttpClientDispatch.java | 63 ++-
.../apache/hadoop/gateway/topology/Service.java | 9 +
.../hadoop/gateway/topology/Topology.java | 36 +-
.../apache/hadoop/gateway/topology/Version.java | 130 +++++++
...ay.config.spi.ConfigurationAdapterDescriptor | 18 +
.../dispatch/HttpClientDispatchTest.java | 2 +
.../hadoop/gateway/GatewayFuncTestDriver.java | 13 +
.../hadoop/gateway/GatewayTestConfig.java | 6 +-
.../deploy/DeploymentFactoryFuncTest.java | 46 ++-
.../WebHCatDeploymentContributorTest.java | 45 ---
gateway-util-configinjector/pom.xml | 63 +++
.../org/apache/hadoop/gateway/config/Alias.java | 31 ++
.../gateway/config/ConfigurationAdapter.java | 24 ++
.../gateway/config/ConfigurationBinding.java | 24 ++
.../gateway/config/ConfigurationException.java | 30 ++
.../config/ConfigurationInjectorBuilder.java | 107 ++++++
.../apache/hadoop/gateway/config/Configure.java | 30 ++
.../apache/hadoop/gateway/config/Default.java | 31 ++
.../apache/hadoop/gateway/config/Optional.java | 30 ++
.../config/impl/BeanConfigurationAdapter.java | 40 ++
.../BeanConfigurationAdapterDescriptor.java | 30 ++
.../impl/ConfigurationAdapterFactory.java | 132 +++++++
.../impl/DefaultConfigurationBinding.java | 29 ++
.../impl/DefaultConfigurationInjector.java | 224 +++++++++++
.../config/impl/MapConfigurationAdapter.java | 37 ++
.../impl/MapConfigurationAdapterDescriptor.java | 30 ++
.../config/impl/MappedConfigurationBinding.java | 38 ++
.../impl/PropertiesConfigurationAdapter.java | 38 ++
...ropertiesConfigurationAdapterDescriptor.java | 30 ++
.../AbstractConfigurationAdapterDescriptor.java | 42 ++
.../spi/ConfigurationAdapterDescriptor.java | 28 ++
.../config/spi/ConfigurationInjector.java | 27 ++
...ay.config.spi.ConfigurationAdapterDescriptor | 20 +
...oop.gateway.config.spi.ConfigurationInjector | 18 +
.../gateway/config/AdapterSampleTest.java | 57 +++
.../apache/hadoop/gateway/config/FuncTest.java | 379 +++++++++++++++++++
.../gateway/config/MapFieldSampleTest.java | 45 +++
.../gateway/config/MapMethodSampleTest.java | 49 +++
.../config/PropertiesFactorySampleTest.java | 40 ++
.../config/PropertiesFieldSampleTest.java | 39 ++
.../config/PropertiesMethodSampleTest.java | 57 +++
.../apache/hadoop/gateway/config/UsageTest.java | 43 +++
.../BeanConfigurationAdapterDescriptorTest.java | 57 +++
.../impl/BeanConfigurationAdapterTest.java | 40 ++
hsso-release/pom.xml | 10 +-
pom.xml | 30 +-
127 files changed, 4276 insertions(+), 2292 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/HaServletContextListener.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/HaServletContextListener.java b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/HaServletContextListener.java
index 62dd684..b84e649 100644
--- a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/HaServletContextListener.java
+++ b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/HaServletContextListener.java
@@ -36,7 +36,7 @@ import java.util.List;
public class HaServletContextListener implements ServletContextListener {
- public static final String PROVIDER_ATTRIBUTE_NAME = HaProvider.class.getName();
+ public static final String PROVIDER_ATTRIBUTE_NAME = "haProvider";
public static final String DESCRIPTOR_LOCATION_INIT_PARAM_NAME = "haDescriptorLocation";
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-release/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-release/pom.xml b/gateway-release/pom.xml
index 744242b..0f7a739 100644
--- a/gateway-release/pom.xml
+++ b/gateway-release/pom.xml
@@ -37,6 +37,7 @@
</license>
</licenses>
+
<profiles>
<profile>
<id>release</id>
@@ -94,6 +95,36 @@
</dependency>
</dependencies>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.8</version>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>${gateway-group}</groupId>
+ <artifactId>gateway-service-definitions</artifactId>
+ <type>jar</type>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ <includes>services/**/*</includes>
+ <!--<excludes>**/*.class</excludes>-->
+ </artifactItem>
+ </artifactItems>
+ <!--<outputDirectory>${project.build.directory}/data</outputDirectory>-->
+ <!--<overWriteReleases>false</overWriteReleases>-->
+ <!--<overWriteSnapshots>true</overWriteSnapshots>-->
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</profile>
@@ -135,22 +166,10 @@
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-oozie</artifactId>
- </dependency>
- <dependency>
- <groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-webhcat</artifactId>
- </dependency>
- <dependency>
- <groupId>${gateway-group}</groupId>
<artifactId>gateway-service-tgs</artifactId>
</dependency>
<dependency>
<groupId>${gateway-group}</groupId>
- <artifactId>gateway-service-yarn-rm</artifactId>
- </dependency>
- <dependency>
- <groupId>${gateway-group}</groupId>
<artifactId>gateway-provider-rewrite</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-release/src/assembly.xml
----------------------------------------------------------------------
diff --git a/gateway-release/src/assembly.xml b/gateway-release/src/assembly.xml
index 9a46f39..709d1f3 100644
--- a/gateway-release/src/assembly.xml
+++ b/gateway-release/src/assembly.xml
@@ -58,6 +58,13 @@
</includes>
<fileMode>0444</fileMode>
</fileSet>
+ <fileSet>
+ <directory>${project.build.directory}/services</directory>
+ <outputDirectory>data/services</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </fileSet>
</fileSets>
<dependencySets>
<dependencySet>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml
index 3f736f3..1304cd0 100644
--- a/gateway-server/pom.xml
+++ b/gateway-server/pom.xml
@@ -178,6 +178,14 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.knox</groupId>
+ <artifactId>gateway-service-definitions</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.knox</groupId>
+ <artifactId>gateway-provider-rewrite</artifactId>
+ </dependency>
<!-- ********** ********** ********** ********** ********** ********** -->
<!-- ********** Test Dependencies ********** -->
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index 9325c02..4990ad1 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -124,6 +124,9 @@ public interface GatewayMessages {
@Message( level = MessageLevel.WARN, text = "Ignoring service deployment contributor with invalid null role: {0}" )
void ignoringServiceContributorWithMissingRole( String className );
+ @Message( level = MessageLevel.WARN, text = "Ignoring service deployment contributor with invalid null version: {0}" )
+ void ignoringServiceContributorWithMissingVersion( String className );
+
@Message( level = MessageLevel.WARN, text = "Ignoring provider deployment contributor with invalid null name: {0}" )
void ignoringProviderContributorWithMissingName( String className );
@@ -325,4 +328,7 @@ public interface GatewayMessages {
@Message( level = MessageLevel.INFO, text = "Computed roles/groups: {0} for principal: {1}" )
void lookedUpUserRoles(Set<String> roleNames, String userName);
+
+ @Message( level = MessageLevel.INFO, text = "Configured stacks directory is {0}" )
+ void usingStacksDirectory(String path);
}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
index 4b2a0ac..a2dfdbf 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
@@ -75,6 +75,8 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
private static final String GATEWAY_CONFIG_FILE_PREFIX = "gateway";
+ private static final String STACKS_SERVICES_DIRECTORY = "services";
+
public static final String[] GATEWAY_CONFIG_FILENAMES = {
GATEWAY_CONFIG_DIR_PREFIX + "/" + GATEWAY_CONFIG_FILE_PREFIX + "-default.xml",
GATEWAY_CONFIG_DIR_PREFIX + "/" + GATEWAY_CONFIG_FILE_PREFIX + "-site.xml"
@@ -164,6 +166,20 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
}
@Override
+ public String getGatewayStacksDir() {
+ return getGatewayDataDir() + File.separator + STACKS_SERVICES_DIRECTORY;
+ }
+ @Override
+ public String getGatewayStacksDir() {
+ return getVar( GATEWAY_DATA_HOME_VAR, getGatewayHomeDir() + File.separator + "stacks" );
+ }
+
+ @Override
+ public String getGatewayStacksDir() {
+ return getVar( GATEWAY_DATA_HOME_VAR, getGatewayHomeDir() + File.separator + "stacks" );
+ }
+
+ @Override
public String getHadoopConfDir() {
return get( HADOOP_CONF_DIR );
}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
index 44ba37a..d2245cc 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
@@ -19,18 +19,18 @@ package org.apache.hadoop.gateway.deploy;
import org.apache.hadoop.gateway.GatewayMessages;
import org.apache.hadoop.gateway.GatewayForwardingServlet;
-import org.apache.hadoop.gateway.GatewayResources;
import org.apache.hadoop.gateway.GatewayServlet;
import org.apache.hadoop.gateway.config.GatewayConfig;
import org.apache.hadoop.gateway.descriptor.GatewayDescriptor;
import org.apache.hadoop.gateway.descriptor.GatewayDescriptorFactory;
import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
import org.apache.hadoop.gateway.services.GatewayServices;
import org.apache.hadoop.gateway.services.registry.ServiceRegistry;
import org.apache.hadoop.gateway.topology.Provider;
import org.apache.hadoop.gateway.topology.Service;
import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.topology.Version;
+import org.apache.hadoop.gateway.util.ServiceDefinitionsLoader;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
@@ -40,27 +40,18 @@ import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
import org.jboss.shrinkwrap.descriptor.api.webcommon30.ServletType;
import java.beans.Statement;
+import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
-import java.util.LinkedHashMap;
+import java.util.*;
public abstract class DeploymentFactory {
private static final String DEFAULT_APP_REDIRECT_CONTEXT_PATH = "redirectTo";
- private static GatewayResources res = ResourcesFactory.get( GatewayResources.class );
private static GatewayMessages log = MessagesFactory.get( GatewayMessages.class );
private static GatewayServices gatewayServices = null;
- //private static Set<ServiceDeploymentContributor> SERVICE_CONTRIBUTORS;
- private static Map<String,Map<String,ServiceDeploymentContributor>> SERVICE_CONTRIBUTOR_MAP;
+ private static Map<String,Map<String,Map<Version, ServiceDeploymentContributor>>> SERVICE_CONTRIBUTOR_MAP;
static {
loadServiceContributors();
}
@@ -70,13 +61,20 @@ public abstract class DeploymentFactory {
static {
loadProviderContributors();
}
-
+
public static void setGatewayServices(GatewayServices services) {
DeploymentFactory.gatewayServices = services;
}
public static WebArchive createDeployment( GatewayConfig config, Topology topology ) {
DeploymentContext context = null;
+ //TODO move the loading of service defs
+ String stacks = config.getGatewayStacksDir();
+ log.usingStacksDirectory(stacks);
+ File stacksDir = new File(stacks);
+ Set<ServiceDeploymentContributor> deploymentContributors = ServiceDefinitionsLoader.loadServiceDefinitions(stacksDir);
+ addServiceDeploymentContributors(deploymentContributors.iterator());
+
Map<String,List<ProviderDeploymentContributor>> providers = selectContextProviders( topology );
Map<String,List<ServiceDeploymentContributor>> services = selectContextServices( topology );
context = createDeploymentContext( config, topology.getName(), topology, providers, services );
@@ -187,7 +185,7 @@ public abstract class DeploymentFactory {
= new HashMap<String,List<ServiceDeploymentContributor>>();
for( Service service : topology.getServices() ) {
String role = service.getRole();
- ServiceDeploymentContributor contributor = getServiceContributor( role, service.getName() );
+ ServiceDeploymentContributor contributor = getServiceContributor( role, service.getName(), service.getVersion() );
if( contributor != null ) {
List<ServiceDeploymentContributor> list = defaults.get( role );
if( list == null ) {
@@ -239,12 +237,12 @@ public abstract class DeploymentFactory {
}
}
}
-
+
private static void injectServices(Object contributor) {
if (gatewayServices != null) {
Statement stmt = null;
for(String serviceName : gatewayServices.getServiceNames()) {
-
+
try {
// TODO: this is just a temporary injection solution
// TODO: test for the existence of the setter before attempting it
@@ -280,12 +278,12 @@ public abstract class DeploymentFactory {
}
}
for( Service service : topology.getServices() ) {
- ServiceDeploymentContributor contributor = getServiceContributor( service.getRole(), null );
+ ServiceDeploymentContributor contributor = getServiceContributor( service.getRole(), service.getName(), service.getVersion() );
if( contributor != null ) {
try {
contributor.contributeService( context, service );
if (gatewayServices != null) {
- ServiceRegistry sr = (ServiceRegistry) gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
+ ServiceRegistry sr = gatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
if (sr != null) {
String regCode = sr.getRegistrationCode(topology.getName());
sr.registerService(regCode, topology.getName(), service.getRole(), service.getUrls() );
@@ -313,14 +311,22 @@ public abstract class DeploymentFactory {
return contributor;
}
- public static ServiceDeploymentContributor getServiceContributor( String role, String name ) {
+ public static ServiceDeploymentContributor getServiceContributor( String role, String name, Version version ) {
ServiceDeploymentContributor contributor = null;
- Map<String,ServiceDeploymentContributor> nameMap = SERVICE_CONTRIBUTOR_MAP.get( role );
- if( nameMap != null ) {
- if( name == null ) {
- contributor = nameMap.values().iterator().next();
- } else if ( !nameMap.isEmpty() ) {
- contributor = nameMap.get( name );
+ Map<String,Map<Version, ServiceDeploymentContributor>> nameMap = SERVICE_CONTRIBUTOR_MAP.get( role );
+ if( nameMap != null && !nameMap.isEmpty()) {
+ Map<Version, ServiceDeploymentContributor> versionMap = null;
+ if ( name == null ) {
+ versionMap = nameMap.values().iterator().next();
+ } else {
+ versionMap = nameMap.get( name );
+ }
+ if ( versionMap != null && !versionMap.isEmpty()) {
+ if( version == null ) {
+ contributor = ((TreeMap<Version, ServiceDeploymentContributor>) versionMap).firstEntry().getValue();
+ } else {
+ contributor = versionMap.get( version );
+ }
}
}
return contributor;
@@ -391,38 +397,45 @@ public abstract class DeploymentFactory {
}
}
return null;
- }
-
- private static void loadServiceContributors() {
- Set<ServiceDeploymentContributor> set = new HashSet<ServiceDeploymentContributor>();
- Map<String,Map<String,ServiceDeploymentContributor>> roleMap
- = new HashMap<String,Map<String,ServiceDeploymentContributor>>();
+ }
+ private static void loadServiceContributors() {
+ SERVICE_CONTRIBUTOR_MAP = new HashMap<String, Map<String, Map<Version, ServiceDeploymentContributor>>>();
ServiceLoader<ServiceDeploymentContributor> loader = ServiceLoader.load( ServiceDeploymentContributor.class );
Iterator<ServiceDeploymentContributor> contributors = loader.iterator();
- while( contributors.hasNext() ) {
- ServiceDeploymentContributor contributor = contributors.next();
- if( contributor.getName() == null ) {
- log.ignoringServiceContributorWithMissingName( contributor.getClass().getName() );
- continue;
- }
- if( contributor.getRole() == null ) {
- log.ignoringServiceContributorWithMissingRole( contributor.getClass().getName() );
- continue;
- }
- set.add( contributor );
- Map nameMap = roleMap.get( contributor.getRole() );
- if( nameMap == null ) {
- nameMap = new HashMap<String,ServiceDeploymentContributor>();
- roleMap.put( contributor.getRole(), nameMap );
- }
- nameMap.put( contributor.getName(), contributor );
- }
- //SERVICE_CONTRIBUTORS = set;
- SERVICE_CONTRIBUTOR_MAP = roleMap;
+ addServiceDeploymentContributors(contributors);
}
- private static void loadProviderContributors() {
+ private static void addServiceDeploymentContributors(Iterator<ServiceDeploymentContributor> contributors) {
+ while( contributors.hasNext() ) {
+ ServiceDeploymentContributor contributor = contributors.next();
+ if( contributor.getName() == null ) {
+ log.ignoringServiceContributorWithMissingName( contributor.getClass().getName() );
+ continue;
+ }
+ if( contributor.getRole() == null ) {
+ log.ignoringServiceContributorWithMissingRole( contributor.getClass().getName() );
+ continue;
+ }
+ if( contributor.getVersion() == null ) {
+ log.ignoringServiceContributorWithMissingVersion(contributor.getClass().getName());
+ continue;
+ }
+ Map<String,Map<Version, ServiceDeploymentContributor>> nameMap = SERVICE_CONTRIBUTOR_MAP.get( contributor.getRole() );
+ if( nameMap == null ) {
+ nameMap = new HashMap<String,Map<Version, ServiceDeploymentContributor>>();
+ SERVICE_CONTRIBUTOR_MAP.put( contributor.getRole(), nameMap );
+ }
+ Map<Version, ServiceDeploymentContributor> versionMap = nameMap.get(contributor.getName());
+ if (versionMap == null) {
+ versionMap = new TreeMap<Version, ServiceDeploymentContributor>();
+ nameMap.put(contributor.getName(), versionMap);
+ }
+ versionMap.put( contributor.getVersion(), contributor );
+ }
+ }
+
+ private static void loadProviderContributors() {
Set<ProviderDeploymentContributor> set = new HashSet<ProviderDeploymentContributor>();
Map<String,Map<String,ProviderDeploymentContributor>> roleMap
= new HashMap<String,Map<String,ProviderDeploymentContributor>>();
@@ -465,18 +478,18 @@ public abstract class DeploymentFactory {
return contributor;
}
- static ServiceDeploymentContributor getServiceContributor(
- Map<String,List<ServiceDeploymentContributor>> services, String role, String name ) {
- ServiceDeploymentContributor contributor = null;
- if( name == null ) {
- List<ServiceDeploymentContributor> list = services.get( role );
- if( !list.isEmpty() ) {
- contributor = list.get( 0 );
- }
- } else {
- contributor = getServiceContributor( role, name );
- }
- return contributor;
- }
+// static ServiceDeploymentContributor getServiceContributor(
+// Map<String,List<ServiceDeploymentContributor>> services, String role, String name ) {
+// ServiceDeploymentContributor contributor = null;
+// if( name == null ) {
+// List<ServiceDeploymentContributor> list = services.get( role );
+// if( !list.isEmpty() ) {
+// contributor = list.get( 0 );
+// }
+// } else {
+// contributor = getServiceContributor( role, name );
+// }
+// return contributor;
+// }
}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/DispatchDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/DispatchDeploymentContributor.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/DispatchDeploymentContributor.java
index ab3448b..30f2c65 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/DispatchDeploymentContributor.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/DispatchDeploymentContributor.java
@@ -22,6 +22,7 @@ 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.dispatch.HttpClientDispatch;
import org.apache.hadoop.gateway.topology.Provider;
import org.apache.hadoop.gateway.topology.Service;
@@ -32,7 +33,9 @@ import java.util.Map;
public class DispatchDeploymentContributor extends ProviderDeploymentContributorBase {
private static final String REPLAY_BUFFER_SIZE_PARAM = "replayBufferSize";
-
+
+ private static final String DISPATCH_IMPL_PARAM = "dispatch-impl";
+
// Default global replay buffer size in KB
public static final String DEFAULT_REPLAY_BUFFER_SIZE = "8";
@@ -48,8 +51,8 @@ public class DispatchDeploymentContributor extends ProviderDeploymentContributor
@Override
public void contributeFilter( DeploymentContext context, Provider provider, Service service, ResourceDescriptor resource, List<FilterParamDescriptor> params ) {
- FilterDescriptor filter = resource.addFilter().name( getName() ).role( getRole() ).impl( HttpClientDispatch.class );
-
+ FilterDescriptor filter = resource.addFilter().name( getName() ).role( getRole() ).impl( GatewayDispatchFilter.class );
+ filter.param().name(DISPATCH_IMPL_PARAM).value(HttpClientDispatch.class.getName());
FilterParamDescriptor filterParam = filter.param().name( REPLAY_BUFFER_SIZE_PARAM ).value( DEFAULT_REPLAY_BUFFER_SIZE );
for ( Map.Entry<String,String> serviceParam : service.getParams().entrySet() ) {
if ( REPLAY_BUFFER_SIZE_PARAM.equals( serviceParam.getKey() ) ) {
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
new file mode 100644
index 0000000..c14a156
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
@@ -0,0 +1,216 @@
+/**
+ * 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.deploy.impl;
+
+import org.apache.hadoop.gateway.deploy.DeploymentContext;
+import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributorBase;
+import org.apache.hadoop.gateway.descriptor.FilterDescriptor;
+import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
+import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
+import org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
+import org.apache.hadoop.gateway.service.definition.*;
+import org.apache.hadoop.gateway.topology.Provider;
+import org.apache.hadoop.gateway.topology.Service;
+import org.apache.hadoop.gateway.topology.Version;
+
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentContributorBase {
+
+ private static final String DISPATCH_ROLE = "dispatch";
+
+ private static final String DISPATCH_IMPL_PARAM = "dispatch-impl";
+
+ private static final String REPLAY_BUFFER_SIZE_PARAM = "replayBufferSize";
+
+ public static final String DEFAULT_REPLAY_BUFFER_SIZE = "8";
+
+ private ServiceDefinition serviceDefinition;
+
+ private UrlRewriteRulesDescriptor serviceRules;
+
+ public ServiceDefinitionDeploymentContributor(ServiceDefinition serviceDefinition, UrlRewriteRulesDescriptor serviceRules) {
+ this.serviceDefinition = serviceDefinition;
+ this.serviceRules = serviceRules;
+ }
+
+ @Override
+ public String getRole() {
+ return serviceDefinition.getRole();
+ }
+
+ @Override
+ public String getName() {
+ return serviceDefinition.getName();
+ }
+
+ @Override
+ public Version getVersion() {
+ return new Version(serviceDefinition.getVersion());
+ }
+
+ @Override
+ public void contributeService(DeploymentContext context, Service service) throws Exception {
+ contributeRewriteRules(context, service);
+ contributeResources(context, service);
+ }
+
+ private void contributeRewriteRules(DeploymentContext context, Service service) {
+ if ( serviceRules != null ) {
+ UrlRewriteRulesDescriptor clusterRules = context.getDescriptor("rewrite");
+ clusterRules.addRules(serviceRules);
+ }
+ }
+
+ private void contributeResources(DeploymentContext context, Service service) {
+ Map<String, String> filterParams = new HashMap<String, String>();
+ List<Route> bindings = serviceDefinition.getRoutes();
+ for ( Route binding : bindings ) {
+ List<Rewrite> filters = binding.getRewrites();
+ if ( filters != null && !filters.isEmpty() ) {
+ filterParams.clear();
+ for ( Rewrite filter : filters ) {
+ filterParams.put(filter.getTo(), filter.getApply());
+ }
+ }
+ try {
+ contributeResource(context, service, binding, filterParams);
+ } catch ( URISyntaxException e ) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ private void contributeResource(DeploymentContext context, Service service, Route binding, Map<String, String> filterParams) throws URISyntaxException {
+ List<FilterParamDescriptor> params = new ArrayList<FilterParamDescriptor>();
+ ResourceDescriptor resource = context.getGatewayDescriptor().addResource();
+ resource.role(service.getRole());
+ resource.pattern(binding.getPath());
+ List<Policy> policyBindings = binding.getPolicies();
+ if ( policyBindings == null ) {
+ policyBindings = serviceDefinition.getPolicies();
+ }
+ if ( policyBindings == null ) {
+ //add default set
+ addDefaultPolicies(context, service, filterParams, params, resource);
+ } else {
+ addPolicies(context, service, filterParams, params, resource, policyBindings);
+ }
+ addDispatchFilter(context, service, resource, binding);
+ }
+
+ private void addPolicies(DeploymentContext context, Service service, Map<String, String> filterParams, List<FilterParamDescriptor> params, ResourceDescriptor resource, List<Policy> policyBindings) throws URISyntaxException {
+ for ( Policy policyBinding : policyBindings ) {
+ String role = policyBinding.getRole();
+ if ( role == null ) {
+ throw new IllegalArgumentException("Policy defined has no role for service " + service.getName());
+ }
+ role = role.trim().toLowerCase();
+ if ( role.equals("rewrite") ) {
+ addRewriteFilter(context, service, filterParams, params, resource);
+ } else if ( topologyContainsProviderType(context, role) ) {
+ context.contributeFilter(service, resource, role, policyBinding.getName(), null);
+ }
+ }
+ }
+
+ private void addDefaultPolicies(DeploymentContext context, Service service, Map<String, String> filterParams, List<FilterParamDescriptor> params, ResourceDescriptor resource) throws URISyntaxException {
+ addWebAppSecFilters(context, service, resource);
+ addAuthenticationFilter(context, service, resource);
+ addRewriteFilter(context, service, filterParams, params, resource);
+ addIdentityAssertionFilter(context, service, resource);
+ addAuthorizationFilter(context, service, resource);
+ }
+
+ private void addRewriteFilter(DeploymentContext context, Service service, Map<String, String> filterParams, List<FilterParamDescriptor> params, ResourceDescriptor resource) throws URISyntaxException {
+ if ( !filterParams.isEmpty() ) {
+ for ( Map.Entry<String, String> filterParam : filterParams.entrySet() ) {
+ params.add(resource.createFilterParam().name(filterParam.getKey()).value(filterParam.getValue()));
+ }
+ }
+ addRewriteFilter(context, service, resource, params);
+ }
+
+ private void addDispatchFilter(DeploymentContext context, Service service, ResourceDescriptor resource, Route binding) {
+ CustomDispatch customDispatch = binding.getDispatch();
+ if ( customDispatch == null ) {
+ customDispatch = serviceDefinition.getDispatch();
+ }
+ if ( customDispatch != null ) {
+ boolean isHaEnabled = isHaEnabled(context);
+ String haContributorName = customDispatch.getHaContributorName();
+ String haClassName = customDispatch.getHaClassName();
+ if ( isHaEnabled && (haContributorName != null || haClassName != null)) {
+ if (haContributorName != null) {
+ addDispatchFilter(context, service, resource, DISPATCH_ROLE, haContributorName);
+ } else {
+ addDispatchFilterForClass(context, service, resource, haClassName);
+ }
+ } else {
+ String contributorName = customDispatch.getContributorName();
+ if ( contributorName != null ) {
+ addDispatchFilter(context, service, resource, DISPATCH_ROLE, contributorName);
+ } else {
+ String className = customDispatch.getClassName();
+ if ( className != null ) {
+ addDispatchFilterForClass(context, service, resource, className);
+ }
+ }
+ }
+ } else {
+ addDispatchFilter(context, service, resource, DISPATCH_ROLE, "http-client");
+ }
+ }
+
+ private void addDispatchFilterForClass(DeploymentContext context, Service service, ResourceDescriptor resource, String className) {
+ FilterDescriptor filter = resource.addFilter().name(getName()).role(DISPATCH_ROLE).impl(GatewayDispatchFilter.class);
+ filter.param().name(DISPATCH_IMPL_PARAM).value(className);
+ FilterParamDescriptor filterParam = filter.param().name(REPLAY_BUFFER_SIZE_PARAM).value(DEFAULT_REPLAY_BUFFER_SIZE);
+ for ( Map.Entry<String, String> serviceParam : service.getParams().entrySet() ) {
+ if ( REPLAY_BUFFER_SIZE_PARAM.equals(serviceParam.getKey()) ) {
+ filterParam.value(serviceParam.getValue());
+ }
+ }
+ if ( context.getGatewayConfig().isHadoopKerberosSecured() ) {
+ filter.param().name("kerberos").value("true");
+ } else {
+ //special case for hive
+ filter.param().name("basicAuthPreemptive").value("true");
+ }
+ }
+
+ private boolean isHaEnabled(DeploymentContext context) {
+ Provider provider = getProviderByRole(context, "ha");
+ if ( provider != null && provider.isEnabled() ) {
+ Map<String, String> params = provider.getParams();
+ if ( params != null ) {
+ if ( params.containsKey(getRole()) ) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
index 5b02221..c0347cf 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.gateway.audit.api.AuditServiceFactory;
import org.apache.hadoop.gateway.audit.api.Auditor;
import org.apache.hadoop.gateway.audit.api.ResourceType;
import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
+import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
import org.apache.hadoop.gateway.util.urltemplate.Parser;
@@ -36,6 +37,8 @@ import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
import org.apache.hadoop.security.authentication.client.AuthenticationException;
import org.apache.hadoop.security.authentication.client.KerberosAuthenticator;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -53,7 +56,7 @@ import java.util.Enumeration;
/**
*
*/
-public class UrlConnectionDispatch extends AbstractGatewayDispatch {
+public class UrlConnectionDispatch extends AbstractGatewayFilter {
private static final GatewayMessages LOG = MessagesFactory.get( GatewayMessages.class );
private static final GatewayResources RES = ResourcesFactory.get( GatewayResources.class );
@@ -61,6 +64,30 @@ public class UrlConnectionDispatch extends AbstractGatewayDispatch {
AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME );
@Override
+ protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
+ String method = request.getMethod().toUpperCase();
+ if (method.equals("GET")) {
+ try {
+ doGet(getDispatchUrl(request), request, response);
+ } catch ( URISyntaxException e ) {
+ throw new ServletException(e);
+ }
+ } else {
+ response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ }
+ }
+
+ protected 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;
+ }
+
public void doGet( URI url, HttpServletRequest request, HttpServletResponse response ) throws IOException, URISyntaxException {
String sourcePathInfo = request.getPathInfo();
String sourcePattern = getConfig().getInitParameter( "pattern" );
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java
index 985fd6b..d297178 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/builder/property/interpreter/ServicePropertyInterpreter.java
@@ -59,7 +59,8 @@ public class ServicePropertyInterpreter extends AbstractInterpreter {
}
nextToken = nextToken.substring(dotPosition + 1);
- Service service = topology.getService(serviceRole, serviceName);
+ //TODO: sumit - version needs to be passed parsed and passed in if we want to continue to support the 'ambari' format
+ Service service = topology.getService(serviceRole, serviceName, null);
if (service == null) {
service = new Service();
service.setName(serviceName);
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java
index 745c661..b32f0c9 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/xml/KnoxFormatXmlTopologyRules.java
@@ -22,6 +22,7 @@ import org.apache.commons.digester3.binder.AbstractRulesModule;
import org.apache.hadoop.gateway.topology.Param;
import org.apache.hadoop.gateway.topology.Provider;
import org.apache.hadoop.gateway.topology.Service;
+import org.apache.hadoop.gateway.topology.Version;
import org.apache.hadoop.gateway.topology.builder.BeanPropertyTopologyBuilder;
import org.xml.sax.Attributes;
@@ -39,6 +40,7 @@ public class KnoxFormatXmlTopologyRules extends AbstractRulesModule {
private static final String VALUE_TAG = "value";
private static final Rule paramRule = new ParamRule();
+
@Override
protected void configure() {
forPattern( ROOT_TAG ).createObject().ofType( BeanPropertyTopologyBuilder.class );
@@ -48,6 +50,7 @@ public class KnoxFormatXmlTopologyRules extends AbstractRulesModule {
forPattern( ROOT_TAG + "/" + SERVICE_TAG ).createObject().ofType( Service.class ).then().setNext( "addService" );
forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + ROLE_TAG ).setBeanProperty();
forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + NAME_TAG ).setBeanProperty();
+ forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + VERSION_TAG ).createObject().ofType(Version.class).then().setBeanProperty().then().setNext("setVersion");
forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + URL_TAG ).callMethod( "addUrl" ).usingElementBodyAsArgument();
forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + PARAM_TAG ).createObject().ofType( Param.class ).then().addRule( paramRule ).then().setNext( "addParam" );
forPattern( ROOT_TAG + "/" + SERVICE_TAG + "/" + PARAM_TAG + "/" + NAME_TAG ).setBeanProperty();
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/java/org/apache/hadoop/gateway/util/ServiceDefinitionsLoader.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/util/ServiceDefinitionsLoader.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/ServiceDefinitionsLoader.java
new file mode 100644
index 0000000..3d41605
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/ServiceDefinitionsLoader.java
@@ -0,0 +1,95 @@
+/**
+ * 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.util;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor;
+import org.apache.hadoop.gateway.deploy.impl.ServiceDefinitionDeploymentContributor;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory;
+import org.apache.hadoop.gateway.service.definition.ServiceDefinition;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.*;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+public class ServiceDefinitionsLoader {
+
+ public static Set<ServiceDeploymentContributor> loadServiceDefinitions(File servicesDir) {
+ Set<ServiceDeploymentContributor> contributors = new HashSet<ServiceDeploymentContributor>();
+ if (servicesDir.exists() && servicesDir.isDirectory()) {
+ JAXBContext context = null;
+ try {
+ context = JAXBContext.newInstance(ServiceDefinition.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ Collection<File> files = FileUtils.listFiles(servicesDir, new IOFileFilter() {
+ @Override
+ public boolean accept(File file) {
+ return file.getName().contains("service");
+ }
+
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.contains("service");
+ }
+ }, TrueFileFilter.INSTANCE);
+ for (File file : files) {
+ try {
+ FileInputStream inputStream = new FileInputStream(file);
+ ServiceDefinition definition = (ServiceDefinition) unmarshaller.unmarshal(inputStream);
+ //look for rewrite rules as a sibling (for now)
+ UrlRewriteRulesDescriptor rewriteRulesDescriptor = loadRewriteRules(file.getParentFile());
+ contributors.add(new ServiceDefinitionDeploymentContributor(definition, rewriteRulesDescriptor));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ }
+ }
+ return contributors;
+ }
+
+ private static UrlRewriteRulesDescriptor loadRewriteRules(File servicesDir) {
+ File rewriteFile = new File(servicesDir, "rewrite.xml");
+ if (rewriteFile.exists()) {
+ InputStream stream = null;
+ try {
+ stream = new FileInputStream(rewriteFile);
+ Reader reader = new InputStreamReader(stream);
+ UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.load(
+ "xml", reader);
+ reader.close();
+ stream.close();
+ return rules;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/main/resources/build.properties
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/resources/build.properties b/gateway-server/src/main/resources/build.properties
index a380579..fbd4d83 100644
--- a/gateway-server/src/main/resources/build.properties
+++ b/gateway-server/src/main/resources/build.properties
@@ -14,5 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-build.version=${gateway-version}
+build.version=0.5.0.2.2.1.0-2340
build.hash=${buildNumber}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
index b15c56b..8d88ec0 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/AuditLoggingTest.java
@@ -49,6 +49,7 @@ import org.apache.hadoop.gateway.audit.log4j.correlation.Log4jCorrelationService
import org.apache.hadoop.gateway.dispatch.HttpClientDispatch;
import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
import org.apache.hadoop.test.log.CollectAppender;
+import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.spi.LoggingEvent;
import org.easymock.EasyMock;
import org.junit.After;
@@ -171,6 +172,7 @@ public class AuditLoggingTest {
EasyMock.replay( outboundResponse );
HttpClientDispatch dispatch = new HttpClientDispatch();
+ dispatch.setHttpClient(new DefaultHttpClient());
try {
dispatch.doGet( new URI( uri ), inboundRequest, outboundResponse );
fail( "Expected exception while accessing to unreachable host" );
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
index 06b5b2a..85836fc 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/topology/xml/TopologyRulesModuleTest.java
@@ -17,11 +17,15 @@
*/
package org.apache.hadoop.gateway.topology.xml;
+import org.apache.commons.collections.keyvalue.MultiKey;
+import org.apache.commons.collections.map.HashedMap;
+import org.apache.commons.collections.map.MultiKeyMap;
import org.apache.commons.digester3.Digester;
import org.apache.commons.digester3.binder.DigesterLoader;
import org.apache.hadoop.gateway.topology.Provider;
import org.apache.hadoop.gateway.topology.Service;
import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.topology.Version;
import org.apache.hadoop.gateway.topology.builder.TopologyBuilder;
import org.junit.After;
import org.junit.Before;
@@ -72,7 +76,8 @@ public class TopologyRulesModuleTest {
Service comp = topology.getServices().iterator().next();
assertThat( comp, notNullValue() );
- assertThat( comp.getRole(), is( "WEBHDFS" ) );
+ assertThat( comp.getRole(), is("WEBHDFS") );
+ assertThat( comp.getVersion().toString(), is( "2.4.0" ));
assertThat( comp.getUrls().size(), is( 2 ) );
assertThat( comp.getUrls(), hasItem( "http://host1:80/webhdfs" ) );
assertThat( comp.getUrls(), hasItem( "http://host2:80/webhdfs" ) );
@@ -116,6 +121,7 @@ public class TopologyRulesModuleTest {
assertThat( service.getName(), is( "test-service-name" ) );
assertThat( service.getParams(), hasEntry( is( "test-service-param-name-1" ), is( "test-service-param-value-1" ) ) );
assertThat( service.getParams(), hasEntry( is( "test-service-param-name-2" ), is( "test-service-param-value-2" ) ) );
+ assertThat( service.getVersion(), is( new Version(1,0,0)));
}
@@ -136,7 +142,7 @@ public class TopologyRulesModuleTest {
assertThat( topology.getServices().size(), is( 4 ) );
assertThat( topology.getProviders().size(), is( 2 ) );
- Service webhdfsService = topology.getService( "WEBHDFS", null );
+ Service webhdfsService = topology.getService( "WEBHDFS", null, null);
assertThat( webhdfsService, notNullValue() );
assertThat( webhdfsService.getRole(), is( "WEBHDFS" ) );
assertThat( webhdfsService.getName(), nullValue() );
@@ -144,21 +150,21 @@ public class TopologyRulesModuleTest {
assertThat( webhdfsService.getUrls(), hasItem( "http://host1:50070/webhdfs" ) );
assertThat( webhdfsService.getUrls(), hasItem( "http://host2:50070/webhdfs" ) );
- Service webhcatService = topology.getService( "WEBHCAT", null );
+ Service webhcatService = topology.getService( "WEBHCAT", null, null);
assertThat( webhcatService, notNullValue() );
assertThat( webhcatService.getRole(), is( "WEBHCAT" ) );
assertThat( webhcatService.getName(), nullValue() );
assertThat( webhcatService.getUrls().size(), is( 1 ) );
assertThat( webhcatService.getUrls(), hasItem( "http://host:50111/templeton" ) );
- Service oozieService = topology.getService( "OOZIE", null );
+ Service oozieService = topology.getService( "OOZIE", null, null);
assertThat( oozieService, notNullValue() );
assertThat( oozieService.getRole(), is( "OOZIE" ) );
assertThat( oozieService.getName(), nullValue() );
assertThat( webhcatService.getUrls().size(), is( 1 ) );
assertThat( oozieService.getUrls(), hasItem( "http://host:11000/oozie" ) );
- Service hiveService = topology.getService( "HIVE", null );
+ Service hiveService = topology.getService( "HIVE", null, null);
assertThat( hiveService, notNullValue() );
assertThat( hiveService.getRole(), is( "HIVE" ) );
assertThat( hiveService.getName(), nullValue() );
@@ -217,5 +223,4 @@ public class TopologyRulesModuleTest {
assertThat( service.getParams(), hasEntry( is( "test-service-param-name-1" ), is( "test-service-param-value-1" ) ) );
assertThat( service.getParams(), hasEntry( is( "test-service-param-name-2" ), is( "test-service-param-value-2" ) ) );
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/service-param-topology-knox-format.xml
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/service-param-topology-knox-format.xml b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/service-param-topology-knox-format.xml
index a7c476e..870015a 100644
--- a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/service-param-topology-knox-format.xml
+++ b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/service-param-topology-knox-format.xml
@@ -31,6 +31,7 @@
<service>
<role>test-service-role</role>
<name>test-service-name</name>
+ <version>1.0.0</version>
<url>test-service-scheme://test-service-host1:42/test-service-path</url>
<url>test-service-scheme://test-service-host2:42/test-service-path</url>
<param>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml
index 46175d1..1a181f1 100644
--- a/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml
+++ b/gateway-server/src/test/resources/org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml
@@ -63,6 +63,7 @@
<service>
<role>WEBHDFS</role>
+ <version>2.4.0</version>
<url>http://host1:80/webhdfs</url>
<url>http://host2:80/webhdfs</url>
</service>
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/pom.xml b/gateway-service-definitions/pom.xml
new file mode 100644
index 0000000..004aed8
--- /dev/null
+++ b/gateway-service-definitions/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.knox</groupId>
+ <artifactId>gateway</artifactId>
+ <version>0.6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>gateway-service-definitions</artifactId>
+ <name>gateway-service-definitions</name>
+ <description>The service definitions aka stacks.</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>org.eclipse.persistence</groupId>
+ <artifactId>eclipselink</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.knox</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-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
new file mode 100644
index 0000000..7270a2b
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType(name = "dispatch")
+public class CustomDispatch {
+
+ private String contributorName;
+
+ private String haContributorName;
+
+ private String className;
+
+ private String haClassName;
+
+ @XmlAttribute(name = "contributor-name")
+ public String getContributorName() {
+ return contributorName;
+ }
+
+ public void setContributorName(String contributorName) {
+ this.contributorName = contributorName;
+ }
+
+ @XmlAttribute(name = "ha-contributor-name")
+ public String getHaContributorName() {
+ return haContributorName;
+ }
+
+ public void setHaContributorName(String haContributorName) {
+ this.haContributorName = haContributorName;
+ }
+
+ @XmlAttribute(name = "classname")
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ @XmlAttribute(name = "ha-classname")
+ public String getHaClassName() {
+ return haClassName;
+ }
+
+ public void setHaClassName(String haContributorClassName) {
+ this.haClassName = haContributorClassName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Policy.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Policy.java b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Policy.java
new file mode 100644
index 0000000..471aae5
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Policy.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+public class Policy {
+
+ private String name;
+
+ private String role;
+
+ @XmlAttribute
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlAttribute
+ public String getRole() {
+ return role;
+ }
+
+ public void setRole(String role) {
+ this.role = role;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Rewrite.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Rewrite.java b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Rewrite.java
new file mode 100644
index 0000000..a7a3e3c
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Rewrite.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType(name = "rewrite")
+public class Rewrite {
+
+ private String apply;
+
+ private String to;
+
+ @XmlAttribute
+ public String getApply() {
+ return apply;
+ }
+
+ public void setApply(String apply) {
+ this.apply = apply;
+ }
+
+ @XmlAttribute
+ public String getTo() {
+ return to;
+ }
+
+ public void setTo(String to) {
+ this.to = to;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Route.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Route.java b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Route.java
new file mode 100644
index 0000000..7112c2e
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/Route.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlType;
+import java.util.List;
+
+@XmlType(name = "route")
+public class Route {
+
+ private String path;
+
+ private List<Rewrite> rewrites;
+
+ private List<Policy> policies;
+
+ private CustomDispatch dispatch;
+
+ @XmlAttribute
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @XmlElement(name = "rewrite")
+ public List<Rewrite> getRewrites() {
+ return rewrites;
+ }
+
+ public void setRewrites(List<Rewrite> rewrites) {
+ this.rewrites = rewrites;
+ }
+
+ @XmlElement(name = "policy")
+ @XmlElementWrapper(name = "policies")
+ public List<Policy> getPolicies() {
+ return policies;
+ }
+
+ public void setPolicies(List<Policy> policies) {
+ this.policies = policies;
+ }
+
+ @XmlElement(name = "dispatch")
+ public CustomDispatch getDispatch() {
+ return dispatch;
+ }
+
+ public void setDispatch(CustomDispatch dispatch) {
+ this.dispatch = dispatch;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
new file mode 100644
index 0000000..0e61b4a
--- /dev/null
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
@@ -0,0 +1,142 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.service.definition;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement(name = "service")
+public class ServiceDefinition {
+
+ private String name;
+
+ private String role;
+
+ private String version;
+
+ private List<Route> routes;
+
+ private List<Policy> policies;
+
+ private CustomDispatch dispatch;
+
+ private List<PolicyBinding> policyBindings;
+
+ private CustomDispatch dispatch;
+
+ private List<PolicyBinding> policyBindings;
+
+ private CustomDispatch dispatch;
+
+ @XmlAttribute
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlAttribute
+ public String getRole() {
+ return role;
+ }
+
+ public void setRole(String role) {
+ this.role = role;
+ }
+
+ @XmlAttribute
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ @XmlElement(name = "route")
+ @XmlElementWrapper(name = "routes")
+ public List<Route> getRoutes() {
+ return routes;
+ }
+
+ public void setRoutes(List<Route> routes) {
+ this.routes = routes;
+ }
+
+ @XmlElement(name = "policy")
+ @XmlElementWrapper(name = "policies")
+ public List<Policy> getPolicies() {
+ return policies;
+ }
+
+ public void setPolicies(List<Policy> policies) {
+ this.policies = policies;
+ }
+
+ @XmlElement(name = "dispatch")
+ public CustomDispatch getDispatch() {
+ return dispatch;
+ }
+
+ public void setDispatch(CustomDispatch dispatch) {
+ this.dispatch = dispatch;
+ }
+
+ @XmlElement(name = "policy")
+ @XmlElementWrapper(name = "policies")
+ public List<PolicyBinding> getPolicyBindings() {
+ return policyBindings;
+ }
+
+ public void setPolicyBindings(List<PolicyBinding> policyBindings) {
+ this.policyBindings = policyBindings;
+ }
+
+ @XmlElement(name = "dispatch")
+ public CustomDispatch getDispatch() {
+ return dispatch;
+ }
+
+ public void setDispatch(CustomDispatch dispatch) {
+ this.dispatch = dispatch;
+ }
+
+ @XmlElement(name = "policy")
+ @XmlElementWrapper(name = "policies")
+ public List<PolicyBinding> getPolicyBindings() {
+ return policyBindings;
+ }
+
+ public void setPolicyBindings(List<PolicyBinding> policyBindings) {
+ this.policyBindings = policyBindings;
+ }
+
+ @XmlElement(name = "dispatch")
+ public CustomDispatch getDispatch() {
+ return dispatch;
+ }
+
+ public void setDispatch(CustomDispatch dispatch) {
+ this.dispatch = dispatch;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/rewrite.xml
new file mode 100644
index 0000000..64ca750
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/rewrite.xml
@@ -0,0 +1,62 @@
+<!--
+ 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="WEBHBASE/webhbase/root/inbound" pattern="*://*:*/**/hbase/?{**}">
+ <rewrite template="{$serviceUrl[WEBHBASE]}/?{**}"/>
+ </rule>
+
+ <rule dir="IN" name="WEBHBASE/webhbase/path/inbound" pattern="*://*:*/**/hbase/{path=**}?{**}">
+ <rewrite template="{$serviceUrl[WEBHBASE]}/{path=**}?{**}"/>
+ </rule>
+
+ <rule name="WEBHBASE/webhbase/location/outbound">
+ <match pattern="*://*:*/{path=**}?{**}"/>
+ <rewrite template="{$frontend[url]}/hbase/{path=**}?{**}"/>
+ </rule>
+
+ <rule name="WEBHBASE/webhbase/address/outbound">
+ <match pattern="{host}:{port}"/>
+ <rewrite template="{$frontend[url]}/hbase-region?host={host}?port={port}"/>
+ <encrypt-query/>
+ </rule>
+
+ <filter name="WEBHBASE/webhbase/headers/outbound">
+ <content type="application/x-http-headers">
+ <apply path="Location" rule="WEBHBASE/webhbase/location/outbound"/>
+ </content>
+ </filter>
+
+ <filter name="WEBHBASE/webhbase/status/outbound">
+ <content type="*/json">
+ <apply path="$[LiveNodes][*][name]" rule="WEBHBASE/webhbase/address/outbound"/>
+ </content>
+ <content type="*/xml">
+ <apply path="/ClusterStatus/LiveNodes/Node/@name" rule="WEBHBASE/webhbase/address/outbound"/>
+ </content>
+ </filter>
+
+ <filter name="WEBHBASE/webhbase/regions/outbound">
+ <content type="*/json">
+ <apply path="$[Region][*][location]" rule="WEBHBASE/webhbase/address/outbound"/>
+ </content>
+ <content type="*/xml">
+ <apply path="/TableInfo/Region/@location" rule="WEBHBASE/webhbase/address/outbound"/>
+ </content>
+ </filter>
+
+</rules>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml b/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
new file mode 100644
index 0000000..e03bca7
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
@@ -0,0 +1,33 @@
+<!--
+ 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.
+-->
+<service role="WEBHBASE" name="webhbase" version="0.98.0">
+ <routes>
+ <route path="/hbase/?**">
+ <rewrite apply="WEBHBASE/webhbase/headers/outbound" to="response.headers"/>
+ </route>
+ <route path="/hbase/**?**">
+ <rewrite apply="WEBHBASE/webhbase/headers/outbound" to="response.headers"/>
+ </route>
+ <route path="/hbase/status/cluster?**">
+ <rewrite apply="WEBHBASE/webhbase/status/outbound" to="response.body"/>
+ </route>
+ <route path="/hbase/*/regions?**">
+ <rewrite apply="WEBHBASE/webhbase/regions/outbound" to="response.body"/>
+ </route>
+ </routes>
+ <dispatch classname="org.apache.hadoop.gateway.hbase.HBaseHttpClientDispatch"/>
+</service>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/hive/0.13.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/hive/0.13.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/hive/0.13.0/rewrite.xml
new file mode 100644
index 0000000..765e017
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/hive/0.13.0/rewrite.xml
@@ -0,0 +1,21 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<rules>
+ <rule dir="IN" name="HIVE/hive/inbound" pattern="*://*:*/**/hive">
+ <rewrite template="{$serviceUrl[HIVE]}"/>
+ </rule>
+</rules>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml b/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
new file mode 100644
index 0000000..32d1560
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
@@ -0,0 +1,22 @@
+<!--
+ 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.
+-->
+<service role="HIVE" name="hive" version="0.13.0">
+ <routes>
+ <route path="/hive"/>
+ </routes>
+ <dispatch classname="org.apache.hadoop.gateway.hive.HiveHttpClientDispatch"/>
+</service>
[6/6] knox git commit: Merge branch 'KNOX-481' of
https://git-wip-us.apache.org/repos/asf/knox into KNOX-481
Posted by su...@apache.org.
Merge branch 'KNOX-481' of https://git-wip-us.apache.org/repos/asf/knox into KNOX-481
Conflicts:
gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/ServiceDefinition.java
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/a1d43564
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/a1d43564
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/a1d43564
Branch: refs/heads/KNOX-481
Commit: a1d43564d67168725cbee477c4280d7962f8a99b
Parents: ea28bf2 9e0e3e8
Author: Sumit Gupta <su...@apache.org>
Authored: Thu Feb 12 12:49:15 2015 -0500
Committer: Sumit Gupta <su...@apache.org>
Committed: Thu Feb 12 12:49:15 2015 -0500
----------------------------------------------------------------------
.../gateway/config/impl/GatewayConfigImpl.java | 10 -----
.../service/definition/ServiceDefinition.java | 46 --------------------
2 files changed, 56 deletions(-)
----------------------------------------------------------------------
[3/6] knox git commit: Combined commits done for KNOX-481, KNOX-483,
KNOX-487
Posted by su...@apache.org.
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.
}
[2/6] knox git commit: Combined commits done for KNOX-481, KNOX-483,
KNOX-487
Posted by su...@apache.org.
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/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 1bf5fc0..177ef8d 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.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import javax.servlet.FilterChain;
@@ -38,48 +39,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public abstract class AbstractGatewayDispatch extends AbstractGatewayFilter implements Dispatch {
+public abstract class AbstractGatewayDispatch 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( "Host", "Authorization", "Content-Length", "Transfer-Encoding" );
- private static Map<String,Adapter> createMethodAdapters() {
- Map<String,Adapter> map = new HashMap<String,Adapter>();
- map.put( "GET", new GetAdapter() );
- map.put( "POST", new PostAdapter() );
- map.put( "PUT", new PutAdapter() );
- map.put( "DELETE", new DeleteAdapter() );
- map.put( "OPTIONS", new OptionsAdapter() );
- return Collections.unmodifiableMap( map );
- }
-
- @Override
- protected void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain )
- throws IOException, ServletException {
- String method = request.getMethod().toUpperCase();
- Adapter adapter = METHOD_ADAPTERS.get( method );
- if( adapter != null ) {
- try {
- adapter.doMethod( this, request, response );
- } catch( URISyntaxException e ) {
- throw new ServletException( e );
- }
- } else {
- response.sendError( HttpServletResponse.SC_METHOD_NOT_ALLOWED );
- }
- }
-
- protected 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;
- }
+ protected HttpClient client;
protected void writeResponse( HttpServletRequest request, HttpServletResponse response, InputStream stream )
throws IOException {
@@ -98,6 +63,16 @@ public abstract class AbstractGatewayDispatch extends AbstractGatewayFilter impl
// }
}
+ @Override
+ public HttpClient getHttpClient() {
+ return client;
+ }
+
+ @Override
+ public void setHttpClient(HttpClient client) {
+ this.client = client;
+ }
+
public void doGet( URI url, HttpServletRequest request, HttpServletResponse response )
throws IOException, URISyntaxException {
response.sendError( HttpServletResponse.SC_METHOD_NOT_ALLOWED );
@@ -122,46 +97,6 @@ public abstract class AbstractGatewayDispatch extends AbstractGatewayFilter impl
throws IOException, URISyntaxException {
response.sendError( HttpServletResponse.SC_METHOD_NOT_ALLOWED );
}
-
- private interface Adapter {
- public void doMethod( Dispatch dispatch, HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException, URISyntaxException;
- }
-
- private static class GetAdapter implements Adapter {
- public void doMethod( Dispatch dispatch, HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException, URISyntaxException {
- dispatch.doGet( getDispatchUrl( request ), request, response );
- }
- }
-
- private static class PostAdapter implements Adapter {
- public void doMethod( Dispatch dispatch, HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException, URISyntaxException {
- dispatch.doPost( getDispatchUrl( request ), request, response );
- }
- }
-
- private static class PutAdapter implements Adapter {
- public void doMethod( Dispatch dispatch, HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException, URISyntaxException {
- dispatch.doPut( getDispatchUrl( request ), request, response );
- }
- }
-
- private static class DeleteAdapter implements Adapter {
- public void doMethod( Dispatch dispatch, HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException, URISyntaxException {
- dispatch.doDelete( getDispatchUrl( request ), request, response );
- }
- }
-
- private static class OptionsAdapter implements Adapter {
- public void doMethod( Dispatch dispatch, HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException, URISyntaxException {
- dispatch.doOptions( getDispatchUrl( request ), request, response );
- }
- }
public static void copyRequestHeaderFields(HttpUriRequest outboundRequest,
HttpServletRequest inboundRequest) {
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/Dispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/Dispatch.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/Dispatch.java
index 072a2c6..0ce1339 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/Dispatch.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/Dispatch.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.gateway.dispatch;
+import org.apache.http.client.HttpClient;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -26,6 +28,14 @@ import java.net.URISyntaxException;
public interface Dispatch {
+ void init();
+
+ void destroy();
+
+ HttpClient getHttpClient();
+
+ void setHttpClient(HttpClient httpClient);
+
void doGet( URI url, HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException, URISyntaxException;
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/GatewayDispatchFilter.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/GatewayDispatchFilter.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/GatewayDispatchFilter.java
new file mode 100644
index 0000000..f359568
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/GatewayDispatchFilter.java
@@ -0,0 +1,152 @@
+/**
+ * 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.dispatch;
+
+import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.hadoop.gateway.config.ConfigurationInjectorBuilder.configuration;
+
+public class GatewayDispatchFilter extends AbstractGatewayFilter {
+
+ private static Map<String, Adapter> METHOD_ADAPTERS = createMethodAdapters();
+
+ private Dispatch dispatch;
+
+ private static Map<String, Adapter> createMethodAdapters() {
+ Map<String, Adapter> map = new HashMap<String, Adapter>();
+ map.put("GET", new GetAdapter());
+ map.put("POST", new PostAdapter());
+ map.put("PUT", new PutAdapter());
+ map.put("DELETE", new DeleteAdapter());
+ map.put("OPTIONS", new OptionsAdapter());
+ return Collections.unmodifiableMap(map);
+ }
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ super.init(filterConfig);
+ String dispatchImpl = filterConfig.getInitParameter("dispatch-impl");
+ dispatch = newDispatch(dispatchImpl);
+ configuration().target(dispatch).source(filterConfig).inject();
+ CloseableHttpClient client = HttpClients.createSystem();
+ //[sumit] this can perhaps be stashed in the servlet context to increase sharing of the client
+ dispatch.setHttpClient(client);
+ dispatch.init();
+ }
+
+ public Dispatch getDispatch() {
+ return dispatch;
+ }
+
+ public void setDispatch(Dispatch dispatch) {
+ this.dispatch = dispatch;
+ }
+
+ @Override
+ protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
+ String method = request.getMethod().toUpperCase();
+ Adapter adapter = METHOD_ADAPTERS.get(method);
+ if ( adapter != null ) {
+ try {
+ adapter.doMethod(dispatch, request, response);
+ } catch ( URISyntaxException e ) {
+ throw new ServletException(e);
+ }
+ } else {
+ response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ }
+ }
+
+ protected 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;
+ }
+
+ private interface Adapter {
+ public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, URISyntaxException;
+ }
+
+ private static class GetAdapter implements Adapter {
+ public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, URISyntaxException {
+ dispatch.doGet(getDispatchUrl(request), request, response);
+ }
+ }
+
+ private static class PostAdapter implements Adapter {
+ public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, URISyntaxException {
+ dispatch.doPost(getDispatchUrl(request), request, response);
+ }
+ }
+
+ private static class PutAdapter implements Adapter {
+ public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, URISyntaxException {
+ dispatch.doPut(getDispatchUrl(request), request, response);
+ }
+ }
+
+ private static class DeleteAdapter implements Adapter {
+ public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, URISyntaxException {
+ dispatch.doDelete(getDispatchUrl(request), request, response);
+ }
+ }
+
+ private static class OptionsAdapter implements Adapter {
+ public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, URISyntaxException {
+ dispatch.doOptions(getDispatchUrl(request), request, response);
+ }
+ }
+
+ private Dispatch newDispatch(String dispatchImpl) throws ServletException {
+ try {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if ( loader == null ) {
+ loader = this.getClass().getClassLoader();
+ }
+ Class<Dispatch> clazz = (Class) loader.loadClass(dispatchImpl);
+ return clazz.newInstance();
+ } catch ( Exception e ) {
+ throw new ServletException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
index 4de9730..e5810d4 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatch.java
@@ -35,6 +35,8 @@ import org.apache.hadoop.gateway.audit.api.AuditServiceFactory;
import org.apache.hadoop.gateway.audit.api.Auditor;
import org.apache.hadoop.gateway.audit.api.ResourceType;
import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
+import org.apache.hadoop.gateway.config.Configure;
+import org.apache.hadoop.gateway.config.Default;
import org.apache.hadoop.gateway.config.GatewayConfig;
import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
@@ -43,6 +45,7 @@ import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpOptions;
@@ -59,43 +62,39 @@ import org.apache.http.message.BasicHeader;
*/
public class HttpClientDispatch extends AbstractGatewayDispatch {
- private static final String REPLAY_BUFFER_SIZE = "replayBufferSize";
+ // private static final String CT_APP_WWW_FORM_URL_ENCODED = "application/x-www-form-urlencoded";
+ // private static final String CT_APP_XML = "application/xml";
+ protected static final String Q_DELEGATION_EQ = "?delegation=";
+ protected static final String AMP_DELEGATION_EQ = "&delegation=";
+ protected static final String COOKIE = "Cookie";
+ protected static final String SET_COOKIE = "Set-Cookie";
+ protected static final String WWW_AUTHENTICATE = "WWW-Authenticate";
+ protected static final String NEGOTIATE = "Negotiate";
- // private static final String CT_APP_WWW_FORM_URL_ENCODED = "application/x-www-form-urlencoded";
- // private static final String CT_APP_XML = "application/xml";
- protected static final String Q_DELEGATION_EQ = "?delegation=";
- protected static final String AMP_DELEGATION_EQ = "&delegation=";
- protected static final String COOKIE = "Cookie";
- protected static final String SET_COOKIE = "Set-Cookie";
- protected static final String WWW_AUTHENTICATE = "WWW-Authenticate";
- protected static final String NEGOTIATE = "Negotiate";
+ protected static SpiGatewayMessages LOG = MessagesFactory.get(SpiGatewayMessages.class);
+ protected static SpiGatewayResources RES = ResourcesFactory.get(SpiGatewayResources.class);
+ protected static Auditor auditor = AuditServiceFactory.getAuditService().getAuditor(AuditConstants.DEFAULT_AUDITOR_NAME,
+ AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME);
- protected static SpiGatewayMessages LOG = MessagesFactory.get(SpiGatewayMessages.class);
- protected static SpiGatewayResources RES = ResourcesFactory.get(SpiGatewayResources.class);
- protected static Auditor auditor = AuditServiceFactory.getAuditService().getAuditor(AuditConstants.DEFAULT_AUDITOR_NAME,
- AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME);
+ protected AppCookieManager appCookieManager;
- protected AppCookieManager appCookieManager;
+ private int replayBufferSize = 0;
- protected static final String REPLAY_BUFFER_SIZE_PARAM = "replayBufferSize";
+ @Override
+ public void init() {
+ setAppCookieManager(new AppCookieManager());
+ }
- private int replayBufferSize = 0;
+ @Override
+ public void destroy() {
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- this.init(filterConfig, new AppCookieManager());
- }
+ }
- protected void init(FilterConfig filterConfig, AppCookieManager cookieManager) throws ServletException {
- super.init(filterConfig);
- appCookieManager = cookieManager;
- String replayBufferSizeString = filterConfig.getInitParameter(REPLAY_BUFFER_SIZE_PARAM);
- if (replayBufferSizeString != null) {
- setReplayBufferSize(Integer.valueOf(replayBufferSizeString));
- }
- }
+ public void setAppCookieManager(AppCookieManager appCookieManager) {
+ this.appCookieManager = appCookieManager;
+ }
- protected void executeRequest(
+ protected void executeRequest(
HttpUriRequest outboundRequest,
HttpServletRequest inboundRequest,
HttpServletResponse outboundResponse)
@@ -107,7 +106,6 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
protected HttpResponse executeOutboundRequest(HttpUriRequest outboundRequest) throws IOException {
LOG.dispatchRequest(outboundRequest.getMethod(), outboundRequest.getURI());
HttpResponse inboundResponse = null;
- DefaultHttpClient client = new DefaultHttpClient();
try {
String query = outboundRequest.getURI().getQuery();
@@ -190,7 +188,7 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
}
protected HttpResponse executeKerberosDispatch(HttpUriRequest outboundRequest,
- DefaultHttpClient client) throws IOException, ClientProtocolException {
+ HttpClient client) throws IOException, ClientProtocolException {
HttpResponse inboundResponse;
outboundRequest.removeHeaders(COOKIE);
String appCookie = appCookieManager.getCachedAppCookie();
@@ -302,7 +300,8 @@ public class HttpClientDispatch extends AbstractGatewayDispatch {
return replayBufferSize;
}
- protected void setReplayBufferSize(int size) {
+ @Configure
+ protected void setReplayBufferSize(@Default("8") int size) {
replayBufferSize = size;
}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
index 9763174..41270a9 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
@@ -27,6 +27,7 @@ public class Service {
private String role;
private String name;
+ private Version version;
private Map<String, String> params = new LinkedHashMap<String, String>();
private List<String> urls;
@@ -46,6 +47,14 @@ public class Service {
this.name = name;
}
+ public Version getVersion() {
+ return version;
+ }
+
+ public void setVersion(Version version) {
+ this.version = version;
+ }
+
public List<String> getUrls() {
if ( urls == null ) {
urls = new ArrayList<String>();
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
index c8d611d..2f5d671 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
@@ -17,12 +17,11 @@
*/
package org.apache.hadoop.gateway.topology;
+import org.apache.commons.collections.map.HashedMap;
+import org.apache.commons.collections.map.MultiKeyMap;
+
import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class Topology {
@@ -32,7 +31,12 @@ public class Topology {
public List<Provider> providerList = new ArrayList<Provider>();
private Map<String,Map<String,Provider>> providerMap = new HashMap<String,Map<String,Provider>>();
public List<Service> services = new ArrayList<Service>();
- private Map<String, Map<String, Service>> serviceMap = new HashMap<String, Map<String, Service>>();
+
+ private MultiKeyMap serviceMap;
+
+ public Topology() {
+ serviceMap = MultiKeyMap.decorate(new HashedMap());
+ }
public URI getUri() {
return uri;
@@ -62,27 +66,13 @@ public class Topology {
return services;
}
- public Service getService( String role, String name ) {
- Service service = null;
- Map<String, Service> nameMap = serviceMap.get( role );
- if( nameMap != null) {
- service = nameMap.get( name );
- if ( service == null && !nameMap.values().isEmpty() ) {
- service = (Service) nameMap.values().toArray()[0];
- }
- }
- return service;
+ public Service getService(String role, String name, Version version) {
+ return (Service)serviceMap.get(role, name, version);
}
public void addService( Service service ) {
services.add( service );
- String role = service.getRole();
- Map<String, Service> nameMap = serviceMap.get( role );
- if( nameMap == null ) {
- nameMap = new HashMap<String, Service>();
- serviceMap.put( role, nameMap );
- }
- nameMap.put( service.getName(), service );
+ serviceMap.put(service.getRole(), service.getName(), service.getVersion(), service);
}
public Collection<Provider> getProviders() {
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Version.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Version.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Version.java
new file mode 100644
index 0000000..08aca08
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Version.java
@@ -0,0 +1,130 @@
+/**
+ * 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.topology;
+
+public class Version implements Comparable<Version> {
+
+ private int major;
+
+ private int minor;
+
+ private int patch;
+
+ public Version() {
+ }
+
+ public Version(String version) {
+ setVersion(version);
+ }
+
+ public Version(int major, int minor, int patch) {
+ this.major = major;
+ this.minor = minor;
+ this.patch = patch;
+ }
+
+ public int getMajor() {
+ return major;
+ }
+
+ public void setMajor(int major) {
+ this.major = major;
+ }
+
+ public int getMinor() {
+ return minor;
+ }
+
+ public void setMinor(int minor) {
+ this.minor = minor;
+ }
+
+ public int getPatch() {
+ return patch;
+ }
+
+ public void setPatch(int patch) {
+ this.patch = patch;
+ }
+
+ public void setVersion(String version) {
+ if (version != null) {
+ parseVersion(version);
+ }
+ }
+
+ private void parseVersion(String version) {
+ String parts[] = version.split("\\.");
+ int length = parts.length;
+ if (length >= 1) {
+ major = Integer.parseInt(parts[0]);
+ }
+ if (length >= 2) {
+ minor = Integer.parseInt(parts[1]);
+ }
+ if (length >= 3) {
+ patch = Integer.parseInt(parts[2]);
+ }
+ }
+
+ @Override
+ public int compareTo(Version version) {
+ if (major > version.getMajor()) {
+ return 1;
+ }
+ if (major < version.getMajor()) {
+ return -1;
+ }
+ if (minor > version.getMinor()) {
+ return 1;
+ }
+ if (minor < version.getMinor()) {
+ return -1;
+ }
+ if (patch > version.getPatch()) {
+ return 1;
+ }
+ if (patch < version.getPatch()) {
+ return -1;
+ }
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(major);
+ buffer.append(".");
+ buffer.append(minor);
+ buffer.append(".");
+ buffer.append(patch);
+ return buffer.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof Version)) {
+ return false;
+ }
+ Version that = (Version) o;
+ if (major == that.getMajor() && minor == that.getMinor() && patch == that.getPatch()) {
+ return true;
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor b/gateway-spi/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor
new file mode 100755
index 0000000..4c1cad9
--- /dev/null
+++ b/gateway-spi/src/main/resources/META-INF/services/org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor
@@ -0,0 +1,18 @@
+##########################################################################
+# 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.config.FilterConfigurationAdapterDescriptor
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java b/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
index b9b26b6..9446ab5 100644
--- a/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
+++ b/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/HttpClientDispatchTest.java
@@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.hadoop.gateway.config.GatewayConfig;
import org.apache.http.HttpEntity;
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;
@@ -76,6 +77,7 @@ public class HttpClientDispatchTest {
EasyMock.replay( outboundRequest, inboundRequest, outboundResponse );
HttpClientDispatch dispatch = new HttpClientDispatch();
+ dispatch.setHttpClient(new DefaultHttpClient());
try {
dispatch.executeRequest( outboundRequest, inboundRequest, outboundResponse );
fail( "Should have thrown IOException" );
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
index 6faccac..6117c76 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
@@ -157,6 +157,18 @@ public class GatewayFuncTestDriver {
} catch (ServiceLifecycleException e) {
e.printStackTrace(); // I18N not required.
}
+ File stacksDir = new File( config.getGatewayStacksDir() );
+ stacksDir.mkdirs();
+ //TODO: [sumit] This is a hack for now, need to find a better way to locate the source resources for 'stacks' to be tested
+ String pathToStacksSource = "gateway-service-definitions/src/main/resources/services";
+ File stacksSourceDir = new File( targetDir.getParent(), pathToStacksSource);
+ if (!stacksSourceDir.exists()) {
+ stacksSourceDir = new File( targetDir.getParentFile().getParent(), pathToStacksSource);
+ }
+ if (stacksSourceDir.exists()) {
+ FileUtils.copyDirectoryToDirectory(stacksSourceDir, stacksDir);
+ }
+
gateway = GatewayServer.startGateway( config, srvcs );
MatcherAssert.assertThat( "Failed to start gateway.", gateway, notNullValue() );
@@ -170,6 +182,7 @@ public class GatewayFuncTestDriver {
FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) );
FileUtils.deleteQuietly( new File( config.getGatewayDeploymentDir() ) );
FileUtils.deleteQuietly( new File( config.getGatewayDataDir() ) );
+ FileUtils.deleteQuietly( new File( config.getGatewayStacksDir() ) );
for( Service service : services.values() ) {
service.server.stop();
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index a013505..259ff09 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -189,5 +189,9 @@ public class GatewayTestConfig implements GatewayConfig {
// public void setKerberosLoginConfig(String kerberosLoginConfig) {
// this.kerberosLoginConfig = kerberosLoginConfig;
// }
-
+
+ @Override
+ public String getGatewayStacksDir() {
+ return gatewayHomeDir + "/data/services";
+ }
}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
index fc699b1..8b54f6f 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
@@ -82,6 +82,7 @@ public class DeploymentFactoryFuncTest {
// ((GatewayTestConfig) config).setDeploymentDir( "clusters" );
+ addStacksDir(config, targetDir);
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String,String> options = new HashMap<String,String>();
options.put("persist-master", "false");
@@ -135,6 +136,7 @@ public class DeploymentFactoryFuncTest {
((GatewayTestConfig) config).setGatewayHomeDir( gatewayDir.getAbsolutePath() );
File deployDir = new File( config.getGatewayDeploymentDir() );
deployDir.mkdirs();
+ addStacksDir(config, targetDir);
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String,String> options = new HashMap<String,String>();
@@ -189,6 +191,7 @@ public class DeploymentFactoryFuncTest {
((GatewayTestConfig) config).setGatewayHomeDir( gatewayDir.getAbsolutePath() );
File deployDir = new File( config.getGatewayDeploymentDir() );
deployDir.mkdirs();
+ addStacksDir(config, targetDir);
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String,String> options = new HashMap<String,String>();
@@ -228,8 +231,8 @@ public class DeploymentFactoryFuncTest {
topology.addProvider( authorizer );
WebArchive war = DeploymentFactory.createDeployment( config, topology );
- //File dir = new File( System.getProperty( "user.dir" ) );
- //File file = war.as( ExplodedExporter.class ).exportExploded( dir, "test-cluster.war" );
+// File dir = new File( System.getProperty( "user.dir" ) );
+// File file = war.as( ExplodedExporter.class ).exportExploded( dir, "test-cluster.war" );
Document web = parse( war.get( "WEB-INF/web.xml" ).getAsset().openStream() );
assertThat( web, hasXPath( "/web-app/servlet/servlet-name", equalTo( "test-cluster" ) ) );
@@ -264,8 +267,8 @@ public class DeploymentFactoryFuncTest {
assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[6]/class", equalTo( "org.apache.hadoop.gateway.filter.AclsAuthorizationFilter" ) ) );
assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[7]/role", equalTo( "dispatch" ) ) );
- assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[7]/name", equalTo( "hdfs" ) ) );
- assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[7]/class", equalTo( "org.apache.hadoop.gateway.hdfs.dispatch.HdfsDispatch" ) ) );
+ assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[7]/name", equalTo( "webhdfs" ) ) );
+ assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[7]/class", equalTo( "org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter" ) ) );
assertThat( gateway, hasXPath( "/gateway/resource[2]/pattern", equalTo( "/webhdfs/v1/**?**" ) ) );
//assertThat( gateway, hasXPath( "/gateway/resource[2]/target", equalTo( "http://localhost:50070/webhdfs/v1/{path=**}?{**}" ) ) );
@@ -290,8 +293,8 @@ public class DeploymentFactoryFuncTest {
assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[6]/class", equalTo( "org.apache.hadoop.gateway.filter.AclsAuthorizationFilter" ) ) );
assertThat( gateway, hasXPath( "/gateway/resource[2]/filter[7]/role", equalTo( "dispatch" ) ) );
- assertThat( gateway, hasXPath( "/gateway/resource[2]/filter[7]/name", equalTo( "hdfs" ) ) );
- assertThat( gateway, hasXPath( "/gateway/resource[2]/filter[7]/class", equalTo( "org.apache.hadoop.gateway.hdfs.dispatch.HdfsDispatch" ) ) );
+ assertThat( gateway, hasXPath( "/gateway/resource[2]/filter[7]/name", equalTo( "webhdfs" ) ) );
+ assertThat( gateway, hasXPath( "/gateway/resource[2]/filter[7]/class", equalTo( "org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter" ) ) );
}
@@ -379,6 +382,7 @@ public class DeploymentFactoryFuncTest {
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
+ addStacksDir(config, targetDir);
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<String, String>();
@@ -453,6 +457,7 @@ public class DeploymentFactoryFuncTest {
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
+ addStacksDir(config, targetDir);
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<String, String>();
@@ -499,7 +504,7 @@ public class DeploymentFactoryFuncTest {
WebArchive war = DeploymentFactory.createDeployment( config, topology );
Document doc = parse( war.get( "WEB-INF/gateway.xml" ).getAsset().openStream() );
- //dump( doc );
+ dump( doc );
Node resourceNode, filterNode, paramNode;
String value;
@@ -538,6 +543,33 @@ public class DeploymentFactoryFuncTest {
return builder.parse( source );
}
+ private void addStacksDir(GatewayConfig config, File targetDir) {
+ File stacksDir = new File( config.getGatewayStacksDir() );
+ stacksDir.mkdirs();
+ //TODO: [sumit] This is a hack for now, need to find a better way to locate the source resources for 'stacks' to be tested
+ String pathToStacksSource = "gateway-service-definitions/src/main/resources/services";
+ File stacksSourceDir = new File( targetDir.getParent(), pathToStacksSource);
+ if (!stacksSourceDir.exists()) {
+ stacksSourceDir = new File( targetDir.getParentFile().getParent(), pathToStacksSource);
+ }
+ if (stacksSourceDir.exists()) {
+ try {
+ FileUtils.copyDirectoryToDirectory(stacksSourceDir, stacksDir);
+ } catch ( IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ }
+// private void dump( Document document ) throws TransformerException {
+// Transformer transformer = TransformerFactory.newInstance().newTransformer();
+// transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
+// StreamResult result = new StreamResult( new StringWriter() );
+// DOMSource source = new DOMSource( document );
+// transformer.transform( source, result );
+// String xmlString = result.getWriter().toString();
+// System.out.println( xmlString );
+// }
private void dump( Document document ) throws TransformerException {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-test/src/test/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributorTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributorTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributorTest.java
deleted file mode 100644
index 8b3303d..0000000
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/webhcat/WebHCatDeploymentContributorTest.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.webhcat;
-
-import org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor;
-import org.junit.Test;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.fail;
-
-public class WebHCatDeploymentContributorTest {
-
- @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 WebHCatDeploymentContributor ) {
- return;
- }
- }
- fail( "Failed to find " + WebHCatDeploymentContributor.class.getName() + " via service loader." );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/pom.xml b/gateway-util-configinjector/pom.xml
new file mode 100755
index 0000000..b247e99
--- /dev/null
+++ b/gateway-util-configinjector/pom.xml
@@ -0,0 +1,63 @@
+<?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-util-configinjector</artifactId>
+
+ <name>gateway-util-configinjector</name>
+ <description>A lightweight config injection utility</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <scope>compile</scope>
+ <version>1.9.2</version>
+ </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>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</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-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Alias.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Alias.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Alias.java
new file mode 100755
index 0000000..b002e7a
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Alias.java
@@ -0,0 +1,31 @@
+/**
+ * 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 java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER} )
+@Retention( RetentionPolicy.RUNTIME )
+@Documented
+public @interface Alias {
+ public String value();
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationAdapter.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationAdapter.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationAdapter.java
new file mode 100755
index 0000000..401258f
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationAdapter.java
@@ -0,0 +1,24 @@
+/**
+ * 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;
+
+public interface ConfigurationAdapter {
+
+ Object getConfigurationValue(String name) throws ConfigurationException;
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationBinding.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationBinding.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationBinding.java
new file mode 100755
index 0000000..a2b2b67
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationBinding.java
@@ -0,0 +1,24 @@
+/**
+ * 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;
+
+public interface ConfigurationBinding {
+
+ String getConfigurationName(String name);
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationException.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationException.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationException.java
new file mode 100755
index 0000000..c979cc6
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationException.java
@@ -0,0 +1,30 @@
+/**
+ * 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;
+
+public class ConfigurationException extends RuntimeException {
+
+ public ConfigurationException( String message, Throwable cause ) {
+ super( message, cause );
+ }
+
+ public ConfigurationException( String message ) {
+ super( message );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationInjectorBuilder.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationInjectorBuilder.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationInjectorBuilder.java
new file mode 100755
index 0000000..e0fadbd
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/ConfigurationInjectorBuilder.java
@@ -0,0 +1,107 @@
+/**
+ * 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.impl.ConfigurationAdapterFactory;
+import org.apache.hadoop.gateway.config.impl.DefaultConfigurationBinding;
+import org.apache.hadoop.gateway.config.impl.MappedConfigurationBinding;
+import org.apache.hadoop.gateway.config.spi.ConfigurationInjector;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+public class ConfigurationInjectorBuilder {
+
+ private static ConfigurationBinding DEFAULT_BINDING = new DefaultConfigurationBinding();
+ private static ConfigurationInjector INSTANCE = null;
+
+ private static synchronized ConfigurationInjector getInjector() {
+ if( INSTANCE == null ) {
+ INSTANCE = createInjector();
+ }
+ return INSTANCE;
+ }
+
+ private static synchronized ConfigurationInjector createInjector() {
+ ConfigurationInjector injector = null;
+ ServiceLoader<ConfigurationInjector> loader = ServiceLoader.load( ConfigurationInjector.class );
+ if( loader != null ) {
+ Iterator<ConfigurationInjector> iterator = loader.iterator();
+ if( iterator != null ) {
+ while( iterator.hasNext() ) {
+ injector = iterator.next();
+ break;
+ }
+ }
+ }
+ if( injector == null ) {
+ throw new ConfigurationException( String.format(
+ "Failed to load an implementation of %s", ConfigurationInjector.class.getName() ) );
+ }
+ return injector;
+ }
+
+ private Object target = null;
+ private ConfigurationAdapter source = null;
+ private ConfigurationBinding binding = null;
+
+ public static ConfigurationInjectorBuilder configuration() {
+ return new ConfigurationInjectorBuilder();
+ }
+
+ public ConfigurationInjectorBuilder target( Object target ) {
+ this.target = target;
+ return this;
+ }
+
+ public ConfigurationInjectorBuilder source( Object source ) {
+ this.source = ConfigurationAdapterFactory.get(source);
+ return this;
+ }
+
+ public ConfigurationInjectorBuilder source( ConfigurationAdapter adapter ) {
+ this.source = adapter;
+ return this;
+ }
+
+ public ConfigurationInjectorBuilder binding( ConfigurationBinding binding ) {
+ this.binding = binding;
+ return this;
+ }
+
+ public ConfigurationInjectorBuilder bind( String targetName, String sourceName ) {
+ ((MappedConfigurationBinding)binding()).bind( targetName, sourceName );
+ return this;
+ }
+
+ public ConfigurationBinding binding() {
+ if( binding == null ) {
+ binding = new MappedConfigurationBinding();
+ }
+ return binding;
+ }
+
+ public void inject() throws ConfigurationException {
+ ConfigurationInjector injector = getInjector();
+ if( binding == null ) {
+ binding = DEFAULT_BINDING;
+ }
+ injector.configure( target, source, binding );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Configure.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Configure.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Configure.java
new file mode 100755
index 0000000..895648f
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Configure.java
@@ -0,0 +1,30 @@
+/**
+ * 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 java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER} )
+@Retention( RetentionPolicy.RUNTIME )
+@Documented
+public @interface Configure {
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Default.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Default.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Default.java
new file mode 100755
index 0000000..1ef9042
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Default.java
@@ -0,0 +1,31 @@
+/**
+ * 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 java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target( { ElementType.PARAMETER } )
+@Retention( RetentionPolicy.RUNTIME )
+@Documented
+public @interface Default {
+ public String value();
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Optional.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Optional.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Optional.java
new file mode 100755
index 0000000..1299e75
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/Optional.java
@@ -0,0 +1,30 @@
+/**
+ * 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 java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target( { ElementType.FIELD } )
+@Retention( RetentionPolicy.RUNTIME )
+@Documented
+public @interface Optional {
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapter.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapter.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapter.java
new file mode 100755
index 0000000..67459a4
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapter.java
@@ -0,0 +1,40 @@
+/**
+ * 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.impl;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+import org.apache.hadoop.gateway.config.ConfigurationException;
+
+public class BeanConfigurationAdapter implements ConfigurationAdapter {
+
+ private Object bean;
+
+ public BeanConfigurationAdapter( Object bean ) {
+ this.bean = bean;
+ }
+
+ @Override
+ public Object getConfigurationValue( String name ) throws ConfigurationException {
+ try {
+ return PropertyUtils.getSimpleProperty( bean, name );
+ } catch( Exception e ) {
+ throw new ConfigurationException( String.format( "" ), e );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptor.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptor.java
new file mode 100755
index 0000000..92a6cca
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/BeanConfigurationAdapterDescriptor.java
@@ -0,0 +1,30 @@
+/**
+ * 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.impl;
+
+import org.apache.hadoop.gateway.config.spi.AbstractConfigurationAdapterDescriptor;
+
+import java.util.Map;
+
+public class BeanConfigurationAdapterDescriptor extends AbstractConfigurationAdapterDescriptor {
+
+ public BeanConfigurationAdapterDescriptor() {
+ add( Object.class, BeanConfigurationAdapter.class );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/ConfigurationAdapterFactory.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/ConfigurationAdapterFactory.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/ConfigurationAdapterFactory.java
new file mode 100755
index 0000000..73cd97b
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/ConfigurationAdapterFactory.java
@@ -0,0 +1,132 @@
+/**
+ * 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.impl;
+
+
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+import org.apache.hadoop.gateway.config.ConfigurationException;
+import org.apache.hadoop.gateway.config.spi.ConfigurationAdapterDescriptor;
+
+import java.lang.reflect.Constructor;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+public class ConfigurationAdapterFactory {
+
+ private static Map<Class<?>, Class<? extends ConfigurationAdapter>> ADAPTERS = null;
+
+ private static synchronized Map<Class<?>, Class<? extends ConfigurationAdapter>> getAdapters() {
+ if( ADAPTERS == null ) {
+ loadAdapters();
+ }
+ return ADAPTERS;
+ }
+
+ private static void loadAdapters() {
+ Map<Class<?>, Class<? extends ConfigurationAdapter>> all =
+ new HashMap<Class<?>, Class<? extends ConfigurationAdapter>>();
+ ServiceLoader<ConfigurationAdapterDescriptor> loader = ServiceLoader.load( ConfigurationAdapterDescriptor.class );
+ if( loader != null ) {
+ Iterator<ConfigurationAdapterDescriptor> i = loader.iterator();
+ if( i != null ) {
+ while( i.hasNext() ) {
+ ConfigurationAdapterDescriptor descriptor = i.next();
+ Map<Class<?>, Class<? extends ConfigurationAdapter>> add = descriptor.providedConfigurationAdapters();
+ if( add != null ) {
+ all.putAll( add );
+ }
+ }
+ }
+ }
+ ADAPTERS = Collections.unmodifiableMap( all );
+ }
+
+ public static ConfigurationAdapter get( Object config ) throws ConfigurationException {
+ if( config == null ) {
+ throw new NullPointerException( "Configuration adapter instantiation impossible for null config object." );
+ }
+ try {
+ Map<Class<?>, Class<? extends ConfigurationAdapter>> adapters = getAdapters();
+ Class configType = config.getClass();
+ Class adapterType = findAdapterTypeForConfigTypeOrParent( adapters, configType );
+ if( adapterType == null ) {
+ throw new ConfigurationException( "No configuration adapter found for config type " + configType.getName() );
+ }
+ Constructor c = findConstructorForConfigType( adapterType, configType );
+ if( !c.isAccessible() ) {
+ c.setAccessible( true );
+ }
+ Object adapter = c.newInstance( config );
+ return ConfigurationAdapter.class.cast( adapter );
+ } catch( ConfigurationException e ) {
+ throw e;
+ } catch( Exception e ) {
+ throw new ConfigurationException( "Configuration adapter instantiation failed.", e );
+ }
+ }
+
+ public static Constructor findConstructorForConfigType( Class<?> adapterType, Class<?> configType ) throws NoSuchMethodException {
+ Constructor constructor = null;
+ Constructor[] constructors = adapterType.getConstructors();
+ for( Constructor candidate : constructors ) {
+ Class<?>[] paramTypes = candidate.getParameterTypes();
+ if( paramTypes.length == 1 ) {
+ Class<?> paramType = paramTypes[0];
+ if( paramType.isAssignableFrom( configType ) ) {
+ constructor = candidate;
+ break;
+ }
+ }
+ }
+ if( constructor == null ) {
+ throw new NoSuchMethodException( "No constructor for " + adapterType.getName() + " that will accept " + configType.getName() );
+ }
+ return constructor;
+ }
+
+ public static Class<? extends ConfigurationAdapter> findAdapterTypeForConfigTypeOrParent(
+ Map<Class<?>, Class<? extends ConfigurationAdapter>> adapters, Class<?> configType ) {
+ Class<? extends ConfigurationAdapter> adapterType = null;
+ while( configType != null ) {
+ adapterType = findAdapterTypeForConfigType( adapters, configType );
+ if( adapterType != null ) {
+ break;
+ }
+ configType = configType.getSuperclass();
+ }
+ return adapterType;
+ }
+
+ public static Class<? extends ConfigurationAdapter> findAdapterTypeForConfigType(
+ Map<Class<?>, Class<? extends ConfigurationAdapter>> adapters, Class<?> configType ) {
+ Class<? extends ConfigurationAdapter> adapterType = adapters.get( configType );
+ if( adapterType == null ) {
+ for( Class interfaceType : configType.getInterfaces() ) {
+ adapterType = findAdapterTypeForConfigTypeOrParent( adapters, interfaceType );
+ if( adapterType != null ) {
+ break;
+ }
+ }
+ }
+ return adapterType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationBinding.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationBinding.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationBinding.java
new file mode 100755
index 0000000..5629bc1
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationBinding.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.impl;
+
+import org.apache.hadoop.gateway.config.ConfigurationBinding;
+
+public class DefaultConfigurationBinding implements ConfigurationBinding {
+
+ @Override
+ public String getConfigurationName( String name ) {
+ return name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationInjector.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationInjector.java
new file mode 100755
index 0000000..8b86ba1
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/DefaultConfigurationInjector.java
@@ -0,0 +1,224 @@
+/**
+ * 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.impl;
+
+import org.apache.commons.beanutils.ConvertUtilsBean2;
+import org.apache.hadoop.gateway.config.*;
+import org.apache.hadoop.gateway.config.spi.ConfigurationInjector;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+public class DefaultConfigurationInjector implements ConfigurationInjector {
+
+ private static ConvertUtilsBean2 DEFAULT_CONVERTER = new ConvertUtilsBean2();
+
+ @Override
+ public void configure( Object target, ConfigurationAdapter adapter, ConfigurationBinding binding )
+ throws ConfigurationException {
+ Class type = target.getClass();
+ while( type != null ) {
+ injectClass( type, target, adapter, binding );
+ type = type.getSuperclass();
+ }
+ }
+
+ private void injectClass( Class type, Object target, ConfigurationAdapter config, ConfigurationBinding binding )
+ throws ConfigurationException {
+ Field[] fields = type.getDeclaredFields();
+ for( Field field : fields ) {
+ injectFieldValue( field, target, config, binding );
+ }
+ Method[] methods = type.getDeclaredMethods();
+ for( Method method : methods ) {
+ injectMethodValue( method, target, config, binding );
+ }
+ }
+
+ private void injectFieldValue( Field field, Object target, ConfigurationAdapter adapter, ConfigurationBinding binding )
+ throws ConfigurationException {
+ Configure annotation = field.getAnnotation( Configure.class );
+ if( annotation != null ) {
+ Alias alias = field.getAnnotation( Alias.class );
+ String name = getConfigName( field, alias );
+ String bind = getBindName( target, name, binding );
+ Object value = retrieveValue( target, bind, name, field.getType(), adapter, binding );
+ if( value == null ) {
+ Optional optional = field.getAnnotation( Optional.class );
+ if( optional == null ) {
+ throw new ConfigurationException( String.format(
+ "Failed to find configuration for %s bound to %s of %s via %s",
+ bind, name, target.getClass().getName(), adapter.getClass().getName() ) );
+ }
+ } else {
+ try {
+ if( !field.isAccessible() ) {
+ field.setAccessible( true );
+ }
+ field.set( target, value );
+ } catch( Exception e ) {
+ throw new ConfigurationException( String.format(
+ "Failed to inject field configuration property %s of %s",
+ name, target.getClass().getName() ), e );
+ }
+ }
+ }
+ }
+
+ private void injectMethodValue( Method method, Object target, ConfigurationAdapter adapter, ConfigurationBinding binding )
+ throws ConfigurationException {
+ Configure methodTag = method.getAnnotation( Configure.class );
+ if( methodTag != null ) {
+ Alias aliasTag = method.getAnnotation( Alias.class );
+ String methodName = getConfigName( method, aliasTag );
+ Class[] argTypes = method.getParameterTypes();
+ Object[] args = new Object[ argTypes.length ];
+ Annotation[][] argTags = method.getParameterAnnotations();
+ for( int i=0; i<argTypes.length; i++ ) {
+ String argName = getConfigName( methodName, argTags[i] );
+ String bndName = getBindName( target, argName, binding );
+ Object argValue = retrieveValue( target, bndName, argName, argTypes[i], adapter, binding );
+ if( argValue == null ) {
+ Default defTag = findAnnotation( argTags[i], Default.class );
+ if( defTag != null ) {
+ String strValue = defTag.value();
+ argValue = convertValue( target, argName, strValue, argTypes[i] );
+ } else {
+ throw new ConfigurationException( String.format(
+ "Failed to find configuration for %s of %s via %s",
+ bndName, argName, target.getClass().getName(), adapter.getClass().getName() ) );
+ }
+ }
+ args[ i ] = argValue;
+ }
+ if( !method.isAccessible() ) {
+ method.setAccessible( true );
+ }
+ try {
+ method.invoke( target, args );
+ } catch( Exception e ) {
+ throw new ConfigurationException( String.format(
+ "Failed to inject method configuration via %s of %s",
+ methodName, target.getClass().getName() ), e );
+ }
+ }
+ }
+
+ private Object convertValue( Object target, String name, Object strValue, Class<?> type ) {
+ Object objValue = null;
+ try {
+ objValue = DEFAULT_CONVERTER.convert( strValue, type );
+ } catch( Exception e ) {
+ throw new ConfigurationException( String.format(
+ "Failed to convert configuration for %s of %s to %s",
+ name, target.getClass().getName(), type.getName() ), e );
+ }
+ return objValue;
+ }
+
+ private Object retrieveValue( Object target, String bind, String name, Class<?> type, ConfigurationAdapter adapter, ConfigurationBinding binding ) {
+ Object value;
+ try {
+ value = adapter.getConfigurationValue( bind );
+ } catch( Exception e ) {
+ throw new ConfigurationException( String.format(
+ "Failed to retrieve configuration for %s bound to %s of %s via %s",
+ bind, name, target.getClass().getName(), adapter.getClass().getName() ), e );
+ }
+ value = convertValue( target, name, value, type );
+ return value;
+ }
+
+ private <T extends Annotation> T findAnnotation( Annotation[] annotations, Class<T> type ) {
+ T found = null;
+ for( Annotation current : annotations ) {
+ if( type.isAssignableFrom( current.getClass() ) ) {
+ found = (T)current;
+ break;
+ }
+ }
+ return found;
+ }
+
+ private static String pickName( String implied, Alias explicit ) {
+ String name = implied;
+ if( explicit != null ) {
+ String tagValue = explicit.value().trim();
+ if( tagValue.length() > 0 ) {
+ name = tagValue;
+ }
+ }
+ return name;
+ }
+
+ private static String getBindName( Object target, String name, ConfigurationBinding binding ) {
+ String bind = null;
+ try {
+ bind = binding.getConfigurationName( name );
+ } catch( Exception e ) {
+ throw new ConfigurationException( String.format(
+ "Failed to bind configuration for %s of %s via %s",
+ name, target.getClass().getName(), binding.getClass().getName() ), e );
+ }
+ if( bind == null ) {
+ bind = name;
+ }
+ return bind;
+ }
+
+ private static String getConfigName( Field field, Alias tag ) {
+ return pickName( field.getName(), tag );
+ }
+
+ private static String getConfigName( String name, Annotation[] tags ) {
+ if( tags != null ) {
+ for( Annotation tag : tags ) {
+ if( tag != null && tag instanceof Alias ) {
+ Alias aliasTag = Alias.class.cast( tag );
+ String aliasValue = aliasTag.value().trim();
+ if( aliasValue.length() > 0 ) {
+ name = aliasValue;
+ break;
+ }
+ }
+ }
+ }
+ return name;
+ }
+
+ private static String getConfigName( Method method, Alias tag ) {
+ return pickName( getConfigName( method ), tag );
+ }
+
+ private static String getConfigName( Method method ) {
+ String methodName = method.getName();
+ StringBuilder name = new StringBuilder( methodName.length() );
+ if( methodName != null &&
+ methodName.length() > 3 &&
+ methodName.startsWith( "set" ) &&
+ Character.isUpperCase( methodName.charAt( 3 ) ) ) {
+ name.append( methodName.substring( 3 ) );
+ name.setCharAt( 0, Character.toLowerCase( name.charAt( 0 ) ) );
+ } else {
+ name.append( name );
+ }
+ return name.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapter.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapter.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapter.java
new file mode 100755
index 0000000..d0556f4
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapter.java
@@ -0,0 +1,37 @@
+/**
+ * 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.impl;
+
+import org.apache.hadoop.gateway.config.ConfigurationAdapter;
+
+import java.util.Map;
+
+public class MapConfigurationAdapter implements ConfigurationAdapter {
+
+ private Map config;
+
+ public MapConfigurationAdapter( Map map ) {
+ this.config = map;
+ }
+
+ @Override
+ public Object getConfigurationValue( String name ) {
+ return config.get( name );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapterDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapterDescriptor.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapterDescriptor.java
new file mode 100755
index 0000000..4099483
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MapConfigurationAdapterDescriptor.java
@@ -0,0 +1,30 @@
+/**
+ * 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.impl;
+
+import org.apache.hadoop.gateway.config.spi.AbstractConfigurationAdapterDescriptor;
+
+import java.util.Map;
+
+public class MapConfigurationAdapterDescriptor extends AbstractConfigurationAdapterDescriptor {
+
+ public MapConfigurationAdapterDescriptor() {
+ add( Map.class, MapConfigurationAdapter.class );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/ea28bf22/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MappedConfigurationBinding.java
----------------------------------------------------------------------
diff --git a/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MappedConfigurationBinding.java b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MappedConfigurationBinding.java
new file mode 100755
index 0000000..161869f
--- /dev/null
+++ b/gateway-util-configinjector/src/main/java/org/apache/hadoop/gateway/config/impl/MappedConfigurationBinding.java
@@ -0,0 +1,38 @@
+/**
+ * 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.impl;
+
+import org.apache.hadoop.gateway.config.ConfigurationBinding;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class MappedConfigurationBinding implements ConfigurationBinding {
+
+ private Map<String,String> map = new ConcurrentHashMap<String, String>();
+
+ public void bind( String targetName, String sourceName ) {
+ map.put( targetName, sourceName );
+ }
+
+ @Override
+ public String getConfigurationName( String name ) {
+ return map.get( name );
+ }
+
+}