Search in sources :

Example 1 with EmailConfigurationDTO

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);
    }
}
Also used : CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) ArrayList(java.util.ArrayList) List(java.util.List) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Example 2 with EmailConfigurationDTO

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;
}
Also used : AlertTaskInfo(com.linkedin.thirdeye.anomaly.alert.AlertTaskInfo) ArrayList(java.util.ArrayList) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Example 3 with EmailConfigurationDTO

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);
        }
    }
}
Also used : AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with EmailConfigurationDTO

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);
    }
}
Also used : AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 5 with EmailConfigurationDTO

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();
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) WebApplicationException(javax.ws.rs.WebApplicationException) AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) AlertConfigDTO(com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO) IOException(java.io.IOException) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) POST(javax.ws.rs.POST)

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