【问题标题】:Checking if a file exists in HDFS location with size greater than zero, using Oozie使用 Oozie 检查 HDFS 位置中是否存在大小大于零的文件
【发布时间】:2021-01-02 09:59:51
【问题描述】:

我有一个 Oozie 工作流,其中包含一个 Pig 操作,生成一个零件文件作为输出

/user/wf_user/app_dir/output/part-v003-o000-r-00100

在 Pig 操作之后,有一个 fs-action 正在生成一个完成标志文件并将 part-v003-o000-r-00100 移动到 alert_message(用于重命名),然后更改文件路径 /user/wf_user/app_dir/output/alert_message 的访问权限以使可从后续工作流操作访问的文件。

然后,有一个决策控制节点来检查文件/user/wf_user/app_dir/output/alert_message 是否存在并且大小是否大于零。仅当大小不为零时,才会通过电子邮件发送警报消息。

但是即使文件存在并且大小不为零,决策条件总是返回 false,因此警报消息永远不会通过电子邮件发送给通知用户。

<switch xmlns="uri:oozie:workflow:0.4">
  <case to="message_pref_alert">false</case>
  <default to="success_email" />
</switch>

下面是相关工作流动作的sn-p

    <action name='generate_preftable_pref_count_report' cred="hcatauth,athensauth">
        <pig>
        <prepare>
        <delete path="${flag_dir}"></delete>
        </prepare>
            <script>generate_diffcount_w_perc_mktg_prefs.pig</script>
            <param>today=${today}</param>
            <param>prev_date=${prev_date}</param>
            <param>lake_tahoe_dump=${lake_tahoe_dump}</param>
            <param>current_pref_snapshot=${current_pref_snapshot}</param>
            <param>preference_user=${preference_user}</param>
            <param>pref_count_report=${pref_count_report}</param>
            <param>flag_dir=${flag_dir}</param>
            <file>${common_lib}/elephant-bird-pig.jar#elephant-bird-pig.jar</file>
            <file>${common_lib}/elephant-bird-core.jar#elephant-bird-core.jar</file>
            <file>${common_lib}/elephant-bird-hadoop-compat.jar#elephant-bird-hadoop-compat.jar</file>
        </pig>
        <ok to="fs-create-report-flag-and-alert" />
        <error to="failure_email" />
    </action>

    <action name="fs-create-report-flag-and-alert">
    <fs>
       <chmod path='${flag_dir}' permissions='-rwxrwxrwx' dir-files='true'/>
       <delete path='${flag_dir}/report_generated_${prev_date}'/>
       <touchz path='${flag_dir}/report_generated_${today}'/>
       <move source='${flag_dir}/part*' target='${alert_message_file}' />
       <chmod path='${alert_message_file}' permissions='-rwxrwxrwx' dir-files='true'/> 
    </fs>
    <ok to="if_alert_prefs_present"/>
    <error to="failure_email"/>
    </action>

    <decision name="if_alert_prefs_present">
        <switch>
    <case to="message_pref_alert">${(fs:exists('${alert_message_file}')) and (fs:fileSize('${alert_message_file}') gt 0 )}</case>
    <default to="success_email"/>
    </switch>
    </decision>

    <action name="message_pref_alert">
                <email xmlns="uri:oozie:email-action:0.1">
                        <to>${notify_to}</to>
                        <subject>PrefTable-PrefCount-Update-${today} : Pref Count Alert</subject>
                        <body>In today's pref counts, the pref count difference >= 5% for some sub/unsub preferences. Please check the below file for sub/unsub details.
                  ${alert_message_file} 
                  For further details on count and percentage difference, please check the hive table ${pref_count_report} .
            </body>
                </email>
                <ok to="success_email"/>
                <error to="failure_email"/>
     </action>

注意:我没有将${alert_message_file} 设置为工作流配置属性,而是仅在协调器属性文件中设置,如下所示。

nameNode=hdfs://clusterName-nn1.clusterDomain.com:8020
jobTracker=clusterName-jt1.clusterDomain.com:8032
MAIN_DIR=/user/wf_user
APP_DIR=${nameNode}${MAIN_DIR}/app_dir
flag_dir=${APP_DIR}/output
alert_message_file=${flag_dir}/alert_message

查看了关于同一主题的关于 SO 的其他类似讨论: How to check whether the file exist in HDFS location, using oozie?

【问题讨论】:

    标签: shell hdfs apache-pig oozie


    【解决方案1】:

    ${alert_message_file} 作为工作流配置属性传递以解决错误。实际上变量alert_message_file(在属性中定义)是不可访问的,除非它通过工作流通过配置属性传递,否则会出现“变量无法解析”的错误。

    在workflow.xml中

    <configuration>
        <property>
            ...
        </property>  
        <property>
            <name>alert_message_file</name>
            <value>${alert_message_file}</value>
        </property>
    </configuration>
    

    然后改变决策节点如下

    <decision name="if_alert_prefs_present">
        <switch>
    <case to="message_pref_alert">${(fs:exists(wf:conf('alert_message_file'))) and (fs:fileSize(wf:conf('alert_message_file')) gt 0 )}</case>
    <default to="success_email"/>
    </switch>
    </decision>
    

    【讨论】:

      猜你喜欢
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多