Search in sources :

Example 16 with Grouping

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());
}
Also used : HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt) Bolt(org.apache.storm.generated.Bolt) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) IRichBolt(org.apache.storm.topology.IRichBolt) Grouping(org.apache.storm.generated.Grouping) NullStruct(org.apache.storm.generated.NullStruct) Test(org.junit.Test)

Example 17 with Grouping

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());
}
Also used : HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) Grouping(org.apache.storm.generated.Grouping) NullStruct(org.apache.storm.generated.NullStruct) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 18 with Grouping

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;
}
Also used : HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) Grouping(org.apache.storm.generated.Grouping) Bolt(org.apache.storm.generated.Bolt) SpoutSpec(org.apache.storm.generated.SpoutSpec) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) Component(org.apache.storm.scheduler.resource.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Grouping (org.apache.storm.generated.Grouping)18 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)16 HashMap (java.util.HashMap)14 Map (java.util.Map)9 Bolt (org.apache.storm.generated.Bolt)6 StormTopology (org.apache.storm.generated.StormTopology)5 Test (org.junit.Test)5 ComponentCommon (org.apache.storm.generated.ComponentCommon)4 NullStruct (org.apache.storm.generated.NullStruct)4 SpoutSpec (org.apache.storm.generated.SpoutSpec)4 StreamInfo (org.apache.storm.generated.StreamInfo)4 Tuple (org.apache.storm.tuple.Tuple)4 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 IRichBolt (org.apache.storm.topology.IRichBolt)3 Fields (org.apache.storm.tuple.Fields)3 EventLoggerBolt (org.apache.storm.metric.EventLoggerBolt)2 MetricsConsumerBolt (org.apache.storm.metric.MetricsConsumerBolt)2 SystemBolt (org.apache.storm.metric.SystemBolt)2 BranchProcessor (org.apache.storm.streams.processors.BranchProcessor)2