use of com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO in project pinot by linkedin.
the class AlertJobSchedulerV2 method run.
public void run() {
try {
// read all alert configs
LOG.info("Reading all alert configs..");
List<AlertConfigDTO> alertConfigs = alertConfigDAO.findAll();
// get active jobs
List<String> scheduledJobs = getScheduledJobs();
LOG.info("Scheduled jobs {}", scheduledJobs);
for (AlertConfigDTO alertConfig : alertConfigs) {
Long id = alertConfig.getId();
String jobKey = getJobKey(id);
boolean isActive = alertConfig.isActive();
boolean isScheduled = scheduledJobs.contains(jobKey);
if (isActive) {
if (isScheduled) {
String cronInDatabase = alertConfig.getCronExpression();
List<Trigger> triggers = (List<Trigger>) quartzScheduler.getTriggersOfJob(JobKey.jobKey(jobKey));
CronTrigger cronTrigger = (CronTrigger) triggers.get(0);
String cronInSchedule = cronTrigger.getCronExpression();
// cron expression has been updated, restart this job
if (!cronInDatabase.equals(cronInSchedule)) {
LOG.info("Cron expression for config {} with jobKey {} has been changed from {} to {}. " + "Restarting schedule", id, jobKey, cronInSchedule, cronInDatabase);
stopJob(jobKey);
startJob(alertConfig, jobKey);
}
} else {
LOG.info("Found active but not scheduled {}", id);
startJob(alertConfig, jobKey);
}
} else {
if (isScheduled) {
LOG.info("Found inactive but scheduled {}", id);
stopJob(jobKey);
}
// for all jobs with not isActive, and not isScheduled, no change required
}
}
// stop the schedule, as function has been deleted
for (String scheduledJobKey : scheduledJobs) {
Long configId = getIdFromJobKey(scheduledJobKey);
AlertConfigDTO alertConfigSpec = alertConfigDAO.findById(configId);
if (alertConfigSpec == null) {
LOG.info("Found scheduled, but not in database {}", configId);
stopJob(scheduledJobKey);
}
}
} catch (SchedulerException e) {
LOG.error("Exception in reading active jobs", e);
}
}
use of com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO in project pinot by linkedin.
the class TaskGenerator method createAlertTasksV2.
public List<AlertTaskInfo> createAlertTasksV2(AlertJobContext alertJobContext, DateTime monitoringWindowStartTime, DateTime monitoringWindowEndTime) throws Exception {
List<AlertTaskInfo> tasks = new ArrayList<>();
AlertConfigDTO alertConfig = alertJobContext.getAlertConfigDTO();
long jobExecutionId = alertJobContext.getJobExecutionId();
AlertTaskInfo taskInfo = new AlertTaskInfo(jobExecutionId, monitoringWindowStartTime, monitoringWindowEndTime, null, alertConfig);
tasks.add(taskInfo);
return tasks;
}
use of com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO in project pinot by linkedin.
the class EntityManagerResource method updateEntity.
@POST
public Response updateEntity(@QueryParam("entityType") String entityTypeStr, String jsonPayload) {
if (Strings.isNullOrEmpty(entityTypeStr)) {
throw new WebApplicationException("EntryType can not be null");
}
EntityType entityType = EntityType.valueOf(entityTypeStr);
try {
switch(entityType) {
case ANOMALY_FUNCTION:
AnomalyFunctionDTO anomalyFunctionDTO = OBJECT_MAPPER.readValue(jsonPayload, AnomalyFunctionDTO.class);
if (anomalyFunctionDTO.getId() == null) {
anomalyFunctionManager.save(anomalyFunctionDTO);
} else {
anomalyFunctionManager.update(anomalyFunctionDTO);
}
break;
case EMAIL_CONFIGURATION:
EmailConfigurationDTO emailConfigurationDTO = OBJECT_MAPPER.readValue(jsonPayload, EmailConfigurationDTO.class);
emailConfigurationManager.update(emailConfigurationDTO);
break;
case DASHBOARD_CONFIG:
DashboardConfigDTO dashboardConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, DashboardConfigDTO.class);
dashboardConfigManager.update(dashboardConfigDTO);
break;
case DATASET_CONFIG:
DatasetConfigDTO datasetConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, DatasetConfigDTO.class);
datasetConfigManager.update(datasetConfigDTO);
break;
case METRIC_CONFIG:
MetricConfigDTO metricConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, MetricConfigDTO.class);
metricConfigManager.update(metricConfigDTO);
break;
case OVERRIDE_CONFIG:
OverrideConfigDTO overrideConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, OverrideConfigDTO.class);
if (overrideConfigDTO.getId() == null) {
overrideConfigManager.save(overrideConfigDTO);
} else {
overrideConfigManager.update(overrideConfigDTO);
}
break;
case ALERT_CONFIG:
AlertConfigDTO alertConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, AlertConfigDTO.class);
if (alertConfigDTO.getId() == null) {
alertConfigManager.save(alertConfigDTO);
} else {
alertConfigManager.update(alertConfigDTO);
}
break;
}
} catch (IOException e) {
LOG.error("Error saving the entity with payload : " + jsonPayload, e);
throw new WebApplicationException(e);
}
return Response.ok().build();
}
use of com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO in project pinot by linkedin.
the class AbstractManagerTestBase method getTestAlertConfiguration.
protected AlertConfigDTO getTestAlertConfiguration(String name) {
AlertConfigDTO alertConfigDTO = new AlertConfigDTO();
alertConfigDTO.setName(name);
alertConfigDTO.setActive(true);
alertConfigDTO.setFromAddress("te@linkedin.com");
alertConfigDTO.setRecipients("anomaly@linedin.com");
alertConfigDTO.setCronExpression("0/10 * * * * ?");
AlertConfigBean.EmailConfig emailConfig = new AlertConfigBean.EmailConfig();
emailConfig.setAnomalyWatermark(0l);
alertConfigDTO.setEmailConfig(emailConfig);
AlertConfigBean.ReportConfigCollection reportConfigCollection = new AlertConfigBean.ReportConfigCollection();
reportConfigCollection.setEnabled(true);
alertConfigDTO.setReportConfigCollection(reportConfigCollection);
return alertConfigDTO;
}
use of com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO in project pinot by linkedin.
the class TestAlertConfigManager method testCreateAlertConfig.
@Test
public void testCreateAlertConfig() {
AlertConfigDTO request = new AlertConfigDTO();
request.setActive(true);
request.setName("my alert config");
alertConfigid = alertConfigDAO.save(request);
Assert.assertTrue(alertConfigid > 0);
}
Aggregations