Search in sources :

Example 1 with AlertOperator

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

the class PrometheusAlertResponseConverter method convert.

@Override
public PrometheusAlert convert(PrometheusAlertResponse source) {
    PrometheusAlert alert = new PrometheusAlert();
    alert.setName(source.getAlertName());
    alert.setDescription(source.getDescription());
    alert.setPeriod(source.getPeriod());
    alert.setAlertState(source.getAlertState() != null ? source.getAlertState() : CRITICAL);
    double threshold = source.getThreshold();
    String alertRuleName = source.getAlertRuleName();
    try {
        AlertOperator alertOperator = source.getAlertOperator() != null ? source.getAlertOperator() : AlertOperator.MORE_THAN;
        String operator = alertOperator.getOperator();
        String alertRule = templateService.createAlert(alertRuleName, alert.getName(), String.valueOf(threshold), alert.getPeriod(), operator);
        alert.setAlertRule(alertRule);
        alert.setParameters(createParametersFrom(threshold, alertOperator));
        if (source.getScalingPolicy() != null) {
            ScalingPolicy scalingPolicy = scalingPolicyRequestConverter.convert(source.getScalingPolicy());
            scalingPolicy.setAlert(alert);
            alert.setScalingPolicy(scalingPolicy);
        }
    } catch (Exception e) {
        throw new ConversionFailedException(TypeDescriptor.valueOf(PrometheusAlertRequest.class), TypeDescriptor.valueOf(PrometheusAlert.class), source.toString(), e);
    }
    return alert;
}
Also used : ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) AlertOperator(com.sequenceiq.periscope.api.model.AlertOperator) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with AlertOperator

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

the class PrometheusAlertRequestConverter method convert.

@Override
public PrometheusAlert convert(PrometheusAlertRequest source) {
    PrometheusAlert alert = new PrometheusAlert();
    alert.setName(source.getAlertName());
    alert.setDescription(source.getDescription());
    alert.setPeriod(source.getPeriod());
    alert.setAlertState(source.getAlertState() != null ? source.getAlertState() : CRITICAL);
    double threshold = source.getThreshold();
    String alertRuleName = source.getAlertRuleName();
    try {
        AlertOperator alertOperator = source.getAlertOperator() != null ? source.getAlertOperator() : AlertOperator.MORE_THAN;
        String operator = alertOperator.getOperator();
        String alertRule = templateService.createAlert(alertRuleName, alert.getName(), String.valueOf(threshold), alert.getPeriod(), operator);
        alert.setAlertRule(alertRule);
        alert.setParameters(createParametersFrom(threshold, alertOperator));
    } catch (Exception e) {
        throw new ConversionFailedException(TypeDescriptor.valueOf(PrometheusAlertRequest.class), TypeDescriptor.valueOf(PrometheusAlert.class), source.toString(), e);
    }
    return alert;
}
Also used : ConversionFailedException(org.springframework.core.convert.ConversionFailedException) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) AlertOperator(com.sequenceiq.periscope.api.model.AlertOperator) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AlertOperator (com.sequenceiq.periscope.api.model.AlertOperator)2 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)2 ConversionFailedException (org.springframework.core.convert.ConversionFailedException)2 ScalingPolicy (com.sequenceiq.periscope.domain.ScalingPolicy)1