com.amazonaws.services.ec2.model.DescribeRegionsResult Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.DescribeRegionsResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EC2FleetCloudTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void descriptorImpl_doFillRegionItems_returnStaticRegionsAndDynamic() {
    AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class);
    when(ec2Api.connect(anyString(), nullable(String.class), nullable(String.class))).thenReturn(amazonEC2Client);
    when(amazonEC2Client.describeRegions()).thenReturn(new DescribeRegionsResult().withRegions(new Region().withRegionName("dynamic-region")));

    ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillRegionItems("");

    Assert.assertThat(r.size(), Matchers.greaterThan(0));
    Assert.assertThat(r.toString(), Matchers.containsString("dynamic-region"));
    assertEquals(RegionUtils.getRegions().size() + 1, r.size());
}
 
Example #2
Source File: EC2FleetCloudTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void descriptorImpl_doFillRegionItems_returnConsistOrderBetweenCalls() {
    AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class);
    when(ec2Api.connect(anyString(), nullable(String.class), nullable(String.class))).thenReturn(amazonEC2Client);
    when(amazonEC2Client.describeRegions()).thenReturn(new DescribeRegionsResult().withRegions(new Region().withRegionName("dynamic-region")));

    ListBoxModel r1 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems("");
    ListBoxModel r2 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems("");
    ListBoxModel r3 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems("");

    assertEquals(r1.toString(), r2.toString());
    assertEquals(r2.toString(), r3.toString());
}
 
Example #3
Source File: DescribeRegionsAndZones.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    {
        final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

// snippet-start:[ec2.java1.describe_region_and_zones.regions]
        DescribeRegionsResult regions_response = ec2.describeRegions();

        for(Region region : regions_response.getRegions()) {
            System.out.printf(
                "Found region %s " +
                "with endpoint %s",
                region.getRegionName(),
                region.getEndpoint());
        }
// snippet-end:[ec2.java1.describe_region_and_zones.regions]

// snippet-start:[ec2.java1.describe_region_and_zones.zones]
        DescribeAvailabilityZonesResult zones_response =
            ec2.describeAvailabilityZones();

        for(AvailabilityZone zone : zones_response.getAvailabilityZones()) {
            System.out.printf(
                "Found availability zone %s " +
                "with status %s " +
                "in region %s",
                zone.getZoneName(),
                zone.getState(),
                zone.getRegionName());
        }
// snippet-end:[ec2.java1.describe_region_and_zones.zones]
    }
 
Example #4
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@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 (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);
}
 
Example #5
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private DescribeRegionsResult describeRegionsResult(AmazonEC2Client ec2Client) {
    LOGGER.debug("Getting regions");
    try {
        DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
        return ec2Client.describeRegions(describeRegionsRequest);
    } catch (AmazonEC2Exception e) {
        LOGGER.info("Failed to retrieve regions!", e);
    }
    return new DescribeRegionsResult();
}