Search in sources :

Example 1 with PrometheusAlertRequest

use of com.sequenceiq.periscope.api.model.PrometheusAlertRequest in project cloudbreak by hortonworks.

the class PrometheusAlertRequestConverter method convert.

@Override
public PrometheusAlertRequest convert(PrometheusAlert source) {
    PrometheusAlertRequest json = new PrometheusAlertRequest();
    json.setAlertName(source.getName());
    json.setDescription(source.getDescription());
    json.setPeriod(source.getPeriod());
    json.setAlertRuleName(source.getAlertRule());
    json.setAlertState(source.getAlertState());
    Map<String, Object> parameters = source.getParameters().getMap();
    json.setAlertOperator(AlertOperator.valueOf(String.valueOf(parameters.get(OPERATOR_PARAM_KEY))));
    json.setThreshold(Double.valueOf(String.valueOf(parameters.get(THRESHOLD_PARAM_KEY))));
    return json;
}
Also used : PrometheusAlertRequest(com.sequenceiq.periscope.api.model.PrometheusAlertRequest)

Example 2 with PrometheusAlertRequest

use of com.sequenceiq.periscope.api.model.PrometheusAlertRequest 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 3 with PrometheusAlertRequest

use of com.sequenceiq.periscope.api.model.PrometheusAlertRequest in project cloudbreak by hortonworks.

the class AutoscalingUtil method createPrometheusAlert.

static void createPrometheusAlert(AutoscaleClient autoscaleClient, Long clusterId, String alertName, String alertOperator, String alertRuleName, int period, Double threshold) {
    PrometheusAlertRequest prometheusAlertRequest = new PrometheusAlertRequest();
    prometheusAlertRequest.setAlertName(alertName);
    if ("more".equals(alertOperator)) {
        prometheusAlertRequest.setAlertOperator(AlertOperator.MORE_THAN);
    } else {
        prometheusAlertRequest.setAlertOperator(AlertOperator.LESS_THAN);
    }
    prometheusAlertRequest.setAlertRuleName(alertRuleName);
    prometheusAlertRequest.setAlertState(AlertState.OK);
    prometheusAlertRequest.setPeriod(period);
    prometheusAlertRequest.setThreshold(threshold);
    AlertEndpoint alertEndpoint = autoscaleClient.alertEndpoint();
    alertEndpoint.createPrometheusAlert(clusterId, prometheusAlertRequest);
}
Also used : PrometheusAlertRequest(com.sequenceiq.periscope.api.model.PrometheusAlertRequest) AlertEndpoint(com.sequenceiq.periscope.api.endpoint.v1.AlertEndpoint)

Aggregations

PrometheusAlertRequest (com.sequenceiq.periscope.api.model.PrometheusAlertRequest)3 AlertEndpoint (com.sequenceiq.periscope.api.endpoint.v1.AlertEndpoint)1 AutoscaleClusterRequest (com.sequenceiq.periscope.api.model.AutoscaleClusterRequest)1 MetricAlertRequest (com.sequenceiq.periscope.api.model.MetricAlertRequest)1 ScalingConfigurationRequest (com.sequenceiq.periscope.api.model.ScalingConfigurationRequest)1 TimeAlertRequest (com.sequenceiq.periscope.api.model.TimeAlertRequest)1 Cluster (com.sequenceiq.periscope.domain.Cluster)1 MetricAlert (com.sequenceiq.periscope.domain.MetricAlert)1 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)1 TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)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