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;
}
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();
}
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();
}
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);
}
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();
}
Aggregations