use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.
the class CassandraLogReader method processSinglePartition.
private boolean processSinglePartition(CassandraPartition partition, List<AttributeDescriptor<?>> attributes, TerminationContext terminationContext, BatchLogObserver observer) {
ResultSet result;
try (ClusterHolder holder = accessor.acquireCluster()) {
Session session = accessor.ensureSession();
result = accessor.execute(accessor.getCqlFactory().scanPartition(attributes, partition, session));
for (Row row : result) {
if (terminationContext.isCancelled()) {
return false;
}
String key = row.getString(0);
int field = 1;
for (AttributeDescriptor<?> attribute : attributes) {
String attributeName = attribute.getName();
if (attribute.isWildcard()) {
// FIXME: this is wrong
// need mapping between attribute and accessor
String suffix = accessor.asString(row.getObject(field++));
attributeName = attribute.toAttributePrefix() + suffix;
}
ByteBuffer bytes = row.getBytes(field++);
if (bytes != null) {
byte[] array = bytes.slice().array();
StreamElement element = accessor.getCqlFactory().toKeyValue(accessor.getEntityDescriptor(), attribute, key, attributeName, System.currentTimeMillis(), Offsets.empty(), array);
if (!observer.onNext(element, BatchLogObservers.defaultContext(partition))) {
return false;
}
}
}
}
}
return true;
}
use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.
the class ConfigRepository method loadSingleFamily.
private void loadSingleFamily(String name, boolean overwrite, Map<String, Object> cfg) throws URISyntaxException {
cfg = flatten(cfg);
boolean isDisabled = Optional.ofNullable(cfg.get(DISABLED)).map(Object::toString).map(Boolean::valueOf).orElse(false);
if (isDisabled) {
log.info("Skipping load of disabled family {}", name);
return;
}
final String entity = Objects.requireNonNull(cfg.get(ENTITY)).toString();
final String filter = toString(cfg.get(FILTER));
final boolean isTransactional = entity.equals(TRANSACTION_ENTITY);
final StorageType type = getStorageType(cfg, isTransactional);
final AccessType access = getAccessType(cfg, isTransactional);
final List<String> attributes = toList(Objects.requireNonNull(cfg.get(ATTRIBUTES), () -> String.format("Missing required field `%s' in attributeFamily %s", ATTRIBUTES, name)));
final URI storageUri = new URI(Objects.requireNonNull(cfg.get(STORAGE), () -> String.format("Missing required field `%s' in attribute family %s", STORAGE, name)).toString());
final EntityDescriptor entDesc = findEntityRequired(entity);
AttributeFamilyDescriptor.Builder family = AttributeFamilyDescriptor.newBuilder().setEntity(entDesc).setName(name).setType(type).setAccess(access).setStorageUri(storageUri).setCfg(withTransactionalPartitioner(isTransactional, cfg)).setSource((String) cfg.get(FROM));
Collection<AttributeDescriptor<?>> allAttributes = new HashSet<>();
for (String attr : attributes) {
// attribute descriptors affected by this settings
final List<AttributeDescriptor<?>> attrDescs;
attrDescs = searchAttributesMatching(attr, entDesc, false, false);
allAttributes.addAll(attrDescs);
}
if (!filter.isEmpty() && !readonly) {
insertFilterIfPossible(allAttributes, type, filter, name, family);
}
allAttributes.forEach(family::addAttribute);
insertFamily(family.build(), overwrite);
}
use of cz.o2.proxima.repository.AttributeDescriptor 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.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.
the class ConfigRepositoryTest method testProxySetupContext.
@Test
public void testProxySetupContext() {
EntityDescriptor entity = repo.getEntity("proxied");
AttributeDescriptor<Object> attribute = entity.getAttribute("raw.*");
AttributeProxyDescriptor<Object> proxy = entity.getAttribute("event.*").asProxy();
ProxySetupContext context = ConfigRepository.asProxySetupContext(proxy, attribute, true, false);
assertTrue(context.isReadTransform());
assertFalse(context.isWriteTransform());
assertFalse(context.isSymmetric());
assertEquals(attribute, context.getTargetAttribute());
assertEquals(proxy, context.getProxyAttribute());
}
use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.
the class StreamElement method dump.
/**
* Dump in more verbose way into given stream.
*
* @return string representing the dumped element
*/
public String dump() {
@SuppressWarnings("unchecked") AttributeDescriptor<Object> attrDesc = (AttributeDescriptor<Object>) getAttributeDescriptor();
Optional<Object> parsedValue = getParsed();
return MoreObjects.toStringHelper(getClass()).add("uuid", uuid).add("entityDesc", entityDescriptor).add("attributeDesc", attributeDescriptor).add("key", key).add("attribute", attribute).add("stamp", new Date(stamp)).add("value", parsedValue.isPresent() ? attrDesc.getValueSerializer().getLogString(parsedValue.get()) : "(null)").toString();
}
Aggregations