Search in sources :

Example 1 with Snapshot

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

the class CreateSnapshotReadyStatusCheckerTask method doCall.

@Override
protected Boolean doCall() {
    LOGGER.info("Checking if AWS EBS snapshot '{}' is ready.", snapshotId);
    DescribeSnapshotsResult result = ec2Client.describeSnapshots(new DescribeSnapshotsRequest().withSnapshotIds(snapshotId));
    return result.getSnapshots() != null && !result.getSnapshots().isEmpty() && "completed".equals(result.getSnapshots().get(0).getState());
}
Also used : DescribeSnapshotsRequest(com.amazonaws.services.ec2.model.DescribeSnapshotsRequest) DescribeSnapshotsResult(com.amazonaws.services.ec2.model.DescribeSnapshotsResult)

Example 2 with Snapshot

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

the class EBSSnapshotJanitorCrawler method getSnapshotResources.

private List<Resource> getSnapshotResources(String... snapshotIds) {
    refreshSnapshotToAMIs();
    List<Resource> resources = new LinkedList<Resource>();
    AWSClient awsClient = getAWSClient();
    for (Snapshot snapshot : awsClient.describeSnapshots(snapshotIds)) {
        Resource snapshotResource = new AWSResource().withId(snapshot.getSnapshotId()).withRegion(getAWSClient().region()).withResourceType(AWSResourceType.EBS_SNAPSHOT).withLaunchTime(snapshot.getStartTime()).withDescription(snapshot.getDescription());
        for (Tag tag : snapshot.getTags()) {
            LOGGER.debug(String.format("Adding tag %s = %s to resource %s", tag.getKey(), tag.getValue(), snapshotResource.getId()));
            snapshotResource.setTag(tag.getKey(), tag.getValue());
        }
        snapshotResource.setOwnerEmail(getOwnerEmailForResource(snapshotResource));
        ((AWSResource) snapshotResource).setAWSResourceState(snapshot.getState());
        Collection<String> amis = snapshotToAMIs.get(snapshotResource.getId());
        if (amis != null) {
            snapshotResource.setAdditionalField(SNAPSHOT_FIELD_AMIS, StringUtils.join(amis, ","));
        }
        resources.add(snapshotResource);
    }
    return resources;
}
Also used : Snapshot(com.amazonaws.services.ec2.model.Snapshot) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Tag(com.amazonaws.services.ec2.model.Tag) LinkedList(java.util.LinkedList)

Example 3 with Snapshot

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

the class EBSSnapshotJanitorCrawler method refreshSnapshotToAMIs.

private void refreshSnapshotToAMIs() {
    snapshotToAMIs.clear();
    for (Image image : getAWSClient().describeImages()) {
        for (BlockDeviceMapping bdm : image.getBlockDeviceMappings()) {
            EbsBlockDevice ebd = bdm.getEbs();
            if (ebd != null && ebd.getSnapshotId() != null) {
                LOGGER.debug(String.format("Snapshot %s is used to generate AMI %s", ebd.getSnapshotId(), image.getImageId()));
                Collection<String> amis = snapshotToAMIs.get(ebd.getSnapshotId());
                if (amis == null) {
                    amis = new ArrayList<String>();
                    snapshotToAMIs.put(ebd.getSnapshotId(), amis);
                }
                amis.add(image.getImageId());
            }
        }
    }
}
Also used : EbsBlockDevice(com.amazonaws.services.ec2.model.EbsBlockDevice) BlockDeviceMapping(com.amazonaws.services.ec2.model.BlockDeviceMapping) Image(com.amazonaws.services.ec2.model.Image)

Example 4 with Snapshot

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

the class TestEBSSnapshotJanitorCrawler method testSnapshotsWithIds.

@Test
public void testSnapshotsWithIds() {
    Date startTime = new Date();
    List<Snapshot> snapshotList = createSnapshotList(startTime);
    String[] ids = { "snap-12345678901234567", "snap-12345678901234567" };
    EBSSnapshotJanitorCrawler crawler = new EBSSnapshotJanitorCrawler(createMockAWSClient(snapshotList, ids));
    List<Resource> resources = crawler.resources(ids);
    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)

Example 5 with Snapshot

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

the class TestEBSSnapshotJanitorCrawler method testResourceTypes.

@Test
public void testResourceTypes() {
    Date startTime = new Date();
    List<Snapshot> snapshotList = createSnapshotList(startTime);
    EBSSnapshotJanitorCrawler crawler = new EBSSnapshotJanitorCrawler(createMockAWSClient(snapshotList));
    EnumSet<?> types = crawler.resourceTypes();
    Assert.assertEquals(types.size(), 1);
    Assert.assertEquals(types.iterator().next().name(), "EBS_SNAPSHOT");
}
Also used : Snapshot(com.amazonaws.services.ec2.model.Snapshot) 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