@Override public String getSerialPortOutput(final InstanceId instance) { try { return runWithRetries( new Callable<String>() { @Override public String call() { return computeRpc.getSerialPortOutput( instance.getZone(), instance.getInstance(), null, optionMap()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public String getSerialPortOutput(final InstanceId instance, final int port) { try { return runWithRetries( new Callable<String>() { @Override public String call() { return computeRpc.getSerialPortOutput( instance.getZone(), instance.getInstance(), port, optionMap()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@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); }
@Override public Region getRegion(final String region, RegionOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Region answer = runWithRetries( new Callable<com.google.api.services.compute.model.Region>() { @Override public com.google.api.services.compute.model.Region call() { return computeRpc.getRegion(region, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Region.fromPb(answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Network getNetwork(final String network, NetworkOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Network answer = runWithRetries( new Callable<com.google.api.services.compute.model.Network>() { @Override public com.google.api.services.compute.model.Network call() { return computeRpc.getNetwork(network, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Network.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 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 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 Disk getDisk(final DiskId diskId, DiskOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Disk answer = runWithRetries( new Callable<com.google.api.services.compute.model.Disk>() { @Override public com.google.api.services.compute.model.Disk call() { return computeRpc.getDisk(diskId.getZone(), diskId.getDisk(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Disk.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Zone getZone(final String zone, ZoneOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Zone answer = runWithRetries( new Callable<com.google.api.services.compute.model.Zone>() { @Override public com.google.api.services.compute.model.Zone call() { return computeRpc.getZone(zone, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Zone.fromPb(answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Override public Snapshot getSnapshot(final String snapshot, SnapshotOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Snapshot answer = runWithRetries( new Callable<com.google.api.services.compute.model.Snapshot>() { @Override public com.google.api.services.compute.model.Snapshot call() { return computeRpc.getSnapshot(snapshot, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Snapshot.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 DiskType getDiskType(final DiskTypeId diskTypeId, DiskTypeOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.DiskType answer = runWithRetries( new Callable<com.google.api.services.compute.model.DiskType>() { @Override public com.google.api.services.compute.model.DiskType call() { return computeRpc.getDiskType( diskTypeId.getZone(), diskTypeId.getType(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : DiskType.fromPb(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 Instance getInstance(final InstanceId instance, InstanceOption... options) { final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Instance answer = runWithRetries( new Callable<com.google.api.services.compute.model.Instance>() { @Override public com.google.api.services.compute.model.Instance call() { return computeRpc.getInstance( instance.getZone(), instance.getInstance(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Instance.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); }