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