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


Java DescribeInstanceStatusResult.getNextToken方法代码示例

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


在下文中一共展示了DescribeInstanceStatusResult.getNextToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInstancesStatusByZone

import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult; //导入方法依赖的package包/类
private List<InstanceStatus> getInstancesStatusByZone(AvailabilityZone zone,
                                                      AmazonEC2Client client) {

  // Create this list to capture paginated async results from aws sdk
  List<InstanceStatus> statusList = new ArrayList<>();

  // Create an initial request object
  DescribeInstanceStatusRequest statusRequest = new DescribeInstanceStatusRequest()
      .withMaxResults(1000)
      .withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName())))
      .withSdkClientExecutionTimeout(600 * 1000)
      .withSdkRequestTimeout(300 * 1000);

  // Make the request for instanceStatus
  DescribeInstanceStatusResult result = client.describeInstanceStatus(statusRequest);

  // Until more results are available we loop through this code
  while (result != null) {

    statusList.addAll(result.getInstanceStatuses());

    if (result.getNextToken() != null) {

      statusRequest.setNextToken(result.getNextToken());
      result = client.describeInstanceStatus(statusRequest);

    } else {
      result = null;
    }
  }

  // Return all statuses as a list of InstanceStatus objects
  return statusList;
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:35,代码来源:Ec2InstanceStore.java

示例2: getBatchInstanceState

import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult; //导入方法依赖的package包/类
/**
 * Returns a map from virtual instance IDs to instance state for the specified batch of virtual
 * instance IDs.
 *
 * @param virtualInstanceIds batch of virtual instance IDs
 * @return the map from instance IDs to instance state for the specified batch of virtual
 * instance IDs
 */
private Map<String, InstanceState> getBatchInstanceState(Collection<String> virtualInstanceIds) {
  Map<String, InstanceState> instanceStateByVirtualInstanceId =
      Maps.newHashMapWithExpectedSize(virtualInstanceIds.size());

  BiMap<String, String> virtualInstanceIdsByEC2InstanceId =
      getEC2InstanceIdsByVirtualInstanceId(virtualInstanceIds).inverse();

  int page = 0;
  LOG.info(">> Fetching page {}", page);

  if (virtualInstanceIdsByEC2InstanceId.isEmpty()) {
    // No EC2 instances are found, which means these id's are already terminated and gone.
    // In practice, this is possible when no instances were provisioned to begin with.
    // For example, when a deployment fails due to tagging error.
    return instanceStateByVirtualInstanceId;
  }

  DescribeInstanceStatusResult result = client.describeInstanceStatus(
      new DescribeInstanceStatusRequest()
          // Note that sending in an empty set will result in fetching _all_ instance Ids.
          // It requires you to send one or more EC2 Ids
          .withInstanceIds(virtualInstanceIdsByEC2InstanceId.keySet())
          .withIncludeAllInstances(true)
  );
  LOG.info("<< Result: {}", result);

  while (!result.getInstanceStatuses().isEmpty()) {
    for (InstanceStatus status : result.getInstanceStatuses()) {

      InstanceStateName currentState =
          InstanceStateName.fromValue(status.getInstanceState().getName());
      String ec2InstanceId = status.getInstanceId();
      String virtualInstanceId = virtualInstanceIdsByEC2InstanceId.get(ec2InstanceId);
      InstanceState instanceState = EC2InstanceState.fromInstanceStateName(currentState);
      instanceStateByVirtualInstanceId.put(virtualInstanceId, instanceState);
    }

    String nextToken = result.getNextToken();
    if (nextToken != null) {
      page++;
      LOG.info(">> Fetching page {} using token {}", page, nextToken);
      result = client.describeInstanceStatus(new DescribeInstanceStatusRequest()
          .withNextToken(nextToken));
      LOG.info("<< Result: {}", result);
    } else {
      break;
    }
  }

  return instanceStateByVirtualInstanceId;
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:60,代码来源:EC2Provider.java


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