Search in sources :

Example 91 with TopologyBuilder

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

the class DumpToHBaseTopology method main.

/**
 * HBase Data Dump to Another HBase Table 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("dumpBolt", new DumpToHBaseBolt(), 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 : DumpToHBaseBolt(ypf412.storm.bolt.DumpToHBaseBolt) 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)

Example 92 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project visitante by pranab.

the class UniqueVisitorTopology method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        throw new IllegalArgumentException("Need two arguments: topology name and config file path");
    }
    String topologyName = args[0];
    String configFilePath = args[1];
    Config conf = RealtimeUtil.buildStormConfig(configFilePath);
    boolean debugOn = ConfigUtility.getBoolean(conf, "debug.on", false);
    System.out.println("config file:" + configFilePath + " debugOn:" + debugOn);
    conf.put(Config.TOPOLOGY_DEBUG, debugOn);
    // spout
    TopologyBuilder builder = new TopologyBuilder();
    int spoutThreads = ConfigUtility.getInt(conf, "spout.threads", 1);
    UniqueVisitorSpout spout = new UniqueVisitorSpout();
    spout.withTupleFields(PART_ID, USER_ID);
    builder.setSpout("unqueVisitorSpout", spout, spoutThreads);
    // unique count bolt
    int uniqueCountTickFreqInSec = ConfigUtility.getInt(conf, "unique.user.tick.freq.sec", 1);
    UniqueVisitorCounterBolt uniqueCountBolt = new UniqueVisitorCounterBolt(uniqueCountTickFreqInSec);
    uniqueCountBolt.withTupleFields(BOLT_ID, UNIQUE_COUNT);
    int boltThreads = ConfigUtility.getInt(conf, "unique.count.bolt.threads", 1);
    builder.setBolt("uniqueCountBolt", uniqueCountBolt, boltThreads).fieldsGrouping("unqueVisitorSpout", new Fields(PART_ID));
    // unique count aggregation bolt
    UniqueVisitorAggregatorBolt uniqueCountAggrBolt = new UniqueVisitorAggregatorBolt();
    boltThreads = ConfigUtility.getInt(conf, "unique.count.aggr.bolt.threads", 1);
    builder.setBolt("uniqueCountAggrBolt", uniqueCountAggrBolt, boltThreads).shuffleGrouping("uniqueCountBolt");
    // submit
    RealtimeUtil.submitStormTopology(topologyName, conf, builder);
}
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