Search in sources :

Example 21 with Stream

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

the class TridentSequenceTopology method buildTopology.

public static StormTopology buildTopology(String hdfsUrl) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence", "key"), 1000, new Values("the cow jumped over the moon", 1L), new Values("the man went to the store and bought some candy", 2L), new Values("four score and seven years ago", 3L), new Values("how many apples can you eat", 4L), new Values("to be or not to be the person", 5L));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    Fields hdfsFields = new Fields("sentence", "key");
    FileNameFormat fileNameFormat = new DefaultFileNameFormat().withPath("/tmp/trident").withPrefix("trident").withExtension(".seq");
    FileRotationPolicy rotationPolicy = new FileSizeRotationPolicy(5.0f, FileSizeRotationPolicy.Units.MB);
    HdfsState.Options seqOpts = new HdfsState.SequenceFileOptions().withFileNameFormat(fileNameFormat).withSequenceFormat(new DefaultSequenceFormat("key", "sentence")).withRotationPolicy(rotationPolicy).withFsUrl(hdfsUrl).withConfigKey("hdfs.config").addRotationAction(new MoveFileAction().toDestination("/tmp/dest2/"));
    StateFactory factory = new HdfsStateFactory().withOptions(seqOpts);
    TridentState state = stream.partitionPersist(factory, hdfsFields, new HdfsUpdater(), new Fields());
    return topology.build();
}
Also used : TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) FileNameFormat(org.apache.storm.hdfs.trident.format.FileNameFormat) DefaultFileNameFormat(org.apache.storm.hdfs.trident.format.DefaultFileNameFormat) FileRotationPolicy(org.apache.storm.hdfs.trident.rotation.FileRotationPolicy) DefaultFileNameFormat(org.apache.storm.hdfs.trident.format.DefaultFileNameFormat) DefaultSequenceFormat(org.apache.storm.hdfs.trident.format.DefaultSequenceFormat) MoveFileAction(org.apache.storm.hdfs.common.rotation.MoveFileAction) Fields(org.apache.storm.tuple.Fields) StateFactory(org.apache.storm.trident.state.StateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) FileInputStream(java.io.FileInputStream) Stream(org.apache.storm.trident.Stream) InputStream(java.io.InputStream) FileSizeRotationPolicy(org.apache.storm.hdfs.trident.rotation.FileSizeRotationPolicy)

Example 22 with Stream

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

the class TridentHiveTopology method buildTopology.

public static StormTopology buildTopology(String metaStoreUri, String dbName, String tblName, Object keytab, Object principal) {
    int batchSize = 100;
    FixedBatchSpout spout = new FixedBatchSpout(batchSize);
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("hiveTridentspout1", spout);
    String[] partNames = { "city", "state" };
    String[] colNames = { "id", "name", "phone", "street" };
    Fields hiveFields = new Fields("id", "name", "phone", "street", "city", "state");
    DelimitedRecordHiveMapper mapper = new DelimitedRecordHiveMapper().withColumnFields(new Fields(colNames)).withPartitionFields(new Fields(partNames));
    HiveOptions hiveOptions;
    if (keytab != null && principal != null) {
        hiveOptions = new HiveOptions(metaStoreUri, dbName, tblName, mapper).withTxnsPerBatch(10).withBatchSize(batchSize).withIdleTimeout(10).withCallTimeout(30000).withKerberosKeytab((String) keytab).withKerberosPrincipal((String) principal);
    } else {
        hiveOptions = new HiveOptions(metaStoreUri, dbName, tblName, mapper).withTxnsPerBatch(10).withBatchSize(batchSize).withCallTimeout(30000).withIdleTimeout(10);
    }
    StateFactory factory = new HiveStateFactory().withOptions(hiveOptions);
    TridentState state = stream.partitionPersist(factory, hiveFields, new HiveUpdater(), new Fields());
    return topology.build();
}
Also used : TridentState(org.apache.storm.trident.TridentState) DelimitedRecordHiveMapper(org.apache.storm.hive.bolt.mapper.DelimitedRecordHiveMapper) 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) HiveOptions(org.apache.storm.hive.common.HiveOptions)

Example 23 with Stream

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

the class WordCountTridentRedis 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();
    RedisStoreMapper storeMapper = new WordCountStoreMapper();
    RedisLookupMapper lookupMapper = new WordCountLookupMapper();
    RedisState.Factory factory = new RedisState.Factory(poolConfig);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new RedisStateUpdater(storeMapper).withExpire(86400000), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new RedisStateQuerier(lookupMapper), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : TridentState(org.apache.storm.trident.TridentState) RedisStateQuerier(org.apache.storm.redis.trident.state.RedisStateQuerier) Values(org.apache.storm.tuple.Values) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) RedisStateUpdater(org.apache.storm.redis.trident.state.RedisStateUpdater) RedisState(org.apache.storm.redis.trident.state.RedisState) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) Stream(org.apache.storm.trident.Stream) RedisLookupMapper(org.apache.storm.redis.common.mapper.RedisLookupMapper)

Example 24 with Stream

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

the class WordCountTridentRedisCluster 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();
    RedisStoreMapper storeMapper = new WordCountStoreMapper();
    RedisLookupMapper lookupMapper = new WordCountLookupMapper();
    RedisClusterState.Factory factory = new RedisClusterState.Factory(clusterConfig);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new RedisClusterStateUpdater(storeMapper).withExpire(86400000), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new RedisClusterStateQuerier(lookupMapper), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : RedisClusterStateUpdater(org.apache.storm.redis.trident.state.RedisClusterStateUpdater) TridentState(org.apache.storm.trident.TridentState) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) RedisClusterState(org.apache.storm.redis.trident.state.RedisClusterState) Values(org.apache.storm.tuple.Values) RedisClusterStateQuerier(org.apache.storm.redis.trident.state.RedisClusterStateQuerier) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) Stream(org.apache.storm.trident.Stream) RedisLookupMapper(org.apache.storm.redis.common.mapper.RedisLookupMapper) HashSet(java.util.HashSet)

Example 25 with Stream

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

the class SolrJsonTridentTopology method getTopology.

@Override
protected StormTopology getTopology() throws IOException {
    final TridentTopology topology = new TridentTopology();
    final SolrJsonSpout spout = new SolrJsonSpout();
    final Stream stream = topology.newStream("SolrJsonSpout", spout);
    final StateFactory solrStateFactory = new SolrStateFactory(getSolrConfig(), getSolrMapper());
    stream.partitionPersist(solrStateFactory, spout.getOutputFields(), new SolrUpdater(), new Fields());
    return topology.build();
}
Also used : StateFactory(org.apache.storm.trident.state.StateFactory) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) SolrJsonSpout(org.apache.storm.solr.spout.SolrJsonSpout) Stream(org.apache.storm.trident.Stream)

Aggregations

Stream (org.apache.storm.trident.Stream)30 Fields (org.apache.storm.tuple.Fields)27 TridentTopology (org.apache.storm.trident.TridentTopology)25 TridentState (org.apache.storm.trident.TridentState)13 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)13 Values (org.apache.storm.tuple.Values)13 StateFactory (org.apache.storm.trident.state.StateFactory)12 RelNode (org.apache.calcite.rel.RelNode)4 Consumer (org.apache.storm.trident.operation.Consumer)4 Debug (org.apache.storm.trident.operation.builtin.Debug)4 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)4 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RexNode (org.apache.calcite.rex.RexNode)3 Config (org.apache.storm.Config)3 MapGet (org.apache.storm.trident.operation.builtin.MapGet)3 Sum (org.apache.storm.trident.operation.builtin.Sum)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 HashSet (java.util.HashSet)2