Search in sources :

Example 1 with AwsParametersDto

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

the class EnvironmentDetailsToCDPEnvironmentDetailsConverter method convertAwsDetails.

private UsageProto.CDPEnvironmentAwsDetails convertAwsDetails(ParametersDto parametersDto) {
    UsageProto.CDPEnvironmentAwsDetails.Builder builder = UsageProto.CDPEnvironmentAwsDetails.newBuilder();
    if (parametersDto != null) {
        AwsParametersDto awsParametersDto = parametersDto.getAwsParametersDto();
        if (awsParametersDto != null) {
            Optional<String> encryptionKeyArn = Optional.of(awsParametersDto).map(AwsParametersDto::getAwsDiskEncryptionParametersDto).map(AwsDiskEncryptionParametersDto::getEncryptionKeyArn);
            builder.setResourceEncryptionEnabled(encryptionKeyArn.isPresent());
        }
    }
    return builder.build();
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)

Example 2 with AwsParametersDto

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

the class AwsParameterValidator method validate.

@Override
public ValidationResult validate(EnvironmentValidationDto environmentValidationDto, ParametersDto parametersDto, ValidationResultBuilder validationResultBuilder) {
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    LOGGER.debug("ParametersDto: {}", parametersDto);
    AwsParametersDto awsParametersDto = parametersDto.getAwsParametersDto();
    if (Objects.isNull(awsParametersDto)) {
        LOGGER.debug("No aws parameters defined.");
        return validationResultBuilder.build();
    }
    // This flag is introduced to skip S3Guard Table validation in case of UpdateAwsDiskEncryptionParameters call.
    boolean validateOnlyAwsEncryptionParameters = validateOnlyAwsEncryptionParameters(environmentDto);
    if (Objects.isNull(awsParametersDto.getAwsDiskEncryptionParametersDto()) && !validateOnlyAwsEncryptionParameters) {
        if (StringUtils.isNotBlank(awsParametersDto.getS3GuardTableName())) {
            LOGGER.debug("S3Guard table name defined: {}", awsParametersDto.getS3GuardTableName());
            boolean tableAlreadyAttached = isTableAlreadyAttached(environmentDto, awsParametersDto);
            if (tableAlreadyAttached) {
                validationResultBuilder.error(String.format("S3Guard Dynamo table '%s' is already attached to another active environment. " + "Please select another unattached table or specify a non-existing name to create it. " + "Refer to Cloudera documentation at %s for the required setup.", awsParametersDto.getS3GuardTableName(), DocumentationLinkProvider.awsDynamoDbSetupLink()));
            } else {
                determineAwsParameters(environmentDto, parametersDto);
            }
        }
    }
    AwsDiskEncryptionParametersDto awsDiskEncryptionParametersDto = awsParametersDto.getAwsDiskEncryptionParametersDto();
    if (awsDiskEncryptionParametersDto != null) {
        ValidationResult validationResult = validateEntitlement(validationResultBuilder, awsDiskEncryptionParametersDto, environmentDto.getAccountId());
        if (validationResult.hasError()) {
            return validationResult;
        }
    }
    if (awsParametersDto.getFreeIpaSpotPercentage() < PERCENTAGE_MIN || awsParametersDto.getFreeIpaSpotPercentage() > PERCENTAGE_MAX) {
        validationResultBuilder.error(String.format("FreeIpa spot percentage must be between %d and %d.", PERCENTAGE_MIN, PERCENTAGE_MAX));
    }
    return validationResultBuilder.build();
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 3 with AwsParametersDto

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

the class AwsParameterValidatorTest method validateAndDetermineAwsParametersUseExisting.

@ParameterizedTest
@EnumSource(value = S3GuardTableCreation.class, names = { "USE_EXISTING", "CREATE_NEW" })
void validateAndDetermineAwsParametersUseExisting(S3GuardTableCreation creation) {
    AwsParametersDto awsParameters = AwsParametersDto.builder().withDynamoDbTableName("tablename").build();
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(awsParameters).build();
    when(parametersService.isS3GuardTableUsed(any(), any(), any(), any())).thenReturn(false);
    when(noSqlTableCreationModeDeterminerService.determineCreationMode(any(), any())).thenReturn(creation);
    ValidationResult validationResult = underTest.validate(environmentValidationDto, parametersDto, ValidationResult.builder());
    assertFalse(validationResult.hasError());
    verify(noSqlTableCreationModeDeterminerService).determineCreationMode(any(), any());
    assertEquals(creation, awsParameters.getDynamoDbTableCreation());
    verify(parametersService, times(1)).saveParameters(ENV_ID, parametersDto);
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with AwsParametersDto

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

the class AwsParameterValidatorTest method validateNoS3GuardCheckOnUpdateAwsDiskEncryptionParameters.

@Test
void validateNoS3GuardCheckOnUpdateAwsDiskEncryptionParameters() {
    AwsParametersDto awsParameters = AwsParametersDto.builder().withDynamoDbTableName("tablename").build();
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(awsParameters).build();
    EnvironmentDto environmentDto = new AwsParameterValidatorTest.EnvironmentDtoBuilder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("tablename").build()).build();
    environmentValidationDto.setEnvironmentDto(environmentDto);
    ValidationResult validationResult = underTest.validate(environmentValidationDto, parametersDto, ValidationResult.builder());
    assertFalse(validationResult.hasError());
    verify(parametersService, never()).isS3GuardTableUsed(any(), any(), any(), any());
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with AwsParametersDto

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

the class AwsParameterValidatorTest method validateS3GuardCheckWhenAWSDiskEncryptionParametersAlreadyPresent.

@Test
void validateS3GuardCheckWhenAWSDiskEncryptionParametersAlreadyPresent() {
    AwsParametersDto awsParameters = AwsParametersDto.builder().withDynamoDbTableName("tablename").build();
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(awsParameters).build();
    EnvironmentDto environmentDto = new AwsParameterValidatorTest.EnvironmentDtoBuilder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummy-key-arn").build()).build()).build();
    environmentValidationDto.setEnvironmentDto(environmentDto);
    when(parametersService.isS3GuardTableUsed(any(), any(), any(), any())).thenReturn(true);
    ValidationResult validationResult = underTest.validate(environmentValidationDto, parametersDto, ValidationResult.builder());
    assertTrue(validationResult.hasError());
    assertEquals(1L, validationResult.getErrors().size());
    assertEquals("S3Guard Dynamo table 'tablename' is already attached to another active environment. " + "Please select another unattached table or specify a non-existing name to create it. Refer to " + "Cloudera documentation at https://docs.cloudera.com/cdp/latest/requirements-aws/topics/mc-aws-req-dynamodb.html " + "for the required setup.", validationResult.getErrors().get(0));
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)9 AwsDiskEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)8 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)7 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 Test (org.junit.jupiter.api.Test)3 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudEncryptionKeys (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1