當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonEC2Client.describeAvailabilityZones方法代碼示例

本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2Client.describeAvailabilityZones方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2Client.describeAvailabilityZones方法的具體用法?Java AmazonEC2Client.describeAvailabilityZones怎麽用?Java AmazonEC2Client.describeAvailabilityZones使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.ec2.AmazonEC2Client的用法示例。


在下文中一共展示了AmazonEC2Client.describeAvailabilityZones方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkAvailabilityZone

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
/**
 * Validates the configured availability zone.
 *
 * @param client              the EC2 client
 * @param configuration       the configuration to be validated
 * @param accumulator         the exception condition accumulator
 * @param localizationContext the localization context
 */
@VisibleForTesting
void checkAvailabilityZone(AmazonEC2Client client,
    Configured configuration,
    PluginExceptionConditionAccumulator accumulator,
    LocalizationContext localizationContext) {

  String zoneName = configuration.getConfigurationValue(AVAILABILITY_ZONE, localizationContext);
  if (zoneName != null) {
    LOG.info(">> Describing zone '{}'", zoneName);

    try {
      DescribeAvailabilityZonesResult result = client.describeAvailabilityZones(
          new DescribeAvailabilityZonesRequest().withZoneNames(zoneName));

      checkCount(accumulator, AVAILABILITY_ZONE, localizationContext, "Availability zone",
          result.getAvailabilityZones());
    } catch (AmazonServiceException e) {
      if (e.getErrorCode().equals(INVALID_PARAMETER_VALUE) &&
          e.getMessage().contains(INVALID_AVAILABILITY_ZONE)) {
        addError(accumulator, AVAILABILITY_ZONE, localizationContext,
            null, INVALID_AVAILABILITY_ZONE_MSG, zoneName);
      } else {
        throw Throwables.propagate(e);
      }
    }
  }
}
 
開發者ID:cloudera,項目名稱:director-aws-plugin,代碼行數:36,代碼來源:EC2InstanceTemplateConfigurationValidator.java

示例2: listAvailableZonesOfRegion

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private List<Zone> listAvailableZonesOfRegion(Region region)
{
    checkNotNull(region);
    checkState(!isNullOrEmpty(region.getName()));
    checkState(!isNullOrEmpty(region.getEndpoint()));

    List<Zone> zones = newArrayList();
    
    AmazonEC2Client client = new AmazonEC2Client(awsCredentials_);
    client.setEndpoint(region.getEndpoint());

    try
    {
        DescribeAvailabilityZonesResult availabilityZonesResult = client.describeAvailabilityZones(new DescribeAvailabilityZonesRequest()
                .withFilters(new com.amazonaws.services.ec2.model.Filter().withName("region-name").withValues(region.getName()),
                             new com.amazonaws.services.ec2.model.Filter().withName("state").withValues("available"))
                            );

        for (AvailabilityZone zone : availabilityZonesResult.getAvailabilityZones())
        {
            zones.add(new Zone().setName(zone.getZoneName()).setRegion(region));
        }

        Collections.sort(zones);
    }
    catch (AmazonClientException exception)
    {
        LOG.warn("Error on listing the available zones of region [name:{}, endpoint:{}]. Error message: [{}]", 
                region.getName(), region.getEndpoint(), exception.getMessage(), exception);
    }

    return zones;
}
 
開發者ID:alessandroleite,項目名稱:dohko,代碼行數:34,代碼來源:EC2.java

示例3: describeAvailabilityZones

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
@Override
public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client,
    DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest)
{
    return ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:7,代碼來源:Ec2OperationsImpl.java

示例4: regions

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
    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");
            List<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);
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:45,代碼來源:AwsPlatformResources.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2Client.describeAvailabilityZones方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。