com.google.cloud.compute.DiskConfiguration

Here are the examples of the java api class com.google.cloud.compute.DiskConfiguration taken from open source projects.

1. ITComputeTest#testListDisksAndSnapshots()

Project: gcloud-java
Source File: ITComputeTest.java
View license
@Test
public void testListDisksAndSnapshots() throws InterruptedException, TimeoutException {
    String prefix = BASE_RESOURCE_NAME + "list-disks-and-snapshots-disk";
    String[] diskNames = { prefix + "1", prefix + "2" };
    DiskId firstDiskId = DiskId.of(ZONE, diskNames[0]);
    DiskId secondDiskId = DiskId.of(ZONE, 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();
    secondOperation.waitFor();
    Set<String> diskSet = ImmutableSet.copyOf(diskNames);
    // test list disks
    Compute.DiskFilter diskFilter = Compute.DiskFilter.equals(Compute.DiskField.NAME, prefix + "\\d");
    Page<Disk> diskPage = compute.listDisks(ZONE, Compute.DiskListOption.filter(diskFilter));
    Iterator<Disk> diskIterator = diskPage.iterateAll();
    int count = 0;
    while (diskIterator.hasNext()) {
        Disk remoteDisk = diskIterator.next();
        assertEquals(ZONE, remoteDisk.diskId().zone());
        assertTrue(diskSet.contains(remoteDisk.diskId().disk()));
        assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus());
        assertNotNull(remoteDisk.creationTimestamp());
        assertNotNull(remoteDisk.generatedId());
        assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration);
        StandardDiskConfiguration remoteConfiguration = remoteDisk.configuration();
        assertEquals(100L, (long) remoteConfiguration.sizeGb());
        assertEquals("pd-ssd", remoteConfiguration.diskType().type());
        assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type());
        assertNull(remoteDisk.lastAttachTimestamp());
        assertNull(remoteDisk.lastDetachTimestamp());
        count++;
    }
    assertEquals(2, count);
    // test list disks with selected fields
    count = 0;
    diskPage = compute.listDisks(ZONE, Compute.DiskListOption.filter(diskFilter), Compute.DiskListOption.fields(Compute.DiskField.STATUS));
    diskIterator = diskPage.iterateAll();
    while (diskIterator.hasNext()) {
        Disk remoteDisk = diskIterator.next();
        assertEquals(ZONE, remoteDisk.diskId().zone());
        assertTrue(diskSet.contains(remoteDisk.diskId().disk()));
        assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus());
        assertNull(remoteDisk.creationTimestamp());
        assertNull(remoteDisk.generatedId());
        assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration);
        StandardDiskConfiguration remoteConfiguration = remoteDisk.configuration();
        assertNull(remoteConfiguration.sizeGb());
        assertEquals("pd-ssd", remoteConfiguration.diskType().type());
        assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type());
        assertNull(remoteDisk.lastAttachTimestamp());
        assertNull(remoteDisk.lastDetachTimestamp());
        count++;
    }
    assertEquals(2, count);
    // test snapshots
    SnapshotId firstSnapshotId = SnapshotId.of(diskNames[0]);
    SnapshotId secondSnapshotId = SnapshotId.of(diskNames[1]);
    firstOperation = compute.create(SnapshotInfo.of(firstSnapshotId, firstDiskId));
    secondOperation = compute.create(SnapshotInfo.of(secondSnapshotId, secondDiskId));
    firstOperation.waitFor();
    secondOperation.waitFor();
    // test list snapshots
    Compute.SnapshotFilter snapshotFilter = Compute.SnapshotFilter.equals(Compute.SnapshotField.NAME, prefix + "\\d");
    Page<Snapshot> snapshotPage = compute.listSnapshots(Compute.SnapshotListOption.filter(snapshotFilter));
    Iterator<Snapshot> snapshotIterator = snapshotPage.iterateAll();
    count = 0;
    while (snapshotIterator.hasNext()) {
        Snapshot remoteSnapshot = snapshotIterator.next();
        assertNotNull(remoteSnapshot.generatedId());
        assertTrue(diskSet.contains(remoteSnapshot.snapshotId().snapshot()));
        assertNotNull(remoteSnapshot.creationTimestamp());
        assertNotNull(remoteSnapshot.status());
        assertEquals(100L, (long) remoteSnapshot.diskSizeGb());
        assertTrue(diskSet.contains(remoteSnapshot.sourceDisk().disk()));
        assertNotNull(remoteSnapshot.sourceDiskId());
        assertNotNull(remoteSnapshot.storageBytes());
        assertNotNull(remoteSnapshot.storageBytesStatus());
        count++;
    }
    assertEquals(2, count);
    // test list snapshots with selected fields
    snapshotPage = compute.listSnapshots(Compute.SnapshotListOption.filter(snapshotFilter), Compute.SnapshotListOption.fields(Compute.SnapshotField.CREATION_TIMESTAMP));
    snapshotIterator = snapshotPage.iterateAll();
    count = 0;
    while (snapshotIterator.hasNext()) {
        Snapshot remoteSnapshot = snapshotIterator.next();
        assertNull(remoteSnapshot.generatedId());
        assertTrue(diskSet.contains(remoteSnapshot.snapshotId().snapshot()));
        assertNotNull(remoteSnapshot.creationTimestamp());
        assertNull(remoteSnapshot.status());
        assertNull(remoteSnapshot.diskSizeGb());
        assertNull(remoteSnapshot.sourceDisk());
        assertNull(remoteSnapshot.sourceDiskId());
        assertNull(remoteSnapshot.storageBytes());
        assertNull(remoteSnapshot.storageBytesStatus());
        count++;
    }
    assertEquals(2, count);
    compute.deleteDisk(firstDiskId);
    compute.deleteDisk(secondDiskId);
    compute.deleteSnapshot(firstSnapshotId);
    compute.deleteSnapshot(secondSnapshotId);
}

2. ITComputeTest#testAggregatedListDisks()

Project: gcloud-java
Source File: ITComputeTest.java
View license
@Test
public void testAggregatedListDisks() throws InterruptedException, TimeoutException {
    String prefix = BASE_RESOURCE_NAME + "list-aggregated-disk";
    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();
    secondOperation.waitFor();
    Set<String> zoneSet = ImmutableSet.copyOf(diskZones);
    Set<String> diskSet = ImmutableSet.copyOf(diskNames);
    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();
    int count = 0;
    while (diskIterator.hasNext()) {
        Disk remoteDisk = diskIterator.next();
        assertTrue(zoneSet.contains(remoteDisk.diskId().zone()));
        assertTrue(diskSet.contains(remoteDisk.diskId().disk()));
        assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus());
        assertNotNull(remoteDisk.creationTimestamp());
        assertNotNull(remoteDisk.generatedId());
        assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration);
        StandardDiskConfiguration remoteConfiguration = remoteDisk.configuration();
        assertEquals(100L, (long) remoteConfiguration.sizeGb());
        assertEquals("pd-ssd", remoteConfiguration.diskType().type());
        assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type());
        count++;
    }
    assertEquals(2, count);
    compute.deleteDisk(firstDiskId);
    compute.deleteDisk(secondDiskId);
}