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