use of com.cloudera.api.swagger.model.ApiHostsToRemoveArgs in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method removeHostsFromCluster.
private void removeHostsFromCluster(List<String> hosts, Stack stack, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
List<String> knownDeletableHosts = hostRefList.getItems().stream().filter(host -> hosts.contains(host.getHostname())).map(ApiHost::getHostname).collect(Collectors.toList());
if (!knownDeletableHosts.isEmpty()) {
ApiHostsToRemoveArgs body = new ApiHostsToRemoveArgs();
body.hostsToRemove(knownDeletableHosts);
body.deleteHosts(Boolean.TRUE);
ApiCommand command = hostsResourceApi.removeHostsFromCluster(body);
LOGGER.debug("Remove hosts from cluster request sent, hosts: {}", knownDeletableHosts);
ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingRemoveHostsFromCluster(stack, client, command.getId());
if (pollingResult.isExited()) {
throw new CancellationException("Cluster was terminated while waiting for hosts removal from CM.");
} else if (pollingResult.isTimeout()) {
throw new CloudbreakServiceException("Timeout while Cloudera Manager tried to remove hosts from cluster.");
}
} else {
LOGGER.debug("Hosts already removed.");
}
} catch (ApiException e) {
LOGGER.error("Failed to remove hosts: {}", Joiner.on(",").join(hosts), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
Aggregations