use of software.amazon.awssdk.services.ec2.model.AvailabilityZone in project GNS by MobilityFirst.
the class AWSStatusCheck method main.
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
init();
/*
* Amazon EC2
*/
for (String endpoint : endpoints) {
try {
ec2.setEndpoint(endpoint);
System.out.println("**** Endpoint: " + endpoint);
DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones.");
for (AvailabilityZone zone : availabilityZonesResult.getAvailabilityZones()) {
System.out.println(zone.getZoneName());
}
DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
List<Reservation> reservations = describeInstancesRequest.getReservations();
Set<Instance> instances = new HashSet<Instance>();
System.out.println("Instances: ");
for (Reservation reservation : reservations) {
for (Instance instance : reservation.getInstances()) {
instances.add(instance);
System.out.println(instance.getPublicDnsName() + " is " + instance.getState().getName());
}
}
System.out.println("Security groups: ");
DescribeSecurityGroupsResult describeSecurityGroupsResult = ec2.describeSecurityGroups();
for (SecurityGroup securityGroup : describeSecurityGroupsResult.getSecurityGroups()) {
System.out.println(securityGroup.getGroupName());
}
//System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running.");
} catch (AmazonServiceException ase) {
System.out.println("Caught Exception: " + ase.getMessage());
System.out.println("Reponse Status Code: " + ase.getStatusCode());
System.out.println("Error Code: " + ase.getErrorCode());
System.out.println("Request ID: " + ase.getRequestId());
}
/*
* Amazon SimpleDB
*
*/
try {
ListDomainsRequest sdbRequest = new ListDomainsRequest().withMaxNumberOfDomains(100);
ListDomainsResult sdbResult = sdb.listDomains(sdbRequest);
int totalItems = 0;
for (String domainName : sdbResult.getDomainNames()) {
DomainMetadataRequest metadataRequest = new DomainMetadataRequest().withDomainName(domainName);
DomainMetadataResult domainMetadata = sdb.domainMetadata(metadataRequest);
totalItems += domainMetadata.getItemCount();
}
System.out.println("You have " + sdbResult.getDomainNames().size() + " Amazon SimpleDB domain(s)" + "containing a total of " + totalItems + " items.");
} catch (AmazonServiceException ase) {
System.out.println("Caught Exception: " + ase.getMessage());
System.out.println("Reponse Status Code: " + ase.getStatusCode());
System.out.println("Error Code: " + ase.getErrorCode());
System.out.println("Request ID: " + ase.getRequestId());
}
/*
* Amazon S3
*.
*/
try {
List<Bucket> buckets = s3.listBuckets();
long totalSize = 0;
int totalItems = 0;
for (Bucket bucket : buckets) {
/*
* In order to save bandwidth, an S3 object listing does not
* contain every object in the bucket; after a certain point the
* S3ObjectListing is truncated, and further pages must be
* obtained with the AmazonS3Client.listNextBatchOfObjects()
* method.
*/
ObjectListing objects = s3.listObjects(bucket.getName());
do {
for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
totalSize += objectSummary.getSize();
totalItems++;
}
objects = s3.listNextBatchOfObjects(objects);
} while (objects.isTruncated());
}
System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s), " + "containing " + 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());
}
}
}
use of software.amazon.awssdk.services.ec2.model.AvailabilityZone in project GNS by MobilityFirst.
the class AWSEC2 method describeAvailabilityZones.
/**
* Describe Availability Zones
*
* @param ec2
*/
public static void describeAvailabilityZones(AmazonEC2 ec2) {
StringBuilder output = new StringBuilder();
String prefix = currentTab + "Availability Zones: ";
DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
prefix = prefix.concat(" [" + availabilityZonesResult.getAvailabilityZones().size() + " total] ");
for (AvailabilityZone zone : availabilityZonesResult.getAvailabilityZones()) {
output.append(prefix);
prefix = ", ";
output.append(zone.getZoneName());
}
System.out.println(output);
}
use of software.amazon.awssdk.services.ec2.model.AvailabilityZone in project herd by FINRAOS.
the class MockAvailabilityZone method toAwsObject.
/**
* Converts this object into an AWS equivalent object.
*
* @return A new equivalent AWS object
*/
public AvailabilityZone toAwsObject() {
AvailabilityZone availabilityZone = new AvailabilityZone();
availabilityZone.setRegionName(regionName);
availabilityZone.setZoneName(zoneName);
return availabilityZone;
}
use of software.amazon.awssdk.services.ec2.model.AvailabilityZone in project photon-model by vmware.
the class AWSDiskService method createDisk.
/**
* Create a volume on aws that represents the requested disk.
*/
private void createDisk(AWSDiskContext context) {
if (context.diskRequest.isMockRequest) {
Volume vol = getMockVolume();
updateDiskState(vol, context, AwsDiskStage.FINISHED);
return;
}
DiskState diskState = context.disk;
// add endpointLinks
AdapterUtils.addToEndpointLinks(diskState, context.disk.endpointLink);
if (diskState.capacityMBytes <= 0) {
String message = "Disk size has to be positive";
this.logWarning(() -> "[AWSDiskService] " + message);
throw new IllegalArgumentException(message);
}
if (diskState.customProperties != null && diskState.customProperties.get(DEVICE_TYPE) != null && diskState.customProperties.get(DEVICE_TYPE).equals(AWSConstants.AWSStorageType.INSTANCE_STORE.getName())) {
String message = "Independent Instance Store disk cannot be created.";
this.logWarning(() -> "[AWSDiskService] " + message);
throw new IllegalArgumentException(message);
}
CreateVolumeRequest req = new CreateVolumeRequest();
String zoneId = diskState.zoneId;
if (zoneId == null) {
List<AvailabilityZone> availabilityZoneList = context.client.getAvailabilityZones();
if (availabilityZoneList.isEmpty()) {
String message = String.format("No zones are available in the region %s:", diskState.regionId);
this.logSevere(() -> "[AWSDiskService] " + message);
throw new IllegalArgumentException(message);
}
zoneId = availabilityZoneList.get(0).getZoneName();
}
// set availability zone
req.withAvailabilityZone(zoneId);
// set volume size
int diskSize = (int) diskState.capacityMBytes / 1024;
req.withSize(diskSize);
// set encrypted field
Boolean encrypted = diskState.encrypted == null ? false : diskState.encrypted;
req.withEncrypted(encrypted);
AWSUtils.setEbsDefaultsIfNotSet(diskState, Boolean.TRUE);
validateSizeSupportedByVolumeType(diskSize, diskState.customProperties.get(VOLUME_TYPE));
// set volume type
if (diskState.customProperties.containsKey(VOLUME_TYPE)) {
req.withVolumeType(diskState.customProperties.get(VOLUME_TYPE));
}
// set iops
String diskIops = diskState.customProperties.get(DISK_IOPS);
if (diskIops != null && !diskIops.isEmpty()) {
int iops = Integer.parseInt(diskIops);
if (iops > diskSize * MAX_IOPS_PER_GiB) {
String info = String.format("[AWSDiskService] Requested IOPS (%s) exceeds" + " the maximum value supported by %sGiB disk. Continues " + "provisioning the disk with %s iops", iops, diskSize, diskSize * MAX_IOPS_PER_GiB);
this.logInfo(() -> info);
iops = diskSize * MAX_IOPS_PER_GiB;
}
req.withIops(iops);
}
AsyncHandler<CreateVolumeRequest, CreateVolumeResult> creationHandler = new AWSDiskCreationHandler(this, context);
context.client.createVolume(req, creationHandler);
}
use of software.amazon.awssdk.services.ec2.model.AvailabilityZone in project aws-doc-sdk-examples by awsdocs.
the class DescribeRegionsAndZones method main.
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]
}
Aggregations