use of com.amazonaws.services.ec2.model.AvailabilityZone in project herd by FINRAOS.
the class Ec2DaoImpl method getAvailabilityZonesForSubnetIds.
/**
* 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();
}
use of com.amazonaws.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 com.amazonaws.services.ec2.model.AvailabilityZone in project aws-doc-sdk-examples by awsdocs.
the class DescribeRegionsAndZones method describeEC2RegionsAndZones.
// snippet-start:[ec2.java2.describe_region_and_zones.main]
public static void describeEC2RegionsAndZones(Ec2Client ec2) {
// snippet-start:[ec2.java2.describe_region_and_zones.region]
try {
DescribeRegionsResponse regionsResponse = ec2.describeRegions();
for (Region region : regionsResponse.regions()) {
System.out.printf("Found Region %s " + "with endpoint %s", region.regionName(), region.endpoint());
System.out.println();
// snippet-end:[ec2.java2.describe_region_and_zones.region]
}
// snippet-start:[ec2.java2.describe_region_and_zones.avail_zone]
DescribeAvailabilityZonesResponse zonesResponse = ec2.describeAvailabilityZones();
for (AvailabilityZone zone : zonesResponse.availabilityZones()) {
System.out.printf("Found Availability Zone %s " + "with status %s " + "in region %s", zone.zoneName(), zone.state(), zone.regionName());
System.out.println();
// snippet-end:[ec2.java2.describe_region_and_zones.avail_zone]
}
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of com.amazonaws.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]
}
use of com.amazonaws.services.ec2.model.AvailabilityZone in project cloudbreak by hortonworks.
the class AwsPlatformResources method gateways.
@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
CloudRegions regions = regions(cloudCredential, region, filters);
for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || regionListEntry.getKey().value().equals(region.value())) {
ec2Client.setRegion(RegionUtils.getRegion(regionListEntry.getKey().value()));
DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest();
DescribeInternetGatewaysResult describeInternetGatewaysResult = ec2Client.describeInternetGateways(describeInternetGatewaysRequest);
Set<CloudGateWay> gateWays = new HashSet<>();
for (InternetGateway internetGateway : describeInternetGatewaysResult.getInternetGateways()) {
CloudGateWay cloudGateWay = new CloudGateWay();
cloudGateWay.setId(internetGateway.getInternetGatewayId());
cloudGateWay.setName(internetGateway.getInternetGatewayId());
Collection<String> vpcs = new ArrayList<>();
for (InternetGatewayAttachment internetGatewayAttachment : internetGateway.getAttachments()) {
vpcs.add(internetGatewayAttachment.getVpcId());
}
Map<String, Object> properties = new HashMap<>();
properties.put("attachment", vpcs);
cloudGateWay.setProperties(properties);
gateWays.add(cloudGateWay);
}
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
resultCloudGateWayMap.put(availabilityZone.value(), gateWays);
}
}
}
return new CloudGateWays(resultCloudGateWayMap);
}
Aggregations