Search in sources :

Example 6 with AwsParameters

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

the class EnvironmentModificationServiceTest method editByNameParametersExistedAndValid.

@Test
void editByNameParametersExistedAndValid() {
    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);
    AwsParameters awsParameters = new AwsParameters();
    awsParameters.setS3guardTableName("existingTable");
    BaseParameters baseParameters = awsParameters;
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentFlowValidatorService.validateParameters(any(), any())).thenReturn(validationResult);
    when(validationResult.hasError()).thenReturn(false);
    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);
    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 7 with AwsParameters

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

the class S3GuardTableDeleteHandlerTest method acceptTestEnvironmentAwsFailure.

@Test
void acceptTestEnvironmentAwsFailure() {
    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());
    Exception exception = new CloudConnectorException(String.format("Cannot delete NoSQL table %s. " + "Provider error message: %s", DYNAMO_TABLE_NAME, "errorMessage"));
    when(noSql.deleteNoSqlTable(any(NoSqlTableDeleteRequest.class))).thenThrow(exception);
    underTest.accept(environmentDtoEvent);
    NoSqlTableDeleteRequest request = getNoSqlTableDeleteRequest(cloudCredential);
    verify(cloudPlatformConnectors).get(any(), any());
    verify(noSql).deleteNoSqlTable(request);
    verify(mockExceptionProcessor, times(1)).handle(any(), any(), any(), any());
    verify(mockExceptionProcessor, times(1)).handle(any(HandlerFailureConjoiner.class), any(Logger.class), eq(eventSender), eq(DELETE_S3GUARD_TABLE_EVENT.selector()));
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) Logger(org.slf4j.Logger) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Test(org.junit.jupiter.api.Test)

Example 8 with AwsParameters

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

the class S3GuardTableDeleteHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            BaseParameters environmentParameters = environment.getParameters();
            if (environmentParameters instanceof AwsParameters) {
                AwsParameters awsParameters = (AwsParameters) environmentParameters;
                deleteS3GuardTable(environment, awsParameters);
            } else {
                LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary.");
            }
        });
        eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters)

Example 9 with AwsParameters

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

the class AwsEnvironmentParametersConverter method postConvertToDto.

@Override
protected void postConvertToDto(Builder builder, BaseParameters source) {
    super.postConvertToDto(builder, source);
    AwsParameters awsParameters = (AwsParameters) source;
    builder.withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName(awsParameters.getS3guardTableName()).withDynamoDbTableCreation(awsParameters.getS3guardTableCreation()).withFreeIpaSpotPercentage(awsParameters.getFreeIpaSpotPercentage()).withFreeIpaSpotMaxPrice(awsParameters.getFreeIpaSpotMaxPrice()).withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn(awsParameters.getEncryptionKeyArn()).build()).build());
}
Also used : AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters)

Example 10 with AwsParameters

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

the class ParametersServiceTest method saveParameters.

@Test
void saveParameters() {
    AwsParameters awsParameters = new AwsParameters();
    when(environmentParamsConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentParametersConverter);
    when(environmentParametersConverter.convert(any(Environment.class), any(ParametersDto.class))).thenReturn(awsParameters);
    when(baseParametersRepository.save(any())).thenReturn(awsParameters);
    Environment environment = new Environment();
    environment.setAccountId("accountId");
    environment.setCloudPlatform("AWS");
    BaseParameters result = underTest.saveParameters(environment, ParametersDto.builder().build());
    assertEquals(awsParameters, result);
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) 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