Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-2837][storm] various improvements for the compatibility layer
- refactor to use Storm's topology builder - remove FlinkTopologyBuilder - instantiate context-based StreamExecutionEnvironment (local or remote) - remove some of the Flink and Storm behavior replicating classes - modify FlinkTopology to parse Storm topology directly - replace StormTestBase with StreamingTestBase - add print example - FlinkTopologyBuilder changes (check if all inputs are available before processing) - correct package typo - two input support - add join example - update docs This closes #1398.
- Loading branch information
Showing
71 changed files
with
1,132 additions
and
1,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...rib/flink-storm-examples/src/main/java/org/apache/flink/storm/join/SingleJoinExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.flink.storm.join; | ||
|
||
import backtype.storm.Config; | ||
import backtype.storm.testing.FeederSpout; | ||
import backtype.storm.topology.TopologyBuilder; | ||
import backtype.storm.tuple.Fields; | ||
import backtype.storm.tuple.Values; | ||
import backtype.storm.utils.Utils; | ||
import org.apache.flink.storm.api.FlinkLocalCluster; | ||
import org.apache.flink.storm.api.FlinkTopology; | ||
import org.apache.flink.storm.util.BoltFileSink; | ||
import org.apache.flink.storm.util.TupleOutputFormatter; | ||
import storm.starter.bolt.PrinterBolt; | ||
import storm.starter.bolt.SingleJoinBolt; | ||
|
||
|
||
public class SingleJoinExample { | ||
|
||
public static void main(String[] args) throws Exception { | ||
final FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender", "hobbies")); | ||
final FeederSpout ageSpout = new FeederSpout(new Fields("id", "age")); | ||
|
||
TopologyBuilder builder = new TopologyBuilder(); | ||
|
||
builder.setSpout("gender", genderSpout); | ||
|
||
builder.setSpout("age", ageSpout); | ||
|
||
builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))) | ||
.fieldsGrouping("gender", new Fields("id")) | ||
.fieldsGrouping("age", new Fields("id")); | ||
|
||
// emit result | ||
if (args.length > 0) { | ||
// read the text file from given input path | ||
builder.setBolt("fileOutput", new BoltFileSink(args[0], new TupleOutputFormatter())) | ||
.shuffleGrouping("join"); | ||
} else { | ||
builder.setBolt("print", new PrinterBolt()).shuffleGrouping("join"); | ||
} | ||
|
||
Config conf = new Config(); | ||
conf.setDebug(true); | ||
|
||
String[] hobbies = new String[] {"reading", "biking", "travelling", "watching tv"}; | ||
|
||
for (int i = 0; i < 10; i++) { | ||
String gender; | ||
if (i % 2 == 0) { | ||
gender = "male"; | ||
} | ||
else { | ||
gender = "female"; | ||
} | ||
genderSpout.feed(new Values(i, gender, hobbies[i % hobbies.length])); | ||
} | ||
|
||
for (int i = 9; i >= 0; i--) { | ||
ageSpout.feed(new Values(i, i + 20)); | ||
} | ||
|
||
|
||
final FlinkLocalCluster cluster = FlinkLocalCluster.getLocalCluster(); | ||
cluster.submitTopology("joinTopology", conf, FlinkTopology.createTopology(builder)); | ||
|
||
Utils.sleep(10 * 1000); | ||
|
||
cluster.shutdown(); | ||
|
||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ib/flink-storm-examples/src/main/java/org/apache/flink/storm/print/PrintSampleStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.storm.print; | ||
|
||
import backtype.storm.Config; | ||
import backtype.storm.topology.TopologyBuilder; | ||
import backtype.storm.utils.Utils; | ||
import org.apache.flink.storm.api.FlinkLocalCluster; | ||
import org.apache.flink.storm.api.FlinkTopology; | ||
import storm.starter.bolt.PrinterBolt; | ||
import storm.starter.spout.TwitterSampleSpout; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Prints incoming tweets. Tweets can be filtered by keywords. | ||
*/ | ||
public class PrintSampleStream { | ||
public static void main(String[] args) throws Exception { | ||
String consumerKey = args[0]; | ||
String consumerSecret = args[1]; | ||
String accessToken = args[2]; | ||
String accessTokenSecret = args[3]; | ||
|
||
// keywords start with the 5th parameter | ||
String[] keyWords = Arrays.copyOfRange(args, 4, args.length); | ||
|
||
TopologyBuilder builder = new TopologyBuilder(); | ||
|
||
builder.setSpout("twitter", new TwitterSampleSpout(consumerKey, consumerSecret, | ||
accessToken, accessTokenSecret, keyWords)); | ||
builder.setBolt("print", new PrinterBolt()) | ||
.shuffleGrouping("twitter"); | ||
|
||
|
||
Config conf = new Config(); | ||
|
||
final FlinkLocalCluster cluster = FlinkLocalCluster.getLocalCluster(); | ||
cluster.submitTopology("Print", conf, FlinkTopology.createTopology(builder)); | ||
|
||
Utils.sleep(10 * 1000); | ||
|
||
cluster.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.