Search in sources :

Example 1 with StateFactory

use of org.apache.storm.trident.state.StateFactory in project storm by apache.

the class MapStateTest method nonTransactionalStateTest.

@Test
public void nonTransactionalStateTest() throws Exception {
    StateFactory factory = MapStateFactoryBuilder.nontransactional(getCassandraConfig()).withTable("words_ks", "words_table").withKeys("word").withJSONBinaryState("state").build();
    wordsTest(factory);
}
Also used : StateFactory(org.apache.storm.trident.state.StateFactory) Test(org.junit.Test)

Example 2 with StateFactory

use of org.apache.storm.trident.state.StateFactory in project storm by apache.

the class MapStateTest method transactionalStateTest.

@Test
public void transactionalStateTest() throws Exception {
    Map<String, Object> config = new HashMap();
    StateFactory factory = MapStateFactoryBuilder.transactional(getCassandraConfig()).withTable("words_ks", "words_table").withKeys("word").withJSONBinaryState("state").build();
    wordsTest(factory);
}
Also used : StateFactory(org.apache.storm.trident.state.StateFactory) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with StateFactory

use of org.apache.storm.trident.state.StateFactory in project storm by apache.

the class WordCountTridentRedisClusterMap method buildTopology.

public static StormTopology buildTopology(String redisHostPort) {
    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);
    Set<InetSocketAddress> nodes = new HashSet<InetSocketAddress>();
    for (String hostPort : redisHostPort.split(",")) {
        String[] hostPortSplit = hostPort.split(":");
        nodes.add(new InetSocketAddress(hostPortSplit[0], Integer.valueOf(hostPortSplit[1])));
    }
    JedisClusterConfig clusterConfig = new JedisClusterConfig.Builder().setNodes(nodes).build();
    RedisDataTypeDescription dataTypeDescription = new RedisDataTypeDescription(RedisDataTypeDescription.RedisDataType.HASH, "test");
    StateFactory factory = RedisClusterMapState.transactional(clusterConfig, dataTypeDescription);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    TridentState state = stream.groupBy(new Fields("word")).persistentAggregate(factory, new Fields("count"), new Sum(), new Fields("sum"));
    stream.stateQuery(state, new Fields("word"), new MapGet(), new Fields("sum")).each(new Fields("word", "sum"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : RedisDataTypeDescription(org.apache.storm.redis.common.mapper.RedisDataTypeDescription) TridentState(org.apache.storm.trident.TridentState) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) Values(org.apache.storm.tuple.Values) Sum(org.apache.storm.trident.operation.builtin.Sum) MapGet(org.apache.storm.trident.operation.builtin.MapGet) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) StateFactory(org.apache.storm.trident.state.StateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) HashSet(java.util.HashSet)

Example 4 with StateFactory

use of org.apache.storm.trident.state.StateFactory in project storm by apache.

the class WordCountTridentRedisMap method buildTopology.

public static StormTopology buildTopology(String redisHost, Integer redisPort) {
    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);
    JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost(redisHost).setPort(redisPort).build();
    RedisDataTypeDescription dataTypeDescription = new RedisDataTypeDescription(RedisDataTypeDescription.RedisDataType.HASH, "test");
    StateFactory factory = RedisMapState.transactional(poolConfig, dataTypeDescription);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    TridentState state = stream.groupBy(new Fields("word")).persistentAggregate(factory, new Fields("count"), new Sum(), new Fields("sum"));
    stream.stateQuery(state, new Fields("word"), new MapGet(), new Fields("sum")).each(new Fields("word", "sum"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : RedisDataTypeDescription(org.apache.storm.redis.common.mapper.RedisDataTypeDescription) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) Sum(org.apache.storm.trident.operation.builtin.Sum) MapGet(org.apache.storm.trident.operation.builtin.MapGet) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) StateFactory(org.apache.storm.trident.state.StateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream)

Example 5 with StateFactory

use of org.apache.storm.trident.state.StateFactory in project storm by apache.

the class WordCountTridentMap 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");
    MongoMapState.Options options = new MongoMapState.Options();
    options.url = url;
    options.collectionName = collectionName;
    options.mapper = mapper;
    QueryFilterCreator filterCreator = new SimpleQueryFilterCreator().withField("word");
    options.queryCreator = filterCreator;
    StateFactory factory = MongoMapState.transactional(options);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    TridentState state = stream.groupBy(new Fields("word")).persistentAggregate(factory, new Fields("count"), new Sum(), new Fields("sum"));
    stream.stateQuery(state, new Fields("word"), new MapGet(), new Fields("sum")).each(new Fields("word", "sum"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : MongoMapState(org.apache.storm.mongodb.trident.state.MongoMapState) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) Sum(org.apache.storm.trident.operation.builtin.Sum) MapGet(org.apache.storm.trident.operation.builtin.MapGet) SimpleQueryFilterCreator(org.apache.storm.mongodb.common.SimpleQueryFilterCreator) QueryFilterCreator(org.apache.storm.mongodb.common.QueryFilterCreator) SimpleQueryFilterCreator(org.apache.storm.mongodb.common.SimpleQueryFilterCreator) 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) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) SimpleMongoMapper(org.apache.storm.mongodb.common.mapper.SimpleMongoMapper)

Aggregations

StateFactory (org.apache.storm.trident.state.StateFactory)16 Fields (org.apache.storm.tuple.Fields)13 Stream (org.apache.storm.trident.Stream)12 TridentTopology (org.apache.storm.trident.TridentTopology)12 TridentState (org.apache.storm.trident.TridentState)9 Values (org.apache.storm.tuple.Values)8 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)6 MapGet (org.apache.storm.trident.operation.builtin.MapGet)3 Sum (org.apache.storm.trident.operation.builtin.Sum)3 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)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 MongoMapper (org.apache.storm.mongodb.common.mapper.MongoMapper)2 SimpleMongoMapper (org.apache.storm.mongodb.common.mapper.SimpleMongoMapper)2 RedisDataTypeDescription (org.apache.storm.redis.common.mapper.RedisDataTypeDescription)2