You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by lm...@apache.org on 2013/09/17 19:32:18 UTC

git commit: KNOX-127 refactor a HostMappingService from the HostmapFunctionProcessor and make available through GatewayServices

Updated Branches:
  refs/heads/master 91da46f24 -> e60093da1


KNOX-127 refactor a HostMappingService from the HostmapFunctionProcessor and make available through GatewayServices

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

Branch: refs/heads/master
Commit: e60093da1fe79f8bfec53a7a8500df0cce96e8a6
Parents: 91da46f
Author: Larry McCay <lm...@hortonworks.com>
Authored: Tue Sep 17 13:28:48 2013 -0400
Committer: Larry McCay <lm...@hortonworks.com>
Committed: Tue Sep 17 13:28:48 2013 -0400

----------------------------------------------------------------------
 .../impl/HostmapDeploymentContributor.java      |  8 +-
 .../hostmap/impl/HostmapFunctionProcessor.java  | 52 ++++++------
 .../impl/HostmapFunctionProcessorTest.java      | 16 +++-
 .../services/DefaultGatewayServices.java        |  5 ++
 .../gateway/services/HssoGatewayServices.java   |  5 ++
 .../hostmap/impl/DefaultHostMappingService.java | 83 ++++++++++++++++++++
 .../gateway/services/GatewayServices.java       |  1 +
 .../services/hostmap/FileBasedHostMapper.java   | 78 ++++++++++++++++++
 .../gateway/services/hostmap/HostMapper.java    | 29 +++++++
 .../services/hostmap/HostMappingService.java    | 35 +++++++++
 10 files changed, 285 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapDeploymentContributor.java b/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapDeploymentContributor.java
index ba9274d..f79b046 100644
--- a/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapDeploymentContributor.java
+++ b/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapDeploymentContributor.java
@@ -24,6 +24,7 @@ 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.hostmap.api.HostmapFunctionDescriptor;
+import org.apache.hadoop.gateway.services.hostmap.HostMappingService;
 import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
 import org.jboss.shrinkwrap.api.asset.Asset;
@@ -42,7 +43,12 @@ public class HostmapDeploymentContributor
   public static final String PROVIDER_IMPL_NAME = "static";
 
   private static final String REWRITE_ROLE_NAME = "rewrite";
-
+  private HostMappingService hostMapping;
+  
+  private void setHostMappingService(HostMappingService hostMapping) {
+    this.hostMapping = hostMapping;
+  }
+  
   @Override
   public String getRole() {
     return PROVIDER_ROLE_NAME;

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessor.java b/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessor.java
index 9e71a4e..9be1dd2 100644
--- a/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-hostmap-static/src/main/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessor.java
@@ -21,12 +21,17 @@ import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
 import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
 import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
 import org.apache.hadoop.gateway.hostmap.api.HostmapFunctionDescriptor;
+import org.apache.hadoop.gateway.services.GatewayServices;
+import org.apache.hadoop.gateway.services.hostmap.FileBasedHostMapper;
+import org.apache.hadoop.gateway.services.hostmap.HostMappingService;
+import org.apache.hadoop.gateway.services.security.CryptoService;
 
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 public class HostmapFunctionProcessor
@@ -34,9 +39,10 @@ public class HostmapFunctionProcessor
 
   public static final String DESCRIPTOR_DEFAULT_FILE_NAME = "hostmap.txt";
   public static final String DESCRIPTOR_DEFAULT_LOCATION = "/WEB-INF/" + DESCRIPTOR_DEFAULT_FILE_NAME;
-
-  private Map<String, String> inbound = new HashMap<String, String>();
-  private Map<String, String> outbound = new HashMap<String, String>();
+  
+  private FileBasedHostMapper hostMapper = null;
+  private String clusterName;
+  private HostMappingService hostMappingService;
 
   @Override
   public String name() {
@@ -46,32 +52,28 @@ public class HostmapFunctionProcessor
   @Override
   public void initialize( UrlRewriteEnvironment environment, HostmapFunctionDescriptor descriptor ) throws Exception {
     URL url = environment.getResource( DESCRIPTOR_DEFAULT_LOCATION );
-    if( url != null ) {
-      InputStream stream = url.openStream();
-      BufferedReader reader = new BufferedReader( new InputStreamReader( stream ) );
-      String line = reader.readLine();
-      while( line != null ) {
-        String[] lineSplit = line.split( "=" );
-        if( lineSplit.length >= 2 ) {
-          String[] externalSplit = lineSplit[ 0 ].split( "," );
-          String[] internalSplit = lineSplit[ 1 ].split( "," );
-          if( externalSplit.length >= 1 && internalSplit.length >= 1 ) {
-            for( String external : externalSplit ) {
-              inbound.put( external, internalSplit[ 0 ] );
-            }
-            for( String internal : internalSplit ) {
-              outbound.put( internal, externalSplit[ 0 ] );
-            }
-          }
-        }
-        line = reader.readLine();
+    List<String> names = environment.resolve( "cluster.name" );
+    if (names != null && names.size() > 0) {
+      clusterName = names.get( 0 );
+    }
+    hostMapper = new FileBasedHostMapper(clusterName, url);
+
+    GatewayServices services = environment.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
+    if (clusterName != null && services != null) {
+      hostMappingService = (HostMappingService) services.getService(GatewayServices.HOST_MAPPING_SERVICE);
+      if (hostMappingService != null) {
+        hostMappingService.registerHostMapperForCluster(clusterName, hostMapper);
       }
-      reader.close();
     }
   }
 
   @Override
   public void destroy() throws Exception {
+    // need to remove the host mapper for the cluster on undeploy
+    if (clusterName != null && hostMappingService != null) {
+      hostMappingService.removeHostMapperForCluster(clusterName);
+    }
+    
   }
 
   @Override
@@ -79,10 +81,10 @@ public class HostmapFunctionProcessor
     String value;
     switch( context.getDirection() ) {
       case IN:
-        value = inbound.get( parameter );
+        value = hostMapper.resolveInboundHostName(parameter);
         break;
       case OUT:
-        value = outbound.get( parameter );
+        value = hostMapper.resolveOutboundHostName(parameter);
         break;
       default:
         value = null;

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java b/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
index 4790158..011a4bd 100644
--- a/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
+++ b/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
@@ -25,6 +25,9 @@ import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFac
 import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
 import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt;
 import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
+import org.apache.hadoop.gateway.services.GatewayServices;
+import org.apache.hadoop.gateway.services.hostmap.HostMapper;
+import org.apache.hadoop.gateway.services.hostmap.HostMappingService;
 import org.apache.hadoop.gateway.util.urltemplate.Parser;
 import org.apache.hadoop.gateway.util.urltemplate.Resolver;
 import org.apache.hadoop.gateway.util.urltemplate.Template;
@@ -62,11 +65,22 @@ public class HostmapFunctionProcessorTest {
   public void testBasicUseCase() throws Exception {
     URL configUrl = TestUtils.getResourceUrl( this.getClass(), "hostmap.txt" );
 
+    HostMapper hm = EasyMock.createNiceMock(HostMapper.class);
+    EasyMock.expect( hm.resolveInboundHostName("test-inbound-host")).andReturn( "test-inbound-rewritten-host" ).anyTimes();
+    
+    HostMappingService hms = EasyMock.createNiceMock( HostMappingService.class );
+
+    GatewayServices gatewayServices = EasyMock.createNiceMock( GatewayServices.class );
+    EasyMock.expect( gatewayServices.getService( GatewayServices.HOST_MAPPING_SERVICE ) ).andReturn( hms ).anyTimes();
+
+
     UrlRewriteEnvironment environment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
+    EasyMock.expect( environment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();    
+    EasyMock.expect( environment.resolve( "cluster.name" ) ).andReturn( Arrays.asList( "test-cluster-name" ) ).anyTimes();
     EasyMock.expect( environment.getResource( "/WEB-INF/hostmap.txt" ) ).andReturn( configUrl ).anyTimes();
     Resolver resolver = EasyMock.createNiceMock( Resolver.class );
     EasyMock.expect( resolver.resolve( "host" ) ).andReturn( Arrays.asList( "test-inbound-host" ) ).anyTimes();
-    EasyMock.replay( environment, resolver );
+    EasyMock.replay( gatewayServices, hm, hms, environment, resolver );
 
     UrlRewriteRulesDescriptor descriptor = UrlRewriteRulesDescriptorFactory.create();
     UrlRewriteRuleDescriptor rule = descriptor.addRule( "test-rule" );

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java
index 23fa983..b5687c1 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.gateway.deploy.DeploymentContext;
 import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
 import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+import org.apache.hadoop.gateway.services.hostmap.impl.DefaultHostMappingService;
 import org.apache.hadoop.gateway.services.registry.impl.DefaultServiceRegistryService;
 import org.apache.hadoop.gateway.services.security.KeystoreServiceException;
 import org.apache.hadoop.gateway.services.security.SSLService;
@@ -87,6 +88,10 @@ public class DefaultGatewayServices implements GatewayServices {
     sr.setCryptoService( crypto );
     sr.init( config, options );
     services.put( SERVICE_REGISTRY_SERVICE, sr );
+
+    DefaultHostMappingService hm = new DefaultHostMappingService();
+    hm.init( config, options );
+    services.put( HOST_MAPPING_SERVICE, hm );
   }
   
   public void start() throws ServiceLifecycleException {

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-server/src/main/java/org/apache/hadoop/gateway/services/HssoGatewayServices.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/HssoGatewayServices.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/HssoGatewayServices.java
index e9f59f1..589be1b 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/HssoGatewayServices.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/HssoGatewayServices.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 import org.apache.hadoop.gateway.services.GatewayServices;
 import org.apache.hadoop.gateway.services.Service;
 import org.apache.hadoop.gateway.services.ServiceLifecycleException;
+import org.apache.hadoop.gateway.services.hostmap.impl.DefaultHostMappingService;
 import org.apache.hadoop.gateway.services.registry.impl.DefaultServiceRegistryService;
 import org.apache.hadoop.gateway.services.security.KeystoreServiceException;
 import org.apache.hadoop.gateway.services.security.SSLService;
@@ -90,6 +91,10 @@ public class HssoGatewayServices implements GatewayServices {
     ssl.setMasterService(ms);
     ssl.init(config, options);
     services.put(SSL_SERVICE, ssl);
+    
+    DefaultHostMappingService hm = new DefaultHostMappingService();
+    hm.init( config, options );
+    services.put( HOST_MAPPING_SERVICE, hm );
   }
   
   public void start() throws ServiceLifecycleException {

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-server/src/main/java/org/apache/hadoop/gateway/services/hostmap/impl/DefaultHostMappingService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/hostmap/impl/DefaultHostMappingService.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/hostmap/impl/DefaultHostMappingService.java
new file mode 100644
index 0000000..5d094dd
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/hostmap/impl/DefaultHostMappingService.java
@@ -0,0 +1,83 @@
+/**
+ * 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.services.hostmap.impl;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.hadoop.gateway.config.GatewayConfig;
+import org.apache.hadoop.gateway.services.ServiceLifecycleException;
+import org.apache.hadoop.gateway.services.hostmap.FileBasedHostMapper;
+import org.apache.hadoop.gateway.services.hostmap.HostMappingService;
+import org.apache.hadoop.gateway.services.hostmap.HostMapper;
+
+/**
+ * 
+ *
+ */
+public class DefaultHostMappingService implements HostMappingService {
+  ConcurrentHashMap<String, FileBasedHostMapper> map = new ConcurrentHashMap<String, FileBasedHostMapper>();
+  
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.Service#init(org.apache.hadoop.gateway.config.GatewayConfig, java.util.Map)
+   */
+  @Override
+  public void init(GatewayConfig config, Map<String, String> options)
+      throws ServiceLifecycleException {
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.Service#start()
+   */
+  @Override
+  public void start() throws ServiceLifecycleException {
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.Service#stop()
+   */
+  @Override
+  public void stop() throws ServiceLifecycleException {
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.hostmap.HostMappingService#getHostMapper(java.lang.String)
+   */
+  @Override
+  public HostMapper getHostMapper(String clusterName) {
+    return null;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.hostmap.HostMappingService#registerHostMapperForCluster(java.lang.String, org.apache.hadoop.gateway.services.hostmap.HostMapper)
+   */
+  @Override
+  public void registerHostMapperForCluster(String clusterName,
+      FileBasedHostMapper hostMapper) {
+    map.put(clusterName, hostMapper);
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.hostmap.HostMappingService#removeHostMapperForCluster(java.lang.String)
+   */
+  @Override
+  public void removeHostMapperForCluster(String clusterName) {
+    map.remove(clusterName);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java
index 187d559..94ef9a8 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java
@@ -32,6 +32,7 @@ public interface GatewayServices extends Service, ProviderDeploymentContributor
   public static final String ALIAS_SERVICE = "AliasService";
   public static final String TOKEN_SERVICE = "TokenService";
   public static final String SERVICE_REGISTRY_SERVICE = "ServiceRegistryService";
+  public static final String HOST_MAPPING_SERVICE = "HostMappingService";
 
   public abstract Collection<String> getServiceNames();
 

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/FileBasedHostMapper.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/FileBasedHostMapper.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/FileBasedHostMapper.java
new file mode 100644
index 0000000..5af0744
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/FileBasedHostMapper.java
@@ -0,0 +1,78 @@
+/**
+ * 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.services.hostmap;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+public class FileBasedHostMapper implements HostMapper {
+  private Map<String, String> inbound = new HashMap<String, String>();
+  private Map<String, String> outbound = new HashMap<String, String>();
+  
+  public FileBasedHostMapper(String clusterName, URL url) {
+    if( url != null ) {
+      InputStream stream;
+      try {
+        stream = url.openStream();
+        BufferedReader reader = new BufferedReader( new InputStreamReader( stream ) );
+        String line = reader.readLine();
+        while( line != null ) {
+          String[] lineSplit = line.split( "=" );
+          if( lineSplit.length >= 2 ) {
+            String[] externalSplit = lineSplit[ 0 ].split( "," );
+            String[] internalSplit = lineSplit[ 1 ].split( "," );
+            if( externalSplit.length >= 1 && internalSplit.length >= 1 ) {
+              for( String external : externalSplit ) {
+                inbound.put( external, internalSplit[ 0 ] );
+              }
+              for( String internal : internalSplit ) {
+                outbound.put( internal, externalSplit[ 0 ] );
+              }
+            }
+          }
+          line = reader.readLine();
+        }
+        reader.close();
+      } catch (IOException e) {
+        // TODO Auto-generated catch block
+        e.printStackTrace();
+      }
+    }
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.hostmap.HostMapper#resolveInboundHostName(java.lang.String)
+   */
+  @Override
+  public String resolveInboundHostName(String inboundHost) {
+    return inbound.get(inboundHost);
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.services.hostmap.HostMapper#resolveOutboundHostName(java.lang.String)
+   */
+  @Override
+  public String resolveOutboundHostName(String outboundHost) {
+    return outbound.get(outboundHost);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMapper.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMapper.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMapper.java
new file mode 100644
index 0000000..14ab0ac
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMapper.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.services.hostmap;
+
+/**
+ *
+ */
+public interface HostMapper {
+
+  public abstract String resolveInboundHostName(String inboundHost);
+
+  public abstract String resolveOutboundHostName(String outboundHost);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/e60093da/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMappingService.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMappingService.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMappingService.java
new file mode 100644
index 0000000..a950724
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/hostmap/HostMappingService.java
@@ -0,0 +1,35 @@
+/**
+ * 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.services.hostmap;
+
+import org.apache.hadoop.gateway.services.Service;
+
+public interface HostMappingService extends Service {
+  HostMapper getHostMapper(String clusterName);
+
+  /**
+   * @param clusterName
+   * @param hostMapper
+   */
+  void registerHostMapperForCluster(String clusterName, FileBasedHostMapper hostMapper);
+
+  /**
+   * @param clusterName
+   */
+  void removeHostMapperForCluster(String clusterName);
+}