Search in sources :

Example 6 with TransformationDescriptor

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

the class ReplicationController method runTransform.

private void runTransform(String name, TransformationDescriptor transform, DirectAttributeFamilyDescriptor family) {
    final StorageFilter filter = transform.getFilter();
    final String consumer = transform.getConsumerNameFactory().apply();
    final CommitLogReader reader = family.getCommitLogReader().orElseThrow(() -> new IllegalStateException("Unable to get reader for family " + family.getDesc().getName() + "."));
    final TransformationObserver observer;
    if (transform.getTransformation().isContextual()) {
        DirectElementWiseTransform transformation = transform.getTransformation().as(DirectElementWiseTransform.class);
        observer = contextualObserver(dataOperator, name, transformation, transform.getOutputTransactionMode() == OutputTransactionMode.ENABLED, filter);
    } else {
        ElementWiseTransformation transformation = transform.getTransformation().asElementWiseTransform();
        observer = nonContextualObserver(dataOperator, name, transformation, transform.getOutputTransactionMode() == OutputTransactionMode.ENABLED, filter);
    }
    startTransformationObserverUsing(consumer, reader, observer);
    log.info("Started transformer {} reading from {} using {}", consumer, reader.getUri(), transform.getTransformation().getClass());
}
Also used : ElementWiseTransformation(cz.o2.proxima.transform.ElementWiseTransformation) StorageFilter(cz.o2.proxima.storage.StorageFilter) DirectElementWiseTransform(cz.o2.proxima.direct.transform.DirectElementWiseTransform) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) TransformationObserver(cz.o2.proxima.direct.transform.TransformationObserver)

Example 7 with TransformationDescriptor

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

the class ReplicationController method runTransformer.

private void runTransformer(String name, TransformationDescriptor transform) {
    if (transform.getInputTransactionMode() == InputTransactionMode.TRANSACTIONAL) {
        log.info("Skipping run of transformation {} which read from transactional attributes {}. " + "Will be executed during transaction commit.", name, transform.getAttributes());
        return;
    }
    DirectAttributeFamilyDescriptor family = transform.getAttributes().stream().map(attr -> getAttributeDescriptorStreamFor(dataOperator, attr).collect(Collectors.toSet())).reduce(Sets::intersection).filter(s -> !s.isEmpty()).flatMap(s -> s.stream().filter(f -> f.getCommitLogReader().isPresent()).findAny()).orElseThrow(() -> new IllegalArgumentException("Cannot obtain attribute family for " + transform.getAttributes()));
    runTransform(name, transform, family);
}
Also used : AttributeWriterBase(cz.o2.proxima.direct.core.AttributeWriterBase) Getter(lombok.Getter) InputTransactionMode(cz.o2.proxima.repository.TransformationDescriptor.InputTransactionMode) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) StorageType(cz.o2.proxima.storage.StorageType) CompletableFuture(java.util.concurrent.CompletableFuture) OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) DirectElementWiseTransform(cz.o2.proxima.direct.transform.DirectElementWiseTransform) HashSet(java.util.HashSet) StreamElement(cz.o2.proxima.storage.StreamElement) Pair(cz.o2.proxima.util.Pair) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConfigFactory(com.typesafe.config.ConfigFactory) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) Metrics(cz.o2.proxima.server.metrics.Metrics) BulkAttributeWriter(cz.o2.proxima.direct.core.BulkAttributeWriter) Repository(cz.o2.proxima.repository.Repository) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) Set(java.util.Set) StorageFilter(cz.o2.proxima.storage.StorageFilter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) RetryPolicy(net.jodah.failsafe.RetryPolicy) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) Failsafe(net.jodah.failsafe.Failsafe) CommitLogObservers(cz.o2.proxima.direct.commitlog.CommitLogObservers) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) DirectAttributeFamilyDescriptor(cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor) TransformationObserver(cz.o2.proxima.direct.transform.TransformationObserver) Optional(java.util.Optional) TerminationStrategy(cz.o2.proxima.direct.commitlog.CommitLogObservers.TerminationStrategy) ElementWiseTransformation(cz.o2.proxima.transform.ElementWiseTransformation) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) OutputTransactionMode(cz.o2.proxima.repository.TransformationDescriptor.OutputTransactionMode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DirectAttributeFamilyDescriptor(cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor)

Example 8 with TransformationDescriptor

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

the class SingleTopicMultipleReplicationsTest method testTransformationWildcardInput.

@Test
public void testTransformationWildcardInput() {
    TransformationDescriptor wildcardInputTransform = repo.getTransformations().get("_wildcardReplication_read");
    assertNotNull(wildcardInputTransform);
    assertEquals(1, wildcardInputTransform.getAttributes().size());
    assertEquals(wildcardInput, wildcardInputTransform.getAttributes().get(0));
    List<StreamElement> transformed = new ArrayList<>();
    int transformedCount = wildcardInputTransform.getTransformation().asElementWiseTransform().apply(StreamElement.upsert(entity, wildcard, uuid(), "key", "wildcard.1", now, value()), transformed::add);
    assertEquals(1, transformedCount);
    assertEquals(1, transformed.size());
    assertEquals("_wildcardReplication_replicated$_raw.*", transformed.get(0).getAttributeDescriptor().getName());
    assertEquals("_raw.2", transformed.get(0).getAttribute());
}
Also used : TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) ArrayList(java.util.ArrayList) StreamElement(cz.o2.proxima.storage.StreamElement) Test(org.junit.Test)

Example 9 with TransformationDescriptor

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

the class TransformationRunner method runTransformation.

/**
 * Run given transformation in local JVM.
 *
 * @param direct the operator to run transformations with
 * @param name name of the transformation
 * @param desc the transformation to run
 * @param onReplicated callback to be called before write to replicated target
 * @return {@link ObserveHandle} of the transformation
 */
public static ObserveHandle runTransformation(DirectDataOperator direct, String name, TransformationDescriptor desc, Consumer<StreamElement> onReplicated) {
    final CommitLogObserver observer;
    if (desc.getTransformation().isContextual()) {
        observer = new TransformationObserver.Contextual(direct, name, desc.getTransformation().as(DirectElementWiseTransform.class), desc.getOutputTransactionMode() == OutputTransactionMode.ENABLED, desc.getFilter()) {

            @Override
            protected void onReplicated(StreamElement element) {
                onReplicated.accept(element);
            }
        };
    } else {
        observer = new TransformationObserver.NonContextual(direct, name, desc.getTransformation().asElementWiseTransform(), desc.getOutputTransactionMode() == OutputTransactionMode.ENABLED, desc.getFilter()) {

            @Override
            protected void onReplicated(StreamElement element) {
                onReplicated.accept(element);
            }
        };
    }
    CommitLogReader reader = desc.getAttributes().stream().flatMap(attr -> findFamilyDescriptorForAttribute(direct, attr)).findAny().flatMap(DirectAttributeFamilyDescriptor::getCommitLogReader).orElseThrow(() -> new IllegalStateException("No commit log reader for attributes of transformation " + desc));
    log.debug("Starting to observe reader {} with observer {} as {}", reader, observer, name);
    return reader.observe(name, observer);
}
Also used : CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) Consumer(cz.o2.proxima.functional.Consumer) Repository(cz.o2.proxima.repository.Repository) InputTransactionMode(cz.o2.proxima.repository.TransformationDescriptor.InputTransactionMode) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) StorageType(cz.o2.proxima.storage.StorageType) ObserveHandle(cz.o2.proxima.direct.commitlog.ObserveHandle) DirectElementWiseTransform(cz.o2.proxima.direct.transform.DirectElementWiseTransform) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) StreamElement(cz.o2.proxima.storage.StreamElement) DirectAttributeFamilyDescriptor(cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor) TransformationObserver(cz.o2.proxima.direct.transform.TransformationObserver) DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) OutputTransactionMode(cz.o2.proxima.repository.TransformationDescriptor.OutputTransactionMode) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) StreamElement(cz.o2.proxima.storage.StreamElement) TransformationObserver(cz.o2.proxima.direct.transform.TransformationObserver)

Example 10 with TransformationDescriptor

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

the class SingleTopicMultipleReplicationsTest method testTransformationWildcardWriteRead.

@Test
public void testTransformationWildcardWriteRead() {
    TransformationDescriptor wildcardReplicatedTransform = repo.getTransformations().get("_wildcardReplication_replicated");
    assertNotNull(wildcardReplicatedTransform);
    assertEquals(1, wildcardReplicatedTransform.getAttributes().size());
    assertEquals(rawWrite, wildcardReplicatedTransform.getAttributes().get(0));
    List<StreamElement> transformed = new ArrayList<>();
    int transformedCount = wildcardReplicatedTransform.getTransformation().asElementWiseTransform().apply(StreamElement.upsert(entity, raw, uuid(), "key", "_raw.2", now, value()), transformed::add);
    assertEquals(1, transformedCount);
    assertEquals(1, transformed.size());
    assertEquals("_wildcardReplication_replicated$_raw.*", transformed.get(0).getAttributeDescriptor().getName());
    assertEquals("_raw.2", transformed.get(0).getAttribute());
}
Also used : TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) ArrayList(java.util.ArrayList) StreamElement(cz.o2.proxima.storage.StreamElement) Test(org.junit.Test)

Aggregations

TransformationDescriptor (cz.o2.proxima.repository.TransformationDescriptor)8 Test (org.junit.Test)6 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)5 StreamElement (cz.o2.proxima.storage.StreamElement)4 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)3 DirectElementWiseTransform (cz.o2.proxima.direct.transform.DirectElementWiseTransform)3 TransformationObserver (cz.o2.proxima.direct.transform.TransformationObserver)3 StorageFilter (cz.o2.proxima.storage.StorageFilter)3 StorageType (cz.o2.proxima.storage.StorageType)3 ArrayList (java.util.ArrayList)3 Stream (java.util.stream.Stream)3 Slf4j (lombok.extern.slf4j.Slf4j)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ConfigFactory (com.typesafe.config.ConfigFactory)2 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)2 DirectAttributeFamilyDescriptor (cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor)2 DirectDataOperator (cz.o2.proxima.direct.core.DirectDataOperator)2 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)2 Repository (cz.o2.proxima.repository.Repository)2 InputTransactionMode (cz.o2.proxima.repository.TransformationDescriptor.InputTransactionMode)2