Search in sources :

Example 11 with TopologyBuilder

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

the class JoinBoltExample method main.

public static void main(String[] args) throws Exception {
    FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
    FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("genderSpout", genderSpout);
    builder.setSpout("ageSpout", ageSpout);
    // inner join of 'age' and 'gender' records on 'id' field
    JoinBolt joiner = new JoinBolt("genderSpout", "id").join("ageSpout", "id", "genderSpout").select("genderSpout:id,ageSpout:id,gender,age").withTumblingWindow(new BaseWindowedBolt.Duration(10, TimeUnit.SECONDS));
    builder.setBolt("joiner", joiner).fieldsGrouping("genderSpout", new Fields("id")).fieldsGrouping("ageSpout", new Fields("id"));
    builder.setBolt("printer", new PrinterBolt()).shuffleGrouping("joiner");
    Config conf = new Config();
    conf.setDebug(true);
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("join-example", conf, builder.createTopology());
    generateGenderData(genderSpout);
    generateAgeData(ageSpout);
    Utils.sleep(30000);
    cluster.shutdown();
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) JoinBolt(org.apache.storm.bolt.JoinBolt) FeederSpout(org.apache.storm.testing.FeederSpout) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt)

Example 12 with TopologyBuilder

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

the class SingleJoinExample method main.

public static void main(String[] args) throws Exception {
    FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
    FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("gender", genderSpout);
    builder.setSpout("age", ageSpout);
    builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id")).fieldsGrouping("age", new Fields("id"));
    Config conf = new Config();
    conf.setDebug(true);
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology("join-example", conf, builder.createTopology())) {
        for (int i = 0; i < 10; i++) {
            String gender;
            if (i % 2 == 0) {
                gender = "male";
            } else {
                gender = "female";
            }
            genderSpout.feed(new Values(i, gender));
        }
        for (int i = 9; i >= 0; i--) {
            ageSpout.feed(new Values(i, i + 20));
        }
        Utils.sleep(2000);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) SingleJoinBolt(org.apache.storm.starter.bolt.SingleJoinBolt) Values(org.apache.storm.tuple.Values) FeederSpout(org.apache.storm.testing.FeederSpout) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 13 with TopologyBuilder

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

the class SkewedRollingTopWords method run.

/**
   * Submits (runs) the topology.
   *
   * Usage: "SkewedRollingTopWords [topology-name] [-local]"
   *
   * By default, the topology is run locally under the name
   * "slidingWindowCounts".
   *
   * Examples:
   *
   * ```
   *
   * # Runs in local mode (LocalCluster), with topology name "slidingWindowCounts"
   * $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords -local
   *
   * # Runs in local mode (LocalCluster), with topology name "foobar"
   * $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords foobar -local
   * 
   * # Runs in local mode (LocalCluster) for 30 seconds, with topology name "foobar" 
   * $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords foobar -local -ttl 30
   *
   * # 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.
   * @throws Exception
   */
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";
    String intermediateRankerId = "intermediateRanker";
    String totalRankerId = "finalRanker";
    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"));
    builder.setBolt(intermediateRankerId, new IntermediateRankingsBolt(TOP_N), 4).fieldsGrouping(aggId, new Fields("obj"));
    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 14 with TopologyBuilder

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

the class ExclamationTopology method run.

protected int run(String[] args) {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("word", new TestWordSpout(), 10);
    builder.setBolt("exclaim1", new ExclamationBolt(), 3).shuffleGrouping("word");
    builder.setBolt("exclaim2", new ExclamationBolt(), 2).shuffleGrouping("exclaim1");
    conf.setDebug(true);
    String topologyName = "test";
    if (isLocal) {
        ttl = 10;
    } else {
        conf.setNumWorkers(3);
    }
    if (args != null && args.length > 0) {
        topologyName = args[0];
    }
    return submit(topologyName, conf, builder);
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout)

Example 15 with TopologyBuilder

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

the class SimpleTopology method getTopology.

public StormTopology getTopology(Map<String, Object> config) {
    TopologyBuilder builder = new TopologyBuilder();
    // spouts
    FluxShellSpout spout = new FluxShellSpout(new String[] { "node", "randomsentence.js" }, new String[] { "word" });
    builder.setSpout("sentence-spout", spout, 1);
    // bolts
    builder.setBolt("log-bolt", new LogInfoBolt(), 1).shuffleGrouping("sentence-spout");
    return builder.createTopology();
}
Also used : LogInfoBolt(org.apache.storm.flux.wrappers.bolts.LogInfoBolt) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) FluxShellSpout(org.apache.storm.flux.wrappers.spouts.FluxShellSpout)

Aggregations

TopologyBuilder (org.apache.storm.topology.TopologyBuilder)118 Config (org.apache.storm.Config)62 Fields (org.apache.storm.tuple.Fields)36 LocalCluster (org.apache.storm.LocalCluster)28 HashMap (java.util.HashMap)25 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)24 Test (org.junit.Test)17 TestWordSpout (org.apache.storm.testing.TestWordSpout)16 Map (java.util.Map)12 StormTopology (org.apache.storm.generated.StormTopology)12 BoltDeclarer (org.apache.storm.topology.BoltDeclarer)9 Values (org.apache.storm.tuple.Values)9 FlinkLocalCluster (org.apache.flink.storm.api.FlinkLocalCluster)8 Cluster (org.apache.storm.scheduler.Cluster)8 INimbus (org.apache.storm.scheduler.INimbus)8 SchedulerAssignmentImpl (org.apache.storm.scheduler.SchedulerAssignmentImpl)8 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)8 Topologies (org.apache.storm.scheduler.Topologies)8 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)8 BoltFileSink (org.apache.flink.storm.util.BoltFileSink)7