use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenPollingTimedOut.
@Test
public void testRotateHostCertificatesWhenPollingTimedOut() throws Exception {
// GIVEN
initTestInput("user");
when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
BatchResourceApi batchResourceApi = mock(BatchResourceApi.class);
when(clouderaManagerApiFactory.getHostsResourceApi(apiClient)).thenReturn(hostsResourceApi);
when(clouderaManagerApiFactory.getBatchResourceApi(apiClient)).thenReturn(batchResourceApi);
ApiHostList hostList = createApiHostList();
when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenReturn(hostList);
ArgumentCaptor<ApiBatchRequest> batchRequestArgumentCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
when(batchResourceApi.execute(batchRequestArgumentCaptor.capture())).thenReturn(createApiBatchResponse(hostList, true));
when(clouderaManagerPollingServiceProvider.startPollingCommandList(eq(stack), eq(apiClient), any(List.class), eq("Rotate host certificates"))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().timeout().build());
// WHEN
ClouderaManagerOperationFailedException exception = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.rotateHostCertificates(null, null, null));
// THEN exception
assertThat(exception).hasMessage("Timeout while Cloudera Manager rotates the host certificates.");
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissionerTest method testDecommissionForNodesNowKnownByCM.
@Test
public void testDecommissionForNodesNowKnownByCM() throws ApiException {
HostTemplatesResourceApi hostTemplatesResourceApi = mock(HostTemplatesResourceApi.class);
ApiHostTemplateList apiHostTemplateList = new ApiHostTemplateList();
apiHostTemplateList.setItems(new ArrayList<>());
when(hostTemplatesResourceApi.readHostTemplates(any())).thenReturn(apiHostTemplateList);
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(client)).thenReturn(hostTemplatesResourceApi);
HostGroup compute = new HostGroup();
compute.setName("compute");
HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
when(clouderaManagerApiFactory.getHostsResourceApi(client)).thenReturn(hostsResourceApi);
ApiHostList apiHostList = new ApiHostList();
apiHostList.addItemsItem(createApiHostRef("host1.example.com"));
apiHostList.addItemsItem(createApiHostRef("host2.example.com", ApiHealthSummary.BAD));
apiHostList.addItemsItem(createApiHostRef("host5.example.com"));
when(hostsResourceApi.readHosts(any(), any(), any())).thenReturn(apiHostList);
InstanceMetaData healthy1 = createInstanceMetadata(InstanceStatus.SERVICES_HEALTHY, "host1.example.com", "compute");
InstanceMetaData bad1 = createInstanceMetadata(InstanceStatus.SERVICES_HEALTHY, "host2.example.com", "compute");
InstanceMetaData failed1 = createInstanceMetadata(InstanceStatus.ORCHESTRATION_FAILED, "host3.example.com", "compute");
InstanceMetaData failed2 = createInstanceMetadata(InstanceStatus.ORCHESTRATION_FAILED, "host4.example.com", "compute");
InstanceMetaData healthy2 = createInstanceMetadata(InstanceStatus.SERVICES_HEALTHY, "host5.example.com", "compute");
Set<InstanceMetaData> instanceMetaDataSet = Set.of(failed1, failed2, healthy1, healthy2, bad1);
Stack stack = getStack();
stack.setPlatformVariant("AWS");
Set<InstanceMetaData> removableInstances = underTest.collectDownscaleCandidates(client, stack, compute, 4, instanceMetaDataSet);
assertEquals(4, removableInstances.size());
assertTrue(removableInstances.contains(failed1));
assertTrue(removableInstances.contains(failed2));
assertTrue(removableInstances.contains(healthy2));
assertTrue(removableInstances.contains(bad1));
}
use of com.cloudera.api.swagger.HostsResourceApi 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.HostsResourceApi 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.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerHostStatusChecker method fetchHeartbeatedHostIpsFromManager.
private List<String> fetchHeartbeatedHostIpsFromManager(ClouderaManagerPollerObject pollerObject) throws ApiException {
HostsResourceApi hostsResourceApi = clouderaManagerApiPojoFactory.getHostsResourceApi(pollerObject.getApiClient());
ApiHostList hostList = hostsResourceApi.readHosts(null, null, VIEW_TYPE);
List<String> hostIpsFromManager = filterForHeartBeatedIps(hostList);
LOGGER.debug("Hosts in the list from manager: " + hostIpsFromManager);
return hostIpsFromManager;
}
Aggregations