使用oozie在hdfs中创建目录

时间:2017-04-24 17:02:59

标签: hadoop hdfs oozie oozie-coordinator

在oozie工作流程中,我们如何在HDFS中创建目录并将文件从Linux复制到HDFS

我想在工作流程中执行以下操作

hdfs dfs -mkdir -p /user/$USER/logging/`date "+%Y-%m-%d"`/logs


hdfs dfs -put /home/$USER/logs/"${table}" /user/$USER/logging/`date "+%Y-%m-%d"`/logs/

我怎样才能做到这一点?

我尝试了以下但没有成功

<action name="Copy_to_HDFS">
    <fs>
        <mkdir path='/user/$USER/logging/`date "+%Y-%m-%d"`/logs'/>
        <move source='/home/$USER/logs${table}' target='/user/$USER/logging/`date "+%Y-%m-%d"`/logs/'/>
    </fs>
    <ok to="end"/>
    <error to="end"/>
</action>

我们如何创建一个具有该特定日期名称的文件夹?

完整的工作流程:

    <workflow-app name="Shell_hive" xmlns="uri:oozie:workflow:0.5">
    <start to="shell-b8e7"/>
    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <action name="shell-b8e7">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>shell.sh</exec>
              <argument>${table}</argument>
           <env-var>HADOOP_USER_NAME=${wf:user()}</env-var>
           <env-var>HADOOP_CONF_DIR=/etc/hadoop/conf</env-var>
           <file>/user/$USER/oozie/scripts/lib/shell.sh#shell.sh</file>   
        </shell>
        <ok to="End"/>
        <error to="Kill"/>
    </action>
    <action name="Copy_to_HDFS">
        <fs>
            <mkdir path="/user/$USER/logging/2017-04-24/logs"/>
            <move source="/tmp/logging/${table}" target="/user/$USER/logging/$(date +%Y-%m-%d)/logs/"/>
        </fs>
        <ok to="end"/>
        <error to="end"/>
    </action>
        <end name="End"/>
    </workflow-app>

2 个答案:

答案 0 :(得分:0)

The problem is with the quotes, single quotes(') block the variable expansion.

<action name="Copy_to_HDFS">
    <fs>
        <mkdir path="/user/$USER/logging/$(date +%Y-%m-%d)/logs"/>
        <move source="/home/$USER/logs${table}" target="/user/$USER/logging/$(date +%Y-%m-%d)/logs/"/>
    </fs>
    <ok to="end"/>
    <error to="end"/>
</action>

UPDATE: The Copy_to_HDFS action is never invoked. The action shell-b8e7 on success is sent to End action. Modify the workflow accordingly to invoke the Copy_to_HDFS action. For example,

</shell>
<ok to="Copy_to_HDFS"/>

答案 1 :(得分:0)

The prepare tag might help :

<prepare>
                <delete path="[PATH]"/>
                ...
                <mkdir path="[PATH]"/>
                ...
</prepare>