Search in sources :

Example 1 with Path

use of cz.o2.proxima.direct.bulk.Path in project proxima-platform by O2-Czech-Republic.

the class HadoopFileSystem method list.

@Override
public Stream<Path> list(long minTs, long maxTs) {
    URI remappedUri = HadoopStorage.remap(getUri());
    RemoteIterator<LocatedFileStatus> iterator = ExceptionUtils.uncheckedFactory(() -> fs().listFiles(new org.apache.hadoop.fs.Path(remappedUri), true));
    Spliterator<LocatedFileStatus> spliterator = asSpliterator(iterator);
    return StreamSupport.stream(spliterator, false).filter(LocatedFileStatus::isFile).map(f -> f.getPath().toUri().toString().substring(remappedUri.toString().length())).filter(name -> namingConvention.isInRange(name, minTs, maxTs)).map(name -> HadoopPath.of(this, remappedUri + name, accessor));
}
Also used : Path(cz.o2.proxima.direct.bulk.Path) Consumer(java.util.function.Consumer) ExceptionUtils(cz.o2.proxima.util.ExceptionUtils) Stream(java.util.stream.Stream) FileSystem(cz.o2.proxima.direct.bulk.FileSystem) Spliterators(java.util.Spliterators) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) StreamSupport(java.util.stream.StreamSupport) URI(java.net.URI) NamingConvention(cz.o2.proxima.direct.bulk.NamingConvention) Spliterator(java.util.Spliterator) RemoteIterator(org.apache.hadoop.fs.RemoteIterator) Path(cz.o2.proxima.direct.bulk.Path) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) URI(java.net.URI)

Example 2 with Path

use of cz.o2.proxima.direct.bulk.Path in project proxima-platform by O2-Czech-Republic.

the class HadoopStorageTest method testHashCodeAndEquals.

@Test
public void testHashCodeAndEquals() {
    TestUtils.assertHashCodeAndEquals(new HadoopStorage(), new HadoopStorage());
    EntityDescriptor entity = EntityDescriptor.newBuilder().setName("dummy").build();
    final AttributeFamilyDescriptor family = TestUtils.createTestFamily(entity, URI.create("hdfs://host:9000/path"));
    TestUtils.assertHashCodeAndEquals(new HadoopDataAccessor(family), new HadoopDataAccessor(family));
}
Also used : EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) Test(org.junit.Test)

Example 3 with Path

use of cz.o2.proxima.direct.bulk.Path in project proxima-platform by O2-Czech-Republic.

the class HadoopBatchLogReader method processPath.

private boolean processPath(BatchLogObserver observer, long watermark, HadoopPartition partition, HadoopPath path, TerminationContext terminationContext) {
    try {
        try (Reader reader = accessor.getFormat().openReader(path, accessor.getEntityDesc())) {
            long elementIndex = 0;
            final Iterator<StreamElement> iterator = reader.iterator();
            while (iterator.hasNext()) {
                final StreamElement element = iterator.next();
                final Offset offset = Offset.of(partition, elementIndex++, !iterator.hasNext());
                if (terminationContext.isCancelled() || !observer.onNext(element, BatchLogObservers.withWatermark(partition, offset, watermark))) {
                    return false;
                }
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException("Failed to read file " + partition, ex);
    }
    return true;
}
Also used : BatchLogReader(cz.o2.proxima.direct.batch.BatchLogReader) Reader(cz.o2.proxima.direct.bulk.Reader) StreamElement(cz.o2.proxima.storage.StreamElement) IOException(java.io.IOException) Offset(cz.o2.proxima.direct.batch.Offset)

Example 4 with Path

use of cz.o2.proxima.direct.bulk.Path in project proxima-platform by O2-Czech-Republic.

the class S3AccessorTest method testNamingConventionWithBucket.

@Test
public void testNamingConventionWithBucket() {
    S3Accessor accessor = new S3Accessor(TestUtils.createTestFamily(entity, URI.create("s3://bucket/path")));
    NamingConvention convention = accessor.getNamingConvention();
    assertTrue(convention.nameOf(1500000000000L).startsWith("/2017/07/"));
}
Also used : NamingConvention(cz.o2.proxima.direct.bulk.NamingConvention) Test(org.junit.Test)

Example 5 with Path

use of cz.o2.proxima.direct.bulk.Path in project proxima-platform by O2-Czech-Republic.

the class S3AccessorTest method testNamingConventionWithBucketAndNoPath.

@Test
public void testNamingConventionWithBucketAndNoPath() {
    S3Accessor accessor = new S3Accessor(TestUtils.createTestFamily(entity, URI.create("s3://bucket/path")));
    NamingConvention convention = accessor.getNamingConvention();
    assertTrue(convention.nameOf(1500000000000L).startsWith("/2017/07/"));
}
Also used : NamingConvention(cz.o2.proxima.direct.bulk.NamingConvention) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 NamingConvention (cz.o2.proxima.direct.bulk.NamingConvention)6 Path (cz.o2.proxima.direct.bulk.Path)6 StreamElement (cz.o2.proxima.storage.StreamElement)6 IOException (java.io.IOException)6 URI (java.net.URI)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExceptionUtils (cz.o2.proxima.util.ExceptionUtils)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)4 Repository (cz.o2.proxima.repository.Repository)4 List (java.util.List)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Slf4j (lombok.extern.slf4j.Slf4j)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ConfigFactory (com.typesafe.config.ConfigFactory)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3