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));
}
}
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));
}
}
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);
}
}
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);
}
}
}
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);
}
Aggregations