Skip to content
This repository has been archived by the owner on Jan 6, 2018. It is now read-only.

Commit

Permalink
Fixes OOZIE-121. Fix issues that stemmed from OOZIE-81's Email Action.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh J authored and Angelo Kaichen Huang committed Jul 14, 2011
1 parent 26cfa8f commit a4d9e47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.hadoop.fs.FileSystem;
import org.apache.oozie.action.ActionExecutor;
import org.apache.oozie.action.ActionExecutorException;
import org.apache.oozie.action.ActionExecutorException.ErrorType;
Expand Down Expand Up @@ -110,23 +109,25 @@ protected void validateAndMail(Context context, Element element) throws ActionEx

protected void email(Context context, String[] to, String[] cc, String subject, String body) throws ActionExecutorException {
// Get mailing server details.
String smtpHost = context.getProtoActionConf().get("oozie.email.smtp.host");
String smtpPort = context.getProtoActionConf().get("oozie.email.smtp.port", "25");
Boolean smtpAuth = context.getProtoActionConf().getBoolean("oozie.email.smtp.auth", false);
String smtpUser = context.getProtoActionConf().get("oozie.email.smtp.username", "");
String smtpPassword = context.getProtoActionConf().get("oozie.email.smtp.password", "");
String fromAddr = context.getProtoActionConf().get("oozie.email.from.address");
String smtpHost = getOozieConf().get("oozie.email.smtp.host");
String smtpPort = getOozieConf().get("oozie.email.smtp.port", "25");
Boolean smtpAuth = getOozieConf().getBoolean("oozie.email.smtp.auth", false);
String smtpUser = getOozieConf().get("oozie.email.smtp.username", "");
String smtpPassword = getOozieConf().get("oozie.email.smtp.password", "");
String fromAddr = getOozieConf().get("oozie.email.from.address");

Properties properties = new Properties();
properties.setProperty("mail.smtp.host", smtpHost);
properties.setProperty("mail.smtp.port", smtpPort);
properties.setProperty("mail.smtp.auth", smtpAuth.toString());

Session session;
// Do not use default instance (i.e. Session.getDefaultInstance)
// (cause it may lead to issues when used second time).
if (!smtpAuth) {
session = Session.getDefaultInstance(properties);
session = Session.getInstance(properties);
} else {
session = Session.getDefaultInstance(properties, new JavaMailAuthenticator(smtpUser, smtpPassword));
session = Session.getInstance(properties, new JavaMailAuthenticator(smtpUser, smtpPassword));
}

Message message = new MimeMessage(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.oozie.WorkflowActionBean;
import org.apache.oozie.WorkflowJobBean;
import org.apache.oozie.action.hadoop.ActionExecutorTestCase;
import org.apache.oozie.service.Services;
import org.apache.oozie.service.WorkflowAppService;
import org.apache.oozie.util.XConfiguration;
import org.apache.oozie.util.XmlUtils;
Expand Down Expand Up @@ -47,12 +48,18 @@ protected void setSystemProps() {
private Context createNormalContext(String actionXml) throws Exception {
EmailActionExecutor ae = new EmailActionExecutor();

Services.get().getConf().setInt("oozie.email.smtp.port", server.getSmtp().getPort());
Services.get().getConf().set("oozie.email.smtp.host", "localhost");
Services.get().getConf().set("oozie.email.from.address", "test@oozie.com");

// Disable auth tests by default.
Services.get().getConf().setBoolean("oozie.email.smtp.auth", false);
Services.get().getConf().set("oozie.email.smtp.username", "");
Services.get().getConf().set("oozie.email.smtp.password", "");

XConfiguration protoConf = new XConfiguration();
protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
protoConf.set(WorkflowAppService.HADOOP_UGI, getTestUser() + "," + getTestGroup());
protoConf.setInt("oozie.email.smtp.port", server.getSmtp().getPort());
protoConf.set("oozie.email.smtp.host", "localhost");
protoConf.set("oozie.email.from.address", "test@oozie.com");
injectKerberosInfo(protoConf);

WorkflowJobBean wf = createBaseWorkflow(protoConf, "email-action");
Expand All @@ -65,9 +72,11 @@ private Context createNormalContext(String actionXml) throws Exception {

private Context createAuthContext(String actionXml) throws Exception {
Context ctx = createNormalContext(actionXml);
ctx.getProtoActionConf().setBoolean("oozie.email.smtp.auth", true);
ctx.getProtoActionConf().set("oozie.email.smtp.username", "test@oozie.com");
ctx.getProtoActionConf().set("oozie.email.smtp.password", "oozie");

// Override and enable auth.
Services.get().getConf().setBoolean("oozie.email.smtp.auth", true);
Services.get().getConf().set("oozie.email.smtp.username", "test@oozie.com");
Services.get().getConf().set("oozie.email.smtp.password", "oozie");
return ctx;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/src/site/twiki/DG_EmailActionExtension.twiki
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The =email= action requires some SMTP server configuration to be present (in ooz
it looks for:

=oozie.email.smtp.host= - The host where the email action may find the SMTP server (localhost by default).
=oozie.email.smtp.host= - The port to connect to for the SMTP server (25 by default).
=oozie.email.smtp.port= - The port to connect to for the SMTP server (25 by default).
=oozie.email.from.address= - The from address to be used for mailing all emails (oozie@localhost by default).
=oozie.email.smtp.auth= - Boolean property that toggles if authentication is to be done or not. (false by default).
=oozie.email.smtp.username= - If authentication is enabled, the username to login as (empty by default).
Expand Down

0 comments on commit a4d9e47

Please sign in to comment.