Search in sources :

Example 81 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class HBaseState method batchRetrieve.

public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
    List<List<Values>> batchRetrieveResult = Lists.newArrayList();
    List<Get> gets = Lists.newArrayList();
    for (TridentTuple tuple : tridentTuples) {
        byte[] rowKey = options.mapper.rowKey(tuple);
        gets.add(hBaseClient.constructGetRequests(rowKey, options.projectionCriteria));
    }
    try {
        Result[] results = hBaseClient.batchGet(gets);
        for (int i = 0; i < results.length; i++) {
            Result result = results[i];
            TridentTuple tuple = tridentTuples.get(i);
            List<Values> values = options.rowToStormValueMapper.toValues(tuple, result);
            batchRetrieveResult.add(values);
        }
    } catch (Exception e) {
        LOG.warn("Batch get operation failed. Triggering replay.", e);
        throw new FailedException(e);
    }
    return batchRetrieveResult;
}
Also used : Values(org.apache.storm.tuple.Values) FailedException(org.apache.storm.topology.FailedException) FailedException(org.apache.storm.topology.FailedException) ColumnList(org.apache.storm.hbase.common.ColumnList) List(java.util.List) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 82 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class AvroGenericRecordBoltTest method generateTestTuple.

private static Tuple generateTestTuple(GenericRecord record) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap(), new HashMap(), new HashMap(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("record");
        }
    };
    return new TupleImpl(topologyContext, new Values(record), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 83 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class TestHdfsBolt method generateTestTuple.

private Tuple generateTestTuple(Object id, Object msg, Object city, Object state) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap(), new HashMap(), new HashMap(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("id", "msg", "city", "state");
        }
    };
    return new TupleImpl(topologyContext, new Values(id, msg, city, state), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 84 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class TestSequenceFileBolt method generateTestTuple.

private Tuple generateTestTuple(Long key, String value) {
    TopologyBuilder builder = new TopologyBuilder();
    GeneralTopologyContext topologyContext = new GeneralTopologyContext(builder.createTopology(), new Config(), new HashMap(), new HashMap(), new HashMap(), "") {

        @Override
        public Fields getComponentOutputFields(String componentId, String streamId) {
            return new Fields("key", "value");
        }
    };
    return new TupleImpl(topologyContext, new Values(key, value), 1, "");
}
Also used : Fields(org.apache.storm.tuple.Fields) GeneralTopologyContext(org.apache.storm.task.GeneralTopologyContext) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Config(org.apache.storm.Config) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 85 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class JmsSpout method nextTuple.

public void nextTuple() {
    Message msg = this.queue.poll();
    if (msg == null) {
        Utils.sleep(50);
    } else {
        LOG.debug("sending tuple: " + msg);
        // get the tuple from the handler
        try {
            Values vals = this.tupleProducer.toTuple(msg);
            // ack if we're not in AUTO_ACKNOWLEDGE mode, or the message requests ACKNOWLEDGE
            LOG.debug("Requested deliveryMode: " + toDeliveryModeString(msg.getJMSDeliveryMode()));
            LOG.debug("Our deliveryMode: " + toDeliveryModeString(this.jmsAcknowledgeMode));
            if (this.isDurableSubscription()) {
                LOG.debug("Requesting acks.");
                JmsMessageID messageId = new JmsMessageID(this.messageSequence++, msg.getJMSMessageID());
                this.collector.emit(vals, messageId);
                // at this point we successfully emitted. Store
                // the message and message ID so we can do a
                // JMS acknowledge later
                this.pendingMessages.put(messageId, msg);
                this.toCommit.add(messageId);
            } else {
                this.collector.emit(vals);
            }
        } catch (JMSException e) {
            LOG.warn("Unable to convert JMS message: " + msg);
        }
    }
}
Also used : Message(javax.jms.Message) Values(org.apache.storm.tuple.Values) JMSException(javax.jms.JMSException)

Aggregations

Values (org.apache.storm.tuple.Values)206 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)42 Fields (org.apache.storm.tuple.Fields)40 HashMap (java.util.HashMap)39 ChannelHandler (org.apache.storm.sql.runtime.ChannelHandler)26 TridentTopology (org.apache.storm.trident.TridentTopology)21 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)14 Stream (org.apache.storm.trident.Stream)12 TupleImpl (org.apache.storm.tuple.TupleImpl)12 List (java.util.List)11 TestUtils (org.apache.storm.sql.TestUtils)11 TridentState (org.apache.storm.trident.TridentState)11 Tuple (org.apache.storm.tuple.Tuple)11 JSONObject (org.json.simple.JSONObject)10 Map (java.util.Map)9 Config (org.apache.storm.Config)9 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)9 GeneralTopologyContext (org.apache.storm.task.GeneralTopologyContext)8 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)8