Search in sources :

Example 11 with StorageObject

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

the class FakeStorageRpc method get.

/**
   * Returns the requested storage object or {@code null} if not found.
   */
@Override
public StorageObject get(StorageObject object, Map<Option, ?> options) throws StorageException {
    // because the caller won't mind the extra fields.
    if (throwIfOption && !options.isEmpty() && options.size() > 1 && options.keySet().toArray()[0] != Storage.BlobGetOption.fields(Storage.BlobField.ID)) {
        throw new UnsupportedOperationException();
    }
    String key = fullname(object);
    if (metadata.containsKey(key)) {
        StorageObject ret = metadata.get(key);
        if (contents.containsKey(key)) {
            ret.setSize(BigInteger.valueOf(contents.get(key).length));
        }
        ret.setId(key);
        return ret;
    }
    return null;
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject)

Example 12 with StorageObject

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

the class StorageBatchTest method testGetWithOptions.

@Test
public void testGetWithOptions() {
    EasyMock.reset(storage, batchMock, optionsMock);
    EasyMock.expect(storage.getOptions()).andReturn(optionsMock).times(2);
    EasyMock.expect(optionsMock.getService()).andReturn(storage);
    Capture<RpcBatch.Callback<StorageObject>> callback = Capture.newInstance();
    Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
    batchMock.addGet(EasyMock.eq(BLOB_INFO.toPb()), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
    EasyMock.replay(storage, batchMock, optionsMock);
    StorageBatchResult<Blob> batchResult = storageBatch.get(BLOB_ID, BLOB_GET_OPTIONS);
    assertNotNull(callback.getValue());
    assertEquals(2, capturedOptions.getValue().size());
    for (BlobGetOption option : BLOB_GET_OPTIONS) {
        assertEquals(option.getValue(), capturedOptions.getValue().get(option.getRpcOption()));
    }
    RpcBatch.Callback<StorageObject> capturedCallback = callback.getValue();
    capturedCallback.onSuccess(BLOB_INFO.toPb());
    assertEquals(new Blob(storage, new Blob.BuilderImpl(BLOB_INFO)), batchResult.get());
}
Also used : StorageRpc(com.google.cloud.storage.spi.v1.StorageRpc) StorageObject(com.google.api.services.storage.model.StorageObject) BlobGetOption(com.google.cloud.storage.Storage.BlobGetOption) RpcBatch(com.google.cloud.storage.spi.v1.RpcBatch) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project gradle by gradle.

the class GcsClient method list.

@Nullable
public List<String> list(URI uri) throws ResourceException {
    List<StorageObject> results = new ArrayList<StorageObject>();
    String path = cleanResourcePath(uri);
    try {
        Storage.Objects.List listRequest = storage.objects().list(uri.getHost()).setPrefix(path);
        Objects objects;
        // Iterate through each page of results, and add them to our results list.
        do {
            objects = listRequest.execute();
            // Add the items in this page of results to the list we'll return.
            results.addAll(objects.getItems());
            // Get the next page, in the next iteration of this loop.
            listRequest.setPageToken(objects.getNextPageToken());
        } while (null != objects.getNextPageToken());
    } catch (IOException e) {
        throw ResourceExceptions.getFailed(uri, e);
    }
    List<String> resultStrings = new ArrayList<String>();
    for (StorageObject result : results) {
        resultStrings.add(result.getName());
    }
    return resultStrings;
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) ArrayList(java.util.ArrayList) Objects(com.google.api.services.storage.model.Objects) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 14 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project gradle by gradle.

the class GcsResourceConnector method openResource.

@Nullable
@Override
public ExternalResourceReadResponse openResource(URI location, boolean revalidate) throws ResourceException {
    LOGGER.debug("Attempting to get resource: {}", location);
    StorageObject gcsObject = gcsClient.getResource(location);
    if (gcsObject == null) {
        return null;
    }
    return new GcsResource(gcsClient, gcsObject, location);
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Nullable(javax.annotation.Nullable)

Example 15 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project ignite by apache.

the class TcpDiscoveryGoogleStorageIpFinder method registerAddresses.

/**
 * {@inheritDoc}
 */
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
    assert !F.isEmpty(addrs);
    init();
    for (InetSocketAddress addr : addrs) {
        String key = keyFromAddr(addr);
        StorageObject object = new StorageObject();
        object.setBucket(bucketName);
        object.setName(key);
        InputStreamContent content = new InputStreamContent("application/octet-stream", OBJECT_CONTENT);
        content.setLength(OBJECT_CONTENT.available());
        try {
            Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, object, content);
            insertObject.execute();
        } catch (Exception e) {
            throw new IgniteSpiException("Failed to put entry [bucketName=" + bucketName + ", entry=" + key + ']', e);
        }
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) InetSocketAddress(java.net.InetSocketAddress) InputStreamContent(com.google.api.client.http.InputStreamContent) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) GeneralSecurityException(java.security.GeneralSecurityException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Aggregations

StorageObject (com.google.api.services.storage.model.StorageObject)39 Test (org.junit.Test)13 Objects (com.google.api.services.storage.model.Objects)12 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 RetryHelperException (com.google.cloud.RetryHelper.RetryHelperException)7 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)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 Nullable (javax.annotation.Nullable)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