forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-12746][docs] Add DataStream API Walkthrough
This closes apache#9201.
- Loading branch information
Showing
25 changed files
with
3,012 additions
and
13 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
95 changes: 95 additions & 0 deletions
95
flink-end-to-end-tests/test-scripts/test_datastream_walkthroughs.sh
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,95 @@ | ||
#!/usr/bin/env bash | ||
################################################################################ | ||
# 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. | ||
################################################################################ | ||
|
||
# End to end test for quick starts test. | ||
# Usage: | ||
# FLINK_DIR=<flink dir> flink-end-to-end-tests/test-scripts/test_datastream_walkthroughs.sh <Type (java or scala)> | ||
|
||
source "$(dirname "$0")"/common.sh | ||
|
||
TEST_TYPE=$1 | ||
|
||
mkdir -p "${TEST_DATA_DIR}" | ||
cd "${TEST_DATA_DIR}" | ||
|
||
ARTIFACT_ID=flink-walkthrough-datastream-${TEST_TYPE} | ||
ARTIFACT_VERSION=0.1 | ||
|
||
mvn archetype:generate \ | ||
-DarchetypeGroupId=org.apache.flink \ | ||
-DarchetypeArtifactId=flink-walkthrough-datastream-${TEST_TYPE} \ | ||
-DarchetypeVersion=${FLINK_VERSION} \ | ||
-DgroupId=org.apache.flink.walkthrough \ | ||
-DartifactId=${ARTIFACT_ID} \ | ||
-Dversion=${ARTIFACT_VERSION} \ | ||
-Dpackage=org.apache.flink.walkthrough \ | ||
-DinteractiveMode=false | ||
|
||
cd "${ARTIFACT_ID}" | ||
|
||
mvn clean package -nsu > compile-output.txt | ||
|
||
if [[ `grep -c "BUILD FAILURE" compile-output.txt` -eq '1' ]]; then | ||
echo "Failure: The walkthrough did not successfully compile" | ||
cat compile-output.txt | ||
exit 1 | ||
fi | ||
|
||
cd target | ||
jar tvf ${ARTIFACT_ID}-${ARTIFACT_VERSION}.jar > contentsInJar.txt | ||
|
||
if [[ `grep -c "org/apache/flink/api/java" contentsInJar.txt` -eq '0' && \ | ||
`grep -c "org/apache/flink/streaming/api" contentsInJar.txt` -eq '0' && \ | ||
`grep -c "org/apache/flink/streaming/experimental" contentsInJar.txt` -eq '0' && \ | ||
`grep -c "org/apache/flink/streaming/runtime" contentsInJar.txt` -eq '0' && \ | ||
`grep -c "org/apache/flink/streaming/util" contentsInJar.txt` -eq '0' ]]; then | ||
|
||
echo "Success: There are no flink core classes are contained in the jar." | ||
else | ||
echo "Failure: There are flink core classes are contained in the jar." | ||
exit 1 | ||
fi | ||
|
||
TEST_PROGRAM_JAR=${TEST_DATA_DIR}/${ARTIFACT_ID}/target/${ARTIFACT_ID}-${ARTIFACT_VERSION}.jar | ||
|
||
start_cluster | ||
|
||
JOB_ID="" | ||
EXIT_CODE=0 | ||
|
||
RETURN=`$FLINK_DIR/bin/flink run -d $TEST_PROGRAM_JAR` | ||
echo "$RETURN" | ||
JOB_ID=`extract_job_id_from_job_submission_return "$RETURN"` | ||
EXIT_CODE=$? # expect matching job id extraction | ||
|
||
if [ $EXIT_CODE == 0 ]; then | ||
RETURN=`$FLINK_DIR/bin/flink list -r` | ||
echo "$RETURN" | ||
if [[ `grep -c "$JOB_ID" "$RETURN"` -eq '1' ]]; then # expect match for running job | ||
echo "[FAIL] Unable to submit walkthrough" | ||
EXIT_CODE=1 | ||
fi | ||
fi | ||
|
||
if [ $EXIT_CODE == 0 ]; then | ||
eval "$FLINK_DIR/bin/flink cancel ${JOB_ID}" | ||
EXIT_CODE=$? | ||
fi | ||
|
||
exit $EXIT_CODE |
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
61 changes: 61 additions & 0 deletions
61
...nk-walkthrough-common/src/main/java/org/apache/flink/walkthrough/common/entity/Alert.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.walkthrough.common.entity; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A simple alert event. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public final class Alert { | ||
|
||
private long id; | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} else if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Alert alert = (Alert) o; | ||
return id == alert.id; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Alert{" + | ||
"id=" + id + | ||
'}'; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...-walkthrough-common/src/main/java/org/apache/flink/walkthrough/common/sink/AlertSink.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,43 @@ | ||
/* | ||
* 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.walkthrough.common.sink; | ||
|
||
import org.apache.flink.annotation.PublicEvolving; | ||
import org.apache.flink.streaming.api.functions.sink.SinkFunction; | ||
import org.apache.flink.walkthrough.common.entity.Alert; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* A sink for outputting alerts. | ||
*/ | ||
@PublicEvolving | ||
@SuppressWarnings("unused") | ||
public class AlertSink implements SinkFunction<Alert> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AlertSink.class); | ||
|
||
@Override | ||
public void invoke(Alert value, Context context) { | ||
LOG.info(value.toString()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
flink-walkthroughs/flink-walkthrough-datastream-java/pom.xml
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,37 @@ | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-walkthroughs</artifactId> | ||
<version>1.10-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<artifactId>flink-walkthrough-datastream-java</artifactId> | ||
<packaging>maven-archetype</packaging> | ||
|
||
</project> |
36 changes: 36 additions & 0 deletions
36
...link-walkthrough-datastream-java/src/main/resources/META-INF/maven/archetype-metadata.xml
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,36 @@ | ||
<!-- | ||
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. | ||
--> | ||
|
||
<archetype-descriptor | ||
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" | ||
name="flink-walkthrough-datastream-java"> | ||
<fileSets> | ||
<fileSet filtered="true" packaged="true" encoding="UTF-8"> | ||
<directory>src/main/java</directory> | ||
<includes> | ||
<include>**/*.java</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet encoding="UTF-8"> | ||
<directory>src/main/resources</directory> | ||
</fileSet> | ||
</fileSets> | ||
</archetype-descriptor> |
Oops, something went wrong.