com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Ec2DaoImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private void fetchAZsIfNeeded(boolean availabilityZonesNeeded, AmazonEC2Client ec2Client, Map<Region, List<AvailabilityZone>> regionListMap,
        com.amazonaws.services.ec2.model.Region awsRegion, CloudCredential cloudCredential) {
    List<AvailabilityZone> collectedAZs = new ArrayList<>();
    if (availabilityZonesNeeded) {
        DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = getDescribeAvailabilityZonesRequest(ec2Client, awsRegion);
        LOGGER.debug("Describing AZs in region {}", awsRegion.getRegionName());
        List<com.amazonaws.services.ec2.model.AvailabilityZone> availabilityZones
                = awsAvailabilityZoneProvider.describeAvailabilityZones(cloudCredential, describeAvailabilityZonesRequest, ec2Client, awsRegion);
        for (com.amazonaws.services.ec2.model.AvailabilityZone availabilityZone : availabilityZones) {
            if (!deniedAZs.contains(availabilityZone.getZoneName())) {
                collectedAZs.add(availabilityZone(availabilityZone.getZoneName()));
            }
        }
    }
    regionListMap.put(region(awsRegion.getRegionName()), collectedAZs);
}
 
Example #3
Source File: Ec2InstanceStore.java    From soundwave with Apache License 2.0 5 votes vote down vote up
@Override
public List<AvailabilityZone> getAvailabilityZones(Region region) throws Exception {
  OperationStats op = new OperationStats("ec2InstanceStore", "getAvailabilityZones");
  try {
    DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest();
    DescribeAvailabilityZonesResult result = getClient(region).describeAvailabilityZones();
    List<AvailabilityZone> ret = result.getAvailabilityZones();
    op.succeed();
    return ret;
  } catch (Exception ex) {
    op.failed();
    throw ex;
  }
}
 
Example #4
Source File: MockEc2OperationsImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #5
Source File: AwsDescribeServiceImpl.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<AvailabilityZone> getAvailabilityZones(Long userNo, Long platformNo) {
    // アベイラビリティゾーンを取得
    AwsProcessClient awsProcessClient = awsProcessClientFactory.createAwsProcessClient(userNo, platformNo);
    DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest();
    DescribeAvailabilityZonesResult result = awsProcessClient.getEc2Client().describeAvailabilityZones(request);
    List<AvailabilityZone> availabilityZones = result.getAvailabilityZones();

    // ソート
    Collections.sort(availabilityZones, Comparators.COMPARATOR_AVAILABILITY_ZONE);

    return availabilityZones;
}
 
Example #6
Source File: AwsCommonProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
public List<AvailabilityZone> describeAvailabilityZones(AwsProcessClient awsProcessClient) {
    DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest();
    DescribeAvailabilityZonesResult result = awsProcessClient.getEc2Client().describeAvailabilityZones(request);
    List<AvailabilityZone> availabilityZones = result.getAvailabilityZones();

    return availabilityZones;
}
 
Example #7
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private DescribeAvailabilityZonesRequest getDescribeAvailabilityZonesRequest(AmazonEC2Client ec2Client, com.amazonaws.services.ec2.model.Region awsRegion) {
    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);
    return describeAvailabilityZonesRequest;
}
 
Example #8
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private DescribeAvailabilityZonesResult describeAvailabilityZonesResult(AmazonEC2Client ec2Client, com.amazonaws.services.ec2.model.Region awsRegion) {
    try {
        DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = getDescribeAvailabilityZonesRequest(ec2Client, awsRegion);
        return ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
    } catch (AmazonEC2Exception e) {
        LOGGER.info("Failed to retrieve AZ from Region: {}!", awsRegion.getRegionName(), e);
    }
    return new DescribeAvailabilityZonesResult();
}
 
Example #9
Source File: AwsAvailabilityZoneProvider.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Cacheable(cacheNames = "cloudResourceAzCache", key = "{ #cloudCredential?.id, #awsRegion.regionName }")
public List<AvailabilityZone> describeAvailabilityZones(CloudCredential cloudCredential,
        DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest, AmazonEC2Client ec2Client,
        com.amazonaws.services.ec2.model.Region awsRegion) {
    DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
    return describeAvailabilityZonesResult.getAvailabilityZones();
}
 
Example #10
Source File: Ec2OperationsImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client,
    DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest)
{
    return ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
}
 
Example #11
Source File: EncryptedSnapshotService.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private DescribeAvailabilityZonesRequest prepareDescribeAvailabilityZoneRequest(String regionName) {
    return new DescribeAvailabilityZonesRequest().withFilters(new Filter().withName(REGION_NAME).withValues(regionName));
}
 
Example #12
Source File: Ec2Operations.java    From herd with Apache License 2.0 2 votes vote down vote up
/**
 * {@link AmazonEC2#describeAvailabilityZones()}
 * 
 * @param ec2Client {@link AmazonEC2} to use.
 * @param describeAvailabilityZonesRequest The request object.
 * @return {@link DescribeAvailabilityZonesResult}
 */
public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client,
    DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest);