Search in sources :

Example 31 with TridentTopology

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

Example 32 with TridentTopology

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

the class WordCountTrident method buildTopology.

public static StormTopology buildTopology(String hbaseRoot) {
    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);
    TridentHBaseMapper tridentHBaseMapper = new SimpleTridentHBaseMapper().withColumnFamily("cf").withColumnFields(new Fields("word")).withCounterFields(new Fields("count")).withRowKeyField("word");
    HBaseValueMapper rowToStormValueMapper = new WordCountValueMapper();
    HBaseProjectionCriteria projectionCriteria = new HBaseProjectionCriteria();
    projectionCriteria.addColumn(new HBaseProjectionCriteria.ColumnMetaData("cf", "count"));
    HBaseState.Options options = new HBaseState.Options().withConfigKey(hbaseRoot).withDurability(Durability.SYNC_WAL).withMapper(tridentHBaseMapper).withProjectionCriteria(projectionCriteria).withRowToStormValueMapper(rowToStormValueMapper).withTableName("WordCount");
    StateFactory factory = new HBaseStateFactory(options);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new HBaseUpdater(), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new HBaseQuery(), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : HBaseUpdater(org.apache.storm.hbase.trident.state.HBaseUpdater) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) HBaseProjectionCriteria(org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria) WordCountValueMapper(org.apache.storm.hbase.topology.WordCountValueMapper) HBaseValueMapper(org.apache.storm.hbase.bolt.mapper.HBaseValueMapper) HBaseStateFactory(org.apache.storm.hbase.trident.state.HBaseStateFactory) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) SimpleTridentHBaseMapper(org.apache.storm.hbase.trident.mapper.SimpleTridentHBaseMapper) StateFactory(org.apache.storm.trident.state.StateFactory) HBaseStateFactory(org.apache.storm.hbase.trident.state.HBaseStateFactory) HBaseState(org.apache.storm.hbase.trident.state.HBaseState) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) SimpleTridentHBaseMapper(org.apache.storm.hbase.trident.mapper.SimpleTridentHBaseMapper) TridentHBaseMapper(org.apache.storm.hbase.trident.mapper.TridentHBaseMapper) HBaseQuery(org.apache.storm.hbase.trident.state.HBaseQuery)

Example 33 with TridentTopology

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

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

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

Aggregations

TridentTopology (org.apache.storm.trident.TridentTopology)44 Fields (org.apache.storm.tuple.Fields)38 Stream (org.apache.storm.trident.Stream)25 Values (org.apache.storm.tuple.Values)25 TridentState (org.apache.storm.trident.TridentState)22 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)19 StateFactory (org.apache.storm.trident.state.StateFactory)12 MapGet (org.apache.storm.trident.operation.builtin.MapGet)10 Sum (org.apache.storm.trident.operation.builtin.Sum)10 HashMap (java.util.HashMap)9 Count (org.apache.storm.trident.operation.builtin.Count)8 AbstractTridentProcessor (org.apache.storm.sql.AbstractTridentProcessor)7 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)7 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)7 TestUtils (org.apache.storm.sql.TestUtils)6 MockState.getCollectedValues (org.apache.storm.sql.TestUtils.MockState.getCollectedValues)6 Consumer (org.apache.storm.trident.operation.Consumer)6 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)6 Test (org.junit.Test)6 FilterNull (org.apache.storm.trident.operation.builtin.FilterNull)5