Search in sources :

Example 91 with Fields

use of backtype.storm.tuple.Fields in project jstorm by alibaba.

the class FastWordCountTransactionTimeWindowTopology method test.

public static void test() throws Exception {
    TransactionTopologyBuilder builder = new TransactionTopologyBuilder();
    if (isLocal) {
        conf.put("tuple.num.per.batch", 100);
        conf.put("transaction.scheduler.spout", false);
        conf.put("transaction.exactly.cache.type", "default");
        conf.put("transaction.topology", true);
    }
    int spoutParallelismHint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPOUT_PARALLELISM_HINT), 1);
    int splitParallelismHint = JStormUtils.parseInt(conf.get(TOPOLOGY_SPLIT_PARALLELISM_HINT), 1);
    int countParallelismHint = JStormUtils.parseInt(conf.get(TOPOLOGY_COUNT_PARALLELISM_HINT), 1);
    builder.setSpout("spout", new TxFastRandomSentenceSpout(), spoutParallelismHint);
    builder.setBolt("split", new SplitSentence(), splitParallelismHint).localOrShuffleGrouping("spout");
    builder.setBolt("count", new WordCount().timeWindow(Time.seconds(1L)).withStateSize(Time.hours(2)), countParallelismHint).fieldsGrouping("split", new Fields("word"));
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), true);
}
Also used : TransactionTopologyBuilder(com.alibaba.jstorm.transactional.TransactionTopologyBuilder) JStormHelper(com.alibaba.starter.utils.JStormHelper) Fields(backtype.storm.tuple.Fields)

Example 92 with Fields

use of backtype.storm.tuple.Fields in project jstorm by alibaba.

the class FastWordCountAccumulatedTimeWindowTopology method test.

public static void test(Config conf) throws Exception {
    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), 1);
    int count_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_COUNT_PARALLELISM_HINT), 1);
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new FastRandomSentenceSpout(), spout_Parallelism_hint);
    builder.setBolt("split", new SplitSentence(), split_Parallelism_hint).shuffleGrouping("spout");
    long windowSize = JStormUtils.parseLong(conf.get("window.size.sec"), 10);
    long stateWindowSize = JStormUtils.parseLong(conf.get("state.window.size.sec"), 60);
    builder.setBolt("count", new WordCount().timeWindow(Time.seconds(windowSize)).withStateSize(Time.seconds(stateWindowSize)), count_Parallelism_hint).fieldsGrouping("split", new Fields("word"));
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    boolean isLocal = true;
    if (conf.containsKey("storm.cluster.mode")) {
        isLocal = StormConfig.local_mode(conf);
    }
    // RUN_LONG_TIME = true
    JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal);
}
Also used : JStormHelper(com.alibaba.starter.utils.JStormHelper) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder)

Example 93 with Fields

use of backtype.storm.tuple.Fields in project jstorm by alibaba.

the class FastWordCountIngestionTimeWindowTopology method test.

public static void test() throws Exception {
    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), 1);
    int count_parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_COUNT_PARALLELISM_HINT), 1);
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new FastRandomSentenceSpout(), spout_parallelism_hint);
    builder.setBolt("split", new SplitSentence(), split_parallelism_hint).shuffleGrouping("spout");
    builder.setBolt("count", new WordCount().ingestionTimeWindow(Time.seconds(1L), Time.milliseconds(500L)).withStateSize(Time.minutes(10)), count_parallelism_hint).fieldsGrouping("split", new Fields("word"));
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), true);
}
Also used : JStormHelper(com.alibaba.starter.utils.JStormHelper) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder)

Example 94 with Fields

use of backtype.storm.tuple.Fields in project jstorm by alibaba.

the class FastWordCountWindowTopology method test.

public static void test() {
    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), 1);
    int count_Parallelism_hint = JStormUtils.parseInt(conf.get(TOPOLOGY_COUNT_PARALLELISM_HINT), 1);
    TopologyBuilder builder = new TopologyBuilder();
    boolean isLocalShuffle = JStormUtils.parseBoolean(conf.get("is.local.first.group"), false);
    builder.setSpout("spout", new FastRandomSentenceSpout(), spout_Parallelism_hint);
    if (isLocalShuffle)
        builder.setBolt("split", new SplitSentence(), split_Parallelism_hint).localFirstGrouping("spout");
    else
        builder.setBolt("split", new SplitSentence(), split_Parallelism_hint).shuffleGrouping("spout");
    // builder.setBolt("count", new WordCount().countWindow(20),
    // count_Parallelism_hint).fieldsGrouping("split", new Fields("word"));
    builder.setBolt("count", new WordCount().countWindow(20, 10), count_Parallelism_hint).fieldsGrouping("split", new Fields("word"));
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    try {
        JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JStormHelper(com.alibaba.starter.utils.JStormHelper) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder)

Example 95 with Fields

use of backtype.storm.tuple.Fields 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)130 TopologyBuilder (backtype.storm.topology.TopologyBuilder)41 Config (backtype.storm.Config)24 TridentTopology (storm.trident.TridentTopology)21 Map (java.util.Map)20 HashMap (java.util.HashMap)18 Test (org.junit.Test)17 JStormHelper (com.alibaba.starter.utils.JStormHelper)16 Values (backtype.storm.tuple.Values)15 ArrayList (java.util.ArrayList)13 LocalCluster (backtype.storm.LocalCluster)12 Stream (storm.trident.Stream)12 StreamInfo (backtype.storm.generated.StreamInfo)10 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)9 HashSet (java.util.HashSet)8 LocalDRPC (backtype.storm.LocalDRPC)7 TridentState (storm.trident.TridentState)7 Count (storm.trident.operation.builtin.Count)7 GroupedStream (storm.trident.fluent.GroupedStream)6 IAggregatableStream (storm.trident.fluent.IAggregatableStream)6