/** * Deletes this disk. * * @return a zone operation if the delete request was successfully sent, {@code null} if the disk * was not found * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { return compute.deleteDisk(getDiskId(), options); }
/** * Fetches current disk's latest information. Returns {@code null} if the disk does not exist. * * @param options disk options * @return a {@code Disk} object with latest information or {@code null} if not found * @throws ComputeException upon failure */ public Disk reload(DiskOption... options) { return compute.getDisk(getDiskId(), options); }
/** * Resizes this disk to the requested size. The new size must be larger than the previous one. * * @return a zone operation if the resize request was issued correctly, {@code null} if this disk * was not found * @throws ComputeException upon failure or if the new disk size is smaller than the previous one */ public Operation resize(long sizeGb, OperationOption... options) { return compute.resize(getDiskId(), sizeGb, options); }
/** * Creates a snapshot for this disk given the snapshot's name. * * @return a zone operation for snapshot creation * @throws ComputeException upon failure */ public Operation createSnapshot(String snapshot, OperationOption... options) { return compute.create(SnapshotInfo.of(SnapshotId.of(snapshot), getDiskId()), options); }
/** * Creates an image for this disk given the image's name. * * @return a global operation if the image creation was successfully requested * @throws ComputeException upon failure */ public Operation createImage(String image, OperationOption... options) { ImageInfo imageInfo = ImageInfo.of(ImageId.of(image), DiskImageConfiguration.of(getDiskId())); return compute.create(imageInfo, options); }
/** * Creates a snapshot for this disk given the snapshot's name and description. * * @return a zone operation for snapshot creation * @throws ComputeException upon failure */ public Operation createSnapshot(String snapshot, String description, OperationOption... options) { SnapshotInfo snapshotInfo = SnapshotInfo.newBuilder(SnapshotId.of(snapshot), getDiskId()) .setDescription(description) .build(); return compute.create(snapshotInfo, options); }
/** * Creates an image for this disk given the image's name and description. * * @return a global operation if the image creation was successfully requested * @throws ComputeException upon failure */ public Operation createImage(String image, String description, OperationOption... options) { ImageInfo imageInfo = ImageInfo.newBuilder(ImageId.of(image), DiskImageConfiguration.of(getDiskId())) .setDescription(description) .build(); return compute.create(imageInfo, options); }
while (diskIterator.hasNext()) { Disk remoteDisk = diskIterator.next(); assertTrue(zoneSet.contains(remoteDisk.getDiskId().getZone())); assertTrue(diskSet.contains(remoteDisk.getDiskId().getDisk())); assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); assertNotNull(remoteDisk.getCreationTimestamp());
public void compareDisk(Disk expected, Disk value) { assertEquals(expected, value); assertEquals(expected.getCompute().getOptions(), value.getCompute().getOptions()); assertEquals(expected.getDiskId(), value.getDiskId()); assertEquals(expected.getConfiguration(), value.getConfiguration()); assertEquals(expected.getGeneratedId(), value.getGeneratedId()); assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); assertEquals(expected.getCreationStatus(), value.getCreationStatus()); assertEquals(expected.getDescription(), value.getDescription()); assertEquals(expected.getLicenses(), value.getLicenses()); assertEquals(expected.getAttachedInstances(), value.getAttachedInstances()); assertEquals(expected.getLastAttachTimestamp(), value.getLastAttachTimestamp()); assertEquals(expected.getLastDetachTimestamp(), value.getLastDetachTimestamp()); assertEquals(expected.hashCode(), value.hashCode()); } }
while (diskIterator.hasNext()) { Disk remoteDisk = diskIterator.next(); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertTrue(diskSet.contains(remoteDisk.getDiskId().getDisk())); assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); assertNotNull(remoteDisk.getCreationTimestamp()); while (diskIterator.hasNext()) { Disk remoteDisk = diskIterator.next(); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertTrue(diskSet.contains(remoteDisk.getDiskId().getDisk())); assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); assertNull(remoteDisk.getCreationTimestamp());
resourceCleaner.add(diskId); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertNotNull(remoteDisk.getCreationTimestamp()); assertNotNull(remoteDisk.getGeneratedId()); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertNull(remoteDisk.getCreationTimestamp()); assertNull(remoteDisk.getGeneratedId());
resourceCleaner.add(diskId); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); assertNotNull(remoteDisk.getCreationTimestamp()); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertNull(remoteDisk.getCreationTimestamp()); assertNull(remoteDisk.getGeneratedId());
@Test public void testBuilder() { initializeExpectedDisk(4); assertEquals(DISK_ID, standardDisk.getDiskId()); assertEquals(GENERATED_ID, standardDisk.getGeneratedId()); assertEquals(DISK_CONFIGURATION, standardDisk.getConfiguration()); assertEquals(LAST_DETACH_TIMESTAMP, standardDisk.getLastDetachTimestamp()); assertSame(serviceMockReturnsOptions, standardDisk.getCompute()); assertEquals(DISK_ID, imageDisk.getDiskId()); assertEquals(GENERATED_ID, imageDisk.getGeneratedId()); assertEquals(IMAGE_DISK_CONFIGURATION, imageDisk.getConfiguration()); assertEquals(LAST_DETACH_TIMESTAMP, imageDisk.getLastDetachTimestamp()); assertSame(serviceMockReturnsOptions, imageDisk.getCompute()); assertEquals(DISK_ID, snapshotDisk.getDiskId()); assertEquals(GENERATED_ID, snapshotDisk.getGeneratedId()); assertEquals(SNAPSHOT_DISK_CONFIGURATION, snapshotDisk.getConfiguration()); .setConfiguration(SNAPSHOT_DISK_CONFIGURATION) .build(); assertEquals(DiskId.of("newProject", "newZone"), disk.getDiskId()); assertNull(disk.getGeneratedId()); assertEquals(SNAPSHOT_DISK_CONFIGURATION, disk.getConfiguration());
resourceCleaner.add(snapshotDiskId); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(snapshotDiskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); assertNotNull(remoteDisk.getCreationTimestamp()); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(snapshotDiskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertNull(remoteDisk.getCreationStatus()); assertNull(remoteDisk.getCreationTimestamp());