【问题标题】:Passing variable based on date in oozie email action for attachments在附件的 oozie 电子邮件操作中基于日期传递变量
【发布时间】:2017-05-03 22:12:27
【问题描述】:

我正在使用oozie 发送带有附件的电子邮件。我正在做如下。

<workflow-app name="Email" xmlns="uri:oozie:workflow:0.5">
    <start to="email-0fdf"/>
    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <action name="email-0fdf">
        <email xmlns="uri:oozie:email-action:0.2">
            <to>xxxxxxxxxxxxxxx@xxxxx</to>
            <subject>job success</subject>
            <content_type>text/plain</content_type>
            <attachment>/user/XXXX/logs/2017-05-03/exec.log</attachment>
        </email>
        <ok to="End"/>
        <error to="Kill"/>
    </action>
    <end name="End"/>
</workflow-app>

现在在&lt;attachment&gt;/user/XXXX/logs/2017-05-03/exec.log&lt;/attachment&gt; 附近的工作流程中,日期总是会发生变化。

我如何传递当调用工作流程时我想发送特定日期的附件的变量。

已编辑问题。

我的 shell 脚本:

#!/bin/bash

TIMESTAMP=`date "+%Y-%m-%d"`
path=/user/$USER/logging/${TIMESTAMP}/status/${TIMESTAMP}.fail_log

path1=/user/$USER/logging/`date -d "-1 days" '+%Y-%m-%d'`/status/`date -d "-1 days" '+%Y-%m-%d'`.fail_log

echo filePath=$path
echo filePath1=$path1

我的新工作流程:

<workflow-app name="My_Workflow" xmlns="uri:oozie:workflow:0.5">
<start to="shell-05e6"/>
<kill name="Kill">
    <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<action name="shell-05e6">
    <shell xmlns="uri:oozie:shell-action:0.1">
        <job-tracker>${jobTracker}</job-tracker>
        <name-node>${nameNode}</name-node>
        <exec>shell.sh</exec>
        <file>/user/xxxxx/oozie/email/lib/shell.sh#shell.sh</file>
          <capture-output/>
    </shell>
    <ok to="email-66c2"/>
    <error to="Kill"/>
</action>
<action name="email-66c2">
    <email xmlns="uri:oozie:email-action:0.2">
        <to>myemail@mycompany.com</to>
        <subject>job status</subject>
        <body>job status ${wf:actionData('shell-05e6')['filePath']}</body>
        <content_type>text/plain</content_type> 
       <attachment>${wf:actionData('shell-05e6')['filePath']},${wf:actionData('shell-05e6')['filePath1']}</attachment>
    </email>
    <ok to="End"/>
    <error to="Kill"/>
</action>
<end name="End"/>

现在,如果其中一个位置没有文件,请说 filepathfilepath1,则电子邮件操作失败。

我想要的是不管文件是否存在我希望电子邮件操作成功

【问题讨论】:

  • 告诉我你最喜欢哪种方法。

标签: hadoop hdfs oozie oozie-coordinator


【解决方案1】:

可能有两种方法可以解决新的需求。

方法#1 在 shell Action 和 email action 之间添加条件 Action

Shell Action 就像:

path=/user/$USER/logging/${TIMESTAMP}/status/${TIMESTAMP}.fail_log
path1=/user/$USER/logging/`date -d "-1 days" '+%Y-%m-%d'`/status/`date -d "-1 days" '+%Y-%m-%d'`.fail_log

if [ -e "$path" ] && [ -e "$path1"]
then
    echo filePath=$path,$path1
elif [ -e "$path" ]
then
    echo filePath=$path
elif [ -e "$path1" ]
then
    echo filePath=$path1
else
    echo filePath=""
fi

条件动作就像:

if filePath = "" then
  call email_0 action # which has NO attachment tag.
else
  call email_2 action # which has attachment tag with two files.
end if

在条件操作下方,您将有两个电子邮件操作。

  1. 带有附件标签“&lt;attachment&gt;${wf:actionData('shell-05e6')['filePath']}&lt;/attachment&gt;”和
  2. 不带附件标签

方法#2没有条件操作。

Shell Action 就像:

path=/user/$USER/logging/${TIMESTAMP}/status/${TIMESTAMP}.fail_log
path1=/user/$USER/logging/`date -d "-1 days" '+%Y-%m-%d'`/status/`date -d "-1 days" '+%Y-%m-%d'`.fail_log

if [ -e "$path" ] && [ -e "$path1"]
then
    echo filePath=$path,$path1
elif [ -e "$path" ]
then
    echo filePath=$path
elif [ -e "$path1" ]
then
    echo filePath=$path1
else
    echo filePath="/user/$USER/logging/No_Status_log.fail_log" # this is default file with no data. You have to create it only one time.
fi

在这种方法中,即使没有可用的数据,也会始终附加一个文件。

【讨论】:

  • 只想知道你会采用哪种方法。
  • 我更喜欢第二种方法
【解决方案2】:

编写 shell 动作。

    #!/bin/sh
    #Need to write a code to find out file path. and assign to "fP".
    echo "filePath=$fP"   #Here "fP" is dynamically assign file path. 

您可以捕获 shell 脚本的输出并将其传递给电子邮件操作。在 shell script 中,回显 'filePath=$fP' 之类的属性,并在 shell 操作中添加 capture-output 元素。这将让您从 shell 脚本中捕获 filePath。在电子邮件操作中,您可以将捕获的变量作为参数传递为 ${wf:actionData('shellAction')['filePath']} 其中 shellAction 是外壳操作名称。

电子邮件操作:

<attachment>${wf:actionData('shellAction')['filePath']}</attachment>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    相关资源
    最近更新 更多