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

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

Introduction

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

Prototype

public CreateSnapshotRequest(String volumeId, String description) 

Source Link

Document

Constructs a new CreateSnapshotRequest object.

Usage

From source file:virtualIT.java

License:Open Source License

private void createExtraSnapShot(int userId) throws Exception {

    /******************************************
     * Creating Snap Shots before detaching volume
     *///ww w .  j  a v a 2  s.c  om
    System.out.println("Creating Snap Shots before detaching volume\n");
    String volumeId = mapUserExtraVolu.get(userId);
    CreateSnapshotResult snapRes = ec2
            .createSnapshot(new CreateSnapshotRequest(volumeId, "Test snapshot" + userId));
    Snapshot snap = snapRes.getSnapshot();

    System.out.println("Snapshot request sent.");
    System.out.println("Waiting for snapshot to be created");

    String snapState = snap.getState();
    System.out.println("snapState is " + snapState);

    System.out.print("Waiting for snapshot to be created");
    // Wait for the snapshot to be created
    while (snapState.equals("pending")) {
        Thread.sleep(500);
        System.out.print(".");
        DescribeSnapshotsResult describeSnapRes = ec2
                .describeSnapshots(new DescribeSnapshotsRequest().withSnapshotIds(snap.getSnapshotId()));
        snapState = describeSnapRes.getSnapshots().get(0).getState();

    }
    mapUserExtraSnap.put(userId, snap.getSnapshotId());

    System.out.println("\nSnap shot Done.");
    return;
}

From source file:virtualIT.java

License:Open Source License

private void createRootSnapShot(int userId) throws Exception {
    String volumeId = mapUserRootVol.get(userId);
    CreateSnapshotResult snapRes = ec2/*from ww  w  . j  av  a2 s .c o  m*/
            .createSnapshot(new CreateSnapshotRequest(volumeId, "Test snapshot" + userId));
    Snapshot snap = snapRes.getSnapshot();

    System.out.println("Snapshot request sent.");
    System.out.println("Waiting for snapshot to be created");

    String snapState = snap.getState();
    System.out.println("snapState is " + snapState);

    System.out.print("Waiting for snapshot to be created");
    // Wait for the snapshot to be created
    while (snapState.equals("pending")) {
        Thread.sleep(500);
        System.out.print(".");
        DescribeSnapshotsResult describeSnapRes = ec2
                .describeSnapshots(new DescribeSnapshotsRequest().withSnapshotIds(snap.getSnapshotId()));
        snapState = describeSnapRes.getSnapshots().get(0).getState();
    }
    mapUserRootSnap.put(userId, snap.getSnapshotId());

    System.out.println("\nSnap shot Done.");
    return;
}

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;//  w  w  w  .  j av a  2s.c o m
    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  . java 2 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;
}