public boolean apply(Snapshot snapshot) { logger.trace("looking for status on snapshot %s", snapshot.getId()); snapshot = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId()))); logger.trace("%s: looking for status %s: currently: %s; progress %d/100", snapshot, Snapshot.Status.COMPLETED, snapshot.getStatus(), snapshot.getProgress()); return snapshot.getStatus() == Snapshot.Status.COMPLETED; }
public Snapshot getResult() { String region = AWSUtils.findRegionInArgsOrNull(getRequest()); if (region == null) region = defaultRegion.get(); Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime, progress, ownerId, description, ownerAlias); this.id = null; this.volumeId = null; this.volumeSize = 0; this.status = null; this.startTime = null; this.progress = 0; this.ownerId = null; this.description = null; this.ownerAlias = null; return snapshot; }
/** * Create a snapshot of the volume attached to the VM * @param vmi a VMInstance */ public String createSnapshot(VMInstance vmi){ NodeMetadata nm=getVMById(vmi.getId()); ElasticBlockStoreApi ebsClient = ec2api.getElasticBlockStoreApi().get(); journal.log(Level.INFO, ">> Creating snapshot of VM: "+vmi.getName()); Snapshot snapshot = ebsClient.createSnapshotInRegion("eu-west-1", nm.getHardware().getVolumes().get(0).getId()); String status=""; while (!status.toLowerCase().equals("completed")){ for(Snapshot s:ebsClient.describeSnapshotsInRegion("eu-west-1")) if(s.getId().equals(snapshot.getId())){ status=s.getStatus().name(); } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } journal.log(Level.INFO, ">> Snapshot created with ID: "+snapshot.getId()); return snapshot.getId(); }
@Test(dependsOnMethods = "testCreateVolumeFromSnapshotInAvailabilityZoneWithSize") public void testGetCreateVolumePermissionForSnapshot() { client.getCreateVolumePermissionForSnapshotInRegion(defaultRegion, snapshot.getId()); }
@Test(dependsOnMethods = "testCreateVolumeInAvailabilityZone") void testCreateSnapshotInRegion() { Snapshot snapshot = client.createSnapshotInRegion(defaultRegion, volumeId); Predicate<Snapshot> snapshotted = retry(new SnapshotCompleted(client), 600, 10, SECONDS); assert snapshotted.apply(snapshot); Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId()))); assertEquals(result.getProgress(), 100); this.snapshot = result; }
@Test(dependsOnMethods = "testCreateVolumeInAvailabilityZone") void testCreateSnapshotInRegion() { Snapshot snapshot = client.createSnapshotInRegion(defaultRegion, volumeId); Predicate<Snapshot> snapshotted = retry(new SnapshotCompleted(client), 600, 10, SECONDS); assert snapshotted.apply(snapshot); Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(defaultRegion, snapshotIds(snapshot.getId()))); assertEquals(result.getProgress(), 100); this.snapshot = result; }
@Test public void testCreateAndListEBSBackedImage() throws Exception { Snapshot snapshot = createSnapshot(); // List of images before... int sizeBefore = client.describeImagesInRegion(regionId).size(); // Register a new image... ebsBackedImageId = client.registerUnixImageBackedByEbsInRegion(regionId, ebsBackedImageName, snapshot.getId(), addNewBlockDevice("/dev/sda2", "myvirtual", 1).withDescription("adrian")); imagesToDeregister.add(ebsBackedImageId); final Image ebsBackedImage = getOnlyElement(client.describeImagesInRegion(regionId, imageIds(ebsBackedImageId))); assertEquals(ebsBackedImage.getName(), ebsBackedImageName); assertEquals(ebsBackedImage.getImageType(), ImageType.MACHINE); assertEquals(ebsBackedImage.getRootDeviceType(), RootDeviceType.EBS); assertEquals(ebsBackedImage.getRootDeviceName(), "/dev/sda1"); assertEquals(ebsBackedImage.getDescription(), "adrian"); assertEquals( ebsBackedImage.getEbsBlockDevices().entrySet(), ImmutableMap.of("/dev/sda1", new Image.EbsBlockDevice(snapshot.getId(), snapshot.getVolumeSize(), true), "/dev/sda2", new Image.EbsBlockDevice(null, 1, false)).entrySet()); // List of images after - should be one larger than before int after = client.describeImagesInRegion(regionId).size(); assertEquals(after, sizeBefore + 1); }
@Test(expectedExceptions = AWSResponseException.class) void testDescribeSnapshotsWithFilterInvalid() { String region = defaultRegion; SortedSet<Snapshot> allResults = Sets.newTreeSet(client.describeSnapshotsInRegion(region)); assertNotNull(allResults); if (!allResults.isEmpty()) { Snapshot snapshot = allResults.last(); client.describeSnapshotsInRegionWithFilter(region, ImmutableMultimap.<String, String>builder() .put("invalid-filter", snapshot.getId()).build()); } }
ebsBackedImageId = client.registerUnixImageBackedByEbsInRegion(regionId, ebsBackedImageName, snapshot.getId(), newBlockDeviceOption()); imagesToDeregister.add(ebsBackedImageId); assertEquals( ebsBackedImage.getEbsBlockDevices().entrySet(), ImmutableMap.of("/dev/sda1", new Image.EbsBlockDevice(snapshot.getId(), snapshot.getVolumeSize(), true, null, null, false), "/dev/sda2", newBlockDeviceInfo()).entrySet());
public boolean apply(Snapshot snapshot) { logger.trace("looking for status on snapshot %s", snapshot.getId()); snapshot = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId()))); logger.trace("%s: looking for status %s: currently: %s; progress %d/100", snapshot, Snapshot.Status.COMPLETED, snapshot.getStatus(), snapshot.getProgress()); return snapshot.getStatus() == Snapshot.Status.COMPLETED; }
@Test(dependsOnMethods = "testCreateSnapshotInRegion") void testCreateVolumeFromSnapshotInAvailabilityZone() { Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(defaultZone, snapshot.getId()); assertNotNull(volume); Predicate<Volume> availabile = retry(new VolumeAvailable(client), 600, 10, SECONDS); assert availabile.apply(volume); Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); assertEquals(volume.getId(), result.getId()); assertEquals(volume.getSnapshotId(), snapshot.getId()); assertEquals(volume.getAvailabilityZone(), defaultZone); assertEquals(result.getStatus(), Volume.Status.AVAILABLE); client.deleteVolumeInRegion(snapshot.getRegion(), volume.getId()); }
public Snapshot getResult() { String region = AWSUtils.findRegionInArgsOrNull(getRequest()); if (region == null) region = defaultRegion.get(); Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime, progress, ownerId, description, ownerAlias); this.id = null; this.volumeId = null; this.volumeSize = 0; this.status = null; this.startTime = null; this.progress = 0; this.ownerId = null; this.description = null; this.ownerAlias = null; return snapshot; }
public boolean apply(Snapshot snapshot) { logger.trace("looking for status on snapshot %s", snapshot.getId()); snapshot = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId()))); logger.trace("%s: looking for status %s: currently: %s; progress %d/100", snapshot, Snapshot.Status.COMPLETED, snapshot.getStatus(), snapshot.getProgress()); return snapshot.getStatus() == Snapshot.Status.COMPLETED; }
@Test(dependsOnMethods = "testCreateSnapshotInRegion") void testCreateVolumeFromSnapshotInAvailabilityZoneWithSize() { Volume volume = client.createVolumeFromSnapshotInAvailabilityZone(defaultZone, 2, snapshot.getId()); assertNotNull(volume); Predicate<Volume> availabile = retry(new VolumeAvailable(client), 600, 10, SECONDS); assert availabile.apply(volume); Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); assertEquals(volume.getId(), result.getId()); assertEquals(volume.getSnapshotId(), snapshot.getId()); assertEquals(volume.getAvailabilityZone(), defaultZone); assertEquals(volume.getSize(), 2); assertEquals(result.getStatus(), Volume.Status.AVAILABLE); client.deleteVolumeInRegion(snapshot.getRegion(), volume.getId()); }
@Test void testDescribeSnapshotsWithFilter() { String region = defaultRegion; SortedSet<Snapshot> allResults = Sets.newTreeSet(client.describeSnapshotsInRegion(region)); assertNotNull(allResults); if (!allResults.isEmpty()) { Snapshot snapshot = allResults.last(); Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegionWithFilter(region, ImmutableMultimap.<String, String>builder() .put("snapshot-id", snapshot.getId()).build())); assertNotNull(result); assertEquals(result, snapshot); } }
public Snapshot getResult() { String region = AWSUtils.findRegionInArgsOrNull(getRequest()); if (region == null) region = defaultRegion.get(); Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime, progress, ownerId, description, ownerAlias); this.id = null; this.volumeId = null; this.volumeSize = 0; this.status = null; this.startTime = null; this.progress = 0; this.ownerId = null; this.description = null; this.ownerAlias = null; return snapshot; }
public boolean apply(Snapshot snapshot) { logger.trace("looking for status on snapshot %s", snapshot.getId()); snapshot = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId()))); logger.trace("%s: looking for status %s: currently: %s; progress %d/100", snapshot, Snapshot.Status.COMPLETED, snapshot.getStatus(), snapshot.getProgress()); return snapshot.getStatus() == Snapshot.Status.COMPLETED; }