Search in sources :

Example 6 with PrometheusAlert

use of com.sequenceiq.periscope.domain.PrometheusAlert 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;
}
Also used : TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) Cluster(com.sequenceiq.periscope.domain.Cluster) ScalingConfigurationRequest(com.sequenceiq.periscope.api.model.ScalingConfigurationRequest) PrometheusAlertRequest(com.sequenceiq.periscope.api.model.PrometheusAlertRequest) Set(java.util.Set) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) MetricAlertRequest(com.sequenceiq.periscope.api.model.MetricAlertRequest) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) AutoscaleClusterRequest(com.sequenceiq.periscope.api.model.AutoscaleClusterRequest) Cluster(com.sequenceiq.periscope.domain.Cluster) MetricAlertRequest(com.sequenceiq.periscope.api.model.MetricAlertRequest) ScalingConfigurationRequest(com.sequenceiq.periscope.api.model.ScalingConfigurationRequest) TimeAlertRequest(com.sequenceiq.periscope.api.model.TimeAlertRequest) PrometheusAlertRequest(com.sequenceiq.periscope.api.model.PrometheusAlertRequest) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert)

Example 7 with PrometheusAlert

use of com.sequenceiq.periscope.domain.PrometheusAlert in project cloudbreak by hortonworks.

the class AlertService method deletePrometheusAlert.

public void deletePrometheusAlert(Long clusterId, Long alertId) {
    PrometheusAlert alert = prometheusAlertRepository.findByCluster(alertId, clusterId);
    Cluster cluster = clusterRepository.findById(clusterId);
    consulKeyValueService.deleteAlert(cluster, alert);
    Set<PrometheusAlert> alerts = cluster.getPrometheusAlerts().stream().filter(a -> a.getId() != alertId).collect(Collectors.toSet());
    cluster.setPrometheusAlerts(alerts);
    prometheusAlertRepository.delete(alertId);
    clusterRepository.save(cluster);
    LOGGER.info("Prometheus alert '{}' has been deleted for cluster 'ID:{}'", alert.getName(), cluster.getId());
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MetricAlertRepository(com.sequenceiq.periscope.repository.MetricAlertRepository) Service(org.springframework.stereotype.Service) Map(java.util.Map) MDCBuilder(com.sequenceiq.periscope.log.MDCBuilder) AlertRuleDefinitionEntry(com.sequenceiq.periscope.api.model.AlertRuleDefinitionEntry) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) ClusterRepository(com.sequenceiq.periscope.repository.ClusterRepository) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) Set(java.util.Set) Collectors(java.util.stream.Collectors) TimeAlertRepository(com.sequenceiq.periscope.repository.TimeAlertRepository) List(java.util.List) FreeMarkerTemplateUtils.processTemplateIntoString(org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString) AmbariClientProvider(com.sequenceiq.periscope.utils.AmbariClientProvider) Configuration(freemarker.template.Configuration) Entry(java.util.Map.Entry) MetricAlert(com.sequenceiq.periscope.domain.MetricAlert) CommonService(com.sequenceiq.ambari.client.services.CommonService) BaseAlert(com.sequenceiq.periscope.domain.BaseAlert) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) PrometheusAlertRepository(com.sequenceiq.periscope.repository.PrometheusAlertRepository) Collections(java.util.Collections) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) Cluster(com.sequenceiq.periscope.domain.Cluster)

Aggregations

PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)7 Cluster (com.sequenceiq.periscope.domain.Cluster)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AlertOperator (com.sequenceiq.periscope.api.model.AlertOperator)2 MetricAlert (com.sequenceiq.periscope.domain.MetricAlert)2 TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)1 CommonService (com.sequenceiq.ambari.client.services.CommonService)1 AlertRuleDefinitionEntry (com.sequenceiq.periscope.api.model.AlertRuleDefinitionEntry)1 AutoscaleClusterRequest (com.sequenceiq.periscope.api.model.AutoscaleClusterRequest)1 MetricAlertRequest (com.sequenceiq.periscope.api.model.MetricAlertRequest)1 PrometheusAlertRequest (com.sequenceiq.periscope.api.model.PrometheusAlertRequest)1 ScalingConfigurationRequest (com.sequenceiq.periscope.api.model.ScalingConfigurationRequest)1 TimeAlertRequest (com.sequenceiq.periscope.api.model.TimeAlertRequest)1 BaseAlert (com.sequenceiq.periscope.domain.BaseAlert)1 ScalingPolicy (com.sequenceiq.periscope.domain.ScalingPolicy)1