Search in sources :

Example 26 with ParametersDto

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);
        }
    }
}
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 27 with ParametersDto

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());
}
Also used : EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) 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) Test(org.junit.jupiter.api.Test)

Example 28 with ParametersDto

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

Example 29 with ParametersDto

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());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Example 30 with ParametersDto

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());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) Test(org.junit.jupiter.api.Test)

Aggregations

ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)38 Test (org.junit.jupiter.api.Test)30 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)28 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)24 AwsDiskEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)23 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)19 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)19 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)18 Environment (com.sequenceiq.environment.environment.domain.Environment)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)9 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)9 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)8 Credential (com.sequenceiq.environment.credential.domain.Credential)8 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)7 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)6 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)6 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)5 GcpParameters (com.sequenceiq.environment.parameters.dao.domain.GcpParameters)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5