Search in sources :

Example 1 with VerifyAndEnrichBolt

use of org.apache.flink.storm.split.operators.VerifyAndEnrichBolt in project flink by apache.

the class SpoutSplitExample method main.

// *************************************************************************
// PROGRAM
// *************************************************************************
public static void main(final String[] args) throws Exception {
    boolean useFile = SpoutSplitExample.parseParameters(args);
    // set up the execution environment
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    String[] rawOutputs = new String[] { RandomSpout.EVEN_STREAM, RandomSpout.ODD_STREAM };
    final DataStream<SplitStreamType<Integer>> numbers = env.addSource(new SpoutWrapper<SplitStreamType<Integer>>(new RandomSpout(true, seed), rawOutputs, 1000), TypeExtractor.getForObject(new SplitStreamType<Integer>()));
    SplitStream<SplitStreamType<Integer>> splitStream = numbers.split(new StormStreamSelector<Integer>());
    DataStream<SplitStreamType<Integer>> evenStream = splitStream.select(RandomSpout.EVEN_STREAM);
    DataStream<SplitStreamType<Integer>> oddStream = splitStream.select(RandomSpout.ODD_STREAM);
    DataStream<Tuple2<String, Integer>> evenResult = evenStream.map(new SplitStreamMapper<Integer>()).returns(Integer.class).map(new Enrich(true));
    DataStream<Tuple2<String, Integer>> oddResult = oddStream.map(new SplitStreamMapper<Integer>()).transform("oddBolt", TypeExtractor.getForObject(new Tuple2<String, Integer>("", 0)), new BoltWrapper<Integer, Tuple2<String, Integer>>(new VerifyAndEnrichBolt(false)));
    if (useFile) {
        evenResult.writeAsText(outputPath + "/even");
        oddResult.writeAsText(outputPath + "/odd");
    } else {
        evenResult.print();
        oddResult.print();
    }
    // execute program
    env.execute("Spout split stream example");
}
Also used : RandomSpout(org.apache.flink.storm.split.operators.RandomSpout) Tuple2(org.apache.flink.api.java.tuple.Tuple2) SplitStreamMapper(org.apache.flink.storm.util.SplitStreamMapper) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) VerifyAndEnrichBolt(org.apache.flink.storm.split.operators.VerifyAndEnrichBolt) SplitStreamType(org.apache.flink.storm.util.SplitStreamType)

Example 2 with VerifyAndEnrichBolt

use of org.apache.flink.storm.split.operators.VerifyAndEnrichBolt in project flink by apache.

the class SplitBoltTopology method buildTopology.

public static TopologyBuilder buildTopology() {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(spoutId, new RandomSpout(false, seed));
    builder.setBolt(boltId, new SplitBolt()).shuffleGrouping(spoutId);
    builder.setBolt(evenVerifierId, new VerifyAndEnrichBolt(true)).shuffleGrouping(boltId, SplitBolt.EVEN_STREAM);
    builder.setBolt(oddVerifierId, new VerifyAndEnrichBolt(false)).shuffleGrouping(boltId, SplitBolt.ODD_STREAM);
    // emit result
    if (outputPath != null) {
        // read the text file from given input path
        final String[] tokens = outputPath.split(":");
        final String outputFile = tokens[tokens.length - 1];
        builder.setBolt(sinkId, new BoltFileSink(outputFile, formatter)).shuffleGrouping(evenVerifierId).shuffleGrouping(oddVerifierId);
    } else {
        builder.setBolt(sinkId, new BoltPrintSink(formatter), 4).shuffleGrouping(evenVerifierId).shuffleGrouping(oddVerifierId);
    }
    return builder;
}
Also used : RandomSpout(org.apache.flink.storm.split.operators.RandomSpout) BoltFileSink(org.apache.flink.storm.util.BoltFileSink) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) VerifyAndEnrichBolt(org.apache.flink.storm.split.operators.VerifyAndEnrichBolt) BoltPrintSink(org.apache.flink.storm.util.BoltPrintSink)

Example 3 with VerifyAndEnrichBolt

use of org.apache.flink.storm.split.operators.VerifyAndEnrichBolt in project flink by apache.

the class SplitSpoutTopology method buildTopology.

public static TopologyBuilder buildTopology() {
    final TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(spoutId, new RandomSpout(true, seed));
    builder.setBolt(evenVerifierId, new VerifyAndEnrichBolt(true)).shuffleGrouping(spoutId, RandomSpout.EVEN_STREAM);
    builder.setBolt(oddVerifierId, new VerifyAndEnrichBolt(false)).shuffleGrouping(spoutId, RandomSpout.ODD_STREAM);
    // emit result
    if (outputPath != null) {
        // read the text file from given input path
        final String[] tokens = outputPath.split(":");
        final String outputFile = tokens[tokens.length - 1];
        builder.setBolt(sinkId, new BoltFileSink(outputFile, formatter)).shuffleGrouping(evenVerifierId).shuffleGrouping(oddVerifierId);
    } else {
        builder.setBolt(sinkId, new BoltPrintSink(formatter), 4).shuffleGrouping(evenVerifierId).shuffleGrouping(oddVerifierId);
    }
    return builder;
}
Also used : RandomSpout(org.apache.flink.storm.split.operators.RandomSpout) BoltFileSink(org.apache.flink.storm.util.BoltFileSink) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) VerifyAndEnrichBolt(org.apache.flink.storm.split.operators.VerifyAndEnrichBolt) BoltPrintSink(org.apache.flink.storm.util.BoltPrintSink)

Aggregations

RandomSpout (org.apache.flink.storm.split.operators.RandomSpout)3 VerifyAndEnrichBolt (org.apache.flink.storm.split.operators.VerifyAndEnrichBolt)3 BoltFileSink (org.apache.flink.storm.util.BoltFileSink)2 BoltPrintSink (org.apache.flink.storm.util.BoltPrintSink)2 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 SplitStreamMapper (org.apache.flink.storm.util.SplitStreamMapper)1 SplitStreamType (org.apache.flink.storm.util.SplitStreamType)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1