Search in sources :

Example 11 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project ud381 by udacity.

the class SentenceCountTopology method main.

public static void main(String[] args) throws Exception {
    // create the topology
    TopologyBuilder builder = new TopologyBuilder();
    // attach the word spout to the topology - parallelism of 5
    // builder.setSpout("word-spout", new WordSpout(), 5);
    // attach sentence spout to the topology - parallelism of 1
    builder.setSpout("sentence-spout", new RandomSentenceSpout(), 1);
    // attach the count bolt using fields grouping - parallelism of 15
    builder.setBolt("count-bolt", new CountBolt(), 15).fieldsGrouping("sentence-spout", new Fields("sentence"));
    // attach the report bolt using global grouping - parallelism of 1
    // ***************************************************
    // BEGIN YOUR CODE - part 2
    builder.setBolt("report-bolt", new ReportBolt(), 1).globalGrouping("count-bolt");
    // END YOUR CODE
    // ***************************************************
    // create the default config object
    Config conf = new Config();
    // set the config in debugging mode
    conf.setDebug(true);
    if (args != null && args.length > 0) {
        // run it in a live cluster
        // set the number of workers for running all spout and bolt tasks
        conf.setNumWorkers(3);
        // create the topology and submit with config
        StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
    } else {
        // run it in a simulated local cluster
        // set the number of threads to run - similar to setting number of workers in live cluster
        conf.setMaxTaskParallelism(3);
        // create the local cluster instance
        LocalCluster cluster = new LocalCluster();
        // submit the topology to the local cluster
        // name topology
        cluster.submitTopology("sentence-count", conf, builder.createTopology());
        // **********************************************************************
        // let the topology run for 30 seconds. note topologies never terminate!
        Thread.sleep(30000);
        // **********************************************************************
        // we are done, so shutdown the local cluster
        cluster.shutdown();
    }
}
Also used : RandomSentenceSpout(udacity.storm.spout.RandomSentenceSpout) LocalCluster(backtype.storm.LocalCluster) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config)

Example 12 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project storm-hbase by ypf412.

the class OutputTopology method main.

/**
 * HBase Data Output Topology
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    PropConfig pc = new PropConfig("storm.properties");
    int topoWorkers = Integer.valueOf(pc.getProperty("storm.topolopy.workers"));
    int spoutTasks = Integer.valueOf(pc.getProperty("storm.spout.tasks"));
    builder.setSpout("hbaseSpout", new HBaseSpout(), spoutTasks);
    int boltTasks = spoutTasks;
    builder.setBolt("outputBolt", new OutputBolt(), boltTasks).fieldsGrouping("hbaseSpout", new Fields("sharding"));
    Config conf = new Config();
    conf.put(Constants.STORM_PROP_CONF_FILE, "storm.properties");
    conf.put(Constants.HBASE_PROP_CONF_FILE, "hbase.properties");
    if (args != null && args.length > 0) {
        // run on storm cluster
        conf.setNumAckers(1);
        conf.setNumWorkers(topoWorkers);
        StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
    } else {
        // run on local cluster
        conf.setMaxTaskParallelism(3);
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("test", conf, builder.createTopology());
        Utils.sleep(10000);
        cluster.killTopology("test");
        cluster.shutdown();
    }
}
Also used : LocalCluster(backtype.storm.LocalCluster) HBaseSpout(ypf412.storm.spout.HBaseSpout) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) PropConfig(ypf412.storm.util.PropConfig) PropConfig(ypf412.storm.util.PropConfig) OutputBolt(ypf412.storm.bolt.OutputBolt)

Example 13 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project avro-kafka-storm by ransilberman.

the class AvroTopology method main.

public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
    // Add those lines to prevent too much logging noise in the console
    Logger.getLogger("storm.kafka.PartitionManager").setLevel(Level.ERROR);
    Logger.getLogger("backtype.storm").setLevel(Level.ERROR);
    Logger.getLogger("storm.kafka").setLevel(Level.ERROR);
    TopologyBuilder builder = new TopologyBuilder();
    int partitions = 1;
    final String offsetPath = "/liveperson-avro-test";
    final String consumerId = "v1";
    final String topic = "avro-test";
    List<String> hosts = new ArrayList<String>();
    hosts.add("tlvwhale1");
    hosts.add("tlvwhale2");
    hosts.add("tlvwhale3");
    SpoutConfig kafkaConfig = new SpoutConfig(KafkaConfig.StaticHosts.fromHostString(hosts, partitions), topic, offsetPath, consumerId);
    KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig);
    builder.setSpout("spout", kafkaSpout);
    builder.setBolt("bolt", new AvroBolt()).shuffleGrouping("spout");
    Config conf = new Config();
    conf.setDebug(true);
    if (args != null && args.length > 0) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
    } else {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("avroTopology", conf, builder.createTopology());
        Utils.sleep(100000);
        cluster.killTopology("avroTopology");
        cluster.shutdown();
    }
}
Also used : LocalCluster(backtype.storm.LocalCluster) TopologyBuilder(backtype.storm.topology.TopologyBuilder) KafkaConfig(storm.kafka.KafkaConfig) SpoutConfig(storm.kafka.SpoutConfig) Config(backtype.storm.Config) SpoutConfig(storm.kafka.SpoutConfig) ArrayList(java.util.ArrayList) KafkaSpout(storm.kafka.KafkaSpout)

Example 14 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project avro-kafka-storm by ransilberman.

the class AvroTopology2 method main.

public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
    // Add those lines to prevent too much logging noise in the console
    Logger.getLogger("storm.kafka.PartitionManager").setLevel(Level.ERROR);
    Logger.getLogger("backtype.storm").setLevel(Level.ERROR);
    Logger.getLogger("storm.kafka").setLevel(Level.ERROR);
    TopologyBuilder builder = new TopologyBuilder();
    int partitions = 1;
    final String offsetPath = "/liveperson-avro-test";
    final String consumerId = "v1";
    final String topic = "avro-test";
    List<String> hosts = new ArrayList<String>();
    hosts.add("tlvwhale1");
    hosts.add("tlvwhale2");
    hosts.add("tlvwhale3");
    SpoutConfig kafkaConfig = new SpoutConfig(KafkaConfig.StaticHosts.fromHostString(hosts, partitions), topic, offsetPath, consumerId);
    KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig);
    builder.setSpout("spout", kafkaSpout);
    builder.setBolt("bolt", new AvroBolt()).shuffleGrouping("spout");
    Config conf = new Config();
    conf.setDebug(true);
    if (args != null && args.length > 0) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
    } else {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("avroTopology", conf, builder.createTopology());
        Utils.sleep(1000000);
        cluster.killTopology("avroTopology");
        cluster.shutdown();
    }
}
Also used : LocalCluster(backtype.storm.LocalCluster) TopologyBuilder(backtype.storm.topology.TopologyBuilder) KafkaConfig(storm.kafka.KafkaConfig) SpoutConfig(storm.kafka.SpoutConfig) Config(backtype.storm.Config) SpoutConfig(storm.kafka.SpoutConfig) ArrayList(java.util.ArrayList) KafkaSpout(storm.kafka.KafkaSpout)

Example 15 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project heron by twitter.

the class WordCountTopology method main.

/**
 * Main method
 */
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
    if (args.length < 1) {
        throw new RuntimeException("Specify topology name");
    }
    int parallelism = 1;
    if (args.length > 1) {
        parallelism = Integer.parseInt(args[1]);
    }
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("word", new WordSpout(), parallelism);
    builder.setBolt("consumer", new ConsumerBolt(), parallelism).fieldsGrouping("word", new Fields("word"));
    Config conf = new Config();
    conf.setNumWorkers(parallelism);
    StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
}
Also used : Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config)

Aggregations

TopologyBuilder (backtype.storm.topology.TopologyBuilder)92 Config (backtype.storm.Config)47 Fields (backtype.storm.tuple.Fields)41 LocalCluster (backtype.storm.LocalCluster)23 JStormHelper (com.alibaba.starter.utils.JStormHelper)16 Map (java.util.Map)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)12 LocalDRPC (backtype.storm.LocalDRPC)7 BoltDeclarer (backtype.storm.topology.BoltDeclarer)6 JStormUnitTestMetricValidator (com.jstorm.example.unittests.utils.JStormUnitTestMetricValidator)5 ArrayList (java.util.ArrayList)5 CoordinatedBolt (backtype.storm.coordination.CoordinatedBolt)4 IdStreamSpec (backtype.storm.coordination.CoordinatedBolt.IdStreamSpec)4 SourceArgs (backtype.storm.coordination.CoordinatedBolt.SourceArgs)4 TestWordSpout (backtype.storm.testing.TestWordSpout)4 HashSet (java.util.HashSet)4 StormTopology (backtype.storm.generated.StormTopology)3 BaseWindowedBolt (backtype.storm.topology.base.BaseWindowedBolt)3 JStormUnitTestValidator (com.jstorm.example.unittests.utils.JStormUnitTestValidator)3