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

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

Introduction

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

Prototype


public String getVolumeId() 

Source Link

Document

The ID of the EBS volume.

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 {/*  ww w  .  j a  va  2  s.co m*/
            // 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:jp.primecloud.auto.aws.typica.EucaEc2Client.java

License:Open Source License

@Override
public CreateSnapshotResult createSnapshot(CreateSnapshotRequest createSnapshotRequest) {
    try {//from  w w w .ja  va 2  s . c  o m
        SnapshotInfo info = jec2.createSnapshot(createSnapshotRequest.getVolumeId());
        Snapshot snapshot = new SnapshotConverter().convert(info);
        return new CreateSnapshotResult().withSnapshot(snapshot);
    } catch (EC2Exception e) {
        throw new AmazonClientException(e);
    }
}