Search in sources :

Example 1 with OutputCollector

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

the class KafkaBoltTest method generateDefaultSerializerBolt.

private KafkaBolt generateDefaultSerializerBolt(boolean async, boolean fireAndForget, KafkaProducer<?, ?> mockProducer) {
    Properties props = new Properties();
    props.put("acks", "1");
    props.put("bootstrap.servers", broker.getBrokerConnectionString());
    props.put("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    props.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    props.put("metadata.fetch.timeout.ms", 1000);
    props.put("linger.ms", 0);
    KafkaBolt bolt = new KafkaBolt().withProducerProperties(props);
    bolt.prepare(config, null, new OutputCollector(collector));
    bolt.setAsync(async);
    bolt.setFireAndForget(fireAndForget);
    if (mockProducer != null) {
        Whitebox.setInternalState(bolt, "producer", mockProducer);
    }
    return bolt;
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) IOutputCollector(org.apache.storm.task.IOutputCollector) Properties(java.util.Properties)

Example 2 with OutputCollector

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

the class KafkaBoltTest method defaultSerializerBoltWithSpecifiedProperties.

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

Example 3 with OutputCollector

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

the class CoordinatedBolt method prepare.

public void prepare(Map config, TopologyContext context, OutputCollector collector) {
    TimeCacheMap.ExpiredCallback<Object, TrackingInfo> callback = null;
    if (_delegate instanceof TimeoutCallback) {
        callback = new TimeoutItems();
    }
    _tracked = new TimeCacheMap<>(context.maxTopologyMessageTimeout(), callback);
    _collector = collector;
    _delegate.prepare(config, context, new OutputCollector(new CoordinatedOutputCollector(collector)));
    for (String component : Utils.get(context.getThisTargets(), Constants.COORDINATED_STREAM_ID, new HashMap<String, Grouping>()).keySet()) {
        for (Integer task : context.getComponentTasks(component)) {
            _countOutTasks.add(task);
        }
    }
    if (!_sourceArgs.isEmpty()) {
        _numSourceReports = 0;
        for (Entry<String, SourceArgs> entry : _sourceArgs.entrySet()) {
            if (entry.getValue().singleCount) {
                _numSourceReports += 1;
            } else {
                _numSourceReports += context.getComponentTasks(entry.getKey()).size();
            }
        }
    }
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) IOutputCollector(org.apache.storm.task.IOutputCollector) HashMap(java.util.HashMap) TimeCacheMap(org.apache.storm.utils.TimeCacheMap)

Example 4 with OutputCollector

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

the class BoltWrapper method open.

@Override
public void open() throws Exception {
    super.open();
    this.flinkCollector = new TimestampedCollector<>(this.output);
    GlobalJobParameters config = getExecutionConfig().getGlobalJobParameters();
    StormConfig stormConfig = new StormConfig();
    if (config != null) {
        if (config instanceof StormConfig) {
            stormConfig = (StormConfig) config;
        } else {
            stormConfig.putAll(config.toMap());
        }
    }
    this.topologyContext = WrapperSetupHelper.createTopologyContext(getRuntimeContext(), this.bolt, this.name, this.stormTopology, stormConfig);
    final OutputCollector stormCollector = new OutputCollector(new BoltCollector<OUT>(this.numberOfAttributes, this.topologyContext.getThisTaskId(), this.flinkCollector));
    if (this.stormTopology != null) {
        Map<GlobalStreamId, Grouping> inputs = this.topologyContext.getThisSources();
        for (GlobalStreamId inputStream : inputs.keySet()) {
            for (Integer tid : this.topologyContext.getComponentTasks(inputStream.get_componentId())) {
                this.inputComponentIds.put(tid, inputStream.get_componentId());
                this.inputStreamIds.put(tid, inputStream.get_streamId());
                this.inputSchemas.put(tid, this.topologyContext.getComponentOutputFields(inputStream));
            }
        }
    }
    this.bolt.prepare(stormConfig, this.topologyContext, stormCollector);
}
Also used : StormConfig(org.apache.flink.storm.util.StormConfig) OutputCollector(org.apache.storm.task.OutputCollector) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) Grouping(org.apache.storm.generated.Grouping) GlobalJobParameters(org.apache.flink.api.common.ExecutionConfig.GlobalJobParameters)

Example 5 with OutputCollector

use of org.apache.storm.task.OutputCollector in project open-kilda by telstra.

the class OFELinkBoltTest method before.

@Before
public void before() throws CmdLineException, ConfigurationException {
    OFEventWFMTopology manager = new OFEventWFMTopology(AbstractStormTest.makeLaunchEnvironment());
    config = manager.getConfig();
    bolt = new OFELinkBolt(config);
    context = Mockito.mock(TopologyContext.class);
    Mockito.when(context.getComponentId(TASK_ID_BOLT)).thenReturn(COMPONENT_ID_SOURCE);
    Mockito.when(context.getComponentOutputFields(COMPONENT_ID_SOURCE, STREAM_ID_INPUT)).thenReturn(KafkaMessage.FORMAT);
    outputDelegate = Mockito.spy(new OutputCollectorMock());
    OutputCollector output = new OutputCollector(outputDelegate);
    bolt.prepare(stormConfig(), context, output);
    bolt.initState(new InMemoryKeyValueState<>());
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) OutputCollectorMock(org.openkilda.wfm.topology.OutputCollectorMock) TopologyContext(org.apache.storm.task.TopologyContext) Before(org.junit.Before)

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