Search in sources :

Example 66 with StorageObject

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

the class GcsResourceConnector method getMetaData.

@Nullable
@Override
public ExternalResourceMetaData getMetaData(ExternalResourceName location, boolean revalidate) throws ResourceException {
    LOGGER.debug("Attempting to get resource metadata: {}", location);
    StorageObject gcsObject = gcsClient.getResource(location.getUri());
    if (gcsObject == null) {
        return null;
    }
    return toExternalResourceMetaData(location.getUri(), gcsObject);
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Nullable(javax.annotation.Nullable)

Example 67 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project druid by druid-io.

the class GoogleTestUtils method newStorageObject.

public static StorageObject newStorageObject(String bucket, String key, long lastModifiedTimestamp) {
    StorageObject object = new StorageObject();
    object.setBucket(bucket);
    object.setName(key);
    object.setUpdated(new DateTime(lastModifiedTimestamp));
    object.setEtag("etag");
    object.setSize(BigInteger.valueOf(CONTENT.length));
    return object;
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) DateTime(com.google.api.client.util.DateTime)

Example 68 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project druid by druid-io.

the class GoogleTimestampVersionedDataFinder method getLatestVersion.

@Override
public URI getLatestVersion(URI descriptorBase, @Nullable Pattern pattern) {
    try {
        long mostRecent = Long.MIN_VALUE;
        URI latest = null;
        final CloudObjectLocation baseLocation = new CloudObjectLocation(descriptorBase);
        final Objects objects = storage.list(baseLocation.getBucket()).setPrefix(baseLocation.getPath()).setMaxResults(MAX_LISTING_KEYS).execute();
        for (StorageObject storageObject : objects.getItems()) {
            if (GoogleUtils.isDirectoryPlaceholder(storageObject)) {
                continue;
            }
            // remove path prefix from file name
            final CloudObjectLocation objectLocation = new CloudObjectLocation(storageObject.getBucket(), storageObject.getName());
            final String keyString = StringUtils.maybeRemoveLeadingSlash(storageObject.getName().substring(baseLocation.getPath().length()));
            if (pattern != null && !pattern.matcher(keyString).matches()) {
                continue;
            }
            final long latestModified = storageObject.getUpdated().getValue();
            if (latestModified >= mostRecent) {
                mostRecent = latestModified;
                latest = objectLocation.toUri(GoogleStorageDruidModule.SCHEME_GS);
            }
        }
        return latest;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) CloudObjectLocation(org.apache.druid.data.input.impl.CloudObjectLocation) Objects(com.google.api.services.storage.model.Objects) IOException(java.io.IOException) URI(java.net.URI)

Example 69 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project druid by druid-io.

the class GoogleDataSegmentKillerTest method test_killAll_noException_deletesAllTaskLogs.

@Test
public void test_killAll_noException_deletesAllTaskLogs() throws IOException {
    StorageObject object1 = GoogleTestUtils.newStorageObject(BUCKET, KEY_1, TIME_0);
    StorageObject object2 = GoogleTestUtils.newStorageObject(BUCKET, KEY_2, TIME_1);
    Storage.Objects.List listRequest = GoogleTestUtils.expectListRequest(storage, PREFIX_URI);
    GoogleTestUtils.expectListObjects(listRequest, PREFIX_URI, MAX_KEYS, ImmutableList.of(object1, object2));
    GoogleTestUtils.expectDeleteObjects(storage, ImmutableList.of(object1, object2), ImmutableMap.of());
    EasyMock.expect(accountConfig.getBucket()).andReturn(BUCKET).anyTimes();
    EasyMock.expect(accountConfig.getPrefix()).andReturn(PREFIX).anyTimes();
    EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
    EasyMock.replay(listRequest, accountConfig, inputDataConfig, storage);
    GoogleDataSegmentKiller killer = new GoogleDataSegmentKiller(storage, accountConfig, inputDataConfig);
    killer.killAll();
    EasyMock.verify(listRequest, accountConfig, inputDataConfig, storage);
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Test(org.junit.Test)

Example 70 with StorageObject

use of com.google.api.services.storage.model.StorageObject in project druid by druid-io.

the class GoogleCloudStorageInputSourceTest method addExpectedPrefixObjects.

private static void addExpectedPrefixObjects(URI prefix, List<URI> uris) throws IOException {
    final String bucket = prefix.getAuthority();
    Storage.Objects.List listRequest = EasyMock.createMock(Storage.Objects.List.class);
    EasyMock.expect(STORAGE.list(EasyMock.eq(bucket))).andReturn(listRequest).once();
    EasyMock.expect(listRequest.setPageToken(EasyMock.anyString())).andReturn(listRequest).once();
    EasyMock.expect(listRequest.setMaxResults((long) MAX_LISTING_LENGTH)).andReturn(listRequest).once();
    EasyMock.expect(listRequest.setPrefix(EasyMock.eq(StringUtils.maybeRemoveLeadingSlash(prefix.getPath())))).andReturn(listRequest).once();
    List<StorageObject> mockObjects = new ArrayList<>();
    for (URI uri : uris) {
        StorageObject s = new StorageObject();
        s.setBucket(bucket);
        s.setName(uri.getPath());
        s.setSize(BigInteger.valueOf(CONTENT.length));
        mockObjects.add(s);
    }
    Objects response = new Objects();
    response.setItems(mockObjects);
    EasyMock.expect(listRequest.execute()).andReturn(response).once();
    EasyMock.expect(response.getItems()).andReturn(mockObjects).once();
    EasyMock.replay(listRequest);
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Objects(com.google.api.services.storage.model.Objects) ArrayList(java.util.ArrayList) URI(java.net.URI)

Aggregations

StorageObject (com.google.api.services.storage.model.StorageObject)81 Test (org.junit.Test)33 Objects (com.google.api.services.storage.model.Objects)21 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)16 Storage (com.google.api.services.storage.Storage)12 List (java.util.List)9 URI (java.net.URI)8 RetryHelperException (com.google.cloud.RetryHelper.RetryHelperException)7 GcsOptions (org.apache.beam.sdk.extensions.gcp.options.GcsOptions)7 GcsPath (org.apache.beam.sdk.extensions.gcp.util.gcsfs.GcsPath)7 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)6 Nullable (javax.annotation.Nullable)6 File (java.io.File)5 Pattern (java.util.regex.Pattern)5 DateTime (com.google.api.client.util.DateTime)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