Search in sources :

Example 16 with BoltDeclarer

use of backtype.storm.topology.BoltDeclarer in project storm by nathanmarz.

the class TransactionalTopologyBuilder method buildTopologyBuilder.

public TopologyBuilder buildTopologyBuilder() {
    String coordinator = _spoutId + "/coordinator";
    TopologyBuilder builder = new TopologyBuilder();
    SpoutDeclarer declarer = builder.setSpout(coordinator, new TransactionalSpoutCoordinator(_spout));
    for (Map conf : _spoutConfs) {
        declarer.addConfigurations(conf);
    }
    declarer.addConfiguration(Config.TOPOLOGY_TRANSACTIONAL_ID, _id);
    BoltDeclarer emitterDeclarer = builder.setBolt(_spoutId, new CoordinatedBolt(new TransactionalSpoutBatchExecutor(_spout), null, null), _spoutParallelism).allGrouping(coordinator, TransactionalSpoutCoordinator.TRANSACTION_BATCH_STREAM_ID).addConfiguration(Config.TOPOLOGY_TRANSACTIONAL_ID, _id);
    if (_spout instanceof ICommitterTransactionalSpout) {
        emitterDeclarer.allGrouping(coordinator, TransactionalSpoutCoordinator.TRANSACTION_COMMIT_STREAM_ID);
    }
    for (String id : _bolts.keySet()) {
        Component component = _bolts.get(id);
        Map<String, SourceArgs> coordinatedArgs = new HashMap<String, SourceArgs>();
        for (String c : componentBoltSubscriptions(component)) {
            coordinatedArgs.put(c, SourceArgs.all());
        }
        IdStreamSpec idSpec = null;
        if (component.committer) {
            idSpec = IdStreamSpec.makeDetectSpec(coordinator, TransactionalSpoutCoordinator.TRANSACTION_COMMIT_STREAM_ID);
        }
        BoltDeclarer input = builder.setBolt(id, new CoordinatedBolt(component.bolt, coordinatedArgs, idSpec), component.parallelism);
        for (Map conf : component.componentConfs) {
            input.addConfigurations(conf);
        }
        for (String c : componentBoltSubscriptions(component)) {
            input.directGrouping(c, Constants.COORDINATED_STREAM_ID);
        }
        for (InputDeclaration d : component.declarations) {
            d.declare(input);
        }
        if (component.committer) {
            input.allGrouping(coordinator, TransactionalSpoutCoordinator.TRANSACTION_COMMIT_STREAM_ID);
        }
    }
    return builder;
}
Also used : TopologyBuilder(backtype.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) IdStreamSpec(backtype.storm.coordination.CoordinatedBolt.IdStreamSpec) SourceArgs(backtype.storm.coordination.CoordinatedBolt.SourceArgs) BoltDeclarer(backtype.storm.topology.BoltDeclarer) SpoutDeclarer(backtype.storm.topology.SpoutDeclarer) HashMap(java.util.HashMap) Map(java.util.Map) CoordinatedBolt(backtype.storm.coordination.CoordinatedBolt)

Aggregations

BoltDeclarer (backtype.storm.topology.BoltDeclarer)16 HashMap (java.util.HashMap)9 Map (java.util.Map)8 SourceArgs (backtype.storm.coordination.CoordinatedBolt.SourceArgs)6 TopologyBuilder (backtype.storm.topology.TopologyBuilder)6 CoordinatedBolt (backtype.storm.coordination.CoordinatedBolt)4 IdStreamSpec (backtype.storm.coordination.CoordinatedBolt.IdStreamSpec)4 GlobalStreamId (backtype.storm.generated.GlobalStreamId)3 IRichBolt (backtype.storm.topology.IRichBolt)3 SpoutDeclarer (backtype.storm.topology.SpoutDeclarer)3 Fields (backtype.storm.tuple.Fields)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ITridentSpout (storm.trident.spout.ITridentSpout)3 FinishedCallback (backtype.storm.coordination.CoordinatedBolt.FinishedCallback)2 StreamInfo (backtype.storm.generated.StreamInfo)2 OutputFieldsGetter (backtype.storm.topology.OutputFieldsGetter)2 BatchTopologyBuilder (com.alibaba.jstorm.batch.BatchTopologyBuilder)2 DefaultDirectedGraph (org.jgrapht.graph.DefaultDirectedGraph)2