Search in sources :

Example 1 with CreateSnapshotResult

use of com.amazonaws.services.ec2.model.CreateSnapshotResult in project cloudbreak by hortonworks.

the class EncryptedSnapshotPreparator method prepareSnapshotForEncryptionBecauseThatDoesNotExist.

private Optional<String> prepareSnapshotForEncryptionBecauseThatDoesNotExist(AuthenticatedContext ac, AwsInstanceView instanceView, AmazonEC2Client client) {
    CreateVolumeResult volumeResult = client.createVolume(prepareCreateVolumeRequest(ac, instanceView, client));
    checkEbsVolumeStatus(ac, client, volumeResult);
    CreateSnapshotResult snapshotResult = client.createSnapshot(prepareCreateSnapshotRequest(volumeResult));
    checkSnapshotReadiness(ac, client, snapshotResult);
    client.createTags(prepareCreateTagsRequest(instanceView, snapshotResult));
    return Optional.of(snapshotResult.getSnapshot().getSnapshotId());
}
Also used : CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) CreateSnapshotResult(com.amazonaws.services.ec2.model.CreateSnapshotResult)

Example 2 with CreateSnapshotResult

use of com.amazonaws.services.ec2.model.CreateSnapshotResult in project photon-model by vmware.

the class TestAWSSetupUtils method createSnapshot.

/**
 * Creates a snapshot and return the snapshot id.
 */
public static String createSnapshot(VerificationHost host, AmazonEC2Client client, String volumeId) {
    CreateSnapshotRequest req = new CreateSnapshotRequest().withVolumeId(volumeId);
    CreateSnapshotResult res = client.createSnapshot(req);
    String snapshotId = res.getSnapshot().getSnapshotId();
    Filter filter = new Filter().withName(SNAPSHOT_ID_ATTRIBUTE).withValues(snapshotId);
    DescribeSnapshotsRequest snapshotsRequest = new DescribeSnapshotsRequest().withSnapshotIds(snapshotId).withFilters(filter);
    host.waitFor("Timeout waiting for creating snapshot", () -> {
        DescribeSnapshotsResult snapshotsResult = client.describeSnapshots(snapshotsRequest);
        String state = snapshotsResult.getSnapshots().get(0).getState();
        if (state.equalsIgnoreCase(SNAPSHOT_STATUS_COMPLETE)) {
            return true;
        }
        return false;
    });
    tagResources(client, Arrays.asList(snapshotId), TAG_KEY_FOR_TEST_RESOURCES, TAG_VALUE_FOR_TEST_RESOURCES + TAG_SNAPSHOT);
    return snapshotId;
}
Also used : CreateSnapshotRequest(com.amazonaws.services.ec2.model.CreateSnapshotRequest) AWSUtils.getAWSNonTerminatedInstancesFilter(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter) Filter(com.amazonaws.services.ec2.model.Filter) CreateSnapshotResult(com.amazonaws.services.ec2.model.CreateSnapshotResult) DescribeSnapshotsRequest(com.amazonaws.services.ec2.model.DescribeSnapshotsRequest) DescribeSnapshotsResult(com.amazonaws.services.ec2.model.DescribeSnapshotsResult)

Aggregations

CreateSnapshotResult (com.amazonaws.services.ec2.model.CreateSnapshotResult)2 CreateSnapshotRequest (com.amazonaws.services.ec2.model.CreateSnapshotRequest)1 CreateVolumeResult (com.amazonaws.services.ec2.model.CreateVolumeResult)1 DescribeSnapshotsRequest (com.amazonaws.services.ec2.model.DescribeSnapshotsRequest)1 DescribeSnapshotsResult (com.amazonaws.services.ec2.model.DescribeSnapshotsResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1 AWSUtils.getAWSNonTerminatedInstancesFilter (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter)1