You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by xi...@apache.org on 2019/03/19 17:51:15 UTC

[samza-beam-examples] branch master updated: Update scripts and docs based on Beam 2.11.0 release

This is an automated email from the ASF dual-hosted git repository.

xinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/samza-beam-examples.git


The following commit(s) were added to refs/heads/master by this push:
     new 0243d04  Update scripts and docs based on Beam 2.11.0 release
     new 09a2968  Update scripts and docs based on Beam 2.11.0 release #2
0243d04 is described below

commit 0243d04b3087d93986383d503d43ba37d7e7b8a3
Author: xinyuiscool <xi...@gmail.com>
AuthorDate: Tue Mar 12 14:09:11 2019 -0700

    Update scripts and docs based on Beam 2.11.0 release
---
 README.md                            | 103 ++++++++++++++++++++++-------------
 pom.xml                              |  20 ++++++-
 scripts/grid                         |   4 +-
 src/main/bash/run-beam-container.sh  |   4 +-
 src/main/bash/run-beam-standalone.sh |   4 +-
 src/main/bash/run-beam-yarn.sh       |   4 +-
 6 files changed, 94 insertions(+), 45 deletions(-)

diff --git a/README.md b/README.md
index 8ac19a9..fa4c2f9 100644
--- a/README.md
+++ b/README.md
@@ -24,25 +24,30 @@ running Beam pipelines with SamzaRunner locally, in Yarn cluster,
 or in standalone cluster with Zookeeper. More complex pipelines
 can be built from here and run in similar manner.  
 
-## Example Pipelines
-
+### Example Pipelines
 The following examples are included:
 
 1. [`WordCount`](https://github.com/apache/samza-beam-examples/blob/master/src/main/java/org/apache/beam/examples/WordCount.java) reads a file as input (bounded data source), and computes word frequencies. 
 
-1. [`KafkaWordCount`](https://github.com/apache/samza-beam-examples/blob/master/src/main/java/org/apache/beam/examples/KafkaWordCount.java) does the same word-count computation but reading from a Kafka stream (unbounded data source). It uses a fixed 10-sec window to aggregate the counts.
-
-## Run Examples
+2. [`KafkaWordCount`](https://github.com/apache/samza-beam-examples/blob/master/src/main/java/org/apache/beam/examples/KafkaWordCount.java) does the same word-count computation but reading from a Kafka stream (unbounded data source). It uses a fixed 10-sec window to aggregate the counts.
 
-Each example can be run locally, in Yarn cluster or in standalone cluster. Here we use WordCount as an example.
+### Run the Examples
 
-### Set Up
+Each example can be run locally, in Yarn cluster or in standalone cluster. Here we use KafkaWordCount as an example.
 
+#### Set Up
 1. Download and install [JDK version 8](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). Verify that the JAVA_HOME environment variable is set and points to your JDK installation.
 
-1. Download and install [Apache Maven](http://maven.apache.org/download.cgi) by following Maven’s [installation guide](http://maven.apache.org/install.html) for your specific operating system.
+2. Download and install [Apache Maven](http://maven.apache.org/download.cgi) by following Maven’s [installation guide](http://maven.apache.org/install.html) for your specific operating system.
+
+Check out the `samza-beam-examples` repo:
+
+```
+$ git clone https://github.com/apache/samza-beam-examples.git
+$ cd samza-beam-examples
+```
 
-1. A script named "grid" is included in this project which allows you to easily download and install Zookeeper, Kafka, and Yarn.
+A script named "grid" is included in this project which allows you to easily download and install Zookeeper, Kafka, and Yarn.
 You can run the following to bring them all up running in your local machine:
 
 ```
@@ -57,16 +62,21 @@ bring them up separately, e.g.:
 $ scripts/grid install zookeeper
 $ scripts/grid start zookeeper
 ```
+Now let's create a Kafka topic named "input-text" for this example:
+
+```
+$ ./deploy/kafka/bin/kafka-topics.sh  --zookeeper localhost:2181 --create --topic input-text --partitions 10 --replication-factor 1
+```
    
-### Local Run
+#### Run Locally
 You can run directly within the project using maven:
 
 ```
-$ mvn compile exec:java -Dexec.mainClass=org.apache.beam.examples.WordCount \
+$ mvn compile exec:java -Dexec.mainClass=org.apache.beam.examples.KafkaWordCount \
     -Dexec.args="--runner=SamzaRunner" -P samza-runner
 ```
 
-### Packaging Your Application
+#### Packaging Your Application
 To execute the example in either Yarn or standalone, you need to package it first.
 After packaging, we deploy and explode the tgz in the deploy folder:
 
@@ -75,53 +85,70 @@ After packaging, we deploy and explode the tgz in the deploy folder:
  $ mvn package && tar -xvf target/samza-beam-examples-0.1-dist.tar.gz -C deploy/examples/
 ```
 
-### Standalone Cluster with Zookeeper
+#### Run in Standalone Cluster with Zookeeper
 You can use the `run-beam-standalone.sh` script included in this repo to run an example
 in standalone mode. The config file is provided as `config/standalone.properties`. Note by
-default we create one single input partition for the whole input. To set the number of 
-partitions, you can add "--maxSourceParallelism=" argument. For example, "--maxSourceParallelism=2"
-will create two partitions of the input file, based on size.  
+default we create one single split for the whole input (--maxSourceParallelism=1). To 
+set each Kafka partition in a split, we can set a large "maxSourceParallelism" value which 
+is the upper bound of the number of splits.
+
+```
+$ deploy/examples/bin/run-beam-standalone.sh org.apache.beam.examples.KafkaWordCount \
+    --configFilePath=$PWD/deploy/examples/config/standalone.properties --maxSourceParallelism=1024
+```
+
+#### Run Yarn Cluster
+Similar to running standalone, we can use the `run-beam-yarn.sh` to run the examples
+in Yarn cluster. The config file is provided as `config/yarn.properties`. To run the 
+KafkaWordCount example in yarn:
 
 ```
-$ deploy/examples/bin/run-beam-standalone.sh org.apache.beam.examples.WordCount \
-    --configFilePath=$PWD/deploy/examples/config/standalone.properties \
-    --inputFile=/Users/xiliu/opensource/samza-beam-examples/pom.xml --output=word-counts.txt \
-    --maxSourceParallelism=2
+$ deploy/examples/bin/run-beam-yarn.sh org.apache.beam.examples.KafkaWordCount \
+    --configFilePath=$PWD/deploy/examples/config/yarn.properties --maxSourceParallelism=1024
 ```
 
-If the example consumes from Kafka, we can set a large "maxSourceParallelism" value so each kafka
-partition be assigned to a Samza task (the total number of tasks will be bounded by 
-maxSourceParallelism). E.g.
+#### Validate the Pipeline Results
+Now the pipeline is deployed to either locally, standalone or Yarn. Let's check out the results. First we start a kakfa consumer to listen to the output:
 
 ```
-$ deploy/examples/bin/run-beam-standalone.sh org.apache.beam.examples.KafkaWordCount \
-    --configFilePath=$PWD/deploy/examples/config/standalone.properties \
-    --maxSourceParallelism=1024
+$ ./deploy/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic word-count --property print.key=true
 ```
 
-###  Yarn Cluster
-Similar to running standalone, we can use the `run-beam-yarn.sh` to run the examples
-in Yarn cluster. The config file is provided as `config/yarn.properties`. To run the 
-WordCount example in yarn:
+Then let's publish a few lines to the input Kafka topic:
 
 ```
- $ deploy/examples/bin/run-beam-yarn.sh org.apache.beam.examples.WordCount \
-    --configFilePath=$PWD/deploy/examples/config/yarn.properties \
-    --inputFile=/Users/xiliu/opensource/samza-beam-examples/pom.xml \
-    --output=/tmp/word-counts.txt --maxSourceParallelism=2
+$ ./deploy/kafka/bin/kafka-console-producer.sh --topic input-text --broker-list localhost:9092
+Nory was a Catholic because her mother was a Catholic, and Nory’s mother was a Catholic because her father was a Catholic, and her father was a Catholic because his mother was a Catholic, or had been.
 ```
 
-Same as Standalone, we can provide a large "maxSourceParallelism" value to have better parallism
-in Kafka case.
+You should see the word count shows up in the consumer console in about 10 secs:
+
+```
+a       6
+br      1
+mother  3
+was     6
+Catholic        6
+his     1
+Nory    2
+s       1
+father  2
+had     1
+been    1
+and     2
+her     3
+or      1
+because 3
+```
 
-## Beyond Examples
+### Beyond Examples
 Feel free to build more complex pipelines based on the examples above, and reach out to us:
 
 * Subscribe and mail to [user@beam.apache.org](mailto:user@beam.apache.org) for any Beam questions.
 
 * Subscribe and mail to [user@samza.apache.org](mailto:user@samza.apache.org) for any Samza questions.
 
-## More Information
+### More Information
 
 * [Apache Beam](http://beam.apache.org)
 * [Apache Samza](https://samza.apache.org/)
diff --git a/pom.xml b/pom.xml
index d78812a..2689de3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
   <packaging>jar</packaging>
 
   <properties>
-    <beam.version>2.9.0</beam.version>
+    <beam.version>2.11.0</beam.version>
     <samza.version>0.14.1</samza.version>
 
     <guava.version>20.0</guava.version>
@@ -192,6 +192,24 @@
       <version>${samza.version}</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.samza</groupId>
+      <artifactId>samza-api</artifactId>
+      <version>${samza.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.samza</groupId>
+      <artifactId>samza-kafka_2.11</artifactId>
+      <version>${samza.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.samza</groupId>
+      <artifactId>samza-core_2.11</artifactId>
+      <version>${samza.version}</version>
+    </dependency>
+
     <!-- Dependencies below this line are specific dependencies needed by the examples code. -->
     <dependency>
       <groupId>joda-time</groupId>
diff --git a/scripts/grid b/scripts/grid
index bf2266a..fb91827 100755
--- a/scripts/grid
+++ b/scripts/grid
@@ -34,7 +34,7 @@ DOWNLOAD_CACHE_DIR=$HOME/.grid/download
 COMMAND=$1
 SYSTEM=$2
 
-DOWNLOAD_KAFKA=https://archive.apache.org/dist/kafka/0.10.1.1/kafka_2.11-0.10.1.1.tgz
+DOWNLOAD_KAFKA=https://archive.apache.org/dist/kafka/0.10.2.1/kafka_2.11-0.10.2.1.tgz
 DOWNLOAD_YARN=https://archive.apache.org/dist/hadoop/common/hadoop-2.6.1/hadoop-2.6.1.tar.gz
 DOWNLOAD_ZOOKEEPER=http://archive.apache.org/dist/zookeeper/zookeeper-3.4.3/zookeeper-3.4.3.tar.gz
 
@@ -93,7 +93,7 @@ install_yarn() {
 
 install_kafka() {
   mkdir -p "$DEPLOY_ROOT_DIR"
-  install kafka $DOWNLOAD_KAFKA kafka_2.11-0.10.1.1
+  install kafka $DOWNLOAD_KAFKA kafka_2.11-0.10.2.1
   # have to use SIGTERM since nohup on appears to ignore SIGINT
   # and Kafka switched to SIGINT in KAFKA-1031.
   sed -i.bak 's/SIGINT/SIGTERM/g' $DEPLOY_ROOT_DIR/kafka/bin/kafka-server-stop.sh
diff --git a/src/main/bash/run-beam-container.sh b/src/main/bash/run-beam-container.sh
index c58a1f1..4e9f8d9 100755
--- a/src/main/bash/run-beam-container.sh
+++ b/src/main/bash/run-beam-container.sh
@@ -31,4 +31,6 @@ cd $base_dir
 base_dir=`pwd`
 cd $home_dir
 
-exec $(dirname $0)/run-class.sh $1 --runner=org.apache.beam.runners.samza.SamzaRunner --configFactory=org.apache.beam.runners.samza.container.ContainerCfgFactory "${@:2}"
\ No newline at end of file
+override="{\"task.execute\":\"bin/run-beam-container.sh $@\"}"
+
+exec $(dirname $0)/run-class.sh $1 --runner=org.apache.beam.runners.samza.SamzaRunner --configFactory=org.apache.beam.runners.samza.container.ContainerCfgFactory --configOverride="$override" "${@:2}"
\ No newline at end of file
diff --git a/src/main/bash/run-beam-standalone.sh b/src/main/bash/run-beam-standalone.sh
index f523f5a..88bd43c 100755
--- a/src/main/bash/run-beam-standalone.sh
+++ b/src/main/bash/run-beam-standalone.sh
@@ -18,4 +18,6 @@
 
 [[ $JAVA_OPTS != *-Dlog4j.configuration* ]] && export JAVA_OPTS="$JAVA_OPTS -Dlog4j.configuration=file:$(dirname $0)/log4j-console.xml"
 
-exec $(dirname $0)/run-class.sh $1 --runner=org.apache.beam.runners.samza.SamzaRunner "${@:2}"
\ No newline at end of file
+override="{\"task.execute\":\"bin/run-beam-container.sh $@\"}"
+
+exec $(dirname $0)/run-class.sh $1 --runner=org.apache.beam.runners.samza.SamzaRunner --configOverride="$override" "${@:2}"
\ No newline at end of file
diff --git a/src/main/bash/run-beam-yarn.sh b/src/main/bash/run-beam-yarn.sh
index 6d65075..0e1df52 100755
--- a/src/main/bash/run-beam-yarn.sh
+++ b/src/main/bash/run-beam-yarn.sh
@@ -29,11 +29,11 @@ mkdir -p $EXECUTION_PLAN_DIR
 
 op=$(if [[ "$@" =~ (--operation=)([^ ]*) ]]; then echo "${BASH_REMATCH[2]}"; else echo "run"; fi)
 
-cmd="{\"task.execute\":\"bin/run-beam-container.sh $@\"}"
+override="{\"task.execute\":\"bin/run-beam-container.sh $@\"}"
 
 case $op in
   run)
-    exec $(dirname $0)/run-class.sh $1 --runner=org.apache.beam.runners.samza.SamzaRunner --configOverride="$cmd" "${@:2}"
+    exec $(dirname $0)/run-class.sh $1 --runner=org.apache.beam.runners.samza.SamzaRunner --configOverride="$override" "${@:2}"
   ;;
 
   kill)