use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificates.
@ParameterizedTest(name = "{0}")
@MethodSource("testRotateHostCertificatesWhenBatchExecuteSucceededDataProvider")
public void testRotateHostCertificates(String testCaseName, String subAltName) 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().success().build());
// WHEN
underTest.rotateHostCertificates(null, null, subAltName);
// THEN no exception
verifyBatchRequest(batchRequestArgumentCaptor.getValue(), subAltName, "/api/v31/hosts/host-1/commands/generateHostCerts", "/api/v31/hosts/host%40company.com%202/commands/generateHostCerts");
}
use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenPollingCancelled.
@Test
public void testRotateHostCertificatesWhenPollingCancelled() 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().exit().build());
// WHEN
CancellationException exception = assertThrows(CancellationException.class, () -> underTest.rotateHostCertificates(null, null, null));
// THEN exception
assertThat(exception).hasMessage("Cluster was terminated during rotation of host certificates");
}
use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenBatchExecuteFailed.
@ParameterizedTest(name = "{0}")
@MethodSource("testRotateHostCertificatesWhenBatchExecuteFailedDataProvider")
public void testRotateHostCertificatesWhenBatchExecuteFailed(String testCaseName, Function<ApiHostList, ApiBatchResponse> batchResponseFactory) 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(batchResponseFactory.apply(hostList));
// WHEN
ClouderaManagerOperationFailedException exception = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.rotateHostCertificates(null, null, null));
// THEN exception
assertThat(exception).hasMessageStartingWith("Host certificates rotation batch operation failed: ");
}
use of com.cloudera.api.swagger.model.ApiBatchRequest 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");
}
use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method upscaleClusterTestWhenRackIdNotUpdatedForClusterHostButSetForUpscaledHost.
@Test
void upscaleClusterTestWhenRackIdNotUpdatedForClusterHostButSetForUpscaledHost() throws Exception {
setUpListClusterHosts();
setUpReadHosts(true, "/originalRack");
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("upscaled", "original");
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");
}
Aggregations