Search in sources :

Example 1 with AlertConfigDTO

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);
    }
}
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) AlertConfigDTO(com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO)

Example 2 with AlertConfigDTO

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

Example 3 with AlertConfigDTO

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

Example 4 with AlertConfigDTO

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;
}
Also used : AlertConfigBean(com.linkedin.thirdeye.datalayer.pojo.AlertConfigBean) AlertConfigDTO(com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO)

Example 5 with 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);
}
Also used : AlertConfigDTO(com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO) Test(org.testng.annotations.Test)

Aggregations

AlertConfigDTO (com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO)10 EmailConfigurationDTO (com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 AlertTaskInfo (com.linkedin.thirdeye.anomaly.alert.AlertTaskInfo)1 AnomalyFunctionDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO)1 DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)1 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)1 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)1 OverrideConfigDTO (com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO)1 AlertConfigBean (com.linkedin.thirdeye.datalayer.pojo.AlertConfigBean)1 EmailConfig (com.linkedin.thirdeye.datalayer.pojo.AlertConfigBean.EmailConfig)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DateTime (org.joda.time.DateTime)1 CronTrigger (org.quartz.CronTrigger)1