Search in sources :

Example 66 with NetworkDto

use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkConverterTest method testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDto.

@Test
void testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDto() {
    Environment environment = createEnvironment();
    NetworkDto networkDto = NetworkDto.builder().withAws(AwsParams.builder().withVpcId(VPC_ID).build()).withName(NETWORK_NAME).withNetworkCidr(NETWORK_CIDR).withSubnetMetas(createSubnetMetas()).build();
    AwsNetwork actual = (AwsNetwork) underTest.convert(environment, networkDto, Map.of(), Map.of());
    assertEquals(NETWORK_NAME, actual.getName());
    assertEquals(VPC_ID, actual.getVpcId());
    assertEquals(NETWORK_CIDR, actual.getNetworkCidr());
    assertEquals(RegistrationType.EXISTING, actual.getRegistrationType());
    assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
    verify(environmentViewConverter).convert(environment);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 67 with NetworkDto

use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverterTest method testConvertToDtoShouldConvertABaseNetworkWithEndpointSubnetsIntoANetworkDto.

@Test
void testConvertToDtoShouldConvertABaseNetworkWithEndpointSubnetsIntoANetworkDto() {
    AzureNetwork azureNetwork = createAzureNetwork();
    azureNetwork.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    azureNetwork.setEndpointGatewaySubnetMetas(createEndpointSubnetMetas());
    NetworkDto actual = underTest.convertToDto(azureNetwork);
    assertEquals(azureNetwork.getId(), actual.getId());
    assertEquals(azureNetwork.getName(), actual.getNetworkName());
    assertEquals(SUBNET_IDS, actual.getSubnetIds());
    assertTrue(actual.getSubnetMetas().containsKey(SUBNET_1));
    assertTrue(actual.getSubnetMetas().containsKey(SUBNET_2));
    assertTrue(actual.getSubnetMetas().containsKey(SUBNET_3));
    assertEquals(PublicEndpointAccessGateway.ENABLED, actual.getPublicEndpointAccessGateway());
    assertEquals(PUBLIC_SUBNET_IDS, actual.getEndpointGatewaySubnetIds());
    assertTrue(actual.getEndpointGatewaySubnetMetas().containsKey(PUBLIC_SUBNET_1));
    assertTrue(actual.getEndpointGatewaySubnetMetas().containsKey(PUBLIC_SUBNET_2));
    assertTrue(actual.getEndpointGatewaySubnetMetas().containsKey(PUBLIC_SUBNET_3));
    assertEquals(azureNetwork.getNetworkCidr(), actual.getNetworkCidr());
    assertEquals(azureNetwork.getResourceCrn(), actual.getResourceCrn());
    assertEquals(azureNetwork.getNetworkId(), actual.getAzure().getNetworkId());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Test(org.junit.jupiter.api.Test)

Example 68 with NetworkDto

use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverterTest method testConvertToDtoShouldConvertABaseNetworkIntoANetworkDto.

@Test
void testConvertToDtoShouldConvertABaseNetworkIntoANetworkDto() {
    AzureNetwork azureNetwork = createAzureNetwork();
    NetworkDto actual = underTest.convertToDto(azureNetwork);
    assertEquals(azureNetwork.getId(), actual.getId());
    assertEquals(azureNetwork.getName(), actual.getNetworkName());
    assertEquals(SUBNET_IDS, actual.getSubnetIds());
    assertTrue(actual.getSubnetMetas().containsKey(SUBNET_1));
    assertTrue(actual.getSubnetMetas().containsKey(SUBNET_2));
    assertTrue(actual.getSubnetMetas().containsKey(SUBNET_3));
    assertNull(actual.getPublicEndpointAccessGateway());
    assertEquals(0, actual.getEndpointGatewaySubnetIds().size());
    assertEquals(azureNetwork.getNetworkCidr(), actual.getNetworkCidr());
    assertEquals(azureNetwork.getResourceCrn(), actual.getResourceCrn());
    assertEquals(azureNetwork.getNetworkId(), actual.getAzure().getNetworkId());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Test(org.junit.jupiter.api.Test)

Example 69 with NetworkDto

use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverterTest method testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDtoWhenOptionalFieldsAreNotPresent.

@Test
void testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDtoWhenOptionalFieldsAreNotPresent() {
    Environment environment = createEnvironment();
    NetworkDto networkDto = NetworkDto.builder().withNetworkCidr(NETWORK_CIDR).withSubnetMetas(createSubnetMetas()).build();
    AzureNetwork actual = (AzureNetwork) underTest.convert(environment, networkDto, Map.of(), Map.of());
    assertEquals(environment.getName(), actual.getName());
    assertNull(actual.getNetworkId());
    assertNull(actual.getResourceGroupName());
    assertFalse(actual.getNoPublicIp());
    assertEquals(NETWORK_CIDR, actual.getNetworkCidr());
    assertEquals(RegistrationType.CREATE_NEW, actual.getRegistrationType());
    assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
    verify(environmentViewConverter).convert(environment);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Test(org.junit.jupiter.api.Test)

Example 70 with NetworkDto

use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.

the class NetworkServiceTest method testMergeNetworkDtoWithNetworkIfNetworkCreateNew.

// TODO: 2020. 01. 31. move these tests to the new CloudNetworkServiceTest class
/*@Test
    public void testRetrieveSubnetMetadataIfNetworkNull() {
        Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(null, null);
        Assertions.assertTrue(actual.isEmpty());
    }

    @Test
    public void testRetrieveSubnetMetadataWhenAwsAndNoExistedSubnetOnProvider() {
        Environment environment = new Environment();
        environment.setCloudPlatform("AWS");
        Region region = new Region();
        region.setName("region1");
        environment.setRegions(Set.of(region));
        NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("sub", new CloudSubnet())).build();
        when(cloudNetworkService.getCloudNetworks(any(PlatformResourceRequest.class))).thenReturn(new CloudNetworks(Map.of("region1", Set.of())));
        Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(environment, networkDto);
        Assertions.assertTrue(actual.isEmpty());
    }

    @Test
    public void testRetrieveSubnetMetadataWhenAwsAndHasSubnetOnProviderAndMatch() {
        Environment environment = new Environment();
        environment.setCloudPlatform("AWS");
        Region region = new Region();
        region.setName("region1");
        environment.setRegions(Set.of(region));
        CloudSubnet editSubnet = new CloudSubnet();
        NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("sub", editSubnet)).build();
        CloudSubnet providerSubnet = new CloudSubnet();
        providerSubnet.setId("sub");
        CloudNetwork cloudNetwork = new CloudNetwork("network", "network", Set.of(providerSubnet), Collections.emptyMap());
        when(cloudNetworkService.getCloudNetworks(any(PlatformResourceRequest.class))).thenReturn(new CloudNetworks(Map.of("region1",
                Set.of(cloudNetwork))));
        Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(environment, networkDto);
        Assertions.assertEquals(1, actual.size());
        Assertions.assertEquals(actual.get("sub"), providerSubnet);
    }

    @Test
    public void testRetrieveSubnetMetadataWhenAwsAndHasSubnetOnProviderAndNotMatch() {
        Environment environment = new Environment();
        environment.setCloudPlatform("AWS");
        Region region = new Region();
        region.setName("region1");
        environment.setRegions(Set.of(region));
        CloudSubnet editSubnet = new CloudSubnet();
        NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("sub", editSubnet)).build();
        CloudSubnet providerSubnet = new CloudSubnet();
        providerSubnet.setId("diff-sub");
        CloudNetwork cloudNetwork = new CloudNetwork("network", "network", Set.of(providerSubnet), Collections.emptyMap());
        when(cloudNetworkService.getCloudNetworks(any(PlatformResourceRequest.class))).thenReturn(new CloudNetworks(Map.of("region1",
                Set.of(cloudNetwork))));
        Map<String, CloudSubnet> actual = underTest.retrieveSubnetMetadata(environment, networkDto);
        Assertions.assertEquals(0, actual.size());
    }*/
@ParameterizedTest
@EnumSource(CloudPlatform.class)
public void testMergeNetworkDtoWithNetworkIfNetworkCreateNew(CloudPlatform cloudPlatform) {
    AwsNetwork baseNetwork = new AwsNetwork();
    baseNetwork.setSubnetMetas(Collections.emptyMap());
    baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
    Environment environment = new Environment();
    environment.setCloudPlatform(cloudPlatform.name());
    environment.setNetwork(baseNetwork);
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build();
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build();
    when(environmentNetworkConverterMap.get(cloudPlatform)).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(networkCreationValidator.validateNetworkEdit(eq(environment), any(NetworkDto.class))).thenReturn(new ValidationResult.ValidationResultBuilder());
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.validate(baseNetwork, environmentEditDto, environment));
    String baseMessage = "Subnets of this environment could not be modified, because its network has been created by Cloudera. " + "You need to re-install the environment into an existing VPC/VNet.";
    String providerSpecificLink = "";
    switch(cloudPlatform) {
        case AWS:
            providerSpecificLink = " Refer to Cloudera documentation at " + "https://docs.cloudera.com/management-console/cloud/environments/topics/mc-subnet-adding-azure.html for more information.";
            break;
        case AZURE:
            providerSpecificLink = " Refer to Cloudera documentation at " + "https://docs.cloudera.com/management-console/cloud/environments-azure/topics/mc-subnet-adding-azure.html for more information.";
            break;
        default:
            break;
    }
    Assertions.assertEquals(String.format("%s%s", baseMessage, providerSpecificLink), exception.getMessage());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)144 Test (org.junit.jupiter.api.Test)124 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)59 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)40 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)31 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)27 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)21 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)21 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)15 Environment (com.sequenceiq.environment.environment.domain.Environment)15 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)12 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)10 AwsParams (com.sequenceiq.environment.network.dto.AwsParams)9 Features (com.sequenceiq.common.api.telemetry.model.Features)8 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)7 EnvironmentRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest)7 ExperimentalFeatures (com.sequenceiq.environment.environment.domain.ExperimentalFeatures)7 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)7