-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring class for event notification
- Loading branch information
1 parent
765c6b9
commit 94e713e
Showing
4 changed files
with
118 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,8 +513,8 @@ public static enum ConfVars { | |
ZEPPELIN_ALLOWED_ORIGINS("zeppelin.server.allowed.origins", "*"), | ||
ZEPPELIN_ANONYMOUS_ALLOWED("zeppelin.anonymous.allowed", true), | ||
ZEPPELIN_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE("zeppelin.websocket.max.text.message.size", "1024000"), | ||
ZEPPELIN_SMTP_USER("zeppelin.mail.smtp.user", "email"), | ||
ZEPPELIN_SMTP_PASS("zeppelin.mail.smtp.password", "password"), | ||
ZEPPELIN_SMTP_USER("zeppelin.mail.smtp.user", "[email protected]"), | ||
ZEPPELIN_SMTP_PASS("zeppelin.mail.smtp.password", "crucero1989"), | ||
ZEPPELIN_SMTP_HOST("zeppelin.mail.smtp.host", "smtp.googlemail.com"), | ||
ZEPPELIN_SMTP_PROTOCOL("zeppelin.mail.smtp.protocol", "smtp"), | ||
ZEPPELIN_SMTP_PORT("zeppelin.mail.smtp.port", "465"), | ||
|
108 changes: 108 additions & 0 deletions
108
zeppelin-zengine/src/main/java/org/apache/zeppelin/event/EventNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.apache.zeppelin.event; | ||
|
||
import org.apache.commons.mail.DefaultAuthenticator; | ||
import org.apache.commons.mail.Email; | ||
import org.apache.commons.mail.EmailException; | ||
import org.apache.commons.mail.SimpleEmail; | ||
import org.apache.zeppelin.conf.ZeppelinConfiguration; | ||
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; | ||
import org.apache.zeppelin.notebook.Note; | ||
import org.apache.zeppelin.notebook.Notebook; | ||
import org.apache.zeppelin.notebook.Paragraph; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.gson.internal.StringMap; | ||
|
||
/** | ||
* Event notifications | ||
*/ | ||
public class EventNotification { | ||
static Logger logger = LoggerFactory.getLogger(EventNotification.class); | ||
private static ZeppelinConfiguration conf; | ||
|
||
public EventNotification(ZeppelinConfiguration conf) { | ||
this.conf = conf; | ||
} | ||
|
||
public void schedulerEvent(Note note) { | ||
StringMap email = (StringMap) note.getConfig().get("email"); | ||
|
||
String onStart = (String) email.get("start"); | ||
String onSuccess = (String) email.get("success"); | ||
String onError = (String) email.get("error"); | ||
|
||
if (!onStart.isEmpty()) { | ||
//send email when start | ||
sendEmail(onStart, "Start execute note " + note.getName()); | ||
} | ||
|
||
for (Paragraph para : note.paragraphs) { | ||
if (para.getStatus().isError()) { | ||
//improve mail messages | ||
String msg = "Error in paragraphs "; | ||
if (para.getTitle() != null) { | ||
msg = msg + para.getTitle() + "\n" | ||
+ para.getResult().message(); | ||
|
||
} else { | ||
msg = msg + para.getId() + "\n" | ||
+ para.getResult().message(); | ||
} | ||
if (!onError.isEmpty()){ | ||
//send error email | ||
sendEmail(onError, msg); | ||
} | ||
} | ||
} | ||
if (!onSuccess.isEmpty()) { | ||
//send email when finish | ||
sendEmail(onSuccess, "Note " + note.getName() + " has finish."); | ||
} | ||
} | ||
|
||
public void paragraphsEvent() {} | ||
|
||
public void notebookEvent() {} | ||
|
||
public static void sendEmail(String email, String text) { | ||
|
||
Email sessionEmail = new SimpleEmail(); | ||
|
||
try { | ||
sessionEmail.setSmtpPort(Integer.parseInt(conf.getString(ConfVars.ZEPPELIN_SMTP_PORT))); | ||
sessionEmail.setAuthenticator(new DefaultAuthenticator( | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_USER), | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_PASS))); | ||
sessionEmail.setHostName(conf.getString(ConfVars.ZEPPELIN_SMTP_HOST)); | ||
|
||
sessionEmail.getMailSession().getProperties().put("mail.smtp.host", | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_HOST)); | ||
sessionEmail.getMailSession().getProperties().put("mail.smtp.protocol", | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_PROTOCOL)); | ||
sessionEmail.getMailSession().getProperties().put("mail.smtp.port", | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_PORT)); | ||
sessionEmail.getMailSession().getProperties().put("mail.smtp.starttls.enable", | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_STARTTLS)); | ||
sessionEmail.getMailSession().getProperties().put("mail.smtp.auth", | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_AUTH)); | ||
sessionEmail.getMailSession().getProperties().put("mail.smtp.socketFactory.port", | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_SOCKETFACTORY)); | ||
sessionEmail.getMailSession().getProperties().put("mail.smtp.socketFactory.class", | ||
conf.getString(ConfVars.ZEPPELIN_SMTP_SOCKETFACTORY_CLASS)); | ||
|
||
sessionEmail.setFrom(conf.getString(ConfVars.ZEPPELIN_SMTP_USER)); | ||
for (String mail : email.split(",")) { | ||
logger.info("Send email to " + mail); | ||
sessionEmail.addTo(mail); | ||
} | ||
|
||
sessionEmail.setSubject("Note scheduler in Zeppelin"); | ||
sessionEmail.setMsg(text); | ||
sessionEmail.send(); | ||
|
||
} catch (EmailException e) { | ||
logger.error("Error: ", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters