use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata in project incubator-rya by apache.
the class PeriodicNotificationProvider method getNotifications.
/**
* Retrieve all of the information about Periodic Query results already registered
* with Fluo. This is returned in the form of {@link CommandNotification}s that
* can be registered with the {@link NotificationCoordinatorExecutor}.
* @param sx - snapshot for reading results from Fluo
* @return - collection of CommandNotifications that indicate Periodic Query information registered with system
*/
public Collection<CommandNotification> getNotifications(Snapshot sx) {
Set<PeriodicQueryMetadata> periodicMetadata = new HashSet<>();
RowScanner scanner = sx.scanner().fetch(FluoQueryColumns.PERIODIC_QUERY_NODE_ID).over(Span.prefix(IncrementalUpdateConstants.PERIODIC_QUERY_PREFIX)).byRow().build();
Iterator<ColumnScanner> colScannerIter = scanner.iterator();
while (colScannerIter.hasNext()) {
ColumnScanner colScanner = colScannerIter.next();
Iterator<ColumnValue> values = colScanner.iterator();
while (values.hasNext()) {
PeriodicQueryMetadata metadata = dao.readPeriodicQueryMetadata(sx, values.next().getsValue());
periodicMetadata.add(metadata);
}
}
return getCommandNotifications(sx, periodicMetadata);
}
use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata in project incubator-rya by apache.
the class PeriodicNotificationProvider method getCommandNotifications.
private Collection<CommandNotification> getCommandNotifications(Snapshot sx, Collection<PeriodicQueryMetadata> metadata) {
Set<CommandNotification> notifications = new HashSet<>();
int i = 1;
for (PeriodicQueryMetadata meta : metadata) {
// offset initial wait to avoid overloading system
PeriodicNotification periodic = new PeriodicNotification(getQueryId(meta.getNodeId(), sx), meta.getPeriod(), TimeUnit.MILLISECONDS, i * 5000);
notifications.add(new CommandNotification(Command.ADD, periodic));
i++;
}
return notifications;
}
use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata in project incubator-rya by apache.
the class BindingSetUpdater method process.
@Override
public final void process(final TransactionBase tx, final Bytes row, final Column col) {
checkNotNull(tx);
checkNotNull(row);
checkNotNull(col);
final Observation observation;
try {
observation = parseObservation(tx, row);
} catch (final Exception e) {
log.error("Unable to parse an Observation from a Row and Column pair, so this notification will be skipped. " + "Row: " + row + " Column: " + col, e);
return;
}
final String observedNodeId = observation.getObservedNodeId();
final VisibilityBindingSet observedBindingSet = observation.getObservedBindingSet();
final String parentNodeId = observation.getParentId();
// Figure out which node needs to handle the new metadata.
final NodeType parentNodeType = NodeType.fromNodeId(parentNodeId).get();
switch(parentNodeType) {
case QUERY:
final QueryMetadata parentQuery = queryDao.readQueryMetadata(tx, parentNodeId);
try {
queryUpdater.updateQueryResults(tx, observedBindingSet, parentQuery);
} catch (final Exception e) {
throw new RuntimeException("Could not process a Query node.", e);
}
break;
case PROJECTION:
final ProjectionMetadata projectionQuery = queryDao.readProjectionMetadata(tx, parentNodeId);
try {
projectionUpdater.updateProjectionResults(tx, observedBindingSet, projectionQuery);
} catch (final Exception e) {
throw new RuntimeException("Could not process a Query node.", e);
}
break;
case CONSTRUCT:
final ConstructQueryMetadata constructQuery = queryDao.readConstructQueryMetadata(tx, parentNodeId);
try {
constructUpdater.updateConstructQueryResults(tx, observedBindingSet, constructQuery);
} catch (final Exception e) {
throw new RuntimeException("Could not process a Query node.", e);
}
break;
case FILTER:
final FilterMetadata parentFilter = queryDao.readFilterMetadata(tx, parentNodeId);
try {
filterUpdater.updateFilterResults(tx, observedBindingSet, parentFilter);
} catch (final Exception e) {
throw new RuntimeException("Could not process a Filter node.", e);
}
break;
case JOIN:
final JoinMetadata parentJoin = queryDao.readJoinMetadata(tx, parentNodeId);
try {
joinUpdater.updateJoinResults(tx, observedNodeId, observedBindingSet, parentJoin);
} catch (final Exception e) {
throw new RuntimeException("Could not process a Join node.", e);
}
break;
case PERIODIC_QUERY:
final PeriodicQueryMetadata parentPeriodicQuery = queryDao.readPeriodicQueryMetadata(tx, parentNodeId);
try {
periodicQueryUpdater.updatePeriodicBinResults(tx, observedBindingSet, parentPeriodicQuery);
} catch (Exception e) {
throw new RuntimeException("Could not process PeriodicBin node.", e);
}
break;
case AGGREGATION:
final AggregationMetadata parentAggregation = queryDao.readAggregationMetadata(tx, parentNodeId);
try {
aggregationUpdater.updateAggregateResults(tx, observedBindingSet, parentAggregation);
} catch (final Exception e) {
throw new RuntimeException("Could not process an Aggregation node.", e);
}
break;
default:
throw new IllegalArgumentException("The parent node's NodeType must be of type Aggregation, Projection, ConstructQuery, Filter, Join, PeriodicBin or Query, but was " + parentNodeType);
}
}
use of org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata in project incubator-rya by apache.
the class PeriodicQueryObserver method parseObservation.
@Override
public Observation parseObservation(final TransactionBase tx, final Bytes row) throws Exception {
requireNonNull(tx);
requireNonNull(row);
// Read the Join metadata.
final String periodicBinNodeId = BindingSetRow.makeFromShardedRow(Bytes.of(PERIODIC_QUERY_PREFIX), row).getNodeId();
final PeriodicQueryMetadata periodicBinMetadata = queryDao.readPeriodicQueryMetadata(tx, periodicBinNodeId);
// Read the Visibility Binding Set from the Value.
final Bytes valueBytes = tx.get(row, FluoQueryColumns.PERIODIC_QUERY_BINDING_SET);
final VisibilityBindingSet periodicBinBindingSet = BS_SERDE.deserialize(valueBytes);
// Figure out which node needs to handle the new metadata.
final String parentNodeId = periodicBinMetadata.getParentNodeId();
return new Observation(periodicBinNodeId, periodicBinBindingSet, parentNodeId);
}
Aggregations