@Test void testProvideThenNetworkSelectorCalled() { NetworkDto networkDto = NetworkDto.builder() .withCbSubnets(Map.of("AZ-a", new CloudSubnet())) .withSubnetMetas(Map.of("AZ-a", new CloudSubnet())) .build(); NetworkConnector networkConnector = setupConnectorWithSelectionResult(List.of(new CloudSubnet("id", "name"))); Tunnel tunnel = Tunnel.DIRECT; String provide = underTest.provide(networkDto, tunnel, CloudPlatform.AWS); assertEquals("id", provide); ArgumentCaptor<SubnetSelectionParameters> subnetSelectionParametersCaptor = ArgumentCaptor.forClass(SubnetSelectionParameters.class); verify(networkConnector).chooseSubnets(any(), subnetSelectionParametersCaptor.capture()); assertFalse(subnetSelectionParametersCaptor.getValue().isPreferPrivateIfExist()); assertFalse(subnetSelectionParametersCaptor.getValue().isHa()); assertEquals(tunnel, subnetSelectionParametersCaptor.getValue().getTunnel()); }
public String provide(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform) { LOGGER.debug("Choosing subnet, network: {}, platform: {}, tunnel: {}", network, cloudPlatform, tunnel); if (network == null || network.getSubnetIds() == null || network.getSubnetIds().isEmpty() || network.getCbSubnets() == null || network.getCbSubnets().isEmpty()) { LOGGER.debug("Check failed, returning null"); return null; } NetworkConnector networkConnector = cloudPlatformConnectors .get(new CloudPlatformVariant(cloudPlatform.name(), cloudPlatform.name())) .networkConnector(); if (networkConnector == null) { LOGGER.warn("Network connector is null for '{}' cloud platform, returning null", cloudPlatform.name()); return null; } SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters .builder() .withTunnel(tunnel) .build(); SubnetSelectionResult subnetSelectionResult = networkConnector .chooseSubnets(network.getCbSubnetValues(), subnetSelectionParameters); CloudSubnet selectedSubnet = subnetSelectionResult.hasResult() ? subnetSelectionResult.getResult().get(0) : fallback(network); return selectedSubnet.getId(); }
SubnetIdProvider { public String provide(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform) { LOGGER.debug("Choosing subnet, network: {}, platform: {}, tunnel: {}", network, cloudPlatform, tunnel); if (network == null || network.getSubnetIds() == null || network.getSubnetIds().isEmpty() || network.getCbSubnets() == null || network.getCbSubnets().isEmpty()) { LOGGER.debug("Check failed, returning null"); return null; } NetworkConnector networkConnector = cloudPlatformConnectors .get(new CloudPlatformVariant(cloudPlatform.name(), cloudPlatform.name())) .networkConnector(); if (networkConnector == null) { LOGGER.warn("Network connector is null for '{}' cloud platform, returning null", cloudPlatform.name()); return null; } SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters .builder() .withTunnel(tunnel) .build(); SubnetSelectionResult subnetSelectionResult = networkConnector .chooseSubnets(network.getCbSubnetValues(), subnetSelectionParameters); CloudSubnet selectedSubnet = subnetSelectionResult.hasResult() ? subnetSelectionResult.getResult().get(0) : fallback(network); return selectedSubnet.getId(); } }
SubnetIdProvider { public String provide(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform) { LOGGER.debug("Choosing subnet, network: {}, platform: {}, tunnel: {}", network, cloudPlatform, tunnel); if (network == null || network.getSubnetIds() == null || network.getSubnetIds().isEmpty() || network.getCbSubnets() == null || network.getCbSubnets().isEmpty()) { LOGGER.debug("Check failed, returning null"); return null; } NetworkConnector networkConnector = cloudPlatformConnectors .get(new CloudPlatformVariant(cloudPlatform.name(), cloudPlatform.name())) .networkConnector(); if (networkConnector == null) { LOGGER.warn("Network connector is null for '{}' cloud platform, returning null", cloudPlatform.name()); return null; } SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters .builder() .withTunnel(tunnel) .build(); SubnetSelectionResult subnetSelectionResult = networkConnector .chooseSubnets(network.getCbSubnetValues(), subnetSelectionParameters); CloudSubnet selectedSubnet = subnetSelectionResult.hasResult() ? subnetSelectionResult.getResult().get(0) : fallback(network); return selectedSubnet.getId(); }  }
SubnetIdProvider { public String provide(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform) { LOGGER.debug("Choosing subnet, network: {}, platform: {}, tunnel: {}", network, cloudPlatform, tunnel); if (network == null || network.getSubnetIds() == null || network.getSubnetIds().isEmpty() || network.getCbSubnets() == null || network.getCbSubnets().isEmpty()) { LOGGER.debug("Check failed, returning null"); return null; } NetworkConnector networkConnector = cloudPlatformConnectors .get(new CloudPlatformVariant(cloudPlatform.name(), cloudPlatform.name())) .networkConnector(); if (networkConnector == null) { LOGGER.warn("Network connector is null for '{}' cloud platform, returning null", cloudPlatform.name()); return null; } SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters .builder() .withTunnel(tunnel) .build(); SubnetSelectionResult subnetSelectionResult = networkConnector .chooseSubnets(network.getCbSubnetValues(), subnetSelectionParameters); CloudSubnet selectedSubnet = subnetSelectionResult.hasResult() ? subnetSelectionResult.getResult().get(0) : fallback(network); return selectedSubnet.getId(); }  String provide(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform); }
SubnetIdProvider { public String provide(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform) { LOGGER.debug("Choosing subnet, network: {}, platform: {}, tunnel: {}", network, cloudPlatform, tunnel); if (network == null || network.getSubnetIds() == null || network.getSubnetIds().isEmpty() || network.getCbSubnets() == null || network.getCbSubnets().isEmpty()) { LOGGER.debug("Check failed, returning null"); return null; } NetworkConnector networkConnector = cloudPlatformConnectors .get(new CloudPlatformVariant(cloudPlatform.name(), cloudPlatform.name())) .networkConnector(); if (networkConnector == null) { LOGGER.warn("Network connector is null for '{}' cloud platform, returning null", cloudPlatform.name()); return null; } SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters .builder() .withTunnel(tunnel) .build(); SubnetSelectionResult subnetSelectionResult = networkConnector .chooseSubnets(network.getCbSubnetValues(), subnetSelectionParameters); CloudSubnet selectedSubnet = subnetSelectionResult.hasResult() ? subnetSelectionResult.getResult().get(0) : fallback(network); return selectedSubnet.getId(); }  String provide(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform);  }