use of com.cloudera.api.swagger.HostTemplatesResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method verifyNodesAreRemovable.
public void verifyNodesAreRemovable(Stack stack, Collection<InstanceMetaData> removableInstances, ApiClient client) {
try {
HostTemplatesResourceApi hostTemplatesResourceApi = clouderaManagerApiFactory.getHostTemplatesResourceApi(client);
ApiHostTemplateList hostTemplates = hostTemplatesResourceApi.readHostTemplates(stack.getName());
for (HostGroup hostGroup : stack.getCluster().getHostGroups()) {
Set<InstanceMetaData> removableHostsInHostGroup = removableInstances.stream().filter(instanceMetaData -> instanceMetaData.getInstanceGroup().getGroupName().equals(hostGroup.getName())).collect(Collectors.toSet());
if (!removableHostsInHostGroup.isEmpty()) {
String hostGroupName = hostGroup.getName();
int replication = hostGroupNodesAreDataNodes(hostTemplates, hostGroupName) ? getReplicationFactor(client, stack.getName()) : 0;
Set<InstanceMetaData> runningInstances = hostGroup.getInstanceGroup().getRunningInstanceMetaDataSet();
int removableSizeFromTheRunning = Math.toIntExact(removableHostsInHostGroup.stream().filter(instance -> runningInstances.contains(instance)).count());
verifyNodeCount(replication, removableSizeFromTheRunning, runningInstances.size(), 0, stack);
Set<String> removableInstanceFqdn = removableInstances.stream().map(InstanceMetaData::getDiscoveryFQDN).filter(org.apache.commons.lang3.StringUtils::isNoneBlank).collect(Collectors.toSet());
verifyNodeNotBusy(removableInstanceFqdn, client);
}
}
} catch (ApiException ex) {
throw new CloudbreakServiceException("Could not verify if nodes are removable or not", ex);
}
}
use of com.cloudera.api.swagger.HostTemplatesResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method collectDownscaleCandidates.
public Set<InstanceMetaData> collectDownscaleCandidates(ApiClient client, Stack stack, HostGroup hostGroup, Integer scalingAdjustment, Set<InstanceMetaData> instanceMetaDatasInStack) {
LOGGER.debug("Collecting downscale candidates");
Set<InstanceMetaData> instancesForHostGroup = instanceMetaDatasInStack.stream().filter(instanceMetaData -> instanceMetaData.getInstanceGroup().getGroupName().equals(hostGroup.getName())).collect(Collectors.toSet());
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
HostTemplatesResourceApi hostTemplatesResourceApi = clouderaManagerApiFactory.getHostTemplatesResourceApi(client);
ApiHostTemplateList hostTemplates = hostTemplatesResourceApi.readHostTemplates(stack.getName());
int replication = hostGroupNodesAreDataNodes(hostTemplates, hostGroup.getName()) ? getReplicationFactor(client, stack.getName()) : 0;
verifyNodeCount(replication, scalingAdjustment, instancesForHostGroup.size(), 0, stack);
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
Set<InstanceMetaData> instancesToRemove = getUnusedInstances(scalingAdjustment, instancesForHostGroup, hostRefList);
List<ApiHost> apiHosts = hostRefList.getItems().stream().filter(host -> instancesForHostGroup.stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null).anyMatch(instanceMetaData -> instanceMetaData.getDiscoveryFQDN().equals(host.getHostname()))).collect(Collectors.toList());
Set<String> hostsToRemove = apiHosts.stream().sorted(hostHealthComparator).limit(Math.abs(scalingAdjustment) - instancesToRemove.size()).map(ApiHost::getHostname).collect(Collectors.toSet());
Set<InstanceMetaData> clouderaManagerNodesToRemove = instancesForHostGroup.stream().filter(instanceMetaData -> hostsToRemove.contains(instanceMetaData.getDiscoveryFQDN())).collect(Collectors.toSet());
instancesToRemove.addAll(clouderaManagerNodesToRemove);
LOGGER.debug("Downscale candidates: [{}]", instancesToRemove);
return instancesToRemove;
} catch (ApiException e) {
LOGGER.error("Failed to get host list for cluster: {}", stack.getName(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
Aggregations