use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameParametersNotExisted.
@Test
void editByNameParametersNotExisted() {
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);
BaseParameters baseParameters = new AwsParameters();
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.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditByNameGcpEncryptionResourcesWhenKeyValidationPass.
@Test
void testEditByNameGcpEncryptionResourcesWhenKeyValidationPass() {
ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey("dummyEncryptionKey").build()).build()).build();
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
Environment environment = new Environment();
environment.setAccountId(ACCOUNT_ID);
GcpParameters gcpParameters = new GcpParameters();
gcpParameters.setEncryptionKey("dummyEncryptionKey");
BaseParameters baseParameters = gcpParameters;
baseParameters.setId(123L);
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateEncryptionKey("dummyEncryptionKey", ACCOUNT_ID)).thenReturn(ValidationResult.builder().build());
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);
ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
verify(environmentService).save(environmentArgumentCaptor.capture());
assertEquals("dummyEncryptionKey", ((GcpParameters) environmentArgumentCaptor.getValue().getParameters()).getEncryptionKey());
}
use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class EnvironmentCreationServiceTest method testCreateAzureDisabled.
@Test
void testCreateAzureDisabled() {
ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("dynamo").build()).build();
final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("AZURE").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withParameters(parametersDto).withLocation(LocationDto.builder().withName("test").withDisplayName("test").withLatitude(0.1).withLongitude(0.1).build()).build();
final Environment environment = new Environment();
environment.setName(ENVIRONMENT_NAME);
environment.setId(1L);
environment.setAccountId(ACCOUNT_ID);
Credential credential = new Credential();
credential.setCloudPlatform("AZURE");
when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
when(environmentService.getRegionsByEnvironment(eq(environment))).thenReturn(getCloudRegions());
when(environmentService.save(any())).thenReturn(environment);
when(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(false);
assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
verify(validatorService, Mockito.times(1)).validatePublicKey(any());
verify(environmentService, never()).save(any());
verify(environmentResourceService, never()).createAndSetNetwork(any(), any(), any(), any(), any());
verify(reactorFlowManager, never()).triggerCreationFlow(anyLong(), eq(ENVIRONMENT_NAME), eq(USER), anyString());
}
use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class EnvironmentCreationServiceTest method testCreate.
@Test
void testCreate() {
ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("dynamo").build()).build();
String environmentCrn = "crn";
final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCreator(CRN).withAccountId(ACCOUNT_ID).withCrn(environmentCrn).withAuthentication(AuthenticationDto.builder().build()).withParameters(parametersDto).withLocation(LocationDto.builder().withName("test").withDisplayName("test").withLatitude(0.1).withLongitude(0.1).build()).build();
final Environment environment = new Environment();
environment.setName(ENVIRONMENT_NAME);
environment.setId(1L);
environment.setAccountId(ACCOUNT_ID);
Credential credential = new Credential();
credential.setCloudPlatform("platform");
when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
when(environmentResourceService.getCredentialFromRequest(any(), eq(ACCOUNT_ID))).thenReturn(credential);
when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
when(environmentService.getRegionsByEnvironment(eq(environment))).thenReturn(getCloudRegions());
when(environmentService.save(any())).thenReturn(environment);
environmentCreationServiceUnderTest.create(environmentCreationDto);
verify(validatorService, Mockito.times(1)).validatePublicKey(any());
verify(environmentService).save(any());
verify(parametersService).saveParameters(eq(environment), eq(parametersDto));
verify(environmentResourceService).createAndSetNetwork(any(), any(), any(), any(), any());
verify(reactorFlowManager).triggerCreationFlow(eq(1L), eq(ENVIRONMENT_NAME), eq(CRN), anyString());
}
use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.
the class EnvironmentCreationService method validateEncryptionKey.
private ValidationResult validateEncryptionKey(EnvironmentCreationDto creationDto) {
ValidationResultBuilder resultBuilder = ValidationResult.builder();
String cloudPlatform = creationDto.getCloudPlatform().toLowerCase(Locale.ROOT);
switch(cloudPlatform) {
case "azure":
String encryptionKeyUrl = Optional.ofNullable(creationDto.getParameters()).map(paramsDto -> paramsDto.getAzureParametersDto()).map(azureParamsDto -> azureParamsDto.getAzureResourceEncryptionParametersDto()).map(azureREParamsDto -> azureREParamsDto.getEncryptionKeyUrl()).orElse(null);
if (encryptionKeyUrl != null) {
resultBuilder.merge(validatorService.validateEncryptionKeyUrl(encryptionKeyUrl, creationDto.getAccountId()));
}
break;
case "gcp":
String encryptionKey = Optional.ofNullable(creationDto.getParameters()).map(parametersDto -> parametersDto.getGcpParametersDto()).map(gcpParametersDto -> gcpParametersDto.getGcpResourceEncryptionParametersDto()).map(gcpREParamsDto -> gcpREParamsDto.getEncryptionKey()).orElse(null);
if (encryptionKey != null) {
resultBuilder.merge(validatorService.validateEncryptionKey(encryptionKey, creationDto.getAccountId()));
}
break;
case "aws":
String encryptionKeyArn = Optional.ofNullable(creationDto.getParameters()).map(paramsDto -> paramsDto.getAwsParametersDto()).map(awsParamsDto -> awsParamsDto.getAwsDiskEncryptionParametersDto()).map(awsREparamsDto -> awsREparamsDto.getEncryptionKeyArn()).orElse(null);
if (encryptionKeyArn != null) {
resultBuilder.merge(validatorService.validateEncryptionKeyArn(encryptionKeyArn, creationDto.getAccountId()));
}
break;
default:
break;
}
return resultBuilder.build();
}
Aggregations