Search in sources :

Example 21 with ParametersDto

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());
}
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 22 with ParametersDto

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());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) 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) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Example 23 with ParametersDto

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());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with ParametersDto

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());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with ParametersDto

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();
}
Also used : EnvironmentDtoConverter(com.sequenceiq.environment.environment.dto.EnvironmentDtoConverter) Environment(com.sequenceiq.environment.environment.domain.Environment) NullUtil.getIfNotNull(com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) AuthenticationDtoConverter(com.sequenceiq.environment.environment.dto.AuthenticationDtoConverter) Credential(com.sequenceiq.environment.credential.domain.Credential) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) LoadBalancerEntitlementService(com.sequenceiq.environment.network.service.LoadBalancerEntitlementService) StringUtils(org.apache.commons.lang3.StringUtils) Value(org.springframework.beans.factory.annotation.Value) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) BadRequestException(javax.ws.rs.BadRequestException) ParametersService(com.sequenceiq.environment.parameters.service.ParametersService) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) Tunnel(com.sequenceiq.common.api.type.Tunnel) Logger(org.slf4j.Logger) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) EnvironmentValidatorService(com.sequenceiq.environment.environment.validation.EnvironmentValidatorService) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) Optional(java.util.Optional) GCP(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.GCP) AZURE(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AZURE) ProxyConfig(com.sequenceiq.environment.proxy.domain.ProxyConfig) EnvironmentReactorFlowManager(com.sequenceiq.environment.environment.flow.EnvironmentReactorFlowManager) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Aggregations

ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)38 Test (org.junit.jupiter.api.Test)30 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)28 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)24 AwsDiskEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)23 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)19 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)19 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)18 Environment (com.sequenceiq.environment.environment.domain.Environment)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)9 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)9 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)8 Credential (com.sequenceiq.environment.credential.domain.Credential)8 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)7 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)6 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)6 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)5 GcpParameters (com.sequenceiq.environment.parameters.dao.domain.GcpParameters)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5