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