From ed4e29ac88250646b763dc85e1ad074b68f4285a Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Thu, 5 Oct 2023 18:01:53 +0000 Subject: [PATCH 01/12] docs: Adding a GCS subscription example --- ...CreateCloudStorageSubscriptionExample.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java new file mode 100644 index 000000000..bf5ca1ece --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -0,0 +1,63 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed 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. + */ + +package pubsub; + +// [START pubsub_create_cloud_storage_subscription] +import com.google.cloud.pubsub.v1.SubscriptionAdminClient; +import com.google.pubsub.v1.CloudStorageConfig; +import com.google.pubsub.v1.ProjectSubscriptionName; +import com.google.pubsub.v1.ProjectTopicName; +import com.google.pubsub.v1.Subscription; +import com.google.pubsub.v1.AvroConfig; +import java.io.IOException; + +public class CreateCloudStorageSubscriptionExample { + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String topicId = "your-topic-id"; + String subscriptionId = "your-subscription-id"; + String bucket = "your-bucket"; + + createCloudStorageSubscription(projectId, topicId, subscriptionId, bucket); + } + + public static void createCloudStorageSubscription( + String projectId, String topicId, String subscriptionId, String bucket) + throws IOException { + try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { + + ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId); + ProjectSubscriptionName subscriptionName = + ProjectSubscriptionName.of(projectId, subscriptionId); + + CloudStorageConfig cloudStorageConfig = + CloudStorageConfig.newBuilder().setBucket(bucket).build(); + + Subscription subscription = + subscriptionAdminClient.createSubscription( + Subscription.newBuilder() + .setName(subscriptionName.toString()) + .setTopic(topicName.toString()) + .setCloudStorageConfig(cloudStorageConfig) + .build()); + + System.out.println("Created a CloudStorage subscription: " + subscription.getAllFields()); + } + } +} +// [END pubsub_create_cloud_storage_subscription] From 4dbf9ceaa9b3d0874a19fc0bebcd9a21c4da6d77 Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Thu, 5 Oct 2023 18:39:51 +0000 Subject: [PATCH 02/12] removing the avro imoprt --- .../main/java/pubsub/CreateCloudStorageSubscriptionExample.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java index bf5ca1ece..1707d9ddf 100644 --- a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -22,7 +22,6 @@ import com.google.pubsub.v1.ProjectSubscriptionName; import com.google.pubsub.v1.ProjectTopicName; import com.google.pubsub.v1.Subscription; -import com.google.pubsub.v1.AvroConfig; import java.io.IOException; public class CreateCloudStorageSubscriptionExample { From 669718e0d290ed3e8d8a4c386a5be7bf2d37a72e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 5 Oct 2023 19:23:38 +0000 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 1 + .../java/pubsub/CreateCloudStorageSubscriptionExample.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 44052f52e..e35541494 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-pubsub/tree/m | Commit Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java) | | Create Avro Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java) | | Create Big Query Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateBigQuerySubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateBigQuerySubscriptionExample.java) | +| Create Cloud Storage Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java) | | Create Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) | | Create Pull Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | | Create Push No Wrapper Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java) | diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java index 1707d9ddf..867ede058 100644 --- a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -36,8 +36,7 @@ public static void main(String... args) throws Exception { } public static void createCloudStorageSubscription( - String projectId, String topicId, String subscriptionId, String bucket) - throws IOException { + String projectId, String topicId, String subscriptionId, String bucket) throws IOException { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId); From 4a33f0cdcf70cffe93f4fdf3d4e97ffc97616547 Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Fri, 13 Oct 2023 14:52:19 +0000 Subject: [PATCH 04/12] adding optional GCS Configurations as well --- .../CreateCloudStorageSubscriptionExample.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java index 1707d9ddf..bcbf6e0bf 100644 --- a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -31,12 +31,16 @@ public static void main(String... args) throws Exception { String topicId = "your-topic-id"; String subscriptionId = "your-subscription-id"; String bucket = "your-bucket"; + String filenamePrefix = "log_events_"; + String filenameSuffix = ".text"; - createCloudStorageSubscription(projectId, topicId, subscriptionId, bucket); + createCloudStorageSubscription(projectId, topicId, subscriptionId, bucket, filenamePrefix, + filenameSuffix); } public static void createCloudStorageSubscription( - String projectId, String topicId, String subscriptionId, String bucket) + String projectId, String topicId, String subscriptionId, String bucket, String filenamePrefix, + String filenameSuffix) throws IOException { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { @@ -45,7 +49,10 @@ public static void createCloudStorageSubscription( ProjectSubscriptionName.of(projectId, subscriptionId); CloudStorageConfig cloudStorageConfig = - CloudStorageConfig.newBuilder().setBucket(bucket).build(); + CloudStorageConfig.newBuilder().setBucket(bucket) + .setFilenamePrefix(filenamePrefix) + .setFilenameSuffix(filenameSuffix) + .build(); Subscription subscription = subscriptionAdminClient.createSubscription( From 7809e1dc6476769f9edd5e4c35b43651f276ca51 Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Fri, 13 Oct 2023 15:41:13 +0000 Subject: [PATCH 05/12] adding test case --- samples/install-without-bom/pom.xml | 5 +++ samples/snapshot/pom.xml | 5 +++ samples/snippets/pom.xml | 4 ++ .../src/test/java/pubsub/AdminIT.java | 41 +++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index e76fdeee0..3513cecf1 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -88,6 +88,11 @@ google-cloud-bigquery 2.33.1 + + com.google.cloud + google-cloud-storage + 2.28.0 + diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 4ff513287..87d443cf2 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -87,6 +87,11 @@ google-cloud-bigquery 2.33.1 + + com.google.cloud + google-cloud-storage + 2.28.0 + diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 7ffe9b828..fafda4479 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -63,6 +63,10 @@ com.google.cloud google-cloud-bigquery + + com.google.cloud + google-cloud-storage + org.apache.avro avro diff --git a/samples/snippets/src/test/java/pubsub/AdminIT.java b/samples/snippets/src/test/java/pubsub/AdminIT.java index e42c81290..82ea8a39d 100644 --- a/samples/snippets/src/test/java/pubsub/AdminIT.java +++ b/samples/snippets/src/test/java/pubsub/AdminIT.java @@ -44,6 +44,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; +import com.google.cloud.storage.Bucket; +import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageClass; +import com.google.cloud.storage.StorageOptions; public class AdminIT { private ByteArrayOutputStream bout; @@ -64,6 +69,11 @@ public class AdminIT { private static final String bigquerySubscriptionId = "iam-bigquery-subscription-" + _suffix; private static final String bigqueryTableId = "java_samples_table_" + _suffix; + private static final String cloudStorageSubscriptionId = "iam-cloudstorage-subscription-" + _suffix; + private static final String cloudStorageBucketName = "java_samples_gcs_bucket_" + _suffix; + private static final String cloudStorageFilenamePrefix = "log_events_"; + private static final String cloudStorageFilenameSuffix = ".text"; + private static final TopicName topicName = TopicName.of(projectId, topicId); private static final SubscriptionName pullSubscriptionName = SubscriptionName.of(projectId, pullSubscriptionId); @@ -97,6 +107,9 @@ public void setUp() throws Exception { // Create table for BigQuery subscription. createBigQueryTable(); + + // Create bucket for CloudStorage subscription + createCloudStorageBucket(); } @After @@ -124,6 +137,9 @@ public void tearDown() throws Exception { // Delete BigQuery table. deleteBigQueryTable(); + //Delete GCS Bucket + deleteCloudStorageBucket(); + System.setOut(null); } @@ -153,6 +169,22 @@ private void deleteBigQueryTable() throws Exception { bigquery.delete(datasetId, BigQuery.DatasetDeleteOption.deleteContents()); } + private void createCloudStorageBucket() throws Exception { + Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); + String location = "ASIA"; + Bucket bucket = + storage.create( + BucketInfo.newBuilder(cloudStorageBucketName) + .setLocation(location) + .build()); + } + + private void deleteCloudStorageBucket() throws Exception { + Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); + Bucket bucket = storage.get(cloudStorageBucketName); + bucket.delete(); + } + @Test public void testAdmin() throws Exception { // Test create topic. @@ -264,6 +296,14 @@ public void testAdmin() throws Exception { assertThat(bout.toString()).contains("Created a BigQuery subscription:"); assertThat(bout.toString()).contains(bigqueryTablePath); + bout.reset(); + // Test create a CloudStorage susbscription + CreateCloudStorageSubscriptionExample.createCloudStorageSubscription( + projectId, topicId, cloudStorageSubscriptionId, cloudStorageBucketName, + cloudStorageFilenamePrefix, cloudStorageFilenameSuffix); + assertThat(bout.toString()).contains("Created a CloudStorage subscription:"); + assertThat(bout.toString()).contains(cloudStorageBucketName); + bout.reset(); // Test delete subscription. DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pullSubscriptionId); @@ -271,6 +311,7 @@ public void testAdmin() throws Exception { DeleteSubscriptionExample.deleteSubscriptionExample(projectId, orderedSubscriptionId); DeleteSubscriptionExample.deleteSubscriptionExample(projectId, exactlyOnceSubscriptionId); DeleteSubscriptionExample.deleteSubscriptionExample(projectId, bigquerySubscriptionId); + DeleteSubscriptionExample.deleteSubscriptionExample(projectId, cloudStorageSubscriptionId); assertThat(bout.toString()).contains("Deleted subscription."); bout.reset(); From f413be877de73b8c6a48138e823a652c9bdd73ba Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Fri, 13 Oct 2023 15:55:44 +0000 Subject: [PATCH 06/12] fixing lint --- samples/snippets/src/test/java/pubsub/AdminIT.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/samples/snippets/src/test/java/pubsub/AdminIT.java b/samples/snippets/src/test/java/pubsub/AdminIT.java index 82ea8a39d..c5011742d 100644 --- a/samples/snippets/src/test/java/pubsub/AdminIT.java +++ b/samples/snippets/src/test/java/pubsub/AdminIT.java @@ -33,6 +33,11 @@ import com.google.cloud.bigquery.TableInfo; import com.google.cloud.pubsub.v1.SubscriptionAdminClient; import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.cloud.storage.Bucket; +import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageClass; +import com.google.cloud.storage.StorageOptions; import com.google.pubsub.v1.SubscriptionName; import com.google.pubsub.v1.TopicName; import java.io.ByteArrayOutputStream; @@ -44,11 +49,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; -import com.google.cloud.storage.Bucket; -import com.google.cloud.storage.BucketInfo; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageClass; -import com.google.cloud.storage.StorageOptions; public class AdminIT { private ByteArrayOutputStream bout; @@ -69,7 +69,8 @@ public class AdminIT { private static final String bigquerySubscriptionId = "iam-bigquery-subscription-" + _suffix; private static final String bigqueryTableId = "java_samples_table_" + _suffix; - private static final String cloudStorageSubscriptionId = "iam-cloudstorage-subscription-" + _suffix; + private static final String cloudStorageSubscriptionId = + "iam-cloudstorage-subscription-" + _suffix; private static final String cloudStorageBucketName = "java_samples_gcs_bucket_" + _suffix; private static final String cloudStorageFilenamePrefix = "log_events_"; private static final String cloudStorageFilenameSuffix = ".text"; From cfa80e07e858900b3a060a5db754be7bd3d5732a Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Tue, 24 Oct 2023 15:47:33 +0000 Subject: [PATCH 07/12] Removing Testcase --- .../src/test/java/pubsub/AdminIT.java | 47 ++----------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/samples/snippets/src/test/java/pubsub/AdminIT.java b/samples/snippets/src/test/java/pubsub/AdminIT.java index c5011742d..9350d2c59 100644 --- a/samples/snippets/src/test/java/pubsub/AdminIT.java +++ b/samples/snippets/src/test/java/pubsub/AdminIT.java @@ -33,11 +33,6 @@ import com.google.cloud.bigquery.TableInfo; import com.google.cloud.pubsub.v1.SubscriptionAdminClient; import com.google.cloud.pubsub.v1.TopicAdminClient; -import com.google.cloud.storage.Bucket; -import com.google.cloud.storage.BucketInfo; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageClass; -import com.google.cloud.storage.StorageOptions; import com.google.pubsub.v1.SubscriptionName; import com.google.pubsub.v1.TopicName; import java.io.ByteArrayOutputStream; @@ -49,6 +44,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; +import com.google.cloud.storage.Bucket; +import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageClass; +import com.google.cloud.storage.StorageOptions; public class AdminIT { private ByteArrayOutputStream bout; @@ -69,12 +69,6 @@ public class AdminIT { private static final String bigquerySubscriptionId = "iam-bigquery-subscription-" + _suffix; private static final String bigqueryTableId = "java_samples_table_" + _suffix; - private static final String cloudStorageSubscriptionId = - "iam-cloudstorage-subscription-" + _suffix; - private static final String cloudStorageBucketName = "java_samples_gcs_bucket_" + _suffix; - private static final String cloudStorageFilenamePrefix = "log_events_"; - private static final String cloudStorageFilenameSuffix = ".text"; - private static final TopicName topicName = TopicName.of(projectId, topicId); private static final SubscriptionName pullSubscriptionName = SubscriptionName.of(projectId, pullSubscriptionId); @@ -108,9 +102,6 @@ public void setUp() throws Exception { // Create table for BigQuery subscription. createBigQueryTable(); - - // Create bucket for CloudStorage subscription - createCloudStorageBucket(); } @After @@ -138,9 +129,6 @@ public void tearDown() throws Exception { // Delete BigQuery table. deleteBigQueryTable(); - //Delete GCS Bucket - deleteCloudStorageBucket(); - System.setOut(null); } @@ -170,22 +158,6 @@ private void deleteBigQueryTable() throws Exception { bigquery.delete(datasetId, BigQuery.DatasetDeleteOption.deleteContents()); } - private void createCloudStorageBucket() throws Exception { - Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); - String location = "ASIA"; - Bucket bucket = - storage.create( - BucketInfo.newBuilder(cloudStorageBucketName) - .setLocation(location) - .build()); - } - - private void deleteCloudStorageBucket() throws Exception { - Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); - Bucket bucket = storage.get(cloudStorageBucketName); - bucket.delete(); - } - @Test public void testAdmin() throws Exception { // Test create topic. @@ -297,14 +269,6 @@ public void testAdmin() throws Exception { assertThat(bout.toString()).contains("Created a BigQuery subscription:"); assertThat(bout.toString()).contains(bigqueryTablePath); - bout.reset(); - // Test create a CloudStorage susbscription - CreateCloudStorageSubscriptionExample.createCloudStorageSubscription( - projectId, topicId, cloudStorageSubscriptionId, cloudStorageBucketName, - cloudStorageFilenamePrefix, cloudStorageFilenameSuffix); - assertThat(bout.toString()).contains("Created a CloudStorage subscription:"); - assertThat(bout.toString()).contains(cloudStorageBucketName); - bout.reset(); // Test delete subscription. DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pullSubscriptionId); @@ -312,7 +276,6 @@ public void testAdmin() throws Exception { DeleteSubscriptionExample.deleteSubscriptionExample(projectId, orderedSubscriptionId); DeleteSubscriptionExample.deleteSubscriptionExample(projectId, exactlyOnceSubscriptionId); DeleteSubscriptionExample.deleteSubscriptionExample(projectId, bigquerySubscriptionId); - DeleteSubscriptionExample.deleteSubscriptionExample(projectId, cloudStorageSubscriptionId); assertThat(bout.toString()).contains("Deleted subscription."); bout.reset(); From c690f8a46d8be40a077d7d52d2e8e928dd83c273 Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Tue, 24 Oct 2023 15:48:25 +0000 Subject: [PATCH 08/12] Removing Testcase --- samples/snippets/src/test/java/pubsub/AdminIT.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/samples/snippets/src/test/java/pubsub/AdminIT.java b/samples/snippets/src/test/java/pubsub/AdminIT.java index 9350d2c59..e42c81290 100644 --- a/samples/snippets/src/test/java/pubsub/AdminIT.java +++ b/samples/snippets/src/test/java/pubsub/AdminIT.java @@ -44,11 +44,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; -import com.google.cloud.storage.Bucket; -import com.google.cloud.storage.BucketInfo; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageClass; -import com.google.cloud.storage.StorageOptions; public class AdminIT { private ByteArrayOutputStream bout; From 1408dc1519d9d7f43790777de36262214fa9b1f0 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 24 Oct 2023 16:04:44 +0000 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../CreateCloudStorageSubscriptionExample.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java index fd23dd3e1..3975ff0c0 100644 --- a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -34,13 +34,18 @@ public static void main(String... args) throws Exception { String filenamePrefix = "log_events_"; String filenameSuffix = ".text"; - createCloudStorageSubscription(projectId, topicId, subscriptionId, bucket, filenamePrefix, - filenameSuffix); + createCloudStorageSubscription( + projectId, topicId, subscriptionId, bucket, filenamePrefix, filenameSuffix); } public static void createCloudStorageSubscription( - String projectId, String topicId, String subscriptionId, String bucket, String filenamePrefix, - String filenameSuffix) throws IOException { + String projectId, + String topicId, + String subscriptionId, + String bucket, + String filenamePrefix, + String filenameSuffix) + throws IOException { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId); @@ -48,7 +53,8 @@ public static void createCloudStorageSubscription( ProjectSubscriptionName.of(projectId, subscriptionId); CloudStorageConfig cloudStorageConfig = - CloudStorageConfig.newBuilder().setBucket(bucket) + CloudStorageConfig.newBuilder() + .setBucket(bucket) .setFilenamePrefix(filenamePrefix) .setFilenameSuffix(filenameSuffix) .build(); From 6ad15475185df19ee1f04d8f76432e365fba80fd Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Thu, 26 Oct 2023 19:01:58 +0000 Subject: [PATCH 10/12] added max duration example --- .../java/pubsub/CreateCloudStorageSubscriptionExample.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java index fd23dd3e1..a82eb939f 100644 --- a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -23,6 +23,7 @@ import com.google.pubsub.v1.ProjectTopicName; import com.google.pubsub.v1.Subscription; import java.io.IOException; +import com.google.protobuf.Duration; public class CreateCloudStorageSubscriptionExample { public static void main(String... args) throws Exception { @@ -33,14 +34,15 @@ public static void main(String... args) throws Exception { String bucket = "your-bucket"; String filenamePrefix = "log_events_"; String filenameSuffix = ".text"; + Duration maxDuration = Duration.newBuilder().setSeconds(300).build(); createCloudStorageSubscription(projectId, topicId, subscriptionId, bucket, filenamePrefix, - filenameSuffix); + filenameSuffix, maxDuration); } public static void createCloudStorageSubscription( String projectId, String topicId, String subscriptionId, String bucket, String filenamePrefix, - String filenameSuffix) throws IOException { + String filenameSuffix, Duration maxDuration) throws IOException { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId); @@ -51,6 +53,7 @@ public static void createCloudStorageSubscription( CloudStorageConfig.newBuilder().setBucket(bucket) .setFilenamePrefix(filenamePrefix) .setFilenameSuffix(filenameSuffix) + .setMaxDuration(maxDuration) .build(); Subscription subscription = From fb7371b1578b244e0bd2c1f822c0adef6f9ffb7e Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Thu, 26 Oct 2023 19:11:52 +0000 Subject: [PATCH 11/12] merge conflicts --- .../main/java/pubsub/CreateCloudStorageSubscriptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java index 64b322806..34d98ae96 100644 --- a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -18,12 +18,12 @@ // [START pubsub_create_cloud_storage_subscription] import com.google.cloud.pubsub.v1.SubscriptionAdminClient; +import com.google.protobuf.Duration; import com.google.pubsub.v1.CloudStorageConfig; import com.google.pubsub.v1.ProjectSubscriptionName; import com.google.pubsub.v1.ProjectTopicName; import com.google.pubsub.v1.Subscription; import java.io.IOException; -import com.google.protobuf.Duration; public class CreateCloudStorageSubscriptionExample { public static void main(String... args) throws Exception { From 89a03fb17121ff2831a98cd180d8d7dad311b73b Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 27 Oct 2023 17:35:24 +0000 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 2 +- .../CreateCloudStorageSubscriptionExample.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1627f7d6d..7f0e4ad6e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.25.0') +implementation platform('com.google.cloud:libraries-bom:26.26.0') implementation 'com.google.cloud:google-cloud-pubsub' ``` diff --git a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java index 34d98ae96..654ba3857 100644 --- a/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java @@ -36,13 +36,19 @@ public static void main(String... args) throws Exception { String filenameSuffix = ".text"; Duration maxDuration = Duration.newBuilder().setSeconds(300).build(); - createCloudStorageSubscription(projectId, topicId, subscriptionId, bucket, filenamePrefix, - filenameSuffix, maxDuration); + createCloudStorageSubscription( + projectId, topicId, subscriptionId, bucket, filenamePrefix, filenameSuffix, maxDuration); } public static void createCloudStorageSubscription( - String projectId, String topicId, String subscriptionId, String bucket, String filenamePrefix, - String filenameSuffix, Duration maxDuration) throws IOException { + String projectId, + String topicId, + String subscriptionId, + String bucket, + String filenamePrefix, + String filenameSuffix, + Duration maxDuration) + throws IOException { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);