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