Configuring Proxy with Apache Knox
Also available as:
PDF
loading table of contents...

Add a New Service to the Knox Gateway

The Knox Gateway supports a declarative way for you to “plug in” a new service into the gateway simply and easily by using a few files.

Overview

Services and service additions in the Knox Gateway are defined as extensions to existing Knox Gateway functionality that enable you to extend the gateway’s capabilities. You use these services to convert information contained in the topology file to runtime descriptors.

The Knox Gateway supports a declarative way for you to “plug in” a new service into the gateway simply and easily by using the following two files:

  • service.xml- file that contains the routes (paths) that the service will provide and the rewrite rules to bind these paths.
  • rewrite.xml – file that contains the rewrite rules for the service.

Directory Structure

The Knox Gateway consists of a directory structure that you should become familiar with before attempting to add a new service to the gateway.

If you navigate to the data directory in your Knox home directory ({GATEWAY_HOME}/data}, you will see the following directory structure:
Services
    Service name
        Version
            service.xml
            rewrite.xml
For example, if you were to navigate to the WebHDFS Service directory, you would see the following directory structure:
Services
    WebHDFS
        2.4.0
            service.xml
            rewrite.xml
  1. Navigate to the services directory in your Knox gateway HOME directory ({GATEWAY_HOME}/data/services).
  2. Add the service.xml and rewrite.xml files to the directory.
    Note
    Note

    If you want to add the service to the Knox build, then add the service.xml and rewrite files to the gateway-services-definitions module.

  3. Restart the Knox Gateway server:
    cd $gateway/bin/gateway.sh stop
    cd $gateway /bin/gateway.sh start
<GATEWAY_HOME>/data/services/webhdfs/0.0.1/service.xml

<service role="WEBHDFS" name="webhdfs" version="0.0.1">
  <routes>
    <route path="/webhdfs/**"/>
  </routes>
</service>
<GATEWAY_HOME>/data/services/webhdfs/0.0.1/rewrite.xml

<rules>
  <rule dir="IN" name="WEBHDFS/webhdfs/inbound" pattern="*://*:*/**/webhdfs/{path=**}?{**}">
    <rewrite template="{$serviceUrl[WEBHDFS]}/{path=**}?{**}"/>
  </rule>
</rules>