@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 boolean deleteDefaultAcl(final String bucket, final Entity entity) { try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.deleteDefaultAcl(bucket, entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public <T> T runInTransaction(final TransactionCallable<T> callable) { final DatastoreImpl self = this; try { return RetryHelper.runWithRetries( new ReadWriteTransactionCallable<T>(self, callable, null), retrySettings, TRANSACTION_EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } }
try { Operation operation = RetryHelper.poll( new Callable<Operation>() { @Override options.getClock()); return operation == null ? null : reload(); } catch (ExecutionException e) { throw ComputeException.translateAndThrow(e);
private Job waitForJob(RetrySettings waitSettings) throws InterruptedException { try { return RetryHelper.poll( new Callable<Job>() { @Override public Job call() throws Exception { return bigquery.getJob(getJobId(), JobOption.fields(BigQuery.JobField.STATUS)); } }, waitSettings, new BasicResultRetryAlgorithm<Job>() { @Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, Job prevResponse, TimedAttemptSettings prevSettings) { return null; } @Override public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) { return prevResponse != null && !JobStatus.State.DONE.equals(prevResponse.getStatus().getState()); } }, options.getClock()); } catch (ExecutionException e) { throw BigQueryException.translateAndThrow(e); } }
public static <V> V runWithRetries(Callable<V> callable, RetryParams params, ExceptionHandler exceptionHandler, Clock clock) throws RetryHelperException { RetryHelper<V> retryHelper = new RetryHelper<>(callable, params, exceptionHandler, clock); Context previousContext = getContext(); setContext(new Context(retryHelper)); try { return retryHelper.doRetry(); } finally { setContext(previousContext); } } }
@Override public boolean deleteAcl(final BlobId blob, final Entity entity) { try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.deleteAcl( blob.getBucket(), blob.getName(), blob.getGeneration(), entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public <T> T runInTransaction( final TransactionCallable<T> callable, TransactionOptions transactionOptions) { final DatastoreImpl self = this; try { return RetryHelper.runWithRetries( new ReadWriteTransactionCallable<T>(self, callable, transactionOptions), retrySettings, TRANSACTION_EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } }
private QueryResponse waitForQueryResults( RetrySettings waitSettings, final QueryResultsOption... resultsOptions) throws InterruptedException { if (getConfiguration().getType() != Type.QUERY) { throw new UnsupportedOperationException( "Waiting for query results is supported only for " + Type.QUERY + " jobs"); } try { return RetryHelper.poll( new Callable<QueryResponse>() { @Override public QueryResponse call() { return bigquery.getQueryResults(getJobId(), resultsOptions); } }, waitSettings, new BasicResultRetryAlgorithm<QueryResponse>() { @Override public boolean shouldRetry(Throwable prevThrowable, QueryResponse prevResponse) { return prevResponse != null && !prevResponse.getCompleted(); } }, options.getClock()); } catch (ExecutionException e) { throw BigQueryException.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); } }
@Override public List<Acl> listDefaultAcls(final String bucket) { try { List<ObjectAccessControl> answer = runWithRetries( new Callable<List<ObjectAccessControl>>() { @Override public List<ObjectAccessControl> call() { return storageRpc.listDefaultAcls(bucket); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return Lists.transform(answer, Acl.FROM_OBJECT_PB_FUNCTION); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
try { com.google.longrunning.Operation proto = RetryHelper.poll( new Callable<com.google.longrunning.Operation>() { @Override
@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 boolean deleteAcl( final String bucket, final Entity entity, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.deleteAcl(bucket, entity.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
private Job waitForJob(RetrySettings waitSettings) throws InterruptedException { try { return RetryHelper.poll( new Callable<Job>() { @Override public Job call() throws Exception { return bigquery.getJob(getJobId(), JobOption.fields(BigQuery.JobField.STATUS)); } }, waitSettings, new BasicResultRetryAlgorithm<Job>() { @Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, Job prevResponse, TimedAttemptSettings prevSettings) { return null; } @Override public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) { return prevResponse != null && !JobStatus.State.DONE.equals(prevResponse.getStatus().getState()); } }, options.getClock()); } catch (ExecutionException e) { throw BigQueryException.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); } }
private static String open( final StorageOptions options, final BlobInfo blob, final Map<StorageRpc.Option, ?> optionsMap) { try { return runWithRetries( new Callable<String>() { @Override public String call() { return options.getStorageRpcV1().open(blob.toPb(), optionsMap); } }, options.getRetrySettings(), StorageImpl.EXCEPTION_HANDLER, options.getClock()); } catch (RetryHelper.RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
private QueryResponse waitForQueryResults( RetrySettings waitSettings, final QueryResultsOption... resultsOptions) throws InterruptedException { if (getConfiguration().getType() != Type.QUERY) { throw new UnsupportedOperationException( "Waiting for query results is supported only for " + Type.QUERY + " jobs"); } try { return RetryHelper.poll( new Callable<QueryResponse>() { @Override public QueryResponse call() { return bigquery.getQueryResults(getJobId(), resultsOptions); } }, waitSettings, new BasicResultRetryAlgorithm<QueryResponse>() { @Override public boolean shouldRetry(Throwable prevThrowable, QueryResponse prevResponse) { return prevResponse != null && !prevResponse.getCompleted(); } }, options.getClock()); } catch (ExecutionException e) { throw BigQueryException.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 List<Acl> listAcls(final String bucket, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); List<BucketAccessControl> answer = runWithRetries( new Callable<List<BucketAccessControl>>() { @Override public List<BucketAccessControl> call() { return storageRpc.listAcls(bucket, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return Lists.transform(answer, Acl.FROM_BUCKET_PB_FUNCTION); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }