camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > HDFS
Date Mon, 09 Jul 2012 11:52:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/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/~davsclaus">Claus
Ibsen</a>
    </h4>
        <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" >| {{pattern}} | {{*}} | The pattern
used for scanning the directory  | <br>| {{chunkSize}} | {{4096}} | When reading a normal
file, this is split into chunks producing a message per chunk. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{connectOnStartup}} | {{true}}
| *Camel <span class="diff-changed-words">2.<span class="diff-added-chars"style="background-color:
#dfd;">9.3/2.</span>10.1:*</span> Whether to connect to the HDFS file system
on starting the producer/consumer. If {{false}} 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 {{false}} allows your application to startup,
and not block for up till 15 minutes. | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <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="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-hadoop<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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="code-java">
hdfs:<span class="code-comment">//hostname[:port][/path][?options]</span>
</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
seg0, seg1, seg2, etc.</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>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 enough 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 actual file name will become
a directory name and a &lt;file name&gt;/seg0 will be initially created.</li>
	<li>Every time a splitting condition is met a new file is created with name &lt;original
file name&gt;/segN where N is 1, 2, 3, etc.<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>


<p>for example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hdfs:<span class="code-comment">//localhost/tmp/simple-file?splitStrategy=IDLE:1000,BYTES:5</span>
</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 find the following files seg0, seg1, seg2, etc</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;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change 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=13&originalVersion=12">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/HDFS?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message