Search in sources :

Example 1 with GcpParametersDto

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

the class EnvironmentDetailsToCDPEnvironmentDetailsConverter method convertGcpDetails.

private UsageProto.CDPEnvironmentGcpDetails convertGcpDetails(ParametersDto parametersDto) {
    UsageProto.CDPEnvironmentGcpDetails.Builder builder = UsageProto.CDPEnvironmentGcpDetails.newBuilder();
    if (parametersDto != null) {
        GcpParametersDto gcpParametersDto = parametersDto.getGcpParametersDto();
        if (gcpParametersDto != null) {
            Optional<String> encryptionKey = Optional.of(gcpParametersDto).map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey);
            builder.setResourceEncryptionEnabled(encryptionKey.isPresent());
        }
    }
    return builder.build();
}
Also used : GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto)

Example 2 with GcpParametersDto

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

the class GcpEnvironmentParametersConverter method postConvert.

@Override
protected void postConvert(BaseParameters baseParameters, Environment environment, ParametersDto parametersDto) {
    super.postConvert(baseParameters, environment, parametersDto);
    GcpParameters gcpParameters = (GcpParameters) baseParameters;
    Optional<GcpParametersDto> gcpParametersDto = Optional.of(parametersDto).map(ParametersDto::getGcpParametersDto);
    gcpParameters.setEncryptionKey(gcpParametersDto.map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey).orElse(null));
}
Also used : GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters)

Example 3 with GcpParametersDto

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

the class GcpParameterValidator method validate.

@Override
public ValidationResult validate(EnvironmentValidationDto environmentValidationDto, ParametersDto parametersDto, ValidationResultBuilder validationResultBuilder) {
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    LOGGER.debug("ParametersDto: {}", parametersDto);
    GcpParametersDto gcpParametersDto = parametersDto.getGcpParametersDto();
    if (Objects.isNull(gcpParametersDto)) {
        return validationResultBuilder.build();
    }
    ValidationResult validationResult;
    GcpResourceEncryptionParametersDto gcpResourceEncryptionParametersDto = gcpParametersDto.getGcpResourceEncryptionParametersDto();
    if (gcpResourceEncryptionParametersDto != null) {
        validationResult = validateGcpEncryptionParameters(validationResultBuilder, gcpParametersDto, environmentDto.getAccountId());
        if (validationResult.hasError()) {
            return validationResult;
        }
    }
    return validationResultBuilder.build();
}
Also used : GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 4 with GcpParametersDto

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

the class EnvironmentModificationService method editEnvironmentParameters.

private void editEnvironmentParameters(EnvironmentEditDto editDto, Environment environment) {
    ParametersDto parametersDto = editDto.getParameters();
    if (parametersDto != null) {
        Optional<BaseParameters> original = parametersService.findByEnvironment(environment.getId());
        if (original.isPresent()) {
            BaseParameters originalParameters = original.get();
            parametersDto.setId(originalParameters.getId());
            if (originalParameters instanceof AwsParameters) {
                AwsParameters awsOriginalParameters = (AwsParameters) originalParameters;
                parametersDto.getAwsParametersDto().setFreeIpaSpotPercentage(awsOriginalParameters.getFreeIpaSpotPercentage());
                validateAwsParameters(environment, parametersDto);
            }
        }
        if (parametersDto.getGcpParametersDto() != null) {
            String encryptionKey = Optional.of(parametersDto.getGcpParametersDto()).map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey).orElse(null);
            ValidationResult validationResult = environmentService.getValidatorService().validateEncryptionKey(encryptionKey, editDto.getAccountId());
            if (validationResult.hasError()) {
                throw new BadRequestException(validationResult.getFormattedErrors());
            }
        }
        BaseParameters parameters = parametersService.saveParameters(environment, parametersDto);
        if (parameters != null) {
            environment.setParameters(parameters);
        }
    }
}
Also used : GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) BadRequestException(javax.ws.rs.BadRequestException) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters)

Aggregations

GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)4 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)4 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)2 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)1 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)1 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)1 GcpParameters (com.sequenceiq.environment.parameters.dao.domain.GcpParameters)1 BadRequestException (javax.ws.rs.BadRequestException)1