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);
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations