Search in sources :

Example 6 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class CronTimeEvaluator method run.

@Override
public void run() {
    Cluster cluster = clusterService.find(clusterId);
    MDCBuilder.buildMdcContext(cluster);
    for (TimeAlert alert : alertRepository.findAllByCluster(clusterId)) {
        if (isTrigger(alert) && isPolicyAttached(alert)) {
            LOGGER.info("Time alert '{}' triggers the '{}' scaling policy", alert.getName(), alert.getScalingPolicy().getName());
            publishEvent(new ScalingEvent(alert));
            break;
        }
    }
}
Also used : TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) ScalingEvent(com.sequenceiq.periscope.monitor.event.ScalingEvent) Cluster(com.sequenceiq.periscope.domain.Cluster)

Example 7 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class ClusterRequestConverter method convert.

@Override
public Cluster convert(AutoscaleClusterRequest source) {
    Cluster cluster = new Cluster();
    cluster.setStackId(source.getStackId());
    cluster.setAutoscalingEnabled(source.enableAutoscaling());
    List<MetricAlertRequest> metricAlertResponses = source.getMetricAlerts();
    if (metricAlertResponses != null && !metricAlertResponses.isEmpty()) {
        Set<MetricAlert> alerts = metricAlertResponses.stream().map(metricAlertJson -> {
            MetricAlert alert = metricAlertRequestConverter.convert(metricAlertJson);
            alert.setCluster(cluster);
            return alert;
        }).collect(Collectors.toSet());
        cluster.setMetricAlerts(alerts);
    }
    List<TimeAlertRequest> timeAlertRequests = source.getTimeAlerts();
    if (timeAlertRequests != null && !timeAlertRequests.isEmpty()) {
        Set<TimeAlert> alerts = timeAlertRequests.stream().map(timeAlertJson -> {
            TimeAlert alert = timeAlertRequestConverter.convert(timeAlertJson);
            alert.setCluster(cluster);
            return alert;
        }).collect(Collectors.toSet());
        cluster.setTimeAlerts(alerts);
    }
    List<PrometheusAlertRequest> prometheusAlertRequests = source.getPrometheusAlerts();
    if (prometheusAlertRequests != null && !prometheusAlertRequests.isEmpty()) {
        Set<PrometheusAlert> alerts = prometheusAlertRequests.stream().map(prometheusAlertJson -> {
            PrometheusAlert alert = prometheusAlertRequestConverter.convert(prometheusAlertJson);
            alert.setCluster(cluster);
            return alert;
        }).collect(Collectors.toSet());
        cluster.setPrometheusAlerts(alerts);
    }
    ScalingConfigurationRequest scalingConfiguration = source.getScalingConfiguration();
    if (scalingConfiguration != null) {
        cluster.setMinSize(scalingConfiguration.getMinSize());
        cluster.setMaxSize(scalingConfiguration.getMaxSize());
        cluster.setCoolDown(scalingConfiguration.getCoolDown());
    }
    return cluster;
}
Also used : TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) Cluster(com.sequenceiq.periscope.domain.Cluster) ScalingConfigurationRequest(com.sequenceiq.periscope.api.model.ScalingConfigurationRequest) PrometheusAlertRequest(com.sequenceiq.periscope.api.model.PrometheusAlertRequest) Set(java.util.Set) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) MetricAlertRequest(com.sequenceiq.periscope.api.model.MetricAlertRequest) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) AutoscaleClusterRequest(com.sequenceiq.periscope.api.model.AutoscaleClusterRequest) Cluster(com.sequenceiq.periscope.domain.Cluster) MetricAlertRequest(com.sequenceiq.periscope.api.model.MetricAlertRequest) ScalingConfigurationRequest(com.sequenceiq.periscope.api.model.ScalingConfigurationRequest) TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) PrometheusAlertRequest(com.sequenceiq.periscope.api.model.PrometheusAlertRequest) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert)

Example 8 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class DateUtilsTest method testIsTriggerWhenTheCurrentTimeIsBeforeTheNextTriggerLessThanTheMonitorUpdateRateThenItShouldNotTriggerAnEvent.

@Test
public void testIsTriggerWhenTheCurrentTimeIsBeforeTheNextTriggerLessThanTheMonitorUpdateRateThenItShouldNotTriggerAnEvent() {
    String timeZone = "America/New_York";
    ZoneId zoneId = ZoneId.of(timeZone);
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 11, 59, 10, 0, zoneId);
    long monitorUpdateRate = 1000;
    when(dateTimeUtils.getDefaultZonedDateTime()).thenReturn(currentZonedTime);
    when(dateTimeUtils.getZonedDateTime(currentZonedTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert("0 0 12 * * ?", timeZone);
    assertFalse(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) Test(org.junit.Test)

Example 9 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class DateUtilsTest method testIsTriggerWhenTheCurrentTimeIsAfterTheNextTriggerLessThanTheMonitorUpdateRateThenItShouldTriggerAnEvent.

@Test
public void testIsTriggerWhenTheCurrentTimeIsAfterTheNextTriggerLessThanTheMonitorUpdateRateThenItShouldTriggerAnEvent() {
    String timeZone = "America/New_York";
    ZoneId zoneId = ZoneId.of(timeZone);
    ZonedDateTime currentTime = ZonedDateTime.of(2017, 12, 20, 20, 1, 10, 0, ZoneId.systemDefault());
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 12, 1, 10, 0, zoneId);
    long monitorUpdateRate = 90000;
    when(dateTimeUtils.getDefaultZonedDateTime()).thenReturn(currentTime);
    when(dateTimeUtils.getZonedDateTime(currentTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert("0 0 12 * * ?", timeZone);
    assertTrue(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) Test(org.junit.Test)

Example 10 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class DateUtilsTest method testIsTriggerWhenTheCurrentTimeIsAfterTheNextTriggerMoreThanTheMonitorUpdateRateThenItShouldNotTriggerAnEvent.

@Test
public void testIsTriggerWhenTheCurrentTimeIsAfterTheNextTriggerMoreThanTheMonitorUpdateRateThenItShouldNotTriggerAnEvent() {
    String timeZone = "UTC";
    ZoneId zoneId = ZoneId.of(timeZone);
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 12, 59, 10, 0, zoneId);
    long monitorUpdateRate = 1000;
    when(dateTimeUtils.getDefaultZonedDateTime()).thenReturn(currentZonedTime);
    when(dateTimeUtils.getZonedDateTime(currentZonedTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert("0 0 12 * * ?", timeZone);
    assertFalse(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) Test(org.junit.Test)

Aggregations

TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)14 ZoneId (java.time.ZoneId)7 ZonedDateTime (java.time.ZonedDateTime)7 Test (org.junit.Test)7 Cluster (com.sequenceiq.periscope.domain.Cluster)2 AutoscaleClusterRequest (com.sequenceiq.periscope.api.model.AutoscaleClusterRequest)1 MetricAlertRequest (com.sequenceiq.periscope.api.model.MetricAlertRequest)1 PrometheusAlertRequest (com.sequenceiq.periscope.api.model.PrometheusAlertRequest)1 ScalingConfigurationRequest (com.sequenceiq.periscope.api.model.ScalingConfigurationRequest)1 TimeAlertRequest (com.sequenceiq.periscope.api.model.TimeAlertRequest)1 MetricAlert (com.sequenceiq.periscope.domain.MetricAlert)1 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)1 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Component (org.springframework.stereotype.Component)1