Search in sources :

Example 1 with TestWordSpout

use of org.apache.storm.testing.TestWordSpout in project storm by apache.

the class SkewedRollingTopWords method run.

/**
 * Submits (runs) the topology.
 *
 * <p>Usage: "SkewedRollingTopWords [topology-name] [-local]"
 *
 * <p>By default, the topology is run locally under the name
 * "slidingWindowCounts".
 *
 * <p>Examples:
 *
 * <p>```
 * # Runs in remote/cluster mode, with topology name "production-topology"
 * $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords production-topology ```
 *
 * @param args
 *          First positional argument (optional) is topology name, second
 *          positional argument (optional) defines whether to run the topology
 *          locally ("-local") or remotely, i.e. on a real cluster
 */
@Override
protected int run(String[] args) {
    String topologyName = "slidingWindowCounts";
    if (args.length >= 1) {
        topologyName = args[0];
    }
    TopologyBuilder builder = new TopologyBuilder();
    String spoutId = "wordGenerator";
    String counterId = "counter";
    String aggId = "aggregator";
    builder.setSpout(spoutId, new TestWordSpout(), 5);
    builder.setBolt(counterId, new RollingCountBolt(9, 3), 4).partialKeyGrouping(spoutId, new Fields("word"));
    builder.setBolt(aggId, new RollingCountAggBolt(), 4).fieldsGrouping(counterId, new Fields("obj"));
    String intermediateRankerId = "intermediateRanker";
    builder.setBolt(intermediateRankerId, new IntermediateRankingsBolt(TOP_N), 4).fieldsGrouping(aggId, new Fields("obj"));
    String totalRankerId = "finalRanker";
    builder.setBolt(totalRankerId, new TotalRankingsBolt(TOP_N)).globalGrouping(intermediateRankerId);
    LOG.info("Topology name: " + topologyName);
    return submit(topologyName, conf, builder);
}
Also used : RollingCountBolt(org.apache.storm.starter.bolt.RollingCountBolt) IntermediateRankingsBolt(org.apache.storm.starter.bolt.IntermediateRankingsBolt) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TotalRankingsBolt(org.apache.storm.starter.bolt.TotalRankingsBolt) TestWordSpout(org.apache.storm.testing.TestWordSpout) RollingCountAggBolt(org.apache.storm.starter.bolt.RollingCountAggBolt)

Example 2 with TestWordSpout

use of org.apache.storm.testing.TestWordSpout in project storm by apache.

the class StatefulWordCount method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    // a stream of words
    builder.newStream(new TestWordSpout(), new ValueMapper<String>(0), 2).window(TumblingWindows.of(BaseWindowedBolt.Duration.seconds(2))).mapToPair(w -> Pair.of(w, 1)).countByKey().updateStateByKey(0L, (state, count) -> state + count).toPairStream().print();
    Config config = new Config();
    // use redis based state store for persistence
    config.put(Config.TOPOLOGY_STATE_PROVIDER, "org.apache.storm.redis.state.RedisKeyValueStateProvider");
    String topoName = "test";
    if (args.length > 0) {
        topoName = args[0];
    }
    config.setNumWorkers(1);
    StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
Also used : Config(org.apache.storm.Config) TestWordSpout(org.apache.storm.testing.TestWordSpout) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 3 with TestWordSpout

use of org.apache.storm.testing.TestWordSpout in project storm by apache.

the class StateQueryExample method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    StreamState<String, Long> ss = builder.newStream(new TestWordSpout(), new ValueMapper<String>(0), 2).mapToPair(w -> Pair.of(w, 1)).updateStateByKey(0L, (count, val) -> count + 1);
    /*
         * A stream of words emitted by the QuerySpout is used as
         * the keys to query the state.
         */
    builder.newStream(new QuerySpout(), new ValueMapper<String>(0)).stateQuery(ss).print();
    Config config = new Config();
    // use redis based state store for persistence
    config.put(Config.TOPOLOGY_STATE_PROVIDER, "org.apache.storm.redis.state.RedisKeyValueStateProvider");
    String topoName = "test";
    if (args.length > 0) {
        topoName = args[0];
    }
    config.setNumWorkers(1);
    StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
Also used : StormSubmitter(org.apache.storm.StormSubmitter) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) Pair(org.apache.storm.streams.Pair) StreamBuilder(org.apache.storm.streams.StreamBuilder) StreamState(org.apache.storm.streams.StreamState) TopologyContext(org.apache.storm.task.TopologyContext) Fields(org.apache.storm.tuple.Fields) Utils(org.apache.storm.utils.Utils) Values(org.apache.storm.tuple.Values) Stream(org.apache.storm.streams.Stream) Map(java.util.Map) ValueMapper(org.apache.storm.streams.operations.mappers.ValueMapper) Config(org.apache.storm.Config) TestWordSpout(org.apache.storm.testing.TestWordSpout) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Config(org.apache.storm.Config) TestWordSpout(org.apache.storm.testing.TestWordSpout) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 4 with TestWordSpout

use of org.apache.storm.testing.TestWordSpout in project storm by apache.

the class WordCountToBolt method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    // Redis config parameters for the RedisStoreBolt
    JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost("127.0.0.1").setPort(6379).build();
    // Storm tuple to redis key-value mapper
    RedisStoreMapper storeMapper = new WordCountStoreMapper();
    // The redis bolt (sink)
    IRichBolt redisStoreBolt = new RedisStoreBolt(poolConfig, storeMapper);
    // A stream of words
    builder.newStream(new TestWordSpout(), new ValueMapper<String>(0)).mapToPair(w -> Pair.of(w, 1)).countByKey().to(redisStoreBolt);
    Config config = new Config();
    String topoName = "test";
    if (args.length > 0) {
        topoName = args[0];
    }
    config.setNumWorkers(1);
    StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) RedisStoreBolt(org.apache.storm.redis.bolt.RedisStoreBolt) ValueMapper(org.apache.storm.streams.operations.mappers.ValueMapper) Config(org.apache.storm.Config) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) TestWordSpout(org.apache.storm.testing.TestWordSpout) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 5 with TestWordSpout

use of org.apache.storm.testing.TestWordSpout in project storm by apache.

the class TopologyIntegrationTest method mkValidateTopology.

private StormTopology mkValidateTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("1", new TestWordSpout(true), 3);
    builder.setBolt("2", new TestWordCounter(), 4).fieldsGrouping("1", new Fields("word"));
    return builder.createTopology();
}
Also used : Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout) TestWordCounter(org.apache.storm.testing.TestWordCounter)

Aggregations

TestWordSpout (org.apache.storm.testing.TestWordSpout)33 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)30 Config (org.apache.storm.Config)18 StormTopology (org.apache.storm.generated.StormTopology)16 TestWordCounter (org.apache.storm.testing.TestWordCounter)14 HashMap (java.util.HashMap)11 Fields (org.apache.storm.tuple.Fields)10 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 TestGlobalCount (org.apache.storm.testing.TestGlobalCount)8 Map (java.util.Map)7 DaemonConfig (org.apache.storm.DaemonConfig)7 Cluster (org.apache.storm.scheduler.Cluster)7 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)7 INimbus (org.apache.storm.scheduler.INimbus)7 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)7 Topologies (org.apache.storm.scheduler.Topologies)7 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)7 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)6