Search in sources :

Example 11 with Stream

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

the class TridentFileTopology 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(".txt");
    RecordFormat recordFormat = new DelimitedRecordFormat().withFields(hdfsFields);
    FileRotationPolicy rotationPolicy = new FileSizeRotationPolicy(5.0f, FileSizeRotationPolicy.Units.MB);
    HdfsState.Options options = new HdfsState.HdfsFileOptions().withFileNameFormat(fileNameFormat).withRecordFormat(recordFormat).withRotationPolicy(rotationPolicy).withFsUrl(hdfsUrl).withConfigKey("hdfs.config");
    StateFactory factory = new HdfsStateFactory().withOptions(options);
    TridentState state = stream.partitionPersist(factory, hdfsFields, new HdfsUpdater(), new Fields());
    return topology.build();
}
Also used : DelimitedRecordFormat(org.apache.storm.hdfs.trident.format.DelimitedRecordFormat) TridentState(org.apache.storm.trident.TridentState) DelimitedRecordFormat(org.apache.storm.hdfs.trident.format.DelimitedRecordFormat) RecordFormat(org.apache.storm.hdfs.trident.format.RecordFormat) 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) 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 12 with Stream

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

the class UserPersistenceTridentTopology method getTopology.

@Override
public StormTopology getTopology() {
    TridentTopology topology = new TridentTopology();
    JdbcState.Options options = new JdbcState.Options().withConnectionProvider(connectionProvider).withMapper(this.jdbcMapper).withJdbcLookupMapper(new SimpleJdbcLookupMapper(new Fields("dept_name"), Lists.newArrayList(new Column("user_id", Types.INTEGER)))).withTableName(TABLE_NAME).withSelectQuery(SELECT_QUERY);
    JdbcStateFactory jdbcStateFactory = new JdbcStateFactory(options);
    Stream stream = topology.newStream("userSpout", new UserSpout());
    TridentState state = topology.newStaticState(jdbcStateFactory);
    stream = stream.stateQuery(state, new Fields("user_id", "user_name", "create_date"), new JdbcQuery(), new Fields("dept_name"));
    stream.partitionPersist(jdbcStateFactory, new Fields("user_id", "user_name", "dept_name", "create_date"), new JdbcUpdater(), new Fields());
    return topology.build();
}
Also used : JdbcState(org.apache.storm.jdbc.trident.state.JdbcState) JdbcQuery(org.apache.storm.jdbc.trident.state.JdbcQuery) SimpleJdbcLookupMapper(org.apache.storm.jdbc.mapper.SimpleJdbcLookupMapper) UserSpout(org.apache.storm.jdbc.spout.UserSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Column(org.apache.storm.jdbc.common.Column) TridentState(org.apache.storm.trident.TridentState) JdbcStateFactory(org.apache.storm.jdbc.trident.state.JdbcStateFactory) Stream(org.apache.storm.trident.Stream) JdbcUpdater(org.apache.storm.jdbc.trident.state.JdbcUpdater)

Example 13 with Stream

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

the class TridentKafkaConsumerTopology method newTopology.

/**
 * Creates a new topology that prints inputs to stdout.
 * @param tridentSpout The spout to use
 */
public static StormTopology newTopology(ITridentDataSource tridentSpout) {
    final TridentTopology tridentTopology = new TridentTopology();
    final Stream spoutStream = tridentTopology.newStream("spout", tridentSpout).parallelismHint(2);
    spoutStream.each(spoutStream.getOutputFields(), new Debug(false));
    return tridentTopology.build();
}
Also used : TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) Debug(org.apache.storm.trident.operation.builtin.Debug)

Example 14 with Stream

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

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

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