Search in sources :

Example 1 with TlsConfiguration

use of com.sequenceiq.periscope.model.TlsConfiguration in project cloudbreak by hortonworks.

the class TlsSecurityService method getConfiguration.

public TlsConfiguration getConfiguration(Cluster cluster) {
    SecurityConfig securityConfig = cluster.getSecurityConfig();
    if (securityConfig != null) {
        return new TlsConfiguration(securityConfig.getClientKeyDecoded(), securityConfig.getClientCertDecoded(), securityConfig.getServerCertDecoded());
    }
    securityConfig = securityConfigRepository.findByClusterId(cluster.getId());
    if (securityConfig == null) {
        securityConfig = prepareSecurityConfig(cluster.getStackId());
    }
    return new TlsConfiguration(securityConfig.getClientKeyDecoded(), securityConfig.getClientCertDecoded(), securityConfig.getServerCertDecoded());
}
Also used : SecurityConfig(com.sequenceiq.periscope.domain.SecurityConfig) TlsConfiguration(com.sequenceiq.periscope.model.TlsConfiguration)

Example 2 with TlsConfiguration

use of com.sequenceiq.periscope.model.TlsConfiguration in project cloudbreak by hortonworks.

the class AmbariClientProvider method createAmbariClient.

public AmbariClient createAmbariClient(Cluster cluster) {
    if (cluster.getStackId() != null) {
        TlsConfiguration tlsConfig = tlsSecurityService.getConfiguration(cluster);
        if (proxyConfig.isUseProxyForClusterConnection()) {
            String proxyHost = proxyConfig.getHttpsProxyHost();
            int proxyPort = proxyConfig.getHttpsProxyPort();
            if (proxyConfig.isProxyAuthRequired()) {
                String proxyUser = proxyConfig.getHttpsProxyUser();
                String proxyPassword = proxyConfig.getHttpsProxyPassword();
                LOGGER.info("Create Ambari client to connect to {}:{}, through proxy: {}:{} with proxy user: {}", cluster.getHost(), cluster.getPort(), proxyHost, proxyPort, proxyUser);
                return new AmbariClient(cluster.getHost(), cluster.getPort(), cluster.getAmbariUser(), cluster.getAmbariPass(), tlsConfig.getClientCert(), tlsConfig.getClientKey(), tlsConfig.getServerCert(), proxyHost, proxyPort, proxyUser, proxyPassword);
            } else {
                LOGGER.info("Create Ambari client to connect to {}:{}, through proxy: {}:{}", cluster.getHost(), cluster.getPort(), proxyHost, proxyPort);
                return new AmbariClient(cluster.getHost(), cluster.getPort(), cluster.getAmbariUser(), cluster.getAmbariPass(), tlsConfig.getClientCert(), tlsConfig.getClientKey(), tlsConfig.getServerCert(), proxyHost, proxyPort);
            }
        } else {
            LOGGER.info("Create Ambari client to connect to {}:{}", cluster.getHost(), cluster.getPort());
            return new AmbariClient(cluster.getHost(), cluster.getPort(), cluster.getAmbariUser(), cluster.getAmbariPass(), tlsConfig.getClientCert(), tlsConfig.getClientKey(), tlsConfig.getServerCert());
        }
    } else {
        return getAmbariClientForNonCloudbreakCluster(cluster);
    }
}
Also used : TlsConfiguration(com.sequenceiq.periscope.model.TlsConfiguration) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 3 with TlsConfiguration

use of com.sequenceiq.periscope.model.TlsConfiguration in project cloudbreak by hortonworks.

the class ConsulKeyValueService method deleteAlert.

public void deleteAlert(Cluster cluster, PrometheusAlert alert) {
    Ambari ambari = cluster.getAmbari();
    try {
        TlsConfiguration tlsConfig = tlsSecurityService.getConfiguration(cluster);
        ConsulClient consulClient = ConsulUtils.createClient(ambari.getHost(), cluster.getPort(), tlsConfig);
        String alertKey = getKeyNameForAlert(alert);
        consulClient.deleteKVValue(alertKey);
        LOGGER.info("Alert has been removed from Consul KV store with name: '{}' on host: '{}'.", alertKey, ambari.getHost());
    } catch (Exception e) {
        LOGGER.warn("Alert could not be deleted from Consul KV store:", e);
    }
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) TlsConfiguration(com.sequenceiq.periscope.model.TlsConfiguration) Ambari(com.sequenceiq.periscope.domain.Ambari)

Example 4 with TlsConfiguration

use of com.sequenceiq.periscope.model.TlsConfiguration in project cloudbreak by hortonworks.

the class PrometheusEvaluator method run.

@Override
public void run() {
    try {
        Cluster cluster = clusterService.find(clusterId);
        MDCBuilder.buildMdcContext(cluster);
        TlsConfiguration tlsConfig = tlsSecurityService.getConfiguration(cluster);
        Client client = RestClientUtil.createClient(tlsConfig.getServerCert(), tlsConfig.getClientCert(), tlsConfig.getClientKey(), true, PrometheusEvaluator.class);
        String prometheusAddress = String.format("https://%s:%s/prometheus", cluster.getAmbari().getHost(), cluster.getPort());
        WebTarget target = client.target(prometheusAddress);
        for (PrometheusAlert alert : alertRepository.findAllByCluster(clusterId)) {
            String alertName = alert.getName();
            LOGGER.info("Checking Prometheus based alert: '{}'", alertName);
            String query = URLEncoder.encode(String.format("ALERTS{alertname=\"%s\"}[%dm]", alert.getName(), alert.getPeriod()), "UTF-8");
            Response response = target.path("/api/v1/query").queryParam("query", query).request().header("Accept", MediaType.APPLICATION_JSON_VALUE).get();
            PrometheusResponse prometheusResponse = JaxRSUtil.response(response, PrometheusResponse.class);
            boolean triggerScale = false;
            switch(alert.getAlertState()) {
                case OK:
                    triggerScale = prometheusResponse.getData().getResult().isEmpty();
                    break;
                case CRITICAL:
                    for (Result alertResult : prometheusResponse.getData().getResult()) {
                        if ("firing".equals(alertResult.getMetric().getAlertstate())) {
                            List<Object> lastSample = alertResult.getValues().get(alertResult.getValues().size() - 1);
                            Object alertValue = lastSample.get(1);
                            if (alertValue instanceof String) {
                                if ("0".equals(alertValue)) {
                                    break;
                                }
                                triggerScale = true;
                            }
                        }
                    }
                    break;
                default:
                    triggerScale = false;
                    break;
            }
            if (triggerScale && isPolicyAttached(alert)) {
                publishEvent(new ScalingEvent(alert));
            }
        }
    } catch (Exception e) {
        LOGGER.error("Failed to retrieve alerts from Prometheus", e);
        publishEvent(new UpdateFailedEvent(clusterId));
    }
}
Also used : UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) PrometheusResponse(com.sequenceiq.periscope.model.PrometheusResponse) Cluster(com.sequenceiq.periscope.domain.Cluster) Result(com.sequenceiq.periscope.model.PrometheusResponse.Result) PrometheusResponse(com.sequenceiq.periscope.model.PrometheusResponse) Response(javax.ws.rs.core.Response) PrometheusAlert(com.sequenceiq.periscope.domain.PrometheusAlert) ScalingEvent(com.sequenceiq.periscope.monitor.event.ScalingEvent) TlsConfiguration(com.sequenceiq.periscope.model.TlsConfiguration) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 5 with TlsConfiguration

use of com.sequenceiq.periscope.model.TlsConfiguration in project cloudbreak by hortonworks.

the class ConsulKeyValueService method addAlert.

public PrometheusAlert addAlert(Cluster cluster, PrometheusAlert alert) {
    Ambari ambari = cluster.getAmbari();
    try {
        if (RUNNING.equals(cluster.getState())) {
            TlsConfiguration tlsConfig = tlsSecurityService.getConfiguration(cluster);
            ConsulClient consulClient = ConsulUtils.createClient(ambari.getHost(), cluster.getPort(), tlsConfig);
            String alertKey = getKeyNameForAlert(alert);
            consulClient.setKVValue(alertKey, alert.getAlertRule());
            LOGGER.info("Alert has been added to Consul KV store with name: '{}' on host: '{}'.", alertKey, ambari.getHost());
        }
    } catch (Exception e) {
        LOGGER.warn("Alert could not be added to Consul KV store:", e);
    }
    return alert;
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) TlsConfiguration(com.sequenceiq.periscope.model.TlsConfiguration) Ambari(com.sequenceiq.periscope.domain.Ambari)

Aggregations

TlsConfiguration (com.sequenceiq.periscope.model.TlsConfiguration)5 ConsulClient (com.ecwid.consul.v1.ConsulClient)2 Ambari (com.sequenceiq.periscope.domain.Ambari)2 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)1 Cluster (com.sequenceiq.periscope.domain.Cluster)1 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)1 SecurityConfig (com.sequenceiq.periscope.domain.SecurityConfig)1 PrometheusResponse (com.sequenceiq.periscope.model.PrometheusResponse)1 Result (com.sequenceiq.periscope.model.PrometheusResponse.Result)1 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)1 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1