Search in sources :

Example 11 with TridentState

use of org.apache.storm.trident.TridentState in project storm by apache.

the class TridentEsTopology method main.

/**
 * The example's main method.
 * @param args the command line arguments
 * @throws AlreadyAliveException if the topology is already started
 * @throws InvalidTopologyException if the topology is invalid
 * @throws AuthorizationException if the topology authorization fails
 */
public static void main(final String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException {
    int batchSize = BATCH_SIZE_DEFAULT;
    FixedBatchSpout spout = new FixedBatchSpout(batchSize);
    spout.cycle = true;
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout", spout);
    EsConfig esConfig = new EsConfig("http://localhost:9300");
    Fields esFields = new Fields("index", "type", "source");
    EsTupleMapper tupleMapper = EsTestUtil.generateDefaultTupleMapper();
    StateFactory factory = new EsStateFactory(esConfig, tupleMapper);
    TridentState state = stream.partitionPersist(factory, esFields, new EsUpdater(), new Fields());
    EsTestUtil.startEsNode();
    EsTestUtil.waitForSeconds(EsConstants.WAIT_DEFAULT_SECS);
    StormSubmitter.submitTopology(TOPOLOGY_NAME, new Config(), topology.build());
}
Also used : EsConfig(org.apache.storm.elasticsearch.common.EsConfig) Fields(org.apache.storm.tuple.Fields) StateFactory(org.apache.storm.trident.state.StateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) EsTupleMapper(org.apache.storm.elasticsearch.common.EsTupleMapper) TridentState(org.apache.storm.trident.TridentState) Config(org.apache.storm.Config) EsConfig(org.apache.storm.elasticsearch.common.EsConfig) Stream(org.apache.storm.trident.Stream)

Example 12 with TridentState

use of org.apache.storm.trident.TridentState in project storm by apache.

the class WordCountTrident method buildTopology.

public static StormTopology buildTopology(String url, String collectionName) {
    Fields fields = new Fields("word", "count");
    FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
    spout.setCycle(true);
    MongoMapper mapper = new SimpleMongoMapper().withFields("word", "count");
    MongoState.Options options = new MongoState.Options().withUrl(url).withCollectionName(collectionName).withMapper(mapper);
    StateFactory factory = new MongoStateFactory(options);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new MongoStateUpdater(), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new MongoStateQuery(), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : MongoState(org.apache.storm.mongodb.trident.state.MongoState) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) SimpleMongoMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoMapper) MongoMapper(org.apache.storm.mongodb.common.mapper.MongoMapper) StateFactory(org.apache.storm.trident.state.StateFactory) MongoStateFactory(org.apache.storm.mongodb.trident.state.MongoStateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) MongoStateFactory(org.apache.storm.mongodb.trident.state.MongoStateFactory) Stream(org.apache.storm.trident.Stream) SimpleMongoMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoMapper) MongoStateUpdater(org.apache.storm.mongodb.trident.state.MongoStateUpdater) MongoStateQuery(org.apache.storm.mongodb.trident.state.MongoStateQuery)

Example 13 with TridentState

use of org.apache.storm.trident.TridentState in project storm by apache.

the class TridentMapExample method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("word"), 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();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).flatMap(split).map(toUpper, new Fields("uppercased")).filter(theFilter).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            System.out.println(input.getString(0));
        }
    }).groupBy(new Fields("uppercased")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(16);
    topology.newDRPCStream("words", drpc).flatMap(split, new Fields("word")).groupBy(new Fields("word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).filter(new FilterNull()).aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) FilterNull(org.apache.storm.trident.operation.builtin.FilterNull) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 14 with TridentState

use of org.apache.storm.trident.TridentState in project storm by apache.

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(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Sum(org.apache.storm.trident.operation.builtin.Sum)

Example 15 with TridentState

use of org.apache.storm.trident.TridentState in project storm by apache.

the class TransactionalTridentEventCount method buildTopology.

@Override
protected StormTopology buildTopology(EventHubSpout eventHubSpout) {
    TridentTopology topology = new TridentTopology();
    TransactionalTridentEventHubSpout spout = new TransactionalTridentEventHubSpout(spoutConfig);
    TridentState state = topology.newStream("stream-" + spoutConfig.getTopologyName(), spout).parallelismHint(spoutConfig.getPartitionCount()).aggregate(new Count(), new Fields("partial-count")).persistentAggregate(new MemoryMapState.Factory(), new Fields("partial-count"), new Sum(), new Fields("count"));
    state.newValuesStream().each(new Fields("count"), new LoggingFilter("got count: ", 10000));
    return topology.build();
}
Also used : Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) MemoryMapState(org.apache.storm.trident.testing.MemoryMapState) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) TransactionalTridentEventHubSpout(org.apache.storm.eventhubs.trident.TransactionalTridentEventHubSpout)

Aggregations

TridentState (org.apache.storm.trident.TridentState)22 TridentTopology (org.apache.storm.trident.TridentTopology)22 Fields (org.apache.storm.tuple.Fields)22 Values (org.apache.storm.tuple.Values)14 Stream (org.apache.storm.trident.Stream)13 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)12 MapGet (org.apache.storm.trident.operation.builtin.MapGet)10 Sum (org.apache.storm.trident.operation.builtin.Sum)10 StateFactory (org.apache.storm.trident.state.StateFactory)9 Count (org.apache.storm.trident.operation.builtin.Count)7 FilterNull (org.apache.storm.trident.operation.builtin.FilterNull)5 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 HashSet (java.util.HashSet)2 DefaultFileNameFormat (org.apache.storm.hdfs.trident.format.DefaultFileNameFormat)2 FileNameFormat (org.apache.storm.hdfs.trident.format.FileNameFormat)2 FileRotationPolicy (org.apache.storm.hdfs.trident.rotation.FileRotationPolicy)2 FileSizeRotationPolicy (org.apache.storm.hdfs.trident.rotation.FileSizeRotationPolicy)2 Column (org.apache.storm.jdbc.common.Column)2