From 061194950feb14af37c6c14786c216f2208a1dad Mon Sep 17 00:00:00 2001 From: garrettjonesgoogle Date: Thu, 5 Jan 2017 11:37:06 -0800 Subject: [PATCH] Regenerating SPI layer (#1501) * Converting Error Reporting and Monitoring to use resource name types * Removing formatX/parseX methods from pubsub, converting usage of the same to resource name types * New methods in Logging and PubSub --- google-cloud-core/pom.xml | 4 +- google-cloud-errorreporting/pom.xml | 2 +- .../spi/v1beta1/ErrorGroupServiceClient.java | 45 +--- .../spi/v1beta1/ErrorStatsServiceClient.java | 92 +++---- .../v1beta1/ReportErrorsServiceClient.java | 40 ++- .../spi/v1beta1/package-info.java | 12 +- .../spi/v1beta1/ErrorGroupServiceTest.java | 21 +- .../spi/v1beta1/ErrorStatsServiceTest.java | 32 +-- .../spi/v1beta1/ReportErrorsServiceTest.java | 11 +- google-cloud-language/pom.xml | 2 +- google-cloud-logging/pom.xml | 2 +- .../logging/spi/v2/ConfigServiceV2Client.java | 62 +++-- .../spi/v2/LoggingServiceV2Client.java | 146 ++++++++++- .../spi/v2/LoggingServiceV2Settings.java | 84 +++++- .../logging/spi/v2/PagedResponseWrappers.java | 14 + .../logging/spi/v2/LoggingServiceV2Test.java | 49 ++++ .../spi/v2/MockLoggingServiceV2Impl.java | 16 ++ google-cloud-monitoring/pom.xml | 2 +- .../monitoring/spi/v3/GroupServiceClient.java | 128 ++++----- .../spi/v3/MetricServiceClient.java | 247 ++++++------------ .../cloud/monitoring/spi/v3/package-info.java | 8 +- .../monitoring/spi/v3/GroupServiceTest.java | 66 ++--- .../monitoring/spi/v3/MetricServiceTest.java | 111 ++++---- google-cloud-pubsub/pom.xml | 2 +- .../cloud/pubsub/MessageConsumerImpl.java | 5 +- .../com/google/cloud/pubsub/PubSubImpl.java | 54 ++-- .../google/cloud/pubsub/SubscriptionId.java | 9 +- .../google/cloud/pubsub/SubscriptionInfo.java | 7 +- .../java/com/google/cloud/pubsub/TopicId.java | 9 +- .../com/google/cloud/pubsub/TopicInfo.java | 7 +- .../cloud/pubsub/spi/v1/PublisherClient.java | 80 ++---- .../cloud/pubsub/spi/v1/SubscriberClient.java | 233 +++++++++-------- .../pubsub/spi/v1/SubscriberSettings.java | 24 ++ .../google/cloud/pubsub/PubSubImplTest.java | 24 +- .../pubsub/spi/v1/MockSubscriberImpl.java | 32 +++ .../cloud/pubsub/spi/v1/PublisherTest.java | 12 +- .../cloud/pubsub/spi/v1/SubscriberTest.java | 84 +++++- google-cloud-speech/pom.xml | 2 +- google-cloud-trace/pom.xml | 2 +- google-cloud-vision/pom.xml | 2 +- 40 files changed, 1022 insertions(+), 762 deletions(-) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 489d27cdf126..613c7f1e98d5 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -122,7 +122,7 @@ com.google.api.grpc grpc-google-common-protos - 0.1.3 + 0.1.5 io.grpc @@ -133,7 +133,7 @@ com.google.api.grpc grpc-google-iam-v1 - 0.1.3 + 0.1.5 io.grpc diff --git a/google-cloud-errorreporting/pom.xml b/google-cloud-errorreporting/pom.xml index dcff54850fc9..49cda878a49e 100644 --- a/google-cloud-errorreporting/pom.xml +++ b/google-cloud-errorreporting/pom.xml @@ -30,7 +30,7 @@ com.google.api.grpc grpc-google-cloud-error-reporting-v1beta1 - 0.1.3 + 0.1.5 io.grpc diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceClient.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceClient.java index 48b9cc6bba46..33e1edc3d84a 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceClient.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceClient.java @@ -17,9 +17,9 @@ import com.google.api.gax.grpc.ChannelAndExecutor; import com.google.api.gax.grpc.UnaryCallable; -import com.google.api.gax.protobuf.PathTemplate; import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup; import com.google.devtools.clouderrorreporting.v1beta1.GetGroupRequest; +import com.google.devtools.clouderrorreporting.v1beta1.GroupName; import com.google.devtools.clouderrorreporting.v1beta1.UpdateGroupRequest; import com.google.protobuf.ExperimentalApi; import io.grpc.ManagedChannel; @@ -40,8 +40,8 @@ *
  * 
  * try (ErrorGroupServiceClient errorGroupServiceClient = ErrorGroupServiceClient.create()) {
- *   String formattedGroupName = ErrorGroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
- *   ErrorGroup response = errorGroupServiceClient.getGroup(formattedGroupName);
+ *   GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]");
+ *   ErrorGroup response = errorGroupServiceClient.getGroup(groupName);
  * }
  * 
  * 
@@ -97,26 +97,6 @@ public class ErrorGroupServiceClient implements AutoCloseable { private final UnaryCallable getGroupCallable; private final UnaryCallable updateGroupCallable; - private static final PathTemplate GROUP_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}/groups/{group}"); - - /** Formats a string containing the fully-qualified path to represent a group resource. */ - public static final String formatGroupName(String project, String group) { - return GROUP_PATH_TEMPLATE.instantiate( - "project", project, - "group", group); - } - - /** Parses the project from the given fully-qualified path which represents a group resource. */ - public static final String parseProjectFromGroupName(String groupName) { - return GROUP_PATH_TEMPLATE.parse(groupName).get("project"); - } - - /** Parses the group from the given fully-qualified path which represents a group resource. */ - public static final String parseGroupFromGroupName(String groupName) { - return GROUP_PATH_TEMPLATE.parse(groupName).get("group"); - } - /** Constructs an instance of ErrorGroupServiceClient with default settings. */ public static final ErrorGroupServiceClient create() throws IOException { return create(ErrorGroupServiceSettings.defaultBuilder().build()); @@ -179,8 +159,8 @@ public final ErrorGroupServiceSettings getSettings() { * *

    * try (ErrorGroupServiceClient errorGroupServiceClient = ErrorGroupServiceClient.create()) {
-   *   String formattedGroupName = ErrorGroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
-   *   ErrorGroup response = errorGroupServiceClient.getGroup(formattedGroupName);
+   *   GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]");
+   *   ErrorGroup response = errorGroupServiceClient.getGroup(groupName);
    * }
    * 
* @@ -192,9 +172,10 @@ public final ErrorGroupServiceSettings getSettings() { *

Example: <code>projects/my-project-123/groups/my-group</code> * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final ErrorGroup getGroup(String groupName) { - GROUP_PATH_TEMPLATE.validate(groupName, "getGroup"); - GetGroupRequest request = GetGroupRequest.newBuilder().setGroupName(groupName).build(); + public final ErrorGroup getGroup(GroupName groupName) { + + GetGroupRequest request = + GetGroupRequest.newBuilder().setGroupNameWithGroupName(groupName).build(); return getGroup(request); } @@ -206,9 +187,9 @@ public final ErrorGroup getGroup(String groupName) { * *


    * try (ErrorGroupServiceClient errorGroupServiceClient = ErrorGroupServiceClient.create()) {
-   *   String formattedGroupName = ErrorGroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]");
    *   GetGroupRequest request = GetGroupRequest.newBuilder()
-   *     .setGroupName(formattedGroupName)
+   *     .setGroupNameWithGroupName(groupName)
    *     .build();
    *   ErrorGroup response = errorGroupServiceClient.getGroup(request);
    * }
@@ -229,9 +210,9 @@ private final ErrorGroup getGroup(GetGroupRequest request) {
    *
    * 

    * try (ErrorGroupServiceClient errorGroupServiceClient = ErrorGroupServiceClient.create()) {
-   *   String formattedGroupName = ErrorGroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]");
    *   GetGroupRequest request = GetGroupRequest.newBuilder()
-   *     .setGroupName(formattedGroupName)
+   *     .setGroupNameWithGroupName(groupName)
    *     .build();
    *   ListenableFuture<ErrorGroup> future = errorGroupServiceClient.getGroupCallable().futureCall(request);
    *   // Do something
diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceClient.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceClient.java
index a612ae883eb7..4a53ccaf92bb 100644
--- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceClient.java
+++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceClient.java
@@ -20,13 +20,13 @@
 
 import com.google.api.gax.grpc.ChannelAndExecutor;
 import com.google.api.gax.grpc.UnaryCallable;
-import com.google.api.gax.protobuf.PathTemplate;
 import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsRequest;
 import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsResponse;
 import com.google.devtools.clouderrorreporting.v1beta1.ListEventsRequest;
 import com.google.devtools.clouderrorreporting.v1beta1.ListEventsResponse;
 import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest;
 import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsResponse;
+import com.google.devtools.clouderrorreporting.v1beta1.ProjectName;
 import com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange;
 import com.google.protobuf.ExperimentalApi;
 import io.grpc.ManagedChannel;
@@ -48,8 +48,8 @@
  * 
  * 
  * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
- *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
- *   DeleteEventsResponse response = errorStatsServiceClient.deleteEvents(formattedProjectName);
+ *   ProjectName projectName = ProjectName.create("[PROJECT]");
+ *   DeleteEventsResponse response = errorStatsServiceClient.deleteEvents(projectName);
  * }
  * 
  * 
@@ -109,19 +109,6 @@ public class ErrorStatsServiceClient implements AutoCloseable { private final UnaryCallable listEventsPagedCallable; private final UnaryCallable deleteEventsCallable; - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}"); - - /** Formats a string containing the fully-qualified path to represent a project resource. */ - public static final String formatProjectName(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** Parses the project from the given fully-qualified path which represents a project resource. */ - public static final String parseProjectFromProjectName(String projectName) { - return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); - } - /** Constructs an instance of ErrorStatsServiceClient with default settings. */ public static final ErrorStatsServiceClient create() throws IOException { return create(ErrorStatsServiceSettings.defaultBuilder().build()); @@ -192,9 +179,9 @@ public final ErrorStatsServiceSettings getSettings() { * *

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
-   *   for (ErrorGroupStats element : errorStatsServiceClient.listGroupStats(formattedProjectName, timeRange).iterateAllElements()) {
+   *   for (ErrorGroupStats element : errorStatsServiceClient.listGroupStats(projectName, timeRange).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -205,18 +192,19 @@ public final ErrorStatsServiceSettings getSettings() {
    *     href="https://support.google.com/cloud/answer/6158840">Google Cloud Platform project
    *     ID</a>.
    *     

Example: <code>projects/my-project-123</code>. - * @param timeRange [Required] List data for the given time range. Only - * <code>ErrorGroupStats</code> with a non-zero count in the given time range are - * returned, unless the request contains an explicit group_id list. If a group_id list is - * given, also <code>ErrorGroupStats</code> with zero occurrences are returned. + * @param timeRange [Optional] List data for the given time range. If not set a default time range + * is used. The field time_range_begin in the response will specify the beginning of this time + * range. Only <code>ErrorGroupStats</code> with a non-zero count in the given + * time range are returned, unless the request contains an explicit group_id list. If a + * group_id list is given, also <code>ErrorGroupStats</code> with zero occurrences + * are returned. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ListGroupStatsPagedResponse listGroupStats( - String projectName, QueryTimeRange timeRange) { - PROJECT_PATH_TEMPLATE.validate(projectName, "listGroupStats"); + ProjectName projectName, QueryTimeRange timeRange) { ListGroupStatsRequest request = ListGroupStatsRequest.newBuilder() - .setProjectName(projectName) + .setProjectNameWithProjectName(projectName) .setTimeRange(timeRange) .build(); return listGroupStats(request); @@ -230,10 +218,10 @@ public final ListGroupStatsPagedResponse listGroupStats( * *


    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
    *   ListGroupStatsRequest request = ListGroupStatsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setTimeRange(timeRange)
    *     .build();
    *   for (ErrorGroupStats element : errorStatsServiceClient.listGroupStats(request).iterateAllElements()) {
@@ -257,10 +245,10 @@ public final ListGroupStatsPagedResponse listGroupStats(ListGroupStatsRequest re
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
    *   ListGroupStatsRequest request = ListGroupStatsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setTimeRange(timeRange)
    *     .build();
    *   ListenableFuture<ListGroupStatsPagedResponse> future = errorStatsServiceClient.listGroupStatsPagedCallable().futureCall(request);
@@ -284,10 +272,10 @@ public final ListGroupStatsPagedResponse listGroupStats(ListGroupStatsRequest re
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
    *   ListGroupStatsRequest request = ListGroupStatsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setTimeRange(timeRange)
    *     .build();
    *   while (true) {
@@ -318,9 +306,9 @@ public final ListGroupStatsPagedResponse listGroupStats(ListGroupStatsRequest re
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   String groupId = "";
-   *   for (ErrorEvent element : errorStatsServiceClient.listEvents(formattedProjectName, groupId).iterateAllElements()) {
+   *   for (ErrorEvent element : errorStatsServiceClient.listEvents(projectName, groupId).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -332,10 +320,12 @@ public final ListGroupStatsPagedResponse listGroupStats(ListGroupStatsRequest re
    * @param groupId [Required] The group for which events shall be returned.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final ListEventsPagedResponse listEvents(String projectName, String groupId) {
-    PROJECT_PATH_TEMPLATE.validate(projectName, "listEvents");
+  public final ListEventsPagedResponse listEvents(ProjectName projectName, String groupId) {
     ListEventsRequest request =
-        ListEventsRequest.newBuilder().setProjectName(projectName).setGroupId(groupId).build();
+        ListEventsRequest.newBuilder()
+            .setProjectNameWithProjectName(projectName)
+            .setGroupId(groupId)
+            .build();
     return listEvents(request);
   }
 
@@ -347,10 +337,10 @@ public final ListEventsPagedResponse listEvents(String projectName, String group
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   String groupId = "";
    *   ListEventsRequest request = ListEventsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setGroupId(groupId)
    *     .build();
    *   for (ErrorEvent element : errorStatsServiceClient.listEvents(request).iterateAllElements()) {
@@ -374,10 +364,10 @@ public final ListEventsPagedResponse listEvents(ListEventsRequest request) {
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   String groupId = "";
    *   ListEventsRequest request = ListEventsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setGroupId(groupId)
    *     .build();
    *   ListenableFuture<ListEventsPagedResponse> future = errorStatsServiceClient.listEventsPagedCallable().futureCall(request);
@@ -400,10 +390,10 @@ public final UnaryCallable listEvent
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   String groupId = "";
    *   ListEventsRequest request = ListEventsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setGroupId(groupId)
    *     .build();
    *   while (true) {
@@ -433,8 +423,8 @@ public final UnaryCallable listEventsCall
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
-   *   DeleteEventsResponse response = errorStatsServiceClient.deleteEvents(formattedProjectName);
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
+   *   DeleteEventsResponse response = errorStatsServiceClient.deleteEvents(projectName);
    * }
    * 
* @@ -443,10 +433,10 @@ public final UnaryCallable listEventsCall * ID](https://support.google.com/cloud/answer/6158840). Example: `projects/my-project-123`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final DeleteEventsResponse deleteEvents(String projectName) { - PROJECT_PATH_TEMPLATE.validate(projectName, "deleteEvents"); + public final DeleteEventsResponse deleteEvents(ProjectName projectName) { + DeleteEventsRequest request = - DeleteEventsRequest.newBuilder().setProjectName(projectName).build(); + DeleteEventsRequest.newBuilder().setProjectNameWithProjectName(projectName).build(); return deleteEvents(request); } @@ -458,9 +448,9 @@ public final DeleteEventsResponse deleteEvents(String projectName) { * *

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   DeleteEventsRequest request = DeleteEventsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .build();
    *   DeleteEventsResponse response = errorStatsServiceClient.deleteEvents(request);
    * }
@@ -481,9 +471,9 @@ private final DeleteEventsResponse deleteEvents(DeleteEventsRequest request) {
    *
    * 

    * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
-   *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   DeleteEventsRequest request = DeleteEventsRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .build();
    *   ListenableFuture<DeleteEventsResponse> future = errorStatsServiceClient.deleteEventsCallable().futureCall(request);
    *   // Do something
diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceClient.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceClient.java
index 65a6ef234b4e..8189c716e86c 100644
--- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceClient.java
+++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceClient.java
@@ -17,7 +17,7 @@
 
 import com.google.api.gax.grpc.ChannelAndExecutor;
 import com.google.api.gax.grpc.UnaryCallable;
-import com.google.api.gax.protobuf.PathTemplate;
+import com.google.devtools.clouderrorreporting.v1beta1.ProjectName;
 import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest;
 import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse;
 import com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent;
@@ -40,9 +40,9 @@
  * 
  * 
  * try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
- *   String formattedProjectName = ReportErrorsServiceClient.formatProjectName("[PROJECT]");
+ *   ProjectName projectName = ProjectName.create("[PROJECT]");
  *   ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
- *   ReportErrorEventResponse response = reportErrorsServiceClient.reportErrorEvent(formattedProjectName, event);
+ *   ReportErrorEventResponse response = reportErrorsServiceClient.reportErrorEvent(projectName, event);
  * }
  * 
  * 
@@ -98,19 +98,6 @@ public class ReportErrorsServiceClient implements AutoCloseable { private final UnaryCallable reportErrorEventCallable; - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}"); - - /** Formats a string containing the fully-qualified path to represent a project resource. */ - public static final String formatProjectName(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** Parses the project from the given fully-qualified path which represents a project resource. */ - public static final String parseProjectFromProjectName(String projectName) { - return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); - } - /** Constructs an instance of ReportErrorsServiceClient with default settings. */ public static final ReportErrorsServiceClient create() throws IOException { return create(ReportErrorsServiceSettings.defaultBuilder().build()); @@ -178,9 +165,9 @@ public final ReportErrorsServiceSettings getSettings() { * *

    * try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
-   *   String formattedProjectName = ReportErrorsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
-   *   ReportErrorEventResponse response = reportErrorsServiceClient.reportErrorEvent(formattedProjectName, event);
+   *   ReportErrorEventResponse response = reportErrorsServiceClient.reportErrorEvent(projectName, event);
    * }
    * 
* @@ -191,10 +178,13 @@ public final ReportErrorsServiceSettings getSettings() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ReportErrorEventResponse reportErrorEvent( - String projectName, ReportedErrorEvent event) { - PROJECT_PATH_TEMPLATE.validate(projectName, "reportErrorEvent"); + ProjectName projectName, ReportedErrorEvent event) { + ReportErrorEventRequest request = - ReportErrorEventRequest.newBuilder().setProjectName(projectName).setEvent(event).build(); + ReportErrorEventRequest.newBuilder() + .setProjectNameWithProjectName(projectName) + .setEvent(event) + .build(); return reportErrorEvent(request); } @@ -213,10 +203,10 @@ public final ReportErrorEventResponse reportErrorEvent( * *

    * try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
-   *   String formattedProjectName = ReportErrorsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
    *   ReportErrorEventRequest request = ReportErrorEventRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setEvent(event)
    *     .build();
    *   ReportErrorEventResponse response = reportErrorsServiceClient.reportErrorEvent(request);
@@ -245,10 +235,10 @@ public final ReportErrorEventResponse reportErrorEvent(ReportErrorEventRequest r
    *
    * 

    * try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
-   *   String formattedProjectName = ReportErrorsServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName projectName = ProjectName.create("[PROJECT]");
    *   ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
    *   ReportErrorEventRequest request = ReportErrorEventRequest.newBuilder()
-   *     .setProjectName(formattedProjectName)
+   *     .setProjectNameWithProjectName(projectName)
    *     .setEvent(event)
    *     .build();
    *   ListenableFuture<ReportErrorEventResponse> future = reportErrorsServiceClient.reportErrorEventCallable().futureCall(request);
diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/package-info.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/package-info.java
index 5254c3f2104a..f48abbe98e8d 100644
--- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/package-info.java
+++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/package-info.java
@@ -28,8 +28,8 @@
  * 
  * 
  * try (ErrorGroupServiceClient errorGroupServiceClient = ErrorGroupServiceClient.create()) {
- *   String formattedGroupName = ErrorGroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
- *   ErrorGroup response = errorGroupServiceClient.getGroup(formattedGroupName);
+ *   GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]");
+ *   ErrorGroup response = errorGroupServiceClient.getGroup(groupName);
  * }
  * 
  * 
@@ -44,8 +44,8 @@ *
  * 
  * try (ErrorStatsServiceClient errorStatsServiceClient = ErrorStatsServiceClient.create()) {
- *   String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]");
- *   DeleteEventsResponse response = errorStatsServiceClient.deleteEvents(formattedProjectName);
+ *   ProjectName projectName = ProjectName.create("[PROJECT]");
+ *   DeleteEventsResponse response = errorStatsServiceClient.deleteEvents(projectName);
  * }
  * 
  * 
@@ -59,9 +59,9 @@ *
  * 
  * try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
- *   String formattedProjectName = ReportErrorsServiceClient.formatProjectName("[PROJECT]");
+ *   ProjectName projectName = ProjectName.create("[PROJECT]");
  *   ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
- *   ReportErrorEventResponse response = reportErrorsServiceClient.reportErrorEvent(formattedProjectName, event);
+ *   ReportErrorEventResponse response = reportErrorsServiceClient.reportErrorEvent(projectName, event);
  * }
  * 
  * 
diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java index f58d6313e864..b11c5cb6fd72 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java @@ -20,6 +20,7 @@ import com.google.api.gax.testing.MockServiceHelper; import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup; import com.google.devtools.clouderrorreporting.v1beta1.GetGroupRequest; +import com.google.devtools.clouderrorreporting.v1beta1.GroupName; import com.google.devtools.clouderrorreporting.v1beta1.UpdateGroupRequest; import com.google.protobuf.GeneratedMessageV3; import io.grpc.Status; @@ -78,21 +79,22 @@ public void tearDown() throws Exception { @Test @SuppressWarnings("all") public void getGroupTest() { - String name = "name3373707"; + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); String groupId = "groupId506361563"; - ErrorGroup expectedResponse = ErrorGroup.newBuilder().setName(name).setGroupId(groupId).build(); + ErrorGroup expectedResponse = + ErrorGroup.newBuilder().setNameWithGroupName(name).setGroupId(groupId).build(); mockErrorGroupService.addResponse(expectedResponse); - String formattedGroupName = ErrorGroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]"); - ErrorGroup actualResponse = client.getGroup(formattedGroupName); + ErrorGroup actualResponse = client.getGroup(groupName); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockErrorGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetGroupRequest actualRequest = (GetGroupRequest) actualRequests.get(0); - Assert.assertEquals(formattedGroupName, actualRequest.getGroupName()); + Assert.assertEquals(groupName, actualRequest.getGroupNameAsGroupName()); } @Test @@ -102,9 +104,9 @@ public void getGroupExceptionTest() throws Exception { mockErrorGroupService.addException(exception); try { - String formattedGroupName = ErrorGroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName groupName = GroupName.create("[PROJECT]", "[GROUP]"); - client.getGroup(formattedGroupName); + client.getGroup(groupName); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -114,9 +116,10 @@ public void getGroupExceptionTest() throws Exception { @Test @SuppressWarnings("all") public void updateGroupTest() { - String name = "name3373707"; + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); String groupId = "groupId506361563"; - ErrorGroup expectedResponse = ErrorGroup.newBuilder().setName(name).setGroupId(groupId).build(); + ErrorGroup expectedResponse = + ErrorGroup.newBuilder().setNameWithGroupName(name).setGroupId(groupId).build(); mockErrorGroupService.addResponse(expectedResponse); ErrorGroup group = ErrorGroup.newBuilder().build(); diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java index 324a3caaf617..9d8250cbc24a 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java @@ -30,6 +30,7 @@ import com.google.devtools.clouderrorreporting.v1beta1.ListEventsResponse; import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest; import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsResponse; +import com.google.devtools.clouderrorreporting.v1beta1.ProjectName; import com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange; import com.google.protobuf.GeneratedMessageV3; import io.grpc.Status; @@ -98,11 +99,10 @@ public void listGroupStatsTest() { .build(); mockErrorStatsService.addResponse(expectedResponse); - String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); QueryTimeRange timeRange = QueryTimeRange.newBuilder().build(); - ListGroupStatsPagedResponse pagedListResponse = - client.listGroupStats(formattedProjectName, timeRange); + ListGroupStatsPagedResponse pagedListResponse = client.listGroupStats(projectName, timeRange); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -112,7 +112,7 @@ public void listGroupStatsTest() { Assert.assertEquals(1, actualRequests.size()); ListGroupStatsRequest actualRequest = (ListGroupStatsRequest) actualRequests.get(0); - Assert.assertEquals(formattedProjectName, actualRequest.getProjectName()); + Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName()); Assert.assertEquals(timeRange, actualRequest.getTimeRange()); } @@ -123,10 +123,10 @@ public void listGroupStatsExceptionTest() throws Exception { mockErrorStatsService.addException(exception); try { - String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); QueryTimeRange timeRange = QueryTimeRange.newBuilder().build(); - client.listGroupStats(formattedProjectName, timeRange); + client.listGroupStats(projectName, timeRange); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -146,10 +146,10 @@ public void listEventsTest() { .build(); mockErrorStatsService.addResponse(expectedResponse); - String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); String groupId = "groupId506361563"; - ListEventsPagedResponse pagedListResponse = client.listEvents(formattedProjectName, groupId); + ListEventsPagedResponse pagedListResponse = client.listEvents(projectName, groupId); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -159,7 +159,7 @@ public void listEventsTest() { Assert.assertEquals(1, actualRequests.size()); ListEventsRequest actualRequest = (ListEventsRequest) actualRequests.get(0); - Assert.assertEquals(formattedProjectName, actualRequest.getProjectName()); + Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName()); Assert.assertEquals(groupId, actualRequest.getGroupId()); } @@ -170,10 +170,10 @@ public void listEventsExceptionTest() throws Exception { mockErrorStatsService.addException(exception); try { - String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); String groupId = "groupId506361563"; - client.listEvents(formattedProjectName, groupId); + client.listEvents(projectName, groupId); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -186,16 +186,16 @@ public void deleteEventsTest() { DeleteEventsResponse expectedResponse = DeleteEventsResponse.newBuilder().build(); mockErrorStatsService.addResponse(expectedResponse); - String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); - DeleteEventsResponse actualResponse = client.deleteEvents(formattedProjectName); + DeleteEventsResponse actualResponse = client.deleteEvents(projectName); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockErrorStatsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteEventsRequest actualRequest = (DeleteEventsRequest) actualRequests.get(0); - Assert.assertEquals(formattedProjectName, actualRequest.getProjectName()); + Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName()); } @Test @@ -205,9 +205,9 @@ public void deleteEventsExceptionTest() throws Exception { mockErrorStatsService.addException(exception); try { - String formattedProjectName = ErrorStatsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); - client.deleteEvents(formattedProjectName); + client.deleteEvents(projectName); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java index 70b1bf877670..913840ab9fe1 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java @@ -18,6 +18,7 @@ import com.google.api.gax.grpc.ApiException; import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; +import com.google.devtools.clouderrorreporting.v1beta1.ProjectName; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse; import com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent; @@ -81,17 +82,17 @@ public void reportErrorEventTest() { ReportErrorEventResponse expectedResponse = ReportErrorEventResponse.newBuilder().build(); mockReportErrorsService.addResponse(expectedResponse); - String formattedProjectName = ReportErrorsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build(); - ReportErrorEventResponse actualResponse = client.reportErrorEvent(formattedProjectName, event); + ReportErrorEventResponse actualResponse = client.reportErrorEvent(projectName, event); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockReportErrorsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ReportErrorEventRequest actualRequest = (ReportErrorEventRequest) actualRequests.get(0); - Assert.assertEquals(formattedProjectName, actualRequest.getProjectName()); + Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName()); Assert.assertEquals(event, actualRequest.getEvent()); } @@ -102,10 +103,10 @@ public void reportErrorEventExceptionTest() throws Exception { mockReportErrorsService.addException(exception); try { - String formattedProjectName = ReportErrorsServiceClient.formatProjectName("[PROJECT]"); + ProjectName projectName = ProjectName.create("[PROJECT]"); ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build(); - client.reportErrorEvent(formattedProjectName, event); + client.reportErrorEvent(projectName, event); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); diff --git a/google-cloud-language/pom.xml b/google-cloud-language/pom.xml index 2d8c6ed025ad..db3b8fb82678 100644 --- a/google-cloud-language/pom.xml +++ b/google-cloud-language/pom.xml @@ -30,7 +30,7 @@ com.google.api.grpc grpc-google-cloud-language-v1 - 0.1.3 + 0.1.5 io.grpc diff --git a/google-cloud-logging/pom.xml b/google-cloud-logging/pom.xml index 9c5e73155481..5ea3038055b1 100644 --- a/google-cloud-logging/pom.xml +++ b/google-cloud-logging/pom.xml @@ -31,7 +31,7 @@ com.google.api.grpc grpc-google-cloud-logging-v2 - 0.1.4 + 0.1.5 io.grpc diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java index c6e570a2b577..6a930936adf8 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java @@ -184,8 +184,8 @@ public final ConfigServiceV2Settings getSettings() { * } *
* - * @param parent Required. The resource name where this sink was created: - *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" + * @param parent Required. The parent resource whose sinks are to be listed. Examples: + * `"projects/my-logging-project"`, `"organizations/123456789"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ListSinksPagedResponse listSinks(ParentNameOneof parent) { @@ -287,9 +287,10 @@ public final UnaryCallable listSinksCallabl * } *

* - * @param sinkName Required. The resource name of the sink to return: + * @param sinkName Required. The parent resource name of the sink: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" + *

Example: `"projects/my-project-id/sinks/my-sink-id"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogSink getSink(SinkNameOneof sinkName) { @@ -346,7 +347,10 @@ public final UnaryCallable getSinkCallable() { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates a sink. + * Creates a sink that exports specified log entries to a destination. The export of + * newly-ingested log entries begins immediately, unless the current time is outside the sink's + * start and end times or the sink's `writer_identity` is not permitted to write to the + * destination. A sink can export log entries only from the resource owning the sink. * *

Sample code: * @@ -360,6 +364,7 @@ public final UnaryCallable getSinkCallable() { * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" + *

Examples: `"projects/my-logging-project"`, `"organizations/123456789"`. * @param sink Required. The new sink, whose `name` parameter is a sink identifier that is not * already in use. * @throws com.google.api.gax.grpc.ApiException if the remote call fails @@ -373,7 +378,10 @@ public final LogSink createSink(ParentNameOneof parent, LogSink sink) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates a sink. + * Creates a sink that exports specified log entries to a destination. The export of + * newly-ingested log entries begins immediately, unless the current time is outside the sink's + * start and end times or the sink's `writer_identity` is not permitted to write to the + * destination. A sink can export log entries only from the resource owning the sink. * *

Sample code: * @@ -398,7 +406,10 @@ public final LogSink createSink(CreateSinkRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates a sink. + * Creates a sink that exports specified log entries to a destination. The export of + * newly-ingested log entries begins immediately, unless the current time is outside the sink's + * start and end times or the sink's `writer_identity` is not permitted to write to the + * destination. A sink can export log entries only from the resource owning the sink. * *

Sample code: * @@ -422,7 +433,12 @@ public final UnaryCallable createSinkCallable() { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Updates or creates a sink. + * Updates a sink. If the named sink doesn't exist, then this method is identical to + * [sinks.create](/logging/docs/api/reference/rest/v2/projects.sinks/create). If the named sink + * does exist, then this method replaces the following fields in the existing sink with values + * from the new sink: `destination`, `filter`, `output_version_format`, `start_time`, and + * `end_time`. The updated filter might also have a new `writer_identity`; see the + * `unique_writer_identity` field. * *

Sample code: * @@ -434,13 +450,13 @@ public final UnaryCallable createSinkCallable() { * } *

* - * @param sinkName Required. The resource name of the sink to update, including the parent + * @param sinkName Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" *

Example: `"projects/my-project-id/sinks/my-sink-id"`. * @param sink Required. The updated sink, whose name is the same identifier that appears as part - * of `sinkName`. If `sinkName` does not exist, then this method creates a new sink. + * of `sink_name`. If `sink_name` does not exist, then this method creates a new sink. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogSink updateSink(SinkNameOneof sinkName, LogSink sink) { @@ -452,7 +468,12 @@ public final LogSink updateSink(SinkNameOneof sinkName, LogSink sink) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Updates or creates a sink. + * Updates a sink. If the named sink doesn't exist, then this method is identical to + * [sinks.create](/logging/docs/api/reference/rest/v2/projects.sinks/create). If the named sink + * does exist, then this method replaces the following fields in the existing sink with values + * from the new sink: `destination`, `filter`, `output_version_format`, `start_time`, and + * `end_time`. The updated filter might also have a new `writer_identity`; see the + * `unique_writer_identity` field. * *

Sample code: * @@ -477,7 +498,12 @@ public final LogSink updateSink(UpdateSinkRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Updates or creates a sink. + * Updates a sink. If the named sink doesn't exist, then this method is identical to + * [sinks.create](/logging/docs/api/reference/rest/v2/projects.sinks/create). If the named sink + * does exist, then this method replaces the following fields in the existing sink with values + * from the new sink: `destination`, `filter`, `output_version_format`, `start_time`, and + * `end_time`. The updated filter might also have a new `writer_identity`; see the + * `unique_writer_identity` field. * *

Sample code: * @@ -501,7 +527,8 @@ public final UnaryCallable updateSinkCallable() { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes a sink. + * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also + * deleted. * *

Sample code: * @@ -512,11 +539,12 @@ public final UnaryCallable updateSinkCallable() { * } *

* - * @param sinkName Required. The resource name of the sink to delete, including the parent + * @param sinkName Required. The full resource name of the sink to delete, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" - *

It is an error if the sink does not exist. + *

It is an error if the sink does not exist. Example: + * `"projects/my-project-id/sinks/my-sink-id"`. It is an error if the sink does not exist. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteSink(SinkNameOneof sinkName) { @@ -528,7 +556,8 @@ public final void deleteSink(SinkNameOneof sinkName) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes a sink. + * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also + * deleted. * *

Sample code: * @@ -551,7 +580,8 @@ private final void deleteSink(DeleteSinkRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes a sink. + * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also + * deleted. * *

Sample code: * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java index 6948bba84a87..fd83a4e2471e 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java @@ -16,6 +16,7 @@ package com.google.cloud.logging.spi.v2; import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogEntriesPagedResponse; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogsPagedResponse; import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse; import com.google.api.MonitoredResource; @@ -24,10 +25,13 @@ import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; import com.google.logging.v2.ListLogEntriesResponse; +import com.google.logging.v2.ListLogsRequest; +import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; import com.google.logging.v2.LogNameOneof; +import com.google.logging.v2.ParentNameOneof; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -115,6 +119,8 @@ public class LoggingServiceV2Client implements AutoCloseable { private final UnaryCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsPagedCallable; + private final UnaryCallable listLogsCallable; + private final UnaryCallable listLogsPagedCallable; /** Constructs an instance of LoggingServiceV2Client with default settings. */ public static final LoggingServiceV2Client create() throws IOException { @@ -156,6 +162,10 @@ protected LoggingServiceV2Client(LoggingServiceV2Settings settings) throws IOExc this.listMonitoredResourceDescriptorsPagedCallable = UnaryCallable.createPagedVariant( settings.listMonitoredResourceDescriptorsSettings(), this.channel, this.executor); + this.listLogsCallable = + UnaryCallable.create(settings.listLogsSettings(), this.channel, this.executor); + this.listLogsPagedCallable = + UnaryCallable.createPagedVariant(settings.listLogsSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -356,8 +366,8 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists log entries. Use this method to retrieve log entries from Cloud Logging. For ways to - * export log entries, see [Exporting Logs](/logging/docs/export). + * Lists log entries. Use this method to retrieve log entries from Stackdriver Logging. For ways + * to export log entries, see [Exporting Logs](/logging/docs/export). * *

Sample code: * @@ -372,13 +382,16 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * } *

* - * @param resourceNames Required. One or more cloud resources from which to retrieve log entries: + * @param resourceNames Required. Names of one or more resources from which to retrieve log + * entries: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" *

Projects listed in the `project_ids` field are added to this list. * @param filter Optional. A filter that chooses which log entries to return. See [Advanced Logs * Filters](/logging/docs/view/advanced_filters). Only log entries that match the filter are - * returned. An empty filter matches all log entries. The maximum length of the filter is - * 20000 characters. + * returned. An empty filter matches all log entries in the resources listed in + * `resource_names`. Referencing a parent resource that is not listed in `resource_names` will + * cause the filter to return no results. The maximum length of the filter is 20000 + * characters. * @param orderBy Optional. How the results should be sorted. Presently, the only permitted values * are `"timestamp asc"` (default) and `"timestamp desc"`. The first option returns entries in * order of increasing values of `LogEntry.timestamp` (oldest first), and the second option @@ -399,8 +412,8 @@ public final ListLogEntriesPagedResponse listLogEntries( // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists log entries. Use this method to retrieve log entries from Cloud Logging. For ways to - * export log entries, see [Exporting Logs](/logging/docs/export). + * Lists log entries. Use this method to retrieve log entries from Stackdriver Logging. For ways + * to export log entries, see [Exporting Logs](/logging/docs/export). * *

Sample code: * @@ -425,8 +438,8 @@ public final ListLogEntriesPagedResponse listLogEntries(ListLogEntriesRequest re // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists log entries. Use this method to retrieve log entries from Cloud Logging. For ways to - * export log entries, see [Exporting Logs](/logging/docs/export). + * Lists log entries. Use this method to retrieve log entries from Stackdriver Logging. For ways + * to export log entries, see [Exporting Logs](/logging/docs/export). * *

Sample code: * @@ -451,8 +464,8 @@ public final ListLogEntriesPagedResponse listLogEntries(ListLogEntriesRequest re // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists log entries. Use this method to retrieve log entries from Cloud Logging. For ways to - * export log entries, see [Exporting Logs](/logging/docs/export). + * Lists log entries. Use this method to retrieve log entries from Stackdriver Logging. For ways + * to export log entries, see [Exporting Logs](/logging/docs/export). * *

Sample code: * @@ -484,7 +497,7 @@ public final ListLogEntriesPagedResponse listLogEntries(ListLogEntriesRequest re // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the monitored resource descriptors used by Stackdriver Logging. + * Lists the descriptors for monitored resource types used by Stackdriver Logging. * *

Sample code: * @@ -507,7 +520,7 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the monitored resource descriptors used by Stackdriver Logging. + * Lists the descriptors for monitored resource types used by Stackdriver Logging. * *

Sample code: * @@ -530,7 +543,7 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the monitored resource descriptors used by Stackdriver Logging. + * Lists the descriptors for monitored resource types used by Stackdriver Logging. * *

Sample code: * @@ -558,6 +571,111 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource return listMonitoredResourceDescriptorsCallable; } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists the logs in projects or organizations. Only logs that have entries are listed. + * + *

Sample code: + * + *


+   * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
+   *   ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
+   *   for (String element : loggingServiceV2Client.listLogs(parent).iterateAllElements()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @param parent Required. The resource name that owns the logs: + *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" + * @throws com.google.api.gax.grpc.ApiException if the remote call fails + */ + public final ListLogsPagedResponse listLogs(ParentNameOneof parent) { + ListLogsRequest request = + ListLogsRequest.newBuilder().setParentWithParentNameOneof(parent).build(); + return listLogs(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists the logs in projects or organizations. Only logs that have entries are listed. + * + *

Sample code: + * + *


+   * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
+   *   ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
+   *   ListLogsRequest request = ListLogsRequest.newBuilder()
+   *     .setParentWithParentNameOneof(parent)
+   *     .build();
+   *   for (String element : loggingServiceV2Client.listLogs(request).iterateAllElements()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.grpc.ApiException if the remote call fails + */ + public final ListLogsPagedResponse listLogs(ListLogsRequest request) { + return listLogsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists the logs in projects or organizations. Only logs that have entries are listed. + * + *

Sample code: + * + *


+   * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
+   *   ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
+   *   ListLogsRequest request = ListLogsRequest.newBuilder()
+   *     .setParentWithParentNameOneof(parent)
+   *     .build();
+   *   ListenableFuture<ListLogsPagedResponse> future = loggingServiceV2Client.listLogsPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (String element : future.get().iterateAllElements()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ */ + public final UnaryCallable listLogsPagedCallable() { + return listLogsPagedCallable; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists the logs in projects or organizations. Only logs that have entries are listed. + * + *

Sample code: + * + *


+   * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
+   *   ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
+   *   ListLogsRequest request = ListLogsRequest.newBuilder()
+   *     .setParentWithParentNameOneof(parent)
+   *     .build();
+   *   while (true) {
+   *     ListLogsResponse response = loggingServiceV2Client.listLogsCallable().call(request);
+   *     for (String element : response.getLogNamesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ */ + public final UnaryCallable listLogsCallable() { + return listLogsCallable; + } + /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java index 3d643d08dbb4..e854c3fcf872 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java @@ -16,6 +16,7 @@ package com.google.cloud.logging.spi.v2; import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogEntriesPagedResponse; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogsPagedResponse; import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse; import com.google.api.MonitoredResourceDescriptor; @@ -41,6 +42,8 @@ import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; import com.google.logging.v2.ListLogEntriesResponse; +import com.google.logging.v2.ListLogsRequest; +import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; @@ -109,6 +112,8 @@ public class LoggingServiceV2Settings extends ClientSettings { ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings; + private final PagedCallSettings + listLogsSettings; /** Returns the object with the settings used for calls to deleteLog. */ public SimpleCallSettings deleteLogSettings() { @@ -136,6 +141,12 @@ public SimpleCallSettings deleteLogSettings() { return listMonitoredResourceDescriptorsSettings; } + /** Returns the object with the settings used for calls to listLogs. */ + public PagedCallSettings + listLogsSettings() { + return listLogsSettings; + } + /** Returns a builder for the default ExecutorProvider for this service. */ public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { return InstantiatingExecutorProvider.newBuilder(); @@ -192,6 +203,7 @@ private LoggingServiceV2Settings(Builder settingsBuilder) throws IOException { listLogEntriesSettings = settingsBuilder.listLogEntriesSettings().build(); listMonitoredResourceDescriptorsSettings = settingsBuilder.listMonitoredResourceDescriptorsSettings().build(); + listLogsSettings = settingsBuilder.listLogsSettings().build(); } private static final PagedListDescriptor @@ -274,6 +286,40 @@ public Iterable extractResources( } }; + private static final PagedListDescriptor + LIST_LOGS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public Object emptyToken() { + return ""; + } + + @Override + public ListLogsRequest injectToken(ListLogsRequest payload, Object token) { + return ListLogsRequest.newBuilder(payload).setPageToken((String) token).build(); + } + + @Override + public ListLogsRequest injectPageSize(ListLogsRequest payload, int pageSize) { + return ListLogsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListLogsRequest payload) { + return payload.getPageSize(); + } + + @Override + public Object extractNextToken(ListLogsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListLogsResponse payload) { + return payload.getLogNamesList(); + } + }; + private static final PagedListResponseFactory< ListLogEntriesRequest, ListLogEntriesResponse, ListLogEntriesPagedResponse> LIST_LOG_ENTRIES_PAGE_STR_FACT = @@ -309,6 +355,19 @@ public ListMonitoredResourceDescriptorsPagedResponse createPagedListResponse( } }; + private static final PagedListResponseFactory< + ListLogsRequest, ListLogsResponse, ListLogsPagedResponse> + LIST_LOGS_PAGE_STR_FACT = + new PagedListResponseFactory() { + @Override + public ListLogsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListLogsRequest request, + CallContext context) { + return new ListLogsPagedResponse(callable, LIST_LOGS_PAGE_STR_DESC, request, context); + } + }; + /** Builder for LoggingServiceV2Settings. */ public static class Builder extends ClientSettings.Builder { private final ImmutableList unaryMethodSettingsBuilders; @@ -323,6 +382,9 @@ public static class Builder extends ClientSettings.Builder { ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings; + private final PagedCallSettings.Builder< + ListLogsRequest, ListLogsResponse, ListLogsPagedResponse> + listLogsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -382,12 +444,17 @@ private Builder() { LoggingServiceV2Grpc.METHOD_LIST_MONITORED_RESOURCE_DESCRIPTORS, LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT); + listLogsSettings = + PagedCallSettings.newBuilder( + LoggingServiceV2Grpc.METHOD_LIST_LOGS, LIST_LOGS_PAGE_STR_FACT); + unaryMethodSettingsBuilders = ImmutableList.of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, - listMonitoredResourceDescriptorsSettings); + listMonitoredResourceDescriptorsSettings, + listLogsSettings); } private static Builder createDefault() { @@ -413,6 +480,11 @@ private static Builder createDefault() { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + builder + .listLogsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + return builder; } @@ -424,13 +496,15 @@ private Builder(LoggingServiceV2Settings settings) { listLogEntriesSettings = settings.listLogEntriesSettings.toBuilder(); listMonitoredResourceDescriptorsSettings = settings.listMonitoredResourceDescriptorsSettings.toBuilder(); + listLogsSettings = settings.listLogsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, - listMonitoredResourceDescriptorsSettings); + listMonitoredResourceDescriptorsSettings, + listLogsSettings); } @Override @@ -483,6 +557,12 @@ public SimpleCallSettings.Builder deleteLogSettings() { return listMonitoredResourceDescriptorsSettings; } + /** Returns the builder for the settings used for calls to listLogs. */ + public PagedCallSettings.Builder + listLogsSettings() { + return listLogsSettings; + } + @Override public LoggingServiceV2Settings build() throws IOException { return new LoggingServiceV2Settings(this); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/PagedResponseWrappers.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/PagedResponseWrappers.java index 60e880bca655..30ac77a1cd25 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/PagedResponseWrappers.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/PagedResponseWrappers.java @@ -24,6 +24,8 @@ import com.google.logging.v2.ListLogEntriesResponse; import com.google.logging.v2.ListLogMetricsRequest; import com.google.logging.v2.ListLogMetricsResponse; +import com.google.logging.v2.ListLogsRequest; +import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.ListSinksRequest; @@ -75,6 +77,18 @@ public ListMonitoredResourceDescriptorsPagedResponse( } } + public static class ListLogsPagedResponse + extends PagedListResponseImpl { + + public ListLogsPagedResponse( + UnaryCallable callable, + PagedListDescriptor pageDescriptor, + ListLogsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + public static class ListSinksPagedResponse extends PagedListResponseImpl { diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Test.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Test.java index c12e838da738..a2f10062c3bb 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Test.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Test.java @@ -16,6 +16,7 @@ package com.google.cloud.logging.spi.v2; import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogEntriesPagedResponse; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogsPagedResponse; import com.google.api.MonitoredResource; import com.google.api.gax.grpc.ApiException; @@ -25,9 +26,13 @@ import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; import com.google.logging.v2.ListLogEntriesResponse; +import com.google.logging.v2.ListLogsRequest; +import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.LogEntry; import com.google.logging.v2.LogName; import com.google.logging.v2.LogNameOneof; +import com.google.logging.v2.ParentNameOneof; +import com.google.logging.v2.ProjectName; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -215,4 +220,48 @@ public void listLogEntriesExceptionTest() throws Exception { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); } } + + @Test + @SuppressWarnings("all") + public void listLogsTest() { + String nextPageToken = ""; + String logNamesElement = "logNamesElement-1079688374"; + List logNames = Arrays.asList(logNamesElement); + ListLogsResponse expectedResponse = + ListLogsResponse.newBuilder() + .setNextPageToken(nextPageToken) + .addAllLogNames(logNames) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]")); + + ListLogsPagedResponse pagedListResponse = client.listLogs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogsRequest actualRequest = (ListLogsRequest) actualRequests.get(0); + + Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof()); + } + + @Test + @SuppressWarnings("all") + public void listLogsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INTERNAL); + mockLoggingServiceV2.addException(exception); + + try { + ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]")); + + client.listLogs(parent); + Assert.fail("No exception raised"); + } catch (ApiException e) { + Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); + } + } } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2Impl.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2Impl.java index c6775b8908bb..02090c9934d4 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2Impl.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2Impl.java @@ -18,6 +18,8 @@ import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; import com.google.logging.v2.ListLogEntriesResponse; +import com.google.logging.v2.ListLogsRequest; +import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LoggingServiceV2Grpc.LoggingServiceV2ImplBase; @@ -121,4 +123,18 @@ public void listMonitoredResourceDescriptors( responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } } + + @Override + public void listLogs(ListLogsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListLogsResponse) { + requests.add(request); + responseObserver.onNext((ListLogsResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } } diff --git a/google-cloud-monitoring/pom.xml b/google-cloud-monitoring/pom.xml index be83a529ed1b..ff4c86b3f52d 100644 --- a/google-cloud-monitoring/pom.xml +++ b/google-cloud-monitoring/pom.xml @@ -30,7 +30,7 @@ com.google.api.grpc grpc-google-cloud-monitoring-v3 - 0.1.3 + 0.1.5 io.grpc diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceClient.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceClient.java index d1f05562d37b..c927f6dc3ee2 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceClient.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceClient.java @@ -20,15 +20,16 @@ import com.google.api.gax.grpc.ChannelAndExecutor; import com.google.api.gax.grpc.UnaryCallable; -import com.google.api.gax.protobuf.PathTemplate; import com.google.monitoring.v3.CreateGroupRequest; import com.google.monitoring.v3.DeleteGroupRequest; import com.google.monitoring.v3.GetGroupRequest; import com.google.monitoring.v3.Group; +import com.google.monitoring.v3.GroupName; import com.google.monitoring.v3.ListGroupMembersRequest; import com.google.monitoring.v3.ListGroupMembersResponse; import com.google.monitoring.v3.ListGroupsRequest; import com.google.monitoring.v3.ListGroupsResponse; +import com.google.monitoring.v3.ProjectName; import com.google.monitoring.v3.UpdateGroupRequest; import com.google.protobuf.Empty; import com.google.protobuf.ExperimentalApi; @@ -58,8 +59,8 @@ *
  * 
  * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
- *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
- *   Group response = groupServiceClient.getGroup(formattedName);
+ *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
+ *   Group response = groupServiceClient.getGroup(name);
  * }
  * 
  * 
@@ -122,39 +123,6 @@ public class GroupServiceClient implements AutoCloseable { private final UnaryCallable listGroupMembersPagedCallable; - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}"); - - private static final PathTemplate GROUP_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}/groups/{group}"); - - /** Formats a string containing the fully-qualified path to represent a project resource. */ - public static final String formatProjectName(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** Formats a string containing the fully-qualified path to represent a group resource. */ - public static final String formatGroupName(String project, String group) { - return GROUP_PATH_TEMPLATE.instantiate( - "project", project, - "group", group); - } - - /** Parses the project from the given fully-qualified path which represents a project resource. */ - public static final String parseProjectFromProjectName(String projectName) { - return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); - } - - /** Parses the project from the given fully-qualified path which represents a group resource. */ - public static final String parseProjectFromGroupName(String groupName) { - return GROUP_PATH_TEMPLATE.parse(groupName).get("project"); - } - - /** Parses the group from the given fully-qualified path which represents a group resource. */ - public static final String parseGroupFromGroupName(String groupName) { - return GROUP_PATH_TEMPLATE.parse(groupName).get("group"); - } - /** Constructs an instance of GroupServiceClient with default settings. */ public static final GroupServiceClient create() throws IOException { return create(GroupServiceSettings.defaultBuilder().build()); @@ -229,9 +197,9 @@ public final GroupServiceSettings getSettings() { * *

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListGroupsRequest request = ListGroupsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   for (Group element : groupServiceClient.listGroups(request).iterateAllElements()) {
    *     // doThingsWith(element);
@@ -254,9 +222,9 @@ public final ListGroupsPagedResponse listGroups(ListGroupsRequest request) {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListGroupsRequest request = ListGroupsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   ListenableFuture<ListGroupsPagedResponse> future = groupServiceClient.listGroupsPagedCallable().futureCall(request);
    *   // Do something
@@ -278,9 +246,9 @@ public final UnaryCallable listGroup
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListGroupsRequest request = ListGroupsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   while (true) {
    *     ListGroupsResponse response = groupServiceClient.listGroupsCallable().call(request);
@@ -309,8 +277,8 @@ public final UnaryCallable listGroupsCall
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
-   *   Group response = groupServiceClient.getGroup(formattedName);
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
+   *   Group response = groupServiceClient.getGroup(name);
    * }
    * 
* @@ -318,9 +286,9 @@ public final UnaryCallable listGroupsCall * `"projects/{project_id_or_number}/groups/{group_id}"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Group getGroup(String name) { - GROUP_PATH_TEMPLATE.validate(name, "getGroup"); - GetGroupRequest request = GetGroupRequest.newBuilder().setName(name).build(); + public final Group getGroup(GroupName name) { + + GetGroupRequest request = GetGroupRequest.newBuilder().setNameWithGroupName(name).build(); return getGroup(request); } @@ -332,9 +300,9 @@ public final Group getGroup(String name) { * *

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    *   GetGroupRequest request = GetGroupRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithGroupName(name)
    *     .build();
    *   Group response = groupServiceClient.getGroup(request);
    * }
@@ -355,9 +323,9 @@ private final Group getGroup(GetGroupRequest request) {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    *   GetGroupRequest request = GetGroupRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithGroupName(name)
    *     .build();
    *   ListenableFuture<Group> future = groupServiceClient.getGroupCallable().futureCall(request);
    *   // Do something
@@ -377,9 +345,9 @@ public final UnaryCallable getGroupCallable() {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   Group group = Group.newBuilder().build();
-   *   Group response = groupServiceClient.createGroup(formattedName, group);
+   *   Group response = groupServiceClient.createGroup(name, group);
    * }
    * 
* @@ -389,10 +357,10 @@ public final UnaryCallable getGroupCallable() { * assigns the name. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Group createGroup(String name, Group group) { - PROJECT_PATH_TEMPLATE.validate(name, "createGroup"); + public final Group createGroup(ProjectName name, Group group) { + CreateGroupRequest request = - CreateGroupRequest.newBuilder().setName(name).setGroup(group).build(); + CreateGroupRequest.newBuilder().setNameWithProjectName(name).setGroup(group).build(); return createGroup(request); } @@ -404,10 +372,10 @@ public final Group createGroup(String name, Group group) { * *

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   Group group = Group.newBuilder().build();
    *   CreateGroupRequest request = CreateGroupRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .setGroup(group)
    *     .build();
    *   Group response = groupServiceClient.createGroup(request);
@@ -429,10 +397,10 @@ public final Group createGroup(CreateGroupRequest request) {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   Group group = Group.newBuilder().build();
    *   CreateGroupRequest request = CreateGroupRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .setGroup(group)
    *     .build();
    *   ListenableFuture<Group> future = groupServiceClient.createGroupCallable().futureCall(request);
@@ -521,8 +489,8 @@ public final UnaryCallable updateGroupCallable() {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
-   *   groupServiceClient.deleteGroup(formattedName);
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
+   *   groupServiceClient.deleteGroup(name);
    * }
    * 
* @@ -530,9 +498,9 @@ public final UnaryCallable updateGroupCallable() { * `"projects/{project_id_or_number}/groups/{group_id}"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void deleteGroup(String name) { - GROUP_PATH_TEMPLATE.validate(name, "deleteGroup"); - DeleteGroupRequest request = DeleteGroupRequest.newBuilder().setName(name).build(); + public final void deleteGroup(GroupName name) { + + DeleteGroupRequest request = DeleteGroupRequest.newBuilder().setNameWithGroupName(name).build(); deleteGroup(request); } @@ -544,9 +512,9 @@ public final void deleteGroup(String name) { * *

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    *   DeleteGroupRequest request = DeleteGroupRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithGroupName(name)
    *     .build();
    *   groupServiceClient.deleteGroup(request);
    * }
@@ -567,9 +535,9 @@ private final void deleteGroup(DeleteGroupRequest request) {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    *   DeleteGroupRequest request = DeleteGroupRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithGroupName(name)
    *     .build();
    *   ListenableFuture<Void> future = groupServiceClient.deleteGroupCallable().futureCall(request);
    *   // Do something
@@ -589,8 +557,8 @@ public final UnaryCallable deleteGroupCallable() {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
-   *   for (MonitoredResource element : groupServiceClient.listGroupMembers(formattedName).iterateAllElements()) {
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
+   *   for (MonitoredResource element : groupServiceClient.listGroupMembers(name).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -600,9 +568,9 @@ public final UnaryCallable deleteGroupCallable() {
    *     `"projects/{project_id_or_number}/groups/{group_id}"`.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final ListGroupMembersPagedResponse listGroupMembers(String name) {
-    GROUP_PATH_TEMPLATE.validate(name, "listGroupMembers");
-    ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder().setName(name).build();
+  public final ListGroupMembersPagedResponse listGroupMembers(GroupName name) {
+    ListGroupMembersRequest request =
+        ListGroupMembersRequest.newBuilder().setNameWithGroupName(name).build();
     return listGroupMembers(request);
   }
 
@@ -614,9 +582,9 @@ public final ListGroupMembersPagedResponse listGroupMembers(String name) {
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    *   ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithGroupName(name)
    *     .build();
    *   for (MonitoredResource element : groupServiceClient.listGroupMembers(request).iterateAllElements()) {
    *     // doThingsWith(element);
@@ -639,9 +607,9 @@ public final ListGroupMembersPagedResponse listGroupMembers(ListGroupMembersRequ
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    *   ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithGroupName(name)
    *     .build();
    *   ListenableFuture<ListGroupMembersPagedResponse> future = groupServiceClient.listGroupMembersPagedCallable().futureCall(request);
    *   // Do something
@@ -664,9 +632,9 @@ public final ListGroupMembersPagedResponse listGroupMembers(ListGroupMembersRequ
    *
    * 

    * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
-   *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
+   *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    *   ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithGroupName(name)
    *     .build();
    *   while (true) {
    *     ListGroupMembersResponse response = groupServiceClient.listGroupMembersCallable().call(request);
diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceClient.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceClient.java
index a3c34aec881a..7dbe8909633d 100644
--- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceClient.java
+++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceClient.java
@@ -23,7 +23,6 @@
 import com.google.api.MonitoredResourceDescriptor;
 import com.google.api.gax.grpc.ChannelAndExecutor;
 import com.google.api.gax.grpc.UnaryCallable;
-import com.google.api.gax.protobuf.PathTemplate;
 import com.google.monitoring.v3.CreateMetricDescriptorRequest;
 import com.google.monitoring.v3.CreateTimeSeriesRequest;
 import com.google.monitoring.v3.DeleteMetricDescriptorRequest;
@@ -36,6 +35,9 @@
 import com.google.monitoring.v3.ListTimeSeriesRequest;
 import com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView;
 import com.google.monitoring.v3.ListTimeSeriesResponse;
+import com.google.monitoring.v3.MetricDescriptorName;
+import com.google.monitoring.v3.MonitoredResourceDescriptorName;
+import com.google.monitoring.v3.ProjectName;
 import com.google.monitoring.v3.TimeInterval;
 import com.google.monitoring.v3.TimeSeries;
 import com.google.protobuf.Empty;
@@ -59,8 +61,8 @@
  * 
  * 
  * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
- *   String formattedName = MetricServiceClient.formatMonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
- *   MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(formattedName);
+ *   MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
+ *   MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(name);
  * }
  * 
  * 
@@ -134,86 +136,6 @@ public class MetricServiceClient implements AutoCloseable { listTimeSeriesPagedCallable; private final UnaryCallable createTimeSeriesCallable; - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}"); - - private static final PathTemplate METRIC_DESCRIPTOR_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding( - "projects/{project}/metricDescriptors/{metric_descriptor=**}"); - - private static final PathTemplate MONITORED_RESOURCE_DESCRIPTOR_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding( - "projects/{project}/monitoredResourceDescriptors/{monitored_resource_descriptor}"); - - /** Formats a string containing the fully-qualified path to represent a project resource. */ - public static final String formatProjectName(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** - * Formats a string containing the fully-qualified path to represent a metric_descriptor resource. - */ - public static final String formatMetricDescriptorName(String project, String metricDescriptor) { - return METRIC_DESCRIPTOR_PATH_TEMPLATE.instantiate( - "project", project, - "metric_descriptor", metricDescriptor); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * monitored_resource_descriptor resource. - */ - public static final String formatMonitoredResourceDescriptorName( - String project, String monitoredResourceDescriptor) { - return MONITORED_RESOURCE_DESCRIPTOR_PATH_TEMPLATE.instantiate( - "project", project, - "monitored_resource_descriptor", monitoredResourceDescriptor); - } - - /** Parses the project from the given fully-qualified path which represents a project resource. */ - public static final String parseProjectFromProjectName(String projectName) { - return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); - } - - /** - * Parses the project from the given fully-qualified path which represents a metric_descriptor - * resource. - */ - public static final String parseProjectFromMetricDescriptorName(String metricDescriptorName) { - return METRIC_DESCRIPTOR_PATH_TEMPLATE.parse(metricDescriptorName).get("project"); - } - - /** - * Parses the metric_descriptor from the given fully-qualified path which represents a - * metric_descriptor resource. - */ - public static final String parseMetricDescriptorFromMetricDescriptorName( - String metricDescriptorName) { - return METRIC_DESCRIPTOR_PATH_TEMPLATE.parse(metricDescriptorName).get("metric_descriptor"); - } - - /** - * Parses the project from the given fully-qualified path which represents a - * monitored_resource_descriptor resource. - */ - public static final String parseProjectFromMonitoredResourceDescriptorName( - String monitoredResourceDescriptorName) { - return MONITORED_RESOURCE_DESCRIPTOR_PATH_TEMPLATE - .parse(monitoredResourceDescriptorName) - .get("project"); - } - - /** - * Parses the monitored_resource_descriptor from the given fully-qualified path which represents a - * monitored_resource_descriptor resource. - */ - public static final String parseMonitoredResourceDescriptorFromMonitoredResourceDescriptorName( - String monitoredResourceDescriptorName) { - return MONITORED_RESOURCE_DESCRIPTOR_PATH_TEMPLATE - .parse(monitoredResourceDescriptorName) - .get("monitored_resource_descriptor"); - } - /** Constructs an instance of MetricServiceClient with default settings. */ public static final MetricServiceClient create() throws IOException { return create(MetricServiceSettings.defaultBuilder().build()); @@ -301,8 +223,8 @@ public final MetricServiceSettings getSettings() { * *

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
-   *   for (MonitoredResourceDescriptor element : metricServiceClient.listMonitoredResourceDescriptors(formattedName).iterateAllElements()) {
+   *   ProjectName name = ProjectName.create("[PROJECT]");
+   *   for (MonitoredResourceDescriptor element : metricServiceClient.listMonitoredResourceDescriptors(name).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -313,10 +235,9 @@ public final MetricServiceSettings getSettings() {
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
   public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResourceDescriptors(
-      String name) {
-    PROJECT_PATH_TEMPLATE.validate(name, "listMonitoredResourceDescriptors");
+      ProjectName name) {
     ListMonitoredResourceDescriptorsRequest request =
-        ListMonitoredResourceDescriptorsRequest.newBuilder().setName(name).build();
+        ListMonitoredResourceDescriptorsRequest.newBuilder().setNameWithProjectName(name).build();
     return listMonitoredResourceDescriptors(request);
   }
 
@@ -329,9 +250,9 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   for (MonitoredResourceDescriptor element : metricServiceClient.listMonitoredResourceDescriptors(request).iterateAllElements()) {
    *     // doThingsWith(element);
@@ -356,9 +277,9 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   ListenableFuture<ListMonitoredResourceDescriptorsPagedResponse> future = metricServiceClient.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
    *   // Do something
@@ -383,9 +304,9 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   while (true) {
    *     ListMonitoredResourceDescriptorsResponse response = metricServiceClient.listMonitoredResourceDescriptorsCallable().call(request);
@@ -417,8 +338,8 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
-   *   MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(formattedName);
+   *   MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
+   *   MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(name);
    * }
    * 
* @@ -427,10 +348,13 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource * `{resource_type}` is a predefined type, such as `cloudsql_database`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final MonitoredResourceDescriptor getMonitoredResourceDescriptor(String name) { - MONITORED_RESOURCE_DESCRIPTOR_PATH_TEMPLATE.validate(name, "getMonitoredResourceDescriptor"); + public final MonitoredResourceDescriptor getMonitoredResourceDescriptor( + MonitoredResourceDescriptorName name) { + GetMonitoredResourceDescriptorRequest request = - GetMonitoredResourceDescriptorRequest.newBuilder().setName(name).build(); + GetMonitoredResourceDescriptorRequest.newBuilder() + .setNameWithMonitoredResourceDescriptorName(name) + .build(); return getMonitoredResourceDescriptor(request); } @@ -443,9 +367,9 @@ public final MonitoredResourceDescriptor getMonitoredResourceDescriptor(String n * *

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
+   *   MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
    *   GetMonitoredResourceDescriptorRequest request = GetMonitoredResourceDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithMonitoredResourceDescriptorName(name)
    *     .build();
    *   MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(request);
    * }
@@ -468,9 +392,9 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
+   *   MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
    *   GetMonitoredResourceDescriptorRequest request = GetMonitoredResourceDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithMonitoredResourceDescriptorName(name)
    *     .build();
    *   ListenableFuture<MonitoredResourceDescriptor> future = metricServiceClient.getMonitoredResourceDescriptorCallable().futureCall(request);
    *   // Do something
@@ -492,8 +416,8 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
-   *   for (MetricDescriptor element : metricServiceClient.listMetricDescriptors(formattedName).iterateAllElements()) {
+   *   ProjectName name = ProjectName.create("[PROJECT]");
+   *   for (MetricDescriptor element : metricServiceClient.listMetricDescriptors(name).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -503,10 +427,9 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
    *     `"projects/{project_id_or_number}"`.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final ListMetricDescriptorsPagedResponse listMetricDescriptors(String name) {
-    PROJECT_PATH_TEMPLATE.validate(name, "listMetricDescriptors");
+  public final ListMetricDescriptorsPagedResponse listMetricDescriptors(ProjectName name) {
     ListMetricDescriptorsRequest request =
-        ListMetricDescriptorsRequest.newBuilder().setName(name).build();
+        ListMetricDescriptorsRequest.newBuilder().setNameWithProjectName(name).build();
     return listMetricDescriptors(request);
   }
 
@@ -519,9 +442,9 @@ public final ListMetricDescriptorsPagedResponse listMetricDescriptors(String nam
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   for (MetricDescriptor element : metricServiceClient.listMetricDescriptors(request).iterateAllElements()) {
    *     // doThingsWith(element);
@@ -546,9 +469,9 @@ public final ListMetricDescriptorsPagedResponse listMetricDescriptors(
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   ListenableFuture<ListMetricDescriptorsPagedResponse> future = metricServiceClient.listMetricDescriptorsPagedCallable().futureCall(request);
    *   // Do something
@@ -572,9 +495,9 @@ public final ListMetricDescriptorsPagedResponse listMetricDescriptors(
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .build();
    *   while (true) {
    *     ListMetricDescriptorsResponse response = metricServiceClient.listMetricDescriptorsCallable().call(request);
@@ -604,8 +527,8 @@ public final ListMetricDescriptorsPagedResponse listMetricDescriptors(
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
-   *   MetricDescriptor response = metricServiceClient.getMetricDescriptor(formattedName);
+   *   MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
+   *   MetricDescriptor response = metricServiceClient.getMetricDescriptor(name);
    * }
    * 
* @@ -614,10 +537,10 @@ public final ListMetricDescriptorsPagedResponse listMetricDescriptors( * `{metric_id}` is `"compute.googleapis.com/instance/disk/read_bytes_count"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final MetricDescriptor getMetricDescriptor(String name) { - METRIC_DESCRIPTOR_PATH_TEMPLATE.validate(name, "getMetricDescriptor"); + public final MetricDescriptor getMetricDescriptor(MetricDescriptorName name) { + GetMetricDescriptorRequest request = - GetMetricDescriptorRequest.newBuilder().setName(name).build(); + GetMetricDescriptorRequest.newBuilder().setNameWithMetricDescriptorName(name).build(); return getMetricDescriptor(request); } @@ -629,9 +552,9 @@ public final MetricDescriptor getMetricDescriptor(String name) { * *

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
+   *   MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
    *   GetMetricDescriptorRequest request = GetMetricDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithMetricDescriptorName(name)
    *     .build();
    *   MetricDescriptor response = metricServiceClient.getMetricDescriptor(request);
    * }
@@ -652,9 +575,9 @@ private final MetricDescriptor getMetricDescriptor(GetMetricDescriptorRequest re
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
+   *   MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
    *   GetMetricDescriptorRequest request = GetMetricDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithMetricDescriptorName(name)
    *     .build();
    *   ListenableFuture<MetricDescriptor> future = metricServiceClient.getMetricDescriptorCallable().futureCall(request);
    *   // Do something
@@ -676,9 +599,9 @@ private final MetricDescriptor getMetricDescriptor(GetMetricDescriptorRequest re
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
-   *   MetricDescriptor response = metricServiceClient.createMetricDescriptor(formattedName, metricDescriptor);
+   *   MetricDescriptor response = metricServiceClient.createMetricDescriptor(name, metricDescriptor);
    * }
    * 
* @@ -688,11 +611,11 @@ private final MetricDescriptor getMetricDescriptor(GetMetricDescriptorRequest re * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final MetricDescriptor createMetricDescriptor( - String name, MetricDescriptor metricDescriptor) { - PROJECT_PATH_TEMPLATE.validate(name, "createMetricDescriptor"); + ProjectName name, MetricDescriptor metricDescriptor) { + CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder() - .setName(name) + .setNameWithProjectName(name) .setMetricDescriptor(metricDescriptor) .build(); return createMetricDescriptor(request); @@ -707,10 +630,10 @@ public final MetricDescriptor createMetricDescriptor( * *

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
    *   CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .setMetricDescriptor(metricDescriptor)
    *     .build();
    *   MetricDescriptor response = metricServiceClient.createMetricDescriptor(request);
@@ -733,10 +656,10 @@ public final MetricDescriptor createMetricDescriptor(CreateMetricDescriptorReque
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build();
    *   CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .setMetricDescriptor(metricDescriptor)
    *     .build();
    *   ListenableFuture<MetricDescriptor> future = metricServiceClient.createMetricDescriptorCallable().futureCall(request);
@@ -759,8 +682,8 @@ public final MetricDescriptor createMetricDescriptor(CreateMetricDescriptorReque
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
-   *   metricServiceClient.deleteMetricDescriptor(formattedName);
+   *   MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
+   *   metricServiceClient.deleteMetricDescriptor(name);
    * }
    * 
* @@ -769,10 +692,10 @@ public final MetricDescriptor createMetricDescriptor(CreateMetricDescriptorReque * `{metric_id}` is: `"custom.googleapis.com/my_test_metric"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void deleteMetricDescriptor(String name) { - METRIC_DESCRIPTOR_PATH_TEMPLATE.validate(name, "deleteMetricDescriptor"); + public final void deleteMetricDescriptor(MetricDescriptorName name) { + DeleteMetricDescriptorRequest request = - DeleteMetricDescriptorRequest.newBuilder().setName(name).build(); + DeleteMetricDescriptorRequest.newBuilder().setNameWithMetricDescriptorName(name).build(); deleteMetricDescriptor(request); } @@ -785,9 +708,9 @@ public final void deleteMetricDescriptor(String name) { * *

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
+   *   MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
    *   DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithMetricDescriptorName(name)
    *     .build();
    *   metricServiceClient.deleteMetricDescriptor(request);
    * }
@@ -809,9 +732,9 @@ private final void deleteMetricDescriptor(DeleteMetricDescriptorRequest request)
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
+   *   MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
    *   DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithMetricDescriptorName(name)
    *     .build();
    *   ListenableFuture<Void> future = metricServiceClient.deleteMetricDescriptorCallable().futureCall(request);
    *   // Do something
@@ -832,11 +755,11 @@ private final void deleteMetricDescriptor(DeleteMetricDescriptorRequest request)
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   String filter = "";
    *   TimeInterval interval = TimeInterval.newBuilder().build();
    *   ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
-   *   for (TimeSeries element : metricServiceClient.listTimeSeries(formattedName, filter, interval, view).iterateAllElements()) {
+   *   for (TimeSeries element : metricServiceClient.listTimeSeries(name, filter, interval, view).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -855,14 +778,13 @@ private final void deleteMetricDescriptor(DeleteMetricDescriptorRequest request)
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
   public final ListTimeSeriesPagedResponse listTimeSeries(
-      String name,
+      ProjectName name,
       String filter,
       TimeInterval interval,
       ListTimeSeriesRequest.TimeSeriesView view) {
-    PROJECT_PATH_TEMPLATE.validate(name, "listTimeSeries");
     ListTimeSeriesRequest request =
         ListTimeSeriesRequest.newBuilder()
-            .setName(name)
+            .setNameWithProjectName(name)
             .setFilter(filter)
             .setInterval(interval)
             .setView(view)
@@ -878,12 +800,12 @@ public final ListTimeSeriesPagedResponse listTimeSeries(
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   String filter = "";
    *   TimeInterval interval = TimeInterval.newBuilder().build();
    *   ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
    *   ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .setFilter(filter)
    *     .setInterval(interval)
    *     .setView(view)
@@ -909,12 +831,12 @@ public final ListTimeSeriesPagedResponse listTimeSeries(ListTimeSeriesRequest re
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   String filter = "";
    *   TimeInterval interval = TimeInterval.newBuilder().build();
    *   ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
    *   ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .setFilter(filter)
    *     .setInterval(interval)
    *     .setView(view)
@@ -940,12 +862,12 @@ public final ListTimeSeriesPagedResponse listTimeSeries(ListTimeSeriesRequest re
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   String filter = "";
    *   TimeInterval interval = TimeInterval.newBuilder().build();
    *   ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
    *   ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .setFilter(filter)
    *     .setInterval(interval)
    *     .setView(view)
@@ -980,9 +902,9 @@ public final ListTimeSeriesPagedResponse listTimeSeries(ListTimeSeriesRequest re
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   List<TimeSeries> timeSeries = new ArrayList<>();
-   *   metricServiceClient.createTimeSeries(formattedName, timeSeries);
+   *   metricServiceClient.createTimeSeries(name, timeSeries);
    * }
    * 
* @@ -994,10 +916,13 @@ public final ListTimeSeriesPagedResponse listTimeSeries(ListTimeSeriesRequest re * by supplying all label values for the metric and the monitored resource. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void createTimeSeries(String name, List timeSeries) { - PROJECT_PATH_TEMPLATE.validate(name, "createTimeSeries"); + public final void createTimeSeries(ProjectName name, List timeSeries) { + CreateTimeSeriesRequest request = - CreateTimeSeriesRequest.newBuilder().setName(name).addAllTimeSeries(timeSeries).build(); + CreateTimeSeriesRequest.newBuilder() + .setNameWithProjectName(name) + .addAllTimeSeries(timeSeries) + .build(); createTimeSeries(request); } @@ -1011,10 +936,10 @@ public final void createTimeSeries(String name, List timeSeries) { * *

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   List<TimeSeries> timeSeries = new ArrayList<>();
    *   CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .addAllTimeSeries(timeSeries)
    *     .build();
    *   metricServiceClient.createTimeSeries(request);
@@ -1038,10 +963,10 @@ public final void createTimeSeries(CreateTimeSeriesRequest request) {
    *
    * 

    * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
-   *   String formattedName = MetricServiceClient.formatProjectName("[PROJECT]");
+   *   ProjectName name = ProjectName.create("[PROJECT]");
    *   List<TimeSeries> timeSeries = new ArrayList<>();
    *   CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder()
-   *     .setName(formattedName)
+   *     .setNameWithProjectName(name)
    *     .addAllTimeSeries(timeSeries)
    *     .build();
    *   ListenableFuture<Void> future = metricServiceClient.createTimeSeriesCallable().futureCall(request);
diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java
index ee65c23d2533..95db6ed368b8 100644
--- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java
+++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java
@@ -36,8 +36,8 @@
  * 
  * 
  * try (GroupServiceClient groupServiceClient = GroupServiceClient.create()) {
- *   String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]");
- *   Group response = groupServiceClient.getGroup(formattedName);
+ *   GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
+ *   Group response = groupServiceClient.getGroup(name);
  * }
  * 
  * 
@@ -52,8 +52,8 @@ *
  * 
  * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
- *   String formattedName = MetricServiceClient.formatMonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
- *   MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(formattedName);
+ *   MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
+ *   MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(name);
  * }
  * 
  * 
diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java index 638dce922115..b4194bfa0fb1 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java @@ -26,8 +26,10 @@ import com.google.monitoring.v3.DeleteGroupRequest; import com.google.monitoring.v3.GetGroupRequest; import com.google.monitoring.v3.Group; +import com.google.monitoring.v3.GroupName; import com.google.monitoring.v3.ListGroupMembersRequest; import com.google.monitoring.v3.ListGroupMembersResponse; +import com.google.monitoring.v3.ProjectName; import com.google.monitoring.v3.UpdateGroupRequest; import com.google.protobuf.Empty; import com.google.protobuf.GeneratedMessageV3; @@ -83,31 +85,31 @@ public void tearDown() throws Exception { @Test @SuppressWarnings("all") public void getGroupTest() { - String formattedName2 = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName name2 = GroupName.create("[PROJECT]", "[GROUP]"); String displayName = "displayName1615086568"; - String parentName = "parentName1015022848"; + GroupName parentName = GroupName.create("[PROJECT]", "[GROUP]"); String filter = "filter-1274492040"; boolean isCluster = false; Group expectedResponse = Group.newBuilder() - .setName(formattedName2) + .setNameWithGroupName(name2) .setDisplayName(displayName) - .setParentName(parentName) + .setParentNameWithGroupName(parentName) .setFilter(filter) .setIsCluster(isCluster) .build(); mockGroupService.addResponse(expectedResponse); - String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); - Group actualResponse = client.getGroup(formattedName); + Group actualResponse = client.getGroup(name); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetGroupRequest actualRequest = (GetGroupRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsGroupName()); } @Test @@ -117,9 +119,9 @@ public void getGroupExceptionTest() throws Exception { mockGroupService.addException(exception); try { - String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); - client.getGroup(formattedName); + client.getGroup(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -129,32 +131,32 @@ public void getGroupExceptionTest() throws Exception { @Test @SuppressWarnings("all") public void createGroupTest() { - String formattedName2 = GroupServiceClient.formatProjectName("[PROJECT]"); + GroupName name2 = GroupName.create("[PROJECT]", "[GROUP]"); String displayName = "displayName1615086568"; - String parentName = "parentName1015022848"; + GroupName parentName = GroupName.create("[PROJECT]", "[GROUP]"); String filter = "filter-1274492040"; boolean isCluster = false; Group expectedResponse = Group.newBuilder() - .setName(formattedName2) + .setNameWithGroupName(name2) .setDisplayName(displayName) - .setParentName(parentName) + .setParentNameWithGroupName(parentName) .setFilter(filter) .setIsCluster(isCluster) .build(); mockGroupService.addResponse(expectedResponse); - String formattedName = GroupServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); Group group = Group.newBuilder().build(); - Group actualResponse = client.createGroup(formattedName, group); + Group actualResponse = client.createGroup(name, group); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateGroupRequest actualRequest = (CreateGroupRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsProjectName()); Assert.assertEquals(group, actualRequest.getGroup()); } @@ -165,10 +167,10 @@ public void createGroupExceptionTest() throws Exception { mockGroupService.addException(exception); try { - String formattedName = GroupServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); Group group = Group.newBuilder().build(); - client.createGroup(formattedName, group); + client.createGroup(name, group); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -178,16 +180,16 @@ public void createGroupExceptionTest() throws Exception { @Test @SuppressWarnings("all") public void updateGroupTest() { - String name = "name3373707"; + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); String displayName = "displayName1615086568"; - String parentName = "parentName1015022848"; + GroupName parentName = GroupName.create("[PROJECT]", "[GROUP]"); String filter = "filter-1274492040"; boolean isCluster = false; Group expectedResponse = Group.newBuilder() - .setName(name) + .setNameWithGroupName(name) .setDisplayName(displayName) - .setParentName(parentName) + .setParentNameWithGroupName(parentName) .setFilter(filter) .setIsCluster(isCluster) .build(); @@ -227,15 +229,15 @@ public void deleteGroupTest() { Empty expectedResponse = Empty.newBuilder().build(); mockGroupService.addResponse(expectedResponse); - String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); - client.deleteGroup(formattedName); + client.deleteGroup(name); List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteGroupRequest actualRequest = (DeleteGroupRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsGroupName()); } @Test @@ -245,9 +247,9 @@ public void deleteGroupExceptionTest() throws Exception { mockGroupService.addException(exception); try { - String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); - client.deleteGroup(formattedName); + client.deleteGroup(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -269,9 +271,9 @@ public void listGroupMembersTest() { .build(); mockGroupService.addResponse(expectedResponse); - String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); - ListGroupMembersPagedResponse pagedListResponse = client.listGroupMembers(formattedName); + ListGroupMembersPagedResponse pagedListResponse = client.listGroupMembers(name); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -281,7 +283,7 @@ public void listGroupMembersTest() { Assert.assertEquals(1, actualRequests.size()); ListGroupMembersRequest actualRequest = (ListGroupMembersRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsGroupName()); } @Test @@ -291,9 +293,9 @@ public void listGroupMembersExceptionTest() throws Exception { mockGroupService.addException(exception); try { - String formattedName = GroupServiceClient.formatGroupName("[PROJECT]", "[GROUP]"); + GroupName name = GroupName.create("[PROJECT]", "[GROUP]"); - client.listGroupMembers(formattedName); + client.listGroupMembers(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java index 49a93045749b..ec9fcee28fff 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java @@ -37,6 +37,9 @@ import com.google.monitoring.v3.ListTimeSeriesRequest; import com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView; import com.google.monitoring.v3.ListTimeSeriesResponse; +import com.google.monitoring.v3.MetricDescriptorName; +import com.google.monitoring.v3.MonitoredResourceDescriptorName; +import com.google.monitoring.v3.ProjectName; import com.google.monitoring.v3.TimeInterval; import com.google.monitoring.v3.TimeSeries; import com.google.protobuf.Empty; @@ -106,10 +109,10 @@ public void listMonitoredResourceDescriptorsTest() { .build(); mockMetricService.addResponse(expectedResponse); - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); ListMonitoredResourceDescriptorsPagedResponse pagedListResponse = - client.listMonitoredResourceDescriptors(formattedName); + client.listMonitoredResourceDescriptors(name); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); @@ -121,7 +124,7 @@ public void listMonitoredResourceDescriptorsTest() { ListMonitoredResourceDescriptorsRequest actualRequest = (ListMonitoredResourceDescriptorsRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsProjectName()); } @Test @@ -131,9 +134,9 @@ public void listMonitoredResourceDescriptorsExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); - client.listMonitoredResourceDescriptors(formattedName); + client.listMonitoredResourceDescriptors(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -143,27 +146,23 @@ public void listMonitoredResourceDescriptorsExceptionTest() throws Exception { @Test @SuppressWarnings("all") public void getMonitoredResourceDescriptorTest() { - String formattedName2 = - MetricServiceClient.formatMonitoredResourceDescriptorName( - "[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); + String name2 = "name2-1052831874"; String type = "type3575610"; String displayName = "displayName1615086568"; String description = "description-1724546052"; MonitoredResourceDescriptor expectedResponse = MonitoredResourceDescriptor.newBuilder() - .setName(formattedName2) + .setName(name2) .setType(type) .setDisplayName(displayName) .setDescription(description) .build(); mockMetricService.addResponse(expectedResponse); - String formattedName = - MetricServiceClient.formatMonitoredResourceDescriptorName( - "[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); + MonitoredResourceDescriptorName name = + MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); - MonitoredResourceDescriptor actualResponse = - client.getMonitoredResourceDescriptor(formattedName); + MonitoredResourceDescriptor actualResponse = client.getMonitoredResourceDescriptor(name); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockMetricService.getRequests(); @@ -171,7 +170,7 @@ public void getMonitoredResourceDescriptorTest() { GetMonitoredResourceDescriptorRequest actualRequest = (GetMonitoredResourceDescriptorRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsMonitoredResourceDescriptorName()); } @Test @@ -181,11 +180,10 @@ public void getMonitoredResourceDescriptorExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = - MetricServiceClient.formatMonitoredResourceDescriptorName( - "[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); + MonitoredResourceDescriptorName name = + MonitoredResourceDescriptorName.create("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"); - client.getMonitoredResourceDescriptor(formattedName); + client.getMonitoredResourceDescriptor(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -205,10 +203,9 @@ public void listMetricDescriptorsTest() { .build(); mockMetricService.addResponse(expectedResponse); - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); - ListMetricDescriptorsPagedResponse pagedListResponse = - client.listMetricDescriptors(formattedName); + ListMetricDescriptorsPagedResponse pagedListResponse = client.listMetricDescriptors(name); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -219,7 +216,7 @@ public void listMetricDescriptorsTest() { ListMetricDescriptorsRequest actualRequest = (ListMetricDescriptorsRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsProjectName()); } @Test @@ -229,9 +226,9 @@ public void listMetricDescriptorsExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); - client.listMetricDescriptors(formattedName); + client.listMetricDescriptors(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -241,15 +238,14 @@ public void listMetricDescriptorsExceptionTest() throws Exception { @Test @SuppressWarnings("all") public void getMetricDescriptorTest() { - String formattedName2 = - MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); + String name2 = "name2-1052831874"; String type = "type3575610"; String unit = "unit3594628"; String description = "description-1724546052"; String displayName = "displayName1615086568"; MetricDescriptor expectedResponse = MetricDescriptor.newBuilder() - .setName(formattedName2) + .setName(name2) .setType(type) .setUnit(unit) .setDescription(description) @@ -257,17 +253,16 @@ public void getMetricDescriptorTest() { .build(); mockMetricService.addResponse(expectedResponse); - String formattedName = - MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); + MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]"); - MetricDescriptor actualResponse = client.getMetricDescriptor(formattedName); + MetricDescriptor actualResponse = client.getMetricDescriptor(name); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetMetricDescriptorRequest actualRequest = (GetMetricDescriptorRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsMetricDescriptorName()); } @Test @@ -277,10 +272,9 @@ public void getMetricDescriptorExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = - MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); + MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]"); - client.getMetricDescriptor(formattedName); + client.getMetricDescriptor(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -290,14 +284,14 @@ public void getMetricDescriptorExceptionTest() throws Exception { @Test @SuppressWarnings("all") public void createMetricDescriptorTest() { - String formattedName2 = MetricServiceClient.formatProjectName("[PROJECT]"); + String name2 = "name2-1052831874"; String type = "type3575610"; String unit = "unit3594628"; String description = "description-1724546052"; String displayName = "displayName1615086568"; MetricDescriptor expectedResponse = MetricDescriptor.newBuilder() - .setName(formattedName2) + .setName(name2) .setType(type) .setUnit(unit) .setDescription(description) @@ -305,11 +299,10 @@ public void createMetricDescriptorTest() { .build(); mockMetricService.addResponse(expectedResponse); - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build(); - MetricDescriptor actualResponse = - client.createMetricDescriptor(formattedName, metricDescriptor); + MetricDescriptor actualResponse = client.createMetricDescriptor(name, metricDescriptor); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockMetricService.getRequests(); @@ -317,7 +310,7 @@ public void createMetricDescriptorTest() { CreateMetricDescriptorRequest actualRequest = (CreateMetricDescriptorRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsProjectName()); Assert.assertEquals(metricDescriptor, actualRequest.getMetricDescriptor()); } @@ -328,10 +321,10 @@ public void createMetricDescriptorExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build(); - client.createMetricDescriptor(formattedName, metricDescriptor); + client.createMetricDescriptor(name, metricDescriptor); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -344,17 +337,16 @@ public void deleteMetricDescriptorTest() { Empty expectedResponse = Empty.newBuilder().build(); mockMetricService.addResponse(expectedResponse); - String formattedName = - MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); + MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]"); - client.deleteMetricDescriptor(formattedName); + client.deleteMetricDescriptor(name); List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteMetricDescriptorRequest actualRequest = (DeleteMetricDescriptorRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsMetricDescriptorName()); } @Test @@ -364,10 +356,9 @@ public void deleteMetricDescriptorExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = - MetricServiceClient.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); + MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]"); - client.deleteMetricDescriptor(formattedName); + client.deleteMetricDescriptor(name); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -387,13 +378,13 @@ public void listTimeSeriesTest() { .build(); mockMetricService.addResponse(expectedResponse); - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); String filter = "filter-1274492040"; TimeInterval interval = TimeInterval.newBuilder().build(); ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL; ListTimeSeriesPagedResponse pagedListResponse = - client.listTimeSeries(formattedName, filter, interval, view); + client.listTimeSeries(name, filter, interval, view); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -403,7 +394,7 @@ public void listTimeSeriesTest() { Assert.assertEquals(1, actualRequests.size()); ListTimeSeriesRequest actualRequest = (ListTimeSeriesRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsProjectName()); Assert.assertEquals(filter, actualRequest.getFilter()); Assert.assertEquals(interval, actualRequest.getInterval()); Assert.assertEquals(view, actualRequest.getView()); @@ -416,12 +407,12 @@ public void listTimeSeriesExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); String filter = "filter-1274492040"; TimeInterval interval = TimeInterval.newBuilder().build(); ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL; - client.listTimeSeries(formattedName, filter, interval, view); + client.listTimeSeries(name, filter, interval, view); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); @@ -434,16 +425,16 @@ public void createTimeSeriesTest() { Empty expectedResponse = Empty.newBuilder().build(); mockMetricService.addResponse(expectedResponse); - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); List timeSeries = new ArrayList<>(); - client.createTimeSeries(formattedName, timeSeries); + client.createTimeSeries(name, timeSeries); List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateTimeSeriesRequest actualRequest = (CreateTimeSeriesRequest) actualRequests.get(0); - Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(name, actualRequest.getNameAsProjectName()); Assert.assertEquals(timeSeries, actualRequest.getTimeSeriesList()); } @@ -454,10 +445,10 @@ public void createTimeSeriesExceptionTest() throws Exception { mockMetricService.addException(exception); try { - String formattedName = MetricServiceClient.formatProjectName("[PROJECT]"); + ProjectName name = ProjectName.create("[PROJECT]"); List timeSeries = new ArrayList<>(); - client.createTimeSeries(formattedName, timeSeries); + client.createTimeSeries(name, timeSeries); Assert.fail("No exception raised"); } catch (ApiException e) { Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml index 3d268c6771da..e780732e4b2c 100644 --- a/google-cloud-pubsub/pom.xml +++ b/google-cloud-pubsub/pom.xml @@ -30,7 +30,7 @@ com.google.api.grpc grpc-google-cloud-pubsub-v1 - 0.1.3 + 0.1.5 io.grpc diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/MessageConsumerImpl.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/MessageConsumerImpl.java index 889b415bd685..7d8f22ad2acc 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/MessageConsumerImpl.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/MessageConsumerImpl.java @@ -16,7 +16,6 @@ package com.google.cloud.pubsub; -import static com.google.cloud.pubsub.spi.v1.SubscriberClient.formatSubscriptionName; import static com.google.common.base.MoreObjects.firstNonNull; import com.google.cloud.GrpcServiceOptions.ExecutorFactory; @@ -28,6 +27,7 @@ import com.google.pubsub.v1.PullRequest; import com.google.pubsub.v1.PullResponse; +import com.google.pubsub.v1.SubscriptionName; import io.grpc.internal.SharedResourceHolder; import java.util.List; @@ -154,7 +154,8 @@ public void failure(Throwable error) { private PullRequest createPullRequest() { return PullRequest.newBuilder() - .setSubscription(formatSubscriptionName(pubsubOptions.getProjectId(), subscription)) + .setSubscriptionWithSubscriptionName( + SubscriptionName.create(pubsubOptions.getProjectId(), subscription)) .setMaxMessages(maxQueuedCallbacks - queuedCallbacks.get()) .setReturnImmediately(false) .build(); diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSubImpl.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSubImpl.java index 4e4307b6108d..35dff5ab2524 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSubImpl.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSubImpl.java @@ -31,8 +31,6 @@ import com.google.cloud.Policy; import com.google.cloud.pubsub.spi.PubSubRpc; import com.google.cloud.pubsub.spi.PubSubRpc.PullFuture; -import com.google.cloud.pubsub.spi.v1.PublisherClient; -import com.google.cloud.pubsub.spi.v1.SubscriberClient; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Throwables; @@ -62,11 +60,13 @@ import com.google.pubsub.v1.ListTopicsResponse; import com.google.pubsub.v1.ModifyAckDeadlineRequest; import com.google.pubsub.v1.ModifyPushConfigRequest; +import com.google.pubsub.v1.ProjectName; import com.google.pubsub.v1.PublishRequest; import com.google.pubsub.v1.PublishResponse; import com.google.pubsub.v1.PullRequest; import com.google.pubsub.v1.PullResponse; - +import com.google.pubsub.v1.SubscriptionName; +import com.google.pubsub.v1.TopicName; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -247,7 +247,7 @@ public Topic getTopic(String topic) { @Override public Future getTopicAsync(String topic) { GetTopicRequest request = GetTopicRequest.newBuilder() - .setTopic(PublisherClient.formatTopicName(getOptions().getProjectId(), topic)) + .setTopicWithTopicName(TopicName.create(getOptions().getProjectId(), topic)) .build(); return transform(rpc.get(request), Topic.fromPbFunction(this)); } @@ -260,7 +260,7 @@ public boolean deleteTopic(String topic) { @Override public Future deleteTopicAsync(String topic) { DeleteTopicRequest request = DeleteTopicRequest.newBuilder() - .setTopic(PublisherClient.formatTopicName(getOptions().getProjectId(), topic)) + .setTopicWithTopicName(TopicName.create(getOptions().getProjectId(), topic)) .build(); return transform(rpc.delete(request), EMPTY_TO_BOOLEAN_FUNCTION); } @@ -268,7 +268,7 @@ public Future deleteTopicAsync(String topic) { private static ListTopicsRequest listTopicsRequest(PubSubOptions serviceOptions, Map options) { ListTopicsRequest.Builder builder = ListTopicsRequest.newBuilder(); - builder.setProject(SubscriberClient.formatProjectName(serviceOptions.getProjectId())); + builder.setProjectWithProjectName(ProjectName.create(serviceOptions.getProjectId())); Integer pageSize = PAGE_SIZE.get(options); String pageToken = PAGE_TOKEN.get(options); if (pageSize != null) { @@ -316,7 +316,7 @@ public String publish(String topic, Message message) { private static PublishRequest publishRequest(PubSubOptions serviceOptions, String topic, Iterable messages) { PublishRequest.Builder builder = PublishRequest.newBuilder(); - builder.setTopic(PublisherClient.formatTopicName(serviceOptions.getProjectId(), topic)); + builder.setTopicWithTopicName(TopicName.create(serviceOptions.getProjectId(), topic)); builder.addAllMessages(Iterables.transform(messages, Message.TO_PB_FUNCTION)); return builder.build(); } @@ -378,8 +378,8 @@ public Subscription getSubscription(String subscription) { @Override public Future getSubscriptionAsync(String subscription) { GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder() - .setSubscription( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + .setSubscriptionWithSubscriptionName( + SubscriptionName.create(getOptions().getProjectId(), subscription)) .build(); return transform(rpc.get(request), Subscription.fromPbFunction(this)); } @@ -392,8 +392,8 @@ public void replacePushConfig(String subscription, PushConfig pushConfig) { @Override public Future replacePushConfigAsync(String subscription, PushConfig pushConfig) { ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder() - .setSubscription( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + .setSubscriptionWithSubscriptionName( + SubscriptionName.create(getOptions().getProjectId(), subscription)) .setPushConfig(pushConfig != null ? pushConfig.toPb() : com.google.pubsub.v1.PushConfig.getDefaultInstance()) .build(); @@ -408,8 +408,8 @@ public boolean deleteSubscription(String subscription) { @Override public Future deleteSubscriptionAsync(String subscription) { DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder() - .setSubscription( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + .setSubscriptionWithSubscriptionName( + SubscriptionName.create(getOptions().getProjectId(), subscription)) .build(); return transform(rpc.delete(request), EMPTY_TO_BOOLEAN_FUNCTION); } @@ -417,7 +417,7 @@ public Future deleteSubscriptionAsync(String subscription) { private static ListSubscriptionsRequest listSubscriptionsRequest(PubSubOptions serviceOptions, Map options) { ListSubscriptionsRequest.Builder builder = ListSubscriptionsRequest.newBuilder(); - builder.setProject(SubscriberClient.formatProjectName(serviceOptions.getProjectId())); + builder.setProjectWithProjectName(ProjectName.create(serviceOptions.getProjectId())); Integer pageSize = PAGE_SIZE.getInteger(options); String pageToken = PAGE_TOKEN.getString(options); if (pageSize != null) { @@ -460,7 +460,7 @@ public Future> listSubscriptionsAsync(ListOption... opti private static ListTopicSubscriptionsRequest listSubscriptionsRequest(String topic, PubSubOptions serviceOptions, Map options) { ListTopicSubscriptionsRequest.Builder builder = ListTopicSubscriptionsRequest.newBuilder(); - builder.setTopic(PublisherClient.formatTopicName(serviceOptions.getProjectId(), topic)); + builder.setTopicWithTopicName(TopicName.create(serviceOptions.getProjectId(), topic)); Integer pageSize = PAGE_SIZE.getInteger(options); String pageToken = PAGE_TOKEN.getString(options); if (pageSize != null) { @@ -515,8 +515,8 @@ public Future> listSubscriptionsAsync(String topic, private Future> pullAsync(final String subscription, int maxMessages, boolean returnImmediately) { PullRequest request = PullRequest.newBuilder() - .setSubscription( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + .setSubscriptionWithSubscriptionName( + SubscriptionName.create(getOptions().getProjectId(), subscription)) .setMaxMessages(maxMessages) .setReturnImmediately(returnImmediately) .build(); @@ -588,8 +588,8 @@ public void ack(String subscription, Iterable ackIds) { @Override public Future ackAsync(String subscription, Iterable ackIds) { AcknowledgeRequest request = AcknowledgeRequest.newBuilder() - .setSubscription( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + .setSubscriptionWithSubscriptionName( + SubscriptionName.create(getOptions().getProjectId(), subscription)) .addAllAckIds(ackIds) .build(); return transform(rpc.acknowledge(request), EMPTY_TO_VOID_FUNCTION); @@ -637,8 +637,8 @@ public void modifyAckDeadline(String subscription, int deadline, TimeUnit unit, public Future modifyAckDeadlineAsync(String subscription, int deadline, TimeUnit unit, Iterable ackIds) { ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder() - .setSubscription( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + .setSubscriptionWithSubscriptionName( + SubscriptionName.create(getOptions().getProjectId(), subscription)) .setAckDeadlineSeconds((int) TimeUnit.SECONDS.convert(deadline, unit)) .addAllAckIds(ackIds) .build(); @@ -653,7 +653,7 @@ public Policy getTopicPolicy(String topic) { @Override public Future getTopicPolicyAsync(String topic) { return transform( - rpc.getIamPolicy(PublisherClient.formatTopicName(getOptions().getProjectId(), topic)), + rpc.getIamPolicy(TopicName.create(getOptions().getProjectId(), topic).toString()), POLICY_TO_PB_FUNCTION); } @@ -666,7 +666,7 @@ public Policy replaceTopicPolicy(String topic, Policy newPolicy) { public Future replaceTopicPolicyAsync(String topic, Policy newPolicy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() .setPolicy(PolicyMarshaller.INSTANCE.toPb(newPolicy)) - .setResource(PublisherClient.formatTopicName(getOptions().getProjectId(), topic)) + .setResource(TopicName.create(getOptions().getProjectId(), topic).toString()) .build(); return transform(rpc.setIamPolicy(request), POLICY_TO_PB_FUNCTION); } @@ -679,7 +679,7 @@ public List testTopicPermissions(String topic, final List permi @Override public Future> testTopicPermissionsAsync(String topic, List permissions) { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() - .setResource(PublisherClient.formatTopicName(getOptions().getProjectId(), topic)) + .setResource(TopicName.create(getOptions().getProjectId(), topic).toString()) .addAllPermissions(permissions) .build(); return transform(rpc.testIamPermissions(request), permissionsFromPbFunction(permissions)); @@ -694,7 +694,7 @@ public Policy getSubscriptionPolicy(String subscription) { public Future getSubscriptionPolicyAsync(String subscription) { return transform( rpc.getIamPolicy( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)), + SubscriptionName.create(getOptions().getProjectId(), subscription).toString()), POLICY_TO_PB_FUNCTION); } @@ -708,7 +708,7 @@ public Future replaceSubscriptionPolicyAsync(String subscription, Policy SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() .setPolicy(PolicyMarshaller.INSTANCE.toPb(newPolicy)) .setResource( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + SubscriptionName.create(getOptions().getProjectId(), subscription).toString()) .build(); return transform(rpc.setIamPolicy(request), POLICY_TO_PB_FUNCTION); } @@ -723,7 +723,7 @@ public Future> testSubscriptionPermissionsAsync(String subscriptio List permissions) { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() .setResource( - SubscriberClient.formatSubscriptionName(getOptions().getProjectId(), subscription)) + SubscriptionName.create(getOptions().getProjectId(), subscription).toString()) .addAllPermissions(permissions) .build(); return transform(rpc.testIamPermissions(request), permissionsFromPbFunction(permissions)); diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionId.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionId.java index 8a3cc166efb6..a01fc9dfc79e 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionId.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionId.java @@ -16,12 +16,10 @@ package com.google.cloud.pubsub; -import static com.google.cloud.pubsub.spi.v1.SubscriberClient.parseProjectFromSubscriptionName; -import static com.google.cloud.pubsub.spi.v1.SubscriberClient.parseSubscriptionFromSubscriptionName; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.MoreObjects; - +import com.google.pubsub.v1.SubscriptionName; import java.io.Serializable; import java.util.Objects; @@ -99,7 +97,8 @@ public final boolean equals(Object obj) { } static SubscriptionId fromPb(String pb) { - return new SubscriptionId(parseProjectFromSubscriptionName(pb), - parseSubscriptionFromSubscriptionName(pb)); + SubscriptionName subscriptionName = SubscriptionName.parse(pb); + return new SubscriptionId(subscriptionName.getProject(), + subscriptionName.getSubscription()); } } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionInfo.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionInfo.java index 5bbc4cd161bc..b5ff3106dbd0 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionInfo.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriptionInfo.java @@ -18,9 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.cloud.pubsub.spi.v1.SubscriberClient; import com.google.common.base.MoreObjects; - +import com.google.pubsub.v1.SubscriptionName; import java.io.Serializable; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -394,7 +393,7 @@ com.google.pubsub.v1.Subscription toPb(String projectId) { com.google.pubsub.v1.Subscription.Builder builder = com.google.pubsub.v1.Subscription.newBuilder(); builder.setTopic(topic.toPb(projectId)); - builder.setName(SubscriberClient.formatSubscriptionName(projectId, name)); + builder.setNameWithSubscriptionName(SubscriptionName.create(projectId, name)); builder.setAckDeadlineSeconds(ackDeadlineSeconds); if (pushConfig != null) { builder.setPushConfig(pushConfig.toPb()); @@ -404,7 +403,7 @@ com.google.pubsub.v1.Subscription toPb(String projectId) { static SubscriptionInfo fromPb(com.google.pubsub.v1.Subscription subscription) { Builder builder = newBuilder(TopicId.fromPb(subscription.getTopic()), - SubscriberClient.parseSubscriptionFromSubscriptionName(subscription.getName())); + subscription.getNameAsSubscriptionName().getSubscription()); builder.setAckDeadLineSeconds(subscription.getAckDeadlineSeconds()); // A subscription with an "empty" push config is a pull subscription if (subscription.hasPushConfig() diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicId.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicId.java index b481c4572000..a121ca11c4e1 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicId.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicId.java @@ -16,13 +16,11 @@ package com.google.cloud.pubsub; -import static com.google.cloud.pubsub.spi.v1.PublisherClient.formatTopicName; -import static com.google.cloud.pubsub.spi.v1.PublisherClient.parseProjectFromTopicName; -import static com.google.cloud.pubsub.spi.v1.PublisherClient.parseTopicFromTopicName; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.MoreObjects; +import com.google.pubsub.v1.TopicName; import java.io.Serializable; import java.util.Objects; @@ -120,7 +118,7 @@ public boolean equals(Object obj) { } String toPb(String projectId) { - return formatTopicName(project != null ? project : projectId, topic); + return TopicName.create(project != null ? project : projectId, topic).toString(); } /** @@ -150,6 +148,7 @@ static TopicId fromPb(String pb) { if (Objects.equals(pb, DELETED_TOPIC_NAME)) { return DELETED_TOPIC; } - return TopicId.of(parseProjectFromTopicName(pb), parseTopicFromTopicName(pb)); + TopicName topicName = TopicName.parse(pb); + return TopicId.of(topicName.getProject(), topicName.getTopic()); } } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicInfo.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicInfo.java index 75771d5ebb35..d669e1b94846 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicInfo.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/TopicInfo.java @@ -18,9 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.cloud.pubsub.spi.v1.PublisherClient; import com.google.common.base.MoreObjects; - +import com.google.pubsub.v1.TopicName; import java.io.Serializable; import java.util.Objects; @@ -145,12 +144,12 @@ public String toString() { com.google.pubsub.v1.Topic toPb(String projectId) { return com.google.pubsub.v1.Topic.newBuilder() - .setName(PublisherClient.formatTopicName(projectId, name)) + .setNameWithTopicName(TopicName.create(projectId, name)) .build(); } static TopicInfo fromPb(com.google.pubsub.v1.Topic topicPb) { - return newBuilder(PublisherClient.parseTopicFromTopicName(topicPb.getName())).build(); + return newBuilder(topicPb.getNameAsTopicName().getTopic()).build(); } /** diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherClient.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherClient.java index e1cd043a439f..059b93be6a73 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherClient.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherClient.java @@ -20,7 +20,6 @@ import com.google.api.gax.grpc.ChannelAndExecutor; import com.google.api.gax.grpc.UnaryCallable; -import com.google.api.gax.protobuf.PathTemplate; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; @@ -127,39 +126,6 @@ public class PublisherClient implements AutoCloseable { private final UnaryCallable testIamPermissionsCallable; - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}"); - - private static final PathTemplate TOPIC_PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}"); - - /** Formats a string containing the fully-qualified path to represent a project resource. */ - public static final String formatProjectName(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** Formats a string containing the fully-qualified path to represent a topic resource. */ - public static final String formatTopicName(String project, String topic) { - return TOPIC_PATH_TEMPLATE.instantiate( - "project", project, - "topic", topic); - } - - /** Parses the project from the given fully-qualified path which represents a project resource. */ - public static final String parseProjectFromProjectName(String projectName) { - return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); - } - - /** Parses the project from the given fully-qualified path which represents a topic resource. */ - public static final String parseProjectFromTopicName(String topicName) { - return TOPIC_PATH_TEMPLATE.parse(topicName).get("project"); - } - - /** Parses the topic from the given fully-qualified path which represents a topic resource. */ - public static final String parseTopicFromTopicName(String topicName) { - return TOPIC_PATH_TEMPLATE.parse(topicName).get("topic"); - } - /** Constructs an instance of PublisherClient with default settings. */ public static final PublisherClient create() throws IOException { return create(PublisherSettings.defaultBuilder().build()); @@ -327,7 +293,8 @@ public final UnaryCallable createTopicCallable() { * } *
* - * @param topic The messages in the request will be published on this topic. + * @param topic The messages in the request will be published on this topic. Format is + * `projects/{project}/topics/{topic}`. * @param messages The messages to publish. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ @@ -412,7 +379,7 @@ public final UnaryCallable publishCallable() { * } *
* - * @param topic The name of the topic to get. + * @param topic The name of the topic to get. Format is `projects/{project}/topics/{topic}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Topic getTopic(TopicName topic) { @@ -481,7 +448,8 @@ public final UnaryCallable getTopicCallable() { * } *
* - * @param project The name of the cloud project that topics belong to. + * @param project The name of the cloud project that topics belong to. Format is + * `projects/{project}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ListTopicsPagedResponse listTopics(ProjectName project) { @@ -585,7 +553,8 @@ public final UnaryCallable listTopicsCall * } *
* - * @param topic The name of the topic that subscriptions are attached to. + * @param topic The name of the topic that subscriptions are attached to. Format is + * `projects/{project}/topics/{topic}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(TopicName topic) { @@ -693,7 +662,7 @@ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions( * } *
* - * @param topic Name of the topic to delete. + * @param topic Name of the topic to delete. Format is `projects/{project}/topics/{topic}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteTopic(TopicName topic) { @@ -762,7 +731,7 @@ public final UnaryCallable deleteTopicCallable() { * *

    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   Policy policy = Policy.newBuilder().build();
    *   Policy response = publisherClient.setIamPolicy(formattedResource, policy);
    * }
@@ -777,7 +746,7 @@ public final UnaryCallable deleteTopicCallable() {
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
   public final Policy setIamPolicy(String resource, Policy policy) {
-    TOPIC_PATH_TEMPLATE.validate(resource, "setIamPolicy");
+
     SetIamPolicyRequest request =
         SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build();
     return setIamPolicy(request);
@@ -791,7 +760,7 @@ public final Policy setIamPolicy(String resource, Policy policy) {
    *
    * 

    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   Policy policy = Policy.newBuilder().build();
    *   SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
@@ -816,7 +785,7 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) {
    *
    * 

    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   Policy policy = Policy.newBuilder().build();
    *   SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
@@ -841,7 +810,7 @@ public final UnaryCallable setIamPolicyCallable() {
    *
    * 

    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   Policy response = publisherClient.getIamPolicy(formattedResource);
    * }
    * 
@@ -852,7 +821,7 @@ public final UnaryCallable setIamPolicyCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { - TOPIC_PATH_TEMPLATE.validate(resource, "getIamPolicy"); + GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); } @@ -866,7 +835,7 @@ public final Policy getIamPolicy(String resource) { * *

    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
    *     .build();
@@ -890,7 +859,7 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) {
    *
    * 

    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
    *     .build();
@@ -906,13 +875,14 @@ public final UnaryCallable getIamPolicyCallable() {
 
   // AUTO-GENERATED DOCUMENTATION AND METHOD
   /**
-   * Returns permissions that a caller has on the specified resource.
+   * Returns permissions that a caller has on the specified resource. If the resource does not
+   * exist, this will return an empty set of permissions, not a NOT_FOUND error.
    *
    * 

Sample code: * *


    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   List<String> permissions = new ArrayList<>();
    *   TestIamPermissionsResponse response = publisherClient.testIamPermissions(formattedResource, permissions);
    * }
@@ -928,7 +898,7 @@ public final UnaryCallable getIamPolicyCallable() {
    */
   public final TestIamPermissionsResponse testIamPermissions(
       String resource, List permissions) {
-    TOPIC_PATH_TEMPLATE.validate(resource, "testIamPermissions");
+
     TestIamPermissionsRequest request =
         TestIamPermissionsRequest.newBuilder()
             .setResource(resource)
@@ -939,13 +909,14 @@ public final TestIamPermissionsResponse testIamPermissions(
 
   // AUTO-GENERATED DOCUMENTATION AND METHOD
   /**
-   * Returns permissions that a caller has on the specified resource.
+   * Returns permissions that a caller has on the specified resource. If the resource does not
+   * exist, this will return an empty set of permissions, not a NOT_FOUND error.
    *
    * 

Sample code: * *


    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   List<String> permissions = new ArrayList<>();
    *   TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
    *     .setResource(formattedResource)
@@ -964,13 +935,14 @@ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsReq
 
   // AUTO-GENERATED DOCUMENTATION AND METHOD
   /**
-   * Returns permissions that a caller has on the specified resource.
+   * Returns permissions that a caller has on the specified resource. If the resource does not
+   * exist, this will return an empty set of permissions, not a NOT_FOUND error.
    *
    * 

Sample code: * *


    * try (PublisherClient publisherClient = PublisherClient.create()) {
-   *   String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+   *   String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
    *   List<String> permissions = new ArrayList<>();
    *   TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
    *     .setResource(formattedResource)
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberClient.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberClient.java
index 8bbd1ff67167..7dce0f18408d 100644
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberClient.java
+++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberClient.java
@@ -18,8 +18,8 @@
 import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse;
 
 import com.google.api.gax.grpc.ChannelAndExecutor;
+import com.google.api.gax.grpc.StreamingCallable;
 import com.google.api.gax.grpc.UnaryCallable;
-import com.google.api.gax.protobuf.PathTemplate;
 import com.google.iam.v1.GetIamPolicyRequest;
 import com.google.iam.v1.Policy;
 import com.google.iam.v1.SetIamPolicyRequest;
@@ -38,6 +38,8 @@
 import com.google.pubsub.v1.PullRequest;
 import com.google.pubsub.v1.PullResponse;
 import com.google.pubsub.v1.PushConfig;
+import com.google.pubsub.v1.StreamingPullRequest;
+import com.google.pubsub.v1.StreamingPullResponse;
 import com.google.pubsub.v1.Subscription;
 import com.google.pubsub.v1.SubscriptionName;
 import com.google.pubsub.v1.TopicName;
@@ -127,71 +129,14 @@ public class SubscriberClient implements AutoCloseable {
   private final UnaryCallable modifyAckDeadlineCallable;
   private final UnaryCallable acknowledgeCallable;
   private final UnaryCallable pullCallable;
+  private final StreamingCallable
+      streamingPullCallable;
   private final UnaryCallable modifyPushConfigCallable;
   private final UnaryCallable setIamPolicyCallable;
   private final UnaryCallable getIamPolicyCallable;
   private final UnaryCallable
       testIamPermissionsCallable;
 
-  private static final PathTemplate PROJECT_PATH_TEMPLATE =
-      PathTemplate.createWithoutUrlEncoding("projects/{project}");
-
-  private static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE =
-      PathTemplate.createWithoutUrlEncoding("projects/{project}/subscriptions/{subscription}");
-
-  private static final PathTemplate TOPIC_PATH_TEMPLATE =
-      PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");
-
-  /** Formats a string containing the fully-qualified path to represent a project resource. */
-  public static final String formatProjectName(String project) {
-    return PROJECT_PATH_TEMPLATE.instantiate("project", project);
-  }
-
-  /** Formats a string containing the fully-qualified path to represent a subscription resource. */
-  public static final String formatSubscriptionName(String project, String subscription) {
-    return SUBSCRIPTION_PATH_TEMPLATE.instantiate(
-        "project", project,
-        "subscription", subscription);
-  }
-
-  /** Formats a string containing the fully-qualified path to represent a topic resource. */
-  public static final String formatTopicName(String project, String topic) {
-    return TOPIC_PATH_TEMPLATE.instantiate(
-        "project", project,
-        "topic", topic);
-  }
-
-  /** Parses the project from the given fully-qualified path which represents a project resource. */
-  public static final String parseProjectFromProjectName(String projectName) {
-    return PROJECT_PATH_TEMPLATE.parse(projectName).get("project");
-  }
-
-  /**
-   * Parses the project from the given fully-qualified path which represents a subscription
-   * resource.
-   */
-  public static final String parseProjectFromSubscriptionName(String subscriptionName) {
-    return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionName).get("project");
-  }
-
-  /**
-   * Parses the subscription from the given fully-qualified path which represents a subscription
-   * resource.
-   */
-  public static final String parseSubscriptionFromSubscriptionName(String subscriptionName) {
-    return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionName).get("subscription");
-  }
-
-  /** Parses the project from the given fully-qualified path which represents a topic resource. */
-  public static final String parseProjectFromTopicName(String topicName) {
-    return TOPIC_PATH_TEMPLATE.parse(topicName).get("project");
-  }
-
-  /** Parses the topic from the given fully-qualified path which represents a topic resource. */
-  public static final String parseTopicFromTopicName(String topicName) {
-    return TOPIC_PATH_TEMPLATE.parse(topicName).get("topic");
-  }
-
   /** Constructs an instance of SubscriberClient with default settings. */
   public static final SubscriberClient create() throws IOException {
     return create(SubscriberSettings.defaultBuilder().build());
@@ -231,6 +176,8 @@ protected SubscriberClient(SubscriberSettings settings) throws IOException {
     this.acknowledgeCallable =
         UnaryCallable.create(settings.acknowledgeSettings(), this.channel, this.executor);
     this.pullCallable = UnaryCallable.create(settings.pullSettings(), this.channel, this.executor);
+    this.streamingPullCallable =
+        StreamingCallable.create(settings.streamingPullSettings(), this.channel);
     this.modifyPushConfigCallable =
         UnaryCallable.create(settings.modifyPushConfigSettings(), this.channel, this.executor);
     this.setIamPolicyCallable =
@@ -270,8 +217,10 @@ public final SubscriberSettings getSettings() {
    * `ALREADY_EXISTS`. If the corresponding topic doesn't exist, returns `NOT_FOUND`.
    *
    * 

If the name is not provided in the request, the server will assign a random name for this - * subscription on the same project as the topic. Note that for REST API requests, you must - * specify a name. + * subscription on the same project as the topic, conforming to the [resource name + * format](https://cloud.google.com/pubsub/docs/overview#names). The generated name is populated + * in the returned Subscription object. Note that for REST API requests, you must specify a name + * in the request. * *

Sample code: * @@ -290,8 +239,9 @@ public final SubscriberSettings getSettings() { * letter, and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), underscores * (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent signs (`%`). It must be between 3 * and 255 characters in length, and it must not start with `"goog"`. - * @param topic The name of the topic from which this subscription is receiving messages. The - * value of this field will be `_deleted-topic_` if the topic has been deleted. + * @param topic The name of the topic from which this subscription is receiving messages. Format + * is `projects/{project}/topics/{topic}`. The value of this field will be `_deleted-topic_` + * if the topic has been deleted. * @param pushConfig If push delivery is used with this subscription, this field is used to * configure it. An empty `pushConfig` signifies that the subscriber will pull and ack * messages using API methods. @@ -301,13 +251,13 @@ public final SubscriberSettings getSettings() { * and will not be delivered again during that time (on a best-effort basis). *

For pull subscriptions, this value is used as the initial value for the ack deadline. To * override this value for a given message, call `ModifyAckDeadline` with the corresponding - * `ack_id` if using pull. The maximum custom deadline you can specify is 600 seconds (10 - * minutes). + * `ack_id` if using pull. The minimum custom deadline you can specify is 10 seconds. The + * maximum custom deadline you can specify is 600 seconds (10 minutes). If this parameter is + * 0, a default value of 10 seconds is used. *

For push delivery, this value is also used to set the request timeout for the call to * the push endpoint. *

If the subscriber never acknowledges the message, the Pub/Sub system will eventually * redeliver the message. - *

If this parameter is 0, a default value of 10 seconds is used. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Subscription createSubscription( @@ -316,7 +266,7 @@ public final Subscription createSubscription( Subscription request = Subscription.newBuilder() .setNameWithSubscriptionName(name) - .setTopicWithTopicNameOneof(TopicNameOneof.from(topic)) + .setTopicWithTopicNameOneof(topic == null ? null : TopicNameOneof.from(topic)) .setPushConfig(pushConfig) .setAckDeadlineSeconds(ackDeadlineSeconds) .build(); @@ -329,8 +279,10 @@ public final Subscription createSubscription( * `ALREADY_EXISTS`. If the corresponding topic doesn't exist, returns `NOT_FOUND`. * *

If the name is not provided in the request, the server will assign a random name for this - * subscription on the same project as the topic. Note that for REST API requests, you must - * specify a name. + * subscription on the same project as the topic, conforming to the [resource name + * format](https://cloud.google.com/pubsub/docs/overview#names). The generated name is populated + * in the returned Subscription object. Note that for REST API requests, you must specify a name + * in the request. * *

Sample code: * @@ -359,8 +311,10 @@ public final Subscription createSubscription(Subscription request) { * `ALREADY_EXISTS`. If the corresponding topic doesn't exist, returns `NOT_FOUND`. * *

If the name is not provided in the request, the server will assign a random name for this - * subscription on the same project as the topic. Note that for REST API requests, you must - * specify a name. + * subscription on the same project as the topic, conforming to the [resource name + * format](https://cloud.google.com/pubsub/docs/overview#names). The generated name is populated + * in the returned Subscription object. Note that for REST API requests, you must specify a name + * in the request. * *

Sample code: * @@ -395,7 +349,8 @@ public final UnaryCallable createSubscriptionCallabl * } *

* - * @param subscription The name of the subscription to get. + * @param subscription The name of the subscription to get. Format is + * `projects/{project}/subscriptions/{sub}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Subscription getSubscription(SubscriptionName subscription) { @@ -467,7 +422,8 @@ public final UnaryCallable getSubscription * } *
* - * @param project The name of the cloud project that subscriptions belong to. + * @param project The name of the cloud project that subscriptions belong to. Format is + * `projects/{project}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ListSubscriptionsPagedResponse listSubscriptions(ProjectName project) { @@ -560,10 +516,10 @@ public final ListSubscriptionsPagedResponse listSubscriptions(ListSubscriptionsR // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes an existing subscription. All pending messages in the subscription are immediately + * Deletes an existing subscription. All messages retained in the subscription are immediately * dropped. Calls to `Pull` after deletion will return `NOT_FOUND`. After a subscription is * deleted, a new one may be created with the same name, but the new one has no association with - * the old subscription, or its topic unless the same topic is specified. + * the old subscription or its topic unless the same topic is specified. * *

Sample code: * @@ -574,7 +530,8 @@ public final ListSubscriptionsPagedResponse listSubscriptions(ListSubscriptionsR * } *

* - * @param subscription The subscription to delete. + * @param subscription The subscription to delete. Format is + * `projects/{project}/subscriptions/{sub}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteSubscription(SubscriptionName subscription) { @@ -588,10 +545,10 @@ public final void deleteSubscription(SubscriptionName subscription) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes an existing subscription. All pending messages in the subscription are immediately + * Deletes an existing subscription. All messages retained in the subscription are immediately * dropped. Calls to `Pull` after deletion will return `NOT_FOUND`. After a subscription is * deleted, a new one may be created with the same name, but the new one has no association with - * the old subscription, or its topic unless the same topic is specified. + * the old subscription or its topic unless the same topic is specified. * *

Sample code: * @@ -614,10 +571,10 @@ private final void deleteSubscription(DeleteSubscriptionRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes an existing subscription. All pending messages in the subscription are immediately + * Deletes an existing subscription. All messages retained in the subscription are immediately * dropped. Calls to `Pull` after deletion will return `NOT_FOUND`. After a subscription is * deleted, a new one may be created with the same name, but the new one has no association with - * the old subscription, or its topic unless the same topic is specified. + * the old subscription or its topic unless the same topic is specified. * *

Sample code: * @@ -655,12 +612,14 @@ public final UnaryCallable deleteSubscriptionC * } *

* - * @param subscription The name of the subscription. + * @param subscription The name of the subscription. Format is + * `projects/{project}/subscriptions/{sub}`. * @param ackIds List of acknowledgment IDs. * @param ackDeadlineSeconds The new ack deadline with respect to the time this request was sent - * to the Pub/Sub system. Must be >= 0. For example, if the value is 10, the new ack - * deadline will expire 10 seconds after the `ModifyAckDeadline` call was made. Specifying - * zero may immediately make the message available for another pull request. + * to the Pub/Sub system. For example, if the value is 10, the new ack deadline will expire 10 + * seconds after the `ModifyAckDeadline` call was made. Specifying zero may immediately make + * the message available for another pull request. The minimum deadline you can specify is 0 + * seconds. The maximum deadline you can specify is 600 seconds (10 minutes). * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void modifyAckDeadline( @@ -752,7 +711,8 @@ public final UnaryCallable modifyAckDeadlineCal * } *
* - * @param subscription The subscription whose message is being acknowledged. + * @param subscription The subscription whose message is being acknowledged. Format is + * `projects/{project}/subscriptions/{sub}`. * @param ackIds The acknowledgment ID for the messages being acknowledged that was returned by * the Pub/Sub system in the `Pull` response. Must not be empty. * @throws com.google.api.gax.grpc.ApiException if the remote call fails @@ -841,11 +801,13 @@ public final UnaryCallable acknowledgeCallable() { * } *
* - * @param subscription The subscription from which messages should be pulled. - * @param returnImmediately If this is specified as true the system will respond immediately even - * if it is not able to return a message in the `Pull` response. Otherwise the system is - * allowed to wait until at least one message is available rather than returning no messages. - * The client may cancel the request if it does not wish to wait any longer for the response. + * @param subscription The subscription from which messages should be pulled. Format is + * `projects/{project}/subscriptions/{sub}`. + * @param returnImmediately If this field set to true, the system will respond immediately even if + * it there are no messages available to return in the `Pull` response. Otherwise, the system + * may wait (for a bounded amount of time) until at least one message is available, rather + * than returning no messages. The client may cancel the request if it does not wish to wait + * any longer for the response. * @param maxMessages The maximum number of messages returned for this request. The Pub/Sub system * may return fewer than the number specified. * @throws com.google.api.gax.grpc.ApiException if the remote call fails @@ -915,6 +877,59 @@ public final UnaryCallable pullCallable() { return pullCallable; } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * (EXPERIMENTAL) StreamingPull is an experimental feature. This RPC will respond with + * UNIMPLEMENTED errors unless you have been invited to test this feature. Contact + * cloud-pubsub{@literal @}google.com with any questions. + * + *

Establishes a stream with the server, which sends messages down to the client. The client + * streams acknowledgements and ack deadline modifications back to the server. The server will + * close the stream and return the status on any error. The server may close the stream with + * status `OK` to reassign server-side resources, in which case, the client should re-establish + * the stream. `UNAVAILABLE` may also be returned in the case of a transient error (e.g., a server + * restart). These should also be retried by the client. Flow control can be achieved by + * configuring the underlying RPC channel. + * + *

Sample code: + * + *


+   * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
+   *   StreamObserver<StreamingPullResponse> responseObserver =
+   *       new StreamObserver<StreamingPullResponse>() {
+   *         {@literal @}Override
+   *         public void onNext(StreamingPullResponse response) {
+   *           // Do something when receive a response
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onError(Throwable t) {
+   *           // Add error-handling
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onCompleted() {
+   *           // Do something when complete.
+   *         }
+   *       };
+   *   StreamObserver<StreamingRecognizeRequest> requestObserver =
+   *       subscriberClient.streamingPullCallable().bidiStreamingCall(responseObserver)});
+   *
+   *   SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
+   *   int streamAckDeadlineSeconds = 0;
+   *   StreamingPullRequest request = StreamingPullRequest.newBuilder()
+   *     .setSubscriptionWithSubscriptionName(subscription)
+   *     .setStreamAckDeadlineSeconds(streamAckDeadlineSeconds)
+   *     .build();
+   *   requestObserver.onNext(request);
+   * }
+   * 
+ */ + public final StreamingCallable + streamingPullCallable() { + return streamingPullCallable; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD /** * Modifies the `PushConfig` for a specified subscription. @@ -934,7 +949,8 @@ public final UnaryCallable pullCallable() { * } *
* - * @param subscription The name of the subscription. + * @param subscription The name of the subscription. Format is + * `projects/{project}/subscriptions/{sub}`. * @param pushConfig The push configuration for future deliveries. *

An empty `pushConfig` indicates that the Pub/Sub system should stop pushing messages * from the given subscription and allow messages to be pulled and acknowledged - effectively @@ -1018,7 +1034,7 @@ public final UnaryCallable modifyPushConfigCalla * *


    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   Policy policy = Policy.newBuilder().build();
    *   Policy response = subscriberClient.setIamPolicy(formattedResource, policy);
    * }
@@ -1033,7 +1049,7 @@ public final UnaryCallable modifyPushConfigCalla
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
   public final Policy setIamPolicy(String resource, Policy policy) {
-    SUBSCRIPTION_PATH_TEMPLATE.validate(resource, "setIamPolicy");
+
     SetIamPolicyRequest request =
         SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build();
     return setIamPolicy(request);
@@ -1047,7 +1063,7 @@ public final Policy setIamPolicy(String resource, Policy policy) {
    *
    * 

    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   Policy policy = Policy.newBuilder().build();
    *   SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
@@ -1072,7 +1088,7 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) {
    *
    * 

    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   Policy policy = Policy.newBuilder().build();
    *   SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
@@ -1097,7 +1113,7 @@ public final UnaryCallable setIamPolicyCallable() {
    *
    * 

    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   Policy response = subscriberClient.getIamPolicy(formattedResource);
    * }
    * 
@@ -1108,7 +1124,7 @@ public final UnaryCallable setIamPolicyCallable() { * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { - SUBSCRIPTION_PATH_TEMPLATE.validate(resource, "getIamPolicy"); + GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); } @@ -1122,7 +1138,7 @@ public final Policy getIamPolicy(String resource) { * *

    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
    *     .build();
@@ -1146,7 +1162,7 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) {
    *
    * 

    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
    *     .setResource(formattedResource)
    *     .build();
@@ -1162,13 +1178,14 @@ public final UnaryCallable getIamPolicyCallable() {
 
   // AUTO-GENERATED DOCUMENTATION AND METHOD
   /**
-   * Returns permissions that a caller has on the specified resource.
+   * Returns permissions that a caller has on the specified resource. If the resource does not
+   * exist, this will return an empty set of permissions, not a NOT_FOUND error.
    *
    * 

Sample code: * *


    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   List<String> permissions = new ArrayList<>();
    *   TestIamPermissionsResponse response = subscriberClient.testIamPermissions(formattedResource, permissions);
    * }
@@ -1184,7 +1201,7 @@ public final UnaryCallable getIamPolicyCallable() {
    */
   public final TestIamPermissionsResponse testIamPermissions(
       String resource, List permissions) {
-    SUBSCRIPTION_PATH_TEMPLATE.validate(resource, "testIamPermissions");
+
     TestIamPermissionsRequest request =
         TestIamPermissionsRequest.newBuilder()
             .setResource(resource)
@@ -1195,13 +1212,14 @@ public final TestIamPermissionsResponse testIamPermissions(
 
   // AUTO-GENERATED DOCUMENTATION AND METHOD
   /**
-   * Returns permissions that a caller has on the specified resource.
+   * Returns permissions that a caller has on the specified resource. If the resource does not
+   * exist, this will return an empty set of permissions, not a NOT_FOUND error.
    *
    * 

Sample code: * *


    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   List<String> permissions = new ArrayList<>();
    *   TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
    *     .setResource(formattedResource)
@@ -1220,13 +1238,14 @@ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsReq
 
   // AUTO-GENERATED DOCUMENTATION AND METHOD
   /**
-   * Returns permissions that a caller has on the specified resource.
+   * Returns permissions that a caller has on the specified resource. If the resource does not
+   * exist, this will return an empty set of permissions, not a NOT_FOUND error.
    *
    * 

Sample code: * *


    * try (SubscriberClient subscriberClient = SubscriberClient.create()) {
-   *   String formattedResource = SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+   *   String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    *   List<String> permissions = new ArrayList<>();
    *   TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
    *     .setResource(formattedResource)
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java
index 971e00f2df72..1366d8e10e90 100644
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java
+++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java
@@ -29,6 +29,7 @@
 import com.google.api.gax.grpc.PagedListDescriptor;
 import com.google.api.gax.grpc.PagedListResponseFactory;
 import com.google.api.gax.grpc.SimpleCallSettings;
+import com.google.api.gax.grpc.StreamingCallSettings;
 import com.google.api.gax.grpc.UnaryCallSettings;
 import com.google.api.gax.grpc.UnaryCallable;
 import com.google.common.collect.ImmutableList;
@@ -53,6 +54,8 @@
 import com.google.pubsub.v1.ModifyPushConfigRequest;
 import com.google.pubsub.v1.PullRequest;
 import com.google.pubsub.v1.PullResponse;
+import com.google.pubsub.v1.StreamingPullRequest;
+import com.google.pubsub.v1.StreamingPullResponse;
 import com.google.pubsub.v1.SubscriberGrpc;
 import com.google.pubsub.v1.Subscription;
 import io.grpc.Status;
@@ -111,6 +114,8 @@ public class SubscriberSettings extends ClientSettings {
   private final SimpleCallSettings modifyAckDeadlineSettings;
   private final SimpleCallSettings acknowledgeSettings;
   private final SimpleCallSettings pullSettings;
+  private final StreamingCallSettings
+      streamingPullSettings;
   private final SimpleCallSettings modifyPushConfigSettings;
   private final SimpleCallSettings setIamPolicySettings;
   private final SimpleCallSettings getIamPolicySettings;
@@ -154,6 +159,12 @@ public SimpleCallSettings pullSettings() {
     return pullSettings;
   }
 
+  /** Returns the object with the settings used for calls to streamingPull. */
+  public StreamingCallSettings
+      streamingPullSettings() {
+    return streamingPullSettings;
+  }
+
   /** Returns the object with the settings used for calls to modifyPushConfig. */
   public SimpleCallSettings modifyPushConfigSettings() {
     return modifyPushConfigSettings;
@@ -233,6 +244,7 @@ private SubscriberSettings(Builder settingsBuilder) throws IOException {
     modifyAckDeadlineSettings = settingsBuilder.modifyAckDeadlineSettings().build();
     acknowledgeSettings = settingsBuilder.acknowledgeSettings().build();
     pullSettings = settingsBuilder.pullSettings().build();
+    streamingPullSettings = settingsBuilder.streamingPullSettings().build();
     modifyPushConfigSettings = settingsBuilder.modifyPushConfigSettings().build();
     setIamPolicySettings = settingsBuilder.setIamPolicySettings().build();
     getIamPolicySettings = settingsBuilder.getIamPolicySettings().build();
@@ -311,6 +323,8 @@ public static class Builder extends ClientSettings.Builder {
         modifyAckDeadlineSettings;
     private final SimpleCallSettings.Builder acknowledgeSettings;
     private final SimpleCallSettings.Builder pullSettings;
+    private final StreamingCallSettings.Builder
+        streamingPullSettings;
     private final SimpleCallSettings.Builder
         modifyPushConfigSettings;
     private final SimpleCallSettings.Builder setIamPolicySettings;
@@ -382,6 +396,9 @@ private Builder() {
 
       pullSettings = SimpleCallSettings.newBuilder(SubscriberGrpc.METHOD_PULL);
 
+      streamingPullSettings =
+          StreamingCallSettings.newBuilder(SubscriberGrpc.METHOD_STREAMING_PULL);
+
       modifyPushConfigSettings =
           SimpleCallSettings.newBuilder(SubscriberGrpc.METHOD_MODIFY_PUSH_CONFIG);
 
@@ -478,6 +495,7 @@ private Builder(SubscriberSettings settings) {
       modifyAckDeadlineSettings = settings.modifyAckDeadlineSettings.toBuilder();
       acknowledgeSettings = settings.acknowledgeSettings.toBuilder();
       pullSettings = settings.pullSettings.toBuilder();
+      streamingPullSettings = settings.streamingPullSettings.toBuilder();
       modifyPushConfigSettings = settings.modifyPushConfigSettings.toBuilder();
       setIamPolicySettings = settings.setIamPolicySettings.toBuilder();
       getIamPolicySettings = settings.getIamPolicySettings.toBuilder();
@@ -561,6 +579,12 @@ public SimpleCallSettings.Builder pullSettings() {
       return pullSettings;
     }
 
+    /** Returns the builder for the settings used for calls to streamingPull. */
+    public StreamingCallSettings.Builder
+        streamingPullSettings() {
+      return streamingPullSettings;
+    }
+
     /** Returns the builder for the settings used for calls to modifyPushConfig. */
     public SimpleCallSettings.Builder modifyPushConfigSettings() {
       return modifyPushConfigSettings;
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java
index 9ace15da5027..4287fab025fe 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java
@@ -16,7 +16,6 @@
 
 package com.google.cloud.pubsub;
 
-import static com.google.cloud.pubsub.spi.v1.SubscriberClient.formatSubscriptionName;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -68,16 +67,7 @@
 import com.google.pubsub.v1.PublishResponse;
 import com.google.pubsub.v1.PullRequest;
 import com.google.pubsub.v1.PullResponse;
-
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
+import com.google.pubsub.v1.SubscriptionName;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
@@ -86,6 +76,14 @@
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 public class PubSubImplTest {
 
@@ -143,8 +141,8 @@ public com.google.pubsub.v1.Subscription apply(SubscriptionInfo subscriptionInfo
       new Function() {
         @Override
         public String apply(SubscriptionId subscriptionId) {
-          return formatSubscriptionName(subscriptionId.getProject(),
-              subscriptionId.getSubscription());
+          return SubscriptionName.create(subscriptionId.getProject(),
+              subscriptionId.getSubscription()).toString();
         }
       };
   private static final MessageProcessor DO_NOTHING = new MessageProcessor() {
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java
index 2bfcd52631d0..cb589e8e0028 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java
@@ -26,6 +26,8 @@
 import com.google.pubsub.v1.ModifyPushConfigRequest;
 import com.google.pubsub.v1.PullRequest;
 import com.google.pubsub.v1.PullResponse;
+import com.google.pubsub.v1.StreamingPullRequest;
+import com.google.pubsub.v1.StreamingPullResponse;
 import com.google.pubsub.v1.SubscriberGrpc.SubscriberImplBase;
 import com.google.pubsub.v1.Subscription;
 import io.grpc.stub.StreamObserver;
@@ -169,6 +171,36 @@ public void pull(PullRequest request, StreamObserver responseObser
     }
   }
 
+  @Override
+  public StreamObserver streamingPull(
+      final StreamObserver responseObserver) {
+    final Object response = responses.remove();
+    StreamObserver requestObserver =
+        new StreamObserver() {
+          @Override
+          public void onNext(StreamingPullRequest value) {
+            if (response instanceof StreamingPullResponse) {
+              responseObserver.onNext((StreamingPullResponse) response);
+            } else if (response instanceof Exception) {
+              responseObserver.onError((Exception) response);
+            } else {
+              responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
+            }
+          }
+
+          @Override
+          public void onError(Throwable t) {
+            responseObserver.onError(t);
+          }
+
+          @Override
+          public void onCompleted() {
+            responseObserver.onCompleted();
+          }
+        };
+    return requestObserver;
+  }
+
   @Override
   public void modifyPushConfig(
       ModifyPushConfigRequest request, StreamObserver responseObserver) {
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java
index 45066d67c31b..dda2496c08ab 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java
@@ -345,7 +345,7 @@ public void setIamPolicyTest() {
     Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
     mockIAMPolicy.addResponse(expectedResponse);
 
-    String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+    String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
     Policy policy = Policy.newBuilder().build();
 
     Policy actualResponse = client.setIamPolicy(formattedResource, policy);
@@ -366,7 +366,7 @@ public void setIamPolicyExceptionTest() throws Exception {
     mockIAMPolicy.addException(exception);
 
     try {
-      String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+      String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
       Policy policy = Policy.newBuilder().build();
 
       client.setIamPolicy(formattedResource, policy);
@@ -384,7 +384,7 @@ public void getIamPolicyTest() {
     Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
     mockIAMPolicy.addResponse(expectedResponse);
 
-    String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+    String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
 
     Policy actualResponse = client.getIamPolicy(formattedResource);
     Assert.assertEquals(expectedResponse, actualResponse);
@@ -403,7 +403,7 @@ public void getIamPolicyExceptionTest() throws Exception {
     mockIAMPolicy.addException(exception);
 
     try {
-      String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+      String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
 
       client.getIamPolicy(formattedResource);
       Assert.fail("No exception raised");
@@ -418,7 +418,7 @@ public void testIamPermissionsTest() {
     TestIamPermissionsResponse expectedResponse = TestIamPermissionsResponse.newBuilder().build();
     mockIAMPolicy.addResponse(expectedResponse);
 
-    String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+    String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
     List permissions = new ArrayList<>();
 
     TestIamPermissionsResponse actualResponse =
@@ -440,7 +440,7 @@ public void testIamPermissionsExceptionTest() throws Exception {
     mockIAMPolicy.addException(exception);
 
     try {
-      String formattedResource = PublisherClient.formatTopicName("[PROJECT]", "[TOPIC]");
+      String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
       List permissions = new ArrayList<>();
 
       client.testIamPermissions(formattedResource, permissions);
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java
index 7da01dd91701..9b7597bfcff7 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java
@@ -18,8 +18,10 @@
 import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse;
 
 import com.google.api.gax.grpc.ApiException;
+import com.google.api.gax.grpc.StreamingCallable;
 import com.google.api.gax.testing.MockGrpcService;
 import com.google.api.gax.testing.MockServiceHelper;
+import com.google.api.gax.testing.MockStreamObserver;
 import com.google.common.collect.Lists;
 import com.google.iam.v1.GetIamPolicyRequest;
 import com.google.iam.v1.Policy;
@@ -40,16 +42,20 @@
 import com.google.pubsub.v1.PullRequest;
 import com.google.pubsub.v1.PullResponse;
 import com.google.pubsub.v1.PushConfig;
+import com.google.pubsub.v1.StreamingPullRequest;
+import com.google.pubsub.v1.StreamingPullResponse;
 import com.google.pubsub.v1.Subscription;
 import com.google.pubsub.v1.SubscriptionName;
 import com.google.pubsub.v1.TopicName;
 import com.google.pubsub.v1.TopicNameOneof;
 import io.grpc.Status;
 import io.grpc.StatusRuntimeException;
+import io.grpc.stub.StreamObserver;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -383,6 +389,66 @@ public void pullExceptionTest() throws Exception {
     }
   }
 
+  @Test
+  @SuppressWarnings("all")
+  public void streamingPullTest() throws Exception {
+    StreamingPullResponse expectedResponse = StreamingPullResponse.newBuilder().build();
+    mockSubscriber.addResponse(expectedResponse);
+    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
+    int streamAckDeadlineSeconds = 1875467245;
+    StreamingPullRequest request =
+        StreamingPullRequest.newBuilder()
+            .setSubscriptionWithSubscriptionName(subscription)
+            .setStreamAckDeadlineSeconds(streamAckDeadlineSeconds)
+            .build();
+
+    MockStreamObserver responseObserver = new MockStreamObserver<>();
+
+    StreamingCallable callable =
+        client.streamingPullCallable();
+    StreamObserver requestObserver =
+        callable.bidiStreamingCall(responseObserver);
+
+    requestObserver.onNext(request);
+    requestObserver.onCompleted();
+
+    List actualResponses = responseObserver.future().get();
+    Assert.assertEquals(1, actualResponses.size());
+    Assert.assertEquals(expectedResponse, actualResponses.get(0));
+  }
+
+  @Test
+  @SuppressWarnings("all")
+  public void streamingPullExceptionTest() throws Exception {
+    StatusRuntimeException exception = new StatusRuntimeException(Status.INTERNAL);
+    mockSubscriber.addException(exception);
+    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
+    int streamAckDeadlineSeconds = 1875467245;
+    StreamingPullRequest request =
+        StreamingPullRequest.newBuilder()
+            .setSubscriptionWithSubscriptionName(subscription)
+            .setStreamAckDeadlineSeconds(streamAckDeadlineSeconds)
+            .build();
+
+    MockStreamObserver responseObserver = new MockStreamObserver<>();
+
+    StreamingCallable callable =
+        client.streamingPullCallable();
+    StreamObserver requestObserver =
+        callable.bidiStreamingCall(responseObserver);
+
+    requestObserver.onNext(request);
+
+    try {
+      List actualResponses = responseObserver.future().get();
+      Assert.fail("No exception thrown");
+    } catch (ExecutionException e) {
+      Assert.assertTrue(e.getCause() instanceof StatusRuntimeException);
+      StatusRuntimeException statusException = (StatusRuntimeException) e.getCause();
+      Assert.assertEquals(Status.INTERNAL, statusException.getStatus());
+    }
+  }
+
   @Test
   @SuppressWarnings("all")
   public void modifyPushConfigTest() {
@@ -427,8 +493,7 @@ public void setIamPolicyTest() {
     Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
     mockIAMPolicy.addResponse(expectedResponse);
 
-    String formattedResource =
-        SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+    String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
     Policy policy = Policy.newBuilder().build();
 
     Policy actualResponse = client.setIamPolicy(formattedResource, policy);
@@ -449,8 +514,7 @@ public void setIamPolicyExceptionTest() throws Exception {
     mockIAMPolicy.addException(exception);
 
     try {
-      String formattedResource =
-          SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+      String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
       Policy policy = Policy.newBuilder().build();
 
       client.setIamPolicy(formattedResource, policy);
@@ -468,8 +532,7 @@ public void getIamPolicyTest() {
     Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
     mockIAMPolicy.addResponse(expectedResponse);
 
-    String formattedResource =
-        SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+    String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
 
     Policy actualResponse = client.getIamPolicy(formattedResource);
     Assert.assertEquals(expectedResponse, actualResponse);
@@ -488,8 +551,7 @@ public void getIamPolicyExceptionTest() throws Exception {
     mockIAMPolicy.addException(exception);
 
     try {
-      String formattedResource =
-          SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+      String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
 
       client.getIamPolicy(formattedResource);
       Assert.fail("No exception raised");
@@ -504,8 +566,7 @@ public void testIamPermissionsTest() {
     TestIamPermissionsResponse expectedResponse = TestIamPermissionsResponse.newBuilder().build();
     mockIAMPolicy.addResponse(expectedResponse);
 
-    String formattedResource =
-        SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+    String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
     List permissions = new ArrayList<>();
 
     TestIamPermissionsResponse actualResponse =
@@ -527,8 +588,7 @@ public void testIamPermissionsExceptionTest() throws Exception {
     mockIAMPolicy.addException(exception);
 
     try {
-      String formattedResource =
-          SubscriberClient.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+      String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
       List permissions = new ArrayList<>();
 
       client.testIamPermissions(formattedResource, permissions);
diff --git a/google-cloud-speech/pom.xml b/google-cloud-speech/pom.xml
index 52fd58a97b58..3e48afaad48e 100644
--- a/google-cloud-speech/pom.xml
+++ b/google-cloud-speech/pom.xml
@@ -30,7 +30,7 @@
     
       com.google.api.grpc
       grpc-google-cloud-speech-v1beta1
-      0.1.3
+      0.1.5
       
         
           io.grpc
diff --git a/google-cloud-trace/pom.xml b/google-cloud-trace/pom.xml
index f787b6c3924b..7a0869402104 100644
--- a/google-cloud-trace/pom.xml
+++ b/google-cloud-trace/pom.xml
@@ -30,7 +30,7 @@
     
       com.google.api.grpc
       grpc-google-cloud-trace-v1
-      0.1.3
+      0.1.5
       
         
           io.grpc
diff --git a/google-cloud-vision/pom.xml b/google-cloud-vision/pom.xml
index f14e51c7b2e8..3b674429969e 100644
--- a/google-cloud-vision/pom.xml
+++ b/google-cloud-vision/pom.xml
@@ -30,7 +30,7 @@
     
       com.google.api.grpc
       grpc-google-cloud-vision-v1
-      0.1.3
+      0.1.5
       
         
           io.grpc