use of org.apache.storm.generated.Grouping in project storm by apache.
the class StreamBuilderTest method testGlobalAggregate.
@Test
public void testGlobalAggregate() throws Exception {
Stream<String> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID), new ValueMapper<>(0), 2);
stream.aggregate(new Count<>());
StormTopology topology = streamBuilder.build();
assertEquals(2, topology.get_bolts_size());
Bolt bolt1 = topology.get_bolts().get("bolt1");
Bolt bolt2 = topology.get_bolts().get("bolt2");
String spoutId = topology.get_spouts().keySet().iterator().next();
Map<GlobalStreamId, Grouping> expected1 = new HashMap<>();
expected1.put(new GlobalStreamId(spoutId, "default"), Grouping.shuffle(new NullStruct()));
Map<GlobalStreamId, Grouping> expected2 = new HashMap<>();
expected2.put(new GlobalStreamId("bolt1", "s1"), Grouping.fields(Collections.emptyList()));
expected2.put(new GlobalStreamId("bolt1", "s1__punctuation"), Grouping.all(new NullStruct()));
assertEquals(expected1, bolt1.get_common().get_inputs());
assertEquals(expected2, bolt2.get_common().get_inputs());
}
use of org.apache.storm.generated.Grouping in project storm by apache.
the class StreamBuilderTest method testSpoutToBolt.
@Test
public void testSpoutToBolt() throws Exception {
Stream<Tuple> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID));
stream.to(newBolt());
StormTopology topology = streamBuilder.build();
assertEquals(1, topology.get_spouts_size());
assertEquals(1, topology.get_bolts_size());
String spoutId = topology.get_spouts().keySet().iterator().next();
Map<GlobalStreamId, Grouping> expected = new HashMap<>();
expected.put(new GlobalStreamId(spoutId, "default"), Grouping.shuffle(new NullStruct()));
assertEquals(expected, topology.get_bolts().values().iterator().next().get_common().get_inputs());
}
use of org.apache.storm.generated.Grouping in project storm by apache.
the class TopologyDetails method getComponents.
/**
* Returns a representation of the non-system components of the topology graph
* Each Component object in the returning map is populated with the list of its
* parents, children and execs assigned to that component.
* @return a map of components
*/
public Map<String, Component> getComponents() {
Map<String, Component> all_comp = new HashMap<>();
StormTopology storm_topo = this.topology;
// spouts
if (storm_topo.get_spouts() != null) {
for (Map.Entry<String, SpoutSpec> spoutEntry : storm_topo.get_spouts().entrySet()) {
if (!Utils.isSystemId(spoutEntry.getKey())) {
Component newComp;
if (all_comp.containsKey(spoutEntry.getKey())) {
newComp = all_comp.get(spoutEntry.getKey());
newComp.execs = componentToExecs(newComp.id);
} else {
newComp = new Component(spoutEntry.getKey());
newComp.execs = componentToExecs(newComp.id);
all_comp.put(spoutEntry.getKey(), newComp);
}
newComp.type = Component.ComponentType.SPOUT;
for (Map.Entry<GlobalStreamId, Grouping> spoutInput : spoutEntry.getValue().get_common().get_inputs().entrySet()) {
newComp.parents.add(spoutInput.getKey().get_componentId());
if (!all_comp.containsKey(spoutInput.getKey().get_componentId())) {
all_comp.put(spoutInput.getKey().get_componentId(), new Component(spoutInput.getKey().get_componentId()));
}
all_comp.get(spoutInput.getKey().get_componentId()).children.add(spoutEntry.getKey());
}
}
}
}
// bolts
if (storm_topo.get_bolts() != null) {
for (Map.Entry<String, Bolt> boltEntry : storm_topo.get_bolts().entrySet()) {
if (!Utils.isSystemId(boltEntry.getKey())) {
Component newComp;
if (all_comp.containsKey(boltEntry.getKey())) {
newComp = all_comp.get(boltEntry.getKey());
newComp.execs = componentToExecs(newComp.id);
} else {
newComp = new Component(boltEntry.getKey());
newComp.execs = componentToExecs(newComp.id);
all_comp.put(boltEntry.getKey(), newComp);
}
newComp.type = Component.ComponentType.BOLT;
for (Map.Entry<GlobalStreamId, Grouping> boltInput : boltEntry.getValue().get_common().get_inputs().entrySet()) {
newComp.parents.add(boltInput.getKey().get_componentId());
if (!all_comp.containsKey(boltInput.getKey().get_componentId())) {
all_comp.put(boltInput.getKey().get_componentId(), new Component(boltInput.getKey().get_componentId()));
}
all_comp.get(boltInput.getKey().get_componentId()).children.add(boltEntry.getKey());
}
}
}
}
return all_comp;
}
Aggregations