Search in sources :

Example 1 with BatchResourceApi

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);
}
Also used : BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest)

Example 2 with BatchResourceApi

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");
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) List(java.util.List) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with BatchResourceApi

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");
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) List(java.util.List) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BatchResourceApi

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: ");
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with BatchResourceApi

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");
}
Also used : BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiException(com.cloudera.api.swagger.client.ApiException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)7 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)6 ApiBatchRequest (com.cloudera.api.swagger.model.ApiBatchRequest)6 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ApiUser2List (com.cloudera.api.swagger.model.ApiUser2List)3 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)3 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 ApiException (com.cloudera.api.swagger.client.ApiException)2 ApiBatchResponse (com.cloudera.api.swagger.model.ApiBatchResponse)2 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1