@Test void testProvideShouldReturnAnySubnetWhenResultIsEmptyAndNoError() { setupConnectorWithSelectionResult(List.of()); NetworkDto networkDto = NetworkDto.builder() .withCbSubnets(Map.of( "AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2"))) .withSubnetMetas(Map.of( "AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2") )) .build(); String actual = underTest.provide(networkDto, Tunnel.DIRECT, CloudPlatform.AWS); Assertions.assertNotNull(actual); }
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);  }