Search in sources :

Example 6 with Snapshot

use of com.amazonaws.services.ec2.model.Snapshot 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)

Example 7 with Snapshot

use of com.amazonaws.services.ec2.model.Snapshot in project SimianArmy by Netflix.

the class AWSClient method describeSnapshots.

/**
 * Describe a set of specific EBS snapshots.
 *
 * @param snapshotIds the snapshot ids
 * @return the snapshots
 */
public List<Snapshot> describeSnapshots(String... snapshotIds) {
    if (snapshotIds == null || snapshotIds.length == 0) {
        LOGGER.info(String.format("Getting all EBS snapshots in region %s.", region));
    } else {
        LOGGER.info(String.format("Getting EBS snapshotIds for %d ids in region %s.", snapshotIds.length, region));
    }
    AmazonEC2 ec2Client = ec2Client();
    DescribeSnapshotsRequest request = new DescribeSnapshotsRequest();
    // Set the owner id to self to avoid getting snapshots from other accounts.
    request.withOwnerIds(Arrays.<String>asList("self"));
    if (snapshotIds != null) {
        request.setSnapshotIds(Arrays.asList(snapshotIds));
    }
    DescribeSnapshotsResult result = ec2Client.describeSnapshots(request);
    List<Snapshot> snapshots = result.getSnapshots();
    LOGGER.info(String.format("Got %d EBS snapshots in region %s.", snapshots.size(), region));
    return snapshots;
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2)

Example 8 with Snapshot

use of com.amazonaws.services.ec2.model.Snapshot in project SimianArmy by Netflix.

the class AWSClient method deleteSnapshot.

/**
 * {@inheritDoc}
 */
@Override
public void deleteSnapshot(String snapshotId) {
    Validate.notEmpty(snapshotId);
    LOGGER.info(String.format("Deleting snapshot %s in region %s.", snapshotId, region));
    AmazonEC2 ec2Client = ec2Client();
    DeleteSnapshotRequest request = new DeleteSnapshotRequest().withSnapshotId(snapshotId);
    ec2Client.deleteSnapshot(request);
}
Also used : AmazonEC2(com.amazonaws.services.ec2.AmazonEC2)

Example 9 with Snapshot

use of com.amazonaws.services.ec2.model.Snapshot in project SimianArmy by Netflix.

the class TestEBSSnapshotJanitorCrawler method testSnapshotsWithResourceType.

@Test
public void testSnapshotsWithResourceType() {
    Date startTime = new Date();
    List<Snapshot> snapshotList = createSnapshotList(startTime);
    EBSSnapshotJanitorCrawler crawler = new EBSSnapshotJanitorCrawler(createMockAWSClient(snapshotList));
    for (AWSResourceType resourceType : AWSResourceType.values()) {
        List<Resource> resources = crawler.resources(resourceType);
        if (resourceType == AWSResourceType.EBS_SNAPSHOT) {
            verifySnapshotList(resources, snapshotList, startTime);
        } else {
            Assert.assertTrue(resources.isEmpty());
        }
    }
}
Also used : Snapshot(com.amazonaws.services.ec2.model.Snapshot) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 10 with Snapshot

use of com.amazonaws.services.ec2.model.Snapshot in project SimianArmy by Netflix.

the class TestEBSSnapshotJanitorCrawler method testSnapshotsWithNullIds.

@Test
public void testSnapshotsWithNullIds() {
    Date startTime = new Date();
    List<Snapshot> snapshotList = createSnapshotList(startTime);
    EBSSnapshotJanitorCrawler crawler = new EBSSnapshotJanitorCrawler(createMockAWSClient(snapshotList));
    List<Resource> resources = crawler.resources();
    verifySnapshotList(resources, snapshotList, startTime);
}
Also used : Snapshot(com.amazonaws.services.ec2.model.Snapshot) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

Snapshot (com.amazonaws.services.ec2.model.Snapshot)6 Resource (com.netflix.simianarmy.Resource)4 AWSResource (com.netflix.simianarmy.aws.AWSResource)4 Date (java.util.Date)4 Test (org.testng.annotations.Test)4 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 DescribeSnapshotsRequest (com.amazonaws.services.ec2.model.DescribeSnapshotsRequest)2 DescribeSnapshotsResult (com.amazonaws.services.ec2.model.DescribeSnapshotsResult)2 BlockDeviceMapping (com.amazonaws.services.ec2.model.BlockDeviceMapping)1 CreateSnapshotRequest (com.amazonaws.services.ec2.model.CreateSnapshotRequest)1 CreateSnapshotResult (com.amazonaws.services.ec2.model.CreateSnapshotResult)1 EbsBlockDevice (com.amazonaws.services.ec2.model.EbsBlockDevice)1 Filter (com.amazonaws.services.ec2.model.Filter)1 Image (com.amazonaws.services.ec2.model.Image)1 Tag (com.amazonaws.services.ec2.model.Tag)1 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)1 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)1 AWSUtils.getAWSNonTerminatedInstancesFilter (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter)1 LinkedList (java.util.LinkedList)1