use of com.cloudera.api.swagger.model.ApiHostTemplateList in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovableWithoutRepairWithReplicationAndTooMuchRemovableNodes.
@Test
public void testVerifyNodesAreRemovableWithoutRepairWithReplicationAndTooMuchRemovableNodes() 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
HostGroup firstHostGroup = hostGroups.iterator().next();
Set<InstanceMetaData> firstHostGroupInstances = firstHostGroup.getInstanceGroup().getInstanceMetaDataSet();
Set<InstanceMetaData> removableInstances = firstHostGroupInstances.stream().limit(5).collect(Collectors.toSet());
assertThrows(NotEnoughNodeException.class, () -> 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 testNotAvailableNodeShouldBeDeletedWhenRunningNodesFulfillTheReplicationNo.
@Test
public void testNotAvailableNodeShouldBeDeletedWhenRunningNodesFulfillTheReplicationNo() 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, 2);
cluster.setHostGroups(hostGroups);
// ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
ApiHostTemplateList hostTemplates = createHostTemplatesWithDataNodes(hostGroups.stream().findFirst().get().getName());
ApiServiceConfig apiServiceConfig = createApiServiceConfigWithReplication("1", true);
when(clouderaManagerApiFactory.getServicesResourceApi(Mockito.any(ApiClient.class))).thenReturn(servicesResourceApi);
when(servicesResourceApi.readServiceConfig(stack.getName(), "hdfs", "full")).thenReturn(apiServiceConfig);
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
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(resourceAttributeUtil.getTypedAttributes(stack.getDiskResources().get(0), VolumeSetAttributes.class)).thenReturn(Optional.of(volumeSetAttributes));
// WHEN
HostGroup firstHostGroup = hostGroups.iterator().next();
InstanceMetaData firstInstanceMetaData = firstHostGroup.getInstanceGroup().getInstanceMetaDataSet().stream().findFirst().get();
firstInstanceMetaData.setInstanceStatus(InstanceStatus.DELETED_BY_PROVIDER);
Set<InstanceMetaData> removableInstances = Set.of(firstInstanceMetaData);
// WHEN
underTest.verifyNodesAreRemovable(stack, removableInstances, new ApiClient());
// THEN there is no exception
}
use of com.cloudera.api.swagger.model.ApiHostTemplateList in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenEveryHostHasHostname.
@Test
public void testCollectDownscaleCandidatesWhenEveryHostHasHostname() 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);
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-instanceid-4", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-4".equals(instanceMetaData.getInstanceId())));
assertTrue("Assert if downscaleCandidates contains hg0-instanceid-4", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-5".equals(instanceMetaData.getInstanceId())));
}
use of com.cloudera.api.swagger.model.ApiHostTemplateList in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovable.
@Test
public void testVerifyNodesAreRemovable() 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);
ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
when(resourceAttributeUtil.getTypedAttributes(Mockito.any(Resource.class), Mockito.any(Class.class))).thenReturn(Optional.of(volumeSetAttributes));
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();
underTest.verifyNodesAreRemovable(stack, firstHostGroup.getInstanceGroup().getInstanceMetaDataSet(), new ApiClient());
// THEN no exception
}
use of com.cloudera.api.swagger.model.ApiHostTemplateList in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testVerifyNodesAreBusy.
@Test
public void testVerifyNodesAreBusy() 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);
ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
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(getBusyHost()));
when(resourceAttributeUtil.getTypedAttributes(Mockito.any(Resource.class), Mockito.any(Class.class))).thenReturn(Optional.of(volumeSetAttributes));
// WHEN
HostGroup firstHostGroup = hostGroups.iterator().next();
NodeIsBusyException e = Assertions.assertThrows(NodeIsBusyException.class, () -> underTest.verifyNodesAreRemovable(stack, firstHostGroup.getInstanceGroup().getInstanceMetaDataSet(), new ApiClient()));
assertEquals("Node is in 'busy' state, cannot be decommissioned right now. " + "Please try to remove the node later. Busy hosts: [hg0-host-1]", e.getMessage());
// THEN exception
}
Aggregations