From ab102630bb3db277a0810c44b05100114e128e44 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 20 Nov 2017 17:01:12 -0800 Subject: [PATCH] Moving off some deprecated stuff (#2640) --- .../java/com/google/cloud/AsyncPageImpl.java | 3 ++- .../CreateSubscriptionAndConsumeMessages.java | 4 +-- .../CreateTopicAndPublishMessages.java | 4 +-- .../pubsub/snippets/PublisherSnippets.java | 2 +- .../pubsub/snippets/SubscriberSnippets.java | 4 +-- .../SubscriptionAdminClientSnippets.java | 22 +++++++-------- .../snippets/TopicAdminClientSnippets.java | 16 +++++------ .../snippets/UsePubSubEmulatorSnippet.java | 2 +- .../examples/storage/StorageExample.java | 6 +++-- .../examples/pubsub/snippets/Cleanup.java | 4 +-- .../pubsub/snippets/ITPubSubSnippets.java | 4 +-- .../ITSubscriptionAdminClientSnippets.java | 2 +- .../snippets/ITTopicAdminClientSnippets.java | 4 +-- .../google/cloud/firestore/FirestoreImpl.java | 2 +- .../google/cloud/firestore/ResourcePath.java | 2 +- .../spi/v1beta1/GrpcFirestoreRpc.java | 2 +- .../cloud/firestore/LocalFirestoreHelper.java | 2 +- .../com/google/cloud/logging/LogEntry.java | 2 +- .../com/google/cloud/logging/LoggingImpl.java | 27 ++++++++++--------- .../google/cloud/logging/BaseSystemTest.java | 8 +++--- .../google/cloud/pubsub/it/ITPubSubTest.java | 6 ++--- .../cloud/pubsub/v1/PublisherImplTest.java | 2 +- .../cloud/pubsub/v1/SubscriberTest.java | 2 +- .../AbstractStructReaderTypesTest.java | 6 +++-- 24 files changed, 72 insertions(+), 66 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java index 8048b9e18f88..643fe0b21d56 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java +++ b/google-cloud-core/src/main/java/com/google/cloud/AsyncPageImpl.java @@ -64,7 +64,8 @@ public Page getNextPage() { return asyncPageFetcher != null ? Uninterruptibles.getUninterruptibly(asyncPageFetcher.getNextPage()) : null; } catch (ExecutionException ex) { - throw Throwables.propagate(ex.getCause()); + Throwables.throwIfUnchecked(ex.getCause()); + throw new RuntimeException(ex); } } } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java index 6300149543b8..5910a2bd2282 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java @@ -33,8 +33,8 @@ public class CreateSubscriptionAndConsumeMessages { public static void main(String... args) throws Exception { - TopicName topic = TopicName.create("my-project-id", "my-topic-id"); - SubscriptionName subscription = SubscriptionName.create("my-project-id", "my-topic-id"); + TopicName topic = TopicName.of("my-project-id", "my-topic-id"); + SubscriptionName subscription = SubscriptionName.of("my-project-id", "my-topic-id"); try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { subscriptionAdminClient.createSubscription(subscription, topic, PushConfig.getDefaultInstance(), 0); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java index 085649f090d9..84c6c6f1c225 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java @@ -34,7 +34,7 @@ public class CreateTopicAndPublishMessages { public static void createTopic() throws Exception { - TopicName topic = TopicName.create("my-project-id", "my-topic-id"); + TopicName topic = TopicName.of("my-project-id", "my-topic-id"); try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { topicAdminClient.createTopic(topic); } @@ -42,7 +42,7 @@ public static void createTopic() throws Exception { public static void publishMessages() throws Exception { // [START pubsub_publish] - TopicName topicName = TopicName.create("my-project-id", "my-topic-id"); + TopicName topicName = TopicName.of("my-project-id", "my-topic-id"); Publisher publisher = null; List> messageIdFutures = new ArrayList<>(); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherSnippets.java index 073c2f5d9cfd..f3518e258c02 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PublisherSnippets.java @@ -71,7 +71,7 @@ public void onFailure(Throwable t) { // [VARIABLE "my_project"] // [VARIABLE "my_topic"] public static void newBuilder(String projectId, String topicId) throws Exception { - TopicName topic = TopicName.create(projectId, topicId); + TopicName topic = TopicName.of(projectId, topicId); Publisher publisher = Publisher.newBuilder(topic).build(); try { // ... diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java index d099e8c1c394..40c99722312d 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java @@ -94,7 +94,7 @@ private void createSubscriber() throws Exception { String projectId = "my-project-id"; String subscriptionId = "my-subscription-id"; - SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); + SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); // Instantiate an asynchronous message receiver MessageReceiver receiver = new MessageReceiver() { @@ -186,7 +186,7 @@ static List createSubscriberWithSyncPull( // String projectId = "my-project-id"; // String subscriptionId = "my-subscription-id"; // int numOfMessages = 10; // max number of messages to be pulled - String subscriptionName = SubscriptionName.create(projectId, subscriptionId).toString(); + String subscriptionName = SubscriptionName.of(projectId, subscriptionId).toString(); PullRequest pullRequest = PullRequest.newBuilder() .setMaxMessages(numOfMessages) diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionAdminClientSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionAdminClientSnippets.java index 2c9528a86e38..9deaa9b97ab6 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionAdminClientSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionAdminClientSnippets.java @@ -54,10 +54,10 @@ public Subscription createSubscription(String topicId, String subscriptionId) th // [START pubsub_create_pull_subscription] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { // eg. projectId = "my-test-project", topicId = "my-test-topic" - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); // eg. subscriptionId = "my-test-subscription" SubscriptionName subscriptionName = - SubscriptionName.create(projectId, subscriptionId); + SubscriptionName.of(projectId, subscriptionId); // create a pull subscription with default acknowledgement deadline Subscription subscription = subscriptionAdminClient.createSubscription( @@ -73,9 +73,9 @@ public Subscription createSubscriptionWithPushEndpoint(String topicId, String su throws Exception { // [START pubsub_create_push_subscription] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); SubscriptionName subscriptionName = - SubscriptionName.create(projectId, subscriptionId); + SubscriptionName.of(projectId, subscriptionId); // eg. endpoint = "https://my-test-project.appspot.com/push" PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build(); @@ -95,7 +95,7 @@ public Subscription createSubscriptionWithPushEndpoint(String topicId, String su public void replacePushConfig(String subscriptionId, String endpoint) throws Exception { // [START pubsub_update_push_configuration] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { - SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); + SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build(); subscriptionAdminClient.modifyPushConfig(subscriptionName, pushConfig); } @@ -108,7 +108,7 @@ public ListSubscriptionsPagedResponse listSubscriptions() throws Exception { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { ListSubscriptionsRequest listSubscriptionsRequest = ListSubscriptionsRequest.newBuilder() - .setProjectWithProjectName(ProjectName.create(projectId)) + .setProjectWithProjectName(ProjectName.of(projectId)) .build(); ListSubscriptionsPagedResponse response = subscriptionAdminClient.listSubscriptions(listSubscriptionsRequest); @@ -125,7 +125,7 @@ public ListSubscriptionsPagedResponse listSubscriptions() throws Exception { public SubscriptionName deleteSubscription(String subscriptionId) throws Exception { // [START pubsub_delete_subscription] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { - SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); + SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); subscriptionAdminClient.deleteSubscription(subscriptionName); return subscriptionName; } @@ -136,7 +136,7 @@ public SubscriptionName deleteSubscription(String subscriptionId) throws Excepti public Policy getSubscriptionPolicy(String subscriptionId) throws Exception { // [START pubsub_get_subscription_policy] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { - SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); + SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); Policy policy = subscriptionAdminClient.getIamPolicy(subscriptionName.toString()); if (policy == null) { // subscription was not found @@ -150,7 +150,7 @@ public Policy getSubscriptionPolicy(String subscriptionId) throws Exception { public Policy replaceSubscriptionPolicy(String subscriptionId) throws Exception { // [START pubsub_set_subscription_policy] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { - SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); + SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); Policy policy = subscriptionAdminClient.getIamPolicy(subscriptionName.toString()); // Create a role => members binding Binding binding = @@ -174,7 +174,7 @@ public TestIamPermissionsResponse testSubscriptionPermissions(String subscriptio try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { List permissions = new LinkedList<>(); permissions.add("pubsub.subscriptions.get"); - SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); + SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); TestIamPermissionsResponse testedPermissions = topicAdminClient.testIamPermissions(subscriptionName.toString(), permissions); return testedPermissions; @@ -186,7 +186,7 @@ public TestIamPermissionsResponse testSubscriptionPermissions(String subscriptio public Subscription getSubscription(String subscriptionId) throws Exception { // [START pubsub_get_subscription] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { - SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId); + SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); Subscription subscription = subscriptionAdminClient.getSubscription(subscriptionName); return subscription; } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicAdminClientSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicAdminClientSnippets.java index c9c53b0086e1..47ae689d347d 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicAdminClientSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicAdminClientSnippets.java @@ -52,7 +52,7 @@ public Topic createTopic(String topicId) throws Exception { try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { // projectId <= unique project identifier, eg. "my-project-id" // topicId <= "my-topic-id" - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); Topic topic = topicAdminClient.createTopic(topicName); return topic; } @@ -65,7 +65,7 @@ public ListTopicsPagedResponse listTopics() throws Exception { try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { ListTopicsRequest listTopicsRequest = ListTopicsRequest.newBuilder() - .setProjectWithProjectName(ProjectName.create(projectId)) + .setProjectWithProjectName(ProjectName.of(projectId)) .build(); ListTopicsPagedResponse response = topicAdminClient.listTopics(listTopicsRequest); Iterable topics = response.iterateAll(); @@ -82,7 +82,7 @@ public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topicId throws Exception { // [START pubsub_list_topic_subscriptions] try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder() .setTopicWithTopicName(topicName) @@ -102,7 +102,7 @@ public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topicId public TopicName deleteTopic(String topicId) throws Exception { // [START pubsub_delete_topic] try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); topicAdminClient.deleteTopic(topicName); return topicName; } @@ -113,7 +113,7 @@ public TopicName deleteTopic(String topicId) throws Exception { public Policy getTopicPolicy(String topicId) throws Exception { // [START pubsub_get_topic_policy] try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); Policy policy = topicAdminClient.getIamPolicy(topicName.toString()); if (policy == null) { // topic iam policy was not found @@ -127,7 +127,7 @@ public Policy getTopicPolicy(String topicId) throws Exception { public Policy replaceTopicPolicy(String topicId) throws Exception { // [START pubsub_set_topic_policy] try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { - String topicName = TopicName.create(projectId, topicId).toString(); + String topicName = TopicName.of(projectId, topicId).toString(); Policy policy = topicAdminClient.getIamPolicy(topicName); // add role -> members binding Binding binding = @@ -150,7 +150,7 @@ public TestIamPermissionsResponse testTopicPermissions(String topicId) throws Ex try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { List permissions = new LinkedList<>(); permissions.add("pubsub.topics.get"); - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); TestIamPermissionsResponse testedPermissions = topicAdminClient.testIamPermissions(topicName.toString(), permissions); return testedPermissions; @@ -162,7 +162,7 @@ public TestIamPermissionsResponse testTopicPermissions(String topicId) throws Ex public Topic getTopic(String topicId) throws Exception { // [START pubsub_get_topic] try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { - TopicName topicName = TopicName.create(projectId, topicId); + TopicName topicName = TopicName.of(projectId, topicId); Topic topic = topicAdminClient.getTopic(topicName); return topic; } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/UsePubSubEmulatorSnippet.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/UsePubSubEmulatorSnippet.java index 111564ad4660..1106aa9e142d 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/UsePubSubEmulatorSnippet.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/UsePubSubEmulatorSnippet.java @@ -55,7 +55,7 @@ public static void main(String... args) throws IOException { .setCredentialsProvider(credentialsProvider) .build()); - TopicName topicName = TopicName.create("my-project-id", "my-topic-id"); + TopicName topicName = TopicName.of("my-project-id", "my-topic-id"); // Set the channel and credentials provider when creating a `Publisher`. // Similarly for Subscriber Publisher publisher = diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/StorageExample.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/StorageExample.java index 7d550477947d..4550a1b82d70 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/StorageExample.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/StorageExample.java @@ -551,8 +551,10 @@ Tuple parse(String... args) throws IOExcept KeyStore keystore = KeyStore.getInstance("PKCS12"); keystore.load(Files.newInputStream(Paths.get(args[0])), PASSWORD); PrivateKey privateKey = (PrivateKey) keystore.getKey("privatekey", PASSWORD); - ServiceAccountCredentials credentials = - new ServiceAccountCredentials(null, args[1], privateKey, null, null); + ServiceAccountCredentials credentials = ServiceAccountCredentials.newBuilder() + .setClientEmail(args[1]) + .setPrivateKey(privateKey) + .build(); return Tuple.of(credentials, BlobInfo.newBuilder(BlobId.of(args[2], args[3])).build()); } diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java index 97ca54854a78..e4a829b75a72 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/Cleanup.java @@ -33,7 +33,7 @@ private static void deleteTestTopics(String projectId, String[] testTopics) thro try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { for (String topicId : testTopics) { try { - topicAdminClient.deleteTopic(TopicName.create(projectId, topicId)); + topicAdminClient.deleteTopic(TopicName.of(projectId, topicId)); System.out.println("Topic deleted : " + topicId); } catch (Exception e) { //do nothing catch clause @@ -48,7 +48,7 @@ private static void deleteTestSubscriptions(String projectId, String[] subscript for (String subscriptionId : subscriptions) { try { subscriptionAdminClient.deleteSubscription( - SubscriptionName.create(projectId, subscriptionId)); + SubscriptionName.of(projectId, subscriptionId)); System.out.println("Subscription deleted : " + subscriptionId); } catch (Exception e) { //do nothing catch clause diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITPubSubSnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITPubSubSnippets.java index b2278a07db37..c6f0e2846c1b 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITPubSubSnippets.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITPubSubSnippets.java @@ -60,9 +60,9 @@ private static String formatForTest(String resourceName) { @Before public void setUp() throws Exception { - topicName = TopicName.create(ServiceOptions.getDefaultProjectId(), formatForTest("test-topic")); + topicName = TopicName.of(ServiceOptions.getDefaultProjectId(), formatForTest("test-topic")); subscriptionName = - SubscriptionName.create( + SubscriptionName.of( ServiceOptions.getDefaultProjectId(), formatForTest("test-subscription")); try (TopicAdminClient publisherClient = TopicAdminClient.create(); diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionAdminClientSnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionAdminClientSnippets.java index 5beb95de1c89..ef7510fd093a 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionAdminClientSnippets.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionAdminClientSnippets.java @@ -160,7 +160,7 @@ public void replaceSubscriptionPolicyAndTestPermissionsIsSuccessful() throws Exc private void createTopic(String name) throws Exception { try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { - topicAdminClient.createTopic(TopicName.create(projectId, name)); + topicAdminClient.createTopic(TopicName.of(projectId, name)); } } diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITTopicAdminClientSnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITTopicAdminClientSnippets.java index 2bc8683e5089..65120810dfc5 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITTopicAdminClientSnippets.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITTopicAdminClientSnippets.java @@ -170,8 +170,8 @@ public void replaceTopicPolicyAndTestPermissionsIsSuccessful() throws Exception private String createSubscription(String topic, String subscriptionName) throws Exception { try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { Subscription subscription = subscriptionAdminClient.createSubscription( - SubscriptionName.create(projectId, subscriptionName), - TopicName.create(projectId, topic), PushConfig.getDefaultInstance(), 0); + SubscriptionName.of(projectId, subscriptionName), + TopicName.of(projectId, topic), PushConfig.getDefaultInstance(), 0); return subscription.getName(); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 189075adfbae..e0c5f1ca0349 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -150,7 +150,7 @@ static Value encodeValue(@Nullable Object sanitizedObject) { + "Please explicitly set your Project ID in FirestoreOptions."); this.databasePath = ResourcePath.create( - DatabaseRootName.create(options.getProjectId(), options.getDatabaseId())); + DatabaseRootName.of(options.getProjectId(), options.getDatabaseId())); } @Nonnull diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java index eb1a7fbec0fa..fcc7bea718be 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java @@ -56,7 +56,7 @@ static ResourcePath create(String resourceName) { if (parts.length >= 6 && parts[0].equals("projects") && parts[2].equals("databases")) { String[] path = Arrays.copyOfRange(parts, 5, parts.length); return create( - DatabaseRootName.create(parts[1], parts[3]), + DatabaseRootName.of(parts[1], parts[3]), ImmutableList.builder().add(path).build()); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1beta1/GrpcFirestoreRpc.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1beta1/GrpcFirestoreRpc.java index f8e104716a4d..eb8ae6699dee 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1beta1/GrpcFirestoreRpc.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1beta1/GrpcFirestoreRpc.java @@ -93,7 +93,7 @@ public GrpcFirestoreRpc(final FirestoreOptions options) throws IOException { FirestoreSettings.Builder settingsBuilder = FirestoreSettings.newBuilder(); DatabaseRootName databaseName = DatabaseRootName - .create(options.getProjectId(), options.getDatabaseId()); + .of(options.getProjectId(), options.getDatabaseId()); settingsBuilder.setCredentialsProvider(GrpcTransportOptions.setUpCredentialsProvider(options)); settingsBuilder.setTransportChannelProvider( diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java index f0b7abcd1a9a..8fc965b26cf8 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java @@ -564,7 +564,7 @@ public boolean equals(Object o) { new DocumentReference( null, ResourcePath.create( - DatabaseRootName.create("", ""), ImmutableList.of("coll", "doc"))), + DatabaseRootName.of("", ""), ImmutableList.of("coll", "doc"))), SINGLE_FIELD_PROTO, Instant.ofEpochSecond(5, 6), Instant.ofEpochSecond(3, 4), diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java index ae4b87bc97d6..f0654673162e 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java @@ -452,7 +452,7 @@ com.google.logging.v2.LogEntry toPb(String projectId) { com.google.logging.v2.LogEntry.Builder builder = payload.toPb(); builder.putAllLabels(labels); if (logName != null) { - builder.setLogName(LogName.create(projectId, logName).toString()); + builder.setLogName(LogName.of(projectId, logName).toString()); } if (resource != null) { builder.setResource(resource.toPb()); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java index 5cf0f4bdb76f..c3e9f74eb870 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java @@ -128,7 +128,8 @@ private static V get(ApiFuture future) { try { return Uninterruptibles.getUninterruptibly(future); } catch (ExecutionException ex) { - throw Throwables.propagate(ex.getCause()); + Throwables.throwIfUnchecked(ex.getCause()); + throw new RuntimeException(ex); } } @@ -238,7 +239,7 @@ public Sink create(SinkInfo sink) { @Override public ApiFuture createAsync(SinkInfo sink) { CreateSinkRequest request = CreateSinkRequest.newBuilder() - .setParent(ProjectName.create(getOptions().getProjectId()).toString()) + .setParent(ProjectName.of(getOptions().getProjectId()).toString()) .setSink(sink.toPb(getOptions().getProjectId())) .build(); return transform(rpc.create(request), Sink.fromPbFunction(this)); @@ -252,7 +253,7 @@ public Sink update(SinkInfo sink) { @Override public ApiFuture updateAsync(SinkInfo sink) { UpdateSinkRequest request = UpdateSinkRequest.newBuilder() - .setSinkName(SinkName.create(getOptions().getProjectId(), sink.getName()).toString()) + .setSinkName(SinkName.of(getOptions().getProjectId(), sink.getName()).toString()) .setSink(sink.toPb(getOptions().getProjectId())) .build(); return transform(rpc.update(request), Sink.fromPbFunction(this)); @@ -266,7 +267,7 @@ public Sink getSink(String sink) { @Override public ApiFuture getSinkAsync(String sink) { GetSinkRequest request = GetSinkRequest.newBuilder() - .setSinkName(SinkName.create(getOptions().getProjectId(), sink).toString()) + .setSinkName(SinkName.of(getOptions().getProjectId(), sink).toString()) .build(); return transform(rpc.get(request), Sink.fromPbFunction(this)); } @@ -274,7 +275,7 @@ public ApiFuture getSinkAsync(String sink) { private static ListSinksRequest listSinksRequest(LoggingOptions serviceOptions, Map options) { ListSinksRequest.Builder builder = ListSinksRequest.newBuilder(); - builder.setParent(ProjectName.create(serviceOptions.getProjectId()).toString()); + builder.setParent(ProjectName.of(serviceOptions.getProjectId()).toString()); Integer pageSize = PAGE_SIZE.get(options); String pageToken = PAGE_TOKEN.get(options); if (pageSize != null) { @@ -322,7 +323,7 @@ public boolean deleteSink(String sink) { @Override public ApiFuture deleteSinkAsync(String sink) { DeleteSinkRequest request = DeleteSinkRequest.newBuilder() - .setSinkName(SinkName.create(getOptions().getProjectId(), sink).toString()) + .setSinkName(SinkName.of(getOptions().getProjectId(), sink).toString()) .build(); return transform(rpc.delete(request), EMPTY_TO_BOOLEAN_FUNCTION); } @@ -333,7 +334,7 @@ public boolean deleteLog(String log) { public ApiFuture deleteLogAsync(String log) { DeleteLogRequest request = DeleteLogRequest.newBuilder() - .setLogName(LogName.create(getOptions().getProjectId(), log).toString()) + .setLogName(LogName.of(getOptions().getProjectId(), log).toString()) .build(); return transform(rpc.delete(request), EMPTY_TO_BOOLEAN_FUNCTION); } @@ -402,7 +403,7 @@ public Metric create(MetricInfo metric) { @Override public ApiFuture createAsync(MetricInfo metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder() - .setParent(ProjectName.create(getOptions().getProjectId()).toString()) + .setParent(ProjectName.of(getOptions().getProjectId()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.create(request), Metric.fromPbFunction(this)); @@ -416,7 +417,7 @@ public Metric update(MetricInfo metric) { @Override public ApiFuture updateAsync(MetricInfo metric) { UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder() - .setMetricName(MetricName.create(getOptions().getProjectId(), metric.getName()).toString()) + .setMetricName(MetricName.of(getOptions().getProjectId(), metric.getName()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.update(request), Metric.fromPbFunction(this)); @@ -430,7 +431,7 @@ public Metric getMetric(String metric) { @Override public ApiFuture getMetricAsync(String metric) { GetLogMetricRequest request = GetLogMetricRequest.newBuilder() - .setMetricName(MetricName.create(getOptions().getProjectId(), metric).toString()) + .setMetricName(MetricName.of(getOptions().getProjectId(), metric).toString()) .build(); return transform(rpc.get(request), Metric.fromPbFunction(this)); } @@ -438,7 +439,7 @@ public ApiFuture getMetricAsync(String metric) { private static ListLogMetricsRequest listMetricsRequest(LoggingOptions serviceOptions, Map options) { ListLogMetricsRequest.Builder builder = ListLogMetricsRequest.newBuilder(); - builder.setParent(ProjectName.create(serviceOptions.getProjectId()).toString()); + builder.setParent(ProjectName.of(serviceOptions.getProjectId()).toString()); Integer pageSize = PAGE_SIZE.get(options); String pageToken = PAGE_TOKEN.get(options); if (pageSize != null) { @@ -486,7 +487,7 @@ public boolean deleteMetric(String metric) { @Override public ApiFuture deleteMetricAsync(String metric) { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder() - .setMetricName(MetricName.create(getOptions().getProjectId(), metric).toString()) + .setMetricName(MetricName.of(getOptions().getProjectId(), metric).toString()) .build(); return transform(rpc.delete(request), EMPTY_TO_BOOLEAN_FUNCTION); } @@ -497,7 +498,7 @@ private static WriteLogEntriesRequest writeLogEntriesRequest(LoggingOptions serv WriteLogEntriesRequest.Builder builder = WriteLogEntriesRequest.newBuilder(); String logName = LOG_NAME.get(options); if (logName != null) { - builder.setLogName(LogName.create(projectId, logName).toString()); + builder.setLogName(LogName.of(projectId, logName).toString()); } MonitoredResource resource = RESOURCE.get(options); if (resource != null) { diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java index 6560ece9ad7d..223e1c905774 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java @@ -338,7 +338,7 @@ public void testListMetricsAsync() throws ExecutionException, InterruptedExcepti public void testWriteAndListLogEntries() throws InterruptedException { String logId = formatForTest("test-write-log-entries-log"); LoggingOptions loggingOptions = logging().getOptions(); - LogName logName = LogName.create(loggingOptions.getProjectId(), logId); + LogName logName = LogName.of(loggingOptions.getProjectId(), logId); StringPayload firstPayload = StringPayload.of("stringPayload"); LogEntry firstEntry = LogEntry.newBuilder(firstPayload) .addLabel("key1", "value1") @@ -405,7 +405,7 @@ public void testWriteAndListLogEntries() throws InterruptedException { public void testWriteAndListLogEntriesAsync() throws InterruptedException, ExecutionException { String logId = formatForTest("test-write-log-entries-async-log"); LoggingOptions loggingOptions = logging().getOptions(); - LogName logName = LogName.create(loggingOptions.getProjectId(), logId); + LogName logName = LogName.of(loggingOptions.getProjectId(), logId); StringPayload firstPayload = StringPayload.of("stringPayload"); LogEntry firstEntry = LogEntry.newBuilder(firstPayload).setSeverity(Severity.ALERT).build(); ProtoPayload secondPayload = @@ -465,7 +465,7 @@ public void testDeleteNonExistingLogAsync() throws ExecutionException, Interrupt public void testLoggingHandler() throws InterruptedException { String logId = formatForTest("test-logging-handler"); LoggingOptions options = logging().getOptions(); - LogName logName = LogName.create(options.getProjectId(), logId); + LogName logName = LogName.of(options.getProjectId(), logId); LoggingHandler handler = new LoggingHandler(logId, options); handler.setLevel(Level.INFO); Logger logger = Logger.getLogger(getClass().getName()); @@ -504,7 +504,7 @@ public void testLoggingHandler() throws InterruptedException { public void testSyncLoggingHandler() throws InterruptedException { String logId = formatForTest("test-sync-logging-handler"); LoggingOptions options = logging().getOptions(); - LogName logName = LogName.create(options.getProjectId(), logId); + LogName logName = LogName.of(options.getProjectId(), logId); MonitoredResource resource = MonitoredResource.of("gce_instance", ImmutableMap.of("project_id", options.getProjectId(), "instance_id", "instance", diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java index f4e42fa3ab2b..4f6d2a6c4127 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java @@ -85,7 +85,7 @@ private String formatForTest(String resourceName) { @Test public void testTopicPolicy() { - TopicName topicName = TopicName.create(projectId, formatForTest("testing-topic-policy")); + TopicName topicName = TopicName.of(projectId, formatForTest("testing-topic-policy")); topicAdminClient.createTopic(topicName); Policy policy = topicAdminClient.getIamPolicy(topicName.toString()); @@ -109,9 +109,9 @@ public void testTopicPolicy() { @Test public void testPublishSubscribe() throws Exception { TopicName topicName = - TopicName.create(projectId, formatForTest("testing-publish-subscribe-topic")); + TopicName.of(projectId, formatForTest("testing-publish-subscribe-topic")); SubscriptionName subscriptionName = - SubscriptionName.create(projectId, formatForTest("testing-publish-subscribe-subscription")); + SubscriptionName.of(projectId, formatForTest("testing-publish-subscribe-subscription")); topicAdminClient.createTopic(topicName); subscriptionAdminClient.createSubscription( diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java index f19fb9b384a0..7b92f7af63f6 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java @@ -56,7 +56,7 @@ @RunWith(JUnit4.class) public class PublisherImplTest { - private static final TopicName TEST_TOPIC = TopicName.create("test-project", "test-topic"); + private static final TopicName TEST_TOPIC = TopicName.of("test-project", "test-topic"); private static final ExecutorProvider SINGLE_THREAD_EXECUTOR = InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1).build(); diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java index e9c0575e8fe3..487b8481cda3 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java @@ -65,7 +65,7 @@ public class SubscriberTest { private static final SubscriptionName TEST_SUBSCRIPTION = - SubscriptionName.create("test-project", "test-subscription"); + SubscriptionName.of("test-project", "test-subscription"); private static final PubsubMessage TEST_MESSAGE = PubsubMessage.newBuilder().setMessageId("1").build(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java index 24566af3ddcf..680eea95ad6b 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java @@ -290,7 +290,8 @@ private Object getterByIndex(String methodName, int columnIndex) { try { return reader.getClass().getMethod(methodName, int.class).invoke(reader, columnIndex); } catch (InvocationTargetException e) { - throw Throwables.propagate(e.getCause()); + Throwables.throwIfUnchecked(e.getCause()); + throw new RuntimeException(e); } catch (NoSuchMethodException | IllegalAccessException e) { throw new RuntimeException(e); } @@ -304,7 +305,8 @@ private Object getterByName(String methodName, String columnName) { try { return reader.getClass().getMethod(methodName, String.class).invoke(reader, columnName); } catch (InvocationTargetException e) { - throw Throwables.propagate(e.getCause()); + Throwables.throwIfUnchecked(e.getCause()); + throw new RuntimeException(e); } catch (NoSuchMethodException | IllegalAccessException e) { throw new RuntimeException(e); }