Search in sources :

Example 1 with FixedBatchSpout

use of storm.trident.testing.FixedBatchSpout in project jstorm by alibaba.

the class TridentWindowingInmemoryStoreTopology method buildTopology.

public static StormTopology buildTopology(WindowsStoreFactory windowStore, WindowConfig windowConfig) throws Exception {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(windowConfig, windowStore, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("Received tuple: [{}]", input);
        }
    });
    return topology.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) Fields(backtype.storm.tuple.Fields) Consumer(storm.trident.operation.Consumer) TridentTopology(storm.trident.TridentTopology) CountAsAggregator(storm.trident.testing.CountAsAggregator) Values(backtype.storm.tuple.Values) Stream(storm.trident.Stream) Split(storm.trident.testing.Split) TridentTuple(storm.trident.tuple.TridentTuple)

Example 2 with FixedBatchSpout

use of storm.trident.testing.FixedBatchSpout in project jstorm by alibaba.

the class TridentTopologySource method getTopology.

public StormTopology getTopology(Config config) {
    this.spout = new FixedBatchSpout(new Fields("sentence"), 20, new Values("one two"), new Values("two three"), new Values("three four"), new Values("four five"), new Values("five six"));
    TridentTopology trident = new TridentTopology();
    trident.newStream("wordcount", spout).name("sentence").parallelismHint(1).shuffle().each(new Fields("sentence"), new Split(), new Fields("word")).parallelismHint(1).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(1);
    return trident.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) Values(backtype.storm.tuple.Values) Count(storm.trident.operation.builtin.Count)

Example 3 with FixedBatchSpout

use of storm.trident.testing.FixedBatchSpout in project storm-hbase by jrkinley.

the class HBaseTridentAggregateTopology method main.

/**
   * @param args
   * @throws InterruptedException
   */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) throws InterruptedException {
    List<Object> v0 = HBaseCountersBatchTopology.values.get(0).get(0);
    List<Object> v1 = HBaseCountersBatchTopology.values.get(0).get(1);
    List<Object> v2 = HBaseCountersBatchTopology.values.get(0).get(2);
    List<Object> v3 = HBaseCountersBatchTopology.values.get(0).get(3);
    List<Object> v4 = HBaseCountersBatchTopology.values.get(0).get(4);
    List<Object> v5 = HBaseCountersBatchTopology.values.get(1).get(0);
    List<Object> v6 = HBaseCountersBatchTopology.values.get(1).get(1);
    List<Object> v7 = HBaseCountersBatchTopology.values.get(1).get(2);
    List<Object> v8 = HBaseCountersBatchTopology.values.get(2).get(0);
    List<Object> v9 = HBaseCountersBatchTopology.values.get(2).get(1);
    List<Object> v10 = HBaseCountersBatchTopology.values.get(2).get(2);
    HBaseCountersBatchTopology.values.values();
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("shortid", "url", "user", "date"), 3, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10);
    spout.setCycle(false);
    TridentConfig config = new TridentConfig("shorturl", "shortid");
    config.setBatch(false);
    StateFactory state = HBaseAggregateState.transactional(config);
    TridentTopology topology = new TridentTopology();
    topology.newStream("spout", spout).each(new Fields("shortid", "date"), new DatePartitionFunction(), new Fields("cf", "cq")).project(new Fields("shortid", "cf", "cq")).groupBy(new Fields("shortid", "cf", "cq")).persistentAggregate(state, new Count(), new Fields("count"));
    Config conf = new Config();
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("hbase-trident-aggregate", conf, topology.build());
    Utils.sleep(5000);
    cluster.shutdown();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) LocalCluster(backtype.storm.LocalCluster) Fields(backtype.storm.tuple.Fields) StateFactory(storm.trident.state.StateFactory) TridentTopology(storm.trident.TridentTopology) Config(backtype.storm.Config) TridentConfig(backtype.storm.contrib.hbase.utils.TridentConfig) TridentConfig(backtype.storm.contrib.hbase.utils.TridentConfig) Count(storm.trident.operation.builtin.Count)

Example 4 with FixedBatchSpout

use of storm.trident.testing.FixedBatchSpout in project storm-hbase by jrkinley.

the class HBaseTridentValueTopology method main.

/**
   * @param args
   * @throws InterruptedException
   */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) throws InterruptedException {
    List<Object> v0 = HBaseCountersBatchTopology.values.get(0).get(0);
    List<Object> v1 = HBaseCountersBatchTopology.values.get(0).get(1);
    List<Object> v2 = HBaseCountersBatchTopology.values.get(0).get(2);
    List<Object> v3 = HBaseCountersBatchTopology.values.get(0).get(3);
    List<Object> v4 = HBaseCountersBatchTopology.values.get(0).get(4);
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("shortid", "url", "user", "date"), 3, v0, v1, v2, v3, v4);
    spout.setCycle(true);
    // Trident updater
    TridentConfig updateConfig = new TridentConfig("shorturl", "shortid");
    updateConfig.setBatch(false);
    updateConfig.addColumn("data", "url");
    updateConfig.addColumn("data", "user");
    updateConfig.addColumn("data", "date");
    TridentTopology topology = new TridentTopology();
    topology.newStream("shorturls", spout).partitionPersist(new HBaseValueFactory(updateConfig), new Fields("shortid", "url", "user", "date"), new HBaseValueUpdater());
    Config conf = new Config();
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("hbase-trident-updater", conf, topology.build());
    Utils.sleep(10000);
    cluster.shutdown();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) LocalCluster(backtype.storm.LocalCluster) Fields(backtype.storm.tuple.Fields) HBaseValueUpdater(backtype.storm.contrib.hbase.trident.HBaseValueUpdater) TridentTopology(storm.trident.TridentTopology) Config(backtype.storm.Config) TridentConfig(backtype.storm.contrib.hbase.utils.TridentConfig) HBaseValueFactory(backtype.storm.contrib.hbase.trident.HBaseValueFactory) TridentConfig(backtype.storm.contrib.hbase.utils.TridentConfig)

Example 5 with FixedBatchSpout

use of storm.trident.testing.FixedBatchSpout in project jstorm by alibaba.

the class TridentFastWordCount method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"), new Values("marry had a little lamb whos fleese was white as snow"), new Values("and every where that marry went the lamb was sure to go"), new Values("one two three four five six seven eight nine ten"), new Values("this is a test of the emergency broadcast system this is only a test"), new Values("peter piper picked a peck of pickeled peppers"), new Values("JStorm is a distributed and fault-tolerant realtime computation system."), new Values("Inspired by Apache Storm, JStorm has been completely rewritten in Java and provides many more enhanced features."), new Values("JStorm has been widely used in many enterprise environments and proved robust and stable."), new Values("JStorm provides a distributed programming framework very similar to Hadoop MapReduce."), new Values("The developer only needs to compose his/her own pipe-lined computation logic by implementing the JStorm API"), new Values(" which is fully compatible with Apache Storm API"), new Values("and submit the composed Topology to a working JStorm instance."), new Values("Similar to Hadoop MapReduce, JStorm computes on a DAG (directed acyclic graph)."), new Values("Different from Hadoop MapReduce, a JStorm topology runs 24 * 7"), new Values("the very nature of its continuity abd 100% in-memory architecture "), new Values("has been proved a particularly suitable solution for streaming data and real-time computation."), new Values("JStorm guarantees fault-tolerance."), new Values("Whenever a worker process crashes, "), new Values("the scheduler embedded in the JStorm instance immediately spawns a new worker process to take the place of the failed one."), new Values(" The Acking framework provided by JStorm guarantees that every single piece of data will be processed at least once."));
    spout.setCycle(true);
    int spout_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPOUT_PARALLELISM_HINT), 1);
    int split_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPLIT_PARALLELISM_HINT), 2);
    int count_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_COUNT_PARALLELISM_HINT), 2);
    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(spout_Parallelism_hint).each(new Fields("sentence"), new Split(), new Fields("word")).parallelismHint(split_Parallelism_hint).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(count_Parallelism_hint);
    return topology.build();
}
Also used : FixedBatchSpout(storm.trident.testing.FixedBatchSpout) Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) TridentState(storm.trident.TridentState) Values(backtype.storm.tuple.Values) Count(storm.trident.operation.builtin.Count)

Aggregations

Fields (backtype.storm.tuple.Fields)9 TridentTopology (storm.trident.TridentTopology)9 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)9 Values (backtype.storm.tuple.Values)5 Count (storm.trident.operation.builtin.Count)5 Stream (storm.trident.Stream)3 TridentState (storm.trident.TridentState)3 Config (backtype.storm.Config)2 LocalCluster (backtype.storm.LocalCluster)2 TridentConfig (backtype.storm.contrib.hbase.utils.TridentConfig)2 Consumer (storm.trident.operation.Consumer)2 Debug (storm.trident.operation.builtin.Debug)2 FilterNull (storm.trident.operation.builtin.FilterNull)2 MapGet (storm.trident.operation.builtin.MapGet)2 Sum (storm.trident.operation.builtin.Sum)2 TridentTuple (storm.trident.tuple.TridentTuple)2 HBaseValueFactory (backtype.storm.contrib.hbase.trident.HBaseValueFactory)1 HBaseValueUpdater (backtype.storm.contrib.hbase.trident.HBaseValueUpdater)1 StateFactory (storm.trident.state.StateFactory)1 CountAsAggregator (storm.trident.testing.CountAsAggregator)1