Search in sources :

Example 21 with AvailabilityZone

use of com.amazonaws.services.ec2.model.AvailabilityZone in project cloudbreak by hortonworks.

the class AwsPlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
    Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
    DescribeRegionsResult describeRegionsResult = ec2Client.describeRegions(describeRegionsRequest);
    String defaultRegion = awsZoneParameterDefault;
    for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) {
        if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) {
            DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
            ec2Client.setRegion(RegionUtils.getRegion(awsRegion.getRegionName()));
            Filter filter = new Filter();
            filter.setName("region-name");
            Collection<String> list = new ArrayList<>();
            list.add(awsRegion.getRegionName());
            filter.setValues(list);
            describeAvailabilityZonesRequest.withFilters(filter);
            DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
            List<AvailabilityZone> tmpAz = new ArrayList<>();
            for (com.amazonaws.services.ec2.model.AvailabilityZone availabilityZone : describeAvailabilityZonesResult.getAvailabilityZones()) {
                tmpAz.add(availabilityZone(availabilityZone.getZoneName()));
            }
            regionListMap.put(region(awsRegion.getRegionName()), tmpAz);
            DisplayName displayName = regionDisplayNames.get(region(awsRegion.getRegionName()));
            if (displayName == null || Strings.isNullOrEmpty(displayName.value())) {
                displayNames.put(region(awsRegion.getRegionName()), awsRegion.getRegionName());
            } else {
                displayNames.put(region(awsRegion.getRegionName()), displayName.value());
            }
        }
    }
    if (region != null && !Strings.isNullOrEmpty(region.value())) {
        defaultRegion = region.value();
    }
    return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) HashMap(java.util.HashMap) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) Filter(com.amazonaws.services.ec2.model.Filter) DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 22 with AvailabilityZone

use of com.amazonaws.services.ec2.model.AvailabilityZone in project cloudbreak by hortonworks.

the class EncryptedSnapshotPreparator method prepareCreateVolumeRequest.

private CreateVolumeRequest prepareCreateVolumeRequest(AuthenticatedContext ac, AwsInstanceView awsInstanceView, AmazonEC2 client) {
    String availabilityZone = prepareDescribeAvailabilityZonesResult(ac, client);
    CreateVolumeRequest createVolumeRequest = new CreateVolumeRequest().withSize(VOLUME_SIZE).withAvailabilityZone(availabilityZone).withEncrypted(true);
    if (awsInstanceView.isKmsEnabled()) {
        createVolumeRequest.withKmsKeyId(awsInstanceView.getKmsKey());
    }
    return createVolumeRequest;
}
Also used : CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest)

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