Search in sources :

Example 6 with SpoutOutputCollector

use of com.twitter.heron.api.spout.SpoutOutputCollector in project heron by twitter.

the class PhysicalPlanUtilTest method getTestTopology.

/**
   * Construct the test topology
   */
public static TopologyAPI.Topology getTestTopology() {
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout("word", new BaseRichSpout() {

        private static final long serialVersionUID = 5406114907377311020L;

        @Override
        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
            outputFieldsDeclarer.declare(new Fields("word"));
        }

        @Override
        public void open(Map<String, Object> map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
        }

        @Override
        public void nextTuple() {
        }
    }, 2);
    topologyBuilder.setBolt("exclaim", new BaseBasicBolt() {

        private static final long serialVersionUID = 4398578755681473899L;

        @Override
        public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
        }

        @Override
        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
        }
    }, 2).shuffleGrouping("word");
    Config conf = new Config();
    conf.setDebug(true);
    conf.setMaxSpoutPending(10);
    conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, "-XX:+HeapDumpOnOutOfMemoryError");
    conf.setComponentRam("word", ByteAmount.fromMegabytes(500));
    conf.setComponentRam("exclaim", ByteAmount.fromGigabytes(1));
    conf.setMessageTimeoutSecs(1);
    return topologyBuilder.createTopology().setName("topology-name").setConfig(conf).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
}
Also used : BaseBasicBolt(com.twitter.heron.api.bolt.BaseBasicBolt) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) Config(com.twitter.heron.api.Config) OutputFieldsDeclarer(com.twitter.heron.api.topology.OutputFieldsDeclarer) BasicOutputCollector(com.twitter.heron.api.bolt.BasicOutputCollector) Fields(com.twitter.heron.api.tuple.Fields) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple) BaseRichSpout(com.twitter.heron.api.spout.BaseRichSpout)

Example 7 with SpoutOutputCollector

use of com.twitter.heron.api.spout.SpoutOutputCollector in project incubator-heron by apache.

the class TopologyTests method createTopologyWithConnection.

/**
 * Create Topology proto object using HeronSubmitter API.
 *
 * @param heronConfig desired config params.
 * @param spouts spoutName -&gt; parallelism
 * @param bolts boltName -&gt; parallelism
 * @param connections connect default stream from value to key.
 * @return topology proto.
 */
public static TopologyAPI.Topology createTopologyWithConnection(String topologyName, Config heronConfig, Map<String, Integer> spouts, Map<String, Integer> bolts, Map<String, String> connections) {
    TopologyBuilder builder = new TopologyBuilder();
    BaseRichSpout baseSpout = new BaseRichSpout() {

        private static final long serialVersionUID = -719523487475322625L;

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
            declarer.declare(new Fields("field1"));
        }

        public void open(Map<String, Object> conf, TopologyContext context, SpoutOutputCollector collector) {
        }

        public void nextTuple() {
        }
    };
    BaseBasicBolt basicBolt = new BaseBasicBolt() {

        private static final long serialVersionUID = 2544765902130713628L;

        public void execute(Tuple input, BasicOutputCollector collector) {
        }

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
        }
    };
    for (String spout : spouts.keySet()) {
        builder.setSpout(spout, baseSpout, spouts.get(spout));
    }
    for (String bolt : bolts.keySet()) {
        BoltDeclarer boltDeclarer = builder.setBolt(bolt, basicBolt, bolts.get(bolt));
        if (connections.containsKey(bolt)) {
            boltDeclarer.shuffleGrouping(connections.get(bolt));
        }
    }
    HeronTopology heronTopology = builder.createTopology();
    return heronTopology.setName(topologyName).setConfig(heronConfig).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
}
Also used : BaseBasicBolt(com.twitter.heron.api.bolt.BaseBasicBolt) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) HeronTopology(com.twitter.heron.api.HeronTopology) OutputFieldsDeclarer(com.twitter.heron.api.topology.OutputFieldsDeclarer) BasicOutputCollector(com.twitter.heron.api.bolt.BasicOutputCollector) Fields(com.twitter.heron.api.tuple.Fields) BoltDeclarer(com.twitter.heron.api.topology.BoltDeclarer) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) TopologyContext(com.twitter.heron.api.topology.TopologyContext) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(com.twitter.heron.api.tuple.Tuple) BaseRichSpout(com.twitter.heron.api.spout.BaseRichSpout)

Example 8 with SpoutOutputCollector

use of com.twitter.heron.api.spout.SpoutOutputCollector in project incubator-heron by apache.

the class SpoutInstance method init.

@SuppressWarnings("unchecked")
@Override
public void init(State<Serializable, Serializable> state) {
    TopologyContextImpl topologyContext = helper.getTopologyContext();
    // Initialize the GlobalMetrics
    GlobalMetrics.init(topologyContext, systemConfig.getHeronMetricsExportInterval());
    spoutMetrics.registerMetrics(topologyContext);
    // Initialize the instanceState if the spout is stateful
    if (spout instanceof IStatefulComponent) {
        this.instanceState = state;
        ((IStatefulComponent<Serializable, Serializable>) spout).initState(instanceState);
    }
    spout.open(topologyContext.getTopologyConfig(), topologyContext, new SpoutOutputCollector(collector));
    // Invoke user-defined prepare task hook
    topologyContext.invokeHookPrepare();
    // Init the CustomStreamGrouping
    helper.prepareForCustomStreamGrouping();
}
Also used : TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) IStatefulComponent(com.twitter.heron.api.topology.IStatefulComponent)

Example 9 with SpoutOutputCollector

use of com.twitter.heron.api.spout.SpoutOutputCollector in project incubator-heron by apache.

the class IntegrationTestSpout method open.

@Override
public void open(Map<String, Object> map, TopologyContext topologyContext, SpoutOutputCollector outputCollector) {
    // Here the spoutOutputCollector should be a default one
    // to emit tuples without adding MessageId
    this.spoutOutputCollector = outputCollector;
    delegateSpout.open(map, new TestTopologyContext(topologyContext), new SpoutOutputCollector(new IntegrationTestSpoutCollector(outputCollector)));
}
Also used : ISpoutOutputCollector(com.twitter.heron.api.spout.ISpoutOutputCollector) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector)

Example 10 with SpoutOutputCollector

use of com.twitter.heron.api.spout.SpoutOutputCollector in project incubator-heron by apache.

the class TopologyManagerTest method getTestTopology.

/**
 * Construct the test topology
 */
public static TopologyAPI.Topology getTestTopology() {
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout(STREAM_ID, new BaseRichSpout() {

        private static final long serialVersionUID = 5406114907377311020L;

        @Override
        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
            outputFieldsDeclarer.declare(new Fields(STREAM_ID));
        }

        @Override
        public void open(Map<String, Object> map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
        }

        @Override
        public void nextTuple() {
        }
    }, 2);
    topologyBuilder.setBolt(BOLT_ID, new BaseBasicBolt() {

        private static final long serialVersionUID = 4398578755681473899L;

        @Override
        public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
        }

        @Override
        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
        }
    }, 2).shuffleGrouping(STREAM_ID);
    Config conf = new Config();
    conf.setDebug(true);
    conf.setMaxSpoutPending(10);
    conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, "-XX:+HeapDumpOnOutOfMemoryError");
    conf.setComponentRam(STREAM_ID, ByteAmount.fromMegabytes(500));
    conf.setComponentRam(BOLT_ID, ByteAmount.fromGigabytes(1));
    conf.setMessageTimeoutSecs(1);
    return topologyBuilder.createTopology().setName("topology-name").setConfig(conf).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
}
Also used : BaseBasicBolt(com.twitter.heron.api.bolt.BaseBasicBolt) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) Config(com.twitter.heron.api.Config) OutputFieldsDeclarer(com.twitter.heron.api.topology.OutputFieldsDeclarer) BasicOutputCollector(com.twitter.heron.api.bolt.BasicOutputCollector) Fields(com.twitter.heron.api.tuple.Fields) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple) BaseRichSpout(com.twitter.heron.api.spout.BaseRichSpout)

Aggregations

SpoutOutputCollector (com.twitter.heron.api.spout.SpoutOutputCollector)10 BaseBasicBolt (com.twitter.heron.api.bolt.BaseBasicBolt)6 BasicOutputCollector (com.twitter.heron.api.bolt.BasicOutputCollector)6 BaseRichSpout (com.twitter.heron.api.spout.BaseRichSpout)6 OutputFieldsDeclarer (com.twitter.heron.api.topology.OutputFieldsDeclarer)6 TopologyBuilder (com.twitter.heron.api.topology.TopologyBuilder)6 TopologyContext (com.twitter.heron.api.topology.TopologyContext)6 Tuple (com.twitter.heron.api.tuple.Tuple)6 HeronTopology (com.twitter.heron.api.HeronTopology)4 Fields (com.twitter.heron.api.tuple.Fields)4 Config (com.twitter.heron.api.Config)2 ISpoutOutputCollector (com.twitter.heron.api.spout.ISpoutOutputCollector)2 BoltDeclarer (com.twitter.heron.api.topology.BoltDeclarer)2 TopologyContextImpl (com.twitter.heron.common.utils.topology.TopologyContextImpl)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IStatefulComponent (com.twitter.heron.api.topology.IStatefulComponent)1