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;
}
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;
}
Aggregations