Search in sources :

Example 1 with Transformation

use of cz.o2.proxima.transform.Transformation in project proxima-platform by O2-Czech-Republic.

the class DirectDataOperatorTest method testReplicationTransformations.

@Test
public void testReplicationTransformations() {
    repo.reloadConfig(true, ConfigFactory.load().withFallback(ConfigFactory.load("test-replication.conf")).withFallback(ConfigFactory.load("test-reference.conf")).resolve());
    final EntityDescriptor dummy = repo.getEntity("dummy");
    Map<String, TransformationDescriptor> transformations = repo.getTransformations();
    assertNotNull(transformations.get("_dummyReplicationMasterSlave_slave"));
    assertNotNull(transformations.get("_dummyReplicationMasterSlave_replicated"));
    assertNotNull(transformations.get("_dummyReplicationProxiedSlave_read"));
    // transformation from local writes to slave
    checkTransformation(dummy, transformations.get("_dummyReplicationMasterSlave_slave"), "wildcard.*", "_dummyReplicationMasterSlave_write$wildcard.*", "wildcard.*", "_dummyReplicationMasterSlave_slave$wildcard.*");
    // transformation from local writes to replicated result
    checkTransformation(dummy, transformations.get("_dummyReplicationMasterSlave_replicated"), "wildcard.*", "_dummyReplicationMasterSlave_write$wildcard.*", "wildcard.*", "_dummyReplicationMasterSlave_replicated$wildcard.*");
    // transformation from remote writes to local replicated result
    // with proxy
    checkTransformation(dummy, transformations.get("_dummyReplicationProxiedSlave_read"), "data", "data", "_d", "_dummyReplicationProxiedSlave_replicated$_d");
}
Also used : TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) Test(org.junit.Test)

Example 2 with Transformation

use of cz.o2.proxima.transform.Transformation in project proxima-platform by O2-Czech-Republic.

the class ConfigRepository method readTransformations.

private void readTransformations(Config cfg) {
    if (entitiesByName.isEmpty()) {
        // no loaded entities, no more stuff to read
        return;
    }
    Map<String, Object> cfgTransforms = Optional.ofNullable(cfg.root().get("transformations")).map(v -> toMap("transformations", v.unwrapped())).orElse(null);
    if (cfgTransforms == null) {
        log.info("Skipping empty transformations configuration.");
        return;
    }
    cfgTransforms.forEach((name, v) -> {
        Map<String, Object> transformation = toMap(name, v);
        boolean disabled = Optional.ofNullable(transformation.get(DISABLED)).map(d -> Boolean.valueOf(d.toString())).orElse(false);
        if (disabled) {
            log.info("Skipping load of disabled transformation {}", name);
            return;
        }
        EntityDescriptor entity = findEntity(readStr(ENTITY, transformation, name)).orElseThrow(() -> new IllegalArgumentException(String.format("Entity `%s` doesn't exist", transformation.get(ENTITY))));
        Transformation t = Classpath.newInstance(readStr("using", transformation, name), Transformation.class);
        List<AttributeDescriptor<?>> attrs = readList(ATTRIBUTES, transformation, name).stream().flatMap(a -> searchAttributesMatching(a, entity, true, true).stream()).collect(Collectors.toList());
        TransformationDescriptor.Builder desc = TransformationDescriptor.newBuilder().setName(name).addAttributes(attrs).setTransformation(t);
        Optional.ofNullable(transformation.get(FILTER)).map(Object::toString).map(s -> Classpath.newInstance(s, StorageFilter.class)).ifPresent(desc::setFilter);
        TransformationDescriptor transformationDescriptor = desc.build();
        setupTransform(transformationDescriptor.getTransformation(), transformation);
        this.transformations.put(name, transformationDescriptor);
    });
}
Also used : Arrays(java.util.Arrays) ConfigConstants(cz.o2.proxima.repository.ConfigConstants) URISyntaxException(java.net.URISyntaxException) ObjectInputStream(java.io.ObjectInputStream) StorageType(cz.o2.proxima.storage.StorageType) Pair(cz.o2.proxima.util.Pair) UnaryFunction(cz.o2.proxima.functional.UnaryFunction) Map(java.util.Map) AccessType(cz.o2.proxima.storage.AccessType) URI(java.net.URI) TransactionSerializerSchemeProvider(cz.o2.proxima.transaction.TransactionSerializerSchemeProvider) Transformation(cz.o2.proxima.transform.Transformation) BiFunction(cz.o2.proxima.functional.BiFunction) ConfigValue(com.typesafe.config.ConfigValue) Collection(java.util.Collection) ConfigObject(com.typesafe.config.ConfigObject) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) TransactionPartitioner(cz.o2.proxima.transaction.TransactionPartitioner) Objects(java.util.Objects) ValueSerializer(cz.o2.proxima.scheme.ValueSerializer) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Optional(java.util.Optional) RenameTransformation(cz.o2.proxima.transform.RenameTransformation) Pattern(java.util.regex.Pattern) VersionedCaching(cz.o2.proxima.repository.RepositoryFactory.VersionedCaching) Iterables(com.google.common.collect.Iterables) Getter(lombok.Getter) HashMap(java.util.HashMap) CamelCase(cz.o2.proxima.util.CamelCase) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Value(lombok.Value) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ConfigFactory(com.typesafe.config.ConfigFactory) ObjectOutputStream(java.io.ObjectOutputStream) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) Classpath(cz.o2.proxima.util.Classpath) Config(com.typesafe.config.Config) ElementWiseProxyTransform(cz.o2.proxima.transform.ElementWiseProxyTransform) ProxyTransform(cz.o2.proxima.transform.ProxyTransform) StorageFilter(cz.o2.proxima.storage.StorageFilter) IOException(java.io.IOException) LocalInstance(cz.o2.proxima.repository.RepositoryFactory.LocalInstance) ObjectStreamException(java.io.ObjectStreamException) DataOperatorAware(cz.o2.proxima.transform.DataOperatorAware) ProxySetupContext(cz.o2.proxima.transform.ElementWiseProxyTransform.ProxySetupContext) ValueSerializerFactory(cz.o2.proxima.scheme.ValueSerializerFactory) TransactionTransformProvider(cz.o2.proxima.transaction.TransactionTransformProvider) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Transformation(cz.o2.proxima.transform.Transformation) RenameTransformation(cz.o2.proxima.transform.RenameTransformation) ConfigObject(com.typesafe.config.ConfigObject)

Example 3 with Transformation

use of cz.o2.proxima.transform.Transformation in project proxima-platform by O2-Czech-Republic.

the class DirectDataOperatorTest method testReplicationTransformationsNonProxied.

@Test
public void testReplicationTransformationsNonProxied() {
    repo.reloadConfig(true, ConfigFactory.load().withFallback(ConfigFactory.load("test-replication.conf")).withFallback(ConfigFactory.load("test-reference.conf")).resolve());
    EntityDescriptor gateway = repo.getEntity("gateway");
    Map<String, TransformationDescriptor> transformations = repo.getTransformations();
    assertNotNull(transformations.get("_gatewayReplication_read"));
    assertNotNull(transformations.get("_gatewayReplication_inmemSecond"));
    // transformation from remote writes to local replicated result
    // without proxy
    checkTransformation(gateway, transformations.get("_gatewayReplication_read"), "armed", "armed");
    // transformation from local writes to slave
    checkTransformation(gateway, transformations.get("_gatewayReplication_inmemSecond"), "armed", "_gatewayReplication_write$armed", "armed", "_gatewayReplication_inmemSecond$armed");
}
Also used : TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) Test(org.junit.Test)

Example 4 with Transformation

use of cz.o2.proxima.transform.Transformation 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 5 with Transformation

use of cz.o2.proxima.transform.Transformation 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)

Aggregations

EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)5 TransformationDescriptor (cz.o2.proxima.repository.TransformationDescriptor)4 Test (org.junit.Test)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 Stream (java.util.stream.Stream)3 Slf4j (lombok.extern.slf4j.Slf4j)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Config (com.typesafe.config.Config)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 OnlineAttributeWriter (cz.o2.proxima.direct.core.OnlineAttributeWriter)2 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)2 Repository (cz.o2.proxima.repository.Repository)2 InputTransactionMode (cz.o2.proxima.repository.TransformationDescriptor.InputTransactionMode)2