Oozie Actions--Oozie Email action configuration


Oozie Email Action Configuration
  • Shell Action can be used to send emails for process tasks in oozie, Email Action must be configured with to recipient, cc recipient (optional), email subject, email content, multiple recipients can be used, split recipients address.
  • Email Action is executed synchronously, and the process task must wait for the current node's email to be sent before executing subsequent node tasks.
  • All node values ​​of Email Action can use EL expressions

Email Action format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
< workflow-app  name = "[WF-DEF-NAME]"  xmlns = "uri:oozie:workflow:0.1" >
     ...
     < action  name = "[NODE-NAME]" >
         < email  xmlns = "uri:oozie:email-action:0.2" >
             < to >[COMMA-SEPARATED-TO-ADDRESSES]</ to >
             < cc >[COMMA-SEPARATED-CC-ADDRESSES]</ cc <!-- cc is optional -->
             < subject >[SUBJECT]</ subject >
             < body >[BODY]</ body >
             < content_type >[CONTENT-TYPE]</ content_type <!-- content_type is optional -->
             < attachment >[COMMA-SEPARATED-HDFS-FILE-PATHS]</ attachment <!-- attachment is optional -->
         </ email >
         < ok  to = "[NODE-NAME]" />
         < error  to = "[NODE-NAME]" />
     </ action >
     ...
</ workflow-app >
  • to 和 cc 命令都用来指定邮件的收件人,多个收件人地址用逗号分割,to 必须有,cc可选
  • subject 指定邮件标题,body指定邮件内容可以指定邮件内容格式(content type)为 "text/html",默认是"text/plain"
  • attachment 用来指定 hdfs中的文件作为附件,多个文件逗号分割,非完全路径(不是以hdfs://开头的路径)默认为hdfs上的路径,不能使用本地文件作为附件
Oozie Email 配置 oozie-site.xml中加入邮件服务器 和发件人信息 ,如果使用smtp协议必须开通
<property>
<name>oozie.email.smtp.host</name>
<value>smtp.qq.com</value>
</property>
<property>
<name>oozie.email.smtp.port</name>
<value>587</value>
</property>
<property>
<name>oozie.email.from.address</name>
<value>[email protected]</value>
</property>
<property>
<name>oozie.email.smtp.auth</name>
<value>true</value>
</property>
<property>
<name>oozie.email.smtp.username</name>
<value>[email protected]</value>
</property>
<property>
<name>oozie.email.smtp.password</name>
<value>bfxymlcmuuorbdef</value>
</property>
Email Action 使用实例一:Oozie自带案例运行
1,新建 job.properties
1
2
3
4
5
jobTracker=hadoop-node1.novalocal:8050
queueName=default
examplesRoot=xwj_test
oozie.wf.application.path=${nameNode}/user/oozie/${examplesRoot}/apps/shell/email/workflow.xml
2,workflow.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
< workflow-app  xmlns = "uri:oozie:workflow:0.4"  name = "email-wf" >
     < start  to = "email-node" />
     < action  name = "email-node" >
         < email  xmlns = "uri:oozie:email-action:0.1" >
             < to >[email protected]</ to >
             < cc >[email protected]</ cc >
             < subject >Email notifications for ${wf:id()}</ subject >
             < body >The wf ${wf:id()} successfully completed.</ body >
         </ email >
         < ok  to = "end" />
         < error  to = "fail" />
     </ action >
     < kill  name = "fail" >
         < message >Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</ message >
     </ kill >
    < end  name = 'end'  />
</ workflow-app >
3,首先在本地的测试节点上创建文件夹
mkdir -p /opt/mydata/user/oozie/xwj_test/apps/shell/email
4,在hdfs上创建目录 hdfs dfs -mkdir -p /user/oozie/xwj_test/apps/shell/email
5,将上述文件上传到新建好的目录中
cd /opt/mydata/user/oozie/xwj_test/apps/shell/email
6,将本地文件 上传到hdfs目录中
hdfs dfs -put ../email/* /user/oozie/xwj_test/apps/shell/email
7,查看hdfs上的目录文件是否存在
hdfs dfs -ls -r /user/oozie/xwj_test/apps/shell/email
8,切换yarn用户重新提交任务
su yarn
oozie job -oozie http://hadoop-node0.novalocal:11000/oozie -config /opt/mydata/user/oozie/xwj_test/apps/shell/ email/job.properties -run
查看邮件结果

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887198&siteId=291194637