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


Java DescribeInstancesRequest.setNextToken方法代碼示例

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


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

示例1: call

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public List<Instance> call() {
    List<Instance> instances = new ArrayList<>();
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    request.withInstanceIds(this.instanceIds);
    request.withFilters(this.filters);
    // paginate through result as long as there is another response token
    boolean moreResults = false;
    do {
        DescribeInstancesResult result = getClient().getApi().describeInstances(request);
        instances.addAll(instances(result));
        moreResults = result.getNextToken() != null && !result.getNextToken().equals("");
        request.setNextToken(result.getNextToken());
    } while (moreResults);

    return instances;
}
 
開發者ID:elastisys,項目名稱:scale.cloudpool,代碼行數:18,代碼來源:GetInstances.java

示例2: getInstancesForZone

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public List<Instance> getInstancesForZone(AvailabilityZone zone, AmazonEC2Client client)
    throws Exception {
  OperationStats op = new OperationStats("ec2InstanceStore", "getInstancesForZone");
  try {
    List<Instance> ret = new ArrayList<>();
    DescribeInstancesRequest request = new DescribeInstancesRequest()
        .withMaxResults(1000)
        .withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName())))
        .withSdkClientExecutionTimeout(
            600 * 1000) //10 minutes time out for total execution including retries
        .withSdkRequestTimeout(300 * 1000); //5 minutes time out for a single request

    List<Reservation> reservations = new ArrayList<>();
    DescribeInstancesResult result = client.describeInstances(request);
    while (result != null) {
      reservations.addAll(result.getReservations());
      if (result.getNextToken() != null) {
        request.setNextToken(result.getNextToken());
        result = client.describeInstances(request);
      } else {
        result = null;
      }
    }

    for (Reservation reservation : reservations) {
      //Reservation refers to one launch command in EC2. Most time it should
      //only contains one instance
      for (Instance inst : reservation.getInstances()) {
        ret.add(inst);
      }
    }
    op.succeed();
    return ret;
  } catch (Exception ex) {
    op.failed();
    throw ex;
  }
}
 
開發者ID:pinterest,項目名稱:soundwave,代碼行數:40,代碼來源:Ec2InstanceStore.java

示例3: createAWSRequestAndAsyncHandler

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
/**
 * Initializes and saves a reference to the request object that is sent to AWS to get a page of
 * instances. Also saves an instance to the async handler that will be used to handle the
 * responses received from AWS. It sets the nextToken value in the request object sent to AWS
 * for getting the next page of results from AWS.
 */
private void createAWSRequestAndAsyncHandler(EnumerationCreationContext aws,
        AWSEnumerationRefreshSubStage next) {
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
    request.getFilters().add(runningInstanceFilter);
    request.setMaxResults(getQueryPageSize());
    request.setNextToken(aws.nextToken);
    aws.describeInstancesRequest = request;
    aws.resultHandler = new AWSEnumerationAsyncHandler(this, aws, next);
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:17,代碼來源:AWSEnumerationAndCreationAdapterService.java

示例4: getAllInstances

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
/**
 * This method returns all EC2 instances.
 * @return
 * @throws AmazonClientException 
 */
public List<Instance> getAllInstances() throws AmazonClientException {
    
    String marker = null;
    List<Instance> allInstances = new ArrayList<>();
    
    try {
        
        while ( true ) {
            DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
            describeInstancesRequest.setNextToken(marker);
            DescribeInstancesResult describeInstancesResult = this.amazonEc2.describeInstances(describeInstancesRequest);
            List<Reservation> reservations = describeInstancesResult.getReservations();
            for(Reservation reservation: reservations) {
                allInstances.addAll(reservation.getInstances());
            }

            marker = describeInstancesResult.getNextToken();
            if ( marker == null) {
                break;
            }
        }
        
    } catch(AmazonClientException e) {
        System.out.println("ERROR : Fetching all EC2 instances.");
        e.printStackTrace();
        throw e;
    }
    
    System.out.println("INFO : Number of EC2 instances : " + allInstances.size());
    List<String> instancesId = allInstances.stream().map( e -> e.getInstanceId()).collect(Collectors.toList());
    System.out.println("INFO : EC2 Instances : " + instancesId);
    return allInstances;
}
 
開發者ID:code4innerpeace,項目名稱:AWSConfig,代碼行數:39,代碼來源:EC2UtilsImpl.java

示例5: main

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
public static void main(String[] args)
{
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    boolean done = false;

    while(!done) {
        DescribeInstancesRequest request = new DescribeInstancesRequest();
        DescribeInstancesResult response = ec2.describeInstances(request);

        for(Reservation reservation : response.getReservations()) {
            for(Instance instance : reservation.getInstances()) {
                System.out.printf(
                    "Found reservation with id %s, " +
                    "AMI %s, " +
                    "type %s, " +
                    "state %s " +
                    "and monitoring state %s",
                    instance.getInstanceId(),
                    instance.getImageId(),
                    instance.getInstanceType(),
                    instance.getState().getName(),
                    instance.getMonitoring().getState());
            }
        }

        request.setNextToken(response.getNextToken());

        if(response.getNextToken() == null) {
            done = true;
        }
    }
}
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:33,代碼來源:DescribeInstances.java


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