Search in sources :

Example 1 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariAgentHealthEvaluator method run.

@Override
public void run() {
    Cluster cluster = clusterService.find(clusterId);
    MDCBuilder.buildMdcContext(cluster);
    LOGGER.info("Checking '{}' alerts.", AMBARI_AGENT_HEARTBEAT);
    try {
        AmbariClient ambariClient = ambariClientProvider.createAmbariClient(cluster);
        List<Map<String, Object>> alertHistory = ambariClient.getAlert(AMBARI_AGENT_HEARTBEAT_DEF_NAME);
        if (!alertHistory.isEmpty()) {
            List<String> hostNamesToRecover = new ArrayList<>();
            for (Map<String, Object> history : alertHistory) {
                String currentState = (String) history.get(ALERT_STATE);
                if (isAlertStateMet(currentState)) {
                    String hostName = (String) history.get(HOST_NAME);
                    hostNamesToRecover.add(hostName);
                    LOGGER.info("Alert: {} is in '{}' state for host '{}'.", AMBARI_AGENT_HEARTBEAT, currentState, hostName);
                }
            }
            if (!hostNamesToRecover.isEmpty()) {
                hostNamesToRecover.forEach(hn -> LOGGER.info("Host to recover: {}", hn));
                CloudbreakClient cbClient = cloudbreakClientConfiguration.cloudbreakClient();
                FailureReport failureReport = new FailureReport();
                failureReport.setFailedNodes(hostNamesToRecover);
                cbClient.clusterEndpoint().failureReport(cluster.getStackId(), failureReport);
            }
        }
    } catch (Exception e) {
        LOGGER.warn(String.format("Failed to retrieve '%s' alerts.", AMBARI_AGENT_HEARTBEAT), e);
        publishEvent(new UpdateFailedEvent(clusterId));
    }
}
Also used : CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.periscope.domain.Cluster) Map(java.util.Map) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 2 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient 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 3 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient 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 4 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AlertService method addPeriscopeAlerts.

public void addPeriscopeAlerts(Cluster cluster) {
    MDCBuilder.buildMdcContext(cluster);
    if (cluster.getSecurityConfig() != null) {
        try {
            AmbariClient client = ambariClientProvider.createAmbariClient(cluster);
            createAlert(client, getAlertDefinition(client, CONTAINER_ALERT), CONTAINER_ALERT);
            createAlert(client, getAlertDefinition(client, APP_ALERT), APP_ALERT);
        } catch (Exception e) {
            LOGGER.error("Cannot create alert definitions", e);
        }
    }
}
Also used : AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 5 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterSetupServiceTest method testApiAvailableWhenPollerReturnTrueThenApiShouldBeAvailable.

@Test
public void testApiAvailableWhenPollerReturnTrueThenApiShouldBeAvailable() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    AmbariClient ambariClient = ambariClient();
    when(ambariPollingServiceProvider.isAmbariAvailable(stack, ambariClient)).thenReturn(true);
    when(clientFactory.getAmbariClient(stack, stack.getCluster())).thenReturn(ambariClient);
    boolean available = underTest.available(stack);
    verify(ambariPollingServiceProvider, times(1)).isAmbariAvailable(stack, ambariClient);
    verify(clientFactory, times(1)).getAmbariClient(stack, stack.getCluster());
    Assert.assertTrue(available);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Aggregations

AmbariClient (com.sequenceiq.ambari.client.AmbariClient)78 Test (org.junit.Test)39 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)37 Stack (com.sequenceiq.cloudbreak.domain.Stack)32 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)23 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)16 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)16 HashMap (java.util.HashMap)16 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)14 Matchers.anyString (org.mockito.Matchers.anyString)14 Map (java.util.Map)13 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)10 Collections.singletonMap (java.util.Collections.singletonMap)9 HashSet (java.util.HashSet)9 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)6 Status (com.sequenceiq.cloudbreak.api.model.Status)6 List (java.util.List)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6