Search in sources :

Example 51 with TopologyBuilder

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

the class ExclamationTopology method getStormTopology.

public static StormTopology getStormTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD, new FixedOrderWordSpout(), SPOUT_EXECUTORS);
    builder.setBolt(EXCLAIM_1, new ExclamationTopology.ExclamationBolt(), 3).shuffleGrouping(WORD);
    builder.setBolt(EXCLAIM_2, new ExclamationTopology.ExclamationBolt(), EXCLAIM_2_EXECUTORS).shuffleGrouping(EXCLAIM_1);
    return builder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder)

Example 52 with TopologyBuilder

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

the class SlidingTimeCorrectness method newTopology.

@Override
public StormTopology newTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(getSpoutName(), new TimeDataIncrementingSpout(), spoutExecutors);
    builder.setBolt(getBoltName(), new TimeDataVerificationBolt().withWindow(new BaseWindowedBolt.Duration(windowSec, TimeUnit.SECONDS), new BaseWindowedBolt.Duration(slideSec, TimeUnit.SECONDS)).withTimestampField(TimeData.getTimestampFieldName()).withLag(new BaseWindowedBolt.Duration(10, TimeUnit.SECONDS)), boltExecutors).globalGrouping(getSpoutName());
    return builder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt)

Example 53 with TopologyBuilder

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

the class TumblingTimeCorrectness method newTopology.

@Override
public StormTopology newTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(getSpoutName(), new TimeDataIncrementingSpout(), spoutExecutors);
    builder.setBolt(getBoltName(), new TimeDataVerificationBolt().withTumblingWindow(new BaseWindowedBolt.Duration(tumbleSec, TimeUnit.SECONDS)).withLag(new BaseWindowedBolt.Duration(10, TimeUnit.SECONDS)).withTimestampField(TimeData.getTimestampFieldName()), boltExecutors).globalGrouping(getSpoutName());
    return builder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt)

Example 54 with TopologyBuilder

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

the class StreamBuilder method build.

/**
 * Builds a new {@link StormTopology} for the computation expressed via the stream api.
 *
 * @return the storm topology
 */
public StormTopology build() {
    nodeGroupingInfo.clear();
    windowInfo.clear();
    curGroup.clear();
    TopologicalOrderIterator<Node, Edge> iterator = new TopologicalOrderIterator<>(graph, queue());
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    while (iterator.hasNext()) {
        Node node = iterator.next();
        if (node instanceof SpoutNode) {
            addSpout(topologyBuilder, (SpoutNode) node);
        } else if (node instanceof ProcessorNode) {
            handleProcessorNode((ProcessorNode) node, topologyBuilder);
        } else if (node instanceof PartitionNode) {
            updateNodeGroupingInfo((PartitionNode) node);
            processCurGroup(topologyBuilder);
        } else if (node instanceof WindowNode) {
            updateWindowInfo((WindowNode) node);
            processCurGroup(topologyBuilder);
        } else if (node instanceof SinkNode) {
            processCurGroup(topologyBuilder);
            addSink(topologyBuilder, (SinkNode) node);
        }
    }
    processCurGroup(topologyBuilder);
    mayBeAddTsField();
    return topologyBuilder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopologicalOrderIterator(org.apache.storm.shade.org.jgrapht.traverse.TopologicalOrderIterator)

Example 55 with TopologyBuilder

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

the class TopologyIntegrationTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withSupervisors(4).withDaemonConf(Collections.singletonMap(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS, true)).build()) {
        FeederSpout feeder = new FeederSpout(new Fields("field1"));
        AckFailMapTracker tracker = new AckFailMapTracker();
        feeder.setAckFailDelegate(tracker);
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", feeder);
        builder.setBolt("2", new AckEveryOtherBolt()).globalGrouping("1");
        StormTopology topology = builder.createTopology();
        cluster.submitTopology("timeout-tester", Collections.singletonMap(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 10), topology);
        cluster.advanceClusterTime(11);
        feeder.feed(new Values("a"), 1);
        feeder.feed(new Values("b"), 2);
        feeder.feed(new Values("c"), 3);
        cluster.advanceClusterTime(9);
        assertAcked(tracker, 1, 3);
        assertThat(tracker.isFailed(2), is(false));
        cluster.advanceClusterTime(12);
        assertFailed(tracker, 2);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) FeederSpout(org.apache.storm.testing.FeederSpout) Test(org.junit.jupiter.api.Test) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TopologyBuilder (org.apache.storm.topology.TopologyBuilder)266 Config (org.apache.storm.Config)141 Fields (org.apache.storm.tuple.Fields)76 StormTopology (org.apache.storm.generated.StormTopology)47 HashMap (java.util.HashMap)41 LocalCluster (org.apache.storm.LocalCluster)39 TestWordSpout (org.apache.storm.testing.TestWordSpout)34 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)26 Test (org.junit.Test)26 Test (org.junit.jupiter.api.Test)26 Cluster (org.apache.storm.scheduler.Cluster)25 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)25 Topologies (org.apache.storm.scheduler.Topologies)25 Values (org.apache.storm.tuple.Values)25 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Map (java.util.Map)23 INimbus (org.apache.storm.scheduler.INimbus)23 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)22 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)22