From ae18de62a78ec46a878da0cc01a45bfdc224c136 Mon Sep 17 00:00:00 2001 From: jiangmichaellll <40044148+jiangmichaellll@users.noreply.github.com> Date: Fri, 12 Feb 2021 12:22:37 -0500 Subject: [PATCH] docs: update readme and other minor nits (#77) --- samples/README.md | 8 ++++---- .../main/java/pubsublite/spark/AdminUtils.java | 16 ++++++++++++---- .../main/java/pubsublite/spark/PublishWords.java | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/samples/README.md b/samples/README.md index d6fde817..cdd24b3b 100644 --- a/samples/README.md +++ b/samples/README.md @@ -27,7 +27,7 @@ PUBSUBLITE_SPARK_SQL_STREAMING_JAR_LOCATION= # downloaded pubsublite-spark-sql-s To run the word count sample in Dataproc cluster, follow the steps: -1. `cd samples/` +1. `cd samples/snippets` 2. Set the current sample version. ```sh SAMPLE_VERSION=$(mvn -q \ @@ -59,7 +59,7 @@ To run the word count sample in Dataproc cluster, follow the steps: 7. Create GCS bucket and upload both `pubsublite-spark-sql-streaming-$CONNECTOR_VERSION-with-dependencies.jar` and the sample jar onto GCS ```sh gsutil mb $BUCKET - gsutil cp snapshot/target/pubsublite-spark-snapshot-$SAMPLE_VERSION.jar $BUCKET + gsutil cp target/pubsublite-spark-snippets-$SAMPLE_VERSION.jar $BUCKET gsutil cp $PUBSUBLITE_SPARK_SQL_STREAMING_JAR_LOCATION $BUCKET ``` 8. Set Dataproc region @@ -70,14 +70,14 @@ To run the word count sample in Dataproc cluster, follow the steps: 9. Run the sample in Dataproc. You would see the word count result show up in the console output. ```sh gcloud dataproc jobs submit spark --cluster=$CLUSTER_NAME \ - --jars=$BUCKET/pubsublite-spark-snapshot-$SAMPLE_VERSION.jar,$BUCKET/pubsublite-spark-sql-streaming-$CONNECTOR_VERSION-with-dependencies.jar \ + --jars=$BUCKET/pubsublite-spark-snippets-$SAMPLE_VERSION.jar,$BUCKET/pubsublite-spark-sql-streaming-$CONNECTOR_VERSION-with-dependencies.jar \ --class=pubsublite.spark.WordCount -- $SUBSCRIPTION_PATH ``` ## Cleaning up 1. Delete Pub/Sub Lite topic and subscription. ```sh - gcloud pubsub lite-subscriptions delete $SUBSCRIPTION_ID --zone=$REGION-$ZONE_ID= + gcloud pubsub lite-subscriptions delete $SUBSCRIPTION_ID --zone=$REGION-$ZONE_ID gcloud pubsub lite-topics delete $TOPIC_ID --zone=$REGION-$ZONE_ID ``` 2. Delete GCS bucket. diff --git a/samples/snippets/src/main/java/pubsublite/spark/AdminUtils.java b/samples/snippets/src/main/java/pubsublite/spark/AdminUtils.java index 3e969d90..8a284905 100644 --- a/samples/snippets/src/main/java/pubsublite/spark/AdminUtils.java +++ b/samples/snippets/src/main/java/pubsublite/spark/AdminUtils.java @@ -85,8 +85,12 @@ public static void createTopicExample( try (AdminClient adminClient = AdminClient.create(adminClientSettings)) { Topic response = adminClient.createTopic(topic).get(); System.out.println(response.getAllFields() + "created successfully."); - } catch (AlreadyExistsException e) { - System.out.println(topicPath + " already exists"); + } catch (ExecutionException e) { + if (e.getCause() instanceof AlreadyExistsException) { + System.out.println(topicPath + " already exists"); + } else { + throw e; + } } } @@ -130,8 +134,12 @@ public static void createSubscriptionExample( try (AdminClient adminClient = AdminClient.create(adminClientSettings)) { Subscription response = adminClient.createSubscription(subscription).get(); System.out.println(response.getAllFields() + "created successfully."); - } catch (AlreadyExistsException e) { - System.out.println(subscriptionPath + " already exists"); + } catch (ExecutionException e) { + if (e.getCause() instanceof AlreadyExistsException) { + System.out.println(topicPath + " already exists"); + } else { + throw e; + } } } diff --git a/samples/snippets/src/main/java/pubsublite/spark/PublishWords.java b/samples/snippets/src/main/java/pubsublite/spark/PublishWords.java index 5b2c9e9c..5845d2d6 100644 --- a/samples/snippets/src/main/java/pubsublite/spark/PublishWords.java +++ b/samples/snippets/src/main/java/pubsublite/spark/PublishWords.java @@ -70,5 +70,7 @@ public static void main(String[] args) throws Exception { createSubscriptionExample(cloudRegion, zoneId, projectNumber, topicId, subscriptionId); publisherExample(cloudRegion, zoneId, projectNumber, topicId, words); + + System.exit(0); } }