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


Java AmazonEC2Client.describeRegions方法代碼示例

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


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

示例1: getEndpointForRegion

import com.amazonaws.services.ec2.AmazonEC2Client; //導入方法依賴的package包/類
private static String getEndpointForRegion(AmazonEC2Client client, String regionName) {
  requireNonNull(client, "client is null");
  requireNonNull(regionName, "regionName is null");

  LOG.info(">> Describing all regions to find endpoint for '{}'", regionName);

  DescribeRegionsResult result = client.describeRegions();
  List<String> regions = Lists.newArrayListWithExpectedSize(result.getRegions().size());

  for (Region candidate : result.getRegions()) {
    regions.add(candidate.getRegionName());

    if (candidate.getRegionName().equals(regionName)) {
      LOG.info("<< Found endpoint '{}' for region '{}'", candidate.getEndpoint(), regionName);

      return candidate.getEndpoint();
    }
  }

  throw new IllegalArgumentException(String.format("Unable to find an endpoint for region '%s'. "
      + "Choose one of the following regions: %s", regionName, Joiner.on(", ").join(regions)));
}
 
開發者ID:cloudera,項目名稱:director-aws-plugin,代碼行數:23,代碼來源:AmazonEC2ClientProvider.java

示例2: 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.describeRegions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。