use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters in project cloudbreak by hortonworks.
the class EnvironmentDtoConverter method getFreeIpaCreationDto.
private FreeIpaCreationDto getFreeIpaCreationDto(boolean createFreeIpa, Integer freeIpaInstanceCountByGroup, String freeIpaImageCatalog, String freeIpaImageId, boolean freeIpaEnableMultiAz, String cloudPlatform, BaseParameters parameters) {
FreeIpaCreationDto.Builder builder = FreeIpaCreationDto.builder().withCreate(createFreeIpa);
Optional.ofNullable(freeIpaInstanceCountByGroup).ifPresent(builder::withInstanceCountByGroup);
builder.withImageCatalog(freeIpaImageCatalog);
builder.withImageId(freeIpaImageId);
builder.withEnableMultiAz(freeIpaEnableMultiAz);
if (cloudPlatform.equals(CloudPlatform.AWS.name())) {
AwsParameters awsParameters = (AwsParameters) parameters;
if (Objects.nonNull(parameters)) {
builder.withAws(FreeIpaCreationAwsParametersDto.builder().withSpot(FreeIpaCreationAwsSpotParametersDto.builder().withPercentage(awsParameters.getFreeIpaSpotPercentage()).withMaxPrice(awsParameters.getFreeIpaSpotMaxPrice()).build()).build());
}
}
return builder.build();
}
use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testUpdateAwsDiskEncryptionParametersByEnvironmentName.
@Test
void testUpdateAwsDiskEncryptionParametersByEnvironmentName() {
UpdateAwsDiskEncryptionParametersDto updateAwsDiskEncryptionParametersDto = UpdateAwsDiskEncryptionParametersDto.builder().withAwsDiskEncryptionParametersDto(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build();
EnvironmentDto environmentDto = EnvironmentDto.builder().withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build()).build()).build();
Environment env = new Environment();
env.setParameters(new AwsParameters());
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
when(validatorService.validateEncryptionKeyArn(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
when(environmentDtoConverter.environmentToDto(env)).thenReturn(environmentDto);
EnvironmentDto envDto = environmentModificationServiceUnderTest.updateAwsDiskEncryptionParametersByEnvironmentName(ACCOUNT_ID, ENVIRONMENT_NAME, updateAwsDiskEncryptionParametersDto);
assertEquals(envDto.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn(), "dummyKeyArn");
ArgumentCaptor<AwsParameters> awsParametersArgumentCaptor = ArgumentCaptor.forClass(AwsParameters.class);
verify(awsParametersRepository).save(awsParametersArgumentCaptor.capture());
assertEquals("dummyKeyArn", awsParametersArgumentCaptor.getValue().getEncryptionKeyArn());
}
use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testUpdateAwsDiskEncryptionParametersByEnvironmentCrn.
@Test
void testUpdateAwsDiskEncryptionParametersByEnvironmentCrn() {
UpdateAwsDiskEncryptionParametersDto updateAwsDiskEncryptionParametersDto = UpdateAwsDiskEncryptionParametersDto.builder().withAwsDiskEncryptionParametersDto(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build();
EnvironmentDto environmentDto = EnvironmentDto.builder().withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build()).build()).build();
Environment env = new Environment();
env.setParameters(new AwsParameters());
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
when(validatorService.validateEncryptionKeyArn(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
when(environmentDtoConverter.environmentToDto(env)).thenReturn(environmentDto);
EnvironmentDto envDto = environmentModificationServiceUnderTest.updateAwsDiskEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, CRN, updateAwsDiskEncryptionParametersDto);
assertEquals(envDto.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn(), "dummyKeyArn");
ArgumentCaptor<AwsParameters> awsParametersArgumentCaptor = ArgumentCaptor.forClass(AwsParameters.class);
verify(awsParametersRepository).save(awsParametersArgumentCaptor.capture());
assertEquals("dummyKeyArn", awsParametersArgumentCaptor.getValue().getEncryptionKeyArn());
}
use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationService method updateAwsDiskEncryptionParameters.
private EnvironmentDto updateAwsDiskEncryptionParameters(String accountId, String environmentNameOrCrn, AwsDiskEncryptionParametersDto dto, Environment environment) {
if (dto.getEncryptionKeyArn() != null) {
ValidationResult validateKey = environmentService.getValidatorService().validateEncryptionKeyArn(dto.getEncryptionKeyArn(), accountId);
if (!validateKey.hasError()) {
if (environment.getParameters() == null) {
AwsParameters awsParameters = new AwsParameters();
awsParameters.setEncryptionKeyArn(dto.getEncryptionKeyArn());
awsParameters.setAccountId(accountId);
awsParameters.setId(environment.getId());
awsParameters.setName(environment.getName());
awsParameters.setEnvironment(environmentViewConverter.convert(environment));
environment.setParameters(awsParameters);
} else {
AwsParameters awsParameters = (AwsParameters) environment.getParameters();
if (awsParameters.getEncryptionKeyArn() == null) {
awsParameters.setEncryptionKeyArn(dto.getEncryptionKeyArn());
} else {
throw new BadRequestException("The environment already has an encryption key set and could not be updated");
}
}
LOGGER.debug("Successfully updated the encryption key ARN for the environment {}.", environmentNameOrCrn);
} else {
throw new BadRequestException(validateKey.getFormattedErrors());
}
AwsParameters awsParameters = (AwsParameters) environment.getParameters();
awsParametersRepository.save(awsParameters);
}
return environmentDtoConverter.environmentToDto(environment);
}
use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameAwsFreeIpaSpotPercentageIsNotModified.
@Test
void editByNameAwsFreeIpaSpotPercentageIsNotModified() {
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withFreeIpaSpotPercentage(50).build()).build()).build();
Environment value = new Environment();
AwsParameters awsParameters = new AwsParameters();
int originalFreeIpaSpotPercentage = 100;
awsParameters.setFreeIpaSpotPercentage(originalFreeIpaSpotPercentage);
value.setParameters(awsParameters);
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(value));
environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
verify(environmentService).save(environmentArgumentCaptor.capture());
Environment result = environmentArgumentCaptor.getValue();
AwsParameters newAwsParameters = (AwsParameters) result.getParameters();
assertEquals(originalFreeIpaSpotPercentage, newAwsParameters.getFreeIpaSpotPercentage());
}
Aggregations