@Test public void testFilterPrivateSubnetWhenOnlyPrivateAndPublicSubnetPresentedShouldReturnPrivateSubnets() { 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, 3); verify(subnetSelectorService, times(1)).collectPrivateSubnets(anyCollection()); assertThat(chosenSubnets.getResult(), hasSize(4)); }
@Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPrivateSubnets(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 private subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> publicSubnets = subnetSelectorService.collectPublicSubnets(subnets); for (CloudSubnet publicSubnet : publicSubnets) { if (!uniqueAzs.contains(publicSubnet.getAvailabilityZone())) { result.add(publicSubnet); uniqueAzs.add(publicSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }
SubnetFilterStrategyMultiplePreferPrivate implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPrivateSubnets(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 private subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> publicSubnets = subnetSelectorService.collectPublicSubnets(subnets); for (CloudSubnet publicSubnet : publicSubnets) { if (!uniqueAzs.contains(publicSubnet.getAvailabilityZone())) { result.add(publicSubnet); uniqueAzs.add(publicSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); } }
SubnetFilterStrategyMultiplePreferPrivate implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPrivateSubnets(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 private subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> publicSubnets = subnetSelectorService.collectPublicSubnets(subnets); for (CloudSubnet publicSubnet : publicSubnets) { if (!uniqueAzs.contains(publicSubnet.getAvailabilityZone())) { result.add(publicSubnet); uniqueAzs.add(publicSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }  }
SubnetFilterStrategyMultiplePreferPrivate implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPrivateSubnets(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 private subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> publicSubnets = subnetSelectorService.collectPublicSubnets(subnets); for (CloudSubnet publicSubnet : publicSubnets) { if (!uniqueAzs.contains(publicSubnet.getAvailabilityZone())) { result.add(publicSubnet); uniqueAzs.add(publicSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }  @Override SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount); @Override SubnetFilterStrategyType getType(); }
SubnetFilterStrategyMultiplePreferPrivate implements SubnetFilterStrategy { @Override public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) { List<CloudSubnet> result = subnetSelectorService.collectPrivateSubnets(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 private subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets); List<CloudSubnet> publicSubnets = subnetSelectorService.collectPublicSubnets(subnets); for (CloudSubnet publicSubnet : publicSubnets) { if (!uniqueAzs.contains(publicSubnet.getAvailabilityZone())) { result.add(publicSubnet); uniqueAzs.add(publicSubnet.getAvailabilityZone()); if (uniqueAzs.size() >= azCount) { break; } } } } return new SubnetSelectionResult(result); }  @Override SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount); @Override SubnetFilterStrategyType getType();  }