Search in sources :

Example 6 with BatchResourceApi

use of com.cloudera.api.swagger.BatchResourceApi 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.");
}
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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with BatchResourceApi

use of com.cloudera.api.swagger.BatchResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityService method rotateHostCertificates.

@Override
public void rotateHostCertificates(String sshUser, KeyPair sshKeyPair, String subAltName) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    String user = cluster.getCloudbreakAmbariUser();
    String password = cluster.getCloudbreakAmbariPassword();
    try {
        ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig);
        HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
        BatchResourceApi batchResourceApi = clouderaManagerApiFactory.getBatchResourceApi(client);
        ApiHostList hostList = hostsResourceApi.readHosts(null, null, "SUMMARY");
        ApiBatchRequest batchRequest = createHostCertsBatchRequest(hostList, sshUser, sshKeyPair, subAltName);
        ApiBatchResponse apiBatchResponse = batchResourceApi.execute(batchRequest);
        processHostCertsBatchResponse(client, apiBatchResponse);
    } catch (ApiException | ClouderaManagerClientInitException e) {
        LOGGER.warn("Can't rotate the host certificates", e);
        throw new CloudbreakException("Can't rotate the host certificates due to: " + e.getMessage());
    }
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ApiException(com.cloudera.api.swagger.client.ApiException)

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