use of com.sequenceiq.periscope.domain.Cluster 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.Cluster in project cloudbreak by hortonworks.
the class ClusterMonitor method execute.
@Override
public void execute(JobExecutionContext context) {
evalContext(context);
try {
CloudbreakClient cloudbreakClient = applicationContext.getBean(CloudbreakClientConfiguration.class).cloudbreakClient();
ClusterService clusterService = applicationContext.getBean(ClusterService.class);
List<Cluster> clusters = clusterService.findAll();
Set<AutoscaleStackResponse> allStacks = cloudbreakClient.stackV1Endpoint().getAllForAutoscale();
for (AutoscaleStackResponse stack : allStacks) {
Status clusterStatus = stack.getClusterStatus();
if (clusterStatus != null && AVAILABLE.equals(clusterStatus)) {
String ambariIp = stack.getAmbariServerIp();
Optional<Cluster> clusterOptional = clusters.stream().filter(c -> c.getStackId() != null && c.getStackId().equals(stack.getStackId())).findFirst();
if (ambariIp != null) {
ClusterCreationEvaluator clusterCreationEvaluator = applicationContext.getBean(ClusterCreationEvaluator.class);
clusterCreationEvaluator.setContext(new ClusterCreationEvaluatorContext(stack, clusterOptional));
executorService.submit(clusterCreationEvaluator);
} else {
LOGGER.info("Could not find Ambari for stack: {}(ID:{})", stack.getName(), stack.getStackId());
}
} else {
LOGGER.info("Do not create or update cluster while the Cloudbreak cluster {}(ID:{}) is in '{}' state instead of 'AVAILABLE'!", stack.getName(), stack.getStackId(), stack.getClusterStatus());
}
}
} catch (Exception ex) {
LOGGER.error("New clusters could not be synchronized from Cloudbreak.", ex);
}
}
use of com.sequenceiq.periscope.domain.Cluster in project cloudbreak by hortonworks.
the class AlertService method updatePrometheusAlert.
public PrometheusAlert updatePrometheusAlert(Long clusterId, Long alertId, PrometheusAlert prometheusAlert) {
PrometheusAlert alert = findPrometheusAlertByCluster(clusterId, alertId);
alert.setName(prometheusAlert.getName());
alert.setAlertRule(prometheusAlert.getAlertRule());
alert.setPeriod(prometheusAlert.getPeriod());
alert.setDescription(prometheusAlert.getDescription());
alert.setAlertState(prometheusAlert.getAlertState());
PrometheusAlert savedAlert = prometheusAlertRepository.save(alert);
Cluster cluster = clusterService.find(clusterId);
consulKeyValueService.addAlert(cluster, savedAlert);
LOGGER.info("Prometheus alert '{}' has been updated for cluster 'ID:{}'", alert.getName(), cluster.getId());
return savedAlert;
}
use of com.sequenceiq.periscope.domain.Cluster 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.Cluster in project cloudbreak by hortonworks.
the class AlertService method getAlertDefinitions.
public List<Map<String, Object>> getAlertDefinitions(Long clusterId) {
Cluster cluster = clusterService.findOneById(clusterId);
List<Map<String, Object>> ret = new ArrayList<>();
List<Map<String, String>> alertDefinitions = ambariClientProvider.createAmbariClient(cluster).getAlertDefinitions();
for (Map<String, String> alertDefinition : alertDefinitions) {
Map<String, Object> tmp = new HashMap<>();
for (Entry<String, String> stringStringEntry : alertDefinition.entrySet()) {
tmp.put(stringStringEntry.getKey(), stringStringEntry.getValue());
}
ret.add(tmp);
}
return ret;
}
Aggregations