private void compareImageDiskConfiguration( ImageDiskConfiguration expected, ImageDiskConfiguration value) { assertEquals(expected, value); assertEquals(expected.getDiskType(), value.getDiskType()); assertEquals(expected.getSizeGb(), value.getSizeGb()); assertEquals(expected.getSourceImage(), value.getSourceImage()); assertEquals(expected.getSourceImageId(), value.getSourceImageId()); assertEquals(expected.getType(), value.getType()); assertEquals(expected.hashCode(), value.hashCode()); } }
@Override ImageDiskConfiguration setProjectId(String projectId) { Builder builder = toBuilder().setSourceImage(sourceImage.setProjectId(projectId)); if (getDiskType() != null) { builder.setDiskType(getDiskType().setProjectId(projectId)); } return builder.build(); }
/** Creates an {@code ImageDiskConfiguration} object. */ @Override public ImageDiskConfiguration build() { return new ImageDiskConfiguration(this); } }
@Test public void testToBuilder() { compareImageDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); ImageId newImageId = ImageId.of("newProject", "newImage"); ImageDiskConfiguration diskConfiguration = DISK_CONFIGURATION .toBuilder() .setSizeGb(24L) .setSourceImage(newImageId) .setSourceImageId("newImageId") .build(); assertEquals(24L, diskConfiguration.getSizeGb().longValue()); assertEquals(newImageId, diskConfiguration.getSourceImage()); assertEquals("newImageId", diskConfiguration.getSourceImageId()); diskConfiguration = diskConfiguration .toBuilder() .setSizeGb(SIZE) .setSourceImage(IMAGE) .setSourceImageId(IMAGE_ID) .build(); compareImageDiskConfiguration(DISK_CONFIGURATION, diskConfiguration); }
@Test public void testSetProjectId() { ImageDiskConfiguration diskConfiguration = DISK_CONFIGURATION .toBuilder() .setDiskType(DiskTypeId.of(DISK_TYPE.getZone(), DISK_TYPE.getType())) .setSourceImage(ImageId.of(IMAGE.getImage())) .build(); compareImageDiskConfiguration(DISK_CONFIGURATION, diskConfiguration.setProjectId("project")); }
@Override DiskInfo parse(String... args) throws Exception { if (args.length == 3) { DiskId diskId = parseDiskId(args); return DiskInfo.of(diskId, ImageDiskConfiguration.of(ImageId.of(args[2]))); } else if (args.length == 4) { DiskId diskId = parseDiskId(args); return DiskInfo.of(diskId, ImageDiskConfiguration.of(ImageId.of(args[2], args[3]))); } else if (args.length > 4) { throw new IllegalArgumentException("Too many arguments."); } else { throw new IllegalArgumentException("Missing required arguments."); } }
ImageDiskConfiguration imageDiskConfiguration = IMAGE_DISK_CONFIGURATION .toBuilder() .setDiskType(DiskTypeId.of(TYPE.getZone(), TYPE.getType())) .setSourceImage(ImageId.of(IMAGE.getImage()))
@Override public final int hashCode() { return Objects.hash(baseHashCode(), sourceImage, sourceImageId); }
@Override public final boolean equals(Object obj) { return obj == this || obj != null && obj.getClass().equals(ImageDiskConfiguration.class) && baseEquals((ImageDiskConfiguration) obj); }
@SuppressWarnings("unchecked") static <T extends DiskConfiguration> T fromPb(Disk diskPb) { if (diskPb.getSourceImage() != null) { return (T) ImageDiskConfiguration.fromPb(diskPb); } else if (diskPb.getSourceSnapshot() != null) { return (T) SnapshotDiskConfiguration.fromPb(diskPb); } return (T) StandardDiskConfiguration.fromPb(diskPb); } }
ImageDiskConfiguration diskConfiguration = ImageDiskConfiguration.of(imageId); DiskInfo disk = DiskInfo.of(diskId, diskConfiguration); operation = compute.create(disk);
@Test public void testOf() { ImageDiskConfiguration configuration = ImageDiskConfiguration.of(IMAGE); assertNull(configuration.getDiskType()); assertNull(configuration.getSizeGb()); assertNull(configuration.getSourceImageId()); assertEquals(IMAGE, configuration.getSourceImage()); assertEquals(Type.IMAGE, configuration.getType()); }
@Test public void testBuilder() { assertEquals(DISK_TYPE, DISK_CONFIGURATION.getDiskType()); assertEquals(SIZE, DISK_CONFIGURATION.getSizeGb()); assertEquals(IMAGE, DISK_CONFIGURATION.getSourceImage()); assertEquals(IMAGE_ID, DISK_CONFIGURATION.getSourceImageId()); assertEquals(Type.IMAGE, DISK_CONFIGURATION.getType()); }
String name = BASE_RESOURCE_NAME + "create-and-get-image-disk"; DiskId diskId = DiskId.of(ZONE, name); DiskInfo diskInfo = DiskInfo.of(diskId, ImageDiskConfiguration.of(IMAGE_ID)); Operation operation = compute.create(diskInfo); operation.waitFor(); assertTrue(remoteDisk.getConfiguration() instanceof ImageDiskConfiguration); ImageDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); assertEquals(IMAGE_ID, remoteConfiguration.getSourceImage()); assertNotNull(remoteConfiguration.getSourceImageId()); assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.getType()); assertNotNull(remoteConfiguration.getSizeGb()); assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); assertNull(remoteDisk.getLastAttachTimestamp()); assertNull(remoteDisk.getLastDetachTimestamp()); assertTrue(remoteDisk.getConfiguration() instanceof ImageDiskConfiguration); remoteConfiguration = remoteDisk.getConfiguration(); assertEquals(IMAGE_ID, remoteConfiguration.getSourceImage()); assertNull(remoteConfiguration.getSourceImageId()); assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.getType()); assertNull(remoteConfiguration.getSizeGb()); assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); assertNull(remoteDisk.getLastAttachTimestamp()); assertNull(remoteDisk.getLastDetachTimestamp());