Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-8119] Properly cleanup Pubsub in release script #9534

Merged
merged 1 commit into from Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -218,9 +218,10 @@ function create_pubsub() {
# 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
# Suppress error since topic/subscription may not exist
gcloud pubsub topics delete --project=$PROJECT_ID $PUBSUB_TOPIC1 2> /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also suppress standard output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no message to stdout by calling gcloud pubsub topics create/delete (whether succeeds or not).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If succeed, it will show messages like
"Created topic [projects/apache-beam-testing/topics/wordstream-python-topic-1]."
"Deleted topic [projects/apache-beam-testing/topics/wordstream-python-topic-1]."

If fail, it will raise something like "ERROR: The topic XXXX does not exist".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, those messages go to standard error which is suppressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the main purpose to suppress stderr here is not to break the script. Messages in stdout can help people know the status of current step.

gcloud pubsub topics delete --project=$PROJECT_ID $PUBSUB_TOPIC2 2> /dev/null
gcloud pubsub subscriptions delete --project=$PROJECT_ID $PUBSUB_SUBSCRIPTION 2> /dev/null
}


Expand Down
Expand Up @@ -37,6 +37,9 @@ BEAM_PYTHON_SDK=$BEAM_PYTHON_SDK_ZIP
ASC_FILE_NAME=$BEAM_PYTHON_SDK_ZIP".asc"
SHA512_FILE_NAME=$BEAM_PYTHON_SDK_ZIP".sha512"

# Cleanup Pubsub once script exits
trap cleanup_pubsub EXIT


#######################################
# Remove temp directory when complete.
Expand Down Expand Up @@ -116,7 +119,7 @@ function verify_wordcount_dataflow() {
--num_workers $NUM_WORKERS \
--sdk_location $BEAM_PYTHON_SDK

# verify results.
# 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
Expand All @@ -139,6 +142,7 @@ function verify_wordcount_dataflow() {
# None
#######################################
function verify_streaming_wordcount_direct() {
cleanup_pubsub
markflyhigh marked this conversation as resolved.
Show resolved Hide resolved
create_pubsub
print_separator "Running Streaming wordcount example with DirectRunner"
python -m apache_beam.examples.streaming_wordcount \
Expand All @@ -148,12 +152,10 @@ function verify_streaming_wordcount_direct() {
pid=$!
sleep 15

# verify result
# verify result
run_pubsub_publish
verify_steaming_result "DirectRunner" $pid

# Delete the pubsub topics and subscription before running the second job. Will recreate them in the second job.
cleanup_pubsub
kill -9 $pid
sleep 10
}
Expand All @@ -168,6 +170,7 @@ function verify_streaming_wordcount_direct() {
# None
#######################################
function verify_streaming_wordcount_dataflow() {
cleanup_pubsub
create_pubsub
print_separator "Running Streaming wordcount example with DataflowRunner "
python -m apache_beam.examples.streaming_wordcount \
Expand All @@ -193,7 +196,6 @@ function verify_streaming_wordcount_dataflow() {

kill -9 $pid
gcloud dataflow jobs cancel $running_job
cleanup_pubsub
}


Expand Down