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


Java DescribeInstancesResult.getNextToken方法代碼示例

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


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

示例1: forEachInstance

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
/**
 * Iterates through the instances in the specified {@code DescribeInstancesResult}
 * and calls the specified handler on each instance. This method will retrieve the
 * follow-on {@code DescribeInstanceResult}s if the result holds a {@code nextToken}.
 *
 * @param result          the {@code DescribeInstancesResult}
 * @param instanceHandler the instance handler
 */
@VisibleForTesting
void forEachInstance(DescribeInstancesResult result, InstanceHandler instanceHandler) {
  List<Reservation> reservations;
  while (!(reservations = result.getReservations()).isEmpty()) {
    for (Reservation reservation : reservations) {
      for (Instance instance : reservation.getInstances()) {
        LOG.debug("Calling instance handler with instance {}", instance);
        instanceHandler.handle(instance);
      }
    }

    if (result.getNextToken() != null) {
      result = client.describeInstances(
          new DescribeInstancesRequest().withNextToken(result.getNextToken()));
    } else {
      break;
    }
  }
}
 
開發者ID:cloudera,項目名稱:director-aws-plugin,代碼行數:28,代碼來源:EC2Provider.java

示例2: call

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的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

示例3: getInstancesForZone

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的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

示例4: onSuccess

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
@Override
public void onSuccess(DescribeInstancesRequest request,
        DescribeInstancesResult result) {
    OperationContext.restoreOperationContext(this.opContext);
    int totalNumberOfInstances = 0;
    // Print the details of the instances discovered on the AWS endpoint
    for (Reservation r : result.getReservations()) {
        for (Instance i : r.getInstances()) {
            ++totalNumberOfInstances;
            final int finalTotal1 = totalNumberOfInstances;
            this.service.logFine(() -> String.format("%d=====Instance details %s =====",
                    finalTotal1, i.getInstanceId()));
            this.context.remoteAWSInstances.put(i.getInstanceId(), i);
        }
    }
    final int finalTotal2 = totalNumberOfInstances;
    this.service.logFine(() -> String.format("Successfully enumerated %d instances on the"
            + " AWS host", finalTotal2));
    // Save the reference to the next token that will be used to retrieve the next page of
    // results from AWS.
    this.context.nextToken = result.getNextToken();
    // Since there is filtering of resources at source, there can be a case when no
    // resources are returned from AWS.
    if (this.context.remoteAWSInstances.size() == 0) {
        if (this.context.nextToken != null) {
            this.context.subStage = AWSComputeEnumerationCreationSubStage.GET_NEXT_PAGE;
        } else {
            this.context.subStage = AWSComputeEnumerationCreationSubStage.NEXT_REFRESH_SUB_STAGE;
        }
    }
    handleReceivedEnumerationData();
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:33,代碼來源:AWSEnumerationAndCreationAdapterService.java

示例5: getAllInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的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

示例6: main

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的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

示例7: listHosts

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
private List<HostAndPort> listHosts(AmazonEC2 client) throws Exception {
    List<HostAndPort> hosts = newArrayList();
    DescribeInstancesRequest request = new DescribeInstancesRequest().withFilters(_filters);
    String nextToken = null;

    LOG.log(FINER, "Discovering instances: filters={0}", new Object[]{_filters});

    do {
        DescribeInstancesResult result = client.describeInstances(request.withNextToken(nextToken));

        for (Reservation reservation : result.getReservations()) {
            for (Instance instance : reservation.getInstances()) {
                LOG.log(FINER, "Instance state: {0} {1}", new Object[]{instance.getInstanceId(), instance.getState().getName()});

                if ("running".equalsIgnoreCase(instance.getState().getName())) {
                    List<InstanceNetworkInterface> networkInterfaces = instance.getNetworkInterfaces();

                    if (networkInterfaces.size() < 1) {
                        LOG.log(WARNING, "No network interface found on instance {0}", instance.getInstanceId());
                    } else {
                        InstanceNetworkInterface nic = networkInterfaces.get(0);
                        String ip;

                        if (_usePublicIP) {
                            ip = nic.getAssociation().getPublicIp();
                        } else {
                            ip = nic.getPrivateIpAddress();
                        }

                        hosts.add(HostAndPort.fromString(ip));
                    }
                }
            }
        }

        nextToken = result.getNextToken();
    } while (nextToken != null);

    return hosts;
}
 
開發者ID:dump247,項目名稱:jenkins-docker-build-plugin,代碼行數:41,代碼來源:EC2DockerHostProvider.java


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