Search in sources :

Example 11 with ApiBatchRequest

use of com.cloudera.api.swagger.model.ApiBatchRequest 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 12 with ApiBatchRequest

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

the class ClouderaManagerSecurityService method createHostCertsBatchRequest.

private ApiBatchRequest createHostCertsBatchRequest(ApiHostList hostList, String sshUser, KeyPair sshKeyPair, String subAltName) {
    ApiGenerateHostCertsArguments apiGenerateHostCertsArguments = createApiGenerateHostCertsArguments(sshUser, sshKeyPair, subAltName);
    List<ApiBatchRequestElement> batchRequestElements = hostList.getItems().stream().filter(host -> host.getClusterRef() != null).map(host -> new ApiBatchRequestElement().method(HTTPMethod.POST).url(ClouderaManagerApiClientProvider.API_V_31 + "/hosts/" + URLUtils.encodeString(host.getHostId()) + "/commands/generateHostCerts").body(apiGenerateHostCertsArguments).acceptType("application/json").contentType("application/json")).collect(Collectors.toList());
    return new ApiBatchRequest().items(batchRequestElements);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) KeyPair(java.security.KeyPair) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) StringUtils(org.apache.commons.lang3.StringUtils) ApiAuthRoleRef(com.cloudera.api.swagger.model.ApiAuthRoleRef) Scope(org.springframework.context.annotation.Scope) ApiException(com.cloudera.api.swagger.client.ApiException) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) Inject(javax.inject.Inject) BigDecimal(java.math.BigDecimal) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) UsersResourceApi(com.cloudera.api.swagger.UsersResourceApi) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) Service(org.springframework.stereotype.Service) LdapView(com.sequenceiq.cloudbreak.dto.LdapView) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) Retryable(org.springframework.retry.annotation.Retryable) Logger(org.slf4j.Logger) VirtualGroupRequest(com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) URLUtils(com.sequenceiq.cloudbreak.util.URLUtils) ClusterSecurityService(com.sequenceiq.cloudbreak.cluster.api.ClusterSecurityService) ApiGenerateHostCertsArguments(com.cloudera.api.swagger.model.ApiGenerateHostCertsArguments) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) ApiUser2(com.cloudera.api.swagger.model.ApiUser2) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) HTTPMethod(com.cloudera.api.swagger.model.HTTPMethod) PkiUtil(com.sequenceiq.cloudbreak.certificate.PkiUtil) DatalakeDto(com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiGenerateHostCertsArguments(com.cloudera.api.swagger.model.ApiGenerateHostCertsArguments) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest)

Example 13 with ApiBatchRequest

use of com.cloudera.api.swagger.model.ApiBatchRequest 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

ApiBatchRequest (com.cloudera.api.swagger.model.ApiBatchRequest)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)7 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)6 ApiClient (com.cloudera.api.swagger.client.ApiClient)6 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)6 Test (org.junit.jupiter.api.Test)6 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)5 ApiHostRefList (com.cloudera.api.swagger.model.ApiHostRefList)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)5 ApiBatchResponse (com.cloudera.api.swagger.model.ApiBatchResponse)4 ApiUser2List (com.cloudera.api.swagger.model.ApiUser2List)4 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)4 BigDecimal (java.math.BigDecimal)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3