Search in sources :

Example 16 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.

the class StorageImplTest method testUpdateAllArray.

@Test
public void testUpdateAllArray() {
    RpcBatch batchMock = EasyMock.createMock(RpcBatch.class);
    Capture<RpcBatch.Callback<StorageObject>> callback1 = Capture.newInstance();
    Capture<RpcBatch.Callback<StorageObject>> callback2 = Capture.newInstance();
    batchMock.addPatch(EasyMock.eq(BLOB_INFO1.toPb()), EasyMock.capture(callback1), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
    batchMock.addPatch(EasyMock.eq(BLOB_INFO2.toPb()), EasyMock.capture(callback2), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
    EasyMock.expect(storageRpcMock.createBatch()).andReturn(batchMock);
    batchMock.submit();
    EasyMock.replay(storageRpcMock, batchMock);
    initializeService();
    List<Blob> resultBlobs = storage.update(BLOB_INFO1, BLOB_INFO2);
    callback1.getValue().onSuccess(BLOB_INFO1.toPb());
    callback2.getValue().onFailure(new GoogleJsonError());
    assertEquals(2, resultBlobs.size());
    assertEquals(new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO1)), resultBlobs.get(0));
    assertNull(resultBlobs.get(1));
    EasyMock.verify(batchMock);
}
Also used : BlobWriteOption(com.google.cloud.storage.Storage.BlobWriteOption) BucketSourceOption(com.google.cloud.storage.Storage.BucketSourceOption) BlobSourceOption(com.google.cloud.storage.Storage.BlobSourceOption) BlobTargetOption(com.google.cloud.storage.Storage.BlobTargetOption) StorageObject(com.google.api.services.storage.model.StorageObject) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) RpcBatch(com.google.cloud.storage.spi.v1.RpcBatch) Test(org.junit.Test)

Example 17 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.

the class StorageImpl method copy.

@Override
public CopyWriter copy(final CopyRequest copyRequest) {
    final StorageObject source = copyRequest.getSource().toPb();
    final Map<StorageRpc.Option, ?> sourceOptions = optionMap(copyRequest.getSource().getGeneration(), null, copyRequest.getSourceOptions(), true);
    final StorageObject targetObject = copyRequest.getTarget().toPb();
    final Map<StorageRpc.Option, ?> targetOptions = optionMap(copyRequest.getTarget().getGeneration(), copyRequest.getTarget().getMetageneration(), copyRequest.getTargetOptions());
    try {
        RewriteResponse rewriteResponse = runWithRetries(new Callable<RewriteResponse>() {

            @Override
            public RewriteResponse call() {
                return storageRpc.openRewrite(new StorageRpc.RewriteRequest(source, sourceOptions, copyRequest.overrideInfo(), targetObject, targetOptions, copyRequest.getMegabytesCopiedPerChunk()));
            }
        }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
        return new CopyWriter(getOptions(), rewriteResponse);
    } catch (RetryHelperException e) {
        throw StorageException.translateAndThrow(e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) RewriteResponse(com.google.cloud.storage.spi.v1.StorageRpc.RewriteResponse) RetryHelperException(com.google.cloud.RetryHelper.RetryHelperException)

Example 18 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.

the class StorageImpl method compose.

@Override
public Blob compose(final ComposeRequest composeRequest) {
    final List<StorageObject> sources = Lists.newArrayListWithCapacity(composeRequest.getSourceBlobs().size());
    for (ComposeRequest.SourceBlob sourceBlob : composeRequest.getSourceBlobs()) {
        sources.add(BlobInfo.newBuilder(BlobId.of(composeRequest.getTarget().getBucket(), sourceBlob.getName(), sourceBlob.getGeneration())).build().toPb());
    }
    final StorageObject target = composeRequest.getTarget().toPb();
    final Map<StorageRpc.Option, ?> targetOptions = optionMap(composeRequest.getTarget().getGeneration(), composeRequest.getTarget().getMetageneration(), composeRequest.getTargetOptions());
    try {
        return Blob.fromPb(this, runWithRetries(new Callable<StorageObject>() {

            @Override
            public StorageObject call() {
                return storageRpc.compose(sources, target, targetOptions);
            }
        }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
    } catch (RetryHelperException e) {
        throw StorageException.translateAndThrow(e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Callable(java.util.concurrent.Callable) RetryHelperException(com.google.cloud.RetryHelper.RetryHelperException)

Example 19 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.

the class StorageImpl method update.

@Override
public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
    final StorageObject storageObject = blobInfo.toPb();
    final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
    try {
        return Blob.fromPb(this, runWithRetries(new Callable<StorageObject>() {

            @Override
            public StorageObject call() {
                return storageRpc.patch(storageObject, optionsMap);
            }
        }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
    } catch (RetryHelperException e) {
        throw StorageException.translateAndThrow(e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Callable(java.util.concurrent.Callable) RetryHelperException(com.google.cloud.RetryHelper.RetryHelperException)

Example 20 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.

the class BlobId method toPb.

StorageObject toPb() {
    StorageObject storageObject = new StorageObject();
    storageObject.setBucket(bucket);
    storageObject.setName(name);
    storageObject.setGeneration(generation);
    return storageObject;
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject)

Aggregations

StorageObject (com.google.api.services.storage.model.StorageObject)35 Test (org.junit.Test)13 Objects (com.google.api.services.storage.model.Objects)10 RetryHelperException (com.google.cloud.RetryHelper.RetryHelperException)7 ArrayList (java.util.ArrayList)7 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)6 IOException (java.io.IOException)6 GcsPath (org.apache.beam.sdk.util.gcsfs.GcsPath)6 RpcBatch (com.google.cloud.storage.spi.v1.RpcBatch)5 Storage (com.google.api.services.storage.Storage)4 BlobSourceOption (com.google.cloud.storage.Storage.BlobSourceOption)4 BlobTargetOption (com.google.cloud.storage.Storage.BlobTargetOption)4 BlobWriteOption (com.google.cloud.storage.Storage.BlobWriteOption)4 BucketSourceOption (com.google.cloud.storage.Storage.BucketSourceOption)4 GcsOptions (org.apache.beam.sdk.extensions.gcp.options.GcsOptions)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 Map (java.util.Map)3 Callable (java.util.concurrent.Callable)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2