use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN.
@Test
public void testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN() 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();
Optional<InstanceMetaData> hgHost2 = downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData().stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN().equals("hg0-host-2")).findFirst();
hgHost2.ifPresent(instanceMetaData -> instanceMetaData.setDiscoveryFQDN(null));
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);
ApiHostList apiHostRefList = new ApiHostList();
List<ApiHost> apiHosts = new ArrayList<>();
hostGroups.stream().flatMap(hostGroup -> hostGroup.getInstanceGroup().getAllInstanceMetaData().stream()).map(InstanceMetaData::getDiscoveryFQDN).forEach(hostName -> {
ApiHost apiHostRef = new ApiHost();
apiHostRef.setHostname(hostName);
apiHostRef.setHostId(hostName);
apiHostRef.setHealthSummary(ApiHealthSummary.GOOD);
apiHosts.add(apiHostRef);
});
apiHostRefList.setItems(apiHosts);
when(hostsResourceApi.readHosts(any(), any(), any())).thenReturn(apiHostRefList);
Set<InstanceMetaData> downscaleCandidates = underTest.collectDownscaleCandidates(mock(ApiClient.class), stack, downscaledHostGroup, -2, downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData());
assertEquals(2, downscaleCandidates.size());
assertTrue("Assert if downscaleCandidates contains hg0-host-2, because FQDN is missing", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-2".equals(instanceMetaData.getInstanceId())));
assertTrue("Assert if downscaleCandidates contains hg0-host-5", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-host-5".equals(instanceMetaData.getDiscoveryFQDN())));
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClouderaManagerClusterDecommissionServiceTest method testCollectHostsToRemove.
@Test
public void testCollectHostsToRemove() {
HostGroup hostGroup = new HostGroup();
Set<String> hostNames = Collections.emptySet();
Map<String, InstanceMetaData> hosts = new HashMap<>();
when(clouderaManagerDecomissioner.collectHostsToRemove(stack, hostGroup, hostNames, v31Client)).thenReturn(hosts);
Map<String, InstanceMetaData> actual = underTest.collectHostsToRemove(hostGroup, hostNames);
assertEquals(hosts, actual);
verify(clouderaManagerDecomissioner).collectHostsToRemove(stack, hostGroup, hostNames, v31Client);
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClouderaManagerCommissionerTest method createHostGroup.
private HostGroup createHostGroup(Set<String> runningHostNames) {
HostGroup hostGroup = new HostGroup();
InstanceGroup instanceGroup = new InstanceGroup();
Set<InstanceMetaData> instanceMetaData = createRunningInstanceMetadata(runningHostNames);
instanceGroup.setInstanceMetaData(instanceMetaData);
instanceGroup.setGroupName(HOSTGROUP_NAME_COMPUTE);
hostGroup.setInstanceGroup(instanceGroup);
hostGroup.setName(HOSTGROUP_NAME_COMPUTE);
return hostGroup;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClouderaManagerCommissionerTest method testCollectHostsToCommissionMissingInCM.
@Test
public void testCollectHostsToCommissionMissingInCM() throws ApiException {
Set<String> hostNames = createHostnames(3);
Set<String> hostnamesKnownToCm = new HashSet<>(hostNames);
hostnamesKnownToCm.remove(hostNames.iterator().next());
ApiHostList apiHostList = createGoodHealthApiHostList(hostnamesKnownToCm);
mockListClusterHosts(apiHostList);
HostGroup hostGroup = createHostGroup(hostNames);
Map<String, InstanceMetaData> result = underTest.collectHostsToCommission(getStack(), hostGroup, hostNames, client);
assertEquals(2, result.size());
assertEquals(hostnamesKnownToCm, result.keySet());
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClouderaManagerCommissionerTest method testCollectHostsToCommissionMissingInCB.
@Test
public void testCollectHostsToCommissionMissingInCB() throws ApiException {
Set<String> hostNames = createHostnames(3);
ApiHostList apiHostList = createGoodHealthApiHostList(hostNames);
mockListClusterHosts(apiHostList);
Set<String> hostnamesKnownToCb = new HashSet<>(hostNames);
hostnamesKnownToCb.remove(hostNames.iterator().next());
HostGroup hostGroup = createHostGroup(hostnamesKnownToCb);
Map<String, InstanceMetaData> result = underTest.collectHostsToCommission(getStack(), hostGroup, hostNames, client);
assertEquals(2, result.size());
assertEquals(hostnamesKnownToCb, result.keySet());
}
Aggregations