本文整理汇总了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);
}
}
}
}
示例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;
}
示例3: describeAvailabilityZones
import com.amazonaws.services.ec2.AmazonEC2Client; //导入方法依赖的package包/类
@Override
public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client,
DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest)
{
return ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
}
示例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);
}