use of com.cloudera.api.swagger.BatchResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method updateHostsWithRackIdUsingBatchCall.
private void updateHostsWithRackIdUsingBatchCall(List<ApiBatchRequestElement> batchRequestElements) throws ApiException {
BatchResourceApi batchResourceApi = clouderaManagerApiFactory.getBatchResourceApi(apiClient);
ApiBatchRequest batchRequest = new ApiBatchRequest().items(batchRequestElements);
ApiBatchResponse batchResponse = batchResourceApi.execute(batchRequest);
validateBatchResponse(batchResponse);
}
use of com.cloudera.api.swagger.BatchResourceApi 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.BatchResourceApi 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.BatchResourceApi 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.BatchResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenCMApiCallFailed.
@Test
public void testRotateHostCertificatesWhenCMApiCallFailed() 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);
when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenThrow(new ApiException("Serious problem"));
// WHEN
CloudbreakException exception = assertThrows(CloudbreakException.class, () -> underTest.rotateHostCertificates(null, null, null));
// THEN exception
assertThat(exception).hasMessage("Can't rotate the host certificates due to: Serious problem");
}
Aggregations