Refine search
private void compareDiskId(DiskId expected, DiskId value) { assertEquals(expected, value); assertEquals(expected.getProject(), expected.getProject()); assertEquals(expected.getZone(), expected.getZone()); assertEquals(expected.getDisk(), expected.getDisk()); assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } }
static DiskId parseDiskId(String[] args) { return DiskId.of(args[0], args[1]); } }
private Builder(Image imagePb) { super(Type.DISK, imagePb); this.sourceDisk = DiskId.fromUrl(imagePb.getSourceDisk()); this.sourceDiskId = imagePb.getSourceDiskId(); }
@Override DiskId setProjectId(String projectId) { if (getProject() != null) { return this; } return DiskId.of(projectId, zone, disk); }
@Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteDisk(disk.getZone(), disk.getDisk(), optionsMap); } },
throws InterruptedException, TimeoutException { String name = BASE_RESOURCE_NAME + "create-and-get-standard-disk"; DiskId diskId = DiskId.of(ZONE, name); DiskInfo diskInfo = DiskInfo.of(diskId, StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd"), 100L)); Operation operation = compute.create(diskInfo); operation.waitFor(); Disk remoteDisk = compute.getDisk(diskId); resourceCleaner.add(diskId); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertNotNull(remoteDisk.getCreationTimestamp()); assertNotNull(remoteDisk.getGeneratedId()); operation.waitFor(); remoteDisk = compute.getDisk(diskId, Compute.DiskOption.fields(Compute.DiskField.SIZE_GB)); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); assertNull(remoteDisk.getCreationTimestamp()); assertNull(remoteDisk.getGeneratedId());
String[] diskZones = {"us-central1-a", "us-east1-c"}; String[] diskNames = {prefix + "1", prefix + "2"}; DiskId firstDiskId = DiskId.of(diskZones[0], diskNames[0]); DiskId secondDiskId = DiskId.of(diskZones[1], diskNames[1]); DiskConfiguration configuration = StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd"), 100L); Operation firstOperation = compute.create(DiskInfo.of(firstDiskId, configuration)); Operation secondOperation = compute.create(DiskInfo.of(secondDiskId, configuration)); firstOperation.waitFor(); resourceCleaner.add(firstDiskId); Compute.DiskFilter diskFilter = Compute.DiskFilter.equals(Compute.DiskField.NAME, prefix + "\\d"); Page<Disk> diskPage = compute.listDisks(Compute.DiskAggregatedListOption.filter(diskFilter)); Iterator<Disk> diskIterator = diskPage.iterateAll().iterator(); int count = 0; 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());
@Test public void testDeleteDisk_Null() { EasyMock.expect( computeRpcMock.deleteDisk(DISK_ID.getZone(), DISK_ID.getDisk(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.getService(); assertNull(compute.deleteDisk(DISK_ID)); }
@Test public void testResizeDisk_Null() { EasyMock.expect( computeRpcMock.resizeDisk(DISK_ID.getZone(), DISK_ID.getDisk(), 42L, EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.getService(); assertNull(compute.resize(DISK_ID, 42L)); }
@Test public void testCreateSnapshot() { EasyMock.expect( computeRpcMock.createSnapshot( DISK_ID.getZone(), DISK_ID.getDisk(), SNAPSHOT_ID.getSnapshot(), null, EMPTY_RPC_OPTIONS)) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); Operation operation = compute.create(SNAPSHOT); assertEquals(zoneOperation, operation); }
String diskName = BASE_RESOURCE_NAME + "create-and-get-image-disk"; String imageName = BASE_RESOURCE_NAME + "create-and-get-image"; DiskId diskId = DiskId.of(ZONE, diskName); ImageId imageId = ImageId.of(imageName); DiskInfo diskInfo = DiskInfo.of(diskId, StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd"), 100L)); Operation operation = compute.create(diskInfo); operation.waitFor(); Disk remoteDisk = compute.getDisk(diskId); ImageInfo imageInfo = ImageInfo.of(imageId, DiskImageConfiguration.of(diskId)); operation = compute.create(imageInfo); operation.waitFor(); resourceCleaner.add(diskId); DiskImageConfiguration remoteConfiguration = image.getConfiguration(); assertEquals(ImageConfiguration.Type.DISK, remoteConfiguration.getType()); assertEquals(diskName, remoteConfiguration.getSourceDisk().getDisk()); assertNull(image.getStatus()); assertNull(image.getDiskSizeGb()); remoteConfiguration = image.getConfiguration(); assertEquals(ImageConfiguration.Type.DISK, remoteConfiguration.getType()); assertEquals(diskName, remoteConfiguration.getSourceDisk().getDisk()); assertEquals(100L, (long) image.getDiskSizeGb()); assertNotNull(image.getStatus());
Operation operation = compute.create(addressInfo); operation.waitFor(); Address address = compute.getAddress(addressId); resourceCleaner.add(addressId); .setNetworkInterfaces(networkInterface) .build(); operation = compute.create(instanceInfo); operation.waitFor(); AttachedDisk.PersistentDiskConfiguration remoteConfiguration = remoteInstance.getAttachedDisks().get(0).getConfiguration(); assertEquals(instanceName, remoteConfiguration.getSourceDisk().getDisk()); assertEquals(ZONE, remoteConfiguration.getSourceDisk().getZone()); assertTrue(remoteConfiguration.boot()); assertTrue(remoteConfiguration.autoDelete());
@Test public void testListEmptyDisks() { compute = options.getService(); ImmutableList<com.google.api.services.compute.model.Disk> disks = ImmutableList.of(); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.<String, Iterable<com.google.api.services.compute.model.Disk>>of(null, disks); EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks(DISK_ID.getZone()); assertNull(page.getNextPageToken()); assertArrayEquals(disks.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testOf() { DiskId diskId = DiskId.of(PROJECT, ZONE, NAME); assertEquals(PROJECT, diskId.getProject()); assertEquals(ZONE, diskId.getZone()); assertEquals(NAME, diskId.getDisk()); assertEquals(URL, diskId.getSelfLink()); diskId = DiskId.of(ZONE, NAME); assertNull(diskId.getProject()); assertEquals(ZONE, diskId.getZone()); assertEquals(NAME, diskId.getDisk()); diskId = DiskId.of(ZoneId.of(ZONE), NAME); assertNull(diskId.getProject()); assertEquals(ZONE, diskId.getZone()); assertEquals(NAME, diskId.getDisk()); }
@Test public void testCreateDisk() { EasyMock.expect(computeRpcMock.createDisk(DISK_ID.getZone(), DISK.toPb(), EMPTY_RPC_OPTIONS)) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); DiskId diskId = DiskId.of("zone", "disk"); DiskTypeId diskTypeId = DiskTypeId.of("zone", "diskType"); DiskInfo disk = DISK.toBuilder() .setDiskId(diskId) .setConfiguration(StandardDiskConfiguration.of(diskTypeId)) .build(); Operation operation = compute.create(disk); assertEquals(zoneOperation, operation); }
public static void main(String... args) throws InterruptedException, TimeoutException { Compute compute = ComputeOptions.getDefaultInstance().getService(); DiskId diskId = DiskId.of("us-central1-a", "disk-name"); Disk disk = compute.getDisk(diskId, Compute.DiskOption.fields()); if (disk != null) { String snapshotName = "disk-name-snapshot"; Operation operation = disk.createSnapshot(snapshotName); operation = operation.waitFor(); if (operation.getErrors() == null) { // use snapshot Snapshot snapshot = compute.getSnapshot(snapshotName); } } } }
@Override public com.google.api.services.compute.model.Operation call() { return computeRpc.resizeDisk(disk.getZone(), disk.getDisk(), sizeGb, optionsMap); } },
Operation operation = compute.create(AddressInfo.of(addressId)); DiskId diskId = DiskId.of("us-central1-a", "test-disk"); ImageDiskConfiguration diskConfiguration = ImageDiskConfiguration.of(imageId); DiskInfo disk = DiskInfo.of(diskId, diskConfiguration); operation = compute.create(disk); Address externalIp = compute.getAddress(addressId); InstanceId instanceId = InstanceId.of("us-central1-a", "test-instance"); NetworkId networkId = NetworkId.of("default");