草庐IT

hadoop - 在附件的 oozie 电子邮件操作中根据日期传递变量

coder 2024-01-09 原文

我正在使用 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>

现在在 <attachment>/user/XXXX/logs/2017-05-03/exec.log</attachment> 附近的工作流程中日期总是在变。

我如何传递变量,以便在调用工作流时发送特定日期的附件。

edited question.

我的 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然后电子邮件操作失败。

我想要的是无论文件是否存在我都希望电子邮件操作成功

最佳答案

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

方法 #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

条件 Action 就像:

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. 带有附件标签“<attachment>${wf:actionData('shell-05e6')['filePath']}</attachment>”和
  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

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

关于hadoop - 在附件的 oozie 电子邮件操作中根据日期传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43770848/

有关hadoop - 在附件的 oozie 电子邮件操作中根据日期传递变量的更多相关文章

  1. ruby-on-rails - 如何使用 instance_variable_set 正确设置实例变量? - 2

    我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击

  2. ruby - 通过 ruby​​ 进程共享变量 - 2

    我正在编写一个gem,我必须在其中fork两个启动两个webrick服务器的进程。我想通过基类的类方法启动这个服务器,因为应该只有这两个服务器在运行,而不是多个。在运行时,我想调用这两个服务器上的一些方法来更改变量。我的问题是,我无法通过基类的类方法访问fork的实例变量。此外,我不能在我的基类中使用线程,因为在幕后我正在使用另一个不是线程安全的库。所以我必须将每个服务器派生到它自己的进程。我用类变量试过了,比如@@server。但是当我试图通过基类访问这个变量时,它是nil。我读到在Ruby中不可能在分支之间共享类变量,对吗?那么,还有其他解决办法吗?我考虑过使用单例,但我不确定这是

  3. ruby-on-rails - date_field_tag,如何设置默认日期? [ rails 上的 ruby ] - 2

    我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问

  4. ruby-on-rails - 如何在我的 Rails 应用程序 View 中打印 ruby​​ 变量的内容? - 2

    我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby​​中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R

  5. ruby - 如何根据特征实现 FactoryGirl 的条件行为 - 2

    我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden

  6. ruby-on-rails - Ruby 检查日期时间是否为 iso8601 并保存 - 2

    我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby​​是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查

  7. ruby - 检查日期是否在过去 7 天内 - 2

    我的日期格式如下:"%d-%m-%Y"(例如,今天的日期为07-09-2015),我想看看是不是在过去的七天内。谁能推荐一种方法? 最佳答案 你可以这样做:require"date"Date.today-7 关于ruby-检查日期是否在过去7天内,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/32438063/

  8. ruby-on-rails - 将 Ruby 中的日期/时间格式化为 YYYY-MM-DD HH :MM:SS - 2

    这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build

  9. ruby - 查找字符串中的内容类型(数字、日期、时间、字符串等) - 2

    我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s

  10. ruby - rails 3 redirect_to 将参数传递给命名路由 - 2

    我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use

随机推荐