Search in sources :

Example 1 with AwsParameters

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();
}
Also used : AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters)

Example 2 with AwsParameters

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());
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with AwsParameters

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());
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with AwsParameters

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);
}
Also used : AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) BadRequestException(javax.ws.rs.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 5 with AwsParameters

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

Aggregations

AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)21 Test (org.junit.jupiter.api.Test)13 Environment (com.sequenceiq.environment.environment.domain.Environment)8 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)8 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)7 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)4 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)4 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)4 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)4 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)3 NoSqlTableDeleteRequest (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest)3 NoSqlTableMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest)3 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)3 AwsDiskEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)3 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 UpdateAwsDiskEncryptionParametersDto (com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto)2 BadRequestException (javax.ws.rs.BadRequestException)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1