Search in sources :

Example 6 with LocalCluster

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

the class AbstractUserTopology method execute.

public void execute(String[] args) throws Exception {
    if (args.length != 4 && args.length != 5) {
        System.out.println("Usage: " + this.getClass().getSimpleName() + " <dataSourceClassName> <dataSource.url> " + "<user> <password> [topology name]");
        System.exit(-1);
    }
    Map map = Maps.newHashMap();
    //com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    map.put("dataSourceClassName", args[0]);
    //jdbc:mysql://localhost/test
    map.put("dataSource.url", args[1]);
    //root
    map.put("dataSource.user", args[2]);
    if (args.length == 4) {
        //password
        map.put("dataSource.password", args[3]);
    }
    Config config = new Config();
    config.put(JDBC_CONF, map);
    ConnectionProvider connectionProvider = new HikariCPConnectionProvider(map);
    connectionProvider.prepare();
    int queryTimeoutSecs = 60;
    JdbcClient jdbcClient = new JdbcClient(connectionProvider, queryTimeoutSecs);
    for (String sql : setupSqls) {
        jdbcClient.executeSql(sql);
    }
    this.userSpout = new UserSpout();
    this.jdbcMapper = new SimpleJdbcMapper(TABLE_NAME, connectionProvider);
    connectionProvider.cleanup();
    Fields outputFields = new Fields("user_id", "user_name", "dept_name", "create_date");
    List<Column> queryParamColumns = Lists.newArrayList(new Column("user_id", Types.INTEGER));
    this.jdbcLookupMapper = new SimpleJdbcLookupMapper(outputFields, queryParamColumns);
    this.connectionProvider = new HikariCPConnectionProvider(map);
    if (args.length == 4) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", config, getTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    } else {
        StormSubmitter.submitTopology(args[4], config, getTopology());
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) UserSpout(org.apache.storm.jdbc.spout.UserSpout) Config(org.apache.storm.Config) JdbcClient(org.apache.storm.jdbc.common.JdbcClient) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) HikariCPConnectionProvider(org.apache.storm.jdbc.common.HikariCPConnectionProvider) ConnectionProvider(org.apache.storm.jdbc.common.ConnectionProvider) HikariCPConnectionProvider(org.apache.storm.jdbc.common.HikariCPConnectionProvider) SimpleJdbcLookupMapper(org.apache.storm.jdbc.mapper.SimpleJdbcLookupMapper) Fields(org.apache.storm.tuple.Fields) SimpleJdbcMapper(org.apache.storm.jdbc.mapper.SimpleJdbcMapper) Column(org.apache.storm.jdbc.common.Column) Map(java.util.Map)

Example 7 with LocalCluster

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

the class WordCountTridentRedisClusterMap method main.

public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.out.println("Usage: WordCountTrident 0(storm-local)|1(storm-cluster) 127.0.0.1:6379,127.0.0.1:6380");
        System.exit(1);
    }
    Integer flag = Integer.valueOf(args[0]);
    String redisHostPort = args[1];
    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(redisHostPort))) {
            Thread.sleep(60 * 1000);
        }
        System.exit(0);
    } else if (flag == 1) {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopology("test_wordCounter_for_redis", conf, buildTopology(redisHostPort));
    } else {
        System.out.println("Usage: WordCountTrident 0(storm-local)|1(storm-cluster) redis-host redis-port");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) Config(org.apache.storm.Config) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 8 with LocalCluster

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

the class SolrTopology method submitTopologyLocalCluster.

protected void submitTopologyLocalCluster(StormTopology topology, Config config) throws Exception {
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology("test", config, topology)) {
        Thread.sleep(10000);
        System.out.println("Killing topology per client's request");
    }
    System.exit(0);
}
Also used : LocalCluster(org.apache.storm.LocalCluster) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 9 with LocalCluster

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

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

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