Search in sources :

Example 41 with Metadata

use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.

the class JoinBolt method onQuery.

private void onQuery(Tuple tuple) {
    String id = tuple.getString(TopologyConstants.ID_POSITION);
    String query = tuple.getString(TopologyConstants.QUERY_POSITION);
    Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.QUERY_METADATA_POSITION);
    Querier querier;
    try {
        querier = createQuerier(Querier.Mode.ALL, id, query, config);
        Optional<List<BulletError>> optionalErrors = querier.initialize();
        if (!optionalErrors.isPresent()) {
            setupQuery(id, query, metadata, querier);
            return;
        }
        emitErrorsAsResult(id, metadata, optionalErrors.get());
    } catch (RuntimeException re) {
        // Includes JSONParseException
        emitErrorsAsResult(id, metadata, ParsingError.makeError(re, query));
    }
    log.error("Failed to initialize query for request {} with query {}", id, query);
}
Also used : Querier(com.yahoo.bullet.querying.Querier) Metadata(com.yahoo.bullet.pubsub.Metadata) List(java.util.List)

Example 42 with Metadata

use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.

the class JoinBolt method emitMetaSignal.

// METADATA_STREAM emitters
private void emitMetaSignal(String id, Metadata.Signal signal) {
    log.error("Emitting {} signal to the feedback stream for {}", signal, id);
    collector.emit(FEEDBACK_STREAM, new Values(id, new Metadata(signal, null)));
}
Also used : Values(org.apache.storm.tuple.Values) Metadata(com.yahoo.bullet.pubsub.Metadata)

Example 43 with Metadata

use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.

the class LoopBolt method execute.

@Override
public void execute(Tuple tuple) {
    String id = tuple.getString(TopologyConstants.ID_POSITION);
    Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.METADATA_POSITION);
    log.info("Looping back metadata with signal {} for {}", metadata.getSignal(), id);
    publish(new PubSubMessage(id, null, metadata), tuple);
}
Also used : Metadata(com.yahoo.bullet.pubsub.Metadata) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage)

Example 44 with Metadata

use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.

the class ResultBolt method execute.

@Override
public void execute(Tuple tuple) {
    String id = tuple.getString(TopologyConstants.ID_POSITION);
    String result = tuple.getString(TopologyConstants.RESULT_POSITION);
    Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.RESULT_METADATA_POSITION);
    publish(new PubSubMessage(id, result, metadata), tuple);
}
Also used : Metadata(com.yahoo.bullet.pubsub.Metadata) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage)

Example 45 with Metadata

use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.

the class DRPCQuerySubscriber method getMessages.

@Override
public List<PubSubMessage> getMessages() throws PubSubException {
    // Try and read from DRPC. The DRPCSpout does a sleep for 1 ms if there are no tuples, so we don't have to do it.
    spout.nextTuple();
    if (!collector.haveOutput()) {
        return null;
    }
    // The DRPCSpout only should have emitted one tuple
    List<List<Object>> tuples = collector.reset();
    log.debug("Have a message through DRPC {}", tuples);
    List<Object> tupleAndID = tuples.get(0);
    // The first object is the actual DRPCSpout tuple and the second is the DRPC messageID.
    List<Object> tuple = (List<Object>) tupleAndID.get(0);
    Object drpcID = tupleAndID.get(1);
    // The first object in the tuple is our PubSubMessage as JSON
    String pubSubMessageJSON = (String) tuple.get(0);
    // The second object in the tuple is the serialized returnInfo added by the DRPCSpout
    String returnInfo = (String) tuple.get(1);
    log.debug("Read message\n{}\nfrom DRPC with return information {}", pubSubMessageJSON, returnInfo);
    PubSubMessage pubSubMessage = PubSubMessage.fromJSON(pubSubMessageJSON);
    // Add returnInfo as metadata. Cannot add it to pubSubMessage
    String id = pubSubMessage.getId();
    String content = pubSubMessage.getContent();
    int sequence = pubSubMessage.getSequence();
    PubSubMessage message = new PubSubMessage(id, content, new Metadata(null, returnInfo), sequence);
    emittedIDs.put(ImmutablePair.of(id, sequence), drpcID);
    return Collections.singletonList(message);
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Metadata(com.yahoo.bullet.pubsub.Metadata) List(java.util.List)

Aggregations

Metadata (com.yahoo.bullet.pubsub.Metadata)45 Test (org.testng.annotations.Test)35 Tuple (org.apache.storm.tuple.Tuple)31 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)25 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)25 TopKTest (com.yahoo.bullet.aggregations.TopKTest)25 BulletRecord (com.yahoo.bullet.record.BulletRecord)25 GroupByTest (com.yahoo.bullet.aggregations.GroupByTest)22 PubSubMessage (com.yahoo.bullet.pubsub.PubSubMessage)11 GroupOperation (com.yahoo.bullet.aggregations.grouping.GroupOperation)7 RateLimitError (com.yahoo.bullet.querying.RateLimitError)7 ArrayList (java.util.ArrayList)6 BulletConfig (com.yahoo.bullet.common.BulletConfig)5 Meta (com.yahoo.bullet.result.Meta)5 CountDistinct (com.yahoo.bullet.aggregations.CountDistinct)4 Distribution (com.yahoo.bullet.aggregations.Distribution)4 TopK (com.yahoo.bullet.aggregations.TopK)4 GroupData (com.yahoo.bullet.aggregations.grouping.GroupData)4 COUNT (com.yahoo.bullet.aggregations.grouping.GroupOperation.GroupOperationType.COUNT)4 COUNT_FIELD (com.yahoo.bullet.aggregations.sketches.QuantileSketch.COUNT_FIELD)4