Search in sources :

Example 71 with StorageObject

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

the class GoogleCloudStorageInputSource method getPrefixesSplitStream.

@Override
protected Stream<InputSplit<List<CloudObjectLocation>>> getPrefixesSplitStream(@Nonnull SplitHintSpec splitHintSpec) {
    final Iterator<List<StorageObject>> splitIterator = splitHintSpec.split(storageObjectIterable().iterator(), storageObject -> {
        final BigInteger sizeInBigInteger = storageObject.getSize();
        long sizeInLong;
        if (sizeInBigInteger == null) {
            sizeInLong = Long.MAX_VALUE;
        } else {
            try {
                sizeInLong = sizeInBigInteger.longValueExact();
            } catch (ArithmeticException e) {
                LOG.warn(e, "The object [%s, %s] has a size [%s] out of the range of the long type. " + "The max long value will be used for its size instead.", storageObject.getBucket(), storageObject.getName(), sizeInBigInteger);
                sizeInLong = Long.MAX_VALUE;
            }
        }
        return new InputFileAttribute(sizeInLong);
    });
    return Streams.sequentialStreamFrom(splitIterator).map(objects -> objects.stream().map(this::byteSourceFromStorageObject).collect(Collectors.toList())).map(InputSplit::new);
}
Also used : Logger(org.apache.druid.java.util.common.logger.Logger) Streams(org.apache.druid.utils.Streams) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) GoogleStorageDruidModule(org.apache.druid.storage.google.GoogleStorageDruidModule) GoogleUtils(org.apache.druid.storage.google.GoogleUtils) InputSplit(org.apache.druid.data.input.InputSplit) CloudObjectInputSource(org.apache.druid.data.input.impl.CloudObjectInputSource) InputFileAttribute(org.apache.druid.data.input.InputFileAttribute) GoogleInputDataConfig(org.apache.druid.storage.google.GoogleInputDataConfig) BigInteger(java.math.BigInteger) URI(java.net.URI) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) StorageObject(com.google.api.services.storage.model.StorageObject) JacksonInject(com.fasterxml.jackson.annotation.JacksonInject) GoogleStorage(org.apache.druid.storage.google.GoogleStorage) Iterator(java.util.Iterator) SplitHintSpec(org.apache.druid.data.input.SplitHintSpec) SplittableInputSource(org.apache.druid.data.input.impl.SplittableInputSource) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) CloudObjectLocation(org.apache.druid.data.input.impl.CloudObjectLocation) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) InputEntity(org.apache.druid.data.input.InputEntity) InputFileAttribute(org.apache.druid.data.input.InputFileAttribute) BigInteger(java.math.BigInteger) List(java.util.List) InputSplit(org.apache.druid.data.input.InputSplit)

Example 72 with StorageObject

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

the class GoogleTaskLogsTest method test_killAll_recoverableExceptionWhenDeletingObjects_deletesAllTaskLogs.

@Test
public void test_killAll_recoverableExceptionWhenDeletingObjects_deletesAllTaskLogs() throws IOException {
    StorageObject object1 = GoogleTestUtils.newStorageObject(BUCKET, KEY_1, TIME_0);
    EasyMock.expect(timeSupplier.getAsLong()).andReturn(TIME_NOW);
    Storage.Objects.List listRequest = GoogleTestUtils.expectListRequest(storage, PREFIX_URI);
    GoogleTestUtils.expectListObjects(listRequest, PREFIX_URI, MAX_KEYS, ImmutableList.of(object1));
    GoogleTestUtils.expectDeleteObjects(storage, ImmutableList.of(object1), ImmutableMap.of(object1, RECOVERABLE_EXCEPTION));
    EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
    EasyMock.replay(listRequest, inputDataConfig, storage, timeSupplier);
    googleTaskLogs.killAll();
    EasyMock.verify(listRequest, inputDataConfig, storage, timeSupplier);
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Test(org.junit.Test)

Example 73 with StorageObject

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

the class GoogleTaskLogsTest method test_killOlderThan_recoverableExceptionWhenListingObjects_deletesAllTaskLogs.

@Test
public void test_killOlderThan_recoverableExceptionWhenListingObjects_deletesAllTaskLogs() throws IOException {
    StorageObject object1 = GoogleTestUtils.newStorageObject(BUCKET, KEY_1, TIME_0);
    Storage.Objects.List listRequest = GoogleTestUtils.expectListRequest(storage, PREFIX_URI);
    GoogleTestUtils.expectListObjects(listRequest, PREFIX_URI, MAX_KEYS, ImmutableList.of(object1));
    GoogleTestUtils.expectDeleteObjects(storage, ImmutableList.of(object1), ImmutableMap.of(object1, RECOVERABLE_EXCEPTION));
    EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
    EasyMock.replay(listRequest, inputDataConfig, storage);
    googleTaskLogs.killOlderThan(TIME_NOW);
    EasyMock.verify(listRequest, inputDataConfig, storage);
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Test(org.junit.Test)

Example 74 with StorageObject

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

the class GoogleTaskLogsTest 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);
    EasyMock.expect(timeSupplier.getAsLong()).andReturn(TIME_NOW);
    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(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
    EasyMock.replay(listRequest, inputDataConfig, storage, timeSupplier);
    googleTaskLogs.killAll();
    EasyMock.verify(listRequest, inputDataConfig, storage, timeSupplier);
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) Test(org.junit.Test)

Example 75 with StorageObject

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

the class GoogleTimestampVersionedDataFinderTest method getLatestVersion.

@Test
public void getLatestVersion() {
    String bucket = "bucket";
    String keyPrefix = "prefix/dir/0";
    // object for directory prefix/dir/0/
    final StorageObject storageObject1 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "//", 0);
    storageObject1.setUpdated(new DateTime(System.currentTimeMillis()));
    final StorageObject storageObject2 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/v1", 1);
    storageObject2.setUpdated(new DateTime(System.currentTimeMillis()));
    final StorageObject storageObject3 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/v2", 1);
    storageObject3.setUpdated(new DateTime(System.currentTimeMillis() + 100));
    final StorageObject storageObject4 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/other", 4);
    storageObject4.setUpdated(new DateTime(System.currentTimeMillis() + 100));
    final GoogleStorage storage = ObjectStorageIteratorTest.makeMockClient(ImmutableList.of(storageObject1, storageObject2, storageObject3, storageObject4));
    final GoogleTimestampVersionedDataFinder finder = new GoogleTimestampVersionedDataFinder(storage);
    Pattern pattern = Pattern.compile("v.*");
    URI latest = finder.getLatestVersion(URI.create(StringUtils.format("gs://%s/%s", bucket, keyPrefix)), pattern);
    URI expected = URI.create(StringUtils.format("gs://%s/%s", bucket, storageObject3.getName()));
    Assert.assertEquals(expected, latest);
}
Also used : Pattern(java.util.regex.Pattern) StorageObject(com.google.api.services.storage.model.StorageObject) URI(java.net.URI) DateTime(com.google.api.client.util.DateTime) Test(org.junit.Test)

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