Search in sources :

Example 1 with FileSizeRotationPolicy

use of org.apache.storm.hdfs.trident.rotation.FileSizeRotationPolicy 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 : TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) FileRotationPolicy(org.apache.storm.hdfs.trident.rotation.FileRotationPolicy) 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 2 with FileSizeRotationPolicy

use of org.apache.storm.hdfs.trident.rotation.FileSizeRotationPolicy 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) FileRotationPolicy(org.apache.storm.hdfs.trident.rotation.FileRotationPolicy) 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 3 with FileSizeRotationPolicy

use of org.apache.storm.hdfs.trident.rotation.FileSizeRotationPolicy in project storm by apache.

the class HdfsStateTest method createHdfsState.

private HdfsState createHdfsState() {
    Fields hdfsFields = new Fields("f1");
    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("file://" + TEST_OUT_DIR);
    Map<String, String> conf = new HashMap<>();
    conf.put(Config.TOPOLOGY_NAME, TEST_TOPOLOGY_NAME);
    HdfsState state = new HdfsState(options);
    state.prepare(conf, null, 0, 1);
    return state;
}
Also used : Fields(org.apache.storm.tuple.Fields) DelimitedRecordFormat(org.apache.storm.hdfs.trident.format.DelimitedRecordFormat) HashMap(java.util.HashMap) DelimitedRecordFormat(org.apache.storm.hdfs.trident.format.DelimitedRecordFormat) RecordFormat(org.apache.storm.hdfs.trident.format.RecordFormat) FileRotationPolicy(org.apache.storm.hdfs.trident.rotation.FileRotationPolicy) FileSizeRotationPolicy(org.apache.storm.hdfs.trident.rotation.FileSizeRotationPolicy)

Aggregations

FileRotationPolicy (org.apache.storm.hdfs.trident.rotation.FileRotationPolicy)3 FileSizeRotationPolicy (org.apache.storm.hdfs.trident.rotation.FileSizeRotationPolicy)3 Fields (org.apache.storm.tuple.Fields)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Stream (org.apache.storm.trident.Stream)2 TridentState (org.apache.storm.trident.TridentState)2 TridentTopology (org.apache.storm.trident.TridentTopology)2 StateFactory (org.apache.storm.trident.state.StateFactory)2 Values (org.apache.storm.tuple.Values)2 HashMap (java.util.HashMap)1 MoveFileAction (org.apache.storm.hdfs.common.rotation.MoveFileAction)1 DelimitedRecordFormat (org.apache.storm.hdfs.trident.format.DelimitedRecordFormat)1 RecordFormat (org.apache.storm.hdfs.trident.format.RecordFormat)1