Search in sources :

Example 1 with BaseParameters

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

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

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

Example 4 with BaseParameters

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

the class GcpEnvironmentParametersConverterTest method convertTest.

@Test
void convertTest() {
    when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
    ParametersDto parameters = ParametersDto.builder().withId(ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey(ENCRYPTION_KEY).build()).build()).build();
    Environment environment = new Environment();
    environment.setName(ENV_NAME);
    environment.setAccountId(ACCOUNT_ID);
    BaseParameters result = underTest.convert(environment, parameters);
    assertEquals(GcpParameters.class, result.getClass());
    GcpParameters gcpResult = (GcpParameters) result;
    assertEquals(ENV_NAME, gcpResult.getName());
    assertEquals(ACCOUNT_ID, gcpResult.getAccountId());
    assertEquals(ENVIRONMENT_VIEW, gcpResult.getEnvironment());
    assertEquals(ID, gcpResult.getId());
    assertEquals(ENCRYPTION_KEY, gcpResult.getEncryptionKey());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters) Test(org.junit.jupiter.api.Test)

Example 5 with BaseParameters

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

the class EnvironmentModificationServiceTest method editByNameParametersExistedAndNotValid.

@Test
void editByNameParametersExistedAndNotValid() {
    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(true);
    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);
    assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
    verify(parametersService, never()).saveParameters(environment, parameters);
}
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)

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