use of com.sequenceiq.environment.environment.dto.EnvironmentCreationDto in project cloudbreak by hortonworks.
the class EnvironmentApiConverterTest method testAzureResourceEncryptionParametersAndAzureRequest.
@Test
void testAzureResourceEncryptionParametersAndAzureRequest() {
EnvironmentRequest request = createEnvironmentRequest(AZURE);
request.setAzure(AzureEnvironmentParameters.builder().withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(KEY_URL_RESOURCE_GROUP).build()).build());
FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
Features features = mock(Features.class);
NetworkDto networkDto = mock(NetworkDto.class);
when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
when(accountTelemetry.getFeatures()).thenReturn(features);
when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
EnvironmentCreationDto actual = testInitCreationDto(request);
assertEquals(KEY_URL, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
assertEquals(KEY_URL_RESOURCE_GROUP, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentCreationDto in project cloudbreak by hortonworks.
the class EnvironmentCreationServiceTest method testEncryptionKeyValidationError.
@Test
void testEncryptionKeyValidationError() {
final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("GCP").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).build();
final Environment environment = new Environment();
environment.setName(ENVIRONMENT_NAME);
environment.setId(1L);
environment.setAccountId(ACCOUNT_ID);
Credential credential = new Credential();
credential.setCloudPlatform("GCP");
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
validationResultBuilder.error("error");
when(validatorService.validateEncryptionKeyUrl(any(), any())).thenReturn(validationResultBuilder.build());
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(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(true);
when(environmentService.save(any())).thenReturn(environment);
assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
}
use of com.sequenceiq.environment.environment.dto.EnvironmentCreationDto 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.environment.dto.EnvironmentCreationDto 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.environment.dto.EnvironmentCreationDto 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