Search in sources :

Example 6 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class DirectDataAccessorWrapper method createStreamFromUpdates.

@Override
public PCollection<StreamElement> createStreamFromUpdates(Pipeline pipeline, List<AttributeDescriptor<?>> attrs, long startStamp, long endStamp, long limit) {
    BatchLogReader reader = direct.getBatchLogReader(context).orElseThrow(() -> new IllegalArgumentException("Cannot create batch reader from " + direct));
    final PCollection<StreamElement> ret;
    ret = pipeline.apply("ReadBatchUnbounded:" + uri, BatchLogRead.of(attrs, Long.MAX_VALUE, factory, reader, startStamp, endStamp));
    return ret.setCoder(StreamElementCoder.of(factory)).setTypeDescriptor(TypeDescriptor.of(StreamElement.class));
}
Also used : BatchLogReader(cz.o2.proxima.direct.batch.BatchLogReader) StreamElement(cz.o2.proxima.storage.StreamElement)

Example 7 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class AttributeDescriptorCoder method decode.

@Override
public AttributeDescriptor<?> decode(InputStream inStream) throws IOException {
    String entity = STRING_CODER.decode(inStream);
    EntityDescriptor entityDesc = repo().getEntity(entity);
    return entityDesc.getAttribute(STRING_CODER.decode(inStream));
}
Also used : EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor)

Example 8 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class Console method delete.

public void delete(EntityDescriptor entityDesc, AttributeDescriptor<?> attrDesc, String key, String attribute, long stamp) throws InterruptedException {
    Preconditions.checkState(direct != null, "Can write with direct operator only. Add runtime dependency");
    OnlineAttributeWriter writer = Optionals.get(direct.getWriter(attrDesc));
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<Throwable> exc = new AtomicReference<>();
    final StreamElement delete;
    if (attrDesc.isWildcard() && attribute.equals(attrDesc.getName())) {
        delete = StreamElement.deleteWildcard(entityDesc, attrDesc, UUID.randomUUID().toString(), key, stamp);
    } else {
        delete = StreamElement.delete(entityDesc, attrDesc, UUID.randomUUID().toString(), key, attribute, stamp);
    }
    writer.write(delete, (success, ex) -> {
        if (!success) {
            exc.set(ex);
        }
        latch.countDown();
    });
    latch.await();
    if (exc.get() != null) {
        throw new RuntimeException(exc.get());
    }
}
Also used : OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) StreamElement(cz.o2.proxima.storage.StreamElement) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 9 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class OffsetTrackingBatchLogReader method observe.

@Override
public ObserveHandle observe(List<Partition> partitions, List<AttributeDescriptor<?>> attributes, BatchLogObserver observer) {
    final OffsetTrackingBatchLogObserver wrappedObserver = new OffsetTrackingBatchLogObserver(observer);
    final ObserveHandle handle = delegate.observe(partitions, attributes, wrappedObserver);
    return new OffsetTrackingObserveHandle() {

        @Override
        public List<Offset> getCurrentOffsets() {
            final Map<Partition, Offset> result = new HashMap<>();
            partitions.forEach(p -> result.put(p, Offset.of(p, -1, false)));
            wrappedObserver.getConsumedOffsets().forEach((p, o) -> result.merge(p, o, OffsetTrackingBatchLogReader::mergeOffsets));
            return new ArrayList<>(result.values());
        }

        @Override
        public void close() {
            handle.close();
        }
    };
}
Also used : Partition(cz.o2.proxima.storage.Partition) ObserveHandle(cz.o2.proxima.direct.batch.ObserveHandle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Offset(cz.o2.proxima.direct.batch.Offset)

Example 10 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class BatchLogSourceFunctionTest method testRunAndClose.

@Test
void testRunAndClose() throws Exception {
    final Repository repository = Repository.ofTest(ConfigFactory.parseString(MODEL));
    final AttributeDescriptor<?> attribute = repository.getEntity("test").getAttribute("data");
    final BatchLogSourceFunction<StreamElement> sourceFunction = new BatchLogSourceFunction<StreamElement>(repository.asFactory(), Collections.singletonList(attribute), ResultExtractor.identity()) {

        @Override
        BatchLogReader createLogReader(List<AttributeDescriptor<?>> attributeDescriptors) {
            final DirectDataOperator direct = repository.getOrCreateOperator(DirectDataOperator.class);
            final ListBatchReader reader = ListBatchReader.ofPartitioned(direct.getContext());
            return OffsetTrackingBatchLogReader.of(reader);
        }
    };
    final AbstractStreamOperatorTestHarness<StreamElement> testHarness = createTestHarness(sourceFunction, 1, 0);
    testHarness.initializeEmptyState();
    testHarness.open();
    final CheckedThread runThread = new CheckedThread("run") {

        @Override
        public void go() throws Exception {
            sourceFunction.run(new TestSourceContext<StreamElement>() {

                @Override
                public void collect(StreamElement element) {
                // No-op.
                }
            });
        }
    };
    runThread.start();
    sourceFunction.awaitRunning();
    sourceFunction.cancel();
    testHarness.close();
    // Make sure run thread finishes normally.
    runThread.sync();
}
Also used : DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) Repository(cz.o2.proxima.repository.Repository) ListBatchReader(cz.o2.proxima.direct.storage.ListBatchReader) StreamElement(cz.o2.proxima.storage.StreamElement) ArrayList(java.util.ArrayList) List(java.util.List) CheckedThread(org.apache.flink.core.testutils.CheckedThread) Test(org.junit.jupiter.api.Test)

Aggregations

EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)71 Test (org.junit.Test)59 StreamElement (cz.o2.proxima.storage.StreamElement)51 ArrayList (java.util.ArrayList)46 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)33 CountDownLatch (java.util.concurrent.CountDownLatch)33 List (java.util.List)29 KeyValue (cz.o2.proxima.direct.randomaccess.KeyValue)24 Slf4j (lombok.extern.slf4j.Slf4j)24 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)22 Map (java.util.Map)22 Collectors (java.util.stream.Collectors)22 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)21 RandomAccessReader (cz.o2.proxima.direct.randomaccess.RandomAccessReader)21 AttributeFamilyDescriptor (cz.o2.proxima.repository.AttributeFamilyDescriptor)20 Arrays (java.util.Arrays)20 Collections (java.util.Collections)20 Optional (java.util.Optional)20 Set (java.util.Set)20 AtomicReference (java.util.concurrent.atomic.AtomicReference)20