当前位置: 首页>>代码示例>>Java>>正文


Java DescribeAvailabilityZonesResult类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult的典型用法代码示例。如果您正苦于以下问题:Java DescribeAvailabilityZonesResult类的具体用法?Java DescribeAvailabilityZonesResult怎么用?Java DescribeAvailabilityZonesResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DescribeAvailabilityZonesResult类属于com.amazonaws.services.ec2.model包,在下文中一共展示了DescribeAvailabilityZonesResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateCredentials

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
private DeferredResult<Void> validateCredentials(
        AuthCredentialsServiceState credentials, String regionId) {
    AmazonEC2AsyncClient client = AWSUtils.getAsyncClient(credentials, regionId,
            this.clientManager.getExecutor());

    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;
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:27,代码来源:AWSEndpointAdapterService.java

示例2: handleSuccess

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
@Override
public void handleSuccess(DescribeAvailabilityZonesRequest request,
        DescribeAvailabilityZonesResult result) {

    List<AvailabilityZone> zones = result.getAvailabilityZones();
    if (zones == null || zones.isEmpty()) {
        this.service
                .logFine(() -> "No AvailabilityZones found. Nothing to be created locally");
        this.context.refreshSubStage = this.next;
        this.service.processRefreshSubStages(this.context);
        return;
    }

    loadLocalResources(this.service, this.context,
            zones.stream()
                    .map(AvailabilityZone::getZoneName)
                    .collect(Collectors.toList()),
            cm -> createMissingLocalInstances(zones, cm),
            cm -> {
                this.service.logFine(() -> "No AvailabilityZones found. Nothing to be"
                        + " created locally");
                this.context.refreshSubStage = this.next;
                this.service.processRefreshSubStages(this.context);
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:26,代码来源:AWSEnumerationAndCreationAdapterService.java

示例3: testGetAvailabilityZones

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
@Test
public void testGetAvailabilityZones() {

    String zoneName = "zone-name";

    when(ec2Client.describeAvailabilityZones()).thenReturn(
            new DescribeAvailabilityZonesResult()
                    .withAvailabilityZones(
                            new AvailabilityZone()
                                    .withZoneName(zoneName)
                                    .withState(AvailabilityZoneState.Available),
                            new AvailabilityZone()
                                    .withZoneName("not-available-zone")
                                    .withState(AvailabilityZoneState.Unavailable)
                    )
    );

    // invoke method under test
    List<String> results = ec2Service.getAvailabilityZones();

    assertEquals(1, results.size());
    assertEquals(zoneName, results.get(0));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:24,代码来源:Ec2ServiceTest.java

示例4: getAvailabilityZonesForSubnetIds

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:19,代码来源:Ec2DaoImpl.java

示例5: getAllAvailabilityZones

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
public static List<String> getAllAvailabilityZones() {
	connect();
	
	DescribeAvailabilityZonesRequest req = new DescribeAvailabilityZonesRequest();
	
	ArrayList<Filter> filters = new ArrayList<Filter>();
	ArrayList<String> regions = new ArrayList<String>();
	regions.add(Configuration.REGION);
	filters.add(new Filter("region-name", regions));
	req.setFilters(filters);
	
	DescribeAvailabilityZonesResult res = client.describeAvailabilityZones(req);
	
	List<AvailabilityZone> zones = res.getAvailabilityZones();
	ArrayList<String> zonesStr = new ArrayList<String>();
	for (AvailabilityZone zone : zones)
		zonesStr.add(zone.getZoneName());
	
	return zonesStr;
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:21,代码来源:AmazonEC2.java

示例6: getZoneByName

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
private Zone getZoneByName(String zoneName)
{
    checkState(!isNullOrEmpty(zoneName));
    
    try
    {
        DescribeAvailabilityZonesResult zones = ec2_
                .describeAvailabilityZones(new DescribeAvailabilityZonesRequest()
                .withZoneNames(zoneName)
                .withFilters(new Filter().withName("region-name").withValues(credentials_.getRegion().getName())));

        if (zones != null && zones.getAvailabilityZones().size() == 1)
        {
            //available | impaired | unavailable
            AvailabilityZone availabilityZone = zones.getAvailabilityZones().get(0);
            return new Zone().setName(availabilityZone.getZoneName()).setRegion(credentials_.getRegion()).setStatus(availabilityZone.getState());
        }

    }
    catch (AmazonClientException exception)
    {
        LOG.debug("Invalid zone [{}]! Error message: [{}]", zoneName, exception.getMessage(), exception);
    }
    
    return null;
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:27,代码来源:EC2.java

示例7: getAvailabilityZones

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
@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;
  }
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:15,代码来源:Ec2InstanceStore.java

示例8: validateAWSCredentials

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
private void validateAWSCredentials(final AWSInstanceContext aws) {
    if (aws.computeRequest.isMockRequest || AWSUtils.isAwsClientMock()) {
        aws.operation.complete();
        return;
    }

    // make a call to validate credentials
    aws.amazonEC2Client
            .describeAvailabilityZonesAsync(
                    new DescribeAvailabilityZonesRequest(),
                    new AsyncHandler<DescribeAvailabilityZonesRequest, DescribeAvailabilityZonesResult>() {
                        @Override
                        public void onError(Exception e) {
                            if (e instanceof AmazonServiceException) {
                                AmazonServiceException ase = (AmazonServiceException) e;
                                if (ase.getStatusCode() == STATUS_CODE_UNAUTHORIZED) {
                                    ServiceErrorResponse r = Utils.toServiceErrorResponse(e);
                                    r.statusCode = STATUS_CODE_UNAUTHORIZED;
                                    aws.operation.fail(e, r);
                                    return;
                                }
                            }

                            aws.operation.fail(e);
                        }

                        @Override
                        public void onSuccess(DescribeAvailabilityZonesRequest request,
                                DescribeAvailabilityZonesResult describeAvailabilityZonesResult) {
                            aws.operation.complete();
                        }
                    });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:34,代码来源:AWSInstanceService.java

示例9: validateCredentials

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
public static void validateCredentials(AmazonEC2AsyncClient ec2Client,
        AWSClientManager clientManager, AuthCredentialsServiceState credentials,
        ComputeEnumerateAdapterRequest context, Operation op, StatelessService service,
        Consumer<DescribeAvailabilityZonesResult> onSuccess, Consumer<Throwable> onFail) {

    if (clientManager.isEc2ClientInvalid(credentials, context.regionId)) {
        op.complete();
        return;
    }

    ec2Client.describeAvailabilityZonesAsync(new DescribeAvailabilityZonesRequest(),
            new AsyncHandler<DescribeAvailabilityZonesRequest, DescribeAvailabilityZonesResult>() {

                @Override
                public void onError(Exception e) {
                    if (e instanceof AmazonServiceException) {
                        AmazonServiceException ase = (AmazonServiceException) e;
                        if (ase.getStatusCode() == STATUS_CODE_UNAUTHORIZED) {
                            clientManager.markEc2ClientInvalid(service, credentials,
                                    context.regionId);
                            op.complete();
                            return;
                        }
                        onFail.accept(e);
                    }
                }

                @Override
                public void onSuccess(DescribeAvailabilityZonesRequest request,
                        DescribeAvailabilityZonesResult describeAvailabilityZonesResult) {
                    onSuccess.accept(describeAvailabilityZonesResult);
                }
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:35,代码来源:AWSUtils.java

示例10: main

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
public static void main(String[] args)
{
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DescribeRegionsResult regions_response = ec2.describeRegions();

    for(Region region : regions_response.getRegions()) {
        System.out.printf(
            "Found region %s " +
            "with endpoint %s",
            region.getRegionName(),
            region.getEndpoint());
    }

    DescribeAvailabilityZonesResult zones_response =
        ec2.describeAvailabilityZones();

    for(AvailabilityZone zone : zones_response.getAvailabilityZones()) {
        System.out.printf(
            "Found availability zone %s " +
            "with status %s " +
            "in region %s",
            zone.getZoneName(),
            zone.getState(),
            zone.getRegionName());
    }
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:28,代码来源:DescribeRegionsAndZones.java

示例11: getAvailabilityZones

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
/**
 * Determines all availability zones for a region that are marked as available.
 *
 * @return List of availability zones
 */
public List<String> getAvailabilityZones() {
    final DescribeAvailabilityZonesResult result = ec2Client.describeAvailabilityZones();

    return result.getAvailabilityZones()
            .stream()
            .filter(az -> AvailabilityZoneState.Available == AvailabilityZoneState.fromValue(az.getState()))
            .map(AvailabilityZone::getZoneName).collect(Collectors.toList());
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:14,代码来源:Ec2Service.java

示例12: checkAvailabilityZone

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的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

示例13: describeAvailabilityZones

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
@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;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:30,代码来源:MockEc2OperationsImpl.java

示例14: availabilityZones

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的package包/类
public synchronized List<String> availabilityZones() {
    if (availabilityZones == null) {
        DescribeAvailabilityZonesResult result = ec2.describeAvailabilityZones();
        availabilityZones = result.getAvailabilityZones().stream()
                                  .filter(zone -> "available".equals(zone.getState()))
                                  .map(AvailabilityZone::getZoneName)
                                  .collect(Collectors.toList());
        logger.info("availability zones => {}", availabilityZones);
    }
    return availabilityZones;
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:12,代码来源:EC2.java

示例15: listAvailableZonesOfRegion

import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; //导入依赖的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


注:本文中的com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。