Search in sources :

Example 66 with LocalCluster

use of org.apache.storm.LocalCluster 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 67 with LocalCluster

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

the class BasicDRPCTopology method main.

public static void main(String[] args) throws Exception {
    LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("exclamation");
    builder.addBolt(new ExclaimBolt(), 3);
    Config conf = new Config();
    if (args == null || args.length == 0) {
        try (LocalDRPC drpc = new LocalDRPC();
            LocalCluster cluster = new LocalCluster()) {
            cluster.submitTopology("drpc-demo", conf, builder.createLocalTopology(drpc));
            for (String word : new String[] { "hello", "goodbye" }) {
                System.out.println("Result for \"" + word + "\": " + drpc.execute("exclamation", word));
            }
            Thread.sleep(10000);
        }
    } else {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createRemoteTopology());
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) LocalDRPC(org.apache.storm.LocalDRPC) LinearDRPCTopologyBuilder(org.apache.storm.drpc.LinearDRPCTopologyBuilder)

Example 68 with LocalCluster

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

the class WordCountTridentMap method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    conf.setMaxSpoutPending(5);
    if (args.length == 2) {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("wordCounter", conf, buildTopology(args[0], args[1]));
        Thread.sleep(60 * 1000);
        cluster.killTopology("wordCounter");
        cluster.shutdown();
        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)

Example 69 with LocalCluster

use of org.apache.storm.LocalCluster 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 70 with LocalCluster

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

the class JpmmlRunnerTestTopology method submitTopologyLocalCluster.

private void submitTopologyLocalCluster(StormTopology topology, Config config) throws Exception {
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology(tplgyName, config, topology);
    stopWaitingForInput();
}
Also used : LocalCluster(org.apache.storm.LocalCluster)

Aggregations

LocalCluster (org.apache.storm.LocalCluster)79 Config (org.apache.storm.Config)71 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)52 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)28 Fields (org.apache.storm.tuple.Fields)22 Map (java.util.Map)14 StreamBuilder (org.apache.storm.streams.StreamBuilder)9 HashMap (java.util.HashMap)7 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)7 LocalDRPC (org.apache.storm.LocalDRPC)6 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)6 TestWordSpout (org.apache.storm.testing.TestWordSpout)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 StormSubmitter (org.apache.storm.StormSubmitter)4 StormTopology (org.apache.storm.generated.StormTopology)4 ValueMapper (org.apache.storm.streams.operations.mappers.ValueMapper)4 TopologyContext (org.apache.storm.task.TopologyContext)4 Utils (org.apache.storm.utils.Utils)4 Yaml (org.yaml.snakeyaml.Yaml)4