Search in sources :

Example 56 with NetworkDto

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

the class EnvironmentDetailsToCDPNetworkDetailsConverterTest method testConversionNetworkShouldReturnNetworkRelatedFields.

@Test
public void testConversionNetworkShouldReturnNetworkRelatedFields() {
    CloudSubnet privateSubnet = new CloudSubnet();
    privateSubnet.setType(SubnetType.PRIVATE);
    CloudSubnet dwxSubnet = new CloudSubnet();
    dwxSubnet.setType(SubnetType.DWX);
    CloudSubnet mlxSubnet = new CloudSubnet();
    mlxSubnet.setType(SubnetType.MLX);
    CloudSubnet publicSubnet1 = new CloudSubnet();
    publicSubnet1.setType(SubnetType.PUBLIC);
    CloudSubnet publicSubnet2 = new CloudSubnet();
    publicSubnet2.setType(SubnetType.PUBLIC);
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.EXISTING).withServiceEndpointCreation(ServiceEndpointCreation.ENABLED).withSubnetMetas(Map.of("1", dwxSubnet, "2", mlxSubnet, "3", publicSubnet1, "4", publicSubnet2, "5", privateSubnet)).build();
    when(environmentDetails.getNetwork()).thenReturn(networkDto);
    when(environmentDetails.getSecurityAccessType()).thenReturn("CIDR_WIDE_OPEN");
    when(environmentDetails.getTunnel()).thenReturn(Tunnel.CCM);
    when(environmentDetails.getDomain()).thenReturn("cldr.com");
    when(environmentDetails.getTlsType()).thenReturn(CcmV2TlsType.ONE_WAY_TLS);
    UsageProto.CDPNetworkDetails networkDetails = underTest.convert(environmentDetails);
    Assert.assertEquals("EXISTING", networkDetails.getNetworkType());
    Assert.assertEquals("ENABLED", networkDetails.getServiceEndpointCreation());
    Assert.assertEquals("EXISTING", networkDetails.getNetworkType());
    Assert.assertEquals(3, networkDetails.getNumberPrivateSubnets());
    Assert.assertEquals(2, networkDetails.getNumberPublicSubnets());
    Assert.assertEquals("DISABLED", networkDetails.getPublicEndpointAccessGateway());
    Assert.assertEquals("CIDR_WIDE_OPEN", networkDetails.getSecurityAccessType());
    Assert.assertEquals("CCM", networkDetails.getConnectivity());
    Assert.assertEquals("ONE_WAY_TLS", networkDetails.getControlPlaneAndCCMAgentConnectionSecurity());
    Assert.assertEquals("cldr.com", networkDetails.getDomain());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) UsageProto(com.cloudera.thunderhead.service.common.usage.UsageProto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 57 with NetworkDto

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

the class EnvironmentDetailsToCDPNetworkDetailsConverterTest method testSettingSubnetNumbersWhenSubnetMetasIsEmpty.

@Test
public void testSettingSubnetNumbersWhenSubnetMetasIsEmpty() {
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.EXISTING).withServiceEndpointCreation(ServiceEndpointCreation.ENABLED).withSubnetMetas(null).build();
    when(environmentDetails.getNetwork()).thenReturn(networkDto);
    UsageProto.CDPNetworkDetails networkDetails = underTest.convert(environmentDetails);
    assertEquals(0, networkDetails.getNumberPrivateSubnets());
    assertEquals(0, networkDetails.getNumberPublicSubnets());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) UsageProto(com.cloudera.thunderhead.service.common.usage.UsageProto) Test(org.junit.jupiter.api.Test)

Example 58 with NetworkDto

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

the class EnvironmentDetailsToCDPNetworkDetailsConverterTest method testSettingSubnetNumbersWhenSubnetTypeIsEmpty.

@Test
public void testSettingSubnetNumbersWhenSubnetTypeIsEmpty() {
    CloudSubnet publicSubnet = new CloudSubnet();
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.EXISTING).withServiceEndpointCreation(ServiceEndpointCreation.ENABLED).withSubnetMetas(Map.of("1", publicSubnet)).build();
    when(environmentDetails.getNetwork()).thenReturn(networkDto);
    UsageProto.CDPNetworkDetails networkDetails = underTest.convert(environmentDetails);
    assertEquals(-1, networkDetails.getNumberPrivateSubnets());
    assertEquals(-1, networkDetails.getNumberPublicSubnets());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) UsageProto(com.cloudera.thunderhead.service.common.usage.UsageProto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 59 with NetworkDto

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

the class EnvironmentDetailsToCDPNetworkDetailsConverterTest method testSettingSubnetNumbersWhenSubnetTypeIsNotEmpty.

@Test
public void testSettingSubnetNumbersWhenSubnetTypeIsNotEmpty() {
    CloudSubnet publicSubnet = new CloudSubnet();
    publicSubnet.setType(SubnetType.PUBLIC);
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.EXISTING).withServiceEndpointCreation(ServiceEndpointCreation.ENABLED).withSubnetMetas(Map.of("1", publicSubnet)).build();
    when(environmentDetails.getNetwork()).thenReturn(networkDto);
    UsageProto.CDPNetworkDetails networkDetails = underTest.convert(environmentDetails);
    assertEquals(0, networkDetails.getNumberPrivateSubnets());
    assertEquals(1, networkDetails.getNumberPublicSubnets());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) UsageProto(com.cloudera.thunderhead.service.common.usage.UsageProto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 60 with NetworkDto

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

the class NetworkServiceTest method testSaveNetworkIfNewNetwork.

@Test
public void testSaveNetworkIfNewNetwork() {
    NetworkDto networkDto = mock(NetworkDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new AwsNetwork();
    baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    environment.setCredential(credential);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convert(environment, networkDto, Map.of(), Map.of())).thenReturn(baseNetwork);
    when(networkRepository.save(baseNetwork)).thenReturn(baseNetwork);
    BaseNetwork result = underTest.saveNetwork(environment, networkDto, "accountId", Map.of(), Map.of());
    Assertions.assertNull(result.getNetworkCidr());
    verify(environmentNetworkService, times(0)).getNetworkCidr(eq(network), anyString(), eq(credential));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) 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) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) Test(org.junit.jupiter.api.Test) 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