Search in sources :

Example 16 with AvailabilityZone

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();
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) Subnet(com.amazonaws.services.ec2.model.Subnet) HashSet(java.util.HashSet)

Example 17 with AvailabilityZone

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);
}
Also used : CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest) Volume(com.amazonaws.services.ec2.model.Volume) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) AvailabilityZone(com.amazonaws.services.ec2.model.AvailabilityZone)

Example 18 with AvailabilityZone

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);
    }
}
Also used : DescribeAvailabilityZonesResponse(software.amazon.awssdk.services.ec2.model.DescribeAvailabilityZonesResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) Region(software.amazon.awssdk.services.ec2.model.Region) AvailabilityZone(software.amazon.awssdk.services.ec2.model.AvailabilityZone) DescribeRegionsResponse(software.amazon.awssdk.services.ec2.model.DescribeRegionsResponse)

Example 19 with AvailabilityZone

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]
}
Also used : DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) Region(com.amazonaws.services.ec2.model.Region) AvailabilityZone(com.amazonaws.services.ec2.model.AvailabilityZone) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)

Example 20 with AvailabilityZone

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);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) InternetGatewayAttachment(com.amazonaws.services.ec2.model.InternetGatewayAttachment) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) CloudGateWay(com.sequenceiq.cloudbreak.cloud.model.CloudGateWay) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)10 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)5 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)4 HashMap (java.util.HashMap)4 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)3 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)3 SpotPrice (com.amazonaws.services.ec2.model.SpotPrice)3 Subnet (com.amazonaws.services.ec2.model.Subnet)3 List (java.util.List)3 CreateVolumeRequest (com.amazonaws.services.ec2.model.CreateVolumeRequest)2 DescribeAvailabilityZonesRequest (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)2 DescribeSpotPriceHistoryResult (com.amazonaws.services.ec2.model.DescribeSpotPriceHistoryResult)2 Region (com.amazonaws.services.ec2.model.Region)2 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)2 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)2 Region (com.sequenceiq.cloudbreak.cloud.model.Region)2 Collections.singletonList (java.util.Collections.singletonList)2 Test (org.junit.Test)2