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));
}
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));
}
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());
}
}
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();
}
};
}
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();
}
Aggregations