Search in sources :

Example 6 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkConverter method convertToNetwork.

@Override
public Network convertToNetwork(BaseNetwork baseNetwork) {
    AwsNetwork awsNetwork = (AwsNetwork) baseNetwork;
    Map<String, Object> param = new HashMap<>();
    param.put(NetworkConstants.VPC_ID, awsNetwork.getVpcId());
    param.put(AwsNetworkView.REGION, awsNetwork.getEnvironments().stream().findFirst().get().getLocation());
    return new Network(null, param);
}
Also used : HashMap(java.util.HashMap) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network)

Example 7 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork 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)

Example 8 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class NetworkServiceTest method testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs.

@Test
public void testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs() {
    String primaryCidr = "10.0.0.0/16";
    String secondaryCidr = "10.2.0.0/16";
    AwsNetwork baseNetwork = new AwsNetwork();
    baseNetwork.setSubnetMetas(Collections.emptyMap());
    baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    environment.setNetwork(baseNetwork);
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build();
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build();
    Network network = new Network(new Subnet(primaryCidr));
    NetworkCidr networkCidr = new NetworkCidr(primaryCidr, List.of(primaryCidr, secondaryCidr));
    when(environmentNetworkConverterMap.get(CloudPlatform.AWS)).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(environmentNetworkConverter.convertToNetwork(baseNetwork)).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential())).thenReturn(networkCidr);
    BaseNetwork actualNetwork = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
    verify(cloudNetworkService, times(1)).retrieveSubnetMetadata(eq(environment), any(NetworkDto.class));
    verify(environmentNetworkService, times(1)).getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential());
    Assertions.assertEquals(primaryCidr, actualNetwork.getNetworkCidr());
    Assertions.assertEquals(StringUtils.join(networkCidr.getCidrs(), ","), actualNetwork.getNetworkCidrs());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkConverterTest method testGetNetworkCidrWhenDuplicated.

@Test
public void testGetNetworkCidrWhenDuplicated() {
    AwsNetwork awsNetwork = createAwsNetwork();
    awsNetwork.setNetworkCidrs("10.0.0.0/16,10.0.0.0/16");
    Set<String> actual = underTest.getNetworkCidrs(awsNetwork);
    Assertions.assertEquals(1, actual.size());
    Assertions.assertEquals("10.0.0.0/16", actual.iterator().next());
}
Also used : AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Test(org.junit.jupiter.api.Test)

Example 10 with AwsNetwork

use of com.sequenceiq.environment.network.dao.domain.AwsNetwork 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)

Aggregations

AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)22 Test (org.junit.jupiter.api.Test)15 Environment (com.sequenceiq.environment.environment.domain.Environment)12 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)9 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)8 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)5 Network (com.sequenceiq.cloudbreak.cloud.model.Network)4 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)4 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Credential (com.sequenceiq.environment.credential.domain.Credential)3 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)3 NetworkTest (com.sequenceiq.environment.environment.service.network.NetworkTest)3 CreatedSubnet (com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)2 Region (com.sequenceiq.environment.environment.domain.Region)2 GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)1 NetworkCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)1