use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method getHostsFromCM.
private List<ApiHost> getHostsFromCM() throws ApiException {
LOGGER.debug("Retrieving registered host details from CM.");
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(apiClient);
List<ApiHost> hosts = hostsResourceApi.readHosts(null, null, SUMMARY).getItems();
LOGGER.debug("Retrieving registered host details from CM completed. Host count: [{}]", hosts.size());
return hosts;
}
use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method createUpscaledHostRefList.
private ApiHostRefList createUpscaledHostRefList(Map<String, InstanceMetaData> upscaleInstancesMap, Map<String, ApiHost> upscaleHostsMap) {
LOGGER.debug("Creating ApiHostRefList from upscaled hosts.");
ApiHostRefList body = new ApiHostRefList();
upscaleHostsMap.forEach((hostname, host) -> Optional.ofNullable(upscaleInstancesMap.get(hostname)).ifPresent(instance -> {
ApiHostRef apiHostRef = new ApiHostRef().hostname(instance.getDiscoveryFQDN()).hostId(host.getHostId());
body.addItemsItem(apiHostRef);
}));
if (body.getItems() != null) {
LOGGER.debug("Created ApiHostRefList from upscaled hosts. Host count: [{}]", body.getItems().size());
} else {
LOGGER.debug("Created ApiHostRefList is empty.");
}
return body;
}
use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method deleteHostFromClouderaManager.
private void deleteHostFromClouderaManager(Stack stack, InstanceMetaData data, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
Optional<ApiHost> hostRefOptional = hostRefList.getItems().stream().filter(host -> data.getDiscoveryFQDN() != null && data.getDiscoveryFQDN().equals(host.getHostname())).findFirst();
if (hostRefOptional.isPresent()) {
ApiHost hostRef = hostRefOptional.get();
ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
clustersResourceApi.removeHost(stack.getName(), hostRef.getHostId());
hostsResourceApi.deleteHost(hostRef.getHostId());
LOGGER.debug("Host remove request sent. Host id: [{}]", hostRef.getHostId());
} else {
LOGGER.debug("Host already deleted.");
}
} catch (ApiException e) {
LOGGER.error("Failed to delete host: {}", data.getDiscoveryFQDN(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method collectHostsToRemove.
public Map<String, InstanceMetaData> collectHostsToRemove(Stack stack, HostGroup hostGroup, Set<String> hostNames, ApiClient client) {
Set<InstanceMetaData> hostsInHostGroup = hostGroup.getInstanceGroup().getNotTerminatedInstanceMetaDataSet();
Map<String, InstanceMetaData> hostsToRemove = hostsInHostGroup.stream().filter(hostMetadata -> hostNames.contains(hostMetadata.getDiscoveryFQDN())).collect(Collectors.toMap(InstanceMetaData::getDiscoveryFQDN, hostMetadata -> hostMetadata));
if (hostsToRemove.size() != hostNames.size()) {
List<String> missingHosts = hostNames.stream().filter(h -> !hostsToRemove.containsKey(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CB for host group: {}. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", hostGroup.getName(), missingHosts.size(), missingHosts, hostNames);
}
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
List<String> runningHosts = hostRefList.getItems().stream().map(ApiHost::getHostname).collect(Collectors.toList());
// TODO: what if i remove a node from CM manually?
List<String> matchingCmHosts = hostsToRemove.keySet().stream().filter(hostName -> runningHosts.contains(hostName)).collect(Collectors.toList());
Set<String> matchingCmHostSet = new HashSet<>(matchingCmHosts);
if (matchingCmHosts.size() != hostsToRemove.size()) {
List<String> missingHostsInCm = hostsToRemove.keySet().stream().filter(h -> !matchingCmHostSet.contains(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CM. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", missingHostsInCm.size(), missingHostsInCm, hostsToRemove.keySet());
}
Sets.newHashSet(hostsToRemove.keySet()).stream().filter(hostName -> !matchingCmHostSet.contains(hostName)).forEach(hostsToRemove::remove);
LOGGER.debug("Collected hosts to remove: [{}]", hostsToRemove);
return hostsToRemove;
} catch (ApiException e) {
LOGGER.error("Failed to get host list for cluster: {}", stack.getName(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method enterMaintenanceMode.
public void enterMaintenanceMode(Set<String> hostList, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
String currentHostId = null;
int successCount = 0;
List<String> availableHostsIdsFromCm = null;
LOGGER.debug("Attempting to put {} instances into CM maintenance mode", hostList == null ? 0 : hostList.size());
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
availableHostsIdsFromCm = hostRefList.getItems().stream().filter(apiHostRef -> hostList.contains(apiHostRef.getHostname())).parallel().map(ApiHost::getHostId).collect(Collectors.toList());
for (String hostId : availableHostsIdsFromCm) {
currentHostId = hostId;
hostsResourceApi.enterMaintenanceMode(hostId);
successCount++;
}
LOGGER.debug("Finished putting {} instances into CM maintenance mode. Initial request size: {}, CM availableCount: {}", successCount, hostList == null ? 0 : hostList.size(), availableHostsIdsFromCm == null ? "null" : availableHostsIdsFromCm);
} catch (ApiException e) {
LOGGER.error("Failed while putting a node into maintenance mode. nodeId=" + currentHostId + ", successCount=" + successCount, e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
Aggregations