Search in sources :

Example 71 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";
    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 72 with TopologyBuilder

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

the class LookupWordCount method main.

public static void main(String[] args) throws Exception {
    String host = TEST_REDIS_HOST;
    int port = TEST_REDIS_PORT;
    if (args.length >= 2) {
        host = args[0];
        port = Integer.parseInt(args[1]);
    }
    JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost(host).setPort(port).build();
    WordSpout spout = new WordSpout();
    RedisLookupMapper lookupMapper = setupLookupMapper();
    RedisLookupBolt lookupBolt = new RedisLookupBolt(poolConfig, lookupMapper);
    PrintWordTotalCountBolt printBolt = new PrintWordTotalCountBolt();
    // wordspout -> lookupbolt
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(LOOKUP_BOLT, lookupBolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(PRINT_BOLT, printBolt, 1).shuffleGrouping(LOOKUP_BOLT);
    String topoName = "test";
    if (args.length == 3) {
        topoName = args[2];
    } else if (args.length > 3) {
        System.out.println("Usage: LookupWordCount <redis host> <redis port> (topology name)");
        return;
    }
    Config config = new Config();
    StormSubmitter.submitTopology(topoName, config, builder.createTopology());
}
Also used : RedisLookupBolt(org.apache.storm.redis.bolt.RedisLookupBolt) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) RedisLookupMapper(org.apache.storm.redis.common.mapper.RedisLookupMapper)

Example 73 with TopologyBuilder

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

the class InsertWordCount method main.

public static void main(String[] args) throws Exception {
    String url = TEST_MONGODB_URL;
    String collectionName = TEST_MONGODB_COLLECTION_NAME;
    if (args.length >= 2) {
        url = args[0];
        collectionName = args[1];
    }
    WordSpout spout = new WordSpout();
    WordCounter bolt = new WordCounter();
    MongoMapper mapper = new SimpleMongoMapper().withFields("word", "count");
    MongoInsertBolt insertBolt = new MongoInsertBolt(url, collectionName, mapper);
    // wordSpout ==> countBolt ==> MongoInsertBolt
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(COUNT_BOLT, bolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(INSERT_BOLT, insertBolt, 1).fieldsGrouping(COUNT_BOLT, new Fields("word"));
    String topoName = "test";
    if (args.length == 3) {
        topoName = args[2];
    } else if (args.length > 3) {
        System.out.println("Usage: InsertWordCount <mongodb url> <mongodb collection> [topology name]");
        return;
    }
    Config config = new Config();
    StormSubmitter.submitTopology(topoName, config, builder.createTopology());
}
Also used : SimpleMongoMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoMapper) MongoMapper(org.apache.storm.mongodb.common.mapper.MongoMapper) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) MongoInsertBolt(org.apache.storm.mongodb.bolt.MongoInsertBolt) SimpleMongoMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoMapper)

Example 74 with TopologyBuilder

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

the class FileReadWordCountTopo method getTopology.

static StormTopology getTopology(Map<String, Object> config) {
    final int spoutNum = Helper.getInt(config, SPOUT_NUM, DEFAULT_SPOUT_NUM);
    final int spBoltNum = Helper.getInt(config, SPLIT_NUM, DEFAULT_SPLIT_BOLT_NUM);
    final int cntBoltNum = Helper.getInt(config, COUNT_NUM, DEFAULT_COUNT_BOLT_NUM);
    final String inputFile = Helper.getStr(config, INPUT_FILE);
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, new FileReadSpout(inputFile), spoutNum);
    builder.setBolt(SPLIT_ID, new SplitSentenceBolt(), spBoltNum).localOrShuffleGrouping(SPOUT_ID);
    builder.setBolt(COUNT_ID, new CountBolt(), cntBoltNum).fieldsGrouping(SPLIT_ID, new Fields(SplitSentenceBolt.FIELDS));
    return builder.createTopology();
}
Also used : FileReadSpout(org.apache.storm.perf.spout.FileReadSpout) SplitSentenceBolt(org.apache.storm.perf.bolt.SplitSentenceBolt) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) CountBolt(org.apache.storm.perf.bolt.CountBolt)

Example 75 with TopologyBuilder

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

the class LowThroughputTopo method getTopology.

static StormTopology getTopology(Map<String, Object> conf) {
    Long sleepMs = ObjectReader.getLong(conf.get(SLEEP_MS));
    // 1 -  Setup Spout   --------
    ThrottledSpout spout = new ThrottledSpout(sleepMs).withOutputFields(ThrottledSpout.DEFAULT_FIELD_NAME);
    // 2 -  Setup DevNull Bolt   --------
    LatencyPrintBolt bolt = new LatencyPrintBolt();
    // 3 - Setup Topology  --------
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, spout, Helper.getInt(conf, SPOUT_COUNT, 1));
    BoltDeclarer bd = builder.setBolt(BOLT_ID, bolt, Helper.getInt(conf, BOLT_COUNT, 1));
    bd.localOrShuffleGrouping(SPOUT_ID);
    // bd.shuffleGrouping(SPOUT_ID);
    return builder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BoltDeclarer(org.apache.storm.topology.BoltDeclarer)

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