[ 
https://issues.apache.org/jira/browse/BEAM-3840?focusedWorklogId=82412&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-82412
 ]

ASF GitHub Bot logged work on BEAM-3840:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 20/Mar/18 18:54
            Start Date: 20/Mar/18 18:54
    Worklog Time Spent: 10m 
      Work Description: aaltay closed pull request #4853: [BEAM-3840] Get 
python mobile-gaming automating on core runners
URL: https://github.com/apache/beam/pull/4853
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.test-infra/jenkins/job_beam_ReleaseCandidate_Python.groovy 
b/.test-infra/jenkins/job_beam_ReleaseCandidate_Python.groovy
index 05a9a44ce3f..d1d9f6d7a68 100644
--- a/.test-infra/jenkins/job_beam_ReleaseCandidate_Python.groovy
+++ b/.test-infra/jenkins/job_beam_ReleaseCandidate_Python.groovy
@@ -46,6 +46,7 @@ job('beam_PostRelease_Python_Candidate') {
     // Execute shell command to test Python SDK.
     steps {
         shell('cd ' + common_job_properties.checkoutDir +
-                ' && bash 
release/src/main/groovy/run_release_candidate_python_validation.sh')
+                ' && bash 
release/src/main/groovy/run_release_candidate_python_quickstart.sh' +
+                ' && bash 
release/src/main/groovy/run_release_candidate_python_mobile_gaming.sh')
     }
 }
diff --git a/release/src/main/groovy/python_release_automation_utils.sh 
b/release/src/main/groovy/python_release_automation_utils.sh
new file mode 100644
index 00000000000..554f3aa5693
--- /dev/null
+++ b/release/src/main/groovy/python_release_automation_utils.sh
@@ -0,0 +1,135 @@
+#!/bin/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.
+#
+
+
+set -e
+set -v
+
+#######################################
+# Print Separators.
+# Arguments:
+#   Info to be printed.
+# Outputs:
+#   Writes info to stdout.
+#######################################
+function print_separator() {
+    echo 
"############################################################################"
+    echo $1
+    echo 
"############################################################################"
+}
+
+#######################################
+# Update gcloud version.
+# Arguments:
+#   None
+#######################################
+function update_gcloud() {
+    curl 
https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-189.0.0-linux-x86_64.tar.gz
 \
+    --output gcloud.tar.gz
+    tar xf gcloud.tar.gz
+    ./google-cloud-sdk/install.sh --quiet
+    . ./google-cloud-sdk/path.bash.inc
+    gcloud components update --quiet || echo 'gcloud components update failed'
+    gcloud -v
+}
+
+#######################################
+# Get Python SDK version from sdk/python/apache_beam/version.py.
+# Arguments:
+#   None
+# Outputs:
+#   Writes version to stdout.
+#######################################
+function get_version() {
+    version=$(awk '/__version__/{print $3}' sdks/python/apache_beam/version.py)
+    if [[ $version = *".dev"* ]]; then
+        echo $version | cut -c 2- | rev | cut -d'.' -f2- | rev
+    else
+        echo $version
+    fi
+}
+
+#######################################
+# Publish data to Pubsub topic for streaming wordcount examples.
+# Arguments:
+#   None
+#######################################
+function run_pubsub_publish(){
+    words=("hello world!", "I like cats!", "Python", "hello Python", "hello 
Python")
+    for word in ${words[@]}; do
+        gcloud pubsub topics publish $PUBSUB_TOPIC1 --message "$word"
+    done
+    sleep 10
+}
+
+#######################################
+# Pull data from Pubsub.
+# Arguments:
+#   None
+#######################################
+function run_pubsub_pull() {
+    gcloud pubsub subscriptions pull --project=$PROJECT_ID 
$PUBSUB_SUBSCRIPTION --limit=100 --auto-ack
+}
+
+#######################################
+# Create Pubsub topics and subscription.
+# Arguments:
+#   None
+#######################################
+function create_pubsub() {
+    gcloud pubsub topics create --project=$PROJECT_ID $PUBSUB_TOPIC1
+    gcloud pubsub topics create --project=$PROJECT_ID $PUBSUB_TOPIC2
+    gcloud pubsub subscriptions create --project=$PROJECT_ID 
$PUBSUB_SUBSCRIPTION --topic $PUBSUB_TOPIC2
+}
+
+#######################################
+# Remove Pubsub topics and subscription.
+# Arguments:
+#   None
+#######################################
+function cleanup_pubsub() {
+    gcloud pubsub topics delete --project=$PROJECT_ID $PUBSUB_TOPIC1
+    gcloud pubsub topics delete --project=$PROJECT_ID $PUBSUB_TOPIC2
+    gcloud pubsub subscriptions delete --project=$PROJECT_ID 
$PUBSUB_SUBSCRIPTION
+}
+
+
+# Python RC configurations
+VERSION=$(get_version)
+CANDIDATE_URL="https://dist.apache.org/repos/dist/dev/beam/$VERSION/";
+BEAM_PYTHON_SDK="apache-beam-$VERSION-python.zip"
+
+# Cloud Configurations
+PROJECT_ID='apache-beam-testing'
+BUCKET_NAME='temp-storage-for-release-validation-tests/nightly-snapshot-validation'
+TEMP_DIR='/tmp'
+DATASET='beam_postrelease_mobile_gaming'
+NUM_WORKERS=1
+
+# Quickstart configurations
+SHA1_FILE_NAME="apache-beam-$VERSION-python.zip.sha1"
+ASC_FILE_NAME="apache-beam-$VERSION-python.zip.asc"
+
+WORDCOUNT_OUTPUT='wordcount_direct.txt'
+PUBSUB_TOPIC1='wordstream-python-topic-1'
+PUBSUB_TOPIC2='wordstream-python-topic-2'
+PUBSUB_SUBSCRIPTION='wordstream-python-sub2'
+
+# Mobile Gaming Configurations
+DATASET='beam_postrelease_mobile_gaming'
+USERSCORE_OUTPUT_PREFIX='python-userscore_result'
diff --git 
a/release/src/main/groovy/run_release_candidate_python_mobile_gaming.sh 
b/release/src/main/groovy/run_release_candidate_python_mobile_gaming.sh
new file mode 100755
index 00000000000..fc6683386a7
--- /dev/null
+++ b/release/src/main/groovy/run_release_candidate_python_mobile_gaming.sh
@@ -0,0 +1,188 @@
+#!/bin/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.
+#
+
+#  This file will verify Apache/Beam release candidate python by following 
steps:
+#
+#  1. Create a new virtualenv and install the SDK
+#  2. Run UserScore examples with DirectRunner
+#  3. Run UserScore examples with DataflowRunner
+#  4. Run HourlyTeamScore on DirectRunner
+#  5. Run HourlyTeamScore on DataflowRunner
+#
+
+set -e
+set -v
+
+source release/src/main/groovy/python_release_automation_utils.sh
+
+#######################################
+# Remove temp directory when complete.
+# Globals:
+#   TMPDIR
+# Arguments:
+#   None
+#######################################
+function complete() {
+    print_separator "Validation $1"
+    rm -rf $TMPDIR
+}
+
+#######################################
+# Verify results of user_score.
+# Globals:
+#   BUCKET_NAME
+# Arguments:
+#   $1: Runner - direct, dataflow
+#######################################
+function verify_user_score() {
+    expected_output_file_name="$USERSCORE_OUTPUT_PREFIX-$1-runner.txt"
+    actual_output_files=$(ls)
+    if [[ $1 = *"dataflow"* ]]; then
+        actual_output_files=$(gsutil ls gs://$BUCKET_NAME)
+        
expected_output_file_name="gs://$BUCKET_NAME/$expected_output_file_name"
+    fi
+    echo $actual_output_files
+    if [[ $actual_output_files != *$expected_output_file_name* ]]
+    then
+        echo "ERROR: The userscore example failed on $1-runner".
+        complete "failed when running userscore example with $1-runner."
+        exit 1
+    fi
+
+    if [[ $1 = *"dataflow"* ]]; then
+        gsutil rm $expected_output_file_name*
+    fi
+    echo "SUCCEED: user_score successfully run on $1-runner."
+}
+
+#######################################
+# Verify results of hourly_team_score.
+# Globals:
+#   DATASET
+# Arguments:
+#   Runner - direct, dataflow
+#######################################
+function verify_hourly_team_score() {
+    retry=3
+    should_see='AntiqueBrassPlatypus'
+    while(( $retry >= 0 )); do
+        if [[ $retry > 0 ]]; then
+            bq_pull_result=$(bq head -n 100 
$DATASET.hourly_team_score_python_$1)
+            if [[ $bq_pull_result = *"$should_see"* ]]; then
+                echo "SUCCEED: hourly_team_score example successful run on 
$1-runner"
+                break
+            else
+                retry=$(($retry-1))
+                echo "Did not find team scores, retry left: $retry"
+                sleep 15
+            fi
+        else
+            echo "FAILED: HourlyTeamScore example failed running on $1-runner. 
\
+                Did not found scores of team $should_see in 
$DATASET.leader_board"
+            complete "FAILED"
+            exit 1
+        fi
+    done
+}
+
+
+print_separator "Start Mobile Gaming Examples"
+echo "SDK version: $VERSION"
+
+TMPDIR=$(mktemp -d)
+echo $TMPDIR
+pushd $TMPDIR
+
+#
+# 1. Download files from RC staging location, install python sdk
+#
+
+wget $CANDIDATE_URL$BEAM_PYTHON_SDK
+print_separator "Creating new virtualenv and installing the SDK"
+virtualenv temp_virtualenv
+. temp_virtualenv/bin/activate
+gcloud_version=$(gcloud --version | head -1 | awk '{print $4}')
+if [[ "$gcloud_version" < "189" ]]; then
+  update_gcloud
+fi
+pip install $BEAM_PYTHON_SDK[gcp]
+
+
+#
+# 2. Run UserScore with DirectRunner
+#
+
+print_separator "Running userscore example with DirectRunner"
+output_file_name="$USERSCORE_OUTPUT_PREFIX-direct-runner.txt"
+python -m apache_beam.examples.complete.game.user_score \
+--output=$output_file_name \
+--project=$PROJECT_ID \
+--dataset=$DATASET \
+--input=gs://$BUCKET_NAME/5000_gaming_data.csv
+
+verify_user_score "direct"
+
+
+#
+# 3. Run UserScore with DataflowRunner
+#
+
+print_separator "Running userscore example with DataflowRunner"
+output_file_name="$USERSCORE_OUTPUT_PREFIX-dataflow-runner.txt"
+python -m apache_beam.examples.complete.game.user_score \
+--project=$PROJECT_ID \
+--runner=DataflowRunner \
+--temp_location=gs://$BUCKET_NAME/temp/ \
+--sdk_location=$BEAM_PYTHON_SDK \
+--input=gs://$BUCKET_NAME/5000_gaming_data.csv \
+--output=gs://$BUCKET_NAME/$output_file_name
+
+verify_user_score "dataflow"
+
+
+#
+# 4. Run HourlyTeamScore with DirectRunner
+#
+
+print_separator "Running HourlyTeamScore example with DirectRunner"
+python -m apache_beam.examples.complete.game.hourly_team_score \
+--project=$PROJECT_ID \
+--dataset=$DATASET \
+--input=gs://$BUCKET_NAME/5000_gaming_data.csv \
+--table="hourly_team_score_python_direct"
+
+verify_hourly_team_score "direct"
+
+
+#
+# 5. Run HourlyTeamScore with DataflowRunner
+#
+
+print_separator "Running HourlyTeamScore example with DataflowRunner"
+python -m apache_beam.examples.complete.game.hourly_team_score \
+--project=$PROJECT_ID \
+--dataset=$DATASET \
+--runner=DataflowRunner \
+--temp_location=gs://$BUCKET_NAME/temp/ \
+--sdk_location $BEAM_PYTHON_SDK \
+--input=gs://$BUCKET_NAME/5000_gaming_data.csv \
+--table="hourly_team_score_python_dataflow"
+
+verify_hourly_team_score "dataflow"
+
+complete "SUCCEED: Mobile Gaming Verification Complete"
diff --git a/release/src/main/groovy/run_release_candidate_python_validation.sh 
b/release/src/main/groovy/run_release_candidate_python_quickstart.sh
similarity index 62%
rename from release/src/main/groovy/run_release_candidate_python_validation.sh
rename to release/src/main/groovy/run_release_candidate_python_quickstart.sh
index 8756cc7d185..914c2f24a31 100755
--- a/release/src/main/groovy/run_release_candidate_python_validation.sh
+++ b/release/src/main/groovy/run_release_candidate_python_quickstart.sh
@@ -30,83 +30,47 @@
 set -e
 set -v
 
-print_separator() {
-    echo 
"############################################################################"
-    echo $1
-    echo 
"############################################################################"
-}
-
-get_version() {
-    # this function will pull python sdk version from 
sdk/python/apache_beam/version.py and eliminate postfix '.dev'
-    version=$(awk '/__version__/{print $3}' sdks/python/apache_beam/version.py)
-    echo $version | cut -c 2- | rev | cut -d'.' -f2- | rev
-}
-
-update_gcloud() {
-    curl 
https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-189.0.0-linux-x86_64.tar.gz
 \
-    --output gcloud.tar.gz
-    tar xf gcloud.tar.gz
-    ./google-cloud-sdk/install.sh --quiet
-    . ./google-cloud-sdk/path.bash.inc
-    gcloud components update --quiet || echo 'gcloud components update failed'
-    gcloud -v
-}
-
-complete() {
+source release/src/main/groovy/python_release_automation_utils.sh
+
+#######################################
+# Remove temp directory when complete.
+# Globals:
+#   TMPDIR
+# Arguments:
+#   None
+#######################################
+function complete() {
     print_separator "Validation $1"
     rm -rf $TMPDIR
 }
 
-run_pubsub_publish(){
-    words=("hello world!", "I like cats!", "Python", "hello Python", "hello 
Python")
-    for word in ${words[@]}
-    do
-        gcloud pubsub topics publish $PUBSUB_TOPIC1 --message "$word"
-    done
-    sleep 10
-}
-
-run_pubsub_pull() {
-    gcloud pubsub subscriptions pull --project=$PROJECT_ID 
$PUBSUB_SUBSCRIPTION --limit=100 --auto-ack
-}
-
-create_pubsub() {
-    gcloud pubsub topics create --project=$PROJECT_ID $PUBSUB_TOPIC1
-    gcloud pubsub topics create --project=$PROJECT_ID $PUBSUB_TOPIC2
-    gcloud pubsub subscriptions create --project=$PROJECT_ID 
$PUBSUB_SUBSCRIPTION --topic $PUBSUB_TOPIC2
-}
-
-cleanup_pubsub() {
-    gcloud pubsub topics delete --project=$PROJECT_ID $PUBSUB_TOPIC1
-    gcloud pubsub topics delete --project=$PROJECT_ID $PUBSUB_TOPIC2
-    gcloud pubsub subscriptions delete --project=$PROJECT_ID 
$PUBSUB_SUBSCRIPTION
-}
-
-verify_steaming_result() {
-    #  $1 - runner type: DirectRunner, DataflowRunner
-    #  $2 - pid: the pid of running pipeline
-    #  $3 - running_job (DataflowRunner only): the job id of streaming 
pipeline running on DataflowRunner
+#######################################
+# Verify results of hourly_team_score.
+# Globals:
+#   DATASET
+# Arguments:
+#   $1 - runner type: DirectRunner, DataflowRunner
+#   $2 - pid: the pid of running pipeline
+#   $3 - running_job (DataflowRunner only): the job id of streaming pipeline 
running on DataflowRunner
+#######################################
+function verify_steaming_result() {
     retry=3
     should_see="Python: "
-    while(( $retry > 0 ))
-    do
+    while(( $retry > 0 )); do
         pull_result=$(run_pubsub_pull)
-        if [[ $pull_result = *"$should_see"* ]]
-        then
+        if [[ $pull_result = *"$should_see"* ]]; then
             echo "SUCCEED: The streaming wordcount example running 
successfully on $1."
             break
         else
-            if [[ $retry > 0 ]]
-            then
-                ((retry-=1))
+            if [[ $retry > 0 ]]; then
+                retry=$(($retry-1))
                 echo "retry left: $retry"
                 sleep 15
             else
                 echo "ERROR: The streaming wordcount example failed on $1."
                 cleanup_pubsub
                 kill -9 $2
-                if [[ $1 = "DataflowRunner" ]]
-                then
+                if [[ $1 = "DataflowRunner" ]]; then
                     gcloud dataflow jobs cancel $3
                 fi
                 complete "failed when running streaming wordcount example with 
$1."
@@ -116,24 +80,8 @@ verify_steaming_result() {
     done
 }
 
-# Python Release Candidate Configuration
-echo "SDK version: $(get_version)"
-VERSION=$(get_version)
-CANDIDATE_URL="https://dist.apache.org/repos/dist/dev/beam/$VERSION/";
-SHA1_FILE_NAME="apache-beam-$VERSION-python.zip.sha1"
-MD5_FILE_NAME="apache-beam-$VERSION-python.zip.md5"
-ASC_FILE_NAME="apache-beam-$VERSION-python.zip.asc"
-BEAM_PYTHON_SDK="apache-beam-$VERSION-python.zip"
-
-# Cloud Configurations
-PROJECT_ID='apache-beam-testing'
-BUCKET_NAME='temp-storage-for-release-validation-tests'
-TEMP_DIR='/quickstart'
-NUM_WORKERS=1
-WORDCOUNT_OUTPUT='wordcount_direct.txt'
-PUBSUB_TOPIC1='wordstream-python-topic-1'
-PUBSUB_TOPIC2='wordstream-python-topic-2'
-PUBSUB_SUBSCRIPTION='wordstream-python-sub2'
+print_separator "Start Quickstarts Examples"
+echo "SDK version: $VERSION"
 
 TMPDIR=$(mktemp -d)
 echo $TMPDIR
@@ -142,8 +90,8 @@ pushd $TMPDIR
 #
 # 1. Download files from RC staging location
 #
+
 wget $CANDIDATE_URL$SHA1_FILE_NAME
-wget $CANDIDATE_URL$MD5_FILE_NAME
 wget $CANDIDATE_URL$ASC_FILE_NAME
 wget $CANDIDATE_URL$BEAM_PYTHON_SDK
 
@@ -159,13 +107,6 @@ then
   complete "The sha1 hash doesn't match."
   exit 1
 fi
-hash_check=$(md5sum -c $MD5_FILE_NAME | head -1 |awk '{print $2}')
-if [[ "$hash_check" != "OK" ]]
-then
-  echo "ERROR: The md5 hash doesn't match."
-  complete "The md5 hash doesn't match."
-  exit 1
-fi
 echo "SUCCEED: Hashes verification completed."
 
 wget https://dist.apache.org/repos/dist/dev/beam/KEYS
@@ -179,12 +120,12 @@ gpg --verify $ASC_FILE_NAME $BEAM_PYTHON_SDK
 
 print_separator "Creating new virtualenv and installing the SDK"
 virtualenv temp_virtualenv
-. temp_virtualenv/bin/activate && pip install $BEAM_PYTHON_SDK[gcp]
+. temp_virtualenv/bin/activate
 gcloud_version=$(gcloud --version | head -1 | awk '{print $4}')
-if [[ "$gcloud_version" < "189" ]]
-then
+if [[ "$gcloud_version" < "189" ]]; then
   update_gcloud
 fi
+pip install $BEAM_PYTHON_SDK[gcp]
 
 
 #
@@ -193,8 +134,7 @@ fi
 
 print_separator "Running wordcount example with DirectRunner"
 python -m apache_beam.examples.wordcount --output wordcount_direct.txt
-if ls wordcount_direct.txt* 1> /dev/null 2>&1;
-then
+if ls wordcount_direct.txt* 1> /dev/null 2>&1; then
        echo "Found output file(s):"
        ls wordcount_direct.txt*
 else
@@ -223,8 +163,7 @@ python -m apache_beam.examples.wordcount \
 # verify results.
 wordcount_output_in_gcs="gs://$BUCKET_NAME/$WORDCOUNT_OUTPUT"
 gcs_pull_result=$(gsutil ls gs://$BUCKET_NAME)
-if [[ $gcs_pull_result != *$wordcount_output_in_gcs* ]]
-then
+if [[ $gcs_pull_result != *$wordcount_output_in_gcs* ]]; then
     echo "ERROR: The wordcount example failed on DataflowRunner".
     complete "failed when running wordcount example with DataflowRunner."
     exit 1
@@ -289,4 +228,4 @@ kill -9 $pid
 gcloud dataflow jobs cancel $running_job
 cleanup_pubsub
 
-complete "Succeed"
+complete "SUCCEED: Quickstart Verification Complete"


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 82412)
    Time Spent: 20.5h  (was: 20h 20m)

> Get Python Mobile-Gaming Running on Core Runners
> ------------------------------------------------
>
>                 Key: BEAM-3840
>                 URL: https://issues.apache.org/jira/browse/BEAM-3840
>             Project: Beam
>          Issue Type: Sub-task
>          Components: examples-python
>    Affects Versions: 2.5.0
>            Reporter: yifan zou
>            Assignee: yifan zou
>            Priority: Major
>             Fix For: 2.5.0
>
>          Time Spent: 20.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to