Search in sources :

Example 6 with TridentTopology

use of storm.trident.TridentTopology 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 7 with TridentTopology

use of storm.trident.TridentTopology in project jstorm by alibaba.

the class TridentMinMaxOfDevicesTopology method buildDevicesTopology.

/**
 * Creates a topology with device-id and count (which are whole numbers) as
 * tuple fields in a stream and it finally generates result stream based on
 * min amd max with device-id and count values.
 */
public static StormTopology buildDevicesTopology() {
    String deviceID = "device-id";
    String count = "count";
    Fields allFields = new Fields(deviceID, count);
    RandomNumberGeneratorSpout spout = new RandomNumberGeneratorSpout(allFields, 10, 1000);
    TridentTopology topology = new TridentTopology();
    Stream devicesStream = topology.newStream("devicegen-spout", spout).each(allFields, new Debug("##### devices"));
    devicesStream.minBy(deviceID).each(allFields, new Debug("#### device with min id"));
    devicesStream.maxBy(count).each(allFields, new Debug("#### device with max count"));
    return topology.build();
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) Stream(storm.trident.Stream) RandomNumberGeneratorSpout(org.apache.storm.starter.spout.RandomNumberGeneratorSpout) Debug(storm.trident.operation.builtin.Debug)

Example 8 with TridentTopology

use of storm.trident.TridentTopology in project jstorm by alibaba.

the class TridentReach method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    TridentTopology topology = new TridentTopology();
    TridentState urlToTweeters = topology.newStaticState(new StaticSingleKeyMapState.Factory(TWEETERS_DB));
    TridentState tweetersToFollowers = topology.newStaticState(new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));
    topology.newDRPCStream("reach", drpc).stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields("tweeters")).each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter")).shuffle().stateQuery(tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers")).each(new Fields("followers"), new ExpandList(), new Fields("follower")).groupBy(new Fields("follower")).aggregate(new One(), new Fields("one")).aggregate(new Fields("one"), new Sum(), new Fields("reach"));
    return topology.build();
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) TridentState(storm.trident.TridentState) MapGet(storm.trident.operation.builtin.MapGet) Sum(storm.trident.operation.builtin.Sum)

Example 9 with TridentTopology

use of storm.trident.TridentTopology in project jstorm by alibaba.

the class TestTridentTopology method buildTopology.

public static StormTopology buildTopology() {
    TridentTopology topology = new TridentTopology();
    topology.newStream("MetaSpout", new MetaSpout()).each(new Fields("MetaTuple"), new MsgPrint(), new Fields());
    return topology.build();
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) MetaSpout(com.alibaba.aloha.meta.MetaSpout)

Example 10 with TridentTopology

use of storm.trident.TridentTopology 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)

Aggregations

Fields (backtype.storm.tuple.Fields)21 TridentTopology (storm.trident.TridentTopology)21 Values (backtype.storm.tuple.Values)13 Stream (storm.trident.Stream)10 Test (org.junit.Test)9 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)9 HashMap (java.util.HashMap)7 Map (java.util.Map)7 TridentState (storm.trident.TridentState)7 Count (storm.trident.operation.builtin.Count)7 MapGet (storm.trident.operation.builtin.MapGet)6 Sum (storm.trident.operation.builtin.Sum)6 Debug (storm.trident.operation.builtin.Debug)5 CountAsAggregator (storm.trident.testing.CountAsAggregator)5 Split (storm.trident.testing.Split)5 FilterNull (storm.trident.operation.builtin.FilterNull)4 InMemoryWindowsStoreFactory (storm.trident.windowing.InMemoryWindowsStoreFactory)4 WindowsStoreFactory (storm.trident.windowing.WindowsStoreFactory)4 LocalDRPC (backtype.storm.LocalDRPC)3 JStormUnitTestDRPCValidator (com.jstorm.example.unittests.utils.JStormUnitTestDRPCValidator)3