private Blob internalCreate(BlobInfo info, final byte[] content, BlobTargetOption... options) { Preconditions.checkNotNull(content); final StorageObject blobPb = info.toPb(); final Map<StorageRpc.Option, ?> optionsMap = optionMap(info, options); try { return Blob.fromPb( this, runWithRetries( new Callable<StorageObject>() { @Override public StorageObject call() { return storageRpc.create(blobPb, new ByteArrayInputStream(content), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public boolean deleteNotification(final String bucket, final String notification) { try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return ((StorageRpc) storage.getOptions().getRpc()) .deleteNotification(bucket, notification); } }, storage.getOptions().getRetrySettings(), EXCEPTION_HANDLER, storage.getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.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 protected void flushBuffer(final int length, final boolean last) { try { runWithRetries( callable( new Runnable() { @Override public void run() { getOptions() .getStorageRpcV1() .write(getUploadId(), getBuffer(), 0, getPosition(), length, last); } }), getOptions().getRetrySettings(), StorageImpl.EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelper.RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@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 ServiceAccount getServiceAccount(final String projectId) { try { com.google.api.services.storage.model.ServiceAccount answer = runWithRetries( new Callable<com.google.api.services.storage.model.ServiceAccount>() { @Override public com.google.api.services.storage.model.ServiceAccount call() { return storageRpc.getServiceAccount(projectId); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : ServiceAccount.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.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); } }
@Override public Acl getAcl(final BlobId blob, final Entity entity) { try { ObjectAccessControl answer = runWithRetries( new Callable<ObjectAccessControl>() { @Override public ObjectAccessControl call() { return storageRpc.getAcl( blob.getBucket(), blob.getName(), blob.getGeneration(), entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Acl.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public boolean delete(BlobId blob, BlobSourceOption... options) { final StorageObject storageObject = blob.toPb(); final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options); try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.delete(storageObject, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public byte[] readAllBytes(BlobId blob, BlobSourceOption... options) { final StorageObject storageObject = blob.toPb(); final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options); try { return runWithRetries( new Callable<byte[]>() { @Override public byte[] call() { return storageRpc.load(storageObject, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Acl getDefaultAcl(final String bucket, final Entity entity) { try { ObjectAccessControl answer = runWithRetries( new Callable<ObjectAccessControl>() { @Override public ObjectAccessControl call() { return storageRpc.getDefaultAcl(bucket, entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Acl.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public boolean delete(String bucket, BucketSourceOption... options) { final com.google.api.services.storage.model.Bucket bucketPb = BucketInfo.of(bucket).toPb(); final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.delete(bucketPb, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public List<Acl> listAcls(final BlobId blob) { try { List<ObjectAccessControl> answer = runWithRetries( new Callable<List<ObjectAccessControl>>() { @Override public List<ObjectAccessControl> call() { return storageRpc.listAcls( blob.getBucket(), blob.getName(), blob.getGeneration()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return Lists.transform(answer, Acl.FROM_OBJECT_PB_FUNCTION); } catch (RetryHelperException e) { throw StorageException.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); } }
@Test public void testCreateFromStream() { RemoteStorageHelper helper = RemoteStorageHelper.create(PROJECT_ID, JSON_KEY_STREAM); StorageOptions options = helper.getOptions(); assertEquals(PROJECT_ID, options.getProjectId()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout()); assertEquals(10, options.getRetrySettings().getMaxAttempts()); assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay()); assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout()); assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay()); } }
@Override public Acl getAcl(final String bucket, final Entity entity, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); BucketAccessControl answer = runWithRetries( new Callable<BucketAccessControl>() { @Override public BucketAccessControl call() { return storageRpc.getAcl(bucket, entity.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Acl.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Acl createDefaultAcl(String bucket, Acl acl) { final ObjectAccessControl aclPb = acl.toObjectPb().setBucket(bucket); try { return Acl.fromPb( runWithRetries( new Callable<ObjectAccessControl>() { @Override public ObjectAccessControl call() { return storageRpc.createDefaultAcl(aclPb); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Policy getIamPolicy(final String bucket, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return convertFromApiPolicy( runWithRetries( new Callable<com.google.api.services.storage.model.Policy>() { @Override public com.google.api.services.storage.model.Policy call() { return storageRpc.getIamPolicy(bucket, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Policy setIamPolicy( final String bucket, final Policy policy, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return convertFromApiPolicy( runWithRetries( new Callable<com.google.api.services.storage.model.Policy>() { @Override public com.google.api.services.storage.model.Policy call() { return storageRpc.setIamPolicy(bucket, convertToApiPolicy(policy), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Acl updateAcl(String bucket, Acl acl, BucketSourceOption... options) { final BucketAccessControl aclPb = acl.toBucketPb().setBucket(bucket); try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return Acl.fromPb( runWithRetries( new Callable<BucketAccessControl>() { @Override public BucketAccessControl call() { return storageRpc.patchAcl(aclPb, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }