Search in sources :

Example 1 with DescribeAvailabilityZonesRequest

use of com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest in project herd by FINRAOS.

the class MockEc2OperationsImpl method describeAvailabilityZones.

@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;
}
Also used : ArrayList(java.util.ArrayList) AvailabilityZone(com.amazonaws.services.ec2.model.AvailabilityZone) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)

Example 2 with DescribeAvailabilityZonesRequest

use of com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest in project photon-model by vmware.

the class AWSEndpointAdapterService method validateCredentials.

private DeferredResult<Void> validateCredentials(AmazonEC2AsyncClient client) {
    AWSDeferredResultAsyncHandler<DescribeAvailabilityZonesRequest, DescribeAvailabilityZonesResult> asyncHandler = new AWSDeferredResultAsyncHandler<>(this, "Validate Credentials");
    client.describeAvailabilityZonesAsync(asyncHandler);
    return asyncHandler.toDeferredResult().handle((describeAvailabilityZonesResult, e) -> {
        if (e instanceof AmazonServiceException) {
            AmazonServiceException ase = (AmazonServiceException) e;
            if (ase.getStatusCode() == STATUS_CODE_UNAUTHORIZED) {
                throw new LocalizableValidationException(e, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE);
            }
        }
        return null;
    });
}
Also used : LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)

Example 3 with DescribeAvailabilityZonesRequest

use of com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest 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 4 with DescribeAvailabilityZonesRequest

use of com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest in project photon-model by vmware.

the class AWSEnumerationAndCreationAdapterService method collectAvailabilityZones.

private void collectAvailabilityZones(EnumerationCreationContext aws, AWSEnumerationRefreshSubStage next) {
    DescribeAvailabilityZonesRequest azRequest = new DescribeAvailabilityZonesRequest();
    AWSAvailabilityZoneAsyncHandler asyncHandler = new AWSAvailabilityZoneAsyncHandler(this, aws, next);
    aws.amazonEC2Client.describeAvailabilityZonesAsync(azRequest, asyncHandler);
}
Also used : DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)

Example 5 with DescribeAvailabilityZonesRequest

use of com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest 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)

Aggregations

DescribeAvailabilityZonesRequest (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)4 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)4 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 ArrayList (java.util.ArrayList)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1 Subnet (com.amazonaws.services.ec2.model.Subnet)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 DisplayName (com.sequenceiq.cloudbreak.cloud.model.DisplayName)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 AWSDeferredResultAsyncHandler (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler)1 LocalizableValidationException (com.vmware.xenon.common.LocalizableValidationException)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1