use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariDecommissioner method removeHostsFromOrchestrator.
private PollingResult removeHostsFromOrchestrator(Stack stack, AmbariClient ambariClient, List<String> hostNames) throws CloudbreakException {
Orchestrator orchestrator = stack.getOrchestrator();
Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
try {
if (orchestratorType.containerOrchestrator()) {
OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
Set<Container> containers = containerRepository.findContainersInCluster(stack.getCluster().getId());
List<ContainerInfo> containersToDelete = containers.stream().filter(input -> hostNames.contains(input.getHost()) && input.getImage().contains(AMBARI_AGENT.getName())).map(input -> new ContainerInfo(input.getContainerId(), input.getName(), input.getHost(), input.getImage())).collect(Collectors.toList());
containerOrchestrator.deleteContainer(containersToDelete, credential);
containerRepository.delete(containers);
return waitForHostsToLeave(stack, ambariClient, hostNames);
} else if (orchestratorType.hostOrchestrator()) {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
Map<String, String> privateIpsByFQDN = new HashMap<>();
stack.getInstanceMetaDataAsList().stream().filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.contains(instanceMetaData.getDiscoveryFQDN().split("\\.")[0]))).forEach(instanceMetaData -> privateIpsByFQDN.put(instanceMetaData.getDiscoveryFQDN(), instanceMetaData.getPrivateIp()));
List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
hostOrchestrator.tearDown(allGatewayConfigs, privateIpsByFQDN);
}
} catch (CloudbreakOrchestratorException e) {
LOGGER.error("Failed to delete orchestrator components while decommissioning: ", e);
throw new CloudbreakException("Failed to delete orchestrator components while decommissioning: ", e);
}
return SUCCESS;
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariDecommissioner method deleteHostFromAmbari.
public boolean deleteHostFromAmbari(Stack stack, HostMetadata data) {
HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getCluster().getAmbariIp());
AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), stack.getCluster());
Map<String, Map<String, String>> runningComponents = ambariClient.getHostComponentsStates();
return deleteHostFromAmbari(data, runningComponents, ambariClient);
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariDecommissioner method collectHostsToRemove.
public Map<String, HostMetadata> collectHostsToRemove(Stack stack, String hostGroupName, Collection<String> hostNames) throws CloudbreakException {
Map<String, HostMetadata> hostsToRemove = collectHostMetadata(stack.getCluster(), hostGroupName, hostNames);
if (hostsToRemove.size() != hostNames.size()) {
throw new CloudbreakException("Not all the hosts found in the given host group.");
}
Cluster cluster = stack.getCluster();
HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp());
AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), cluster);
List<String> runningHosts = ambariClient.getClusterHosts();
Sets.newHashSet(hostsToRemove.keySet()).forEach(hostName -> {
if (!runningHosts.contains(hostName)) {
hostsToRemove.remove(hostName);
}
});
return hostsToRemove;
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariHostsJoinStatusCheckerTask method checkStatus.
@Override
public boolean checkStatus(AmbariHostsCheckerContext hosts) {
try {
AmbariClient ambariClient = hosts.getAmbariClient();
Map<String, String> hostNames = ambariClient.getHostStatuses();
for (HostMetadata hostMetadata : hosts.getHostsInCluster()) {
boolean contains = false;
for (Entry<String, String> hostName : hostNames.entrySet()) {
if (hostName.getKey().equals(hostMetadata.getHostName()) && !"UNKNOWN".equals(hostName.getValue())) {
contains = true;
break;
}
}
if (!contains) {
LOGGER.info("The host {} currently not part of the cluster, waiting for join", hostMetadata.getHostName());
return false;
}
}
} catch (Exception ignored) {
LOGGER.info("Did not join all hosts yet, polling");
return false;
}
return true;
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariOperationsStartCheckerTask method checkStatus.
@Override
public boolean checkStatus(AmbariOperations t) {
Map<String, Integer> installRequests = t.getRequests();
for (Entry<String, Integer> request : installRequests.entrySet()) {
AmbariClient ambariClient = t.getAmbariClient();
BigDecimal installProgress = Optional.ofNullable(ambariClient.getRequestProgress(request.getValue())).orElse(PENDING);
LOGGER.info("Ambari operation start: '{}', Progress: {}", request.getKey(), installProgress);
if (FAILED.compareTo(installProgress) == 0) {
boolean failed = true;
for (int i = 0; i < MAX_RETRY; i++) {
if (ambariClient.getRequestProgress(request.getValue()).compareTo(FAILED) != 0) {
failed = false;
break;
}
}
if (failed) {
Map<String, ?> requests = (Map<String, ?>) ambariClient.getRequestStatus(request.getValue()).get("Requests");
String context = (String) requests.get("request_context");
String status = (String) requests.get("request_status");
throw new AmbariOperationFailedException(String.format("Ambari operation start failed: [component:'%s', requestID: '%s', context: '%s', status: '%s']", request.getKey(), request.getValue(), context, status));
}
}
if (PENDING.compareTo(installProgress) == 0) {
return false;
}
}
return true;
}
Aggregations