Nav

HDFS Connector

Select

The Anypoint Connector for the Hadoop Distributed File System (HDFS) is used as a bi-directional gateway between Mule applications and HDFS.

Prerequisites

This document assumes that you are familiar with Mule.

To use the HDFS connector, you need:

  • Anypoint Studio version 7.0 or above - An instance of Anypoint Studio. If you do not use Anypoint Studio for development.

  • An instance of Hadoop Distributed File System up and running.

Compatibility

HDFS Hadoop connector is compatible with the following:

Application/Service Version

Mule Runtime

4.0 or newer

Apache Hadoop

2.8.1 or newer

Install the Connector

  1. In Anypoint Studio, click the Exchange icon in the Studio taskbar.

  2. Click Login in Anypoint Exchange.

  3. Search for the connector and click Install.

  4. Follow the prompts to install the connector.

When Studio has an update, a message displays in the lower right corner, which you can click to install the update.

Configure the Connector Global Element

To use the HDFS connector in your Mule application, you must configure a global HDFS element that can be used by the connector. The HDFS connector offers the following global configuration options, requiring the following credentials.

Simple Authentication Configuration

Field Description

NameNode URI

The URI of the file system to connect to.

This is passed to the HDFS client as the FileSystem#FS_DEFAULT_NAME_KEY configuration entry. It can be overridden by values in configurationResources and configurationEntries.

Username

User identity that Hadoop uses for permissions in HDFS.

When Simple Authentication is used, Hadoop requires the user to be set as a System Property called HADOOP_USER_NAME. If you fill this field then the connector sets it for you, however you can set it by yourself. If the variable is not set, Hadoop uses the current logged in OS user.

Configuration Resources

A list of configuration resource files to be loaded by the HDFS client. Here you can provide additional configuration files. For example, core-site.xml.

Configuration Entries

A map of configuration entries to be used by the HDFS client. Here you can provide additional configuration entries as key/value pairs.

hdfs-config

Kerberos Authentication Configuration

Field Description

NameNode URI

The URI of the file system to connect to.

This is passed to HDFS client as the FileSystem#FS_DEFAULT_NAME_KEY configuration entry. It can be overridden by values in configurationResources and configurationEntries.

Username

Kerberos principal.

This is passed to HDFS client as the "hadoop.job.ugi" configuration entry. It can be overridden by values in configurationResources and configurationEntries. If not provided, it uses the currently logged in user.

KeytabPath

Path to the keytab file associated with username.

KeytabPath is used in order to obtain TGT from "Authorization server". If not provided it looks for a TGT associated to username within your local kerberos cache.

Configuration Resources

A list of configuration resource files to be loaded by the HDFS client. Here you can provide additional configuration files. For example, core-site.xml.

Configuration Entries

A map of configuration entries to be used by the HDFS client. Here you can provide additional configuration entries as key/value pairs.

hdfs-config-with-kerberos

Using the Connector

You can use this connector as an inbound endpoint for polling content of a file at a configurable rate (interval) or as an outbound connector for manipulating data into the HDFS server.

Connector Namespace and Schema

When designing your application in Studio, the act of dragging the connector from the palette onto the Anypoint Studio canvas should automatically populate the XML code with the connector namespace and schema location.

Namespace: http://www.mulesoft.org/schema/mule/hdfs
Schema Location: http://www.mulesoft.org/schema/mule/connector/current/mule-hdfs.xsd

If you are manually coding the Mule application in Studio’s XML editor or other text editor, define the namespace and schema location in the header of your Configuration XML, inside the <mule> tag.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
 <mule xmlns:http="xmlns:hdfs="http://www.mulesoft.org/schema/mule/hdfs"
              xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
              xmlns="http://www.mulesoft.org/schema/mule/core"
       xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
              xmlns:spring="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="

      http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
      http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
      http://www.mulesoft.org/schema/mule/hdfs http://www.mulesoft.org/schema/mule/hdfs/current/mule-hdfs.xsd">
</mule>

Example Use Case

The following example shows how to create a text file into HDFS using the connector:

  1. In Anypoint Studio, click File > New > Mule Project, name the project, and click OK.

  2. In the search field, type "http" and drag the HTTP connector to the canvas, click the green plus sign to the right of Connector Configuration, and in the next screen, click OK to accept the default settings. Name the endpoint /createFile.

  3. In the Search bar type hdfs and drag the HDFS connector onto the canvas.

  4. Choose Write to path as an operation. Set Path to /test.txt (this is the path of the file that is going to be created into HDFS) and leave other options with default values.

  5. The flow should look like this:

  6. Run the application. From your favorite HTTP client, make a POST request with "Content-type:plain/text" to locahost:8081/createFile with content that you want to write as payload. (for example, curl -X POST -H "Content-Type:plain/text" -d "payload to write to file" localhost:8090/createFile)

  7. Check that /test.txt has been created and has your content by using Hadoop explorer.

A demo with the above mentioned use case was provided.