Exemplo n.º 1
0
  public boolean doCheckAndSend() throws JobEmailNotificationException {
    String jobStatus =
        jobState.getGenericInformation().get(GENERIC_INFORMATION_KEY_NOTIFICATION_EVENT);
    List<String> jobStatusList = new ArrayList<>();
    if (jobStatus != null) {
      jobStatusList = Arrays.asList(jobStatus.toLowerCase().split("\\s*,\\s*"));
    }

    switch (eventType) {
      case JOB_CHANGE_PRIORITY:
      case JOB_IN_ERROR:
      case JOB_PAUSED:
      case JOB_PENDING_TO_FINISHED:
      case JOB_PENDING_TO_RUNNING:
      case JOB_RESTARTED_FROM_ERROR:
      case JOB_RESUMED:
      case JOB_RUNNING_TO_FINISHED:
      case JOB_SUBMITTED:
        break;
      default:
        logger.trace("Event not in the list of email notification, doing nothing");
        return false;
    }
    if (!PASchedulerProperties.EMAIL_NOTIFICATIONS_ENABLED.getValueAsBoolean()) {
      logger.debug("Notification emails disabled, doing nothing");
      return false;
    }
    if (!jobStatusList.contains(eventType.toString().toLowerCase())) {
      return false;
    }
    try {
      sender.sender(getTo(), getSubject(), getBody());
      return true;
    } catch (AddressException e) {
      throw new JobEmailNotificationException("Malformed email address", e);
    } catch (MessagingException e) {
      throw new JobEmailNotificationException("Error sending email: " + e.getMessage(), e);
    }
  }
Exemplo n.º 2
0
 private String getSubject() {
   String jobID = jobState.getId().value();
   String event = eventType.toString();
   return String.format(SUBJECT_TEMPLATE, jobID, event);
 }