@Override public Operation apply(com.google.api.services.compute.model.Operation operation) { return Operation.fromPb(serviceOptions.getService(), operation); } };
@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); }
@Test public void testIsDone_False() throws Exception { initializeExpectedOperation(4); Compute.OperationOption[] expectedOptions = { Compute.OperationOption.fields(Compute.OperationField.STATUS) }; expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getOperation(GLOBAL_OPERATION_ID, expectedOptions)) .andReturn( Operation.fromPb( serviceMockReturnsOptions, globalOperation.toPb().setStatus("PENDING"))); replay(compute); initializeOperation(); assertFalse(operation.isDone()); verify(compute); }
@Override public Operation resize(final DiskId disk, final long sizeGb, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.resizeDisk(disk.getZone(), disk.getDisk(), sizeGb, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation reset(final InstanceId instance, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.reset(instance.getZone(), instance.getInstance(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation start(final InstanceId instance, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.start(instance.getZone(), instance.getInstance(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation deleteNetwork(final NetworkId network, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteNetwork(network.getNetwork(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation deleteSnapshot(final String snapshot, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteSnapshot(snapshot, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation deleteDisk(final DiskId disk, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteDisk(disk.getZone(), disk.getDisk(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation deleteSubnetwork(final SubnetworkId subnetwork, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteSubnetwork( subnetwork.getRegion(), subnetwork.getSubnetwork(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation setTags(final InstanceId instance, final Tags tags, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.setTags( instance.getZone(), instance.getInstance(), tags.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation deleteInstance(final InstanceId instance, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteInstance( instance.getZone(), instance.getInstance(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation stop(final InstanceId instance, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.stop(instance.getZone(), instance.getInstance(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation detachDisk( final InstanceId instance, final String deviceName, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.detachDisk( instance.getZone(), instance.getInstance(), deviceName, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation setMetadata( final InstanceId instance, final Metadata metadata, OperationOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.setMetadata( instance.getZone(), instance.getInstance(), metadata.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@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); }
@Override public Operation create(NetworkInfo network, OperationOption... options) { final NetworkInfo completeNetwork = network.setProjectId(getOptions().getProjectId()); final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.createNetwork(completeNetwork.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation create(ImageInfo image, OperationOption... options) { final ImageInfo completeImage = image.setProjectId(getOptions().getProjectId()); final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.createImage(completeImage.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Operation deleteImage(ImageId image, OperationOption... options) { final ImageId completeId = image.setProjectId(getOptions().getProjectId()); final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteImage( completeId.getProject(), completeId.getImage(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
private Operation attachDisk( final InstanceId instance, AttachedDisk diskToAttach, OperationOption... options) { final AttachedDisk completeDisk = diskToAttach.setProjectId(getOptions().getProjectId()); final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.attachDisk( instance.getZone(), instance.getInstance(), completeDisk.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }