camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben O'Day (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > HDFS
Date Thu, 07 Nov 2013 15:00:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/HDFS">HDFS</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~boday">Ben
O&#39;Day</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        added split strategy note per CAMEL-6864<br />
    </div>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* IDLE a new file is created, and
the old is closed when no writing happened in the last &lt;value&gt; milliseconds
<br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{note}
<br>note that this strategy currently requires either setting an IDLE value or setting
the HdfsConstants.HDFS_CLOSE header to false to use the BYTES/MESSAGES configuration...otherwise,
the file will be closed with each message <br>{note} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >for example: <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="HDFS-HDFSComponent"></a>HDFS Component</h2>
<p><b>Available as of Camel 2.8</b></p>

<p>The <b>hdfs</b> component enables you to read and write messages from/to
an HDFS file system. HDFS is the distributed file system at the heart of <a href="http://hadoop.apache.org"
class="external-link" rel="nofollow">Hadoop</a>.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-hdfs&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h3><a name="HDFS-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
hdfs://hostname[:port][/path][?options]
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt><br/>
The path is treated in the following way:</p>
<ol>
	<li>as a consumer, if it's a file, it just reads the file, otherwise if it represents
a directory it scans all the file under the path satisfying the configured pattern. All the
files under that directory must be of the same type.</li>
	<li>as a producer, if at least one split strategy is defined, the path is considered
a directory and under that directory the producer creates a different file per split named
using the configured <a href="/confluence/display/CAMEL/UuidGenerator" title="UuidGenerator">UuidGenerator</a>.</li>
</ol>


<h3><a name="HDFS-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>overwrite</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> The file can be overwritten </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>append</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Append to existing file. Notice that not all HDFS file systems
support the append option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bufferSize</tt> </td>
<td class='confluenceTd'> <tt>4096</tt> </td>
<td class='confluenceTd'> The buffer size used by HDFS  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replication</tt> </td>
<td class='confluenceTd'> <tt>3</tt> </td>
<td class='confluenceTd'> The HDFS replication factor  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>blockSize</tt> </td>
<td class='confluenceTd'> <tt>67108864</tt> </td>
<td class='confluenceTd'> The size of the HDFS blocks  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileType</tt> </td>
<td class='confluenceTd'> <tt>NORMAL_FILE</tt> </td>
<td class='confluenceTd'> It can be SEQUENCE_FILE, MAP_FILE, ARRAY_FILE, or BLOOMMAP_FILE,
see Hadoop </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fileSystemType</tt> </td>
<td class='confluenceTd'> <tt>HDFS</tt> </td>
<td class='confluenceTd'> It can be LOCAL for local filesystem  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyType</tt> </td>
<td class='confluenceTd'> <tt>NULL</tt> </td>
<td class='confluenceTd'> The type for the key in case of sequence or map files. See
below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>valueType</tt> </td>
<td class='confluenceTd'> <tt>TEXT</tt> </td>
<td class='confluenceTd'> The type for the key in case of sequence or map files. See
below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitStrategy</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> A string describing the strategy on how to split the file
based on different criteria. See below.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>openedSuffix</tt> </td>
<td class='confluenceTd'> <tt>opened</tt> </td>
<td class='confluenceTd'> When a file is opened for reading/writing the file is renamed
with this suffix to avoid to read it during the writing phase. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>readSuffix</tt> </td>
<td class='confluenceTd'> <tt>read</tt> </td>
<td class='confluenceTd'> Once the file has been read is renamed with this suffix to
avoid to read it again.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>initialDelay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> For the consumer, how much to wait (milliseconds) before to
start scanning the directory.  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> The interval (milliseconds) between the directory scans. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pattern</tt> </td>
<td class='confluenceTd'> <tt>*</tt> </td>
<td class='confluenceTd'> The pattern used for scanning the directory  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>chunkSize</tt> </td>
<td class='confluenceTd'> <tt>4096</tt> </td>
<td class='confluenceTd'> When reading a normal file, this is split into chunks producing
a message per chunk. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectOnStartup</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.3/2.10.1:</b> Whether to connect
to the HDFS file system on starting the producer/consumer. If <tt>false</tt> then
the connection is created on-demand. Notice that HDFS may take up till 15 minutes to establish
a connection, as it has hardcoded 45 x 20 sec redelivery. By setting this option to <tt>false</tt>
allows your application to startup, and not block for up till 15 minutes. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="HDFS-KeyTypeandValueType"></a>KeyType and ValueType</h4>
<ul>
	<li>NULL it means that the key or the value is absent</li>
	<li>BYTE for writing a byte, the java Byte class is mapped into a BYTE</li>
	<li>BYTES for writing a sequence of bytes. It maps the java ByteBuffer class</li>
	<li>INT for writing java integer</li>
	<li>FLOAT for writing java float</li>
	<li>LONG for writing java long</li>
	<li>DOUBLE for writing java double</li>
	<li>TEXT for writing java strings</li>
</ul>


<p>BYTES is also used with everything else, for example, in Camel a file is sent around
as an InputStream, int this case is written in a sequence file or a map file as a sequence
of bytes.</p>

<h3><a name="HDFS-SplittingStrategy"></a>Splitting Strategy</h3>
<p>In the current version of Hadoop opening a file in append mode is disabled since
it's not very reliable. So, for the moment, it's only possible to create new files. The Camel
HDFS endpoint tries to solve this problem in this way:</p>
<ul>
	<li>If the split strategy option has been defined, the hdfs path will be used as a
directory and files will be created using the configured <a href="/confluence/display/CAMEL/UuidGenerator"
title="UuidGenerator">UuidGenerator</a></li>
	<li>Every time a splitting condition is met, a new file is created.<br/>
The splitStrategy option is defined as a string with the following syntax:<br/>
splitStrategy=&lt;ST&gt;:&lt;value&gt;,&lt;ST&gt;:&lt;value&gt;,*</li>
</ul>


<p>where &lt;ST&gt; can be:</p>
<ul>
	<li>BYTES a new file is created, and the old is closed when the number of written bytes
is more than &lt;value&gt;</li>
	<li>MESSAGES a new file is created, and the old is closed when the number of written
messages is more than &lt;value&gt;</li>
	<li>IDLE a new file is created, and the old is closed when no writing happened in the
last &lt;value&gt; milliseconds</li>
</ul>


<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>note that this strategy currently
requires either setting an IDLE value or setting the HdfsConstants.HDFS_CLOSE header to false
to use the BYTES/MESSAGES configuration...otherwise, the file will be closed with each message</td></tr></table></div>

<p>for example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
hdfs://localhost/tmp/simple-file?splitStrategy=IDLE:1000,BYTES:5
</pre>
</div></div>
<p>it means: a new file is created either when it has been idle for more than 1 second
or if more than 5 bytes have been written. So, running <tt>hadoop fs -ls /tmp/simple-file</tt>
you'll see that multiple files have been created.</p>

<h3><a name="HDFS-MessageHeaders"></a>Message Headers</h3>

<p>The following headers are supported by this component:</p>

<h4><a name="HDFS-Produceronly"></a>Producer only</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelFileName</tt> </td>
<td class='confluenceTd'> <b>Camel 2.13:</b> Specifies the name of the file
to write (relative to the endpoint path). The name can be a <tt>String</tt> or
an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>
object. Only relevant when not using a split strategy. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="HDFS-Controllingtoclosefilestream"></a>Controlling to close
file stream</h3>
<p><b>Available as of Camel 2.10.4</b></p>

<p>When using the <a href="/confluence/display/CAMEL/HDFS" title="HDFS">HDFS</a>
producer <b>without</b> a split strategy, then the file output stream is by default
closed after the write. However you may want to keep the stream open, and only explicitly
close the stream later. For that you can use the header <tt>HdfsConstants.HDFS_CLOSE</tt>
(value = <tt>"CamelHdfsClose"</tt>) to control this. Setting this value to a boolean
allows you to explicit control whether the stream should be closed or not.</p>

<p>Notice this does not apply if you use a split strategy, as there are various strategies
that can control when the stream is closed.</p>


<h3><a name="HDFS-UsingthiscomponentinOSGi"></a>Using this component in
OSGi</h3>
<p>This component is fully functional in an OSGi environment, however, it requires some
actions from the user. Hadoop uses the thread context class loader in order to load resources.
Usually, the thread context classloader will be the bundle class loader of the bundle that
contains the routes. So, the default configuration files need to be visible from the bundle
class loader. A typical way to deal with it is to keep a copy of core-default.xml in your
bundle root. That file can be found in the hadoop-common.jar.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/HDFS">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=10388004&revisedVersion=22&originalVersion=21">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message