/** * Checks if this operation exists. * * @return {@code true} if this operation exists, {@code false} otherwise * @throws ComputeException upon failure */ public boolean exists() { return reload(OperationOption.fields()) != null; }
@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, 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, 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, AddressId address) throws InterruptedException { Operation operation = compute.deleteAddress(address); if (operation == null) { System.out.printf("Address %s does not exist%n", address); 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("Address %s was deleted%n", address); } else { System.out.printf("Deletion of address %s failed%n", address); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Override public void run(Compute compute, InstanceId instance) throws InterruptedException { Operation operation = compute.stop(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 stopped%n", instance); } else { System.out.printf("Attempt to stop instance %s failed%n", instance); 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, 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, 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, SchedulingOptions> instanceAndScheduling) throws InterruptedException { InstanceId instanceId = instanceAndScheduling.x(); SchedulingOptions schedulingOptions = instanceAndScheduling.y(); Operation operation = compute.setSchedulingOptions(instanceId, schedulingOptions); if (operation == null) { System.out.printf("Instance %s does not exist%n", instanceId); 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("Scheduling options set for instance %s%n", instanceId); } else { System.out.printf("Attempt to set scheduling options for instance %s failed%n", instanceId); System.out.printf("Error: %s%n", operation.getErrors()); } }
@Test public void testReload() throws Exception { initializeExpectedOperation(5); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(globalOperation); replay(compute); initializeOperation(); Operation updatedOperation = operation.reload(); compareOperation(globalOperation, updatedOperation); verify(compute); }
@Test public void testReloadNull() throws Exception { initializeExpectedOperation(3); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(null); replay(compute); initializeOperation(); assertNull(operation.reload()); verify(compute); }
@Test public void testReloadWithOptions() throws Exception { initializeExpectedOperation(5); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getOperation(GLOBAL_OPERATION_ID, Compute.OperationOption.fields())) .andReturn(globalOperation); replay(compute); initializeOperation(); Operation updatedOperation = operation.reload(Compute.OperationOption.fields()); compareOperation(globalOperation, updatedOperation); verify(compute); }