use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class EnvironmentModificationService method editEnvironmentParameters.
private void editEnvironmentParameters(EnvironmentEditDto editDto, Environment environment) {
ParametersDto parametersDto = editDto.getParameters();
if (parametersDto != null) {
Optional<BaseParameters> original = parametersService.findByEnvironment(environment.getId());
if (original.isPresent()) {
BaseParameters originalParameters = original.get();
parametersDto.setId(originalParameters.getId());
if (originalParameters instanceof AwsParameters) {
AwsParameters awsOriginalParameters = (AwsParameters) originalParameters;
parametersDto.getAwsParametersDto().setFreeIpaSpotPercentage(awsOriginalParameters.getFreeIpaSpotPercentage());
validateAwsParameters(environment, parametersDto);
}
}
if (parametersDto.getGcpParametersDto() != null) {
String encryptionKey = Optional.of(parametersDto.getGcpParametersDto()).map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey).orElse(null);
ValidationResult validationResult = environmentService.getValidatorService().validateEncryptionKey(encryptionKey, editDto.getAccountId());
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
}
BaseParameters parameters = parametersService.saveParameters(environment, parametersDto);
if (parameters != null) {
environment.setParameters(parameters);
}
}
}
use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class AwsEnvironmentParametersConverterTest method convertToDtoTest.
@Test
void convertToDtoTest() {
EnvironmentView environmentView = ENVIRONMENT_VIEW;
AwsParameters parameters = new AwsParameters();
parameters.setAccountId(ACCOUNT_ID);
parameters.setEnvironment(environmentView);
parameters.setId(ID);
parameters.setName(ENV_NAME);
parameters.setS3guardTableName(TABLE_NAME);
parameters.setS3guardTableCreation(S3GuardTableCreation.CREATE_NEW);
parameters.setFreeIpaSpotPercentage(null);
parameters.setFreeIpaSpotMaxPrice(0.9);
parameters.setEncryptionKeyArn(ENCRYPTION_KEY_ARN);
ParametersDto result = underTest.convertToDto(parameters);
assertEquals(ACCOUNT_ID, result.getAccountId());
assertEquals(ID, result.getId());
assertEquals(ENV_NAME, result.getName());
assertEquals(TABLE_NAME, result.getAwsParametersDto().getS3GuardTableName());
assertEquals(S3GuardTableCreation.CREATE_NEW, result.getAwsParametersDto().getDynamoDbTableCreation());
assertEquals(0, result.getAwsParametersDto().getFreeIpaSpotPercentage());
assertEquals(0.9, result.getAwsParametersDto().getFreeIpaSpotMaxPrice());
assertEquals(ENCRYPTION_KEY_ARN, result.getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn());
}
use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class AwsEnvironmentParametersConverterTest method convertTest.
@Test
void convertTest() {
when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
ParametersDto parameters = ParametersDto.builder().withId(ID).withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName(TABLE_NAME).withDynamoDbTableCreation(S3GuardTableCreation.CREATE_NEW).withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn(ENCRYPTION_KEY_ARN).build()).build()).build();
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setAccountId(ACCOUNT_ID);
BaseParameters result = underTest.convert(environment, parameters);
assertEquals(AwsParameters.class, result.getClass());
AwsParameters awsResult = (AwsParameters) result;
assertEquals(ENV_NAME, awsResult.getName());
assertEquals(ACCOUNT_ID, awsResult.getAccountId());
assertEquals(ENVIRONMENT_VIEW, awsResult.getEnvironment());
assertEquals(ID, awsResult.getId());
assertEquals(TABLE_NAME, awsResult.getS3guardTableName());
assertEquals(S3GuardTableCreation.CREATE_NEW, awsResult.getS3guardTableCreation());
}
use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class AzureEnvironmentParametersConverterTest method convertTest.
@Test
void convertTest() {
when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
ParametersDto parameters = ParametersDto.builder().withId(ID).withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(KEY_RESOURCE_GROUP_NAME).build()).build()).build();
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setAccountId(ACCOUNT_ID);
BaseParameters result = underTest.convert(environment, parameters);
assertEquals(AzureParameters.class, result.getClass());
AzureParameters azureResult = (AzureParameters) result;
assertEquals(ENV_NAME, azureResult.getName());
assertEquals(ACCOUNT_ID, azureResult.getAccountId());
assertEquals(ENVIRONMENT_VIEW, azureResult.getEnvironment());
assertEquals(ID, azureResult.getId());
assertEquals(KEY_URL, azureResult.getEncryptionKeyUrl());
assertEquals(KEY_RESOURCE_GROUP_NAME, azureResult.getEncryptionKeyResourceGroupName());
}
use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class AzureEnvironmentParametersConverterTest method convertToDtoTest.
@Test
void convertToDtoTest() {
EnvironmentView environmentView = ENVIRONMENT_VIEW;
AzureParameters parameters = new AzureParameters();
parameters.setAccountId(ACCOUNT_ID);
parameters.setEnvironment(environmentView);
parameters.setId(ID);
parameters.setName(ENV_NAME);
parameters.setEncryptionKeyUrl(KEY_URL);
parameters.setDiskEncryptionSetId("DummyDesId");
parameters.setEncryptionKeyResourceGroupName(KEY_RESOURCE_GROUP_NAME);
ParametersDto result = underTest.convertToDto(parameters);
assertEquals(ACCOUNT_ID, result.getAccountId());
assertEquals(ID, result.getId());
assertEquals(ENV_NAME, result.getName());
assertEquals(KEY_URL, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
assertEquals("DummyDesId", result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getDiskEncryptionSetId());
assertEquals(KEY_RESOURCE_GROUP_NAME, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
Aggregations