Search in sources :

Example 16 with AwsParameters

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

the class S3GuardTableDeleteHandlerTest method acceptTestEnvironmentSuccess.

@Test
void acceptTestEnvironmentSuccess() {
    when(cloudPlatformConnectors.get(any(), any())).thenReturn(cloudConnector);
    when(cloudConnector.noSql()).thenReturn(noSql);
    CloudCredential cloudCredential = new CloudCredential();
    when(credentialToCloudCredentialConverter.convert(any())).thenReturn(cloudCredential);
    AwsParameters awsParameters = getAwsParameters(S3GuardTableCreation.CREATE_NEW);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(awsParameters)));
    when(noSql.getNoSqlTableMetaData(any(NoSqlTableMetadataRequest.class))).thenReturn(NoSqlTableMetadataResponse.builder().withStatus(ResponseStatus.OK).build());
    when(noSql.deleteNoSqlTable(any(NoSqlTableDeleteRequest.class))).thenReturn(NoSqlTableDeleteResponse.builder().withStatus(ResponseStatus.OK).build());
    underTest.accept(environmentDtoEvent);
    NoSqlTableDeleteRequest request = getNoSqlTableDeleteRequest(cloudCredential);
    verify(cloudPlatformConnectors).get(any(), any());
    verify(noSql).deleteNoSqlTable(request);
    verify(eventSender).sendEvent(eventArgumentCaptor.capture(), headersArgumentCaptor.capture());
    verifyEnvDeleteEvent();
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) Test(org.junit.jupiter.api.Test)

Example 17 with AwsParameters

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

the class S3GuardTableDeleteHandlerTest method acceptTestEnvironmentPreExistingTable.

@Test
void acceptTestEnvironmentPreExistingTable() {
    AwsParameters awsParameters = getAwsParameters(S3GuardTableCreation.USE_EXISTING);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(awsParameters)));
    underTest.accept(environmentDtoEvent);
    verify(cloudPlatformConnectors, never()).get(any());
    verify(cloudPlatformConnectors, never()).get(any(), any());
    verify(eventSender).sendEvent(eventArgumentCaptor.capture(), headersArgumentCaptor.capture());
    verifyEnvDeleteEvent();
}
Also used : AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) Test(org.junit.jupiter.api.Test)

Example 18 with AwsParameters

use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters 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 19 with AwsParameters

use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters 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 20 with AwsParameters

use of com.sequenceiq.environment.parameters.dao.domain.AwsParameters 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

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