Search in sources :

Example 1 with JavaMailAuthenticator

use of org.apache.oozie.action.email.EmailActionExecutor.JavaMailAuthenticator in project oozie by apache.

the class SLAEmailEventListener method init.

@Override
public void init(Configuration conf) throws Exception {
    oozieBaseUrl = ConfigurationService.get(conf, OOZIE_BASE_URL);
    // Get SMTP properties from the configuration used in Email Action
    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);
    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);
    String smtpTimeout = conf.get(SMTP_TIMEOUT, SMTP_TIMEOUT_DEFAULT);
    int blacklistTimeOut = Integer.valueOf(conf.get(BLACKLIST_CACHE_TIMEOUT, BLACKLIST_CACHE_TIMEOUT_DEFAULT));
    blacklistFailCount = Integer.valueOf(conf.get(BLACKLIST_FAIL_COUNT, BLACKLIST_FAIL_COUNT_DEFAULT));
    // blacklist email addresses causing SendFailedException with cache timeout
    blackList = CacheBuilder.newBuilder().expireAfterWrite(blacklistTimeOut, TimeUnit.SECONDS).build(new CacheLoader<String, AtomicInteger>() {

        @Override
        public AtomicInteger load(String key) throws Exception {
            return new AtomicInteger();
        }
    });
    // Set SMTP properties
    Properties properties = new Properties();
    properties.setProperty("mail.smtp.host", smtpHost);
    properties.setProperty("mail.smtp.port", smtpPort);
    properties.setProperty("mail.smtp.auth", smtpAuth.toString());
    properties.setProperty("mail.smtp.connectiontimeout", smtpConnectTimeout);
    properties.setProperty("mail.smtp.timeout", smtpTimeout);
    try {
        fromAddr = new InternetAddress(conf.get("oozie.email.from.address", SMTP_SOURCE_DEFAULT));
    } catch (AddressException ae) {
        LOG.error("Bad Source Address specified in oozie.email.from.address", ae);
        throw ae;
    }
    if (!smtpAuth) {
        session = Session.getInstance(properties);
    } else {
        session = Session.getInstance(properties, new JavaMailAuthenticator(smtpUser, smtpPassword));
    }
    alertEvents = new HashSet<SLAEvent.EventStatus>();
    String alertEventsStr = ConfigurationService.get(conf, SLAService.CONF_ALERT_EVENTS);
    if (alertEventsStr != null) {
        String[] alertEvt = alertEventsStr.split(",", -1);
        for (String evt : alertEvt) {
            alertEvents.add(SLAEvent.EventStatus.valueOf(evt));
        }
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AddressException(javax.mail.internet.AddressException) JavaMailAuthenticator(org.apache.oozie.action.email.EmailActionExecutor.JavaMailAuthenticator) CacheLoader(com.google.common.cache.CacheLoader) Properties(java.util.Properties)

Aggregations

CacheLoader (com.google.common.cache.CacheLoader)1 Properties (java.util.Properties)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AddressException (javax.mail.internet.AddressException)1 InternetAddress (javax.mail.internet.InternetAddress)1 JavaMailAuthenticator (org.apache.oozie.action.email.EmailActionExecutor.JavaMailAuthenticator)1