Search in sources :

Example 1 with TransformationDescriptor

use of cz.o2.proxima.repository.TransformationDescriptor 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 TransformationDescriptor

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

the class ConfigRepository method createTransactionCommitTransformation.

private void createTransactionCommitTransformation() {
    EntityDescriptor transaction = getEntity(TRANSACTION_ENTITY);
    String name = "_transaction-commit";
    TransactionTransformProvider provider = getTransactionTransformProvider();
    TransformationDescriptor descriptor = TransformationDescriptor.newBuilder().setTransformation(provider.create()).addAttributes(transaction.getAttribute(COMMIT_ATTRIBUTE)).setName(name).disableOutputTransactions().build();
    setupTransform(descriptor.getTransformation(), Collections.emptyMap());
    this.transformations.put(name, descriptor);
}
Also used : TransactionTransformProvider(cz.o2.proxima.transaction.TransactionTransformProvider)

Example 3 with TransformationDescriptor

use of cz.o2.proxima.repository.TransformationDescriptor 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 4 with TransformationDescriptor

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

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

the class DirectDataOperatorTest method testConfigParsing.

@Test
public void testConfigParsing() {
    assertTrue("Entity event should have been parsed", repo.findEntity("event").isPresent());
    assertTrue("Entity gateway should have been parsed", repo.findEntity("gateway").isPresent());
    EntityDescriptor event = repo.getEntity("event");
    assertEquals("event", event.getName());
    assertEquals("data", event.getAttribute("data").getName());
    assertEquals("bytes", event.getAttribute("data").getSchemeUri().getScheme());
    assertNotNull(event.getAttribute("data").getValueSerializer());
    EntityDescriptor gateway = repo.getEntity("gateway");
    assertEquals("gateway", gateway.getName());
    assertEquals("bytes:///", gateway.getAttribute("armed").getSchemeUri().toString());
    assertEquals("fail:whenever", gateway.getAttribute("fail").getSchemeUri().toString());
    assertEquals("bytes:///", gateway.getAttribute("bytes").getSchemeUri().toString());
    assertEquals(1, repo.getTransformations().size());
    TransformationDescriptor transform = Iterables.getOnlyElement(repo.getTransformations().values());
    assertEquals(PassthroughFilter.class, transform.getFilter().getClass());
    assertEquals(Arrays.asList(event.getAttribute("data")), transform.getAttributes());
    assertEquals(EventDataToDummy.class, transform.getTransformation().getClass());
}
Also used : TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) 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