Search in sources :

Example 6 with BaseParameters

use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails.

@Test
void testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails() {
    ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey("dummyEncryptionKey").build()).build()).build();
    EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
    Environment environment = new Environment();
    environment.setAccountId(ACCOUNT_ID);
    BaseParameters baseParameters = new GcpParameters();
    baseParameters.setId(123L);
    ValidationResult validationResultError = ValidationResult.builder().error("Wrong key format").build();
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(validatorService.validateEncryptionKey("dummyEncryptionKey", ACCOUNT_ID)).thenReturn(validationResultError);
    when(parametersService.findByEnvironment(any())).thenReturn(Optional.of(baseParameters));
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
    assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
    verify(parametersService, never()).saveParameters(environment, parameters);
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters) Test(org.junit.jupiter.api.Test)

Example 7 with BaseParameters

use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method editByNameParametersNotExisted.

@Test
void editByNameParametersNotExisted() {
    String dynamotable = "dynamotable";
    ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName(dynamotable).build()).build();
    EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
    Environment environment = new Environment();
    environment.setAccountId(ACCOUNT_ID);
    BaseParameters baseParameters = new AwsParameters();
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
    when(parametersService.saveParameters(environment, parameters)).thenReturn(baseParameters);
    environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
    verify(parametersService).saveParameters(environment, parameters);
    assertEquals(baseParameters, environment.getParameters());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Example 8 with BaseParameters

use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testEditByNameGcpEncryptionResourcesWhenKeyValidationPass.

@Test
void testEditByNameGcpEncryptionResourcesWhenKeyValidationPass() {
    ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey("dummyEncryptionKey").build()).build()).build();
    EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
    Environment environment = new Environment();
    environment.setAccountId(ACCOUNT_ID);
    GcpParameters gcpParameters = new GcpParameters();
    gcpParameters.setEncryptionKey("dummyEncryptionKey");
    BaseParameters baseParameters = gcpParameters;
    baseParameters.setId(123L);
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(validatorService.validateEncryptionKey("dummyEncryptionKey", ACCOUNT_ID)).thenReturn(ValidationResult.builder().build());
    when(parametersService.findByEnvironment(any())).thenReturn(Optional.of(baseParameters));
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
    when(parametersService.saveParameters(environment, parameters)).thenReturn(baseParameters);
    environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
    ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
    verify(environmentService).save(environmentArgumentCaptor.capture());
    assertEquals("dummyEncryptionKey", ((GcpParameters) environmentArgumentCaptor.getValue().getParameters()).getEncryptionKey());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Example 9 with BaseParameters

use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters 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);
        }
    }
}
Also used : GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) BadRequestException(javax.ws.rs.BadRequestException) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters)

Example 10 with BaseParameters

use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters 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());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) 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) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Aggregations

BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)14 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)10 Environment (com.sequenceiq.environment.environment.domain.Environment)9 Test (org.junit.jupiter.api.Test)9 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)7 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)7 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)7 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)7 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)6 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)5 GcpParameters (com.sequenceiq.environment.parameters.dao.domain.GcpParameters)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 AzureParameters (com.sequenceiq.environment.parameters.dao.domain.AzureParameters)2 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)1 AwsDiskEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)1 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)1