Example #1
0
  /**
   * Describe a set of specific auto scaling groups.
   *
   * @param names the ASG names
   * @return the auto scaling groups
   */
  public List<AutoScalingGroup> describeAutoScalingGroups(String... names) {
    if (names == null || names.length == 0) {
      LOGGER.info("Getting all auto-scaling groups.");
    } else {
      LOGGER.info(String.format("Getting auto-scaling groups for %d names.", names.length));
    }

    List<AutoScalingGroup> asgs = new LinkedList<AutoScalingGroup>();

    AmazonAutoScalingClient asgClient = asgClient();
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
    if (names != null) {
      request.setAutoScalingGroupNames(Arrays.asList(names));
    }
    DescribeAutoScalingGroupsResult result = asgClient.describeAutoScalingGroups(request);

    asgs.addAll(result.getAutoScalingGroups());
    while (result.getNextToken() != null) {
      request.setNextToken(result.getNextToken());
      result = asgClient.describeAutoScalingGroups(request);
      asgs.addAll(result.getAutoScalingGroups());
    }

    LOGGER.info(String.format("Got %d auto-scaling groups.", asgs.size()));
    return asgs;
  }
  public Request<DescribeAutoScalingGroupsRequest> marshall(
      DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest) {

    if (describeAutoScalingGroupsRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<DescribeAutoScalingGroupsRequest> request =
        new DefaultRequest<DescribeAutoScalingGroupsRequest>(
            describeAutoScalingGroupsRequest, "AmazonAutoScaling");
    request.addParameter("Action", "DescribeAutoScalingGroups");
    request.addParameter("Version", "2011-01-01");

    java.util.List<String> autoScalingGroupNamesList =
        describeAutoScalingGroupsRequest.getAutoScalingGroupNames();
    int autoScalingGroupNamesListIndex = 1;

    for (String autoScalingGroupNamesListValue : autoScalingGroupNamesList) {
      if (autoScalingGroupNamesListValue != null) {
        request.addParameter(
            "AutoScalingGroupNames.member." + autoScalingGroupNamesListIndex,
            StringUtils.fromString(autoScalingGroupNamesListValue));
      }

      autoScalingGroupNamesListIndex++;
    }
    if (describeAutoScalingGroupsRequest.getNextToken() != null) {
      request.addParameter(
          "NextToken", StringUtils.fromString(describeAutoScalingGroupsRequest.getNextToken()));
    }
    if (describeAutoScalingGroupsRequest.getMaxRecords() != null) {
      request.addParameter(
          "MaxRecords", StringUtils.fromInteger(describeAutoScalingGroupsRequest.getMaxRecords()));
    }

    return request;
  }