Search in sources :

Example 21 with OutputCollector

use of org.apache.storm.task.OutputCollector in project storm by apache.

the class KafkaBoltTest method generateStringSerializerBolt.

private KafkaBolt generateStringSerializerBolt() {
    Properties props = new Properties();
    props.put("acks", "1");
    props.put("bootstrap.servers", broker.getBrokerConnectionString());
    props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    props.put("metadata.fetch.timeout.ms", 1000);
    KafkaBolt bolt = new KafkaBolt().withProducerProperties(props);
    bolt.prepare(config, null, new OutputCollector(collector));
    bolt.setAsync(false);
    return bolt;
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) IOutputCollector(org.apache.storm.task.IOutputCollector) Properties(java.util.Properties)

Example 22 with OutputCollector

use of org.apache.storm.task.OutputCollector in project storm by apache.

the class BoltExecutor method init.

public void init(Map<Integer, Task> idToTask) {
    while (!stormActive.get()) {
        Utils.sleep(100);
    }
    LOG.info("Preparing bolt {}:{}", componentId, idToTask.keySet());
    for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
        Task taskData = entry.getValue();
        IBolt boltObject = (IBolt) taskData.getTaskObject();
        TopologyContext userContext = taskData.getUserContext();
        taskData.getBuiltInMetrics().registerAll(stormConf, userContext);
        if (boltObject instanceof ICredentialsListener) {
            ((ICredentialsListener) boltObject).setCredentials(credentials);
        }
        if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue, "transfer", workerData.getTransferQueue());
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
            Map cachedNodePortToSocket = (Map) workerData.getCachedNodeToPortSocket().get();
            BuiltinMetricsUtil.registerIconnectionClientMetrics(cachedNodePortToSocket, stormConf, userContext);
            BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), stormConf, userContext);
        } else {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
        }
        IOutputCollector outputCollector = new BoltOutputCollectorImpl(this, taskData, entry.getKey(), rand, hasEventLoggers, isDebug);
        boltObject.prepare(stormConf, userContext, new OutputCollector(outputCollector));
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Prepared bolt {}:{}", componentId, idToTask.keySet());
    setupMetrics();
}
Also used : IOutputCollector(org.apache.storm.task.IOutputCollector) OutputCollector(org.apache.storm.task.OutputCollector) Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) IOutputCollector(org.apache.storm.task.IOutputCollector) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 23 with OutputCollector

use of org.apache.storm.task.OutputCollector in project nifi by apache.

the class TestNiFiBolt method testTickTupleWhenNotExceedingBatchInterval.

@Test
public void testTickTupleWhenNotExceedingBatchInterval() {
    final NiFiBolt bolt = new TestableNiFiBolt(siteToSiteClientConfig, niFiDataPacketBuilder, tickFrequency);
    // prepare the bolt
    Map conf = mock(Map.class);
    TopologyContext context = mock(TopologyContext.class);
    OutputCollector collector = mock(OutputCollector.class);
    bolt.prepare(conf, context, collector);
    // process a regular tuple
    Tuple dataTuple = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple);
    // process a tick tuple
    Tuple tickTuple = MockTupleHelpers.mockTickTuple();
    bolt.execute(tickTuple);
    // should not have produced any NiFiDataPackets
    verifyZeroInteractions(niFiDataPacketBuilder);
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 24 with OutputCollector

use of org.apache.storm.task.OutputCollector in project metron by apache.

the class ParserDriver method run.

public ProcessorResult<List<byte[]>> run(List<byte[]> in) {
    ShimParserBolt bolt = new ShimParserBolt(new ArrayList<>());
    OutputCollector collector = mock(OutputCollector.class);
    bolt.prepare(null, null, collector);
    for (byte[] record : in) {
        bolt.execute(toTuple(record));
    }
    return bolt.getResults();
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector)

Example 25 with OutputCollector

use of org.apache.storm.task.OutputCollector in project incubator-pulsar by apache.

the class PulsarBoltTest method testFailedProducer.

@Test
public void testFailedProducer() {
    PulsarBoltConfiguration pulsarBoltConf = new PulsarBoltConfiguration();
    pulsarBoltConf.setServiceUrl(serviceUrl);
    pulsarBoltConf.setTopic("persistent://invalid");
    pulsarBoltConf.setTupleToMessageMapper(tupleToMessageMapper);
    pulsarBoltConf.setMetricsTimeIntervalInSecs(60);
    PulsarBolt bolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
    MockOutputCollector mockCollector = new MockOutputCollector();
    OutputCollector collector = new OutputCollector(mockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("new" + methodName);
    when(context.getThisTaskId()).thenReturn(0);
    try {
        bolt.prepare(Maps.newHashMap(), context, collector);
        fail("should have failed as producer creation failed");
    } catch (IllegalStateException ie) {
    // Ok.
    }
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) TopologyContext(org.apache.storm.task.TopologyContext) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Aggregations

OutputCollector (org.apache.storm.task.OutputCollector)38 Tuple (org.apache.storm.tuple.Tuple)21 TopologyContext (org.apache.storm.task.TopologyContext)20 Test (org.junit.Test)19 HashMap (java.util.HashMap)16 Fields (org.apache.storm.tuple.Fields)11 Map (java.util.Map)9 IOutputCollector (org.apache.storm.task.IOutputCollector)8 HiveOptions (org.apache.storm.hive.common.HiveOptions)6 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)5 Grouping (org.apache.storm.generated.Grouping)5 Before (org.junit.Before)5 Collections (java.util.Collections)4 Bolt (org.apache.storm.generated.Bolt)4 NullStruct (org.apache.storm.generated.NullStruct)4 SpoutSpec (org.apache.storm.generated.SpoutSpec)4 StormTopology (org.apache.storm.generated.StormTopology)4 JsonRecordHiveMapper (org.apache.storm.hive.bolt.mapper.JsonRecordHiveMapper)4 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)4 Count (org.apache.storm.streams.operations.aggregators.Count)4