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;
}
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;
});
}
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();
}
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);
}
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);
}
Aggregations