Example usage for com.amazonaws.services.ec2.model CreateSnapshotResult getSnapshot

List of usage examples for com.amazonaws.services.ec2.model CreateSnapshotResult getSnapshot

Introduction

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

Prototype


public Snapshot getSnapshot() 

Source Link

Document

Describes a snapshot.

Usage

From source file:HW1.java

License:Open Source License

public static String createSnapShotFromVolume(String volumeId) {
    CreateSnapshotRequest createsanpShotRequest1 = new CreateSnapshotRequest();
    createsanpShotRequest1.setVolumeId(volumeId);
    CreateSnapshotResult createSnapshotresult1 = ec2.createSnapshot(createsanpShotRequest1);
    String snapshotid = createSnapshotresult1.getSnapshot().getSnapshotId();

    return snapshotid;
}

From source file:virtualIT.java

License:Open Source License

private void createExtraSnapShot(int userId) throws Exception {

    /******************************************
     * Creating Snap Shots before detaching volume
     *//* w  ww . jav a2  s.com*/
    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
            .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);//from w ww .j  a  v a2  s . c  om
        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.dowdandassociates.gentoo.bootstrap.DefaultTestSnapshotProvider.java

License:Apache License

public Optional<Snapshot> get() {
    BootstrapInstanceInformation instanceInfo = bootstrapResultInformation.getInstanceInfo();
    Optional<Instance> instance = instanceInfo.getInstance();
    Optional<Volume> volume = instanceInfo.getVolume();
    Optional<Integer> exitStatus = bootstrapResultInformation.getExitStatus();

    if (!instance.isPresent()) {
        log.info("Instance is absent");
        return Optional.absent();
    }/*from w w  w  . j  a  v  a 2s.  c om*/

    String instanceId = instance.get().getInstanceId();

    TerminateInstancesResult terminateInstancesResult = ec2Client
            .terminateInstances(new TerminateInstancesRequest().withInstanceIds(instanceId));

    if (!volume.isPresent()) {
        log.info("Volume is absent");
        return Optional.absent();
    }

    String volumeId = volume.get().getVolumeId();

    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
            .withInstanceIds(instanceId);

    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withVolumeIds(volumeId);
    try {
        while (true) {
            log.info("Sleeping for " + instanceSleep.get() + " ms");
            Thread.sleep(instanceSleep.get());
            DescribeInstancesResult describeInstancesResult = ec2Client
                    .describeInstances(describeInstancesRequest);
            String state = describeInstancesResult.getReservations().get(0).getInstances().get(0).getState()
                    .getName();
            log.info("Instance State = " + state);
            if ("terminated".equals(state)) {
                break;
            }
        }

        CreateSnapshotResult createSnapshotResult = ec2Client
                .createSnapshot(new CreateSnapshotRequest().withVolumeId(volumeId));

        log.info("SnapshotId = " + createSnapshotResult.getSnapshot().getSnapshotId());

        DescribeSnapshotsRequest describeSnapshotsRequest = new DescribeSnapshotsRequest()
                .withSnapshotIds(createSnapshotResult.getSnapshot().getSnapshotId());

        Snapshot snapshot;

        while (true) {
            log.info("Sleeping for " + snapshotSleep.get() + " ms");
            Thread.sleep(snapshotSleep.get());

            DescribeSnapshotsResult describeSnapshotsResult = ec2Client
                    .describeSnapshots(describeSnapshotsRequest);
            String state = describeSnapshotsResult.getSnapshots().get(0).getState();
            log.info("Snapshot State = " + state);
            if ("error".equals(state)) {
                return Optional.absent();
            }
            if ("completed".equals(state)) {
                snapshot = describeSnapshotsResult.getSnapshots().get(0);
                break;
            }
        }

        ec2Client.deleteVolume(new DeleteVolumeRequest().withVolumeId(volumeId));

        if (!exitStatus.isPresent()) {
            log.info("Exit status is not present");
            return Optional.absent();
        }

        log.info("exit status = " + exitStatus.get());

        if (0 != exitStatus.get()) {
            return Optional.absent();
        }

        return Optional.fromNullable(snapshot);
    } catch (InterruptedException e) {
        return Optional.absent();
    }
}

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 ww.j  a  v a 2 s  .  com*/
    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  a  v a 2s . com
    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.zotoh.cloudapi.aws.EBSSnapshot.java

License:Open Source License

@Override
public String create(String volId, String desc) throws InternalException, CloudException {
    tstEStrArg("volume-id", volId);
    desc = nsb(desc);/*from   w  w  w.ja v  a2 s .c o  m*/
    CreateSnapshotResult res = _svc.getCloud().getEC2()
            .createSnapshot(new CreateSnapshotRequest().withVolumeId(volId).withDescription(desc));
    com.amazonaws.services.ec2.model.Snapshot s = res == null ? null : res.getSnapshot();
    return s == null ? null : s.getSnapshotId();
}