【问题标题】:Pass table names from a file to oozie workflow将表名从文件传递到 oozie 工作流
【发布时间】:2017-04-25 18:33:17
【问题描述】:

我在oozie 中有一个工作流程。在此工作流程中,我想将表名作为参数传递。表名存在于文件tables.txt 我想将tables.txt 中的表名传递给工作流。

<workflow-app name="Shell_test" xmlns="uri:oozie:workflow:0.5">
<start to="shell-8f63"/>
<kill name="Kill">
    <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<action name="test_shell">
    <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>
        <file>/user/oozie/lib/test_shell.sh#shell.sh</file>
        <file>/user/oozie/input/tables.txt#tables.txt</file>
    </shell>
    <ok to="End"/>
        <error to="email-error"/>
    </action>
    <action name="email-error">
    <email xmlns="uri:oozie:email-action:0.2">
        <to>xxxxxxxxxx.com</to>
        <subject>Status of workflow ${table}</subject>
        <body>The workflow ${table} ${wf:id()} had issues and was killed. The error message is: ${wf:errorMessage(wf:lastErrorNode())}</body>
        <content_type>text/plain</content_type>
    </email>
    <ok to="end"/>
    <error to="end"/>
    </action>
    <end name="End"/>
</workflow-app>

我能够在工作流程中使用以下内容来做到这一点。

<argument>${input_file}</argument>
<env-var>HADOOP_USER_NAME=${wf:user()}</env-var>
<file>/user/oozie/lib/test_shell.sh#shell.sh</file>
<file>/user/oozie/input/${input_file}#${input_file}</file>

现在我有一个问题。

说如果input_file 中的一个表的工作流失败,那么我不会收到任何电子邮件。仅当 input_file 中最后一个表的工作流失败时,我才会收到电子邮件。

为什么会发生这种情况?每次工作流失败时我如何才能收到一封电子邮件?

还是我做错了整个过程。

谁能解释并纠正我在哪里做错了。

我的test_shell.sh

while read line ;do 
     spark-submit --name "SparkJob" --master "yarn-client" test.py $line 
done < tables.txt 

【问题讨论】:

    标签: hadoop hdfs oozie oozie-coordinator


    【解决方案1】:

    Shell 操作不会像 shh 操作那样运行,因为 shell 操作工作流将在其中一个数据节点上运行,它会将脚本错误视为警告,除非您在脚本中执行 exit 1 .另一种在失败时接收电子邮件的方法是在脚本中使用电子邮件实用程序,在执行 exit 1 echo 'script X returned an error due to some reason; Please check the workflow for validation' | mailx -r oozie -s 'SUBJECTTOEMAIL' email@someemail.com 以使电子邮件实用程序从数据节点工作之前类似这样,请确保您的数据节点具有已安装电子邮件实用程序。如果未安装,您可以在电子邮件部分执行 ssh 到您的边缘节点,看起来像这样 ssh -o StrictHostKeyChecking=no ${edgeUser}@${edgeHost} "echo 'script X returned an error due to some reason; Please check the workflow for validation' | mailx -r oozie -s 'SUBJECTTOEMAIL' email@someemail.com"

    我可以建议您对工作流程进行一些更改,这可能会在反映错误和利用工作流程中的电子邮件操作方面为您提供更好的结果

    不要从 shell 操作本身调用配置文件,相反,您可以执行以下操作

    <workflow-app name="Shell_test" xmlns="uri:oozie:workflow:0.5">
    <start to="shell-8f63"/>
    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <action name="test_shell">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>shell.sh</exec>
            <env-var>HADOOP_USER_NAME=${wf:user()}</env-var>
            <file>/user/oozie/lib/test_shell.sh#shell.sh</file>
            <file>/user/oozie/input/tables.txt</file>
        </shell>
      

    如果您注意到我对您的工作流程所做的更改,我只是将 tables.txt 作为文件调用,而不是通过删除 #tables.txt 将其实际作为执行

    当您这样做时,shell 操作实际上会复制该文件并存储在它正在运行的容器中,因此要利用 table.txt 配置文件,在脚本中您将像这样调用. ./tables.txt,因为容器已复制,因此您可以调用主目录中的 tables.txt。

    希望这会对您有所帮助...!!!如果您对我建议的解决方案有任何疑问,请发表评论。

    【讨论】:

    • @Intrested_user 你能详细说明一下吗?哪个电子邮件操作?您是否尝试从脚本中使用或者您指的是 shell 电子邮件操作?如果您指的是 oozie 电子邮件操作,您是尝试使用我的 workflow.xml 建议还是使用您问题中的建议?
    • @Intrested_user 假设您指的是 oozie 电子邮件操作:[table] 无法解析,因为电子邮件操作与执行脚本的 shell 操作不同。您在脚本操作中传递变量,因为电子邮件操作是不同的操作,它无法识别 ${table} 参数。
    • 您可以通过在脚本中执行 tables.txt 的回显来做到这一点,并且在 shell 操作结束时,您将使用此 捕获输出,因此当输出为捕获您应该能够将其用作电子邮件操作中的参数。
    • @Intrested_user 抱歉,我没有代码导师帐户。你能分步告诉我你的脚本会做什么吗?我可以帮助你
    • 好的,在这种情况下,我的建议是依赖脚本而不是 oozie 电子邮件操作。这样,您甚至可以使用 exit 1 退出脚本。建议这样做的主要原因是 shell 操作不会总是像 ssh 操作那样准确地向您发送电子邮件,因为它贯穿数据节点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多