Search in sources :

Example 1 with ApiBatchResponse

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

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

the class ClouderaManagerSecurityService method processHostCertsBatchResponse.

private void processHostCertsBatchResponse(ApiClient client, ApiBatchResponse apiBatchResponse) {
    if (apiBatchResponse != null && apiBatchResponse.getSuccess() != null && apiBatchResponse.getItems() != null && apiBatchResponse.getSuccess()) {
        List<BigDecimal> ids = apiBatchResponse.getItems().stream().map(bre -> new Json((String) bre.getResponse()).getSilent(ApiCommand.class).getId()).collect(Collectors.toList());
        ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCommandList(stack, client, ids, "Rotate host certificates");
        if (pollingResult.isExited()) {
            throw new CancellationException("Cluster was terminated during rotation of host certificates");
        } else if (pollingResult.isTimeout()) {
            throw new ClouderaManagerOperationFailedException("Timeout while Cloudera Manager rotates the host certificates.");
        }
    } else {
        throw new ClouderaManagerOperationFailedException("Host certificates rotation batch operation failed: " + apiBatchResponse);
    }
}
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) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Json(com.sequenceiq.cloudbreak.common.json.Json) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) BigDecimal(java.math.BigDecimal)

Example 3 with ApiBatchResponse

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

the class ClouderaManagerModificationServiceTest method setUpBatchSuccess.

private void setUpBatchSuccess() throws ApiException {
    setUpBatchWithResponseAnswer(invocation -> {
        ApiBatchRequest batchRequest = invocation.getArgument(0, ApiBatchRequest.class);
        int responseItemCount = batchRequest.getItems().size();
        ApiBatchResponse batchResponse = new ApiBatchResponse().success(true).items(new ArrayList<>());
        for (int i = 0; i < responseItemCount; i++) {
            batchResponse.addItemsItem(new ApiBatchResponseElement());
        }
        return batchResponse;
    });
}
Also used : ApiBatchResponseElement(com.cloudera.api.swagger.model.ApiBatchResponseElement) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest)

Example 4 with ApiBatchResponse

use of com.cloudera.api.swagger.model.ApiBatchResponse 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)4 ApiBatchResponse (com.cloudera.api.swagger.model.ApiBatchResponse)4 BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)3 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)2 ApiClient (com.cloudera.api.swagger.client.ApiClient)2 ApiException (com.cloudera.api.swagger.client.ApiException)2 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)2 ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)2 ToolsResourceApi (com.cloudera.api.swagger.ToolsResourceApi)1 UsersResourceApi (com.cloudera.api.swagger.UsersResourceApi)1 ApiAuthRoleRef (com.cloudera.api.swagger.model.ApiAuthRoleRef)1 ApiBatchRequestElement (com.cloudera.api.swagger.model.ApiBatchRequestElement)1 ApiBatchResponseElement (com.cloudera.api.swagger.model.ApiBatchResponseElement)1 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)1 ApiGenerateHostCertsArguments (com.cloudera.api.swagger.model.ApiGenerateHostCertsArguments)1 ApiUser2 (com.cloudera.api.swagger.model.ApiUser2)1 ApiUser2List (com.cloudera.api.swagger.model.ApiUser2List)1 HTTPMethod (com.cloudera.api.swagger.model.HTTPMethod)1