@Override public void run(Compute compute, InstanceId instance) throws InterruptedException { Operation operation = compute.start(instance); if (operation == null) { System.out.printf("Instance %s does not exist%n", instance); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Instance %s was started%n", instance); } else { System.out.printf("Attempt to start instance %s failed%n", instance); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, DiskId disk) throws InterruptedException { Operation operation = compute.deleteDisk(disk); if (operation == null) { System.out.printf("Disk %s does not exist%n", disk); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Disk %s was deleted%n", disk); } else { System.out.printf("Deletion of disk %s failed%n", disk); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, InstanceId instance) throws InterruptedException { Operation operation = compute.deleteInstance(instance); if (operation == null) { System.out.printf("Instance %s does not exist%n", instance); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Instance %s was deleted%n", instance); } else { System.out.printf("Deletion of instance %s failed%n", instance); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, SubnetworkId subnetwork) throws InterruptedException { Operation operation = compute.deleteSubnetwork(subnetwork); if (operation == null) { System.out.printf("Subnetwork %s does not exist%n", subnetwork); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Subnetwork %s was deleted%n", subnetwork); } else { System.out.printf("Deletion of subnetwork %s failed%n", subnetwork); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, InstanceId instance) throws InterruptedException { Operation operation = compute.reset(instance); if (operation == null) { System.out.printf("Instance %s does not exist%n", instance); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Instance %s was reset%n", instance); } else { System.out.printf("Attempt to reset instance %s failed%n", instance); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, SubnetworkInfo subnetwork) throws InterruptedException { Operation operation = compute.create(subnetwork); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Subnetwork %s was created%n", subnetwork.getSubnetworkId()); } else { System.out.printf("Creation of subnetwork %s failed%n", subnetwork.getSubnetworkId()); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Override public void run(Compute compute, NetworkId network) throws InterruptedException { Operation operation = compute.deleteNetwork(network.getNetwork()); if (operation == null) { System.out.printf("Network %s does not exist%n", network); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Network %s was deleted%n", network); } else { System.out.printf("Deletion of network %s failed%n", network); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, AddressId address) throws InterruptedException { Operation operation = compute.create(AddressInfo.of(address)); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Address %s was created%n", address); } else { System.out.printf("Creation of address %s failed%n", address); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, SnapshotInfo snapshot) throws InterruptedException { Operation operation = compute.create(snapshot); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Snapshot %s was created%n", snapshot.getSnapshotId()); } else { System.out.printf("Creation of snapshot %s failed%n", snapshot.getSnapshotId()); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Override public void run(Compute compute, ImageInfo image) throws InterruptedException { Operation operation = compute.create(image); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Image %s was created%n", image.getImageId()); } else { System.out.printf("Creation of image %s failed%n", image.getImageId()); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Override public void run(Compute compute, NetworkInfo network) throws InterruptedException { Operation operation = compute.create(network); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Network %s was created%n", network.getNetworkId()); } else { System.out.printf("Creation of network %s failed%n", network.getNetworkId()); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, DiskInfo disk) throws InterruptedException { Operation operation = compute.create(disk); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Disk %s was created%n", disk.getDiskId()); } else { System.out.printf("Creation of disk %s failed%n", disk.getDiskId()); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Override public void run(Compute compute, InstanceInfo instance) throws InterruptedException { Operation operation = compute.create(instance); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Instance %s was created%n", instance.getInstanceId()); } else { System.out.printf("Creation of instance %s failed%n", instance.getInstanceId()); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Override public void run(Compute compute, Tuple<InstanceId, MachineTypeId> instanceAndType) throws InterruptedException { InstanceId instance = instanceAndType.x(); MachineTypeId machineType = instanceAndType.y(); Operation operation = compute.setMachineType(instance, machineType); if (operation == null) { System.out.printf("Instance %s does not exist%n", instance); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Machine type set for instance %s%n", instance); } else { System.out.printf("Attempt to set machine type for instance %s failed%n", instance); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Override public void run(Compute compute, Tuple<InstanceId, String> instanceAndDevice) throws InterruptedException { InstanceId instance = instanceAndDevice.x(); String deviceName = instanceAndDevice.y(); Operation operation = compute.detachDisk(instance, deviceName); if (operation == null) { System.out.printf("Instance %s does not exist%n", instance); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Disk detached from instance %s%n", instance); } else { System.out.printf("Attempt to detach disk from instance %s failed%n", instance); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Override public void run(Compute compute, Tuple<InstanceId, Map<String, String>> instanceAndMetadata) throws InterruptedException { InstanceId instanceId = instanceAndMetadata.x(); Map<String, String> metadata = instanceAndMetadata.y(); Instance instance = compute.getInstance(instanceId); if (instance == null) { System.out.printf("Instance %s does not exist%n", instanceId); return; } Operation operation = instance.setMetadata(metadata); while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Metadata set for instance %s%n", instanceId); } else { System.out.printf("Attempt to set metadata for instance %s failed%n", instanceId); System.out.printf("Error: %s%n", operation.getErrors()); } }
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); } } } }
public static void main(String... args) throws InterruptedException, TimeoutException { Compute compute = ComputeOptions.getDefaultInstance().getService(); ImageId imageId = ImageId.of("debian-cloud", "debian-8-jessie-v20160329"); NetworkId networkId = NetworkId.of("default"); AttachedDisk attachedDisk = AttachedDisk.of(AttachedDisk.CreateDiskConfiguration.of(imageId)); NetworkInterface networkInterface = NetworkInterface.of(networkId); InstanceId instanceId = InstanceId.of("us-central1-a", "instance-name"); MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1"); Operation operation = compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface)); operation = operation.waitFor(); if (operation.getErrors() == null) { // use instance Instance instance = compute.getInstance(instanceId); } } }
private void assertEqualsCommonFields(Operation operation) { assertEquals(GENERATED_ID, operation.getGeneratedId()); assertEquals(CLIENT_OPERATION_ID, operation.getClientOperationId()); assertEquals(OPERATION_TYPE, operation.getOperationType()); assertEquals(TARGET_LINK, operation.getTargetLink()); assertEquals(TARGET_ID, operation.getTargetId()); assertEquals(STATUS, operation.getStatus()); assertEquals(STATUS_MESSAGE, operation.getStatusMessage()); assertEquals(USER, operation.getUser()); assertEquals(PROGRESS, operation.getProgress()); assertEquals(INSERT_TIME, operation.getInsertTime()); assertEquals(START_TIME, operation.getStartTime()); assertEquals(END_TIME, operation.getEndTime()); assertEquals(ERRORS, operation.getErrors()); assertEquals(WARNINGS, operation.getWarnings()); assertEquals(HTTP_ERROR_STATUS_CODE, globalOperation.getHttpErrorStatusCode()); assertEquals(HTTP_ERROR_MESSAGE, globalOperation.getHttpErrorMessage()); assertEquals(DESCRIPTION, globalOperation.getDescription()); assertSame(serviceMockReturnsOptions, globalOperation.getCompute()); }
private void assertNullCommonFields(Operation operation) { assertNull(operation.getGeneratedId()); assertNull(operation.getClientOperationId()); assertNull(operation.getOperationType()); assertNull(operation.getTargetLink()); assertNull(operation.getTargetId()); assertNull(operation.getStatus()); assertNull(operation.getStatusMessage()); assertNull(operation.getUser()); assertNull(operation.getProgress()); assertNull(operation.getInsertTime()); assertNull(operation.getStartTime()); assertNull(operation.getEndTime()); assertNull(operation.getErrors()); assertNull(operation.getWarnings()); assertNull(operation.getHttpErrorStatusCode()); assertNull(operation.getHttpErrorMessage()); assertNull(operation.getDescription()); assertSame(serviceMockReturnsOptions, operation.getCompute()); }