Search in sources :

Example 31 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class AzureStorageAccountBuilderService method buildStorageAccount.

public StorageAccount buildStorageAccount(AzureClient client, StorageAccountParameters storageAccountParameters) {
    String resourceGroupName = storageAccountParameters.getResourceGroupName();
    String storageAccountName = storageAccountParameters.getStorageAccountName();
    try {
        String template = azureStorageAccountTemplateBuilder.build(storageAccountParameters);
        ResourceStatus templateDeploymentStatus = client.getTemplateDeploymentStatus(resourceGroupName, storageAccountName);
        LOGGER.debug("Template deployment status retrieved: {}.", templateDeploymentStatus);
        if (templateDeploymentStatus.isPermanent()) {
            LOGGER.debug("Creating template deployment.");
            String parameters = new Json(Map.of()).getValue();
            Deployment templateDeployment = client.createTemplateDeployment(resourceGroupName, storageAccountName, template, parameters);
            LOGGER.debug("Created template deployment for storage account: {}", templateDeployment.exportTemplate().template());
        }
        return client.getStorageAccountByGroup(resourceGroupName, storageAccountName);
    } catch (CloudException e) {
        throw azureUtils.convertToCloudConnectorException(e, "Storage account creation");
    } catch (Exception e) {
        String message = String.format("Could not create storage account %s in resource group %s%s", storageAccountName, resourceGroupName, getDeniedPolicyReasonIfApplicable(e));
        LOGGER.warn(message, e);
        throw new CloudConnectorException(message);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) Deployment(com.microsoft.azure.management.resources.Deployment) Json(com.sequenceiq.cloudbreak.common.json.Json) CloudException(com.microsoft.azure.CloudException) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudException(com.microsoft.azure.CloudException)

Example 32 with Json

use of com.sequenceiq.cloudbreak.common.json.Json 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 33 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class ResourceAttributeUtil method getTypedAttributes.

public <T> Optional<T> getTypedAttributes(Resource resource) {
    Json attributes = resource.getAttributes();
    Optional<T> ret = Optional.empty();
    try {
        if (Objects.nonNull(attributes.getValue())) {
            Map<String, Object> map = attributes.get(Map.class);
            String clss = map.getOrDefault(CloudResource.ATTRIBUTE_TYPE, VolumeSetAttributes.class.getCanonicalName()).toString();
            Class<T> attributeType = (Class<T>) Class.forName(clss);
            ret = Optional.ofNullable(attributes.get(attributeType));
        }
    } catch (IOException e) {
        throw new CloudbreakServiceException("Failed to parse attributes to type: " + attributes, e);
    } catch (ClassNotFoundException e) {
        LOGGER.debug("Cannot parse class: {}", e.getMessage());
    }
    return ret;
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException)

Example 34 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class JaxRSUtil method transformErrorMessage.

private static String transformErrorMessage(String textResponse) {
    try {
        Json jsonResponse = new Json(textResponse);
        Map<String, Object> mapResponse = jsonResponse.getMap();
        Integer status = (Integer) mapResponse.get("status");
        String code = (String) mapResponse.get("code");
        if (status != null && StringUtils.isNotEmpty(code)) {
            return ERROR_MESSAGE_MAP.getOrDefault(generateErrorMessageMapKey(status, code), textResponse);
        } else {
            return textResponse;
        }
    } catch (RuntimeException ex) {
        return textResponse;
    }
}
Also used : Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 35 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class ClusterV4RequestToClusterConverterTest method testConvertClouderaManagerRequestWithNullRepo.

@Test
public void testConvertClouderaManagerRequestWithNullRepo() {
    ClusterV4Request request = new ClusterV4Request();
    request.setBlueprintName(BLUEPRINT);
    blueprint.setStackType(StackType.CDH.name());
    when(blueprintService.getByNameForWorkspaceAndLoadDefaultsIfNecessary(eq(BLUEPRINT), any())).thenReturn(blueprint);
    ClouderaManagerV4Request cm = new ClouderaManagerV4Request();
    ClouderaManagerProductV4Request cdp = new ClouderaManagerProductV4Request();
    cdp.setName("cdp");
    cdp.setParcel("cdp.parcel");
    cdp.setVersion("cdp.version");
    cdp.setCsd(List.of("cdp.csd"));
    ClouderaManagerProductV4Request cdf = new ClouderaManagerProductV4Request();
    cdf.setName("cdf");
    cdf.setParcel("cdf.parcel");
    cdf.setVersion("cdf.version");
    cdf.setCsd(List.of("cdf.csd"));
    List<ClouderaManagerProductV4Request> products = List.of(cdp, cdf);
    cm.setProducts(products);
    request.setCm(cm);
    Cluster cluster = underTest.convert(request);
    assertFalse(cluster.getComponents().isEmpty());
    assertEquals(2, cluster.getComponents().size());
    assertAll(cluster.getComponents().stream().map(component -> () -> assertEquals(ComponentType.CDH_PRODUCT_DETAILS, component.getComponentType())));
    List<Json> cdps = cluster.getComponents().stream().map(ClusterComponent::getAttributes).filter(attr -> attr.getValue().contains("cdp")).collect(Collectors.toList());
    Json cdpJson = new Json(cdp);
    assertAll(() -> assertEquals(1, cdps.size()), () -> assertEquals(cdpJson, cdps.iterator().next()));
    List<Json> cdfs = cluster.getComponents().stream().map(ClusterComponent::getAttributes).filter(attr -> attr.getValue().contains("cdf")).collect(Collectors.toList());
    Json cdfJson = new Json(cdf);
    assertAll(() -> assertEquals(1, cdfs.size()), () -> assertEquals(cdfJson, cdfs.iterator().next()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) GatewayConvertUtil(com.sequenceiq.cloudbreak.converter.util.GatewayConvertUtil) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) CloudStorageConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.CloudStorageConverter) GatewayV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Spy(org.mockito.Spy) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudStorageBase(com.sequenceiq.common.api.cloudstorage.CloudStorageBase) Set(java.util.Set) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) StackType(com.sequenceiq.cloudbreak.cloud.model.component.StackType) Collectors(java.util.stream.Collectors) GatewayV4RequestToGatewayConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.gateway.GatewayV4RequestToGatewayConverter) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) Matchers.is(org.hamcrest.Matchers.is) CloudStorageValidationUtil(com.sequenceiq.cloudbreak.converter.util.CloudStorageValidationUtil) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) IdBrokerConverterUtil(com.sequenceiq.cloudbreak.converter.IdBrokerConverterUtil) ClouderaManagerProductV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.product.ClouderaManagerProductV4Request) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) InjectMocks(org.mockito.InjectMocks) ClouderaManagerRepositoryV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.repository.ClouderaManagerRepositoryV4Request) Collections.emptySet(java.util.Collections.emptySet) ClusterV4RequestToClusterConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.ClusterV4RequestToClusterConverter) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Mockito.verify(org.mockito.Mockito.verify) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Mockito(org.mockito.Mockito) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) ClouderaManagerV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerV4Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) ClouderaManagerProductV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.product.ClouderaManagerProductV4Request) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Json(com.sequenceiq.cloudbreak.common.json.Json) ClouderaManagerV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerV4Request) Test(org.junit.jupiter.api.Test)

Aggregations

Json (com.sequenceiq.cloudbreak.common.json.Json)266 Test (org.junit.jupiter.api.Test)95 HashMap (java.util.HashMap)49 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)31 Template (com.sequenceiq.freeipa.entity.Template)26 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)25 List (java.util.List)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)23 Map (java.util.Map)22 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)21 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)21 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)20 IOException (java.io.IOException)20 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)16 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)14