Search in sources :

Example 16 with TridentTopology

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

the class OpaqueTridentEventCount method buildTopology.

@Override
protected StormTopology buildTopology(EventHubSpout eventHubSpout) {
    TridentTopology topology = new TridentTopology();
    OpaqueTridentEventHubSpout spout = new OpaqueTridentEventHubSpout(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) OpaqueTridentEventHubSpout(org.apache.storm.eventhubs.trident.OpaqueTridentEventHubSpout) TridentState(org.apache.storm.trident.TridentState) MemoryMapState(org.apache.storm.trident.testing.MemoryMapState) LoggingFilter(org.apache.storm.eventhubs.samples.TransactionalTridentEventCount.LoggingFilter) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count)

Example 17 with TridentTopology

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

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

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

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

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