Search in sources :

Example 1 with EmailConfigurationManager

use of com.linkedin.thirdeye.datalayer.bao.EmailConfigurationManager in project pinot by linkedin.

the class AlertJobRunner method execute.

@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    LOG.info("Running " + jobExecutionContext.getJobDetail().getKey().toString());
    alertJobContext = (AlertJobContext) jobExecutionContext.getJobDetail().getJobDataMap().get(ALERT_JOB_CONTEXT);
    jobDAO = alertJobContext.getJobDAO();
    taskDAO = alertJobContext.getTaskDAO();
    EmailConfigurationManager emailConfigurationDAO = alertJobContext.getEmailConfigurationDAO();
    long alertConfigId = alertJobContext.getAlertConfigId();
    EmailConfigurationDTO alertConfig = emailConfigurationDAO.findById(alertConfigId);
    if (alertConfig == null) {
        LOG.error("Alert config with id {} does not exist", alertConfigId);
    } else {
        alertJobContext.setAlertConfig(alertConfig);
        DateTime monitoringWindowStartTime = (DateTime) jobExecutionContext.getJobDetail().getJobDataMap().get(ALERT_JOB_MONITORING_WINDOW_START_TIME);
        DateTime monitoringWindowEndTime = (DateTime) jobExecutionContext.getJobDetail().getJobDataMap().get(ALERT_JOB_MONITORING_WINDOW_END_TIME);
        // Compute window end
        if (monitoringWindowEndTime == null) {
            long delayMillis = 0;
            if (alertConfig.getWindowDelay() != null) {
                delayMillis = TimeUnit.MILLISECONDS.convert(alertConfig.getWindowDelay(), alertConfig.getWindowDelayUnit());
            }
            Date scheduledFireTime = jobExecutionContext.getScheduledFireTime();
            monitoringWindowEndTime = new DateTime(scheduledFireTime).minus(delayMillis);
        }
        // Compute window start according to window end
        if (monitoringWindowStartTime == null) {
            int windowSize = alertConfig.getWindowSize();
            TimeUnit windowUnit = alertConfig.getWindowUnit();
            long windowMillis = TimeUnit.MILLISECONDS.convert(windowSize, windowUnit);
            monitoringWindowStartTime = monitoringWindowEndTime.minus(windowMillis);
        }
        // write to alert_jobs
        Long jobExecutionId = createJob(monitoringWindowStartTime, monitoringWindowEndTime);
        alertJobContext.setJobExecutionId(jobExecutionId);
        // write to alert_tasks
        List<Long> taskIds = createTasks(monitoringWindowStartTime, monitoringWindowEndTime);
    }
}
Also used : EmailConfigurationManager(com.linkedin.thirdeye.datalayer.bao.EmailConfigurationManager) TimeUnit(java.util.concurrent.TimeUnit) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Aggregations

EmailConfigurationManager (com.linkedin.thirdeye.datalayer.bao.EmailConfigurationManager)1 EmailConfigurationDTO (com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)1 Date (java.util.Date)1 TimeUnit (java.util.concurrent.TimeUnit)1 DateTime (org.joda.time.DateTime)1