Search in sources :

Example 6 with LocalTopology

use of org.apache.storm.LocalCluster.LocalTopology in project storm by apache.

the class InsertWordCount method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    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"));
    if (args.length == 2) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", config, builder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    } else if (args.length == 3) {
        StormSubmitter.submitTopology(args[2], config, builder.createTopology());
    } else {
        System.out.println("Usage: InsertWordCount <mongodb url> <mongodb collection> [topology name]");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) 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) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 7 with LocalTopology

use of org.apache.storm.LocalCluster.LocalTopology in project storm by apache.

the class WordCountTrident method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    conf.setMaxSpoutPending(5);
    if (args.length == 2) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("wordCounter", conf, buildTopology(args[0], args[1]))) {
            Thread.sleep(60 * 1000);
        }
        System.exit(0);
    } else if (args.length == 3) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopology(args[2], conf, buildTopology(args[0], args[1]));
    } else {
        System.out.println("Usage: WordCountTrident <mongodb url> <mongodb collection> [topology name]");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 8 with LocalTopology

use of org.apache.storm.LocalCluster.LocalTopology in project storm by apache.

the class SampleOpenTsdbTridentTopology method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalArgumentException("There should be at least one argument. Run as `SampleOpenTsdbTridentTopology <tsdb-url>`");
    }
    String tsdbUrl = args[0];
    final OpenTsdbClient.Builder openTsdbClientBuilder = OpenTsdbClient.newBuilder(tsdbUrl);
    final OpenTsdbStateFactory openTsdbStateFactory = new OpenTsdbStateFactory(openTsdbClientBuilder, Collections.singletonList(TupleOpenTsdbDatapointMapper.DEFAULT_MAPPER));
    TridentTopology tridentTopology = new TridentTopology();
    final Stream stream = tridentTopology.newStream("metric-tsdb-stream", new MetricGenBatchSpout(10));
    stream.peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("########### Received tuple: [{}]", input);
        }
    }).partitionPersist(openTsdbStateFactory, MetricGenSpout.DEFAULT_METRIC_FIELDS, new OpenTsdbStateUpdater());
    Config conf = new Config();
    conf.setDebug(true);
    if (args.length > 1) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[1], conf, tridentTopology.build());
    } else {
        conf.setMaxTaskParallelism(3);
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("word-count", conf, tridentTopology.build())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) OpenTsdbStateFactory(org.apache.storm.opentsdb.trident.OpenTsdbStateFactory) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) OpenTsdbClient(org.apache.storm.opentsdb.client.OpenTsdbClient) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) OpenTsdbStateUpdater(org.apache.storm.opentsdb.trident.OpenTsdbStateUpdater) Stream(org.apache.storm.trident.Stream) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 9 with LocalTopology

use of org.apache.storm.LocalCluster.LocalTopology in project storm by apache.

the class LookupWordCount method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    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);
    if (args.length == 2) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", config, builder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    } else if (args.length == 3) {
        StormSubmitter.submitTopology(args[2], config, builder.createTopology());
    } else {
        System.out.println("Usage: LookupWordCount <redis host> <redis port> (topology name)");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) 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) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 10 with LocalTopology

use of org.apache.storm.LocalCluster.LocalTopology in project storm by apache.

the class WordCountTridentRedis method main.

public static void main(String[] args) throws Exception {
    if (args.length != 3) {
        System.out.println("Usage: WordCountTrident 0(storm-local)|1(storm-cluster) redis-host redis-port");
        System.exit(1);
    }
    Integer flag = Integer.valueOf(args[0]);
    String redisHost = args[1];
    Integer redisPort = Integer.valueOf(args[2]);
    Config conf = new Config();
    conf.setMaxSpoutPending(5);
    if (flag == 0) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test_wordCounter_for_redis", conf, buildTopology(redisHost, redisPort))) {
            Thread.sleep(60 * 1000);
        }
        System.exit(0);
    } else if (flag == 1) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopology("test_wordCounter_for_redis", conf, buildTopology(redisHost, redisPort));
    } else {
        System.out.println("Usage: WordCountTrident 0(storm-local)|1(storm-cluster) redis-host redis-port");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Aggregations

LocalTopology (org.apache.storm.LocalCluster.LocalTopology)54 LocalCluster (org.apache.storm.LocalCluster)52 Config (org.apache.storm.Config)50 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)24 Fields (org.apache.storm.tuple.Fields)17 Map (java.util.Map)7 HashMap (java.util.HashMap)6 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 LocalDRPC (org.apache.storm.LocalDRPC)4 StormTopology (org.apache.storm.generated.StormTopology)4 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)4 Yaml (org.yaml.snakeyaml.Yaml)4 JedisClusterConfig (org.apache.storm.redis.common.config.JedisClusterConfig)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DruidBeamFactory (org.apache.storm.druid.bolt.DruidBeamFactory)2 ITupleDruidEventMapper (org.apache.storm.druid.bolt.ITupleDruidEventMapper)2 TupleDruidEventMapper (org.apache.storm.druid.bolt.TupleDruidEventMapper)2 EsConfig (org.apache.storm.elasticsearch.common.EsConfig)2