@Test @DisplayName("when retrieveSubnetMetadata has called with Environment and the platform is neither AWS or AZURE then the result will be combined " + "from the network ids and no need for fetching anything from the provider") void testRetrieveSubnetMetadataByEnvironmentWhenPlatformIsNeitherAzureOrAwsThenNoNeedForFetchingAnythingFromProvider() { when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET); Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironment, testNetworkDto); byte expectedAmountOfResultCloudSubnet = 1; assertNotNull(result); assertEquals(expectedAmountOfResultCloudSubnet, result.size(), "The amount of result CloudSubnet(s) must be: " + expectedAmountOfResultCloudSubnet); assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), result.get(result.keySet().iterator().next()).getId()); verify(platformParameterService, times(0)).getCloudNetworks(any()); }
public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } CloudNetworkService(PlatformParameterService platformParameterService); }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } CloudNetworkService(PlatformParameterService platformParameterService); Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network); Map<String, CloudSubnet> retrieveSubnetMetadata(Environment environment, NetworkDto network); }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } CloudNetworkService(PlatformParameterService platformParameterService); Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network); Map<String, CloudSubnet> retrieveSubnetMetadata(Environment environment, NetworkDto network);  }