Search in sources :

Example 6 with Cluster

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));
    }
}
Also used : UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) ScalingEvent(com.sequenceiq.periscope.monitor.event.ScalingEvent) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert) Map(java.util.Map) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 7 with Cluster

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);
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) JobExecutionContext(org.quartz.JobExecutionContext) EvaluatorContext(com.sequenceiq.periscope.monitor.evaluator.EvaluatorContext) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) Set(java.util.Set) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ApplicationContext(org.springframework.context.ApplicationContext) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator) Status(com.sequenceiq.cloudbreak.api.model.Status) List(java.util.List) Component(org.springframework.stereotype.Component) JobDataMap(org.quartz.JobDataMap) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) ExecutorService(java.util.concurrent.ExecutorService) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Cluster(com.sequenceiq.periscope.domain.Cluster) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator)

Example 8 with Cluster

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;
}
Also used : PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) Cluster(com.sequenceiq.periscope.domain.Cluster)

Example 9 with Cluster

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;
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert)

Example 10 with Cluster

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.periscope.domain.Cluster) FreeMarkerTemplateUtils.processTemplateIntoString(org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Cluster (com.sequenceiq.periscope.domain.Cluster)34 Map (java.util.Map)6 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)5 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)4 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)4 MetricAlert (com.sequenceiq.periscope.domain.MetricAlert)4 PeriscopeUser (com.sequenceiq.periscope.domain.PeriscopeUser)4 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)4 TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)3 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)3 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 Inject (javax.inject.Inject)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Component (org.springframework.stereotype.Component)3 AutoscaleStackResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse)2 FailureReport (com.sequenceiq.cloudbreak.api.model.FailureReport)2 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)2