Skip to content

Commit

Permalink
[FLINK-12746][docs] Add DataStream API Walkthrough
Browse files Browse the repository at this point in the history
This closes apache#9201.
  • Loading branch information
sjwiesman authored and fhueske committed Sep 18, 2019
1 parent e2728c0 commit df8f9a5
Show file tree
Hide file tree
Showing 25 changed files with 3,012 additions and 13 deletions.
71 changes: 71 additions & 0 deletions docs/fig/fraud-transactions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
925 changes: 925 additions & 0 deletions docs/getting-started/walkthroughs/datastream_api.md

Large diffs are not rendered by default.

925 changes: 925 additions & 0 deletions docs/getting-started/walkthroughs/datastream_api.zh.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/getting-started/walkthroughs/table_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "Table API"
nav-id: tableapiwalkthrough
nav-title: 'Table API'
nav-parent_id: walkthroughs
nav-pos: 1
nav-pos: 2
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/walkthroughs/table_api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "Table API"
nav-id: tableapiwalkthrough
nav-title: 'Table API'
nav-parent_id: walkthroughs
nav-pos: 1
nav-pos: 2
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
Expand Down
2 changes: 2 additions & 0 deletions flink-end-to-end-tests/run-nightly-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ run_test "Quickstarts Scala nightly end-to-end test" "$END_TO_END_DIR/test-scrip

run_test "Walkthrough Table Java nightly end-to-end test" "$END_TO_END_DIR/test-scripts/test_table_walkthroughs.sh java"
run_test "Walkthrough Table Scala nightly end-to-end test" "$END_TO_END_DIR/test-scripts/test_table_walkthroughs.sh scala"
run_test "Walkthrough DataStream Java nightly end-to-end test" "$END_TO_END_DIR/test-scripts/test_datastream_walkthroughs.sh java"
run_test "Walkthrough DataStream Scala nightly end-to-end test" "$END_TO_END_DIR/test-scripts/test_datastream_walkthroughs.sh scala"

run_test "Test PubSub connector with Docker based Google PubSub Emulator" "$END_TO_END_DIR/test-scripts/test_streaming_gcp_pubsub.sh"

Expand Down
12 changes: 12 additions & 0 deletions flink-end-to-end-tests/test-scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,15 @@ function retry_times() {
return 1
}

JOB_ID_REGEX_EXTRACTOR=".*JobID ([0-9,a-f]*)"

function extract_job_id_from_job_submission_return() {
if [[ $1 =~ $JOB_ID_REGEX_EXTRACTOR ]];
then
JOB_ID="${BASH_REMATCH[1]}";
else
JOB_ID=""
fi
echo "$JOB_ID"
}

11 changes: 0 additions & 11 deletions flink-end-to-end-tests/test-scripts/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,12 @@ $FLINK_DIR/bin/taskmanager.sh start
$FLINK_DIR/bin/taskmanager.sh start

# CLI regular expressions
JOB_ID_REGEX_EXTRACTOR=".*JobID ([0-9,a-f]*)"
JOB_INFO_PACT_DATA_SOURCE_REGEX_EXTRACTOR="\"pact\": \"(Data Source)\""
JOB_INFO_PACT_DATA_SINK_REGEX_EXTRACTOR="\"pact\": \"(Data Sink)\""
JOB_LIST_REGEX_EXTRACTOR_BY_STATUS="([0-9,a-f]*) :"

EXIT_CODE=0

function extract_job_id_from_job_submission_return() {
if [[ $1 =~ $JOB_ID_REGEX_EXTRACTOR ]];
then
JOB_ID="${BASH_REMATCH[1]}";
else
JOB_ID=""
fi
echo "$JOB_ID"
}

function extract_valid_pact_from_job_info_return() {
PACT_MATCH=0
if [[ $1 =~ $JOB_INFO_PACT_DATA_SOURCE_REGEX_EXTRACTOR ]];
Expand Down
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:https://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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mvn clean package -nsu > compile-output.txt

if [[ `grep -c "BUILD FAILURE" compile-output.txt` -eq '1' ]]; then
echo "Failure: The walk-through did not successfully compile"
cat compile-output.txt
exit 1
fi

Expand Down
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:https://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 +
'}';
}
}
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:https://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 flink-walkthroughs/flink-walkthrough-datastream-java/pom.xml
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:https://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:https://maven.apache.org/POM/4.0.0" xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://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>
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:https://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:https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http:https://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>
Loading

0 comments on commit df8f9a5

Please sign in to comment.