Repository: oozie
Updated Branches:
  refs/heads/master 2fd0b66b5 -> 9911ebbf4


OOZIE-1393 Allow sending emails via TLS (mbalakrishnan, dionusos via 
andras.piros)


Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/9911ebbf
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/9911ebbf
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/9911ebbf

Branch: refs/heads/master
Commit: 9911ebbf43f09aca2696ec5385c97c4f6c649dcb
Parents: 2fd0b66
Author: Andras Piros <[email protected]>
Authored: Thu Jun 7 10:46:49 2018 +0200
Committer: Andras Piros <[email protected]>
Committed: Thu Jun 7 10:47:48 2018 +0200

----------------------------------------------------------------------
 .../oozie/action/email/EmailActionExecutor.java |  3 ++
 .../sla/listener/SLAEmailEventListener.java     |  3 ++
 core/src/main/resources/oozie-default.xml       |  8 +++++
 .../action/email/TestEmailActionExecutor.java   | 23 +++++++------
 .../site/twiki/DG_EmailActionExtension.twiki    | 34 ++++++++++++++------
 release-log.txt                                 |  1 +
 6 files changed, 53 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/9911ebbf/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java 
b/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
index f93b7ad..a094d93 100644
--- a/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
+++ b/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
@@ -74,6 +74,7 @@ public class EmailActionExecutor extends ActionExecutor {
     public static final String EMAIL_SMTP_USER = CONF_PREFIX + "smtp.username";
     public static final String EMAIL_SMTP_PASS = CONF_PREFIX + "smtp.password";
     public static final String EMAIL_SMTP_FROM = CONF_PREFIX + "from.address";
+    public static final String EMAIL_SMTP_STARTTLS = CONF_PREFIX + 
"smtp.starttls.enable";
     public static final String EMAIL_SMTP_SOCKET_TIMEOUT_MS = CONF_PREFIX + 
"smtp.socket.timeout.ms";
     public static final String EMAIL_ATTACHMENT_ENABLED = CONF_PREFIX + 
"attachment.enabled";
 
@@ -185,6 +186,7 @@ public class EmailActionExecutor extends ActionExecutor {
         Boolean smtpAuthBool = 
ConfigurationService.getBoolean(EMAIL_SMTP_AUTH);
         String smtpUser = ConfigurationService.get(EMAIL_SMTP_USER);
         String smtpPassword = 
ConfigurationService.getPassword(EMAIL_SMTP_PASS, "");
+        Boolean smtpStarttlsBool = 
ConfigurationService.getBoolean(EMAIL_SMTP_STARTTLS);
         String fromAddr = ConfigurationService.get(EMAIL_SMTP_FROM);
         Integer timeoutMillisInt = 
ConfigurationService.getInt(EMAIL_SMTP_SOCKET_TIMEOUT_MS);
 
@@ -192,6 +194,7 @@ public class EmailActionExecutor extends ActionExecutor {
         properties.setProperty("mail.smtp.host", smtpHost);
         properties.setProperty("mail.smtp.port", smtpPortInt.toString());
         properties.setProperty("mail.smtp.auth", smtpAuthBool.toString());
+        properties.setProperty("mail.smtp.starttls.enable", 
smtpStarttlsBool.toString());
 
         // Apply sensible timeouts, as defaults are infinite. See 
https://s.apache.org/javax-mail-timeouts
         properties.setProperty("mail.smtp.connectiontimeout", 
timeoutMillisInt.toString());

http://git-wip-us.apache.org/repos/asf/oozie/blob/9911ebbf/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java 
b/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java
index 6e863df..9602053 100644
--- 
a/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java
+++ 
b/core/src/main/java/org/apache/oozie/sla/listener/SLAEmailEventListener.java
@@ -71,6 +71,7 @@ public class SLAEmailEventListener extends SLAEventListener {
     private final String SMTP_HOST_DEFAULT = "localhost";
     private final String SMTP_PORT_DEFAULT = "25";
     private final boolean SMTP_AUTH_DEFAULT = false;
+    private final boolean SMTP_STARTTLS_DEFAULT = false;
     private final String SMTP_SOURCE_DEFAULT = "oozie@localhost";
     private final String SMTP_CONNECTION_TIMEOUT_DEFAULT = "5000";
     private final String SMTP_TIMEOUT_DEFAULT = "5000";
@@ -109,6 +110,7 @@ public class SLAEmailEventListener extends SLAEventListener 
{
         String smtpHost = conf.get(EmailActionExecutor.EMAIL_SMTP_HOST, 
SMTP_HOST_DEFAULT);
         String smtpPort = conf.get(EmailActionExecutor.EMAIL_SMTP_PORT, 
SMTP_PORT_DEFAULT);
         Boolean smtpAuth = 
conf.getBoolean(EmailActionExecutor.EMAIL_SMTP_AUTH, SMTP_AUTH_DEFAULT);
+        Boolean smtpStarttls = 
conf.getBoolean(EmailActionExecutor.EMAIL_SMTP_STARTTLS, SMTP_STARTTLS_DEFAULT);
         String smtpUser = conf.get(EmailActionExecutor.EMAIL_SMTP_USER, "");
         String smtpPassword = 
ConfigurationService.getPassword(EmailActionExecutor.EMAIL_SMTP_PASS, "");
         String smtpConnectTimeout = conf.get(SMTP_CONNECTION_TIMEOUT, 
SMTP_CONNECTION_TIMEOUT_DEFAULT);
@@ -132,6 +134,7 @@ public class SLAEmailEventListener extends SLAEventListener 
{
         properties.setProperty("mail.smtp.host", smtpHost);
         properties.setProperty("mail.smtp.port", smtpPort);
         properties.setProperty("mail.smtp.auth", smtpAuth.toString());
+        properties.setProperty("mail.smtp.starttls.enable", 
smtpStarttls.toString());
         properties.setProperty("mail.smtp.connectiontimeout", 
smtpConnectTimeout);
         properties.setProperty("mail.smtp.timeout", smtpTimeout);
 

http://git-wip-us.apache.org/repos/asf/oozie/blob/9911ebbf/core/src/main/resources/oozie-default.xml
----------------------------------------------------------------------
diff --git a/core/src/main/resources/oozie-default.xml 
b/core/src/main/resources/oozie-default.xml
index b828c80..3d627be 100644
--- a/core/src/main/resources/oozie-default.xml
+++ b/core/src/main/resources/oozie-default.xml
@@ -3027,6 +3027,14 @@ will be the requeue interval for the actions which are 
waiting for a long time w
     </property>
 
     <property>
+        <name>oozie.email.smtp.starttls.enable</name>
+        <value>false</value>
+        <description>
+            Boolean property that toggles if use TLS in communication or not.
+        </description>
+    </property>
+
+    <property>
       <name>oozie.email.smtp.username</name>
       <value></value>
       <description>

http://git-wip-us.apache.org/repos/asf/oozie/blob/9911ebbf/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java 
b/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
index 354176e..5b39a44 100644
--- 
a/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
+++ 
b/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
@@ -38,6 +38,11 @@ import org.apache.hadoop.fs.Path;
 import org.apache.oozie.WorkflowActionBean;
 import org.apache.oozie.WorkflowJobBean;
 import org.apache.oozie.action.ActionExecutorException;
+import static 
org.apache.oozie.action.email.EmailActionExecutor.EMAIL_SMTP_AUTH;
+import static 
org.apache.oozie.action.email.EmailActionExecutor.EMAIL_SMTP_PASS;
+import static 
org.apache.oozie.action.email.EmailActionExecutor.EMAIL_SMTP_PORT;
+import static 
org.apache.oozie.action.email.EmailActionExecutor.EMAIL_SMTP_SOCKET_TIMEOUT_MS;
+import static 
org.apache.oozie.action.email.EmailActionExecutor.EMAIL_SMTP_USER;
 import org.apache.oozie.action.hadoop.ActionExecutorTestCase;
 import org.apache.oozie.service.ConfigurationService;
 import org.apache.oozie.service.Services;
@@ -68,7 +73,7 @@ public class TestEmailActionExecutor extends 
ActionExecutorTestCase {
 
     private Context createNormalContext(String actionXml) throws Exception {
         EmailActionExecutor ae = new EmailActionExecutor();
-        
Services.get().get(ConfigurationService.class).getConf().setInt("oozie.email.smtp.port",
 server.getSmtp().getPort());
+        
Services.get().get(ConfigurationService.class).getConf().setInt(EMAIL_SMTP_PORT,
 server.getSmtp().getPort());
         // Use default host 'localhost'. Hence, do not set the smtp host.
         // 
Services.get().get(ConfigurationService.class).getConf().set("oozie.email.smtp.host",
 "localhost");
         // Use default from address, 'oozie@localhost'.
@@ -76,9 +81,9 @@ public class TestEmailActionExecutor extends 
ActionExecutorTestCase {
         // 
Services.get().get(ConfigurationService.class).getConf().set("oozie.email.from.address",
 "oozie@localhost");
 
         // Disable auth tests by default.
-        
Services.get().get(ConfigurationService.class).getConf().setBoolean("oozie.email.smtp.auth",
 false);
-        
Services.get().get(ConfigurationService.class).getConf().set("oozie.email.smtp.username",
 "");
-        
Services.get().get(ConfigurationService.class).getConf().set("oozie.email.smtp.password",
 "");
+        
Services.get().get(ConfigurationService.class).getConf().setBoolean(EMAIL_SMTP_AUTH,
 false);
+        
Services.get().get(ConfigurationService.class).getConf().set(EMAIL_SMTP_USER, 
"");
+        
Services.get().get(ConfigurationService.class).getConf().set(EMAIL_SMTP_PASS, 
"");
 
         XConfiguration protoConf = new XConfiguration();
         protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
@@ -96,9 +101,9 @@ public class TestEmailActionExecutor extends 
ActionExecutorTestCase {
         Context ctx = createNormalContext(actionXml);
 
         // Override and enable auth.
-        
Services.get().get(ConfigurationService.class).getConf().setBoolean("oozie.email.smtp.auth",
 true);
-        
Services.get().get(ConfigurationService.class).getConf().set("oozie.email.smtp.username",
 "oozie@localhost");
-        
Services.get().get(ConfigurationService.class).getConf().set("oozie.email.smtp.password",
 "oozie");
+        
Services.get().get(ConfigurationService.class).getConf().setBoolean(EMAIL_SMTP_AUTH,
 true);
+        
Services.get().get(ConfigurationService.class).getConf().set(EMAIL_SMTP_USER, 
"oozie@localhost");
+        
Services.get().get(ConfigurationService.class).getConf().set(EMAIL_SMTP_PASS, 
"oozie");
         return ctx;
     }
 
@@ -196,9 +201,9 @@ public class TestEmailActionExecutor extends 
ActionExecutorTestCase {
             serverThread.start();
             EmailActionExecutor email = new EmailActionExecutor();
             Context ctx = createNormalContext("email-action");
-            
Services.get().get(ConfigurationService.class).getConf().setInt("oozie.email.smtp.port",
 srvPort);
+            
Services.get().get(ConfigurationService.class).getConf().setInt(EMAIL_SMTP_PORT,
 srvPort);
             // Apply a 0.1s timeout to induce a very quick "Read timed out" 
error
-            
Services.get().get(ConfigurationService.class).getConf().setInt("oozie.email.smtp.socket.timeout.ms",
 100);
+            
Services.get().get(ConfigurationService.class).getConf().setInt(EMAIL_SMTP_SOCKET_TIMEOUT_MS,
 100);
             try {
               email.validateAndMail(ctx, prepareEmailElement(false, false));
               fail("Should have failed with a socket timeout error!");

http://git-wip-us.apache.org/repos/asf/oozie/blob/9911ebbf/docs/src/site/twiki/DG_EmailActionExtension.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/DG_EmailActionExtension.twiki 
b/docs/src/site/twiki/DG_EmailActionExtension.twiki
index 588a413..4de290c 100644
--- a/docs/src/site/twiki/DG_EmailActionExtension.twiki
+++ b/docs/src/site/twiki/DG_EmailActionExtension.twiki
@@ -50,21 +50,23 @@ The =subject= and =body= commands are used to specify 
subject and body of the ma
 From uri:oozie:email-action:0.2 one can also specify mail content type as 
<content_type>text/html</content_type>.
 "text/plain" is default.
 
-The =attachment= is used to attach a file(s) on HDFS to the mail. Multiple 
attachment can be provided using comma-separated values. Non fully qualified 
path is considered as a file on default HDFS. A local file cannot be attached.
+The =attachment= is used to attach a file(s) on HDFS to the mail. Multiple 
attachment can be provided using comma-separated values.
+Non fully qualified path is considered as a file on default HDFS. A local file 
cannot be attached.
 
 *Configuration*
 
 The =email= action requires some SMTP server configuration to be present (in 
oozie-site.xml). The following are the values
 it looks for:
-
-=oozie.email.smtp.host= - The host where the email action may find the SMTP 
server (localhost 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).
-=oozie.email.smtp.password= - If authentication is enabled, the username's 
password (empty by default).
-=oozie.email.attachment.enabled= - Boolean property that toggles if configured 
attachments are to be placed into the emails. (false by default).
-=oozie.email.smtp.socket.timeout.ms= - The timeout to apply over all SMTP 
server socket operations (10000ms by default).
+   * =oozie.email.smtp.host= - The host where the email action may find the 
SMTP server (localhost 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.starttls.enable= - Boolean property that toggles if use 
TLS communication or not. (false by default).
+   * =oozie.email.smtp.username= - If authentication is enabled, the username 
to login as (empty by default).
+   * =oozie.email.smtp.password= - If authentication is enabled, the 
username's password (empty by default).
+   * =oozie.email.attachment.enabled= - Boolean property that toggles if 
configured attachments are to be placed into the emails.
+   (false by default).
+   * =oozie.email.smtp.socket.timeout.ms= - The timeout to apply over all SMTP 
server socket operations (10000ms by default).
 
 *Example:*
 
@@ -112,6 +114,18 @@ with the subject and body both containing the workflow ID 
after substitution.
 </xs:schema>
 </verbatim>
 
+*GMail example to oozie-site.xml*
+
+<verbatim>
+oozie.email.smtp.host=smtp.gmail.com
+oozie.email.smtp.port=587
+oozie.email.from.address=<some email address>
+oozie.email.smtp.auth=true
+oozie.email.smtp.starttls.enable=true
+oozie.email.smtp.username=<Gmail Id>
+oozie.email.smtp.password=<Gmail Pass>
+</verbatim>
+
 [[index][::Go back to Oozie Documentation Index::]]
 
 </noautolink>

http://git-wip-us.apache.org/repos/asf/oozie/blob/9911ebbf/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index d07d459..a117bef 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 5.1.0 release (trunk - unreleased)
 
+OOZIE-1393 Allow sending emails via TLS (mbalakrishnan, dionusos via 
andras.piros)
 OOZIE-3156 Retry SSH action check when cannot connect to remote host (txsing 
via andras.piros)
 OOZIE-3227 Eliminate duplicate dependencies when using Hadoop 3 
DistributedCache (dionusos via andras.piros)
 OOZIE-2097 Get rid of non-Javadoc comments (Jan Hentschel via andras.piros)

Reply via email to