Search in sources :

Example 1 with ApiHostsToRemoveArgs

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);
    }
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiHostsToRemoveArgs(com.cloudera.api.swagger.model.ApiHostsToRemoveArgs) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)1 ApiException (com.cloudera.api.swagger.client.ApiException)1 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)1 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)1 ApiHostsToRemoveArgs (com.cloudera.api.swagger.model.ApiHostsToRemoveArgs)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)1