Search in sources :

Example 11 with EmailConfigurationDTO

use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO in project pinot by linkedin.

the class TestEmailConfigurationManager method testCreateEmailConfig.

@Test
public void testCreateEmailConfig() {
    EmailConfigurationDTO request = getTestEmailConfiguration(metricName, collection);
    emailConfigId = emailConfigurationDAO.save(request);
    assertNotNull(emailConfigId);
}
Also used : EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) Test(org.testng.annotations.Test)

Example 12 with EmailConfigurationDTO

use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO in project pinot by linkedin.

the class TestEmailConfigurationManager method testFunctionEmailAssignment.

@Test(dependsOnMethods = { "testCreateEmailConfig" })
public void testFunctionEmailAssignment() {
    // create function
    AnomalyFunctionDTO functionReq = getTestFunctionSpec("testMetric", "testCollection");
    functionId = anomalyFunctionDAO.save(functionReq);
    assertNotNull(functionId);
    // save function in EmailConfig
    EmailConfigurationDTO emailConfiguration = emailConfigurationDAO.findById(emailConfigId);
    AnomalyFunctionDTO anomalyFunctionSpec = anomalyFunctionDAO.findById(functionId);
    assertEquals(emailConfiguration.getFunctions().size(), 0);
    List<AnomalyFunctionDTO> functionSpecList = new ArrayList<>();
    functionSpecList.add(anomalyFunctionSpec);
    emailConfiguration.setFunctions(functionSpecList);
    emailConfigurationDAO.save(emailConfiguration);
    // Validate relation in both Email and Function objects
    EmailConfigurationDTO emailConfig1 = emailConfigurationDAO.findById(emailConfigId);
    assertEquals(emailConfig1.getFunctions().size(), 1);
}
Also used : ArrayList(java.util.ArrayList) AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) Test(org.testng.annotations.Test)

Example 13 with EmailConfigurationDTO

use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO 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)

Example 14 with EmailConfigurationDTO

use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO in project pinot by linkedin.

the class AlertJobScheduler method runAdHoc.

public void runAdHoc(Long id, DateTime windowStartTime, DateTime windowEndTime) {
    EmailConfigurationDTO alertConfig = emailConfigurationDAO.findById(id);
    if (alertConfig == null) {
        throw new IllegalArgumentException("No alert config with id " + id);
    }
    String triggerKey = String.format("alert_adhoc_trigger_%d", id);
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).startNow().build();
    String jobKey = "adhoc_" + getJobKey(id);
    JobDetail job = JobBuilder.newJob(AlertJobRunner.class).withIdentity(jobKey).build();
    AlertJobContext alertJobContext = new AlertJobContext();
    alertJobContext.setJobDAO(anomalyJobDAO);
    alertJobContext.setTaskDAO(anomalyTaskDAO);
    alertJobContext.setEmailConfigurationDAO(emailConfigurationDAO);
    alertJobContext.setAlertConfigId(id);
    alertJobContext.setJobName(jobKey);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_CONTEXT, alertJobContext);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_START_TIME, windowStartTime);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_END_TIME, windowEndTime);
    try {
        quartzScheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error("Exception while scheduling job", e);
    }
    LOG.info("Started {}: {}", jobKey, alertConfig);
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Example 15 with EmailConfigurationDTO

use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO in project pinot by linkedin.

the class AlertJobScheduler method startJob.

public void startJob(Long id) throws SchedulerException {
    EmailConfigurationDTO alertConfig = emailConfigurationDAO.findById(id);
    if (alertConfig == null) {
        throw new IllegalArgumentException("No alert config with id " + id);
    }
    if (!alertConfig.isActive()) {
        throw new IllegalStateException("Alert config with id " + id + " is not active");
    }
    String jobKey = getJobKey(alertConfig.getId());
    startJob(alertConfig, jobKey);
}
Also used : EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Aggregations

EmailConfigurationDTO (com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)23 ArrayList (java.util.ArrayList)8 AnomalyFunctionDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO)7 EmailConfigurationBean (com.linkedin.thirdeye.datalayer.pojo.EmailConfigurationBean)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)3 Test (org.testng.annotations.Test)3 AlertConfigDTO (com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO)2 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)2 CronTrigger (org.quartz.CronTrigger)2 SchedulerException (org.quartz.SchedulerException)2 Trigger (org.quartz.Trigger)2 AlertTaskInfo (com.linkedin.thirdeye.anomaly.alert.AlertTaskInfo)1 EmailConfigurationManager (com.linkedin.thirdeye.datalayer.bao.EmailConfigurationManager)1 DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)1 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)1 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)1 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)1 OverrideConfigDTO (com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO)1 RawAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO)1