Search in sources :

Example 6 with AwsParametersDto

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

the class AwsParameterValidatorTest method validateFreeIpaSpotPercentage.

@ParameterizedTest(name = "FreeIpa Spot percentage {0} is validated as {1}")
@MethodSource("freeIpaSpotPercentageParameters")
void validateFreeIpaSpotPercentage(int percentage, boolean hasError) {
    AwsParametersDto awsParameters = AwsParametersDto.builder().withFreeIpaSpotPercentage(percentage).build();
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(awsParameters).build();
    ValidationResult validationResult = underTest.validate(environmentValidationDto, parametersDto, ValidationResult.builder());
    assertEquals(hasError, validationResult.hasError());
    if (hasError) {
        assertEquals("FreeIpa spot percentage must be between 0 and 100.", validationResult.getErrors().get(0));
    }
}
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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with AwsParametersDto

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

the class AwsParameterValidatorTest method validateAndDetermineAwsParametersAttached.

@Test
void validateAndDetermineAwsParametersAttached() {
    AwsParametersDto awsParameters = AwsParametersDto.builder().withDynamoDbTableName("tablename").build();
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(awsParameters).build();
    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));
    verify(noSqlTableCreationModeDeterminerService, never()).determineCreationMode(any(), any());
}
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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with AwsParametersDto

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

the class AwsEnvironmentParametersConverter method postConvert.

@Override
protected void postConvert(BaseParameters baseParameters, Environment environment, ParametersDto parametersDto) {
    super.postConvert(baseParameters, environment, parametersDto);
    AwsParameters awsParameters = (AwsParameters) baseParameters;
    Optional<AwsParametersDto> awsParametersDto = Optional.of(parametersDto).map(ParametersDto::getAwsParametersDto);
    awsParameters.setS3guardTableName(awsParametersDto.map(AwsParametersDto::getS3GuardTableName).orElse(null));
    awsParameters.setS3guardTableCreation(awsParametersDto.map(AwsParametersDto::getDynamoDbTableCreation).orElse(null));
    awsParameters.setFreeIpaSpotPercentage(awsParametersDto.map(AwsParametersDto::getFreeIpaSpotPercentage).orElse(0));
    awsParameters.setFreeIpaSpotMaxPrice(awsParametersDto.map(AwsParametersDto::getFreeIpaSpotMaxPrice).orElse(null));
    awsParameters.setEncryptionKeyArn(awsParametersDto.map(AwsParametersDto::getAwsDiskEncryptionParametersDto).map(AwsDiskEncryptionParametersDto::getEncryptionKeyArn).orElse(null));
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto)

Example 9 with AwsParametersDto

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

the class EncryptionKeyArnValidator method validate.

public ValidationResult validate(EnvironmentValidationDto environmentValidationDto) {
    String encryptionKeyArn = Optional.ofNullable(environmentValidationDto).map(EnvironmentValidationDto::getEnvironmentDto).map(environmentDto -> environmentDto.getParameters()).map(ParametersDto::getAwsParametersDto).map(AwsParametersDto::getAwsDiskEncryptionParametersDto).map(AwsDiskEncryptionParametersDto::getEncryptionKeyArn).orElse(null);
    ValidationResult.ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
    if (encryptionKeyArn == null || encryptionKeyArn.isEmpty()) {
        return validationResultBuilder.build();
    }
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(environmentDto.getCredential());
    ExtendedCloudCredential extendedCloudCredential = new ExtendedCloudCredential(cloudCredential, environmentDto.getCloudPlatform(), environmentDto.getDescription(), environmentDto.getCreator(), environmentDto.getAccountId(), entitlementService.getEntitlements(environmentDto.getAccountId()));
    Region region = region(environmentDto.getLocation().getName());
    CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(environmentDto.getCloudPlatform()), null);
    try {
        CloudEncryptionKeys encryptionKeys = retryService.testWith2SecDelayMax15Times(() -> cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().encryptionKeys(extendedCloudCredential, region, Collections.emptyMap()));
        if (encryptionKeys.getCloudEncryptionKeys().stream().map(CloudEncryptionKey::getName).noneMatch(s -> s.equals(encryptionKeyArn))) {
            validationResultBuilder.error("The provided encryption key does not exist in the given region's encryption key list for this credential.");
        }
    } catch (Exception e) {
        LOGGER.error("An unexpected error occurred while trying to fetch the KMS keys from AWS");
        throw e;
    }
    return validationResultBuilder.build();
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Region(com.sequenceiq.cloudbreak.cloud.model.Region) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)

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