Example usage for com.amazonaws.services.ec2.model CreateSnapshotRequest toString

List of usage examples for com.amazonaws.services.ec2.model CreateSnapshotRequest toString

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model CreateSnapshotRequest toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a string representation of this object.

Usage

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

public static CreateSnapshotResult createSnapshot(AmazonEC2Client ec2Client,
        CreateSnapshotRequest snapshotRequest, Integer numRetries, Integer maxApiRequestsPerSecond,
        String uniqueAwsAccountIdentifier) {
    CreateSnapshotResult createSnapshotResult = null;
    for (int i = 0; i <= numRetries; i++) {
        try {/*  w ww.j a  va  2  s  .c om*/
            // if the initial download attempt failed, wait for i * 500ms 
            if (i > 0) {
                long sleepTimeInMilliseconds = 500 * i;
                Threads.sleepMilliseconds(sleepTimeInMilliseconds);
                logger.debug(snapshotRequest.toString() + System.lineSeparator()
                        + "**********I am sleeping because something is blocking on AWS****************");

            }

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

            while (currentRequestCount > maxApiRequestsPerSecond) {
                Threads.sleepMilliseconds(50);
                currentRequestCount = requestAttemptCounter.incrementAndGet();
                logger.debug(snapshotRequest.toString() + System.lineSeparator()
                        + "****** I am waiting because the request rate is being throttled by Eidetic");
            }
            Long elapsedTime;
            Long startTime = System.currentTimeMillis();

            createSnapshotResult = ec2Client.createSnapshot(snapshotRequest);

            elapsedTime = (new Date()).getTime() - startTime;

            if (createSnapshotResult != null) {
                GlobalVariables.apiRequestCountersByAwsAccount.get(uniqueAwsAccountIdentifier)
                        .incrementAndGet();
                logger.debug("************** I finished this snapshot and it took " + elapsedTime.toString()
                        + " ms *******************");
                break;
            }
        } catch (Exception e) {
            if (e.toString().contains("retired")) {
                logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier + "\","
                        + snapshotRequest.toString() + System.lineSeparator() + e.toString()
                        + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
                return createSnapshotResult;
            }
            logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier + "\","
                    + snapshotRequest.toString() + System.lineSeparator() + e.toString()
                    + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        }
    }
    logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier
            + "\",Event=\"Snapshot Created\", Volume_id=\"" + snapshotRequest.getVolumeId() + "\"");
    return createSnapshotResult;

}

From source file:com.pearson.eidetic.driver.threads.EideticSubThreadMethods.java

@Override
public Snapshot createSnapshotOfVolume(AmazonEC2Client ec2Client, Volume vol, String description,
        Integer numRetries, Integer maxApiRequestsPerSecond, String uniqueAwsAccountIdentifier) {
    String volumeId = vol.getVolumeId();
    CreateSnapshotRequest snapshotRequest = new CreateSnapshotRequest(volumeId, description);
    Snapshot snapshot = null;//from  w w  w  . j  a v  a2  s . c om
    try {
        CreateSnapshotResult result = EC2ClientMethods.createSnapshot(ec2Client, snapshotRequest, numRetries,
                maxApiRequestsPerSecond, uniqueAwsAccountIdentifier);
        snapshot = result.getSnapshot();
    } catch (Exception e) {
        logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier + "\"," + snapshotRequest.toString()
                + System.lineSeparator() + e.toString() + System.lineSeparator()
                + StackTrace.getStringFromStackTrace(e));
    }

    return snapshot;
}

From source file:com.pearson.eidetic.driver.threads.EideticSubThreadMethods.java

@Override
public Snapshot createSnapshotOfVolume(AmazonEC2Client ec2Client, Volume vol, Integer numRetries,
        Integer maxApiRequestsPerSecond, String uniqueAwsAccountIdentifier) {
    String volumeId = vol.getVolumeId();
    String description = "";
    CreateSnapshotRequest snapshotRequest = new CreateSnapshotRequest(volumeId, description);

    Snapshot snapshot = null;//from  ww w .j  av  a2  s.  c  om
    try {
        CreateSnapshotResult result = EC2ClientMethods.createSnapshot(ec2Client, snapshotRequest, numRetries,
                maxApiRequestsPerSecond, uniqueAwsAccountIdentifier);
        snapshot = result.getSnapshot();
    } catch (Exception e) {
        logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier + "\"," + snapshotRequest.toString()
                + System.lineSeparator() + e.toString() + System.lineSeparator()
                + StackTrace.getStringFromStackTrace(e));
    }

    return snapshot;
}