Example usage for com.amazonaws.services.ec2 AmazonEC2Client describeSnapshots

List of usage examples for com.amazonaws.services.ec2 AmazonEC2Client describeSnapshots

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2 AmazonEC2Client describeSnapshots.

Prototype

@Override
public DescribeSnapshotsResult describeSnapshots(DescribeSnapshotsRequest request) 

Source Link

Document

Describes the specified EBS snapshots available to you or all of the EBS snapshots available to you.

Usage

From source file:com.pearson.eidetic.aws.EC2ClientMethods.java

public static DescribeSnapshotsResult describeSnapshots(AmazonEC2Client ec2Client,
        DescribeSnapshotsRequest describeSnapshotsRequest, Integer numRetries, Integer maxApiRequestsPerSecond,
        String uniqueAwsAccountIdentifier) {
    DescribeSnapshotsResult describeSnapshotsResult = null;
    for (int i = 0; i <= numRetries; i++) {
        try {/*from ww  w . j a va  2  s  .c  o m*/
            // if the initial download attempt failed, wait for i * 500ms 
            if (i > 0) {
                long sleepTimeInMilliseconds = 500 * i;
                Threads.sleepMilliseconds(sleepTimeInMilliseconds);
            }

            AtomicLong requestAttemptCounter = GlobalVariables.apiRequestAttemptCountersByAwsAccount
                    .get(uniqueAwsAccountIdentifier);
            long currentRequestCount = requestAttemptCounter.incrementAndGet();

            while (currentRequestCount > maxApiRequestsPerSecond) {
                Threads.sleepMilliseconds(50);
                currentRequestCount = requestAttemptCounter.incrementAndGet();
            }

            describeSnapshotsResult = ec2Client.describeSnapshots(describeSnapshotsRequest);

            if (describeSnapshotsResult != null) {
                GlobalVariables.apiRequestCountersByAwsAccount.get(uniqueAwsAccountIdentifier)
                        .incrementAndGet();
                break;
            }
        } catch (Exception e) {
            logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier + "\","
                    + describeSnapshotsRequest.toString() + System.lineSeparator() + e.toString()
                    + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        }
    }

    return describeSnapshotsResult;

}