Search in sources :

Example 21 with BoltDeclarer

use of org.apache.storm.topology.BoltDeclarer in project open-kilda by telstra.

the class AbstractTopology method declareBolt.

protected BoltDeclarer declareBolt(TopologyBuilder builder, IRichBolt bolt, String boltId) {
    BoltDeclarer boltDeclarer = builder.setBolt(boltId, bolt, getBoltParallelism(boltId));
    Integer boltNumTasks = getBoltNumTasks(boltId);
    if (boltNumTasks != null) {
        boltDeclarer.setNumTasks(boltNumTasks);
    }
    return boltDeclarer;
}
Also used : BoltDeclarer(org.apache.storm.topology.BoltDeclarer)

Example 22 with BoltDeclarer

use of org.apache.storm.topology.BoltDeclarer in project storm by apache.

the class ConstSpoutNullBoltTopo method getTopology.

public static StormTopology getTopology(Map conf) {
    // 1 -  Setup Spout   --------
    ConstSpout spout = new ConstSpout("some data").withOutputFields("str");
    // 2 -  Setup DevNull Bolt   --------
    DevNullBolt bolt = new DevNullBolt();
    // 3 - Setup Topology  --------
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, spout, Helper.getInt(conf, SPOUT_COUNT, 1));
    BoltDeclarer bd = builder.setBolt(BOLT_ID, bolt, Helper.getInt(conf, BOLT_COUNT, 1));
    String groupingType = Helper.getStr(conf, GROUPING);
    if (groupingType == null || groupingType.equalsIgnoreCase(DEFAULT_GROUPING))
        bd.localOrShuffleGrouping(SPOUT_ID);
    else if (groupingType.equalsIgnoreCase(SHUFFLE_GROUPING))
        bd.shuffleGrouping(SPOUT_ID);
    return builder.createTopology();
}
Also used : ConstSpout(org.apache.storm.perf.spout.ConstSpout) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) DevNullBolt(org.apache.storm.perf.bolt.DevNullBolt)

Example 23 with BoltDeclarer

use of org.apache.storm.topology.BoltDeclarer in project storm by apache.

the class TestUtilsForResourceAwareScheduler method buildTopology.

public static StormTopology buildTopology(int numSpout, int numBolt, int spoutParallelism, int boltParallelism) {
    LOG.debug("buildTopology with -> numSpout: " + numSpout + " spoutParallelism: " + spoutParallelism + " numBolt: " + numBolt + " boltParallelism: " + boltParallelism);
    TopologyBuilder builder = new TopologyBuilder();
    for (int i = 0; i < numSpout; i++) {
        SpoutDeclarer s1 = builder.setSpout("spout-" + i, new TestSpout(), spoutParallelism);
    }
    int j = 0;
    for (int i = 0; i < numBolt; i++) {
        if (j >= numSpout) {
            j = 0;
        }
        BoltDeclarer b1 = builder.setBolt("bolt-" + i, new TestBolt(), boltParallelism).shuffleGrouping("spout-" + j);
        j++;
    }
    return builder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) SpoutDeclarer(org.apache.storm.topology.SpoutDeclarer)

Example 24 with BoltDeclarer

use of org.apache.storm.topology.BoltDeclarer in project incubator-heron by apache.

the class StreamBuilder method buildStreams.

protected void buildStreams(EcoExecutionContext executionContext, TopologyBuilder builder, ObjectBuilder objectBuilder) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchFieldException, InvocationTargetException {
    EcoTopologyDefinition topologyDefinition = executionContext.getTopologyDefinition();
    Map<String, ComponentStream> componentStreams = new HashMap<>();
    HashMap<String, BoltDeclarer> declarers = new HashMap<>();
    for (StreamDefinition stream : topologyDefinition.getStreams()) {
        Object boltObj = executionContext.getBolt(stream.getTo());
        BoltDeclarer declarer = declarers.get(stream.getTo());
        if (boltObj instanceof IRichBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IRichBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IBasicBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IBasicBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IWindowedBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IWindowedBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else {
            throw new IllegalArgumentException("Class does not appear to be a bolt: " + boltObj.getClass().getName());
        }
        GroupingDefinition grouping = stream.getGrouping();
        // if the streamId is defined, use it for the grouping,
        // otherwise assume default stream
        String streamId = grouping.getStreamId() == null ? Utils.DEFAULT_STREAM_ID : grouping.getStreamId();
        switch(grouping.getType()) {
            case SHUFFLE:
                declarer.shuffleGrouping(stream.getFrom(), streamId);
                break;
            case FIELDS:
                List<String> groupingArgs = grouping.getArgs();
                if (groupingArgs == null) {
                    throw new IllegalArgumentException("You must supply arguments for Fields grouping");
                }
                declarer.fieldsGrouping(stream.getFrom(), streamId, new Fields(groupingArgs));
                break;
            case ALL:
                declarer.allGrouping(stream.getFrom(), streamId);
                break;
            case GLOBAL:
                declarer.globalGrouping(stream.getFrom(), streamId);
                break;
            case NONE:
                declarer.noneGrouping(stream.getFrom(), streamId);
                break;
            case CUSTOM:
                declarer.customGrouping(stream.getFrom(), streamId, buildCustomStreamGrouping(stream.getGrouping().getCustomClass(), executionContext, objectBuilder));
                break;
            default:
                throw new UnsupportedOperationException("unsupported grouping type: " + grouping);
        }
    }
    executionContext.setStreams(componentStreams);
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) ComponentStream(com.twitter.heron.eco.definition.ComponentStream) StreamDefinition(com.twitter.heron.eco.definition.StreamDefinition) HashMap(java.util.HashMap) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) GroupingDefinition(com.twitter.heron.eco.definition.GroupingDefinition) IBasicBolt(org.apache.storm.topology.IBasicBolt) Fields(org.apache.storm.tuple.Fields) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) IWindowedBolt(org.apache.storm.topology.IWindowedBolt)

Example 25 with BoltDeclarer

use of org.apache.storm.topology.BoltDeclarer in project open-kilda by telstra.

the class OFEventWFMTopology method createTopology.

/**
 * The best place to look for detailed design information regarding this topologies
 * interactions is to look at docs/design/usecase/network-discovery.md
 *
 * At a high level, it receives input from the speaker, and sends output to the
 * topology engine.
 *
 * @return
 * @throws StreamNameCollisionException
 */
public StormTopology createTopology() throws StreamNameCollisionException {
    logger.debug("Building Topology - " + this.getClass().getSimpleName());
    String kafkaTopoDiscoTopic = config.getKafkaTopoDiscoTopic();
    String kafkaTopoEngTopic = config.getKafkaTopoEngTopic();
    String kafkaSpeakerTopic = config.getKafkaSpeakerTopic();
    checkAndCreateTopic(kafkaTopoDiscoTopic);
    checkAndCreateTopic(kafkaTopoEngTopic);
    TopologyBuilder builder = new TopologyBuilder();
    List<CtrlBoltRef> ctrlTargets = new ArrayList<>();
    String spoutName = SPOUT_ID_INPUT;
    String boltName = BOLT_ID;
    builder.setSpout(spoutName, createKafkaSpout(kafkaTopoDiscoTopic, spoutName));
    IStatefulBolt bolt = new OFELinkBolt(config);
    // TODO: resolve the comments below; are there any state issues?
    // NB: with shuffleGrouping, we can't maintain state .. would need to parse first
    // just to pull out switchID.
    // (crimi) - not sure I agree here .. state can be maintained, albeit distributed.
    // 
    BoltDeclarer bd = builder.setBolt(boltName, bolt, config.getParallelism()).shuffleGrouping(spoutName);
    builder.setBolt(kafkaTopoEngTopic, createKafkaBolt(kafkaTopoEngTopic), config.getParallelism()).shuffleGrouping(boltName, kafkaTopoEngTopic);
    builder.setBolt(kafkaSpeakerTopic, createKafkaBolt(kafkaSpeakerTopic), config.getParallelism()).shuffleGrouping(boltName, kafkaSpeakerTopic);
    // TODO: verify this ctrlTarget after refactoring.
    ctrlTargets.add(new CtrlBoltRef(boltName, (ICtrlBolt) bolt, bd));
    createCtrlBranch(builder, ctrlTargets);
    // TODO: verify WFM_TOPOLOGY health check
    createHealthCheckHandler(builder, ServiceType.WFM_TOPOLOGY.getId());
    return builder.createTopology();
}
Also used : CtrlBoltRef(org.openkilda.wfm.CtrlBoltRef) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) ICtrlBolt(org.openkilda.wfm.ctrl.ICtrlBolt) ArrayList(java.util.ArrayList) IStatefulBolt(org.apache.storm.topology.IStatefulBolt)

Aggregations

BoltDeclarer (org.apache.storm.topology.BoltDeclarer)34 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)20 HashMap (java.util.HashMap)13 SpoutDeclarer (org.apache.storm.topology.SpoutDeclarer)10 ArrayList (java.util.ArrayList)7 IRichBolt (org.apache.storm.topology.IRichBolt)6 Map (java.util.Map)5 IBasicBolt (org.apache.storm.topology.IBasicBolt)5 Config (org.apache.storm.Config)4 SharedMemory (org.apache.storm.generated.SharedMemory)4 KafkaSpout (org.apache.storm.kafka.spout.KafkaSpout)4 Fields (org.apache.storm.tuple.Fields)4 List (java.util.List)3 SourceArgs (org.apache.storm.coordination.CoordinatedBolt.SourceArgs)3 StormTopology (org.apache.storm.generated.StormTopology)3 KafkaBolt (org.apache.storm.kafka.bolt.KafkaBolt)3 CtrlBoltRef (org.openkilda.wfm.CtrlBoltRef)3 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2