message.addAllToAddress(emailList); message.setMimeType("text/html"); message.setSubject( "Flow status could not be updated from " + executor.getHost() + " on " + azkabanName); message.println( "<h2 style=\"color:#FF0000\"> Flow status could not be updated from " + executor.getHost() + " on " + azkabanName + "</h2>"); message.println("The actual status of these executions is unknown, " + "because getting status update from azkaban executor is failing"); message.println(""); message.println("<h3>Error detail</h3>"); message.println("<pre>" + ExceptionUtils.getStackTrace(updateException) + "</pre>"); message.println(""); message.println("<h3>Affected executions</h3>"); message.println("<ul>"); for (final ExecutableFlow flow : flows) { final int execId = flow.getExecutionId(); message.println("<li>Execution '" + flow.getExecutionId() + "' of flow '" + flow.getFlowId() + "' of project '" + flow.getProjectName() + "' - " + " <a href=\"" + executionUrl + "\">Execution Link</a></li>"); message.println("</ul>"); return true;
public EmailMessage createMessage() { final EmailMessage message = new EmailMessage( this.mailHost, this.mailPort, this.mailUser, this.mailPassword, this); message.setFromAddress(this.mailSender); message.setTLS(this.tls); message.setAuth(this.usesAuth); return message; }
@Test public void testSendEmail() throws Exception { this.em.setTLS("true"); this.em.addToAddress(this.toAddr); this.em.setFromAddress(this.sender); this.em.setSubject("azkaban test email"); this.em.setBody("azkaban test email"); this.em.sendEmail(); verify(this.mimeMessage).addRecipient(RecipientType.TO, this.addresses[0]); verify(this.mailSender).sendMessage(this.mimeMessage, this.addresses); }
public EmailMessage createEmailMessage(final String subject, final String mimetype, final Collection<String> emailList) { final EmailMessage message = this.messageCreator.createMessage(); message.addAllToAddress(emailList); message.setMimeType(mimetype); message.setSubject(subject); return message; }
protected EmailMessage createEmailMessage(String subject, String mimetype, Collection<String> emailList) { EmailMessage message = new EmailMessage(mailHost, mailUser, mailPassword); message.setFromAddress(mailSender); message.addAllToAddress(emailList); message.setMimeType(mimetype); message.setSubject(subject); return message; }
message.addAllToAddress(triggerInst.getFailureEmails()); message.setMimeType("text/html"); message.println("<table>"); message.println("<tr><td>Start Time</td><td>"); message.println("<tr><td>" + sdf.format(new Date(triggerInst.getStartTime())) + "</td><td>"); message.println("<tr><td>End Time</td><td>"); message.println("<tr><td>" + sdf.format(new Date(triggerInst.getEndTime())) + "</td><td>"); message.println("<tr><td>Duration</td><td>" + Utils.formatDuration(triggerInst.getStartTime(), triggerInst.getEndTime()) + "</td></tr>"); message.println("<tr><td>Status</td><td>" + triggerInst.getStatus() + "</td></tr>"); message.println("</table>"); message.println(""); final String executionUrl = this.emailer.getAzkabanURL() + "/executor?triggerinstanceid=" + triggerInst.getId(); message.println("<a href=\"" + executionUrl + "\">" + triggerInst.getFlowId() + " Flow Trigger Instance Link</a>"); message.println(""); message.println("<h3>Cancelled Dependencies</h3>"); message.println("<table>"); message.println("<tr><td>Dependency Name: " + depInst.getDepName() + "</td><td>"); message .println("<tr><td>Cancellation Cause: " + depInst.getCancellationCause() + "</td><td>"); message.println("</table>");
public void sendSuccessEmail(ExecutableFlow flow) { EmailMessage message = new EmailMessage(mailHost, mailUser, mailPassword); message.setFromAddress(mailSender); ExecutionOptions option = flow.getExecutionOptions(); MailCreator mailCreator = DefaultMailCreator.getCreator(option.getMailCreator()); logger.debug("ExecutorMailer using mail creator:" + mailCreator.getClass().getCanonicalName()); boolean mailCreated = mailCreator.createSuccessEmail(flow, message, azkabanName, clientHostname, clientPortNumber); if (mailCreated && !testMode) { try { message.sendEmail(); } catch (MessagingException e) { logger.error("Email message send failed", e); } } }
@Test public void testSendErrorEmail() throws Exception { final Flow flow = this.project.getFlow("jobe"); flow.addFailureEmails(this.receiveAddrList); Assert.assertNotNull(flow); final ExecutableFlow exFlow = new ExecutableFlow(this.project, flow); final CommonMetrics commonMetrics = new CommonMetrics(new MetricsManager(new MetricRegistry())); final Emailer emailer = new Emailer(this.props, commonMetrics, this.messageCreator, this.executorLoader); emailer.alertOnError(exFlow); verify(this.message).addAllToAddress(this.receiveAddrList); verify(this.message).setSubject("Flow 'jobe' has failed on azkaban"); assertThat(TestUtils.readResource("errorEmail2.html", this)) .isEqualToIgnoringWhitespace(this.message.getBody()); }
public void sendEmail() throws MessagingException { checkSettings(); final Properties props = new Properties(); if (this._usesAuth) { retryConnectToSMTPServer(sender); retrySendMessage(sender, message); sender.close();
public static EmailMessage mockEmailMessage() { final EmailMessage message = mock(EmailMessage.class); final StringBuffer body = new StringBuffer(); when(message.println(any())).thenAnswer((Answer<EmailMessage>) invocation -> { body.append(invocation.<Object>getArgument(0)); return message; }); when(message.getBody()).thenAnswer(invocation -> body.toString()); return message; }
public void setBody(final String body) { setBody(body, this._mimeType); }
@Test public void testProcessTermination() throws Exception { final TriggerInstance triggerInstance = createTriggerInstance(); this.processor.processTermination(triggerInstance); this.sendEmailLatch.await(10L, TimeUnit.SECONDS); verify(this.message).setSubject( "flow trigger for flow 'flowId', project 'proj' has been cancelled on azkaban"); assertThat(TestUtils.readResource("/emailTemplate/flowtriggerfailureemail.html", this)) .isEqualToIgnoringWhitespace(this.message.getBody()); }
public void sendEmail(final EmailMessage message, final boolean mailCreated, final String operation) { if (mailCreated) { try { message.sendEmail(); logger.info("Sent " + operation); this.commonMetrics.markSendEmailSuccess(); } catch (final Exception e) { logger.error("Failed to send " + operation, e); if (!(e instanceof AddressException)) { this.commonMetrics.markSendEmailFail(); } } } }
@Test public void testCreateEmailMessage() { final AbstractMailer mailer = new AbstractMailer(this.props, this.messageCreator); final EmailMessage em = mailer.createEmailMessage("subject", "text/html", this.senderList); verify(this.messageCreator).createMessage(); assertThat(this.message).isEqualTo(em); verify(this.message).setSubject("subject"); }
@Before public void setUp() throws Exception { this.creator = mock(EmailMessageCreator.class); this.mailSender = mock(JavaxMailSender.class); this.mimeMessage = mock(Message.class); this.addresses = new Address[]{new InternetAddress(this.toAddr, false)}; when(this.creator.createSender(any())).thenReturn(this.mailSender); when(this.mailSender.createMessage()).thenReturn(this.mimeMessage); when(this.mimeMessage.getRecipients(Message.RecipientType.TO)).thenReturn(this.addresses); this.em = new EmailMessage(this.host, this.port, this.user, this.password, this.creator); }
public EmailMessage addAttachment(final File file) throws MessagingException { return addAttachment(file.getName(), file); }
public void sendEmail() throws MessagingException { checkSettings(); Properties props = new Properties();
@Test public void testCreateEmailMessage() { final CommonMetrics commonMetrics = new CommonMetrics(new MetricsManager(new MetricRegistry())); final Emailer emailer = new Emailer(this.props, commonMetrics, this.messageCreator, this.executorLoader); final EmailMessage em = emailer .createEmailMessage("subject", "text/html", this.receiveAddrList); verify(this.messageCreator).createMessage(); assertThat(this.messageCreator.createMessage()).isEqualTo(em); verify(this.message).addAllToAddress(this.receiveAddrList); verify(this.message).setSubject("subject"); verify(this.message).setMimeType("text/html"); }
public void sendFirstErrorMessage(ExecutableFlow flow) { EmailMessage message = new EmailMessage(mailHost, mailUser, mailPassword); message.setFromAddress(mailSender); ExecutionOptions option = flow.getExecutionOptions(); MailCreator mailCreator = DefaultMailCreator.getCreator(option.getMailCreator()); logger.debug("ExecutorMailer using mail creator:" + mailCreator.getClass().getCanonicalName()); boolean mailCreated = mailCreator.createFirstErrorMessage(flow, message, azkabanName, clientHostname, clientPortNumber); if (mailCreated && !testMode) { try { message.sendEmail(); } catch (MessagingException e) { logger.error("Email message send failed", e); } } }