Search in sources :

Example 1 with AzureParametersDto

use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.

the class EnvironmentResponseConverter method azureEnvParamsToAzureEnvironmentParams.

private AzureEnvironmentParameters azureEnvParamsToAzureEnvironmentParams(ParametersDto parameters) {
    AzureResourceGroupDto resourceGroupDto = Optional.ofNullable(parameters.getAzureParametersDto()).map(AzureParametersDto::getAzureResourceGroupDto).filter(rgDto -> Objects.nonNull(rgDto.getResourceGroupUsagePattern())).filter(rgDto -> Objects.nonNull(rgDto.getResourceGroupCreation())).orElse(null);
    AzureResourceEncryptionParametersDto resourceEncryptionParametersDto = Optional.ofNullable(parameters.getAzureParametersDto()).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).orElse(null);
    return AzureEnvironmentParameters.builder().withAzureResourceGroup(getIfNotNull(resourceGroupDto, this::azureParametersToAzureResourceGroup)).withResourceEncryptionParameters(getIfNotNull(resourceEncryptionParametersDto, this::azureParametersToAzureResourceEncryptionParameters)).build();
}
Also used : GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto) NullUtil.getIfNotNull(com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) ResourceGroupUsage(com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) LoggerFactory(org.slf4j.LoggerFactory) AzureResourceEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceEncryptionParameters) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AzureEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters) GcpResourceEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpResourceEncryptionParameters) SecurityAccessResponse(com.sequenceiq.environment.api.v1.environment.model.response.SecurityAccessResponse) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) AwsDiskEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsDiskEncryptionParameters) CredentialViewConverter(com.sequenceiq.environment.credential.v1.converter.CredentialViewConverter) ResourceGroupUsagePattern(com.sequenceiq.environment.parameter.dto.ResourceGroupUsagePattern) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) YarnEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.yarn.YarnEnvironmentParameters) ProxyConfigToProxyResponseConverter(com.sequenceiq.environment.proxy.v1.converter.ProxyConfigToProxyResponseConverter) Tunnel(com.sequenceiq.common.api.type.Tunnel) CredentialToCredentialV1ResponseConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCredentialV1ResponseConverter) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) SecurityGroupSeparator.getSecurityGroupIds(com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) NullUtil(com.sequenceiq.cloudbreak.util.NullUtil) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) LocationResponse(com.sequenceiq.environment.api.v1.environment.model.response.LocationResponse) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) EnvironmentAuthenticationResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentAuthenticationResponse) S3GuardRequestParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) LocationDto(com.sequenceiq.environment.environment.dto.LocationDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentTags(com.sequenceiq.environment.environment.domain.EnvironmentTags) Optional(java.util.Optional) EnvironmentViewDto(com.sequenceiq.environment.environment.dto.EnvironmentViewDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) EnvironmentDeletionType(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentDeletionType) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)

Example 2 with AzureParametersDto

use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.

the class ResourceEncryptionInitializationHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("Accepting ResourceEncryptionInitialization event");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            if (AZURE.name().equalsIgnoreCase(environmentDto.getCloudPlatform())) {
                String encryptionKeyUrl = Optional.ofNullable(environmentDto.getParameters()).map(ParametersDto::getAzureParametersDto).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null);
                String environmentName = environment.getName();
                if (StringUtils.isNotEmpty(encryptionKeyUrl)) {
                    if (environment.getStatus() != EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_INITIALIZED) {
                        initializeEncryptionResources(environmentDto, environment);
                    } else {
                        LOGGER.info("Initialization of encryption resources for environment \"{}\" has already been triggered, " + "continuing without new initialize trigger. Environment status: {}", environmentName, environment.getStatus());
                    }
                } else {
                    LOGGER.info("Environment \"{}\" has not requested for SSE with CMK.", environmentName);
                }
            }
        });
        EnvCreationEvent envCreationEvent = getEnvCreateEvent(environmentDto);
        eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.error("ResourceEncryptionInitialization failed with error.", e);
        EnvCreationFailureEvent failedEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), e, environmentDto.getResourceCrn());
        Event<EnvCreationFailureEvent> ev = new Event<>(environmentDtoEvent.getHeaders(), failedEvent);
        eventBus.notify(failedEvent.selector(), ev);
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Event(reactor.bus.Event) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 3 with AzureParametersDto

use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.

the class ResourceEncryptionDeleteHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    LOGGER.debug("Accepting ResourceEncryptionDelete event");
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            if (AZURE.name().equalsIgnoreCase(environmentDto.getCloudPlatform())) {
                String encryptionKeyUrl = Optional.ofNullable(environmentDto.getParameters()).map(ParametersDto::getAzureParametersDto).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null);
                if (StringUtils.isNotEmpty(encryptionKeyUrl) && (environment.getStatus() != EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_DELETED)) {
                    deleteEncryptionResources(environmentDto, environment);
                } else {
                    LOGGER.info("No encryption resources found to delete for environment \"{}\".", environment.getName());
                }
            }
        });
        eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.error("ResourceEncryptionDelete failed with error.", e);
        exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 4 with AzureParametersDto

use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.

the class AzureParameterValidator method validate.

@Override
public ValidationResult validate(EnvironmentValidationDto environmentValidationDto, ParametersDto parametersDto, ValidationResultBuilder validationResultBuilder) {
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    LOGGER.debug("ParametersDto: {}", parametersDto);
    AzureParametersDto azureParametersDto = parametersDto.azureParametersDto();
    if (Objects.isNull(azureParametersDto)) {
        return validationResultBuilder.build();
    }
    ValidationResult validationResult;
    AzureResourceEncryptionParametersDto azureResourceEncryptionParametersDto = azureParametersDto.getAzureResourceEncryptionParametersDto();
    if (azureResourceEncryptionParametersDto != null) {
        validationResult = validateEncryptionParameters(validationResultBuilder, azureParametersDto, environmentDto.getAccountId());
        if (validationResult.hasError()) {
            return validationResult;
        }
    }
    AzureResourceGroupDto azureResourceGroupDto = azureParametersDto.getAzureResourceGroupDto();
    if (Objects.isNull(azureResourceGroupDto)) {
        return validationResultBuilder.build();
    }
    validationResult = validateEntitlement(validationResultBuilder, azureResourceGroupDto, environmentDto.getAccountId());
    if (validationResult.hasError()) {
        return validationResult;
    }
    if (USE_MULTIPLE.equals(azureResourceGroupDto.getResourceGroupUsagePattern())) {
        return validateMultipleResourceGroupUsage(validationResultBuilder, azureResourceGroupDto);
    }
    if (USE_EXISTING.equals(azureResourceGroupDto.getResourceGroupCreation())) {
        return validateExistingResourceGroupUsage(validationResultBuilder, environmentDto, azureResourceGroupDto);
    }
    return validationResultBuilder.build();
}
Also used : AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)

Example 5 with AzureParametersDto

use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.

the class AzureEnvironmentParametersConverter method postConvert.

@Override
protected void postConvert(BaseParameters baseParameters, Environment environment, ParametersDto parametersDto) {
    super.postConvert(baseParameters, environment, parametersDto);
    AzureParameters azureParameters = (AzureParameters) baseParameters;
    Optional<AzureParametersDto> azureParametersDto = Optional.of(parametersDto).map(ParametersDto::getAzureParametersDto);
    azureParameters.setResourceGroupName(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getName).orElse(null));
    azureParameters.setResourceGroupCreation(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getResourceGroupCreation).orElse(null));
    azureParameters.setResourceGroupUsagePattern(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getResourceGroupUsagePattern).orElse(null));
    azureParameters.setEncryptionKeyUrl(azureParametersDto.map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null));
    azureParameters.setEncryptionKeyResourceGroupName(azureParametersDto.map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyResourceGroupName).orElse(null));
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)

Aggregations

AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)6 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)4 AzureResourceGroupDto (com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NullUtil (com.sequenceiq.cloudbreak.util.NullUtil)1 NullUtil.getIfNotNull (com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull)1 SecurityGroupSeparator.getSecurityGroupIds (com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 Tunnel (com.sequenceiq.common.api.type.Tunnel)1 AwsDiskEncryptionParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsDiskEncryptionParameters)1 AwsEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters)1 S3GuardRequestParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters)1 AzureEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters)1 AzureResourceEncryptionParameters (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceEncryptionParameters)1 AzureResourceGroup (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup)1 ResourceGroupUsage (com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage)1 GcpEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters)1