com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult.
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: Ec2DaoImpl.java From herd with Apache License 2.0 | 6 votes |
/** * This implementation uses the DescribeAvailabilityZones API to get the list of AZs. */ @Override public List<AvailabilityZone> getAvailabilityZonesForSubnetIds(Collection<Subnet> subnets, AwsParamsDto awsParamsDto) { Set<String> zoneNames = new HashSet<>(); for (Subnet subnet : subnets) { zoneNames.add(subnet.getAvailabilityZone()); } AmazonEC2Client ec2Client = getEc2Client(awsParamsDto); DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest(); describeAvailabilityZonesRequest.setZoneNames(zoneNames); DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Operations.describeAvailabilityZones(ec2Client, describeAvailabilityZonesRequest); return describeAvailabilityZonesResult.getAvailabilityZones(); }
Example #2
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public List<AvailabilityZone> getAvailabilityZones(Region region) throws Exception { OperationStats op = new OperationStats("ec2InstanceStore", "getAvailabilityZones"); try { DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest(); DescribeAvailabilityZonesResult result = getClient(region).describeAvailabilityZones(); List<AvailabilityZone> ret = result.getAvailabilityZones(); op.succeed(); return ret; } catch (Exception ex) { op.failed(); throw ex; } }
Example #3
Source File: DescribeRegionsAndZones.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
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: MockEc2OperationsImpl.java From herd with Apache License 2.0 | 5 votes |
@Override public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest) { List<AvailabilityZone> availabilityZones = new ArrayList<>(); List<String> requestedZoneNames = describeAvailabilityZonesRequest.getZoneNames(); // add all AZ if request is empty (this is AWS behavior) if (requestedZoneNames.isEmpty()) { requestedZoneNames.addAll(mockAvailabilityZones.keySet()); } for (String requestedZoneName : requestedZoneNames) { // ignore AZ name which does not exist (this is AWS behavior) MockAvailabilityZone mockAvailabilityZone = mockAvailabilityZones.get(requestedZoneName); if (mockAvailabilityZone != null) { availabilityZones.add(mockAvailabilityZone.toAwsObject()); } } DescribeAvailabilityZonesResult describeAvailabilityZonesResult = new DescribeAvailabilityZonesResult(); describeAvailabilityZonesResult.setAvailabilityZones(availabilityZones); return describeAvailabilityZonesResult; }
Example #5
Source File: AwsDescribeServiceImpl.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public List<AvailabilityZone> getAvailabilityZones(Long userNo, Long platformNo) { // アベイラビリティゾーンを取得 AwsProcessClient awsProcessClient = awsProcessClientFactory.createAwsProcessClient(userNo, platformNo); DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest(); DescribeAvailabilityZonesResult result = awsProcessClient.getEc2Client().describeAvailabilityZones(request); List<AvailabilityZone> availabilityZones = result.getAvailabilityZones(); // ソート Collections.sort(availabilityZones, Comparators.COMPARATOR_AVAILABILITY_ZONE); return availabilityZones; }
Example #6
Source File: AwsCommonProcess.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
public List<AvailabilityZone> describeAvailabilityZones(AwsProcessClient awsProcessClient) { DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest(); DescribeAvailabilityZonesResult result = awsProcessClient.getEc2Client().describeAvailabilityZones(request); List<AvailabilityZone> availabilityZones = result.getAvailabilityZones(); return availabilityZones; }
Example #7
Source File: AWSSdkClient.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/*** * Get availability zones in an Amazon AWS region * * @return List of availability zones */ public List<AvailabilityZone> getAvailabilityZones() { final AmazonEC2 amazonEC2 = getEc2Client(); final DescribeAvailabilityZonesResult describeAvailabilityZonesResult = amazonEC2.describeAvailabilityZones(); final List<AvailabilityZone> availabilityZones = describeAvailabilityZonesResult.getAvailabilityZones(); LOGGER.info("Found: " + availabilityZones.size() + " availability zone"); return availabilityZones; }
Example #8
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 5 votes |
private DescribeAvailabilityZonesResult describeAvailabilityZonesResult(AmazonEC2Client ec2Client, com.amazonaws.services.ec2.model.Region awsRegion) { try { DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = getDescribeAvailabilityZonesRequest(ec2Client, awsRegion); return ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest); } catch (AmazonEC2Exception e) { LOGGER.info("Failed to retrieve AZ from Region: {}!", awsRegion.getRegionName(), e); } return new DescribeAvailabilityZonesResult(); }
Example #9
Source File: AwsAvailabilityZoneProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Cacheable(cacheNames = "cloudResourceAzCache", key = "{ #cloudCredential?.id, #awsRegion.regionName }") public List<AvailabilityZone> describeAvailabilityZones(CloudCredential cloudCredential, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest, AmazonEC2Client ec2Client, com.amazonaws.services.ec2.model.Region awsRegion) { DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest); return describeAvailabilityZonesResult.getAvailabilityZones(); }
Example #10
Source File: AwsSubnetRequestProviderTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private AmazonEC2Client createEc2Client(List<AvailabilityZone> availabilityZones) { AmazonEC2Client ec2Client = Mockito.mock(AmazonEC2Client.class); DescribeAvailabilityZonesResult result = new DescribeAvailabilityZonesResult(); result.setAvailabilityZones(availabilityZones); Mockito.when(ec2Client.describeAvailabilityZones()).thenReturn(result); return ec2Client; }
Example #11
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Describe AvailabilityZone. * * @return AvailabilityZone */ protected final AvailabilityZone getAvailiablityZones() { AvailabilityZone availabilityZone = null; DescribeAvailabilityZonesResult result = amazonEC2Client.describeAvailabilityZones(); if (result != null && !result.getAvailabilityZones().isEmpty()) { availabilityZone = result.getAvailabilityZones().get(0); } return availabilityZone; }
Example #12
Source File: Ec2OperationsImpl.java From herd with Apache License 2.0 | 4 votes |
@Override public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest) { return ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest); }
Example #13
Source File: AwsSdkSample.java From aws-sdk-java-archetype with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { System.out.println("==========================================="); System.out.println("Welcome to the AWS Java SDK!"); System.out.println("==========================================="); init(); try { /* * The Amazon EC2 client allows you to easily launch and configure * computing capacity in AWS datacenters. * * In this sample, we use the EC2 client to list the availability zones * in a region, and then list the instances running in those zones. */ DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones(); List<AvailabilityZone> availabilityZones = availabilityZonesResult.getAvailabilityZones(); System.out.println("You have access to " + availabilityZones.size() + " availability zones:"); for (AvailabilityZone zone : availabilityZones) { System.out.println(" - " + zone.getZoneName() + " (" + zone.getRegionName() + ")"); } DescribeInstancesResult describeInstancesResult = ec2.describeInstances(); Set<Instance> instances = new HashSet<Instance>(); for (Reservation reservation : describeInstancesResult.getReservations()) { instances.addAll(reservation.getInstances()); } System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running."); /* * The Amazon S3 client allows you to manage and configure buckets * and to upload and download data. * * In this sample, we use the S3 client to list all the buckets in * your account, and then iterate over the object metadata for all * objects in one bucket to calculate the total object count and * space usage for that one bucket. Note that this sample only * retrieves the object's metadata and doesn't actually download the * object's content. * * In addition to the low-level Amazon S3 client in the SDK, there * is also a high-level TransferManager API that provides * asynchronous management of uploads and downloads with an easy to * use API: * http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferManager.html */ List<Bucket> buckets = s3.listBuckets(); System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s)."); if (buckets.size() > 0) { Bucket bucket = buckets.get(0); long totalSize = 0; long totalItems = 0; /* * The S3Objects and S3Versions classes provide convenient APIs * for iterating over the contents of your buckets, without * having to manually deal with response pagination. */ for (S3ObjectSummary objectSummary : S3Objects.inBucket(s3, bucket.getName())) { totalSize += objectSummary.getSize(); totalItems++; } System.out.println("The bucket '" + bucket.getName() + "' contains "+ totalItems + " objects " + "with a total size of " + totalSize + " bytes."); } } catch (AmazonServiceException ase) { /* * AmazonServiceExceptions represent an error response from an AWS * services, i.e. your request made it to AWS, but the AWS service * either found it invalid or encountered an error trying to execute * it. */ System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { /* * AmazonClientExceptions represent an error that occurred inside * the client on the local host, either while trying to send the * request to AWS or interpret the response. For example, if no * network connection is available, the client won't be able to * connect to AWS to execute a request and will throw an * AmazonClientException. */ System.out.println("Error Message: " + ace.getMessage()); } }
Example #14
Source File: Ec2Operations.java From herd with Apache License 2.0 | 2 votes |
/** * {@link AmazonEC2#describeAvailabilityZones()} * * @param ec2Client {@link AmazonEC2} to use. * @param describeAvailabilityZonesRequest The request object. * @return {@link DescribeAvailabilityZonesResult} */ public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest);