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));
}
}
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());
}
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));
}
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();
}
Aggregations