use of com.cloudera.api.swagger.model.ApiHostTemplateList in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovableWithoutRepairAndReplication.
@Test
public void testVerifyNodesAreRemovableWithoutRepairAndReplication() throws ApiException {
// GIVEN
VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", true, "fstab", List.of(), 50, "vt");
Stack stack = createTestStack(volumeSetAttributes);
Cluster cluster = new Cluster();
stack.setCluster(cluster);
Set<HostGroup> hostGroups = createTestHostGroups(2, 5);
cluster.setHostGroups(hostGroups);
ApiServiceConfig apiServiceConfig = createApiServiceConfigWithReplication("3", true);
ApiHostTemplateList hostTemplates = createHostTemplatesWithDataNodes(hostGroups.stream().findFirst().get().getName());
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
when(resourceAttributeUtil.getTypedAttributes(stack.getDiskResources().get(0), VolumeSetAttributes.class)).thenReturn(Optional.of(volumeSetAttributes));
when(clouderaManagerApiFactory.getServicesResourceApi(Mockito.any(ApiClient.class))).thenReturn(servicesResourceApi);
when(servicesResourceApi.readServiceConfig(stack.getName(), "hdfs", "full")).thenReturn(apiServiceConfig);
when(clouderaManagerApiFactory.getHostsResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostsResourceApi);
when(hostsResourceApi.readHosts(eq(null), eq(null), anyString())).thenReturn(apiHostList);
when(apiHostList.getItems()).thenReturn(List.of());
// WHEN
HostGroup firstHostGroup = hostGroups.iterator().next();
Set<InstanceMetaData> firstHostGroupInstances = firstHostGroup.getInstanceGroup().getInstanceMetaDataSet();
Set<InstanceMetaData> removableInstances = firstHostGroupInstances.stream().limit(2).collect(Collectors.toSet());
underTest.verifyNodesAreRemovable(stack, removableInstances, new ApiClient());
// THEN no exception
}
use of com.cloudera.api.swagger.model.ApiHostTemplateList in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenEveryHostHasHostnameButNotEnoughNodesToDownscale.
@Test
public void testCollectDownscaleCandidatesWhenEveryHostHasHostnameButNotEnoughNodesToDownscale() throws ApiException {
// GIVEN
VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 50, "vt");
Stack stack = createTestStack(volumeSetAttributes);
Cluster cluster = new Cluster();
stack.setCluster(cluster);
Set<HostGroup> hostGroups = createTestHostGroups(1, 6);
cluster.setHostGroups(hostGroups);
HostGroup downscaledHostGroup = hostGroups.iterator().next();
HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(hostsResourceApi);
HostTemplatesResourceApi hostTemplatesResourceApi = mock(HostTemplatesResourceApi.class);
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
assertThrows(NotEnoughNodeException.class, () -> underTest.collectDownscaleCandidates(mock(ApiClient.class), stack, downscaledHostGroup, -8, downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData()));
}
use of com.cloudera.api.swagger.model.ApiHostTemplateList 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.model.ApiHostTemplateList 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