コード例 #1
0
ファイル: AWSClient.java プロジェクト: jnayegandhi/SimianArmy
  /**
   * Describe a set of specific EBS snapshots.
   *
   * @param snapshotIds the snapshot ids
   * @return the snapshots
   */
  public List<Snapshot> describeSnapshots(String... snapshotIds) {
    if (snapshotIds == null || snapshotIds.length == 0) {
      LOGGER.info("Getting all EBS volumes.");
    } else {
      LOGGER.info(String.format("Getting EBS snapshotIds for %d ids.", snapshotIds.length));
    }

    AmazonEC2 ec2Client = ec2Client();
    DescribeSnapshotsRequest request = new DescribeSnapshotsRequest();
    if (snapshotIds != null) {
      request.setSnapshotIds(Arrays.asList(snapshotIds));
    }
    DescribeSnapshotsResult result = ec2Client.describeSnapshots(request);
    List<Snapshot> snapshots = result.getSnapshots();

    LOGGER.info(String.format("Got %d EBS snapshots.", snapshots.size()));
    return snapshots;
  }
コード例 #2
0
  public Request<DescribeSnapshotsRequest> marshall(
      DescribeSnapshotsRequest describeSnapshotsRequest) {

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

    Request<DescribeSnapshotsRequest> request =
        new DefaultRequest<DescribeSnapshotsRequest>(describeSnapshotsRequest, "AmazonEC2");
    request.addParameter("Action", "DescribeSnapshots");
    request.addParameter("Version", "2013-07-15");

    java.util.List<String> snapshotIdsList = describeSnapshotsRequest.getSnapshotIds();
    int snapshotIdsListIndex = 1;

    for (String snapshotIdsListValue : snapshotIdsList) {
      if (snapshotIdsListValue != null) {
        request.addParameter(
            "SnapshotId." + snapshotIdsListIndex, StringUtils.fromString(snapshotIdsListValue));
      }

      snapshotIdsListIndex++;
    }

    java.util.List<String> ownerIdsList = describeSnapshotsRequest.getOwnerIds();
    int ownerIdsListIndex = 1;

    for (String ownerIdsListValue : ownerIdsList) {
      if (ownerIdsListValue != null) {
        request.addParameter(
            "Owner." + ownerIdsListIndex, StringUtils.fromString(ownerIdsListValue));
      }

      ownerIdsListIndex++;
    }

    java.util.List<String> restorableByUserIdsList =
        describeSnapshotsRequest.getRestorableByUserIds();
    int restorableByUserIdsListIndex = 1;

    for (String restorableByUserIdsListValue : restorableByUserIdsList) {
      if (restorableByUserIdsListValue != null) {
        request.addParameter(
            "RestorableBy." + restorableByUserIdsListIndex,
            StringUtils.fromString(restorableByUserIdsListValue));
      }

      restorableByUserIdsListIndex++;
    }

    java.util.List<Filter> filtersList = describeSnapshotsRequest.getFilters();
    int filtersListIndex = 1;

    for (Filter filtersListValue : filtersList) {
      Filter filterMember = filtersListValue;
      if (filterMember != null) {
        if (filterMember.getName() != null) {
          request.addParameter(
              "Filter." + filtersListIndex + ".Name",
              StringUtils.fromString(filterMember.getName()));
        }

        java.util.List<String> valuesList = filterMember.getValues();
        int valuesListIndex = 1;

        for (String valuesListValue : valuesList) {
          if (valuesListValue != null) {
            request.addParameter(
                "Filter." + filtersListIndex + ".Value." + valuesListIndex,
                StringUtils.fromString(valuesListValue));
          }

          valuesListIndex++;
        }
      }

      filtersListIndex++;
    }

    return request;
  }