Search in sources :

Example 46 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();
    Map<String, Object> hbConf = new HashMap<String, Object>();
    if (args.length > 0) {
        hbConf.put("hbase.rootdir", args[0]);
    }
    config.put("hbase.conf", hbConf);
    WordSpout spout = new WordSpout();
    TotalWordCounter totalBolt = new TotalWordCounter();
    SimpleHBaseMapper mapper = new SimpleHBaseMapper().withRowKeyField("word");
    HBaseProjectionCriteria projectionCriteria = new HBaseProjectionCriteria();
    projectionCriteria.addColumn(new HBaseProjectionCriteria.ColumnMetaData("cf", "count"));
    WordCountValueMapper rowToTupleMapper = new WordCountValueMapper();
    HBaseLookupBolt hBaseLookupBolt = new HBaseLookupBolt("WordCount", mapper, rowToTupleMapper).withConfigKey("hbase.conf").withProjectionCriteria(projectionCriteria);
    //wordspout -> lookupbolt -> totalCountBolt
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(LOOKUP_BOLT, hBaseLookupBolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(TOTAL_COUNT_BOLT, totalBolt, 1).fieldsGrouping(LOOKUP_BOLT, new Fields("columnName"));
    if (args.length == 1) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", config, builder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    } else if (args.length == 2) {
        StormSubmitter.submitTopology(args[1], config, builder.createTopology());
    } else {
        System.out.println("Usage: LookupWordCount <hbase.rootdir>");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) HBaseProjectionCriteria(org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) HBaseLookupBolt(org.apache.storm.hbase.bolt.HBaseLookupBolt) Fields(org.apache.storm.tuple.Fields) SimpleHBaseMapper(org.apache.storm.hbase.bolt.mapper.SimpleHBaseMapper)

Example 47 with LocalTopology

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

the class PersistentWordCount method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    Map<String, Object> hbConf = new HashMap<String, Object>();
    if (args.length > 0) {
        hbConf.put("hbase.rootdir", args[0]);
    }
    config.put("hbase.conf", hbConf);
    WordSpout spout = new WordSpout();
    WordCounter bolt = new WordCounter();
    SimpleHBaseMapper mapper = new SimpleHBaseMapper().withRowKeyField("word").withColumnFields(new Fields("word")).withCounterFields(new Fields("count")).withColumnFamily("cf");
    HBaseBolt hbase = new HBaseBolt("WordCount", mapper).withConfigKey("hbase.conf");
    // wordSpout ==> countBolt ==> HBaseBolt
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(COUNT_BOLT, bolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(HBASE_BOLT, hbase, 1).fieldsGrouping(COUNT_BOLT, new Fields("word"));
    if (args.length == 1) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", config, builder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    } else if (args.length == 2) {
        StormSubmitter.submitTopology(args[1], config, builder.createTopology());
    } else if (args.length == 4) {
        System.out.println("hdfs url: " + args[0] + ", keytab file: " + args[2] + ", principal name: " + args[3] + ", toplogy name: " + args[1]);
        hbConf.put(HBaseSecurityUtil.STORM_KEYTAB_FILE_KEY, args[2]);
        hbConf.put(HBaseSecurityUtil.STORM_USER_NAME_KEY, args[3]);
        config.setNumWorkers(3);
        StormSubmitter.submitTopology(args[1], config, builder.createTopology());
    } else {
        System.out.println("Usage: PersistentWordCount <hbase.rootdir> [topology name] [keytab file] [principal name]");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) Fields(org.apache.storm.tuple.Fields) HBaseBolt(org.apache.storm.hbase.bolt.HBaseBolt) SimpleHBaseMapper(org.apache.storm.hbase.bolt.mapper.SimpleHBaseMapper)

Example 48 with LocalTopology

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

the class SampleOpenTsdbBoltTopology 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 `SampleOpenTsdbBoltTopology <tsdb-url>`");
    }
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout("metric-gen", new MetricGenSpout(), 5);
    String openTsdbUrl = args[0];
    OpenTsdbClient.Builder builder = OpenTsdbClient.newBuilder(openTsdbUrl).sync(30_000).returnDetails();
    final OpenTsdbBolt openTsdbBolt = new OpenTsdbBolt(builder, Collections.singletonList(TupleOpenTsdbDatapointMapper.DEFAULT_MAPPER));
    openTsdbBolt.withBatchSize(10).withFlushInterval(2).failTupleForFailedMetrics();
    topologyBuilder.setBolt("opentsdb", openTsdbBolt).shuffleGrouping("metric-gen");
    Config conf = new Config();
    conf.setDebug(true);
    if (args.length > 1) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[1], conf, topologyBuilder.createTopology());
    } else {
        conf.setMaxTaskParallelism(3);
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("word-count", conf, topologyBuilder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) OpenTsdbClient(org.apache.storm.opentsdb.client.OpenTsdbClient) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) OpenTsdbBolt(org.apache.storm.opentsdb.bolt.OpenTsdbBolt) Config(org.apache.storm.Config) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 49 with LocalTopology

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

the class WordCountTridentRedisMap 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)

Example 50 with LocalTopology

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

the class EsIndexTopology method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    config.setNumWorkers(1);
    TopologyBuilder builder = new TopologyBuilder();
    UserDataSpout spout = new UserDataSpout();
    builder.setSpout(SPOUT_ID, spout, 1);
    EsTupleMapper tupleMapper = EsTestUtil.generateDefaultTupleMapper();
    EsConfig esConfig = new EsConfig(EsConstants.clusterName, new String[] { "localhost:9300" });
    builder.setBolt(BOLT_ID, new EsIndexBolt(esConfig, tupleMapper), 1).shuffleGrouping(SPOUT_ID);
    EsTestUtil.startEsNode();
    EsTestUtil.waitForSeconds(5);
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology(TOPOLOGY_NAME, config, builder.createTopology())) {
        EsTestUtil.waitForSeconds(20);
    }
    System.exit(0);
}
Also used : LocalCluster(org.apache.storm.LocalCluster) EsConfig(org.apache.storm.elasticsearch.common.EsConfig) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) EsTupleMapper(org.apache.storm.elasticsearch.common.EsTupleMapper) Config(org.apache.storm.Config) EsConfig(org.apache.storm.elasticsearch.common.EsConfig) 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