Search in sources :

Example 6 with StormConfig

use of org.apache.flink.storm.util.StormConfig in project flink by apache.

the class ExclamationWithBolt method main.

// *************************************************************************
// PROGRAM
// *************************************************************************
public static void main(final String[] args) throws Exception {
    if (!parseParameters(args)) {
        return;
    }
    // set up the execution environment
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    // set Storm configuration
    StormConfig config = new StormConfig();
    config.put(ExclamationBolt.EXCLAMATION_COUNT, new Integer(exclamationNum));
    env.getConfig().setGlobalJobParameters(config);
    // get input data
    final DataStream<String> text = getTextDataStream(env);
    final DataStream<String> exclaimed = text.transform("StormBoltTokenizer", TypeExtractor.getForObject(""), new BoltWrapper<String, String>(new ExclamationBolt(), new String[] { Utils.DEFAULT_STREAM_ID })).map(new ExclamationMap());
    // emit result
    if (fileOutput) {
        exclaimed.writeAsText(outputPath);
    } else {
        exclaimed.print();
    }
    // execute program
    env.execute("Streaming WordCount with bolt tokenizer");
}
Also used : StormConfig(org.apache.flink.storm.util.StormConfig) ExclamationBolt(org.apache.flink.storm.exclamation.operators.ExclamationBolt) BoltWrapper(org.apache.flink.storm.wrappers.BoltWrapper) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Example 7 with StormConfig

use of org.apache.flink.storm.util.StormConfig in project flink by apache.

the class ExclamationWithSpout method getTextDataStream.

private static DataStream<String> getTextDataStream(final StreamExecutionEnvironment env) {
    if (fileOutput) {
        final String[] tokens = textPath.split(":");
        final String inputFile = tokens[tokens.length - 1];
        // set Storm configuration
        StormConfig config = new StormConfig();
        config.put(FiniteFileSpout.INPUT_FILE_PATH, inputFile);
        env.getConfig().setGlobalJobParameters(config);
        return env.addSource(new SpoutWrapper<String>(new FiniteFileSpout(), new String[] { Utils.DEFAULT_STREAM_ID }), TypeExtractor.getForClass(String.class)).setParallelism(1);
    }
    return env.addSource(new SpoutWrapper<String>(new FiniteInMemorySpout(WordCountData.WORDS), new String[] { Utils.DEFAULT_STREAM_ID }), TypeExtractor.getForClass(String.class)).setParallelism(1);
}
Also used : FiniteInMemorySpout(org.apache.flink.storm.util.FiniteInMemorySpout) StormConfig(org.apache.flink.storm.util.StormConfig) SpoutWrapper(org.apache.flink.storm.wrappers.SpoutWrapper) FiniteFileSpout(org.apache.flink.storm.util.FiniteFileSpout)

Example 8 with StormConfig

use of org.apache.flink.storm.util.StormConfig in project flink by apache.

the class FlinkClient method addStormConfigToTopology.

@SuppressWarnings({ "unchecked", "rawtypes" })
static void addStormConfigToTopology(FlinkTopology topology, Map conf) throws ClassNotFoundException {
    if (conf != null) {
        ExecutionConfig flinkConfig = topology.getExecutionEnvironment().getConfig();
        flinkConfig.setGlobalJobParameters(new StormConfig(conf));
        // add all registered types to ExecutionConfig
        List<?> registeredClasses = (List<?>) conf.get(Config.TOPOLOGY_KRYO_REGISTER);
        if (registeredClasses != null) {
            for (Object klass : registeredClasses) {
                if (klass instanceof String) {
                    flinkConfig.registerKryoType(Class.forName((String) klass));
                } else {
                    for (Entry<String, String> register : ((Map<String, String>) klass).entrySet()) {
                        flinkConfig.registerTypeWithKryoSerializer(Class.forName(register.getKey()), (Class<? extends Serializer<?>>) Class.forName(register.getValue()));
                    }
                }
            }
        }
    }
}
Also used : StormConfig(org.apache.flink.storm.util.StormConfig) List(java.util.List) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Map(java.util.Map)

Aggregations

StormConfig (org.apache.flink.storm.util.StormConfig)8 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)4 Map (java.util.Map)3 Configuration (org.apache.flink.configuration.Configuration)3 AbstractTest (org.apache.flink.storm.util.AbstractTest)3 StreamingRuntimeContext (org.apache.flink.streaming.api.operators.StreamingRuntimeContext)3 TopologyContext (org.apache.storm.task.TopologyContext)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 GlobalJobParameters (org.apache.flink.api.common.ExecutionConfig.GlobalJobParameters)2 UnmodifiableConfiguration (org.apache.flink.configuration.UnmodifiableConfiguration)2 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)2 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)2 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)2 OutputCollector (org.apache.storm.task.OutputCollector)2 IRichBolt (org.apache.storm.topology.IRichBolt)2 List (java.util.List)1 Entry (java.util.Map.Entry)1 ExclamationBolt (org.apache.flink.storm.exclamation.operators.ExclamationBolt)1 FiniteFileSpout (org.apache.flink.storm.util.FiniteFileSpout)1