Search in sources :

Example 16 with ParametersDto

use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.

the class AwsParameterValidatorTest method validateNoS3GuardCheckOnUpdateAwsDiskEncryptionParameters.

@Test
void validateNoS3GuardCheckOnUpdateAwsDiskEncryptionParameters() {
    AwsParametersDto awsParameters = AwsParametersDto.builder().withDynamoDbTableName("tablename").build();
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(awsParameters).build();
    EnvironmentDto environmentDto = new AwsParameterValidatorTest.EnvironmentDtoBuilder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("tablename").build()).build();
    environmentValidationDto.setEnvironmentDto(environmentDto);
    ValidationResult validationResult = underTest.validate(environmentValidationDto, parametersDto, ValidationResult.builder());
    assertFalse(validationResult.hasError());
    verify(parametersService, never()).isS3GuardTableUsed(any(), any(), any(), any());
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with ParametersDto

use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.

the class AwsParameterValidatorTest method validateS3GuardCheckWhenAWSDiskEncryptionParametersAlreadyPresent.

@Test
void validateS3GuardCheckWhenAWSDiskEncryptionParametersAlreadyPresent() {
    AwsParametersDto awsParameters = AwsParametersDto.builder().withDynamoDbTableName("tablename").build();
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(awsParameters).build();
    EnvironmentDto environmentDto = new AwsParameterValidatorTest.EnvironmentDtoBuilder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummy-key-arn").build()).build()).build();
    environmentValidationDto.setEnvironmentDto(environmentDto);
    when(parametersService.isS3GuardTableUsed(any(), any(), any(), any())).thenReturn(true);
    ValidationResult validationResult = underTest.validate(environmentValidationDto, parametersDto, ValidationResult.builder());
    assertTrue(validationResult.hasError());
    assertEquals(1L, validationResult.getErrors().size());
    assertEquals("S3Guard Dynamo table 'tablename' is already attached to another active environment. " + "Please select another unattached table or specify a non-existing name to create it. Refer to " + "Cloudera documentation at https://docs.cloudera.com/cdp/latest/requirements-aws/topics/mc-aws-req-dynamodb.html " + "for the required setup.", validationResult.getErrors().get(0));
}
Also used : AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with ParametersDto

use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.

the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.

@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
    NetworkDto networkDto = mock(NetworkDto.class);
    AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
    ParametersDto parametersDto = mock(ParametersDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new GcpNetwork();
    baseNetwork.setRegistrationType(RegistrationType.EXISTING);
    Environment environment = new Environment();
    environment.setCloudPlatform("GCP");
    environment.setCredential(credential);
    EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
    BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
    Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "subnet1");
    Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) ArrayList(java.util.ArrayList) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with ParametersDto

use of com.sequenceiq.environment.parameter.dto.ParametersDto 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)

Example 20 with ParametersDto

use of com.sequenceiq.environment.parameter.dto.ParametersDto in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails.

@Test
void testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails() {
    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);
    BaseParameters baseParameters = new GcpParameters();
    baseParameters.setId(123L);
    ValidationResult validationResultError = ValidationResult.builder().error("Wrong key format").build();
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(validatorService.validateEncryptionKey("dummyEncryptionKey", ACCOUNT_ID)).thenReturn(validationResultError);
    when(parametersService.findByEnvironment(any())).thenReturn(Optional.of(baseParameters));
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
    assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
    verify(parametersService, never()).saveParameters(environment, parameters);
}
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) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters) Test(org.junit.jupiter.api.Test)

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