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);
}
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));
}
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());
}
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());
}
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);
}
Aggregations