@Test public void regionsShouldBeFilteredByEnabledRegionsAndEnabledAvailabilityZones() { setUpRegions(); CloudRegions cloudRegions = underTest.regions(new CloudCredential("crn", "aws-credential"), region(REGION_NAME), Map.of(), true); assertThat(cloudRegions.getCloudRegions()) .containsKey(region(REGION_NAME)) .doesNotContainKey(region(NOT_ENABLED_REGION_NAME)); assertThat(cloudRegions.getCloudRegions().get(region(REGION_NAME))) .contains(availabilityZone(AZ_NAME)) .doesNotContain(availabilityZone(NOT_ENABLED_AZ_NAME)); }
@Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded) { AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential); Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>(); Map<Region, String> displayNames = new HashMap<>(); Map<Region, Coordinate> coordinates = new HashMap<>(); DescribeRegionsResult describeRegionsResult = describeRegionsResult(ec2Client); String defaultRegion = awsDefaultZoneProvider.getDefaultZone(cloudCredential); for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) { if (!enabledRegions.contains(region(awsRegion.getRegionName()))) { continue; } if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) { try { fetchAZsIfNeeded(availabilityZonesNeeded, ec2Client, regionListMap, awsRegion, cloudCredential); } catch (AmazonEC2Exception e) { LOGGER.info("Failed to retrieve AZ from Region: {}!", awsRegion.getRegionName(), e); } addDisplayName(displayNames, awsRegion); addCoordinate(coordinates, awsRegion); } } if (region != null && !Strings.isNullOrEmpty(region.value())) { defaultRegion = region.value(); } return new CloudRegions(regionListMap, displayNames, coordinates, defaultRegion, true); }
AwsPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded) { AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential); Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>(); Map<Region, String> displayNames = new HashMap<>(); Map<Region, Coordinate> coordinates = new HashMap<>(); DescribeRegionsResult describeRegionsResult = describeRegionsResult(ec2Client); String defaultRegion = awsDefaultZoneProvider.getDefaultZone(cloudCredential); for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) { if (!enabledRegions.contains(region(awsRegion.getRegionName()))) { continue; } if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) { try { fetchAZsIfNeeded(availabilityZonesNeeded, ec2Client, regionListMap, awsRegion, cloudCredential); } catch (AmazonEC2Exception e) { LOGGER.info("Failed to retrieve AZ from Region: {}!", awsRegion.getRegionName(), e); } addDisplayName(displayNames, awsRegion); addCoordinate(coordinates, awsRegion); } } if (region != null && !Strings.isNullOrEmpty(region.value())) { defaultRegion = region.value(); } return new CloudRegions(regionListMap, displayNames, coordinates, defaultRegion, true); } }
AwsPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded) { AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential); Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>(); Map<Region, String> displayNames = new HashMap<>(); Map<Region, Coordinate> coordinates = new HashMap<>(); DescribeRegionsResult describeRegionsResult = describeRegionsResult(ec2Client); String defaultRegion = awsDefaultZoneProvider.getDefaultZone(cloudCredential); for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) { if (!enabledRegions.contains(region(awsRegion.getRegionName()))) { continue; } if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) { try { fetchAZsIfNeeded(availabilityZonesNeeded, ec2Client, regionListMap, awsRegion, cloudCredential); } catch (AmazonEC2Exception e) { LOGGER.info("Failed to retrieve AZ from Region: {}!", awsRegion.getRegionName(), e); } addDisplayName(displayNames, awsRegion); addCoordinate(coordinates, awsRegion); } } if (region != null && !Strings.isNullOrEmpty(region.value())) { defaultRegion = region.value(); } return new CloudRegions(regionListMap, displayNames, coordinates, defaultRegion, true); }  }
AwsPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded) { AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential); Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>(); Map<Region, String> displayNames = new HashMap<>(); Map<Region, Coordinate> coordinates = new HashMap<>(); DescribeRegionsResult describeRegionsResult = describeRegionsResult(ec2Client); String defaultRegion = awsDefaultZoneProvider.getDefaultZone(cloudCredential); for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) { if (!enabledRegions.contains(region(awsRegion.getRegionName()))) { continue; } if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) { try { fetchAZsIfNeeded(availabilityZonesNeeded, ec2Client, regionListMap, awsRegion, cloudCredential); } catch (AmazonEC2Exception e) { LOGGER.info("Failed to retrieve AZ from Region: {}!", awsRegion.getRegionName(), e); } addDisplayName(displayNames, awsRegion); addCoordinate(coordinates, awsRegion); } } if (region != null && !Strings.isNullOrEmpty(region.value())) { defaultRegion = region.value(); } return new CloudRegions(regionListMap, displayNames, coordinates, defaultRegion, true); }  @PostConstruct void init(); String resourceDefinition(String resource); @Override CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded); void addDisplayName(Map<Region, String> displayNames, com.amazonaws.services.ec2.model.Region awsRegion); void addCoordinate(Map<Region, Coordinate> coordinates, com.amazonaws.services.ec2.model.Region awsRegion); @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName() + 'distrox'") CloudVmTypes virtualMachinesForDistroX(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudAccessConfigs accessConfigs(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudEncryptionKeys encryptionKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudNoSqlTables noSqlTables(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudResourceGroups resourceGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters); }
AwsPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded) { AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential); Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>(); Map<Region, String> displayNames = new HashMap<>(); Map<Region, Coordinate> coordinates = new HashMap<>(); DescribeRegionsResult describeRegionsResult = describeRegionsResult(ec2Client); String defaultRegion = awsDefaultZoneProvider.getDefaultZone(cloudCredential); for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) { if (!enabledRegions.contains(region(awsRegion.getRegionName()))) { continue; } if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) { try { fetchAZsIfNeeded(availabilityZonesNeeded, ec2Client, regionListMap, awsRegion, cloudCredential); } catch (AmazonEC2Exception e) { LOGGER.info("Failed to retrieve AZ from Region: {}!", awsRegion.getRegionName(), e); } addDisplayName(displayNames, awsRegion); addCoordinate(coordinates, awsRegion); } } if (region != null && !Strings.isNullOrEmpty(region.value())) { defaultRegion = region.value(); } return new CloudRegions(regionListMap, displayNames, coordinates, defaultRegion, true); }  @PostConstruct void init(); String resourceDefinition(String resource); @Override CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded); void addDisplayName(Map<Region, String> displayNames, com.amazonaws.services.ec2.model.Region awsRegion); void addCoordinate(Map<Region, Coordinate> coordinates, com.amazonaws.services.ec2.model.Region awsRegion); @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName() + 'distrox'") CloudVmTypes virtualMachinesForDistroX(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudAccessConfigs accessConfigs(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudEncryptionKeys encryptionKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudNoSqlTables noSqlTables(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudResourceGroups resourceGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters);  }