CREATE_DISK_CONFIGURATION .toBuilder() .setDiskType(DiskTypeId.of("zone", "diskType")) .setSourceImage(ImageId.of("image")) .build();
@Test public void testConfigurationSetProjectId() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DiskId.of("zone", "disk")); comparePersistentDiskConfiguration( PersistentDiskConfiguration.of(DiskId.of("project", "zone", "disk")), persistentConfiguration.setProjectId("project")); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DiskTypeId.of("zone", "diskType")); compareScratchDiskConfiguration( ScratchDiskConfiguration.of(DiskTypeId.of("project", "zone", "diskType")), scratchDiskConfiguration.setProjectId("project")); CreateDiskConfiguration createDiskConfiguration = CREATE_DISK_CONFIGURATION .toBuilder() .setDiskType(DiskTypeId.of("zone", "diskType")) .setSourceImage(ImageId.of("image")) .build(); compareCreateDiskConfiguration( CREATE_DISK_CONFIGURATION, createDiskConfiguration.setProjectId("project")); }
@SuppressWarnings("unchecked") static CreateDiskConfiguration fromPb( com.google.api.services.compute.model.AttachedDisk diskPb) { AttachedDiskInitializeParams initializeParamsPb = diskPb.getInitializeParams(); Builder builder = newBuilder(ImageId.fromUrl(initializeParamsPb.getSourceImage())); if (initializeParamsPb.getDiskType() != null) { builder.setDiskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); } builder.setDiskName(initializeParamsPb.getDiskName()); builder.setDiskSizeGb(initializeParamsPb.getDiskSizeGb()); builder.setAutoDelete(diskPb.getAutoDelete()); if (initializeParamsPb.getDiskType() != null) { builder.setDiskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); } return builder.build(); } }
@Override CreateDiskConfiguration setProjectId(String projectId) { Builder builder = toBuilder(); if (builder.diskType != null) { builder.setDiskType(diskType.setProjectId(projectId)); } if (builder.sourceImage != null) { builder.setSourceImage(sourceImage.setProjectId(projectId)); } return builder.build(); }