将文件中的 table 个名称传递给 oozie 工作流

Pass table names from a file to oozie workflow

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

<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 中的 table 之一的工作流程失败,那么我将收不到任何电子邮件。只有在 input_file.

中的最后一个 table 工作流程失败时,我才会收到电子邮件

为什么会发生这种情况以及每次工作流失败时如何收到电子邮件?

还是我做错了整个过程。

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

我的test_shell.sh

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

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[=14 将其实际执行=]

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

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