@Test public void testSelectNonHAPrivateSubnetWhenOnlyPrivateAndPublicSubnetPresentedShouldReturnPrivateSubnets() { List<CloudSubnet> subnets = new SubnetBuilder() .withPrivateSubnet(AZ_A) .withPrivateSubnet(AZ_B) .withPrivateSubnet(AZ_B) .withPublicSubnet(AZ_C) .withPublicSubnet(AZ_D) .build(); SubnetSelectionResult chosenSubnets = underTest.filter(subnets, 1); verify(subnetSelectorService, times(1)).collectPublicSubnets(anyCollection()); assertThat(chosenSubnets.getResult(), hasSize(2)); }
@Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPublicSubnets(subnets); Set<String> uniqueAzs = result.stream().map(e -> e.getAvailabilityZone()).collect(Collectors.toSet()); if (uniqueAzs.size() < azCount) { LOGGER.info("There is not enough different AZ in the public subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> privateSubnets = subnetSelectorService.collectPrivateSubnets(subnets); for (CloudSubnet privateSubnet : privateSubnets) { if (!uniqueAzs.contains(privateSubnet.getAvailabilityZone())) { result.add(privateSubnet); uniqueAzs.add(privateSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }
SubnetFilterStrategyMultiplePreferPublic implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPublicSubnets(subnets); Set<String> uniqueAzs = result.stream().map(e -> e.getAvailabilityZone()).collect(Collectors.toSet()); if (uniqueAzs.size() < azCount) { LOGGER.info("There is not enough different AZ in the public subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> privateSubnets = subnetSelectorService.collectPrivateSubnets(subnets); for (CloudSubnet privateSubnet : privateSubnets) { if (!uniqueAzs.contains(privateSubnet.getAvailabilityZone())) { result.add(privateSubnet); uniqueAzs.add(privateSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); } }
SubnetFilterStrategyMultiplePreferPublic implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPublicSubnets(subnets); Set<String> uniqueAzs = result.stream().map(e -> e.getAvailabilityZone()).collect(Collectors.toSet()); if (uniqueAzs.size() < azCount) { LOGGER.info("There is not enough different AZ in the public subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> privateSubnets = subnetSelectorService.collectPrivateSubnets(subnets); for (CloudSubnet privateSubnet : privateSubnets) { if (!uniqueAzs.contains(privateSubnet.getAvailabilityZone())) { result.add(privateSubnet); uniqueAzs.add(privateSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }  }
SubnetFilterStrategyMultiplePreferPublic implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPublicSubnets(subnets); Set<String> uniqueAzs = result.stream().map(e -> e.getAvailabilityZone()).collect(Collectors.toSet()); if (uniqueAzs.size() < azCount) { LOGGER.info("There is not enough different AZ in the public subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> privateSubnets = subnetSelectorService.collectPrivateSubnets(subnets); for (CloudSubnet privateSubnet : privateSubnets) { if (!uniqueAzs.contains(privateSubnet.getAvailabilityZone())) { result.add(privateSubnet); uniqueAzs.add(privateSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }  @Override SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount); @Override SubnetFilterStrategyType getType(); }
SubnetFilterStrategyMultiplePreferPublic implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPublicSubnets(subnets); Set<String> uniqueAzs = result.stream().map(e -> e.getAvailabilityZone()).collect(Collectors.toSet()); if (uniqueAzs.size() < azCount) { LOGGER.info("There is not enough different AZ in the public subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> privateSubnets = subnetSelectorService.collectPrivateSubnets(subnets); for (CloudSubnet privateSubnet : privateSubnets) { if (!uniqueAzs.contains(privateSubnet.getAvailabilityZone())) { result.add(privateSubnet); uniqueAzs.add(privateSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }  @Override SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount); @Override SubnetFilterStrategyType getType();  }