Search in sources :

Example 1 with ApiBatchRequestElement

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

the class ClouderaManagerSecurityServiceTest method verifyBatchRequest.

private void verifyBatchRequest(ApiBatchRequest batchRequest, String subAltName, String... urlsExpected) {
    assertThat(batchRequest).isNotNull();
    List<ApiBatchRequestElement> batchRequestElements = batchRequest.getItems();
    assertThat(batchRequestElements).isNotNull();
    if (urlsExpected == null) {
        assertThat(batchRequestElements).isEmpty();
    } else {
        assertThat(batchRequestElements).hasSize(urlsExpected.length);
        for (int i = 0; i < urlsExpected.length; i++) {
            ApiBatchRequestElement batchRequestElement = batchRequestElements.get(i);
            assertThat(batchRequestElement).isNotNull();
            assertThat(batchRequestElement.getUrl()).isEqualTo(urlsExpected[i]);
            ApiGenerateHostCertsArguments apiGenerateHostCertsArguments = (ApiGenerateHostCertsArguments) batchRequestElement.getBody();
            if (subAltName == null) {
                assertNull(apiGenerateHostCertsArguments.getSubjectAltName());
            } else {
                assertThat(apiGenerateHostCertsArguments.getSubjectAltName().get(0)).isEqualTo(subAltName);
            }
        }
    }
}
Also used : ApiGenerateHostCertsArguments(com.cloudera.api.swagger.model.ApiGenerateHostCertsArguments) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement)

Example 2 with ApiBatchRequestElement

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

the class ClouderaManagerModificationServiceTest method verifyRackIdBatch.

private void verifyRackIdBatch(ApiBatchRequest batchRequest, String hostIdExpected, String rackIdExpected) {
    assertThat(batchRequest).isNotNull();
    List<ApiBatchRequestElement> batchRequestElements = batchRequest.getItems();
    assertThat(batchRequestElements).isNotNull();
    assertThat(batchRequestElements).hasSize(1);
    ApiBatchRequestElement batchRequestElement = batchRequestElements.get(0);
    assertThat(batchRequestElement.getMethod()).isEqualTo(HTTPMethod.PUT);
    assertThat(batchRequestElement.getUrl()).isEqualTo("/api/v31/hosts/" + hostIdExpected);
    assertThat(batchRequestElement.getAcceptType()).isEqualTo("application/json");
    assertThat(batchRequestElement.getContentType()).isEqualTo("application/json");
    assertThat(batchRequestElement.getBody()).isInstanceOf(ApiHost.class);
    ApiHost host = (ApiHost) batchRequestElement.getBody();
    assertThat(host.getRackId()).isEqualTo(rackIdExpected);
}
Also used : ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 3 with ApiBatchRequestElement

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

Aggregations

ApiBatchRequestElement (com.cloudera.api.swagger.model.ApiBatchRequestElement)3 ApiGenerateHostCertsArguments (com.cloudera.api.swagger.model.ApiGenerateHostCertsArguments)2 BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)1 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)1 ToolsResourceApi (com.cloudera.api.swagger.ToolsResourceApi)1 UsersResourceApi (com.cloudera.api.swagger.UsersResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiException (com.cloudera.api.swagger.client.ApiException)1 ApiAuthRoleRef (com.cloudera.api.swagger.model.ApiAuthRoleRef)1 ApiBatchRequest (com.cloudera.api.swagger.model.ApiBatchRequest)1 ApiBatchResponse (com.cloudera.api.swagger.model.ApiBatchResponse)1 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)1 ApiHost (com.cloudera.api.swagger.model.ApiHost)1 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)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 VirtualGroupRequest (com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest)1 PkiUtil (com.sequenceiq.cloudbreak.certificate.PkiUtil)1 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)1