use of cz.o2.proxima.repository.AttributeFamilyProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class DirectAttributeFamilyProxyDescriptor method getPartitionedCachedView.
private static Optional<CachedView> getPartitionedCachedView(AttrLookup lookup, Context context, AttributeFamilyProxyDescriptor desc) {
if (desc.getTargetFamilyRead().getAccess().canReadCommitLog() && !desc.getTargetFamilyWrite().getAccess().isReadonly() && desc.getTargetFamilyRead().getAccess().canCreateCachedView()) {
Optional<CommitLogReader> maybeReader = getCommitLogReader(lookup, context, desc);
Optional<OnlineAttributeWriter> maybeWriter = getWriter(lookup, context, desc).map(AttributeWriterBase::online);
if (maybeReader.isPresent() && maybeWriter.isPresent()) {
return Optional.of(new LocalCachedPartitionedView(desc.getTargetFamilyRead().getEntity(), maybeReader.get(), maybeWriter.get()));
}
}
return Optional.empty();
}
use of cz.o2.proxima.repository.AttributeFamilyProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class DirectDataOperator method dependencyOrdered.
/**
* Create list of families ordered by dependencies between them (non-proxy first).
*/
private List<AttributeFamilyDescriptor> dependencyOrdered(Stream<AttributeFamilyDescriptor> families) {
Set<AttributeFamilyDescriptor> available = new HashSet<>();
List<AttributeFamilyDescriptor> resolved = new ArrayList<>();
Set<AttributeFamilyDescriptor> toResolve = families.collect(Collectors.toSet());
while (!toResolve.isEmpty()) {
// prevent infinite cycles
List<AttributeFamilyDescriptor> remove = new ArrayList<>();
List<AttributeFamilyDescriptor> add = new ArrayList<>();
toResolve.stream().filter(af -> !available.contains(af)).forEachOrdered(af -> {
if (!af.isProxy()) {
available.add(af);
resolved.add(af);
remove.add(af);
} else {
AttributeFamilyProxyDescriptor proxy = af.toProxy();
if (available.contains(proxy.getTargetFamilyRead()) && available.contains(proxy.getTargetFamilyWrite())) {
available.add(af);
resolved.add(af);
remove.add(af);
} else if (!available.contains(proxy.getTargetFamilyRead())) {
add.add(proxy.getTargetFamilyRead());
} else {
add.add(proxy.getTargetFamilyWrite());
}
}
});
if (add.isEmpty() && remove.isEmpty()) {
throw new IllegalStateException("Cannot make progress in resolving families " + toResolve.stream().map(AttributeFamilyDescriptor::getName).collect(Collectors.toList()) + ", currently resolved " + available.stream().map(AttributeFamilyDescriptor::getName).collect(Collectors.toList()));
}
toResolve.addAll(add);
remove.forEach(toResolve::remove);
}
return resolved;
}
use of cz.o2.proxima.repository.AttributeFamilyProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class DirectDataOperatorTest method testReplicationProxies.
@Test
public void testReplicationProxies() {
repo.reloadConfig(true, ConfigFactory.load("test-replication-proxy.conf").resolve());
EntityDescriptor dummy = repo.getEntity("dummy");
// attribute _d should be proxy to
// _dummyReplicationMasterSlave_write$_d
// and _dummyReplicationMasterSlave_replicated$_d
AttributeDescriptor<Object> _d = dummy.getAttribute("_d", true);
assertTrue(_d.isProxy());
Set<AttributeFamilyDescriptor> families = repo.getFamiliesForAttribute(_d);
assertEquals(1, families.size());
AttributeFamilyDescriptor primary = Iterables.getOnlyElement(families);
assertTrue("Family " + primary + " must be proxy", primary.isProxy());
AttributeFamilyProxyDescriptor proxy = (AttributeFamilyProxyDescriptor) primary;
assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", primary.getName());
assertEquals("replication_dummy-replication-proxied-slave_replicated", proxy.getTargetFamilyRead().getName());
assertEquals("replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyWrite().getName());
assertFalse(proxy.getTargetFamilyRead().isProxy());
assertFalse(proxy.getTargetFamilyWrite().isProxy());
assertEquals(1, proxy.getAttributes().size());
AttributeProxyDescriptor<?> attr;
attr = (AttributeProxyDescriptor<?>) _d;
assertNotNull(attr.getWriteTransform());
assertEquals("_d", attr.getWriteTransform().asElementWise().fromProxy("_d"));
assertEquals("_d", attr.getWriteTransform().asElementWise().toProxy("_d"));
assertNotNull(attr.getReadTransform());
assertEquals("_d", attr.getReadTransform().asElementWise().fromProxy("_d"));
assertEquals("_d", attr.getReadTransform().asElementWise().toProxy("_d"));
// attribute dummy.data should be proxy to _d
attr = (AttributeProxyDescriptor<?>) dummy.getAttribute("data");
assertNotNull(attr.getWriteTransform());
assertNotNull(attr.getReadTransform());
assertEquals("data", attr.getWriteTransform().asElementWise().toProxy("_d"));
assertEquals("data", attr.getReadTransform().asElementWise().toProxy("_d"));
assertEquals("_d", attr.getWriteTransform().asElementWise().fromProxy("data"));
assertEquals("_d", attr.getReadTransform().asElementWise().fromProxy("data"));
families = repo.getFamiliesForAttribute(attr);
assertEquals(2, families.size());
primary = families.stream().filter(af -> af.getType() == StorageType.PRIMARY).findAny().orElse(null);
assertNotNull(primary);
assertTrue(primary.isProxy());
proxy = (AttributeFamilyProxyDescriptor) primary;
assertEquals("proxy::proxy::replication_dummy-replication-proxied-slave_replicated" + "::replication_dummy-replication-proxied-slave_write::proxy" + "::replication_dummy-replication-proxied-slave_replicated" + "::replication_dummy-replication-proxied-slave_write", primary.getName());
assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyRead().getName());
assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyWrite().getName());
assertTrue(proxy.getTargetFamilyRead().isProxy());
assertTrue(proxy.getTargetFamilyWrite().isProxy());
assertEquals(1, proxy.getAttributes().size());
}
use of cz.o2.proxima.repository.AttributeFamilyProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class BeamDataOperator method createAccessorFor.
private DataAccessor createAccessorFor(AttributeFamilyDescriptor family) {
if (family.isProxy()) {
AttributeFamilyProxyDescriptor proxy = family.toProxy();
DataAccessor readAccessor = accessorFor(proxy.getTargetFamilyRead());
DataAccessor writeAccessor = accessorFor(proxy.getTargetFamilyWrite());
return AttributeFamilyProxyDataAccessor.of(proxy, readAccessor, writeAccessor);
}
URI uri = family.getStorageUri();
return loader.findForUri(uri).map(f -> f.createAccessor(this, family)).orElseThrow(() -> new IllegalStateException("No accessor for URI " + family.getStorageUri()));
}
use of cz.o2.proxima.repository.AttributeFamilyProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class DirectDataOperator method addResolvedFamily.
private void addResolvedFamily(AttributeFamilyDescriptor family) {
try {
if (!familyMap.containsKey(family)) {
log.debug("Adding new family {} to familyMap", family);
if (family.isProxy()) {
AttributeFamilyProxyDescriptor proxy = family.toProxy();
familyMap.put(family, DirectAttributeFamilyProxyDescriptor.of(repo, context, proxy));
addResolvedFamily(proxy.getTargetFamilyRead());
addResolvedFamily(proxy.getTargetFamilyWrite());
} else {
DataAccessor accessor = findAccessorFor(family);
familyMap.put(family, new DirectAttributeFamilyDescriptor(repo, family, context, accessor));
}
}
} catch (Exception ex) {
log.error("Failed to add family {}", family, ex);
throw ex;
}
}
Aggregations