use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method createUpscaledHostRefList.
private ApiHostRefList createUpscaledHostRefList(Map<String, InstanceMetaData> upscaleInstancesMap, Map<String, ApiHost> upscaleHostsMap) {
LOGGER.debug("Creating ApiHostRefList from upscaled hosts.");
ApiHostRefList body = new ApiHostRefList();
upscaleHostsMap.forEach((hostname, host) -> Optional.ofNullable(upscaleInstancesMap.get(hostname)).ifPresent(instance -> {
ApiHostRef apiHostRef = new ApiHostRef().hostname(instance.getDiscoveryFQDN()).hostId(host.getHostId());
body.addItemsItem(apiHostRef);
}));
if (body.getItems() != null) {
LOGGER.debug("Created ApiHostRefList from upscaled hosts. Host count: [{}]", body.getItems().size());
} else {
LOGGER.debug("Created ApiHostRefList is empty.");
}
return body;
}
use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method upscaleCluster.
@Test
void upscaleCluster() throws Exception {
setUpListClusterHosts();
setUpReadHosts(true);
setUpDeployClientConfigPolling(success);
setUpBatchSuccess();
BigDecimal applyHostTemplateCommandId = new BigDecimal(200);
when(hostTemplatesResourceApi.applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), any(ApiHostRefList.class))).thenReturn(new ApiCommand().id(applyHostTemplateCommandId));
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(eq(apiClientMock))).thenReturn(hostTemplatesResourceApi);
when(clouderaManagerPollingServiceProvider.startPollingCmApplyHostTemplate(eq(stack), eq(apiClientMock), eq(applyHostTemplateCommandId))).thenReturn(success);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName(HOST_GROUP_NAME);
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setDiscoveryFQDN("upscaled");
instanceMetaData.setRackId("/upscaledRack");
instanceMetaData.setInstanceGroup(instanceGroup);
List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
List<String> result = underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
assertThat(result).isEqualTo(List.of("upscaled"));
ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
verify(clouderaManagerRoleRefreshService).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
assertEquals(1, bodyCatcher.getValue().getItems().size());
assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
ArgumentCaptor<ApiHostRefList> applyTemplateBodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
verify(hostTemplatesResourceApi, times(1)).applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), applyTemplateBodyCatcher.capture());
assertEquals(1, applyTemplateBodyCatcher.getValue().getItems().size());
assertEquals("upscaled", applyTemplateBodyCatcher.getValue().getItems().get(0).getHostname());
ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
verify(batchResourceApi).execute(batchRequestCaptor.capture());
verifyRackIdBatch(batchRequestCaptor.getValue(), "upscaledId", "/upscaledRack");
}
use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method upscaleClusterTerminationOnDeployConfig.
@Test
void upscaleClusterTerminationOnDeployConfig() throws Exception {
setUpListClusterHosts();
setUpReadHosts(true);
setUpDeployClientConfigPolling(exit);
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setDiscoveryFQDN("upscaled");
List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
String exceptionMessage = "Cluster was terminated while waiting for config deploy";
doThrow(new CancellationException(exceptionMessage)).when(pollingResultErrorHandler).handlePollingResult(eq(exit), any(), any());
CancellationException exception = assertThrows(CancellationException.class, () -> underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList))));
assertEquals(exceptionMessage, exception.getMessage());
ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
assertEquals(1, bodyCatcher.getValue().getItems().size());
assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
verify(clouderaManagerRoleRefreshService, never()).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
verify(clouderaManagerApiFactory, never()).getBatchResourceApi(any(ApiClient.class));
}
use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method upscaleClusterTimeoutOnDeployConfig.
@Test
void upscaleClusterTimeoutOnDeployConfig() throws Exception {
setUpListClusterHosts();
setUpReadHosts(true);
setUpDeployClientConfigPolling(timeout);
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setDiscoveryFQDN("upscaled");
List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
String exceptionMessage = "Timeout while Cloudera Manager was config deploying services.";
doThrow(new CloudbreakException(exceptionMessage)).when(pollingResultErrorHandler).handlePollingResult(eq(timeout), any(), any());
CloudbreakException exception = assertThrows(CloudbreakException.class, () -> underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList))));
assertEquals(exceptionMessage, exception.getMessage());
ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
assertEquals(1, bodyCatcher.getValue().getItems().size());
assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
verify(clouderaManagerRoleRefreshService, never()).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
verify(clouderaManagerApiFactory, never()).getBatchResourceApi(any(ApiClient.class));
}
use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method upscaleClusterTestWhenRackIdUpdatedForOutdatedClusterHostAndUpscaledHost.
@Test
void upscaleClusterTestWhenRackIdUpdatedForOutdatedClusterHostAndUpscaledHost() throws Exception {
setUpListClusterHosts();
setUpReadHosts(true);
setUpDeployClientConfigPolling(success);
setUpBatchSuccess();
BigDecimal applyHostTemplateCommandId = new BigDecimal(200);
when(hostTemplatesResourceApi.applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), any(ApiHostRefList.class))).thenReturn(new ApiCommand().id(applyHostTemplateCommandId));
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(eq(apiClientMock))).thenReturn(hostTemplatesResourceApi);
when(clouderaManagerPollingServiceProvider.startPollingCmApplyHostTemplate(eq(stack), eq(apiClientMock), eq(applyHostTemplateCommandId))).thenReturn(success);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName(HOST_GROUP_NAME);
InstanceMetaData instanceMetaDataOriginal = new InstanceMetaData();
instanceMetaDataOriginal.setDiscoveryFQDN("original");
instanceMetaDataOriginal.setRackId("/originalRack");
instanceMetaDataOriginal.setInstanceGroup(instanceGroup);
InstanceMetaData instanceMetaDataUpscaled = new InstanceMetaData();
instanceMetaDataUpscaled.setDiscoveryFQDN("upscaled");
instanceMetaDataUpscaled.setRackId("/upscaledRack");
instanceMetaDataUpscaled.setInstanceGroup(instanceGroup);
List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaDataOriginal, instanceMetaDataUpscaled);
List<String> result = underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
assertThat(result).containsOnly("original", "upscaled");
ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
verify(clouderaManagerRoleRefreshService).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
assertEquals(1, bodyCatcher.getValue().getItems().size());
assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
ArgumentCaptor<ApiHostRefList> applyTemplateBodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
verify(hostTemplatesResourceApi, times(1)).applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), applyTemplateBodyCatcher.capture());
assertEquals(1, applyTemplateBodyCatcher.getValue().getItems().size());
assertEquals("upscaled", applyTemplateBodyCatcher.getValue().getItems().get(0).getHostname());
ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
verify(batchResourceApi, times(2)).execute(batchRequestCaptor.capture());
List<ApiBatchRequest> batchRequests = batchRequestCaptor.getAllValues();
assertThat(batchRequests).hasSize(2);
verifyRackIdBatch(batchRequests.get(0), "originalId", "/originalRack");
verifyRackIdBatch(batchRequests.get(1), "upscaledId", "/upscaledRack");
}
Aggregations