Search in sources :

Example 1 with MetricAlert

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

the class MetricAlertRequestConverter method convert.

@Override
public MetricAlert convert(MetricAlertRequest source) {
    MetricAlert alert = new MetricAlert();
    alert.setName(source.getAlertName());
    alert.setDescription(source.getDescription());
    alert.setDefinitionName(source.getAlertDefinition());
    alert.setPeriod(source.getPeriod());
    alert.setAlertState(source.getAlertState());
    if (source.getScalingPolicy() != null) {
        alert.setScalingPolicy(scalingPolicyRequestConverter.convert(source.getScalingPolicy()));
    }
    return alert;
}
Also used : MetricAlert(com.sequenceiq.periscope.domain.MetricAlert)

Example 2 with MetricAlert

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

the class MetricEvaluator method run.

@Override
public void run() {
    Cluster cluster = clusterService.find(clusterId);
    MDCBuilder.buildMdcContext(cluster);
    AmbariClient ambariClient = ambariClientProvider.createAmbariClient(cluster);
    try {
        for (MetricAlert alert : alertRepository.findAllByCluster(clusterId)) {
            String alertName = alert.getName();
            LOGGER.info("Checking metric based alert: '{}'", alertName);
            List<Map<String, Object>> alertHistory = ambariClient.getAlertHistory(alert.getDefinitionName(), 1);
            int historySize = alertHistory.size();
            if (historySize > 1) {
                LOGGER.debug("Multiple results found for alert: {}, probably HOST alert, ignoring now..", alertName);
                continue;
            }
            if (!alertHistory.isEmpty()) {
                Map<String, Object> history = alertHistory.get(0);
                String currentState = (String) history.get(ALERT_STATE);
                if (isAlertStateMet(currentState, alert)) {
                    long elapsedTime = getPeriod(history);
                    LOGGER.info("Alert: {} is in '{}' state since {} min(s)", alertName, currentState, ClusterUtils.TIME_FORMAT.format((double) elapsedTime / ClusterUtils.MIN_IN_MS));
                    if (isPeriodReached(alert, elapsedTime) && isPolicyAttached(alert)) {
                        publishEvent(new ScalingEvent(alert));
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("Failed to retrieve alert history", e);
        publishEvent(new UpdateFailedEvent(clusterId));
    }
}
Also used : UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) ScalingEvent(com.sequenceiq.periscope.monitor.event.ScalingEvent) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert) Map(java.util.Map) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 3 with MetricAlert

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

the class AlertService method createMetricAlert.

public MetricAlert createMetricAlert(Long clusterId, MetricAlert alert) {
    Cluster cluster = clusterService.findOneById(clusterId);
    alert.setCluster(cluster);
    MetricAlert metricAlert = (MetricAlert) save(alert);
    cluster.addMetricAlert(metricAlert);
    clusterRepository.save(cluster);
    return metricAlert;
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert)

Example 4 with MetricAlert

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

the class MetricAlertResponseConverter method convert.

@Override
public MetricAlert convert(MetricAlertResponse source) {
    MetricAlert alert = new MetricAlert();
    alert.setName(source.getAlertName());
    alert.setDescription(source.getDescription());
    alert.setDefinitionName(source.getAlertDefinition());
    alert.setPeriod(source.getPeriod());
    alert.setAlertState(source.getAlertState());
    if (source.getScalingPolicy() != null) {
        alert.setScalingPolicy(scalingPolicyRequestConverter.convert(source.getScalingPolicy()));
    }
    return alert;
}
Also used : MetricAlert(com.sequenceiq.periscope.domain.MetricAlert)

Example 5 with MetricAlert

use of com.sequenceiq.periscope.domain.MetricAlert 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)

Aggregations

MetricAlert (com.sequenceiq.periscope.domain.MetricAlert)6 Cluster (com.sequenceiq.periscope.domain.Cluster)3 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)1 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 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)1 TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)1 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)1 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Component (org.springframework.stereotype.Component)1