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());
}
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;
}
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());
}
}
}
}
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);
}
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");
}
Aggregations