use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO in project pinot by linkedin.
the class AlertJobScheduler method run.
public void run() {
try {
// read all alert configs
LOG.info("Reading all alert configs..");
List<EmailConfigurationDTO> alertConfigs = emailConfigurationDAO.findAll();
// get active jobs
List<String> scheduledJobs = getScheduledJobs();
LOG.info("Scheduled jobs {}", scheduledJobs);
for (EmailConfigurationDTO alertConfig : alertConfigs) {
Long id = alertConfig.getId();
String jobKey = getJobKey(id);
boolean isActive = alertConfig.isActive();
boolean isScheduled = scheduledJobs.contains(jobKey);
// schedule them with quartz, as function is newly created, or newly activated
if (isActive && !isScheduled) {
LOG.info("Found active but not scheduled {}", id);
startJob(alertConfig, jobKey);
} else // remove them from quartz, as function is newly deactivated
if (!isActive && isScheduled) {
LOG.info("Found inactive but scheduled {}", id);
stopJob(jobKey);
} else // but check for cron updates
if (isActive && isScheduled) {
String cronInDatabase = alertConfig.getCron();
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);
}
}
// 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);
EmailConfigurationDTO alertConfigSpec = emailConfigurationDAO.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.EmailConfigurationDTO in project pinot by linkedin.
the class TaskGenerator method createAlertTasks.
public List<AlertTaskInfo> createAlertTasks(AlertJobContext alertJobContext, DateTime monitoringWindowStartTime, DateTime monitoringWindowEndTime) throws Exception {
List<AlertTaskInfo> tasks = new ArrayList<>();
EmailConfigurationDTO alertConfig = alertJobContext.getAlertConfig();
long jobExecutionId = alertJobContext.getJobExecutionId();
AlertTaskInfo taskInfo = new AlertTaskInfo(jobExecutionId, monitoringWindowStartTime, monitoringWindowEndTime, alertConfig, null);
tasks.add(taskInfo);
return tasks;
}
use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO in project pinot by linkedin.
the class EmailResource method removeFunctionFromEmail.
@POST
@Path("{emailId}/delete/{functionId}")
public void removeFunctionFromEmail(@PathParam("emailId") Long emailId, @PathParam("functionId") Long functionId) {
AnomalyFunctionDTO function = functionDAO.findById(functionId);
EmailConfigurationDTO emailConfiguration = emailDAO.findById(emailId);
if (function != null && emailConfiguration != null) {
if (emailConfiguration.getFunctions().contains(function)) {
emailConfiguration.getFunctions().remove(function);
emailDAO.update(emailConfiguration);
}
}
}
use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO in project pinot by linkedin.
the class EmailResource method addFunctionInEmail.
@POST
@Path("{emailId}/add/{functionId}")
public void addFunctionInEmail(@PathParam("emailId") Long emailId, @PathParam("functionId") Long functionId) {
AnomalyFunctionDTO function = functionDAO.findById(functionId);
EmailConfigurationDTO emailConfiguration = emailDAO.findById(emailId);
List<EmailConfigurationDTO> emailConfigurationsWithFunction = emailDAO.findByFunctionId(functionId);
for (EmailConfigurationDTO emailConfigurationDTO : emailConfigurationsWithFunction) {
emailConfigurationDTO.getFunctions().remove(function);
emailDAO.update(emailConfigurationDTO);
}
if (function != null && emailConfiguration != null) {
if (!emailConfiguration.getFunctions().contains(function)) {
emailConfiguration.getFunctions().add(function);
emailDAO.update(emailConfiguration);
}
} else {
throw new IllegalArgumentException("function or email not found for email : " + emailId + " function : " + functionId);
}
}
use of com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO 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();
}
Aggregations