@Test public void testWaitFor_Null() throws InterruptedException { initializeExpectedOperation(3); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; expect(compute.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(null); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(null); replay(compute, mockOptions); initializeOperation(); assertNull(operation.waitFor()); verify(mockOptions); }
@Test public void testWaitFor() throws InterruptedException { initializeExpectedOperation(4); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; Operation successOperation = Operation.fromPb(serviceMockReturnsOptions, globalOperation.toPb().setError(null)); expect(compute.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(successOperation); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(successOperation); replay(compute, mockOptions); initializeOperation(); assertSame(successOperation, operation.waitFor()); verify(mockOptions); }
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); } } } }
Operation operation = compute.create(AddressInfo.of(addressId)); operation = operation.waitFor(); if (operation.getErrors() == null) { System.out.println("Address " + addressId + " was successfully created"); operation = compute.create(disk); operation = operation.waitFor(); if (operation.getErrors() == null) { System.out.println("Disk " + diskId + " was successfully created"); operation = compute.create(instance); operation = operation.waitFor(); if (operation.getErrors() == null) { System.out.println("Instance " + instanceId + " was successfully created");
@Test public void testWaitForCheckingPeriod_Null() throws InterruptedException { initializeExpectedOperation(4); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; Operation runningOperation = Operation.fromPb( serviceMockReturnsOptions, globalOperation.toPb().setError(null).setStatus("RUNNING")); expect(compute.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(runningOperation); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(null); replay(compute, mockOptions); initializeOperation(); assertNull(operation.waitFor(RetryOption.initialRetryDelay(Duration.ofMillis(1L)))); verify(compute, mockOptions); }
@Test public void testWaitForCheckingPeriod() throws InterruptedException { initializeExpectedOperation(5); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; Operation runningOperation = Operation.fromPb( serviceMockReturnsOptions, globalOperation.toPb().setError(null).setStatus("RUNNING")); Operation completedOperation = Operation.fromPb(serviceMockReturnsOptions, globalOperation.toPb().setError(null)); expect(compute.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(runningOperation); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)) .andReturn(completedOperation); expect(compute.getOperation(GLOBAL_OPERATION_ID)).andReturn(completedOperation); replay(compute, mockOptions); initializeOperation(); assertSame( completedOperation, operation.waitFor(RetryOption.initialRetryDelay(Duration.ofMillis(1)))); verify(mockOptions); }
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); } } }
@Test public void testAggregatedListAddresses() throws InterruptedException, TimeoutException { String prefix = BASE_RESOURCE_NAME + "aggregated-list-address"; String[] addressNames = {prefix + "1", prefix + "2"}; AddressId firstAddressId = RegionAddressId.of(REGION, addressNames[0]); AddressId secondAddressId = GlobalAddressId.of(REGION, addressNames[1]); Operation firstOperation = compute.create(AddressInfo.of(firstAddressId)); Operation secondOperation = compute.create(AddressInfo.of(secondAddressId)); firstOperation.waitFor(); resourceCleaner.add(firstAddressId); secondOperation.waitFor(); resourceCleaner.add(secondAddressId); Set<String> addressSet = ImmutableSet.copyOf(addressNames); Compute.AddressFilter filter = Compute.AddressFilter.equals(Compute.AddressField.NAME, prefix + "\\d"); Page<Address> addressPage = compute.listAddresses(Compute.AddressAggregatedListOption.filter(filter)); Iterator<Address> addressIterator = addressPage.iterateAll().iterator(); int count = 0; while (addressIterator.hasNext()) { Address address = addressIterator.next(); assertNotNull(address.getAddressId()); assertTrue(addressSet.contains(address.getAddressId().getAddress())); assertNotNull(address.getAddress()); assertNotNull(address.getCreationTimestamp()); assertNotNull(address.getGeneratedId()); count++; } assertEquals(2, count); }
.build(); Operation operation = compute.create(instanceInfo); operation.waitFor(); Instance remoteInstance = compute.getInstance(instanceId); resourceCleaner.add(instanceId); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); assertEquals(tags, remoteInstance.getTags().getValues()); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); assertEquals(metadata, remoteInstance.getMetadata().getValues()); operation.waitFor(); operation = remoteInstance.setMachineType(MachineTypeId.of(ZONE, "n1-standard-1")); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); assertEquals("n1-standard-1", remoteInstance.getMachineType().getType()); SchedulingOptions.standard(false, SchedulingOptions.Maintenance.TERMINATE); operation = remoteInstance.setSchedulingOptions(options); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); assertEquals(options, remoteInstance.getSchedulingOptions());
AddressInfo addressInfo = AddressInfo.of(addressId); Operation addressOperation = compute.create(addressInfo); addressOperation.waitFor(); instanceOperation.waitFor(); Address remoteAddress = compute.getAddress(addressId); resourceCleaner.add(addressId); .build(); instanceOperation = remoteInstance.addAccessConfig(networkInterfaceName, accessConfig); instanceOperation.waitFor(); remoteInstance = compute.getInstance(instanceId); List<NetworkInterface.AccessConfig> accessConfigurations = instanceOperation.waitFor(); remoteInstance = compute.getInstance(instanceId); assertTrue(remoteInstance.getNetworkInterfaces().get(0).getAccessConfigurations().isEmpty());
Operation firstOperation = compute.create(DiskInfo.of(firstDiskId, configuration)); Operation secondOperation = compute.create(DiskInfo.of(secondDiskId, configuration)); firstOperation.waitFor(); resourceCleaner.add(firstDiskId); secondOperation.waitFor(); resourceCleaner.add(secondDiskId); Set<String> zoneSet = ImmutableSet.copyOf(diskZones);
Operation firstOperation = compute.create(AddressInfo.of(firstAddressId)); Operation secondOperation = compute.create(AddressInfo.of(secondAddressId)); firstOperation.waitFor(); resourceCleaner.add(firstAddressId); secondOperation.waitFor(); resourceCleaner.add(secondAddressId); Set<String> addressSet = ImmutableSet.copyOf(addressNames);
.build(); Operation operation = compute.create(instanceInfo); operation.waitFor(); Instance remoteInstance = compute.getInstance( assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.getStatus()); operation = remoteInstance.stop(); operation.waitFor(); remoteInstance = compute.getInstance( assertEquals(InstanceInfo.Status.TERMINATED, remoteInstance.getStatus()); operation = remoteInstance.start(); operation.waitFor(); remoteInstance = compute.getInstance( assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.getStatus()); operation = remoteInstance.reset(); operation.waitFor(); remoteInstance = compute.getInstance(
Operation firstOperation = compute.create(AddressInfo.of(firstAddressId)); Operation secondOperation = compute.create(AddressInfo.of(secondAddressId)); firstOperation.waitFor(); resourceCleaner.add(firstAddressId); secondOperation.waitFor(); resourceCleaner.add(secondAddressId); Set<String> addressSet = ImmutableSet.copyOf(addressNames);
@Test public void testCreateGetAndDeleteGlobalAddress() throws InterruptedException, TimeoutException { String name = BASE_RESOURCE_NAME + "create-and-get-global-address"; AddressId addressId = GlobalAddressId.of(name); AddressInfo addressInfo = AddressInfo.of(addressId); Operation operation = compute.create(addressInfo); operation.waitFor(); // test get Address remoteAddress = compute.getAddress(addressId); resourceCleaner.add(addressId); assertNotNull(remoteAddress); assertTrue(remoteAddress.getAddressId() instanceof GlobalAddressId); assertEquals(addressId.getAddress(), remoteAddress.getAddressId().getAddress()); assertNotNull(remoteAddress.getAddress()); assertNotNull(remoteAddress.getCreationTimestamp()); assertNotNull(remoteAddress.getGeneratedId()); assertNotNull(remoteAddress.getStatus()); // test get with selected fields remoteAddress = compute.getAddress(addressId, Compute.AddressOption.fields()); assertNotNull(remoteAddress); assertTrue(remoteAddress.getAddressId() instanceof GlobalAddressId); assertEquals(addressId.getAddress(), remoteAddress.getAddressId().getAddress()); assertNull(remoteAddress.getAddress()); assertNull(remoteAddress.getCreationTimestamp()); assertNull(remoteAddress.getGeneratedId()); operation = remoteAddress.delete(); operation.waitFor(); resourceCleaner.remove(addressId); assertNull(compute.getAddress(addressId)); }
AddressInfo addressInfo = AddressInfo.of(addressId); Operation operation = compute.create(addressInfo); operation.waitFor(); assertNull(remoteAddress.getGeneratedId()); operation = remoteAddress.delete(); operation.waitFor(); resourceCleaner.remove(addressId); assertNull(compute.getAddress(addressId));
NetworkInfo.of(networkId, StandardNetworkConfiguration.of("192.168.0.0/16")); Operation operation = compute.create(networkInfo); operation.waitFor(); assertEquals("192.168.0.0/16", remoteConfiguration.getIpRange()); operation = network.delete(); operation.waitFor(); resourceCleaner.remove(networkId); assertNull(compute.getNetwork(name));
DiskInfo.of(diskId, StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd"), 100L)); Operation operation = compute.create(diskInfo); operation.waitFor(); assertNull(remoteDisk.getLastDetachTimestamp()); operation = remoteDisk.resize(200L); operation.waitFor(); assertNull(remoteDisk.getLastDetachTimestamp()); operation = remoteDisk.delete(); operation.waitFor(); resourceCleaner.remove(diskId); assertNull(compute.getDisk(diskId));
DiskInfo diskInfo = DiskInfo.of(diskId, ImageDiskConfiguration.of(IMAGE_ID)); Operation operation = compute.create(diskInfo); operation.waitFor(); assertNull(remoteDisk.getLastDetachTimestamp()); operation = remoteDisk.delete(); operation.waitFor(); resourceCleaner.remove(diskId); assertNull(compute.getDisk(diskId));