diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index e3fb52ed2ef8..1ea4eb6cceb8 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -106,7 +106,7 @@ com.google.api gax - 0.0.18 + 0.0.21 com.google.api.grpc diff --git a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java index 330a3dff2b15..a4991ae312d1 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/GrpcServiceOptions.java @@ -20,7 +20,7 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spi.ServiceRpcFactory; import com.google.common.annotations.VisibleForTesting; @@ -226,7 +226,7 @@ protected ExecutorFactory executorFactory() { /** * Returns a builder for API call settings. */ - protected ApiCallSettings.Builder apiCallSettings() { + protected UnaryCallSettings.Builder apiCallSettings() { // todo(mziccard): specify timeout these settings: // retryParams().retryMaxAttempts(), retryParams().retryMinAttempts() final RetrySettings.Builder builder = RetrySettings.newBuilder() @@ -237,7 +237,7 @@ protected ApiCallSettings.Builder apiCallSettings() { .setInitialRetryDelay(Duration.millis(retryParams().initialRetryDelayMillis())) .setRetryDelayMultiplier(retryParams().retryDelayBackoffFactor()) .setMaxRetryDelay(Duration.millis(retryParams().maxRetryDelayMillis())); - return ApiCallSettings.newBuilder().setRetrySettingsBuilder(builder); + return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(builder); } /** diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceApi.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceApi.java index fecd24c11af0..945e0fc6b2be 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceApi.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceApi.java @@ -13,7 +13,7 @@ */ package com.google.cloud.errorreporting.spi.v1beta1; -import com.google.api.gax.grpc.ApiCallable; +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; @@ -54,8 +54,8 @@ *
  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -83,8 +83,8 @@ public class ErrorGroupServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable getGroupCallable; - private final ApiCallable updateGroupCallable; + private final UnaryCallable getGroupCallable; + private final UnaryCallable updateGroupCallable; private static final PathTemplate GROUP_PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding("projects/{project}/groups/{group}"); @@ -130,9 +130,9 @@ protected ErrorGroupServiceApi(ErrorGroupServiceSettings settings) throws IOExce this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.getGroupCallable = - ApiCallable.create(settings.getGroupSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getGroupSettings(), this.channel, this.executor); this.updateGroupCallable = - ApiCallable.create(settings.updateGroupSettings(), this.channel, this.executor); + UnaryCallable.create(settings.updateGroupSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -226,7 +226,7 @@ private final ErrorGroup getGroup(GetGroupRequest request) { * } * */ - public final ApiCallable getGroupCallable() { + public final UnaryCallable getGroupCallable() { return getGroupCallable; } @@ -292,7 +292,7 @@ private final ErrorGroup updateGroup(UpdateGroupRequest request) { * } * */ - public final ApiCallable updateGroupCallable() { + public final UnaryCallable updateGroupCallable() { return updateGroupCallable; } diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceSettings.java index 4dc8bbeae7f1..653ea1709602 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceSettings.java @@ -15,9 +15,9 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -74,14 +74,6 @@ public class ErrorGroupServiceSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings getGroupSettings; private final SimpleCallSettings updateGroupSettings; @@ -140,7 +132,7 @@ private ErrorGroupServiceSettings(Builder settingsBuilder) throws IOException { /** Builder for ErrorGroupServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder getGroupSettings; private final SimpleCallSettings.Builder updateGroupSettings; @@ -177,15 +169,15 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); getGroupSettings = SimpleCallSettings.newBuilder(ErrorGroupServiceGrpc.METHOD_GET_GROUP); updateGroupSettings = SimpleCallSettings.newBuilder(ErrorGroupServiceGrpc.METHOD_UPDATE_GROUP); - methodSettingsBuilders = - ImmutableList.of(getGroupSettings, updateGroupSettings); + unaryMethodSettingsBuilders = + ImmutableList.of(getGroupSettings, updateGroupSettings); } private static Builder createDefault() { @@ -210,13 +202,20 @@ private Builder(ErrorGroupServiceSettings settings) { getGroupSettings = settings.getGroupSettings.toBuilder(); updateGroupSettings = settings.updateGroupSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of(getGroupSettings, updateGroupSettings); + unaryMethodSettingsBuilders = + ImmutableList.of(getGroupSettings, updateGroupSettings); + } + + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); } @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -262,11 +261,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java index f333c555e500..589951fd7189 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java @@ -13,13 +13,13 @@ */ package com.google.cloud.errorreporting.spi.v1beta1; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListEventsPagedResponse; +import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListGroupStatsPagedResponse; + +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.ErrorEvent; -import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats; import com.google.devtools.clouderrorreporting.v1beta1.ListEventsRequest; import com.google.devtools.clouderrorreporting.v1beta1.ListEventsResponse; import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest; @@ -62,8 +62,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -91,16 +91,12 @@ public class ErrorStatsServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable listGroupStatsCallable; - private final ApiCallable< - ListGroupStatsRequest, - PagedListResponse> + private final UnaryCallable listGroupStatsCallable; + private final UnaryCallable listGroupStatsPagedCallable; - private final ApiCallable listEventsCallable; - private final ApiCallable< - ListEventsRequest, PagedListResponse> - listEventsPagedCallable; - private final ApiCallable deleteEventsCallable; + private final UnaryCallable listEventsCallable; + private final UnaryCallable listEventsPagedCallable; + private final UnaryCallable deleteEventsCallable; private static final PathTemplate PROJECT_PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding("projects/{project}"); @@ -139,16 +135,17 @@ protected ErrorStatsServiceApi(ErrorStatsServiceSettings settings) throws IOExce this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.listGroupStatsCallable = - ApiCallable.create(settings.listGroupStatsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listGroupStatsSettings(), this.channel, this.executor); this.listGroupStatsPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listGroupStatsSettings(), this.channel, this.executor); this.listEventsCallable = - ApiCallable.create(settings.listEventsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listEventsSettings(), this.channel, this.executor); this.listEventsPagedCallable = - ApiCallable.createPagedVariant(settings.listEventsSettings(), this.channel, this.executor); + UnaryCallable.createPagedVariant( + settings.listEventsSettings(), this.channel, this.executor); this.deleteEventsCallable = - ApiCallable.create(settings.deleteEventsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.deleteEventsSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -195,13 +192,14 @@ 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. The service is tuned for - * retrieving data up to (approximately) 'now'. Retrieving data for arbitrary time periods in - * the past can result in higher response times or in returning incomplete results. + * @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. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse - listGroupStats(String projectName, QueryTimeRange timeRange) { + public final ListGroupStatsPagedResponse listGroupStats( + String projectName, QueryTimeRange timeRange) { PROJECT_PATH_TEMPLATE.validate(projectName, "listGroupStats"); ListGroupStatsRequest request = ListGroupStatsRequest.newBuilder() @@ -234,8 +232,7 @@ public final ErrorStatsServiceSettings getSettings() { * @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 PagedListResponse - listGroupStats(ListGroupStatsRequest request) { + public final ListGroupStatsPagedResponse listGroupStats(ListGroupStatsRequest request) { return listGroupStatsPagedCallable().call(request); } @@ -253,7 +250,7 @@ public final ErrorStatsServiceSettings getSettings() { * .setProjectName(formattedProjectName) * .setTimeRange(timeRange) * .build(); - * ListenableFuture<PagedListResponse<ListGroupStatsRequest,ListGroupStatsResponse,ErrorGroupStats>> future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request); + * ListenableFuture<ListGroupStatsPagedResponse> future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request); * // Do something * for (ErrorGroupStats element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -261,9 +258,7 @@ public final ErrorStatsServiceSettings getSettings() { * } * */ - public final ApiCallable< - ListGroupStatsRequest, - PagedListResponse> + public final UnaryCallable listGroupStatsPagedCallable() { return listGroupStatsPagedCallable; } @@ -297,7 +292,8 @@ public final ErrorStatsServiceSettings getSettings() { * } * */ - public final ApiCallable listGroupStatsCallable() { + public final UnaryCallable + listGroupStatsCallable() { return listGroupStatsCallable; } @@ -323,8 +319,7 @@ public final ApiCallable listGrou * @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 PagedListResponse listEvents( - String projectName, String groupId) { + public final ListEventsPagedResponse listEvents(String projectName, String groupId) { PROJECT_PATH_TEMPLATE.validate(projectName, "listEvents"); ListEventsRequest request = ListEventsRequest.newBuilder().setProjectName(projectName).setGroupId(groupId).build(); @@ -354,8 +349,7 @@ public final PagedListResponse listEvents( - ListEventsRequest request) { + public final ListEventsPagedResponse listEvents(ListEventsRequest request) { return listEventsPagedCallable().call(request); } @@ -373,7 +367,7 @@ public final PagedListResponse */ - public final ApiCallable< - ListEventsRequest, PagedListResponse> - listEventsPagedCallable() { + public final UnaryCallable listEventsPagedCallable() { return listEventsPagedCallable; } @@ -416,7 +408,7 @@ public final PagedListResponse */ - public final ApiCallable listEventsCallable() { + public final UnaryCallable listEventsCallable() { return listEventsCallable; } @@ -486,7 +478,7 @@ private final DeleteEventsResponse deleteEvents(DeleteEventsRequest request) { * } * */ - public final ApiCallable deleteEventsCallable() { + public final UnaryCallable deleteEventsCallable() { return deleteEventsCallable; } diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java index b34dde3f867b..63ffa975b475 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java @@ -13,13 +13,19 @@ */ package com.google.cloud.errorreporting.spi.v1beta1; +import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListEventsPagedResponse; +import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListGroupStatsPagedResponse; + import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -81,29 +87,22 @@ public class ErrorStatsServiceSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - - private final PageStreamingCallSettings< - ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats> + private final PagedCallSettings< + ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse> listGroupStatsSettings; - private final PageStreamingCallSettings + private final PagedCallSettings listEventsSettings; private final SimpleCallSettings deleteEventsSettings; /** Returns the object with the settings used for calls to listGroupStats. */ - public PageStreamingCallSettings + public PagedCallSettings< + ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse> listGroupStatsSettings() { return listGroupStatsSettings; } /** Returns the object with the settings used for calls to listEvents. */ - public PageStreamingCallSettings + public PagedCallSettings listEventsSettings() { return listEventsSettings; } @@ -157,10 +156,10 @@ private ErrorStatsServiceSettings(Builder settingsBuilder) throws IOException { deleteEventsSettings = settingsBuilder.deleteEventsSettings().build(); } - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats> LIST_GROUP_STATS_PAGE_STR_DESC = - new PageStreamingDescriptor< + new PagedListDescriptor< ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>() { @Override public Object emptyToken() { @@ -194,9 +193,9 @@ public Iterable extractResources(ListGroupStatsResponse payload } }; - private static final PageStreamingDescriptor + private static final PagedListDescriptor LIST_EVENTS_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -228,15 +227,45 @@ public Iterable extractResources(ListEventsResponse payload) { } }; + private static final PagedListResponseFactory< + ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse> + LIST_GROUP_STATS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse>() { + @Override + public ListGroupStatsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListGroupStatsRequest request, + CallContext context) { + return new ListGroupStatsPagedResponse( + callable, LIST_GROUP_STATS_PAGE_STR_DESC, request, context); + } + }; + + private static final PagedListResponseFactory< + ListEventsRequest, ListEventsResponse, ListEventsPagedResponse> + LIST_EVENTS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListEventsRequest, ListEventsResponse, ListEventsPagedResponse>() { + @Override + public ListEventsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListEventsRequest request, + CallContext context) { + return new ListEventsPagedResponse( + callable, LIST_EVENTS_PAGE_STR_DESC, request, context); + } + }; + /** Builder for ErrorStatsServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; - private final PageStreamingCallSettings.Builder< - ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats> + private final PagedCallSettings.Builder< + ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse> listGroupStatsSettings; - private final PageStreamingCallSettings.Builder< - ListEventsRequest, ListEventsResponse, ErrorEvent> + private final PagedCallSettings.Builder< + ListEventsRequest, ListEventsResponse, ListEventsPagedResponse> listEventsSettings; private final SimpleCallSettings.Builder deleteEventsSettings; @@ -273,21 +302,21 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); listGroupStatsSettings = - PageStreamingCallSettings.newBuilder( - ErrorStatsServiceGrpc.METHOD_LIST_GROUP_STATS, LIST_GROUP_STATS_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + ErrorStatsServiceGrpc.METHOD_LIST_GROUP_STATS, LIST_GROUP_STATS_PAGE_STR_FACT); listEventsSettings = - PageStreamingCallSettings.newBuilder( - ErrorStatsServiceGrpc.METHOD_LIST_EVENTS, LIST_EVENTS_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + ErrorStatsServiceGrpc.METHOD_LIST_EVENTS, LIST_EVENTS_PAGE_STR_FACT); deleteEventsSettings = SimpleCallSettings.newBuilder(ErrorStatsServiceGrpc.METHOD_DELETE_EVENTS); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listGroupStatsSettings, listEventsSettings, deleteEventsSettings); } @@ -319,14 +348,21 @@ private Builder(ErrorStatsServiceSettings settings) { listEventsSettings = settings.listEventsSettings.toBuilder(); deleteEventsSettings = settings.deleteEventsSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listGroupStatsSettings, listEventsSettings, deleteEventsSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -372,23 +408,26 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } /** Returns the builder for the settings used for calls to listGroupStats. */ - public PageStreamingCallSettings.Builder< - ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats> + public PagedCallSettings.Builder< + ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse> listGroupStatsSettings() { return listGroupStatsSettings; } /** Returns the builder for the settings used for calls to listEvents. */ - public PageStreamingCallSettings.Builder + public PagedCallSettings.Builder listEventsSettings() { return listEventsSettings; } diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/PagedResponseWrappers.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/PagedResponseWrappers.java new file mode 100644 index 000000000000..094cdcaa0ea1 --- /dev/null +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/PagedResponseWrappers.java @@ -0,0 +1,61 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.errorreporting.spi.v1beta1; + +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseImpl; +import com.google.api.gax.grpc.UnaryCallable; +import com.google.devtools.clouderrorreporting.v1beta1.ErrorEvent; +import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats; +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; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers { + + public static class ListGroupStatsPagedResponse + extends PagedListResponseImpl< + ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats> { + + public ListGroupStatsPagedResponse( + UnaryCallable callable, + PagedListDescriptor + pageDescriptor, + ListGroupStatsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListEventsPagedResponse + extends PagedListResponseImpl { + + public ListEventsPagedResponse( + UnaryCallable callable, + PagedListDescriptor pageDescriptor, + ListEventsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } +} diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceApi.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceApi.java index cdd5714e093e..907c9d193271 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceApi.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceApi.java @@ -13,7 +13,7 @@ */ package com.google.cloud.errorreporting.spi.v1beta1; -import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.UnaryCallable; import com.google.api.gax.protobuf.PathTemplate; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse; @@ -56,8 +56,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -85,7 +85,7 @@ public class ReportErrorsServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable + private final UnaryCallable reportErrorEventCallable; private static final PathTemplate PROJECT_PATH_TEMPLATE = @@ -126,7 +126,7 @@ protected ReportErrorsServiceApi(ReportErrorsServiceSettings settings) throws IO this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.reportErrorEventCallable = - ApiCallable.create(settings.reportErrorEventSettings(), this.channel, this.executor); + UnaryCallable.create(settings.reportErrorEventSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -246,7 +246,7 @@ public final ReportErrorEventResponse reportErrorEvent(ReportErrorEventRequest r * } * */ - public final ApiCallable + public final UnaryCallable reportErrorEventCallable() { return reportErrorEventCallable; } diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceSettings.java index a4b390017c31..5c0d864d7907 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceSettings.java @@ -15,9 +15,9 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -73,14 +73,6 @@ public class ReportErrorsServiceSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings reportErrorEventSettings; @@ -134,7 +126,7 @@ private ReportErrorsServiceSettings(Builder settingsBuilder) throws IOException /** Builder for ReportErrorsServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder reportErrorEventSettings; @@ -171,12 +163,13 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); reportErrorEventSettings = SimpleCallSettings.newBuilder(ReportErrorsServiceGrpc.METHOD_REPORT_ERROR_EVENT); - methodSettingsBuilders = ImmutableList.of(reportErrorEventSettings); + unaryMethodSettingsBuilders = + ImmutableList.of(reportErrorEventSettings); } private static Builder createDefault() { @@ -195,12 +188,20 @@ private Builder(ReportErrorsServiceSettings settings) { reportErrorEventSettings = settings.reportErrorEventSettings.toBuilder(); - methodSettingsBuilders = ImmutableList.of(reportErrorEventSettings); + unaryMethodSettingsBuilders = + ImmutableList.of(reportErrorEventSettings); + } + + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); } @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -246,11 +247,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } 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 15a1f4bf3564..94e1d677bb90 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 @@ -15,7 +15,7 @@ /** * A client to Stackdriver Error Reporting API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    ==================== ErrorGroupServiceApi ==================== * 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 df94dfc07b04..323f437c222e 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 @@ -14,7 +14,9 @@ package com.google.cloud.errorreporting.spi.v1beta1; -import com.google.api.gax.core.PagedListResponse; +import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListEventsPagedResponse; +import static com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListGroupStatsPagedResponse; + import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -98,8 +100,8 @@ public void listGroupStatsTest() { String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]"); QueryTimeRange timeRange = QueryTimeRange.newBuilder().build(); - PagedListResponse - pagedListResponse = api.listGroupStats(formattedProjectName, timeRange); + ListGroupStatsPagedResponse pagedListResponse = + api.listGroupStats(formattedProjectName, timeRange); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -131,8 +133,7 @@ public void listEventsTest() { String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]"); String groupId = "groupId506361563"; - PagedListResponse pagedListResponse = - api.listEvents(formattedProjectName, groupId); + ListEventsPagedResponse pagedListResponse = api.listEvents(formattedProjectName, groupId); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceApi.java b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceApi.java index 1f663b9929f6..d4efc38381aa 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceApi.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceApi.java @@ -13,7 +13,7 @@ */ package com.google.cloud.language.spi.v1beta1; -import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.UnaryCallable; import com.google.cloud.language.v1beta1.AnalyzeEntitiesRequest; import com.google.cloud.language.v1beta1.AnalyzeEntitiesResponse; import com.google.cloud.language.v1beta1.AnalyzeSentimentRequest; @@ -60,8 +60,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -89,11 +89,11 @@ public class LanguageServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable + private final UnaryCallable analyzeSentimentCallable; - private final ApiCallable + private final UnaryCallable analyzeEntitiesCallable; - private final ApiCallable annotateTextCallable; + private final UnaryCallable annotateTextCallable; /** Constructs an instance of LanguageServiceApi with default settings. */ public static final LanguageServiceApi create() throws IOException { @@ -119,11 +119,11 @@ protected LanguageServiceApi(LanguageServiceSettings settings) throws IOExceptio this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.analyzeSentimentCallable = - ApiCallable.create(settings.analyzeSentimentSettings(), this.channel, this.executor); + UnaryCallable.create(settings.analyzeSentimentSettings(), this.channel, this.executor); this.analyzeEntitiesCallable = - ApiCallable.create(settings.analyzeEntitiesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.analyzeEntitiesSettings(), this.channel, this.executor); this.annotateTextCallable = - ApiCallable.create(settings.annotateTextSettings(), this.channel, this.executor); + UnaryCallable.create(settings.annotateTextSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -213,7 +213,7 @@ private final AnalyzeSentimentResponse analyzeSentiment(AnalyzeSentimentRequest * } * */ - public final ApiCallable + public final UnaryCallable analyzeSentimentCallable() { return analyzeSentimentCallable; } @@ -294,7 +294,7 @@ public final AnalyzeEntitiesResponse analyzeEntities(AnalyzeEntitiesRequest requ * } * */ - public final ApiCallable + public final UnaryCallable analyzeEntitiesCallable() { return analyzeEntitiesCallable; } @@ -385,7 +385,7 @@ public final AnnotateTextResponse annotateText(AnnotateTextRequest request) { * } * */ - public final ApiCallable annotateTextCallable() { + public final UnaryCallable annotateTextCallable() { return annotateTextCallable; } diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceSettings.java b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceSettings.java index 394c2a7add5e..93e0cc6fc90c 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceSettings.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/LanguageServiceSettings.java @@ -15,9 +15,9 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.cloud.language.v1beta1.AnalyzeEntitiesRequest; import com.google.cloud.language.v1beta1.AnalyzeEntitiesResponse; @@ -76,14 +76,6 @@ public class LanguageServiceSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings analyzeSentimentSettings; private final SimpleCallSettings @@ -153,7 +145,7 @@ private LanguageServiceSettings(Builder settingsBuilder) throws IOException { /** Builder for LanguageServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder analyzeSentimentSettings; @@ -194,7 +186,7 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); analyzeSentimentSettings = SimpleCallSettings.newBuilder(LanguageServiceGrpc.METHOD_ANALYZE_SENTIMENT); @@ -205,8 +197,8 @@ private Builder() { annotateTextSettings = SimpleCallSettings.newBuilder(LanguageServiceGrpc.METHOD_ANNOTATE_TEXT); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( analyzeSentimentSettings, analyzeEntitiesSettings, annotateTextSettings); } @@ -238,14 +230,21 @@ private Builder(LanguageServiceSettings settings) { analyzeEntitiesSettings = settings.analyzeEntitiesSettings.toBuilder(); annotateTextSettings = settings.annotateTextSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( analyzeSentimentSettings, analyzeEntitiesSettings, annotateTextSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -291,11 +290,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/PagedResponseWrappers.java b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/PagedResponseWrappers.java new file mode 100644 index 000000000000..c3971cf9e604 --- /dev/null +++ b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/PagedResponseWrappers.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.language.spi.v1beta1; + + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers {} diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/package-info.java b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/package-info.java index 9adb4a848362..00a31e853d4c 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/package-info.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/spi/v1beta1/package-info.java @@ -15,7 +15,7 @@ /** * A client to Google Cloud Natural Language API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    ================== LanguageServiceApi ================== * diff --git a/google-cloud-logging/pom.xml b/google-cloud-logging/pom.xml index d2185f866bb2..c277ef51017f 100644 --- a/google-cloud-logging/pom.xml +++ b/google-cloud-logging/pom.xml @@ -30,7 +30,7 @@ com.google.api.grpc grpc-google-logging-v2 - 0.1.0 + 0.1.1 io.grpc diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java index a707c29d5a42..20bb13cf7273 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java @@ -19,7 +19,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.grpc.ApiCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.api.gax.grpc.ApiException; import com.google.cloud.AuthCredentials; import com.google.cloud.GrpcServiceOptions.ExecutorFactory; @@ -92,7 +92,7 @@ protected ExecutorFactory executorFactory() { } @Override - protected ApiCallSettings.Builder apiCallSettings() { + protected UnaryCallSettings.Builder apiCallSettings() { return super.apiCallSettings(); } @@ -133,7 +133,7 @@ public DefaultLoggingRpc(LoggingOptions options) throws IOException { logBuilder.provideChannelWith(connectionSettings); metricsBuilder.provideChannelWith(connectionSettings); } - ApiCallSettings.Builder callSettingsBuilder = internalOptions.apiCallSettings(); + UnaryCallSettings.Builder callSettingsBuilder = internalOptions.apiCallSettings(); confBuilder.applyToAllApiMethods(callSettingsBuilder); logBuilder.applyToAllApiMethods(callSettingsBuilder); metricsBuilder.applyToAllApiMethods(callSettingsBuilder); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java index f49aca494e33..42c8ae8cccf0 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java @@ -13,8 +13,9 @@ */ package com.google.cloud.logging.spi.v2; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse; + +import com.google.api.gax.grpc.UnaryCallable; import com.google.api.gax.protobuf.PathTemplate; import com.google.logging.v2.CreateSinkRequest; import com.google.logging.v2.DeleteSinkRequest; @@ -61,8 +62,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -90,14 +91,12 @@ public class ConfigServiceV2Api implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable listSinksCallable; - private final ApiCallable< - ListSinksRequest, PagedListResponse> - listSinksPagedCallable; - private final ApiCallable getSinkCallable; - private final ApiCallable createSinkCallable; - private final ApiCallable updateSinkCallable; - private final ApiCallable deleteSinkCallable; + private final UnaryCallable listSinksCallable; + private final UnaryCallable listSinksPagedCallable; + private final UnaryCallable getSinkCallable; + private final UnaryCallable createSinkCallable; + private final UnaryCallable updateSinkCallable; + private final UnaryCallable deleteSinkCallable; private static final PathTemplate PARENT_PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding("projects/{project}"); @@ -156,17 +155,17 @@ protected ConfigServiceV2Api(ConfigServiceV2Settings settings) throws IOExceptio this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.listSinksCallable = - ApiCallable.create(settings.listSinksSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listSinksSettings(), this.channel, this.executor); this.listSinksPagedCallable = - ApiCallable.createPagedVariant(settings.listSinksSettings(), this.channel, this.executor); + UnaryCallable.createPagedVariant(settings.listSinksSettings(), this.channel, this.executor); this.getSinkCallable = - ApiCallable.create(settings.getSinkSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getSinkSettings(), this.channel, this.executor); this.createSinkCallable = - ApiCallable.create(settings.createSinkSettings(), this.channel, this.executor); + UnaryCallable.create(settings.createSinkSettings(), this.channel, this.executor); this.updateSinkCallable = - ApiCallable.create(settings.updateSinkSettings(), this.channel, this.executor); + UnaryCallable.create(settings.updateSinkSettings(), this.channel, this.executor); this.deleteSinkCallable = - ApiCallable.create(settings.deleteSinkSettings(), this.channel, this.executor); + UnaryCallable.create(settings.deleteSinkSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -207,12 +206,11 @@ public final ConfigServiceV2Settings getSettings() { * } * * - * @param parent Required. The resource name containing the sinks. Example: + * @param parent Required. The cloud resource containing the sinks. Example: * `"projects/my-logging-project"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse listSinks( - String parent) { + public final ListSinksPagedResponse listSinks(String parent) { PARENT_PATH_TEMPLATE.validate(parent, "listSinks"); ListSinksRequest request = ListSinksRequest.newBuilder().setParent(parent).build(); return listSinks(request); @@ -239,8 +237,7 @@ public final PagedListResponse lis * @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 PagedListResponse listSinks( - ListSinksRequest request) { + public final ListSinksPagedResponse listSinks(ListSinksRequest request) { return listSinksPagedCallable().call(request); } @@ -256,7 +253,7 @@ public final PagedListResponse lis * ListSinksRequest request = ListSinksRequest.newBuilder() * .setParent(formattedParent) * .build(); - * ListenableFuture<PagedListResponse<ListSinksRequest,ListSinksResponse,LogSink>> future = configServiceV2Api.listSinksPagedCallable().futureCall(request); + * ListenableFuture<ListSinksPagedResponse> future = configServiceV2Api.listSinksPagedCallable().futureCall(request); * // Do something * for (LogSink element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -264,9 +261,7 @@ public final PagedListResponse lis * } * */ - public final ApiCallable< - ListSinksRequest, PagedListResponse> - listSinksPagedCallable() { + public final UnaryCallable listSinksPagedCallable() { return listSinksPagedCallable; } @@ -297,7 +292,7 @@ public final PagedListResponse lis * } * */ - public final ApiCallable listSinksCallable() { + public final UnaryCallable listSinksCallable() { return listSinksCallable; } @@ -314,7 +309,7 @@ public final ApiCallable listSinksCallable( * } * * - * @param sinkName The resource name of the sink to return. Example: + * @param sinkName Required. The resource name of the sink to return. Example: * `"projects/my-project-id/sinks/my-sink-id"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ @@ -365,7 +360,7 @@ private final LogSink getSink(GetSinkRequest request) { * } * */ - public final ApiCallable getSinkCallable() { + public final UnaryCallable getSinkCallable() { return getSinkCallable; } @@ -383,9 +378,10 @@ public final ApiCallable getSinkCallable() { * } * * - * @param parent The resource in which to create the sink. Example: `"projects/my-project-id"`. - *

    The new sink must be provided in the request. - * @param sink The new sink, which must not have an identifier that already exists. + * @param parent Required. The resource in which to create the sink. Example: + * `"projects/my-project-id"`. The new sink must be provided in the request. + * @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 */ public final LogSink createSink(String parent, LogSink sink) { @@ -440,13 +436,13 @@ public final LogSink createSink(CreateSinkRequest request) { * } * */ - public final ApiCallable createSinkCallable() { + public final UnaryCallable createSinkCallable() { return createSinkCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates or updates a sink. + * Updates or creates a sink. * *

    Sample code: * @@ -458,12 +454,11 @@ public final ApiCallable createSinkCallable() { * } * * - * @param sinkName The resource name of the sink to update. Example: - * `"projects/my-project-id/sinks/my-sink-id"`. - *

    The updated sink must be provided in the request and have the same name that is - * specified in `sinkName`. If the sink does not exist, it is created. - * @param sink The updated sink, whose name must be the same as the sink identifier in `sinkName`. - * If `sinkName` does not exist, then this method creates a new sink. + * @param sinkName Required. The resource name of the sink to update, including the parent + * resource and the sink identifier. If the sink does not exist, this method creates the sink. + * 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. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogSink updateSink(String sinkName, LogSink sink) { @@ -475,7 +470,7 @@ public final LogSink updateSink(String sinkName, LogSink sink) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates or updates a sink. + * Updates or creates a sink. * *

    Sample code: * @@ -500,7 +495,7 @@ public final LogSink updateSink(UpdateSinkRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates or updates a sink. + * Updates or creates a sink. * *

    Sample code: * @@ -518,7 +513,7 @@ public final LogSink updateSink(UpdateSinkRequest request) { * } * */ - public final ApiCallable updateSinkCallable() { + public final UnaryCallable updateSinkCallable() { return updateSinkCallable; } @@ -535,8 +530,9 @@ public final ApiCallable updateSinkCallable() { * } * * - * @param sinkName The resource name of the sink to delete. Example: - * `"projects/my-project-id/sinks/my-sink-id"`. + * @param sinkName Required. The resource name of the sink to delete, including the parent + * resource and the sink identifier. 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(String sinkName) { @@ -586,7 +582,7 @@ private final void deleteSink(DeleteSinkRequest request) { * } * */ - public final ApiCallable deleteSinkCallable() { + public final UnaryCallable deleteSinkCallable() { return deleteSinkCallable; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java index f44dddab6743..e64335800d90 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java @@ -13,13 +13,18 @@ */ package com.google.cloud.logging.spi.v2; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse; + import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -86,15 +91,7 @@ public class ConfigServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/logging.write") .build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - - private final PageStreamingCallSettings + private final PagedCallSettings listSinksSettings; private final SimpleCallSettings getSinkSettings; private final SimpleCallSettings createSinkSettings; @@ -102,7 +99,7 @@ public class ConfigServiceV2Settings extends ServiceApiSettings { private final SimpleCallSettings deleteSinkSettings; /** Returns the object with the settings used for calls to listSinks. */ - public PageStreamingCallSettings + public PagedCallSettings listSinksSettings() { return listSinksSettings; } @@ -173,9 +170,9 @@ private ConfigServiceV2Settings(Builder settingsBuilder) throws IOException { deleteSinkSettings = settingsBuilder.deleteSinkSettings().build(); } - private static final PageStreamingDescriptor + private static final PagedListDescriptor LIST_SINKS_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -207,11 +204,27 @@ public Iterable extractResources(ListSinksResponse payload) { } }; + private static final PagedListResponseFactory< + ListSinksRequest, ListSinksResponse, ListSinksPagedResponse> + LIST_SINKS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListSinksRequest, ListSinksResponse, ListSinksPagedResponse>() { + @Override + public ListSinksPagedResponse createPagedListResponse( + UnaryCallable callable, + ListSinksRequest request, + CallContext context) { + return new ListSinksPagedResponse( + callable, LIST_SINKS_PAGE_STR_DESC, request, context); + } + }; + /** Builder for ConfigServiceV2Settings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; - private final PageStreamingCallSettings.Builder + private final PagedCallSettings.Builder< + ListSinksRequest, ListSinksResponse, ListSinksPagedResponse> listSinksSettings; private final SimpleCallSettings.Builder getSinkSettings; private final SimpleCallSettings.Builder createSinkSettings; @@ -250,11 +263,11 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); listSinksSettings = - PageStreamingCallSettings.newBuilder( - ConfigServiceV2Grpc.METHOD_LIST_SINKS, LIST_SINKS_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + ConfigServiceV2Grpc.METHOD_LIST_SINKS, LIST_SINKS_PAGE_STR_FACT); getSinkSettings = SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_GET_SINK); @@ -264,8 +277,8 @@ private Builder() { deleteSinkSettings = SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_DELETE_SINK); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listSinksSettings, getSinkSettings, createSinkSettings, @@ -313,8 +326,8 @@ private Builder(ConfigServiceV2Settings settings) { updateSinkSettings = settings.updateSinkSettings.toBuilder(); deleteSinkSettings = settings.deleteSinkSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listSinksSettings, getSinkSettings, createSinkSettings, @@ -322,9 +335,16 @@ private Builder(ConfigServiceV2Settings settings) { deleteSinkSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -370,16 +390,19 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } /** Returns the builder for the settings used for calls to listSinks. */ - public PageStreamingCallSettings.Builder + public PagedCallSettings.Builder listSinksSettings() { return listSinksSettings; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java index 0200b82f7d2a..7897bfd14a57 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java @@ -13,10 +13,11 @@ */ 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.ListMonitoredResourceDescriptorsPagedResponse; + import com.google.api.MonitoredResource; -import com.google.api.MonitoredResourceDescriptor; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.UnaryCallable; import com.google.api.gax.protobuf.PathTemplate; import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; @@ -64,8 +65,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -93,22 +94,17 @@ public class LoggingServiceV2Api implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable deleteLogCallable; - private final ApiCallable + private final UnaryCallable deleteLogCallable; + private final UnaryCallable writeLogEntriesCallable; - private final ApiCallable listLogEntriesCallable; - private final ApiCallable< - ListLogEntriesRequest, - PagedListResponse> + private final UnaryCallable listLogEntriesCallable; + private final UnaryCallable listLogEntriesPagedCallable; - private final ApiCallable< + private final UnaryCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable; - private final ApiCallable< - ListMonitoredResourceDescriptorsRequest, - PagedListResponse< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor>> + private final UnaryCallable< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsPagedCallable; private static final PathTemplate PARENT_PATH_TEMPLATE = @@ -168,19 +164,19 @@ protected LoggingServiceV2Api(LoggingServiceV2Settings settings) throws IOExcept this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.deleteLogCallable = - ApiCallable.create(settings.deleteLogSettings(), this.channel, this.executor); + UnaryCallable.create(settings.deleteLogSettings(), this.channel, this.executor); this.writeLogEntriesCallable = - ApiCallable.create(settings.writeLogEntriesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.writeLogEntriesSettings(), this.channel, this.executor); this.listLogEntriesCallable = - ApiCallable.create(settings.listLogEntriesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listLogEntriesSettings(), this.channel, this.executor); this.listLogEntriesPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listLogEntriesSettings(), this.channel, this.executor); this.listMonitoredResourceDescriptorsCallable = - ApiCallable.create( + UnaryCallable.create( settings.listMonitoredResourceDescriptorsSettings(), this.channel, this.executor); this.listMonitoredResourceDescriptorsPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listMonitoredResourceDescriptorsSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { @@ -271,7 +267,7 @@ private final void deleteLog(DeleteLogRequest request) { * } * */ - public final ApiCallable deleteLogCallable() { + public final UnaryCallable deleteLogCallable() { return deleteLogCallable; } @@ -291,19 +287,24 @@ public final ApiCallable deleteLogCallable() { * } * * - * @param logName Optional. A default log resource name for those log entries in `entries` that do - * not specify their own `logName`. Example: `"projects/my-project/logs/syslog"`. See + * @param logName Optional. A default log resource name that is assigned to all log entries in + * `entries` that do not specify a value for `log_name`. Example: + * `"projects/my-project/logs/syslog"`. See [LogEntry][google.logging.v2.LogEntry]. + * @param resource Optional. A default monitored resource object that is assigned to all log + * entries in `entries` that do not specify a value for `resource`. Example: + *

    { "type": "gce_instance", "labels": { "zone": "us-central1-a", "instance_id": + * "00000000000000000000" }} + *

    See [LogEntry][google.logging.v2.LogEntry]. + * @param labels Optional. Default labels that are added to the `labels` field of all log entries + * in `entries`. If a log entry already has a label with the same key as a label in this + * parameter, then the log entry's label is not changed. See * [LogEntry][google.logging.v2.LogEntry]. - * @param resource Optional. A default monitored resource for those log entries in `entries` that - * do not specify their own `resource`. - * @param labels Optional. User-defined `key:value` items that are added to the `labels` field of - * each log entry in `entries`, except when a log entry specifies its own `key:value` item - * with the same key. Example: `{ "size": "large", "color":"red" }` - * @param entries Required. The log entries to write. The log entries must have values for all - * required fields. - *

    To improve throughput and to avoid exceeding the quota limit for calls to - * `entries.write`, use this field to write multiple log entries at once rather than // - * calling this method for each log entry. + * @param entries Required. The log entries to write. Values supplied for the fields `log_name`, + * `resource`, and `labels` in this `entries.write` request are added to those log entries + * that do not provide their own values for the fields. + *

    To improve throughput and to avoid exceeding the [quota limit](/logging/quota-policy) + * for calls to `entries.write`, you should write multiple log entries at once rather than + * calling this method for each individual log entry. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final WriteLogEntriesResponse writeLogEntries( @@ -365,7 +366,7 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * } * */ - public final ApiCallable + public final UnaryCallable writeLogEntriesCallable() { return writeLogEntriesCallable; } @@ -388,11 +389,13 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * } * * - * @param projectIds Required. One or more project IDs or project numbers from which to retrieve - * log entries. Examples of a project ID: `"my-project-1A"`, `"1234567890"`. - * @param filter Optional. An [advanced logs filter](/logging/docs/view/advanced_filters). The - * filter is compared against all log entries in the projects specified by `projectIds`. Only - * entries that match the filter are retrieved. An empty filter matches all log entries. + * @param projectIds Deprecated. One or more project identifiers or project numbers from which to + * retrieve log entries. Examples: `"my-project-1A"`, `"1234567890"`. If present, these + * project identifiers are converted to resource format and added to the list of resources in + * `resourceNames`. Callers should use `resourceNames` rather than this parameter. + * @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. * @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 @@ -400,8 +403,8 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * timestamps are returned in order of `LogEntry.insertId`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse - listLogEntries(List projectIds, String filter, String orderBy) { + public final ListLogEntriesPagedResponse listLogEntries( + List projectIds, String filter, String orderBy) { ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() .addAllProjectIds(projectIds) @@ -433,8 +436,7 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * @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 PagedListResponse - listLogEntries(ListLogEntriesRequest request) { + public final ListLogEntriesPagedResponse listLogEntries(ListLogEntriesRequest request) { return listLogEntriesPagedCallable().call(request); } @@ -451,7 +453,7 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() * .addAllProjectIds(projectIds) * .build(); - * ListenableFuture<PagedListResponse<ListLogEntriesRequest,ListLogEntriesResponse,LogEntry>> future = loggingServiceV2Api.listLogEntriesPagedCallable().futureCall(request); + * ListenableFuture<ListLogEntriesPagedResponse> future = loggingServiceV2Api.listLogEntriesPagedCallable().futureCall(request); * // Do something * for (LogEntry element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -459,9 +461,7 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * } * */ - public final ApiCallable< - ListLogEntriesRequest, - PagedListResponse> + public final UnaryCallable listLogEntriesPagedCallable() { return listLogEntriesPagedCallable; } @@ -494,7 +494,8 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * } * */ - public final ApiCallable listLogEntriesCallable() { + public final UnaryCallable + listLogEntriesCallable() { return listLogEntriesCallable; } @@ -516,10 +517,8 @@ public final ApiCallable listLogE * @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 PagedListResponse< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> - listMonitoredResourceDescriptors(ListMonitoredResourceDescriptorsRequest request) { + public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResourceDescriptors( + ListMonitoredResourceDescriptorsRequest request) { return listMonitoredResourceDescriptorsPagedCallable().call(request); } @@ -532,7 +531,7 @@ public final ApiCallable listLogE *

    
        * try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create()) {
        *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
    -   *   ListenableFuture<PagedListResponse<ListMonitoredResourceDescriptorsRequest,ListMonitoredResourceDescriptorsResponse,MonitoredResourceDescriptor>> future = loggingServiceV2Api.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
    +   *   ListenableFuture<ListMonitoredResourceDescriptorsPagedResponse> future = loggingServiceV2Api.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
        *   // Do something
        *   for (MonitoredResourceDescriptor element : future.get().iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -540,11 +539,8 @@ public final ApiCallable listLogE
        * }
        * 
    */ - public final ApiCallable< - ListMonitoredResourceDescriptorsRequest, - PagedListResponse< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor>> + public final UnaryCallable< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsPagedCallable() { return listMonitoredResourceDescriptorsPagedCallable; } @@ -573,7 +569,7 @@ public final ApiCallable listLogE * } * */ - public final ApiCallable< + public final UnaryCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable() { return listMonitoredResourceDescriptorsCallable; 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 3db49f10b4f0..9df5a05994cd 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 @@ -13,14 +13,20 @@ */ 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.ListMonitoredResourceDescriptorsPagedResponse; + import com.google.api.MonitoredResourceDescriptor; import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -88,22 +94,15 @@ public class LoggingServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/logging.write") .build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings deleteLogSettings; private final SimpleCallSettings writeLogEntriesSettings; - private final PageStreamingCallSettings + private final PagedCallSettings< + ListLogEntriesRequest, ListLogEntriesResponse, ListLogEntriesPagedResponse> listLogEntriesSettings; - private final PageStreamingCallSettings< + private final PagedCallSettings< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings; /** Returns the object with the settings used for calls to deleteLog. */ @@ -118,15 +117,16 @@ public SimpleCallSettings deleteLogSettings() { } /** Returns the object with the settings used for calls to listLogEntries. */ - public PageStreamingCallSettings + public PagedCallSettings< + ListLogEntriesRequest, ListLogEntriesResponse, ListLogEntriesPagedResponse> listLogEntriesSettings() { return listLogEntriesSettings; } /** Returns the object with the settings used for calls to listMonitoredResourceDescriptors. */ - public PageStreamingCallSettings< + public PagedCallSettings< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings() { return listMonitoredResourceDescriptorsSettings; } @@ -177,10 +177,9 @@ private LoggingServiceV2Settings(Builder settingsBuilder) throws IOException { settingsBuilder.listMonitoredResourceDescriptorsSettings().build(); } - private static final PageStreamingDescriptor< - ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> + private static final PagedListDescriptor LIST_LOG_ENTRIES_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -213,11 +212,11 @@ public Iterable extractResources(ListLogEntriesResponse payload) { } }; - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor> LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC = - new PageStreamingDescriptor< + new PagedListDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor>() { @Override @@ -258,19 +257,54 @@ public Iterable extractResources( } }; + private static final PagedListResponseFactory< + ListLogEntriesRequest, ListLogEntriesResponse, ListLogEntriesPagedResponse> + LIST_LOG_ENTRIES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListLogEntriesRequest, ListLogEntriesResponse, ListLogEntriesPagedResponse>() { + @Override + public ListLogEntriesPagedResponse createPagedListResponse( + UnaryCallable callable, + ListLogEntriesRequest request, + CallContext context) { + return new ListLogEntriesPagedResponse( + callable, LIST_LOG_ENTRIES_PAGE_STR_DESC, request, context); + } + }; + + private static final PagedListResponseFactory< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + ListMonitoredResourceDescriptorsPagedResponse> + LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + ListMonitoredResourceDescriptorsPagedResponse>() { + @Override + public ListMonitoredResourceDescriptorsPagedResponse createPagedListResponse( + UnaryCallable< + ListMonitoredResourceDescriptorsRequest, + ListMonitoredResourceDescriptorsResponse> + callable, + ListMonitoredResourceDescriptorsRequest request, + CallContext context) { + return new ListMonitoredResourceDescriptorsPagedResponse( + callable, LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC, request, context); + } + }; + /** Builder for LoggingServiceV2Settings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder deleteLogSettings; private final SimpleCallSettings.Builder writeLogEntriesSettings; - private final PageStreamingCallSettings.Builder< - ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> + private final PagedCallSettings.Builder< + ListLogEntriesRequest, ListLogEntriesResponse, ListLogEntriesPagedResponse> listLogEntriesSettings; - private final PageStreamingCallSettings.Builder< + private final PagedCallSettings.Builder< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -315,7 +349,7 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); deleteLogSettings = SimpleCallSettings.newBuilder(LoggingServiceV2Grpc.METHOD_DELETE_LOG); @@ -323,16 +357,16 @@ private Builder() { SimpleCallSettings.newBuilder(LoggingServiceV2Grpc.METHOD_WRITE_LOG_ENTRIES); listLogEntriesSettings = - PageStreamingCallSettings.newBuilder( - LoggingServiceV2Grpc.METHOD_LIST_LOG_ENTRIES, LIST_LOG_ENTRIES_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + LoggingServiceV2Grpc.METHOD_LIST_LOG_ENTRIES, LIST_LOG_ENTRIES_PAGE_STR_FACT); listMonitoredResourceDescriptorsSettings = - PageStreamingCallSettings.newBuilder( + PagedCallSettings.newBuilder( LoggingServiceV2Grpc.METHOD_LIST_MONITORED_RESOURCE_DESCRIPTORS, - LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC); + LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, @@ -374,17 +408,24 @@ private Builder(LoggingServiceV2Settings settings) { listMonitoredResourceDescriptorsSettings = settings.listMonitoredResourceDescriptorsSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, listMonitoredResourceDescriptorsSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -430,11 +471,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } @@ -450,16 +494,16 @@ public SimpleCallSettings.Builder deleteLogSettings() { } /** Returns the builder for the settings used for calls to listLogEntries. */ - public PageStreamingCallSettings.Builder< - ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> + public PagedCallSettings.Builder< + ListLogEntriesRequest, ListLogEntriesResponse, ListLogEntriesPagedResponse> listLogEntriesSettings() { return listLogEntriesSettings; } /** Returns the builder for the settings used for calls to listMonitoredResourceDescriptors. */ - public PageStreamingCallSettings.Builder< + public PagedCallSettings.Builder< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings() { return listMonitoredResourceDescriptorsSettings; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java index e458ba1c756e..14e282373f89 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java @@ -13,8 +13,9 @@ */ package com.google.cloud.logging.spi.v2; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse; + +import com.google.api.gax.grpc.UnaryCallable; import com.google.api.gax.protobuf.PathTemplate; import com.google.logging.v2.CreateLogMetricRequest; import com.google.logging.v2.DeleteLogMetricRequest; @@ -60,8 +61,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -89,15 +90,13 @@ public class MetricsServiceV2Api implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable listLogMetricsCallable; - private final ApiCallable< - ListLogMetricsRequest, - PagedListResponse> + private final UnaryCallable listLogMetricsCallable; + private final UnaryCallable listLogMetricsPagedCallable; - private final ApiCallable getLogMetricCallable; - private final ApiCallable createLogMetricCallable; - private final ApiCallable updateLogMetricCallable; - private final ApiCallable deleteLogMetricCallable; + private final UnaryCallable getLogMetricCallable; + private final UnaryCallable createLogMetricCallable; + private final UnaryCallable updateLogMetricCallable; + private final UnaryCallable deleteLogMetricCallable; private static final PathTemplate PARENT_PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding("projects/{project}"); @@ -156,18 +155,18 @@ protected MetricsServiceV2Api(MetricsServiceV2Settings settings) throws IOExcept this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.listLogMetricsCallable = - ApiCallable.create(settings.listLogMetricsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listLogMetricsSettings(), this.channel, this.executor); this.listLogMetricsPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listLogMetricsSettings(), this.channel, this.executor); this.getLogMetricCallable = - ApiCallable.create(settings.getLogMetricSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getLogMetricSettings(), this.channel, this.executor); this.createLogMetricCallable = - ApiCallable.create(settings.createLogMetricSettings(), this.channel, this.executor); + UnaryCallable.create(settings.createLogMetricSettings(), this.channel, this.executor); this.updateLogMetricCallable = - ApiCallable.create(settings.updateLogMetricSettings(), this.channel, this.executor); + UnaryCallable.create(settings.updateLogMetricSettings(), this.channel, this.executor); this.deleteLogMetricCallable = - ApiCallable.create(settings.deleteLogMetricSettings(), this.channel, this.executor); + UnaryCallable.create(settings.deleteLogMetricSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -212,8 +211,7 @@ public final MetricsServiceV2Settings getSettings() { * `"projects/my-project-id"`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse - listLogMetrics(String parent) { + public final ListLogMetricsPagedResponse listLogMetrics(String parent) { PARENT_PATH_TEMPLATE.validate(parent, "listLogMetrics"); ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setParent(parent).build(); return listLogMetrics(request); @@ -240,8 +238,7 @@ public final MetricsServiceV2Settings getSettings() { * @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 PagedListResponse - listLogMetrics(ListLogMetricsRequest request) { + public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest request) { return listLogMetricsPagedCallable().call(request); } @@ -257,7 +254,7 @@ public final MetricsServiceV2Settings getSettings() { * ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder() * .setParent(formattedParent) * .build(); - * ListenableFuture<PagedListResponse<ListLogMetricsRequest,ListLogMetricsResponse,LogMetric>> future = metricsServiceV2Api.listLogMetricsPagedCallable().futureCall(request); + * ListenableFuture<ListLogMetricsPagedResponse> future = metricsServiceV2Api.listLogMetricsPagedCallable().futureCall(request); * // Do something * for (LogMetric element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -265,9 +262,7 @@ public final MetricsServiceV2Settings getSettings() { * } * */ - public final ApiCallable< - ListLogMetricsRequest, - PagedListResponse> + public final UnaryCallable listLogMetricsPagedCallable() { return listLogMetricsPagedCallable; } @@ -299,7 +294,8 @@ public final MetricsServiceV2Settings getSettings() { * } * */ - public final ApiCallable listLogMetricsCallable() { + public final UnaryCallable + listLogMetricsCallable() { return listLogMetricsCallable; } @@ -368,7 +364,7 @@ private final LogMetric getLogMetric(GetLogMetricRequest request) { * } * */ - public final ApiCallable getLogMetricCallable() { + public final UnaryCallable getLogMetricCallable() { return getLogMetricCallable; } @@ -444,7 +440,7 @@ public final LogMetric createLogMetric(CreateLogMetricRequest request) { * } * */ - public final ApiCallable createLogMetricCallable() { + public final UnaryCallable createLogMetricCallable() { return createLogMetricCallable; } @@ -522,7 +518,7 @@ public final LogMetric updateLogMetric(UpdateLogMetricRequest request) { * } * */ - public final ApiCallable updateLogMetricCallable() { + public final UnaryCallable updateLogMetricCallable() { return updateLogMetricCallable; } @@ -591,7 +587,7 @@ private final void deleteLogMetric(DeleteLogMetricRequest request) { * } * */ - public final ApiCallable deleteLogMetricCallable() { + public final UnaryCallable deleteLogMetricCallable() { return deleteLogMetricCallable; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java index 33302e500c2f..c7959b1f2953 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java @@ -13,13 +13,18 @@ */ package com.google.cloud.logging.spi.v2; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse; + import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -86,15 +91,8 @@ public class MetricsServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/logging.write") .build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - - private final PageStreamingCallSettings + private final PagedCallSettings< + ListLogMetricsRequest, ListLogMetricsResponse, ListLogMetricsPagedResponse> listLogMetricsSettings; private final SimpleCallSettings getLogMetricSettings; private final SimpleCallSettings createLogMetricSettings; @@ -102,7 +100,8 @@ public class MetricsServiceV2Settings extends ServiceApiSettings { private final SimpleCallSettings deleteLogMetricSettings; /** Returns the object with the settings used for calls to listLogMetrics. */ - public PageStreamingCallSettings + public PagedCallSettings< + ListLogMetricsRequest, ListLogMetricsResponse, ListLogMetricsPagedResponse> listLogMetricsSettings() { return listLogMetricsSettings; } @@ -173,10 +172,9 @@ private MetricsServiceV2Settings(Builder settingsBuilder) throws IOException { deleteLogMetricSettings = settingsBuilder.deleteLogMetricSettings().build(); } - private static final PageStreamingDescriptor< - ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> + private static final PagedListDescriptor LIST_LOG_METRICS_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -209,12 +207,27 @@ public Iterable extractResources(ListLogMetricsResponse payload) { } }; + private static final PagedListResponseFactory< + ListLogMetricsRequest, ListLogMetricsResponse, ListLogMetricsPagedResponse> + LIST_LOG_METRICS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListLogMetricsRequest, ListLogMetricsResponse, ListLogMetricsPagedResponse>() { + @Override + public ListLogMetricsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListLogMetricsRequest request, + CallContext context) { + return new ListLogMetricsPagedResponse( + callable, LIST_LOG_METRICS_PAGE_STR_DESC, request, context); + } + }; + /** Builder for MetricsServiceV2Settings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; - private final PageStreamingCallSettings.Builder< - ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> + private final PagedCallSettings.Builder< + ListLogMetricsRequest, ListLogMetricsResponse, ListLogMetricsPagedResponse> listLogMetricsSettings; private final SimpleCallSettings.Builder getLogMetricSettings; private final SimpleCallSettings.Builder @@ -255,11 +268,11 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); listLogMetricsSettings = - PageStreamingCallSettings.newBuilder( - MetricsServiceV2Grpc.METHOD_LIST_LOG_METRICS, LIST_LOG_METRICS_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + MetricsServiceV2Grpc.METHOD_LIST_LOG_METRICS, LIST_LOG_METRICS_PAGE_STR_FACT); getLogMetricSettings = SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_GET_LOG_METRIC); @@ -273,8 +286,8 @@ private Builder() { deleteLogMetricSettings = SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_DELETE_LOG_METRIC); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listLogMetricsSettings, getLogMetricSettings, createLogMetricSettings, @@ -322,8 +335,8 @@ private Builder(MetricsServiceV2Settings settings) { updateLogMetricSettings = settings.updateLogMetricSettings.toBuilder(); deleteLogMetricSettings = settings.deleteLogMetricSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listLogMetricsSettings, getLogMetricSettings, createLogMetricSettings, @@ -331,9 +344,16 @@ private Builder(MetricsServiceV2Settings settings) { deleteLogMetricSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -379,17 +399,20 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } /** Returns the builder for the settings used for calls to listLogMetrics. */ - public PageStreamingCallSettings.Builder< - ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> + public PagedCallSettings.Builder< + ListLogMetricsRequest, ListLogMetricsResponse, ListLogMetricsPagedResponse> listLogMetricsSettings() { return listLogMetricsSettings; } 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 new file mode 100644 index 000000000000..75e2e10d3584 --- /dev/null +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/PagedResponseWrappers.java @@ -0,0 +1,97 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.logging.spi.v2; + +import com.google.api.MonitoredResourceDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseImpl; +import com.google.api.gax.grpc.UnaryCallable; +import com.google.logging.v2.ListLogEntriesRequest; +import com.google.logging.v2.ListLogEntriesResponse; +import com.google.logging.v2.ListLogMetricsRequest; +import com.google.logging.v2.ListLogMetricsResponse; +import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; +import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; +import com.google.logging.v2.ListSinksRequest; +import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.LogEntry; +import com.google.logging.v2.LogMetric; +import com.google.logging.v2.LogSink; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers { + + public static class ListLogEntriesPagedResponse + extends PagedListResponseImpl { + + public ListLogEntriesPagedResponse( + UnaryCallable callable, + PagedListDescriptor pageDescriptor, + ListLogEntriesRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListMonitoredResourceDescriptorsPagedResponse + extends PagedListResponseImpl< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> { + + public ListMonitoredResourceDescriptorsPagedResponse( + UnaryCallable< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> + callable, + PagedListDescriptor< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + pageDescriptor, + ListMonitoredResourceDescriptorsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListSinksPagedResponse + extends PagedListResponseImpl { + + public ListSinksPagedResponse( + UnaryCallable callable, + PagedListDescriptor pageDescriptor, + ListSinksRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListLogMetricsPagedResponse + extends PagedListResponseImpl { + + public ListLogMetricsPagedResponse( + UnaryCallable callable, + PagedListDescriptor + pageDescriptor, + ListLogMetricsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } +} diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java index c579f3ff26d6..26d0600a08b3 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java @@ -15,7 +15,7 @@ /** * A client to Stackdriver Logging API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    =================== LoggingServiceV2Api =================== * diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Test.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Test.java index 4ea8363a0dd8..32433dc85e51 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Test.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Test.java @@ -14,7 +14,8 @@ package com.google.cloud.logging.spi.v2; -import com.google.api.gax.core.PagedListResponse; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse; + import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -93,8 +94,7 @@ public void listSinksTest() { String formattedParent = ConfigServiceV2Api.formatParentName("[PROJECT]"); - PagedListResponse pagedListResponse = - api.listSinks(formattedParent); + ListSinksPagedResponse pagedListResponse = api.listSinks(formattedParent); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -113,8 +113,14 @@ public void getSinkTest() { String name = "name3373707"; String destination = "destination-1429847026"; String filter = "filter-1274492040"; + String writerIdentity = "writerIdentity775638794"; LogSink expectedResponse = - LogSink.newBuilder().setName(name).setDestination(destination).setFilter(filter).build(); + LogSink.newBuilder() + .setName(name) + .setDestination(destination) + .setFilter(filter) + .setWriterIdentity(writerIdentity) + .build(); List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockConfigServiceV2.setResponses(expectedResponses); @@ -137,8 +143,14 @@ public void createSinkTest() { String name = "name3373707"; String destination = "destination-1429847026"; String filter = "filter-1274492040"; + String writerIdentity = "writerIdentity775638794"; LogSink expectedResponse = - LogSink.newBuilder().setName(name).setDestination(destination).setFilter(filter).build(); + LogSink.newBuilder() + .setName(name) + .setDestination(destination) + .setFilter(filter) + .setWriterIdentity(writerIdentity) + .build(); List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockConfigServiceV2.setResponses(expectedResponses); @@ -163,8 +175,14 @@ public void updateSinkTest() { String name = "name3373707"; String destination = "destination-1429847026"; String filter = "filter-1274492040"; + String writerIdentity = "writerIdentity775638794"; LogSink expectedResponse = - LogSink.newBuilder().setName(name).setDestination(destination).setFilter(filter).build(); + LogSink.newBuilder() + .setName(name) + .setDestination(destination) + .setFilter(filter) + .setWriterIdentity(writerIdentity) + .build(); List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockConfigServiceV2.setResponses(expectedResponses); 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 24e7dcd5d64e..e4a44b72031e 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 @@ -14,8 +14,9 @@ package com.google.cloud.logging.spi.v2; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogEntriesPagedResponse; + import com.google.api.MonitoredResource; -import com.google.api.gax.core.PagedListResponse; import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -146,8 +147,7 @@ public void listLogEntriesTest() { String filter = "filter-1274492040"; String orderBy = "orderBy1234304744"; - PagedListResponse pagedListResponse = - api.listLogEntries(projectIds, filter, orderBy); + ListLogEntriesPagedResponse pagedListResponse = api.listLogEntries(projectIds, filter, orderBy); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Test.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Test.java index a497c5570804..54c76528be31 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Test.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Test.java @@ -14,7 +14,8 @@ package com.google.cloud.logging.spi.v2; -import com.google.api.gax.core.PagedListResponse; +import static com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse; + import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -96,8 +97,7 @@ public void listLogMetricsTest() { String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]"); - PagedListResponse pagedListResponse = - api.listLogMetrics(formattedParent); + ListLogMetricsPagedResponse pagedListResponse = api.listLogMetrics(formattedParent); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceApi.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceApi.java deleted file mode 100644 index a81142c23194..000000000000 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceApi.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.cloud.monitoring.spi.v3; - -import com.google.api.MonitoredResource; -import com.google.api.gax.grpc.ApiCallable; -import com.google.api.gax.protobuf.PathTemplate; -import com.google.monitoring.v3.CollectdPayload; -import com.google.monitoring.v3.CreateCollectdTimeSeriesRequest; -import com.google.protobuf.Empty; -import io.grpc.ManagedChannel; -import java.io.Closeable; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ScheduledExecutorService; - -// AUTO-GENERATED DOCUMENTATION AND SERVICE -/** - * Service Description: The AgentTranslation API allows `collectd`-based agents to write time series - * data to Cloud Monitoring. See [google.monitoring.v3.MetricService.CreateTimeSeries] instead. - * - *

    This class provides the ability to make remote calls to the backing service through method - * calls that map to API methods. Sample code to get started: - * - *

    - * 
    - * try (AgentTranslationServiceApi agentTranslationServiceApi = AgentTranslationServiceApi.create()) {
    - *   String formattedName = AgentTranslationServiceApi.formatProjectName("[PROJECT]");
    - *   MonitoredResource resource = MonitoredResource.newBuilder().build();
    - *   String collectdVersion = "";
    - *   List<CollectdPayload> collectdPayloads = new ArrayList<>();
    - *   agentTranslationServiceApi.createCollectdTimeSeries(formattedName, resource, collectdVersion, collectdPayloads);
    - * }
    - * 
    - * 
    - * - *

    Note: close() needs to be called on the agentTranslationServiceApi object to clean up - * resources such as threads. In the example above, try-with-resources is used, which automatically - * calls close(). - * - *

    The surface of this class includes several types of Java methods for each of the API's - * methods: - * - *

      - *
    1. A "flattened" method. With this type of method, the fields of the request type have been - * converted into function parameters. It may be the case that not all fields are available as - * parameters, and not every API method will have a flattened method entry point. - *
    2. A "request object" method. This type of method only takes one parameter, a request object, - * which must be constructed before the call. Not every API method will have a request object - * method. - *
    3. A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. - *
    - * - *

    See the individual methods for example code. - * - *

    Many parameters require resource names to be formatted in a particular way. To assist with - * these names, this class includes a format method for each type of name, and additionally a parse - * method to extract the individual identifiers contained within names that are returned. - * - *

    This class can be customized by passing in a custom instance of - * AgentTranslationServiceSettings to create(). For example: - * - *

    - * 
    - * AgentTranslationServiceSettings agentTranslationServiceSettings = AgentTranslationServiceSettings.defaultBuilder()
    - *     .provideChannelWith(myCredentials)
    - *     .build();
    - * AgentTranslationServiceApi agentTranslationServiceApi = AgentTranslationServiceApi.create(agentTranslationServiceSettings);
    - * 
    - * 
    - */ -@javax.annotation.Generated("by GAPIC") -public class AgentTranslationServiceApi implements AutoCloseable { - private final AgentTranslationServiceSettings settings; - private final ManagedChannel channel; - private final ScheduledExecutorService executor; - private final List closeables = new ArrayList<>(); - - private final ApiCallable - createCollectdTimeSeriesCallable; - - 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 AgentTranslationServiceApi with default settings. */ - public static final AgentTranslationServiceApi create() throws IOException { - return create(AgentTranslationServiceSettings.defaultBuilder().build()); - } - - /** - * Constructs an instance of AgentTranslationServiceApi, using the given settings. The channels - * are created based on the settings passed in, or defaults for any settings that are not set. - */ - public static final AgentTranslationServiceApi create(AgentTranslationServiceSettings settings) - throws IOException { - return new AgentTranslationServiceApi(settings); - } - - /** - * Constructs an instance of AgentTranslationServiceApi, using the given settings. This is - * protected so that it easy to make a subclass, but otherwise, the static factory methods should - * be preferred. - */ - protected AgentTranslationServiceApi(AgentTranslationServiceSettings settings) - throws IOException { - this.settings = settings; - this.executor = settings.getExecutorProvider().getOrBuildExecutor(); - this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); - - this.createCollectdTimeSeriesCallable = - ApiCallable.create( - settings.createCollectdTimeSeriesSettings(), this.channel, this.executor); - - if (settings.getChannelProvider().shouldAutoClose()) { - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); - } - if (settings.getExecutorProvider().shouldAutoClose()) { - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - executor.shutdown(); - } - }); - } - } - - public final AgentTranslationServiceSettings getSettings() { - return settings; - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * **Stackdriver Monitoring Agent only:** Creates a new time series. - * - *

    <aside class="caution">This method is only for use by the Google Monitoring Agent. Use - * [projects.timeSeries.create][google.monitoring.v3.MetricService.CreateTimeSeries] - * instead.</aside> - * - *

    Sample code: - * - *

    
    -   * try (AgentTranslationServiceApi agentTranslationServiceApi = AgentTranslationServiceApi.create()) {
    -   *   String formattedName = AgentTranslationServiceApi.formatProjectName("[PROJECT]");
    -   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
    -   *   String collectdVersion = "";
    -   *   List<CollectdPayload> collectdPayloads = new ArrayList<>();
    -   *   agentTranslationServiceApi.createCollectdTimeSeries(formattedName, resource, collectdVersion, collectdPayloads);
    -   * }
    -   * 
    - * - * @param name The project in which to create the time series. The format is - * `"projects/PROJECT_ID_OR_NUMBER"`. - * @param resource The monitored resource associated with the time series. - * @param collectdVersion The version of `collectd` that collected the data. Example: - * `"5.3.0-192.el6"`. - * @param collectdPayloads The `collectd` payloads representing the time series data. You must not - * include more than a single point for each time series, so no two payloads can have the same - * values for all of the fields `plugin`, `plugin_instance`, `type`, and `type_instance`. - * @throws com.google.api.gax.grpc.ApiException if the remote call fails - */ - public final void createCollectdTimeSeries( - String name, - MonitoredResource resource, - String collectdVersion, - List collectdPayloads) { - PROJECT_PATH_TEMPLATE.validate(name, "createCollectdTimeSeries"); - CreateCollectdTimeSeriesRequest request = - CreateCollectdTimeSeriesRequest.newBuilder() - .setName(name) - .setResource(resource) - .setCollectdVersion(collectdVersion) - .addAllCollectdPayloads(collectdPayloads) - .build(); - createCollectdTimeSeries(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * **Stackdriver Monitoring Agent only:** Creates a new time series. - * - *

    <aside class="caution">This method is only for use by the Google Monitoring Agent. Use - * [projects.timeSeries.create][google.monitoring.v3.MetricService.CreateTimeSeries] - * instead.</aside> - * - *

    Sample code: - * - *

    
    -   * try (AgentTranslationServiceApi agentTranslationServiceApi = AgentTranslationServiceApi.create()) {
    -   *   String formattedName = AgentTranslationServiceApi.formatProjectName("[PROJECT]");
    -   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
    -   *   String collectdVersion = "";
    -   *   List<CollectdPayload> collectdPayloads = new ArrayList<>();
    -   *   CreateCollectdTimeSeriesRequest request = CreateCollectdTimeSeriesRequest.newBuilder()
    -   *     .setName(formattedName)
    -   *     .setResource(resource)
    -   *     .setCollectdVersion(collectdVersion)
    -   *     .addAllCollectdPayloads(collectdPayloads)
    -   *     .build();
    -   *   agentTranslationServiceApi.createCollectdTimeSeries(request);
    -   * }
    -   * 
    - * - * @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 void createCollectdTimeSeries(CreateCollectdTimeSeriesRequest request) { - createCollectdTimeSeriesCallable().call(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * **Stackdriver Monitoring Agent only:** Creates a new time series. - * - *

    <aside class="caution">This method is only for use by the Google Monitoring Agent. Use - * [projects.timeSeries.create][google.monitoring.v3.MetricService.CreateTimeSeries] - * instead.</aside> - * - *

    Sample code: - * - *

    
    -   * try (AgentTranslationServiceApi agentTranslationServiceApi = AgentTranslationServiceApi.create()) {
    -   *   String formattedName = AgentTranslationServiceApi.formatProjectName("[PROJECT]");
    -   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
    -   *   String collectdVersion = "";
    -   *   List<CollectdPayload> collectdPayloads = new ArrayList<>();
    -   *   CreateCollectdTimeSeriesRequest request = CreateCollectdTimeSeriesRequest.newBuilder()
    -   *     .setName(formattedName)
    -   *     .setResource(resource)
    -   *     .setCollectdVersion(collectdVersion)
    -   *     .addAllCollectdPayloads(collectdPayloads)
    -   *     .build();
    -   *   ListenableFuture<Void> future = agentTranslationServiceApi.createCollectdTimeSeriesCallable().futureCall(request);
    -   *   // Do something
    -   *   future.get();
    -   * }
    -   * 
    - */ - public final ApiCallable - createCollectdTimeSeriesCallable() { - return createCollectdTimeSeriesCallable; - } - - /** - * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately - * cancelled. - */ - @Override - public final void close() throws Exception { - for (AutoCloseable closeable : closeables) { - closeable.close(); - } - } -} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceSettings.java deleted file mode 100644 index 72bbff0eebbb..000000000000 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceSettings.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.cloud.monitoring.spi.v3; - -import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ServiceApiSettings; -import com.google.api.gax.grpc.SimpleCallSettings; -import com.google.auth.Credentials; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.monitoring.v3.AgentTranslationServiceGrpc; -import com.google.monitoring.v3.CreateCollectdTimeSeriesRequest; -import com.google.protobuf.Empty; -import io.grpc.ManagedChannel; -import io.grpc.Status; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.ScheduledExecutorService; -import org.joda.time.Duration; - -// AUTO-GENERATED DOCUMENTATION AND CLASS -/** - * Settings class to configure an instance of {@link AgentTranslationServiceApi}. - * - *

    The default instance has everything set to sensible defaults: - * - *

      - *
    • The default service address (monitoring.googleapis.com) and default port (443) are used. - *
    • Credentials are acquired automatically through Application Default Credentials. - *
    • Retries are configured for idempotent methods but not for non-idempotent methods. - *
    - * - *

    The builder of this class is recursive, so contained classes are themselves builders. When - * build() is called, the tree of builders is called to create the complete settings object. For - * example, to set the total timeout of createCollectdTimeSeries to 30 seconds: - * - *

    - * 
    - * AgentTranslationServiceSettings.Builder agentTranslationServiceSettingsBuilder =
    - *     AgentTranslationServiceSettings.defaultBuilder();
    - * agentTranslationServiceSettingsBuilder.createCollectdTimeSeriesSettings().getRetrySettingsBuilder()
    - *     .setTotalTimeout(Duration.standardSeconds(30));
    - * AgentTranslationServiceSettings agentTranslationServiceSettings = agentTranslationServiceSettingsBuilder.build();
    - * 
    - * 
    - */ -@javax.annotation.Generated("by GAPIC") -public class AgentTranslationServiceSettings extends ServiceApiSettings { - /** The default address of the service. */ - private static final String DEFAULT_SERVICE_ADDRESS = "monitoring.googleapis.com"; - - /** The default port of the service. */ - private static final int DEFAULT_SERVICE_PORT = 443; - - /** The default scopes of the service. */ - private static final ImmutableList DEFAULT_SERVICE_SCOPES = - ImmutableList.builder().build(); - - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - - private final SimpleCallSettings - createCollectdTimeSeriesSettings; - - /** Returns the object with the settings used for calls to createCollectdTimeSeries. */ - public SimpleCallSettings - createCollectdTimeSeriesSettings() { - return createCollectdTimeSeriesSettings; - } - - /** Returns the default service address. */ - public static String getDefaultServiceAddress() { - return DEFAULT_SERVICE_ADDRESS; - } - - /** Returns the default service port. */ - public static int getDefaultServicePort() { - return DEFAULT_SERVICE_PORT; - } - - /** Returns the default service scopes. */ - public static ImmutableList getDefaultServiceScopes() { - return DEFAULT_SERVICE_SCOPES; - } - - /** Returns a builder for this class with recommended defaults. */ - public static Builder defaultBuilder() { - return Builder.createDefault(); - } - - /** Returns a new builder for this class. */ - public static Builder newBuilder() { - return new Builder(); - } - - /** Returns a builder containing all the values of this settings class. */ - public Builder toBuilder() { - return new Builder(this); - } - - private AgentTranslationServiceSettings(Builder settingsBuilder) throws IOException { - super( - settingsBuilder.getChannelProvider(), - settingsBuilder.getExecutorProvider(), - settingsBuilder.getGeneratorName(), - settingsBuilder.getGeneratorVersion(), - settingsBuilder.getClientLibName(), - settingsBuilder.getClientLibVersion()); - - createCollectdTimeSeriesSettings = settingsBuilder.createCollectdTimeSeriesSettings().build(); - } - - /** Builder for AgentTranslationServiceSettings. */ - public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; - - private final SimpleCallSettings.Builder - createCollectdTimeSeriesSettings; - - private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; - - static { - ImmutableMap.Builder> definitions = ImmutableMap.builder(); - definitions.put( - "idempotent", - Sets.immutableEnumSet( - Lists.newArrayList( - Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE))); - definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.newArrayList())); - RETRYABLE_CODE_DEFINITIONS = definitions.build(); - } - - private static final ImmutableMap RETRY_PARAM_DEFINITIONS; - - static { - ImmutableMap.Builder definitions = ImmutableMap.builder(); - RetrySettings.Builder settingsBuilder = null; - settingsBuilder = - RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.millis(100L)) - .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.millis(60000L)) - .setInitialRpcTimeout(Duration.millis(20000L)) - .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.millis(20000L)) - .setTotalTimeout(Duration.millis(600000L)); - definitions.put("default", settingsBuilder); - RETRY_PARAM_DEFINITIONS = definitions.build(); - } - - private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); - - createCollectdTimeSeriesSettings = - SimpleCallSettings.newBuilder( - AgentTranslationServiceGrpc.METHOD_CREATE_COLLECTD_TIME_SERIES); - - methodSettingsBuilders = - ImmutableList.of(createCollectdTimeSeriesSettings); - } - - private static Builder createDefault() { - Builder builder = new Builder(); - - builder - .createCollectdTimeSeriesSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) - .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); - - return builder; - } - - private Builder(AgentTranslationServiceSettings settings) { - super(settings); - - createCollectdTimeSeriesSettings = settings.createCollectdTimeSeriesSettings.toBuilder(); - - methodSettingsBuilders = - ImmutableList.of(createCollectdTimeSeriesSettings); - } - - @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; - } - - @Override - public Builder provideExecutorWith(ScheduledExecutorService executor, boolean shouldAutoClose) { - super.provideExecutorWith(executor, shouldAutoClose); - return this; - } - - @Override - public Builder provideChannelWith(ManagedChannel channel, boolean shouldAutoClose) { - super.provideChannelWith(channel, shouldAutoClose); - return this; - } - - @Override - public Builder provideChannelWith(ConnectionSettings settings) { - super.provideChannelWith(settings); - return this; - } - - @Override - public Builder provideChannelWith(Credentials credentials) { - super.provideChannelWith(credentials); - return this; - } - - @Override - public Builder provideChannelWith(List scopes) { - super.provideChannelWith(scopes); - return this; - } - - @Override - public Builder setGeneratorHeader(String name, String version) { - super.setGeneratorHeader(name, version); - return this; - } - - @Override - public Builder setClientLibHeader(String name, String version) { - super.setClientLibHeader(name, version); - return this; - } - - /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. - */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); - return this; - } - - /** Returns the builder for the settings used for calls to createCollectdTimeSeries. */ - public SimpleCallSettings.Builder - createCollectdTimeSeriesSettings() { - return createCollectdTimeSeriesSettings; - } - - @Override - public AgentTranslationServiceSettings build() throws IOException { - return new AgentTranslationServiceSettings(this); - } - } -} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java index 850406c119de..1f9cb8ec9307 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java @@ -13,9 +13,10 @@ */ package com.google.cloud.monitoring.spi.v3; -import com.google.api.MonitoredResource; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupMembersPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupsPagedResponse; + +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; @@ -25,7 +26,6 @@ import com.google.monitoring.v3.ListGroupMembersResponse; import com.google.monitoring.v3.ListGroupsRequest; import com.google.monitoring.v3.ListGroupsResponse; -import com.google.monitoring.v3.TimeInterval; import com.google.monitoring.v3.UpdateGroupRequest; import com.google.protobuf.Empty; import io.grpc.ManagedChannel; @@ -72,8 +72,8 @@ *
  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -101,19 +101,15 @@ public class GroupServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable listGroupsCallable; - private final ApiCallable< - ListGroupsRequest, PagedListResponse> - listGroupsPagedCallable; - private final ApiCallable getGroupCallable; - private final ApiCallable createGroupCallable; - private final ApiCallable updateGroupCallable; - private final ApiCallable deleteGroupCallable; - private final ApiCallable + private final UnaryCallable listGroupsCallable; + private final UnaryCallable listGroupsPagedCallable; + private final UnaryCallable getGroupCallable; + private final UnaryCallable createGroupCallable; + private final UnaryCallable updateGroupCallable; + private final UnaryCallable deleteGroupCallable; + private final UnaryCallable listGroupMembersCallable; - private final ApiCallable< - ListGroupMembersRequest, - PagedListResponse> + private final UnaryCallable listGroupMembersPagedCallable; private static final PathTemplate PROJECT_PATH_TEMPLATE = @@ -172,21 +168,22 @@ protected GroupServiceApi(GroupServiceSettings settings) throws IOException { this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.listGroupsCallable = - ApiCallable.create(settings.listGroupsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listGroupsSettings(), this.channel, this.executor); this.listGroupsPagedCallable = - ApiCallable.createPagedVariant(settings.listGroupsSettings(), this.channel, this.executor); + UnaryCallable.createPagedVariant( + settings.listGroupsSettings(), this.channel, this.executor); this.getGroupCallable = - ApiCallable.create(settings.getGroupSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getGroupSettings(), this.channel, this.executor); this.createGroupCallable = - ApiCallable.create(settings.createGroupSettings(), this.channel, this.executor); + UnaryCallable.create(settings.createGroupSettings(), this.channel, this.executor); this.updateGroupCallable = - ApiCallable.create(settings.updateGroupSettings(), this.channel, this.executor); + UnaryCallable.create(settings.updateGroupSettings(), this.channel, this.executor); this.deleteGroupCallable = - ApiCallable.create(settings.deleteGroupSettings(), this.channel, this.executor); + UnaryCallable.create(settings.deleteGroupSettings(), this.channel, this.executor); this.listGroupMembersCallable = - ApiCallable.create(settings.listGroupMembersSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listGroupMembersSettings(), this.channel, this.executor); this.listGroupMembersPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listGroupMembersSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { @@ -215,7 +212,7 @@ public final GroupServiceSettings getSettings() { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the existing groups. The project ID in the URL path must refer to a Stackdriver account. + * Lists the existing groups. * *

    Sample code: * @@ -234,14 +231,13 @@ public final GroupServiceSettings getSettings() { * @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 PagedListResponse listGroups( - ListGroupsRequest request) { + public final ListGroupsPagedResponse listGroups(ListGroupsRequest request) { return listGroupsPagedCallable().call(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the existing groups. The project ID in the URL path must refer to a Stackdriver account. + * Lists the existing groups. * *

    Sample code: * @@ -251,7 +247,7 @@ public final PagedListResponse lis * ListGroupsRequest request = ListGroupsRequest.newBuilder() * .setName(formattedName) * .build(); - * ListenableFuture<PagedListResponse<ListGroupsRequest,ListGroupsResponse,Group>> future = groupServiceApi.listGroupsPagedCallable().futureCall(request); + * ListenableFuture<ListGroupsPagedResponse> future = groupServiceApi.listGroupsPagedCallable().futureCall(request); * // Do something * for (Group element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -259,15 +255,13 @@ public final PagedListResponse lis * } * */ - public final ApiCallable< - ListGroupsRequest, PagedListResponse> - listGroupsPagedCallable() { + public final UnaryCallable listGroupsPagedCallable() { return listGroupsPagedCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the existing groups. The project ID in the URL path must refer to a Stackdriver account. + * Lists the existing groups. * *

    Sample code: * @@ -292,13 +286,13 @@ public final PagedListResponse lis * } * */ - public final ApiCallable listGroupsCallable() { + public final UnaryCallable listGroupsCallable() { return listGroupsCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets a single group. The project ID in the URL path must refer to a Stackdriver account. + * Gets a single group. * *

    Sample code: * @@ -321,7 +315,7 @@ public final Group getGroup(String name) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets a single group. The project ID in the URL path must refer to a Stackdriver account. + * Gets a single group. * *

    Sample code: * @@ -344,7 +338,7 @@ private final Group getGroup(GetGroupRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets a single group. The project ID in the URL path must refer to a Stackdriver account. + * Gets a single group. * *

    Sample code: * @@ -360,13 +354,13 @@ private final Group getGroup(GetGroupRequest request) { * } * */ - public final ApiCallable getGroupCallable() { + public final UnaryCallable getGroupCallable() { return getGroupCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates a new group. The project ID in the URL path must refer to a Stackdriver account. + * Creates a new group. * *

    Sample code: * @@ -374,8 +368,7 @@ public final ApiCallable getGroupCallable() { * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) { * String formattedName = GroupServiceApi.formatProjectName("[PROJECT]"); * Group group = Group.newBuilder().build(); - * boolean validateOnly = false; - * Group response = groupServiceApi.createGroup(formattedName, group, validateOnly); + * Group response = groupServiceApi.createGroup(formattedName, group); * } * * @@ -383,23 +376,18 @@ public final ApiCallable getGroupCallable() { * `"projects/{project_id_or_number}"`. * @param group A group definition. It is an error to define the `name` field because the system * assigns the name. - * @param validateOnly If true, validate this request but do not create the group. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Group createGroup(String name, Group group, boolean validateOnly) { + public final Group createGroup(String name, Group group) { PROJECT_PATH_TEMPLATE.validate(name, "createGroup"); CreateGroupRequest request = - CreateGroupRequest.newBuilder() - .setName(name) - .setGroup(group) - .setValidateOnly(validateOnly) - .build(); + CreateGroupRequest.newBuilder().setName(name).setGroup(group).build(); return createGroup(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates a new group. The project ID in the URL path must refer to a Stackdriver account. + * Creates a new group. * *

    Sample code: * @@ -407,11 +395,9 @@ public final Group createGroup(String name, Group group, boolean validateOnly) { * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) { * String formattedName = GroupServiceApi.formatProjectName("[PROJECT]"); * Group group = Group.newBuilder().build(); - * boolean validateOnly = false; * CreateGroupRequest request = CreateGroupRequest.newBuilder() * .setName(formattedName) * .setGroup(group) - * .setValidateOnly(validateOnly) * .build(); * Group response = groupServiceApi.createGroup(request); * } @@ -426,7 +412,7 @@ public final Group createGroup(CreateGroupRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Creates a new group. The project ID in the URL path must refer to a Stackdriver account. + * Creates a new group. * *

    Sample code: * @@ -434,11 +420,9 @@ public final Group createGroup(CreateGroupRequest request) { * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) { * String formattedName = GroupServiceApi.formatProjectName("[PROJECT]"); * Group group = Group.newBuilder().build(); - * boolean validateOnly = false; * CreateGroupRequest request = CreateGroupRequest.newBuilder() * .setName(formattedName) * .setGroup(group) - * .setValidateOnly(validateOnly) * .build(); * ListenableFuture<Group> future = groupServiceApi.createGroupCallable().futureCall(request); * // Do something @@ -446,50 +430,43 @@ public final Group createGroup(CreateGroupRequest request) { * } * */ - public final ApiCallable createGroupCallable() { + public final UnaryCallable createGroupCallable() { return createGroupCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Updates an existing group. You can change any group attributes except `name`. The project ID in - * the URL path must refer to a Stackdriver account. + * Updates an existing group. You can change any group attributes except `name`. * *

    Sample code: * *

    
        * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) {
        *   Group group = Group.newBuilder().build();
    -   *   boolean validateOnly = false;
    -   *   Group response = groupServiceApi.updateGroup(group, validateOnly);
    +   *   Group response = groupServiceApi.updateGroup(group);
        * }
        * 
    * * @param group The new definition of the group. All fields of the existing group, excepting * `name`, are replaced with the corresponding fields of this group. - * @param validateOnly If true, validate this request but do not update the existing group. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Group updateGroup(Group group, boolean validateOnly) { - UpdateGroupRequest request = - UpdateGroupRequest.newBuilder().setGroup(group).setValidateOnly(validateOnly).build(); + public final Group updateGroup(Group group) { + UpdateGroupRequest request = UpdateGroupRequest.newBuilder().setGroup(group).build(); return updateGroup(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Updates an existing group. You can change any group attributes except `name`. The project ID in - * the URL path must refer to a Stackdriver account. + * Updates an existing group. You can change any group attributes except `name`. * *

    Sample code: * *

    
        * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) {
        *   Group group = Group.newBuilder().build();
    -   *   boolean validateOnly = false;
        *   UpdateGroupRequest request = UpdateGroupRequest.newBuilder()
        *     .setGroup(group)
    -   *     .setValidateOnly(validateOnly)
        *     .build();
        *   Group response = groupServiceApi.updateGroup(request);
        * }
    @@ -504,18 +481,15 @@ public final Group updateGroup(UpdateGroupRequest request) {
     
       // AUTO-GENERATED DOCUMENTATION AND METHOD
       /**
    -   * Updates an existing group. You can change any group attributes except `name`. The project ID in
    -   * the URL path must refer to a Stackdriver account.
    +   * Updates an existing group. You can change any group attributes except `name`.
        *
        * 

    Sample code: * *

    
        * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) {
        *   Group group = Group.newBuilder().build();
    -   *   boolean validateOnly = false;
        *   UpdateGroupRequest request = UpdateGroupRequest.newBuilder()
        *     .setGroup(group)
    -   *     .setValidateOnly(validateOnly)
        *     .build();
        *   ListenableFuture<Group> future = groupServiceApi.updateGroupCallable().futureCall(request);
        *   // Do something
    @@ -523,13 +497,13 @@ public final Group updateGroup(UpdateGroupRequest request) {
        * }
        * 
    */ - public final ApiCallable updateGroupCallable() { + public final UnaryCallable updateGroupCallable() { return updateGroupCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes an existing group. The project ID in the URL path must refer to a Stackdriver account. + * Deletes an existing group. * *

    Sample code: * @@ -552,7 +526,7 @@ public final void deleteGroup(String name) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes an existing group. The project ID in the URL path must refer to a Stackdriver account. + * Deletes an existing group. * *

    Sample code: * @@ -575,7 +549,7 @@ private final void deleteGroup(DeleteGroupRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes an existing group. The project ID in the URL path must refer to a Stackdriver account. + * Deletes an existing group. * *

    Sample code: * @@ -591,23 +565,20 @@ private final void deleteGroup(DeleteGroupRequest request) { * } *

    */ - public final ApiCallable deleteGroupCallable() { + public final UnaryCallable deleteGroupCallable() { return deleteGroupCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the monitored resources that are members of a group. The project ID in the URL path must - * refer to a Stackdriver account. + * Lists the monitored resources that are members of a group. * *

    Sample code: * *

    
        * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) {
        *   String formattedName = GroupServiceApi.formatGroupName("[PROJECT]", "[GROUP]");
    -   *   String filter = "";
    -   *   TimeInterval interval = TimeInterval.newBuilder().build();
    -   *   for (MonitoredResource element : groupServiceApi.listGroupMembers(formattedName, filter, interval).iterateAllElements()) {
    +   *   for (MonitoredResource element : groupServiceApi.listGroupMembers(formattedName).iterateAllElements()) {
        *     // doThingsWith(element);
        *   }
        * }
    @@ -615,45 +586,25 @@ public final ApiCallable deleteGroupCallable() {
        *
        * @param name The group whose members are listed. The format is
        *     `"projects/{project_id_or_number}/groups/{group_id}"`.
    -   * @param filter An optional [list filter](/monitoring/api/learn_more#filtering) describing the
    -   *     members to be returned. The filter may reference the type, labels, and metadata of
    -   *     monitored resources that comprise the group. For example, to return only resources
    -   *     representing Compute Engine VM instances, use this filter:
    -   *     

    resource.type = "gce_instance" - * @param interval An optional time interval for which results should be returned. Only members - * that were part of the group during the specified interval are included in the response. If - * no interval is provided then the group membership over the last minute is returned. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse< - ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> - listGroupMembers(String name, String filter, TimeInterval interval) { + public final ListGroupMembersPagedResponse listGroupMembers(String name) { GROUP_PATH_TEMPLATE.validate(name, "listGroupMembers"); - ListGroupMembersRequest request = - ListGroupMembersRequest.newBuilder() - .setName(name) - .setFilter(filter) - .setInterval(interval) - .build(); + ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder().setName(name).build(); return listGroupMembers(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the monitored resources that are members of a group. The project ID in the URL path must - * refer to a Stackdriver account. + * Lists the monitored resources that are members of a group. * *

    Sample code: * *

    
        * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) {
        *   String formattedName = GroupServiceApi.formatGroupName("[PROJECT]", "[GROUP]");
    -   *   String filter = "";
    -   *   TimeInterval interval = TimeInterval.newBuilder().build();
        *   ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
    -   *     .setInterval(interval)
        *     .build();
        *   for (MonitoredResource element : groupServiceApi.listGroupMembers(request).iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -664,30 +615,23 @@ public final ApiCallable deleteGroupCallable() {
        * @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 PagedListResponse<
    -          ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource>
    -      listGroupMembers(ListGroupMembersRequest request) {
    +  public final ListGroupMembersPagedResponse listGroupMembers(ListGroupMembersRequest request) {
         return listGroupMembersPagedCallable().call(request);
       }
     
       // AUTO-GENERATED DOCUMENTATION AND METHOD
       /**
    -   * Lists the monitored resources that are members of a group. The project ID in the URL path must
    -   * refer to a Stackdriver account.
    +   * Lists the monitored resources that are members of a group.
        *
        * 

    Sample code: * *

    
        * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) {
        *   String formattedName = GroupServiceApi.formatGroupName("[PROJECT]", "[GROUP]");
    -   *   String filter = "";
    -   *   TimeInterval interval = TimeInterval.newBuilder().build();
        *   ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
    -   *     .setInterval(interval)
        *     .build();
    -   *   ListenableFuture<PagedListResponse<ListGroupMembersRequest,ListGroupMembersResponse,MonitoredResource>> future = groupServiceApi.listGroupMembersPagedCallable().futureCall(request);
    +   *   ListenableFuture<ListGroupMembersPagedResponse> future = groupServiceApi.listGroupMembersPagedCallable().futureCall(request);
        *   // Do something
        *   for (MonitoredResource element : future.get().iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -695,29 +639,22 @@ public final ApiCallable deleteGroupCallable() {
        * }
        * 
    */ - public final ApiCallable< - ListGroupMembersRequest, - PagedListResponse> + public final UnaryCallable listGroupMembersPagedCallable() { return listGroupMembersPagedCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Lists the monitored resources that are members of a group. The project ID in the URL path must - * refer to a Stackdriver account. + * Lists the monitored resources that are members of a group. * *

    Sample code: * *

    
        * try (GroupServiceApi groupServiceApi = GroupServiceApi.create()) {
        *   String formattedName = GroupServiceApi.formatGroupName("[PROJECT]", "[GROUP]");
    -   *   String filter = "";
    -   *   TimeInterval interval = TimeInterval.newBuilder().build();
        *   ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
    -   *     .setInterval(interval)
        *     .build();
        *   while (true) {
        *     ListGroupMembersResponse response = groupServiceApi.listGroupMembersCallable().call(request);
    @@ -734,7 +671,7 @@ public final ApiCallable deleteGroupCallable() {
        * }
        * 
    */ - public final ApiCallable + public final UnaryCallable listGroupMembersCallable() { return listGroupMembersCallable; } diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java index a5e1f1d06d73..28053d5a78fb 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java @@ -13,14 +13,20 @@ */ package com.google.cloud.monitoring.spi.v3; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupMembersPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupsPagedResponse; + import com.google.api.MonitoredResource; import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -83,26 +89,18 @@ public class GroupServiceSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - - private final PageStreamingCallSettings + private final PagedCallSettings listGroupsSettings; private final SimpleCallSettings getGroupSettings; private final SimpleCallSettings createGroupSettings; private final SimpleCallSettings updateGroupSettings; private final SimpleCallSettings deleteGroupSettings; - private final PageStreamingCallSettings< - ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> + private final PagedCallSettings< + ListGroupMembersRequest, ListGroupMembersResponse, ListGroupMembersPagedResponse> listGroupMembersSettings; /** Returns the object with the settings used for calls to listGroups. */ - public PageStreamingCallSettings + public PagedCallSettings listGroupsSettings() { return listGroupsSettings; } @@ -128,8 +126,8 @@ public SimpleCallSettings deleteGroupSettings() { } /** Returns the object with the settings used for calls to listGroupMembers. */ - public PageStreamingCallSettings< - ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> + public PagedCallSettings< + ListGroupMembersRequest, ListGroupMembersResponse, ListGroupMembersPagedResponse> listGroupMembersSettings() { return listGroupMembersSettings; } @@ -181,9 +179,9 @@ private GroupServiceSettings(Builder settingsBuilder) throws IOException { listGroupMembersSettings = settingsBuilder.listGroupMembersSettings().build(); } - private static final PageStreamingDescriptor + private static final PagedListDescriptor LIST_GROUPS_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -215,10 +213,10 @@ public Iterable extractResources(ListGroupsResponse payload) { } }; - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> LIST_GROUP_MEMBERS_PAGE_STR_DESC = - new PageStreamingDescriptor< + new PagedListDescriptor< ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource>() { @Override public Object emptyToken() { @@ -255,18 +253,49 @@ public Iterable extractResources(ListGroupMembersResponse pay } }; + private static final PagedListResponseFactory< + ListGroupsRequest, ListGroupsResponse, ListGroupsPagedResponse> + LIST_GROUPS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListGroupsRequest, ListGroupsResponse, ListGroupsPagedResponse>() { + @Override + public ListGroupsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListGroupsRequest request, + CallContext context) { + return new ListGroupsPagedResponse( + callable, LIST_GROUPS_PAGE_STR_DESC, request, context); + } + }; + + private static final PagedListResponseFactory< + ListGroupMembersRequest, ListGroupMembersResponse, ListGroupMembersPagedResponse> + LIST_GROUP_MEMBERS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListGroupMembersRequest, ListGroupMembersResponse, ListGroupMembersPagedResponse>() { + @Override + public ListGroupMembersPagedResponse createPagedListResponse( + UnaryCallable callable, + ListGroupMembersRequest request, + CallContext context) { + return new ListGroupMembersPagedResponse( + callable, LIST_GROUP_MEMBERS_PAGE_STR_DESC, request, context); + } + }; + /** Builder for GroupServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; - private final PageStreamingCallSettings.Builder + private final PagedCallSettings.Builder< + ListGroupsRequest, ListGroupsResponse, ListGroupsPagedResponse> listGroupsSettings; private final SimpleCallSettings.Builder getGroupSettings; private final SimpleCallSettings.Builder createGroupSettings; private final SimpleCallSettings.Builder updateGroupSettings; private final SimpleCallSettings.Builder deleteGroupSettings; - private final PageStreamingCallSettings.Builder< - ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> + private final PagedCallSettings.Builder< + ListGroupMembersRequest, ListGroupMembersResponse, ListGroupMembersPagedResponse> listGroupMembersSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -301,11 +330,11 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); listGroupsSettings = - PageStreamingCallSettings.newBuilder( - GroupServiceGrpc.METHOD_LIST_GROUPS, LIST_GROUPS_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + GroupServiceGrpc.METHOD_LIST_GROUPS, LIST_GROUPS_PAGE_STR_FACT); getGroupSettings = SimpleCallSettings.newBuilder(GroupServiceGrpc.METHOD_GET_GROUP); @@ -316,11 +345,11 @@ private Builder() { deleteGroupSettings = SimpleCallSettings.newBuilder(GroupServiceGrpc.METHOD_DELETE_GROUP); listGroupMembersSettings = - PageStreamingCallSettings.newBuilder( - GroupServiceGrpc.METHOD_LIST_GROUP_MEMBERS, LIST_GROUP_MEMBERS_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + GroupServiceGrpc.METHOD_LIST_GROUP_MEMBERS, LIST_GROUP_MEMBERS_PAGE_STR_FACT); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listGroupsSettings, getGroupSettings, createGroupSettings, @@ -375,8 +404,8 @@ private Builder(GroupServiceSettings settings) { deleteGroupSettings = settings.deleteGroupSettings.toBuilder(); listGroupMembersSettings = settings.listGroupMembersSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listGroupsSettings, getGroupSettings, createGroupSettings, @@ -385,9 +414,16 @@ private Builder(GroupServiceSettings settings) { listGroupMembersSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -433,16 +469,19 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } /** Returns the builder for the settings used for calls to listGroups. */ - public PageStreamingCallSettings.Builder + public PagedCallSettings.Builder listGroupsSettings() { return listGroupsSettings; } @@ -468,8 +507,8 @@ public SimpleCallSettings.Builder deleteGroupSettings } /** Returns the builder for the settings used for calls to listGroupMembers. */ - public PageStreamingCallSettings.Builder< - ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> + public PagedCallSettings.Builder< + ListGroupMembersRequest, ListGroupMembersResponse, ListGroupMembersPagedResponse> listGroupMembersSettings() { return listGroupMembersSettings; } diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java index bd3599c6d493..b88e28b7e8c4 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java @@ -13,10 +13,13 @@ */ package com.google.cloud.monitoring.spi.v3; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMetricDescriptorsPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListTimeSeriesPagedResponse; + import com.google.api.MetricDescriptor; import com.google.api.MonitoredResourceDescriptor; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +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; @@ -28,7 +31,9 @@ import com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest; import com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse; import com.google.monitoring.v3.ListTimeSeriesRequest; +import com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView; import com.google.monitoring.v3.ListTimeSeriesResponse; +import com.google.monitoring.v3.TimeInterval; import com.google.monitoring.v3.TimeSeries; import com.google.protobuf.Empty; import io.grpc.ManagedChannel; @@ -68,8 +73,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -97,42 +102,34 @@ public class MetricServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable< + private final UnaryCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable; - private final ApiCallable< - ListMonitoredResourceDescriptorsRequest, - PagedListResponse< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor>> + private final UnaryCallable< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsPagedCallable; - private final ApiCallable + private final UnaryCallable getMonitoredResourceDescriptorCallable; - private final ApiCallable + private final UnaryCallable listMetricDescriptorsCallable; - private final ApiCallable< - ListMetricDescriptorsRequest, - PagedListResponse< - ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor>> + private final UnaryCallable listMetricDescriptorsPagedCallable; - private final ApiCallable + private final UnaryCallable getMetricDescriptorCallable; - private final ApiCallable + private final UnaryCallable createMetricDescriptorCallable; - private final ApiCallable deleteMetricDescriptorCallable; - private final ApiCallable listTimeSeriesCallable; - private final ApiCallable< - ListTimeSeriesRequest, - PagedListResponse> + private final UnaryCallable deleteMetricDescriptorCallable; + private final UnaryCallable listTimeSeriesCallable; + private final UnaryCallable listTimeSeriesPagedCallable; - private final ApiCallable createTimeSeriesCallable; + private final UnaryCallable createTimeSeriesCallable; private static final PathTemplate PROJECT_PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding("projects/{project}"); - private static final PathTemplate METRIC_DESCRIPTOR_PATH_PATH_TEMPLATE = + private static final PathTemplate METRIC_DESCRIPTOR_PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding( - "projects/{project}/metricDescriptors/{metric_descriptor_path=**}"); + "projects/{project}/metricDescriptors/{metric_descriptor=**}"); private static final PathTemplate MONITORED_RESOURCE_DESCRIPTOR_PATH_TEMPLATE = PathTemplate.createWithoutUrlEncoding( @@ -144,14 +141,12 @@ public static final String formatProjectName(String project) { } /** - * Formats a string containing the fully-qualified path to represent a metric_descriptor_path - * resource. + * Formats a string containing the fully-qualified path to represent a metric_descriptor resource. */ - public static final String formatMetricDescriptorPathName( - String project, String metricDescriptorPath) { - return METRIC_DESCRIPTOR_PATH_PATH_TEMPLATE.instantiate( + public static final String formatMetricDescriptorName(String project, String metricDescriptor) { + return METRIC_DESCRIPTOR_PATH_TEMPLATE.instantiate( "project", project, - "metric_descriptor_path", metricDescriptorPath); + "metric_descriptor", metricDescriptor); } /** @@ -171,23 +166,20 @@ public static final String parseProjectFromProjectName(String projectName) { } /** - * Parses the project from the given fully-qualified path which represents a metricDescriptorPath + * Parses the project from the given fully-qualified path which represents a metricDescriptor * resource. */ - public static final String parseProjectFromMetricDescriptorPathName( - String metricDescriptorPathName) { - return METRIC_DESCRIPTOR_PATH_PATH_TEMPLATE.parse(metricDescriptorPathName).get("project"); + public static final String parseProjectFromMetricDescriptorName(String metricDescriptorName) { + return METRIC_DESCRIPTOR_PATH_TEMPLATE.parse(metricDescriptorName).get("project"); } /** - * Parses the metric_descriptor_path from the given fully-qualified path which represents a - * metricDescriptorPath resource. + * Parses the metric_descriptor from the given fully-qualified path which represents a + * metricDescriptor resource. */ - public static final String parseMetricDescriptorPathFromMetricDescriptorPathName( - String metricDescriptorPathName) { - return METRIC_DESCRIPTOR_PATH_PATH_TEMPLATE - .parse(metricDescriptorPathName) - .get("metric_descriptor_path"); + public static final String parseMetricDescriptorFromMetricDescriptorName( + String metricDescriptorName) { + return METRIC_DESCRIPTOR_PATH_TEMPLATE.parse(metricDescriptorName).get("metric_descriptor"); } /** @@ -235,32 +227,34 @@ protected MetricServiceApi(MetricServiceSettings settings) throws IOException { this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.listMonitoredResourceDescriptorsCallable = - ApiCallable.create( + UnaryCallable.create( settings.listMonitoredResourceDescriptorsSettings(), this.channel, this.executor); this.listMonitoredResourceDescriptorsPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listMonitoredResourceDescriptorsSettings(), this.channel, this.executor); this.getMonitoredResourceDescriptorCallable = - ApiCallable.create( + UnaryCallable.create( settings.getMonitoredResourceDescriptorSettings(), this.channel, this.executor); this.listMetricDescriptorsCallable = - ApiCallable.create(settings.listMetricDescriptorsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listMetricDescriptorsSettings(), this.channel, this.executor); this.listMetricDescriptorsPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listMetricDescriptorsSettings(), this.channel, this.executor); this.getMetricDescriptorCallable = - ApiCallable.create(settings.getMetricDescriptorSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getMetricDescriptorSettings(), this.channel, this.executor); this.createMetricDescriptorCallable = - ApiCallable.create(settings.createMetricDescriptorSettings(), this.channel, this.executor); + UnaryCallable.create( + settings.createMetricDescriptorSettings(), this.channel, this.executor); this.deleteMetricDescriptorCallable = - ApiCallable.create(settings.deleteMetricDescriptorSettings(), this.channel, this.executor); + UnaryCallable.create( + settings.deleteMetricDescriptorSettings(), this.channel, this.executor); this.listTimeSeriesCallable = - ApiCallable.create(settings.listTimeSeriesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listTimeSeriesSettings(), this.channel, this.executor); this.listTimeSeriesPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listTimeSeriesSettings(), this.channel, this.executor); this.createTimeSeriesCallable = - ApiCallable.create(settings.createTimeSeriesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.createTimeSeriesSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -296,8 +290,7 @@ public final MetricServiceSettings getSettings() { *

    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
    -   *   for (MonitoredResourceDescriptor element : metricServiceApi.listMonitoredResourceDescriptors(formattedName, filter).iterateAllElements()) {
    +   *   for (MonitoredResourceDescriptor element : metricServiceApi.listMonitoredResourceDescriptors(formattedName).iterateAllElements()) {
        *     // doThingsWith(element);
        *   }
        * }
    @@ -305,22 +298,13 @@ public final MetricServiceSettings getSettings() {
        *
        * @param name The project on which to execute the request. The format is
        *     `"projects/{project_id_or_number}"`.
    -   * @param filter An optional [filter](/monitoring/api/v3/filters) describing the descriptors to be
    -   *     returned. The filter can reference the descriptor's type and labels. For example, the
    -   *     following filter returns only Google Compute Engine descriptors that have an `id` label:
    -   *     

    resource.type = starts_with("gce_") AND resource.label:id * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> - listMonitoredResourceDescriptors(String name, String filter) { + public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResourceDescriptors( + String name) { PROJECT_PATH_TEMPLATE.validate(name, "listMonitoredResourceDescriptors"); ListMonitoredResourceDescriptorsRequest request = - ListMonitoredResourceDescriptorsRequest.newBuilder() - .setName(name) - .setFilter(filter) - .build(); + ListMonitoredResourceDescriptorsRequest.newBuilder().setName(name).build(); return listMonitoredResourceDescriptors(request); } @@ -334,10 +318,8 @@ public final MetricServiceSettings getSettings() { *

    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
        *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
        *     .build();
        *   for (MonitoredResourceDescriptor element : metricServiceApi.listMonitoredResourceDescriptors(request).iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -348,10 +330,8 @@ public final MetricServiceSettings getSettings() {
        * @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 PagedListResponse<
    -          ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse,
    -          MonitoredResourceDescriptor>
    -      listMonitoredResourceDescriptors(ListMonitoredResourceDescriptorsRequest request) {
    +  public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResourceDescriptors(
    +      ListMonitoredResourceDescriptorsRequest request) {
         return listMonitoredResourceDescriptorsPagedCallable().call(request);
       }
     
    @@ -365,12 +345,10 @@ public final MetricServiceSettings getSettings() {
        * 
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
        *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
        *     .build();
    -   *   ListenableFuture<PagedListResponse<ListMonitoredResourceDescriptorsRequest,ListMonitoredResourceDescriptorsResponse,MonitoredResourceDescriptor>> future = metricServiceApi.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
    +   *   ListenableFuture<ListMonitoredResourceDescriptorsPagedResponse> future = metricServiceApi.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
        *   // Do something
        *   for (MonitoredResourceDescriptor element : future.get().iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -378,11 +356,8 @@ public final MetricServiceSettings getSettings() {
        * }
        * 
    */ - public final ApiCallable< - ListMonitoredResourceDescriptorsRequest, - PagedListResponse< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor>> + public final UnaryCallable< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsPagedCallable() { return listMonitoredResourceDescriptorsPagedCallable; } @@ -397,10 +372,8 @@ public final MetricServiceSettings getSettings() { *
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
        *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
        *     .build();
        *   while (true) {
        *     ListMonitoredResourceDescriptorsResponse response = metricServiceApi.listMonitoredResourceDescriptorsCallable().call(request);
    @@ -417,7 +390,7 @@ public final MetricServiceSettings getSettings() {
        * }
        * 
    */ - public final ApiCallable< + public final UnaryCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable() { return listMonitoredResourceDescriptorsCallable; @@ -493,7 +466,7 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( * } *
    */ - public final ApiCallable + public final UnaryCallable getMonitoredResourceDescriptorCallable() { return getMonitoredResourceDescriptorCallable; } @@ -508,8 +481,7 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( *
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
    -   *   for (MetricDescriptor element : metricServiceApi.listMetricDescriptors(formattedName, filter).iterateAllElements()) {
    +   *   for (MetricDescriptor element : metricServiceApi.listMetricDescriptors(formattedName).iterateAllElements()) {
        *     // doThingsWith(element);
        *   }
        * }
    @@ -517,19 +489,12 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
        *
        * @param name The project on which to execute the request. The format is
        *     `"projects/{project_id_or_number}"`.
    -   * @param filter If this field is empty, all custom and system-defined metric descriptors are
    -   *     returned. Otherwise, the [filter](/monitoring/api/v3/filters) specifies which metric
    -   *     descriptors are to be returned. For example, the following filter matches all [custom
    -   *     metrics](/monitoring/custom-metrics):
    -   *     

    metric.type = starts_with("custom.googleapis.com/") * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse< - ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> - listMetricDescriptors(String name, String filter) { + public final ListMetricDescriptorsPagedResponse listMetricDescriptors(String name) { PROJECT_PATH_TEMPLATE.validate(name, "listMetricDescriptors"); ListMetricDescriptorsRequest request = - ListMetricDescriptorsRequest.newBuilder().setName(name).setFilter(filter).build(); + ListMetricDescriptorsRequest.newBuilder().setName(name).build(); return listMetricDescriptors(request); } @@ -543,10 +508,8 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( *

    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
        *   ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
        *     .build();
        *   for (MetricDescriptor element : metricServiceApi.listMetricDescriptors(request).iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -557,9 +520,8 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
        * @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 PagedListResponse<
    -          ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor>
    -      listMetricDescriptors(ListMetricDescriptorsRequest request) {
    +  public final ListMetricDescriptorsPagedResponse listMetricDescriptors(
    +      ListMetricDescriptorsRequest request) {
         return listMetricDescriptorsPagedCallable().call(request);
       }
     
    @@ -573,12 +535,10 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
        * 
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
        *   ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
        *     .build();
    -   *   ListenableFuture<PagedListResponse<ListMetricDescriptorsRequest,ListMetricDescriptorsResponse,MetricDescriptor>> future = metricServiceApi.listMetricDescriptorsPagedCallable().futureCall(request);
    +   *   ListenableFuture<ListMetricDescriptorsPagedResponse> future = metricServiceApi.listMetricDescriptorsPagedCallable().futureCall(request);
        *   // Do something
        *   for (MetricDescriptor element : future.get().iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -586,10 +546,7 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
        * }
        * 
    */ - public final ApiCallable< - ListMetricDescriptorsRequest, - PagedListResponse< - ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor>> + public final UnaryCallable listMetricDescriptorsPagedCallable() { return listMetricDescriptorsPagedCallable; } @@ -604,10 +561,8 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( *
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    -   *   String filter = "";
        *   ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
        *     .setName(formattedName)
    -   *     .setFilter(filter)
        *     .build();
        *   while (true) {
        *     ListMetricDescriptorsResponse response = metricServiceApi.listMetricDescriptorsCallable().call(request);
    @@ -624,7 +579,7 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor(
        * }
        * 
    */ - public final ApiCallable + public final UnaryCallable listMetricDescriptorsCallable() { return listMetricDescriptorsCallable; } @@ -637,7 +592,7 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( * *
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
    -   *   String formattedName = MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]");
    +   *   String formattedName = MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
        *   MetricDescriptor response = metricServiceApi.getMetricDescriptor(formattedName);
        * }
        * 
    @@ -648,7 +603,7 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final MetricDescriptor getMetricDescriptor(String name) { - METRIC_DESCRIPTOR_PATH_PATH_TEMPLATE.validate(name, "getMetricDescriptor"); + METRIC_DESCRIPTOR_PATH_TEMPLATE.validate(name, "getMetricDescriptor"); GetMetricDescriptorRequest request = GetMetricDescriptorRequest.newBuilder().setName(name).build(); return getMetricDescriptor(request); @@ -662,7 +617,7 @@ public final MetricDescriptor getMetricDescriptor(String name) { * *
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
    -   *   String formattedName = MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]");
    +   *   String formattedName = MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
        *   GetMetricDescriptorRequest request = GetMetricDescriptorRequest.newBuilder()
        *     .setName(formattedName)
        *     .build();
    @@ -685,7 +640,7 @@ private final MetricDescriptor getMetricDescriptor(GetMetricDescriptorRequest re
        *
        * 
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
    -   *   String formattedName = MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]");
    +   *   String formattedName = MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
        *   GetMetricDescriptorRequest request = GetMetricDescriptorRequest.newBuilder()
        *     .setName(formattedName)
        *     .build();
    @@ -695,7 +650,7 @@ private final MetricDescriptor getMetricDescriptor(GetMetricDescriptorRequest re
        * }
        * 
    */ - public final ApiCallable + public final UnaryCallable getMetricDescriptorCallable() { return getMetricDescriptorCallable; } @@ -778,7 +733,7 @@ public final MetricDescriptor createMetricDescriptor(CreateMetricDescriptorReque * } *
    */ - public final ApiCallable + public final UnaryCallable createMetricDescriptorCallable() { return createMetricDescriptorCallable; } @@ -792,7 +747,7 @@ public final MetricDescriptor createMetricDescriptor(CreateMetricDescriptorReque * *
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
    -   *   String formattedName = MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]");
    +   *   String formattedName = MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
        *   metricServiceApi.deleteMetricDescriptor(formattedName);
        * }
        * 
    @@ -803,7 +758,7 @@ public final MetricDescriptor createMetricDescriptor(CreateMetricDescriptorReque * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteMetricDescriptor(String name) { - METRIC_DESCRIPTOR_PATH_PATH_TEMPLATE.validate(name, "deleteMetricDescriptor"); + METRIC_DESCRIPTOR_PATH_TEMPLATE.validate(name, "deleteMetricDescriptor"); DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder().setName(name).build(); deleteMetricDescriptor(request); @@ -818,7 +773,7 @@ public final void deleteMetricDescriptor(String name) { * *
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
    -   *   String formattedName = MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]");
    +   *   String formattedName = MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
        *   DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder()
        *     .setName(formattedName)
        *     .build();
    @@ -842,7 +797,7 @@ private final void deleteMetricDescriptor(DeleteMetricDescriptorRequest request)
        *
        * 
    
        * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
    -   *   String formattedName = MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]");
    +   *   String formattedName = MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
        *   DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder()
        *     .setName(formattedName)
        *     .build();
    @@ -852,7 +807,8 @@ private final void deleteMetricDescriptor(DeleteMetricDescriptorRequest request)
        * }
        * 
    */ - public final ApiCallable deleteMetricDescriptorCallable() { + public final UnaryCallable + deleteMetricDescriptorCallable() { return deleteMetricDescriptorCallable; } @@ -867,15 +823,57 @@ public final ApiCallable deleteMetricDescr * String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); * String filter = ""; * TimeInterval interval = TimeInterval.newBuilder().build(); - * Aggregation aggregation = Aggregation.newBuilder().build(); - * String orderBy = ""; + * ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL; + * for (TimeSeries element : metricServiceApi.listTimeSeries(formattedName, filter, interval, view).iterateAllElements()) { + * // doThingsWith(element); + * } + * } + *
    + * + * @param name The project on which to execute the request. The format is + * "projects/{project_id_or_number}". + * @param filter A [monitoring filter](/monitoring/api/v3/filters) that specifies which time + * series should be returned. The filter must specify a single metric type, and can + * additionally specify metric labels and other information. For example: + *

    metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND + * metric.label.instance_name = "my-instance-name" + * @param interval The time interval for which results should be returned. Only time series that + * contain data points in the specified interval are included in the response. + * @param view Specifies which information is returned about the time series. + * @throws com.google.api.gax.grpc.ApiException if the remote call fails + */ + public final ListTimeSeriesPagedResponse listTimeSeries( + String name, + String filter, + TimeInterval interval, + ListTimeSeriesRequest.TimeSeriesView view) { + PROJECT_PATH_TEMPLATE.validate(name, "listTimeSeries"); + ListTimeSeriesRequest request = + ListTimeSeriesRequest.newBuilder() + .setName(name) + .setFilter(filter) + .setInterval(interval) + .setView(view) + .build(); + return listTimeSeries(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists time series that match a filter. This method does not require a Stackdriver account. + * + *

    Sample code: + * + *

    
    +   * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) {
    +   *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
    +   *   String filter = "";
    +   *   TimeInterval interval = TimeInterval.newBuilder().build();
        *   ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
        *   ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
        *     .setName(formattedName)
        *     .setFilter(filter)
        *     .setInterval(interval)
    -   *     .setAggregation(aggregation)
    -   *     .setOrderBy(orderBy)
        *     .setView(view)
        *     .build();
        *   for (TimeSeries element : metricServiceApi.listTimeSeries(request).iterateAllElements()) {
    @@ -887,8 +885,7 @@ public final ApiCallable deleteMetricDescr
        * @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 PagedListResponse
    -      listTimeSeries(ListTimeSeriesRequest request) {
    +  public final ListTimeSeriesPagedResponse listTimeSeries(ListTimeSeriesRequest request) {
         return listTimeSeriesPagedCallable().call(request);
       }
     
    @@ -903,18 +900,14 @@ public final ApiCallable deleteMetricDescr
        *   String formattedName = MetricServiceApi.formatProjectName("[PROJECT]");
        *   String filter = "";
        *   TimeInterval interval = TimeInterval.newBuilder().build();
    -   *   Aggregation aggregation = Aggregation.newBuilder().build();
    -   *   String orderBy = "";
        *   ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
        *   ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder()
        *     .setName(formattedName)
        *     .setFilter(filter)
        *     .setInterval(interval)
    -   *     .setAggregation(aggregation)
    -   *     .setOrderBy(orderBy)
        *     .setView(view)
        *     .build();
    -   *   ListenableFuture<PagedListResponse<ListTimeSeriesRequest,ListTimeSeriesResponse,TimeSeries>> future = metricServiceApi.listTimeSeriesPagedCallable().futureCall(request);
    +   *   ListenableFuture<ListTimeSeriesPagedResponse> future = metricServiceApi.listTimeSeriesPagedCallable().futureCall(request);
        *   // Do something
        *   for (TimeSeries element : future.get().iterateAllElements()) {
        *     // doThingsWith(element);
    @@ -922,9 +915,7 @@ public final ApiCallable deleteMetricDescr
        * }
        * 
    */ - public final ApiCallable< - ListTimeSeriesRequest, - PagedListResponse> + public final UnaryCallable listTimeSeriesPagedCallable() { return listTimeSeriesPagedCallable; } @@ -940,15 +931,11 @@ public final ApiCallable deleteMetricDescr * String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); * String filter = ""; * TimeInterval interval = TimeInterval.newBuilder().build(); - * Aggregation aggregation = Aggregation.newBuilder().build(); - * String orderBy = ""; * ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL; * ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder() * .setName(formattedName) * .setFilter(filter) * .setInterval(interval) - * .setAggregation(aggregation) - * .setOrderBy(orderBy) * .setView(view) * .build(); * while (true) { @@ -966,7 +953,8 @@ public final ApiCallable deleteMetricDescr * } *
    */ - public final ApiCallable listTimeSeriesCallable() { + public final UnaryCallable + listTimeSeriesCallable() { return listTimeSeriesCallable; } @@ -1050,7 +1038,7 @@ public final void createTimeSeries(CreateTimeSeriesRequest request) { * } *
    */ - public final ApiCallable createTimeSeriesCallable() { + public final UnaryCallable createTimeSeriesCallable() { return createTimeSeriesCallable; } diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java index c7c89badb66d..a2a86ed5c0ff 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java @@ -13,15 +13,22 @@ */ package com.google.cloud.monitoring.spi.v3; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMetricDescriptorsPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListTimeSeriesPagedResponse; + import com.google.api.MetricDescriptor; import com.google.api.MonitoredResourceDescriptor; import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -87,23 +94,16 @@ public class MetricServiceSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - - private final PageStreamingCallSettings< + private final PagedCallSettings< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings; private final SimpleCallSettings< GetMonitoredResourceDescriptorRequest, MonitoredResourceDescriptor> getMonitoredResourceDescriptorSettings; - private final PageStreamingCallSettings< - ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> + private final PagedCallSettings< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, + ListMetricDescriptorsPagedResponse> listMetricDescriptorsSettings; private final SimpleCallSettings getMetricDescriptorSettings; @@ -111,14 +111,15 @@ public class MetricServiceSettings extends ServiceApiSettings { createMetricDescriptorSettings; private final SimpleCallSettings deleteMetricDescriptorSettings; - private final PageStreamingCallSettings + private final PagedCallSettings< + ListTimeSeriesRequest, ListTimeSeriesResponse, ListTimeSeriesPagedResponse> listTimeSeriesSettings; private final SimpleCallSettings createTimeSeriesSettings; /** Returns the object with the settings used for calls to listMonitoredResourceDescriptors. */ - public PageStreamingCallSettings< + public PagedCallSettings< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings() { return listMonitoredResourceDescriptorsSettings; } @@ -130,8 +131,9 @@ public class MetricServiceSettings extends ServiceApiSettings { } /** Returns the object with the settings used for calls to listMetricDescriptors. */ - public PageStreamingCallSettings< - ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> + public PagedCallSettings< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, + ListMetricDescriptorsPagedResponse> listMetricDescriptorsSettings() { return listMetricDescriptorsSettings; } @@ -154,7 +156,8 @@ public SimpleCallSettings deleteMetricDesc } /** Returns the object with the settings used for calls to listTimeSeries. */ - public PageStreamingCallSettings + public PagedCallSettings< + ListTimeSeriesRequest, ListTimeSeriesResponse, ListTimeSeriesPagedResponse> listTimeSeriesSettings() { return listTimeSeriesSettings; } @@ -215,11 +218,11 @@ private MetricServiceSettings(Builder settingsBuilder) throws IOException { createTimeSeriesSettings = settingsBuilder.createTimeSeriesSettings().build(); } - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor> LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC = - new PageStreamingDescriptor< + new PagedListDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor>() { @Override @@ -260,10 +263,10 @@ public Iterable extractResources( } }; - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> LIST_METRIC_DESCRIPTORS_PAGE_STR_DESC = - new PageStreamingDescriptor< + new PagedListDescriptor< ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor>() { @Override public Object emptyToken() { @@ -301,10 +304,10 @@ public Iterable extractResources( } }; - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListTimeSeriesRequest, ListTimeSeriesResponse, TimeSeries> LIST_TIME_SERIES_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -337,19 +340,72 @@ public Iterable extractResources(ListTimeSeriesResponse payload) { } }; + private static final PagedListResponseFactory< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + ListMonitoredResourceDescriptorsPagedResponse> + LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + ListMonitoredResourceDescriptorsPagedResponse>() { + @Override + public ListMonitoredResourceDescriptorsPagedResponse createPagedListResponse( + UnaryCallable< + ListMonitoredResourceDescriptorsRequest, + ListMonitoredResourceDescriptorsResponse> + callable, + ListMonitoredResourceDescriptorsRequest request, + CallContext context) { + return new ListMonitoredResourceDescriptorsPagedResponse( + callable, LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC, request, context); + } + }; + + private static final PagedListResponseFactory< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, + ListMetricDescriptorsPagedResponse> + LIST_METRIC_DESCRIPTORS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, + ListMetricDescriptorsPagedResponse>() { + @Override + public ListMetricDescriptorsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListMetricDescriptorsRequest request, + CallContext context) { + return new ListMetricDescriptorsPagedResponse( + callable, LIST_METRIC_DESCRIPTORS_PAGE_STR_DESC, request, context); + } + }; + + private static final PagedListResponseFactory< + ListTimeSeriesRequest, ListTimeSeriesResponse, ListTimeSeriesPagedResponse> + LIST_TIME_SERIES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListTimeSeriesRequest, ListTimeSeriesResponse, ListTimeSeriesPagedResponse>() { + @Override + public ListTimeSeriesPagedResponse createPagedListResponse( + UnaryCallable callable, + ListTimeSeriesRequest request, + CallContext context) { + return new ListTimeSeriesPagedResponse( + callable, LIST_TIME_SERIES_PAGE_STR_DESC, request, context); + } + }; + /** Builder for MetricServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; - private final PageStreamingCallSettings.Builder< + private final PagedCallSettings.Builder< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings; private final SimpleCallSettings.Builder< GetMonitoredResourceDescriptorRequest, MonitoredResourceDescriptor> getMonitoredResourceDescriptorSettings; - private final PageStreamingCallSettings.Builder< - ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> + private final PagedCallSettings.Builder< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, + ListMetricDescriptorsPagedResponse> listMetricDescriptorsSettings; private final SimpleCallSettings.Builder getMetricDescriptorSettings; @@ -357,8 +413,8 @@ public static class Builder extends ServiceApiSettings.Builder { createMetricDescriptorSettings; private final SimpleCallSettings.Builder deleteMetricDescriptorSettings; - private final PageStreamingCallSettings.Builder< - ListTimeSeriesRequest, ListTimeSeriesResponse, TimeSeries> + private final PagedCallSettings.Builder< + ListTimeSeriesRequest, ListTimeSeriesResponse, ListTimeSeriesPagedResponse> listTimeSeriesSettings; private final SimpleCallSettings.Builder createTimeSeriesSettings; @@ -395,20 +451,20 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); listMonitoredResourceDescriptorsSettings = - PageStreamingCallSettings.newBuilder( + PagedCallSettings.newBuilder( MetricServiceGrpc.METHOD_LIST_MONITORED_RESOURCE_DESCRIPTORS, - LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC); + LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT); getMonitoredResourceDescriptorSettings = SimpleCallSettings.newBuilder(MetricServiceGrpc.METHOD_GET_MONITORED_RESOURCE_DESCRIPTOR); listMetricDescriptorsSettings = - PageStreamingCallSettings.newBuilder( + PagedCallSettings.newBuilder( MetricServiceGrpc.METHOD_LIST_METRIC_DESCRIPTORS, - LIST_METRIC_DESCRIPTORS_PAGE_STR_DESC); + LIST_METRIC_DESCRIPTORS_PAGE_STR_FACT); getMetricDescriptorSettings = SimpleCallSettings.newBuilder(MetricServiceGrpc.METHOD_GET_METRIC_DESCRIPTOR); @@ -420,14 +476,14 @@ private Builder() { SimpleCallSettings.newBuilder(MetricServiceGrpc.METHOD_DELETE_METRIC_DESCRIPTOR); listTimeSeriesSettings = - PageStreamingCallSettings.newBuilder( - MetricServiceGrpc.METHOD_LIST_TIME_SERIES, LIST_TIME_SERIES_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + MetricServiceGrpc.METHOD_LIST_TIME_SERIES, LIST_TIME_SERIES_PAGE_STR_FACT); createTimeSeriesSettings = SimpleCallSettings.newBuilder(MetricServiceGrpc.METHOD_CREATE_TIME_SERIES); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listMonitoredResourceDescriptorsSettings, getMonitoredResourceDescriptorSettings, listMetricDescriptorsSettings, @@ -498,8 +554,8 @@ private Builder(MetricServiceSettings settings) { listTimeSeriesSettings = settings.listTimeSeriesSettings.toBuilder(); createTimeSeriesSettings = settings.createTimeSeriesSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( listMonitoredResourceDescriptorsSettings, getMonitoredResourceDescriptorSettings, listMetricDescriptorsSettings, @@ -510,9 +566,16 @@ private Builder(MetricServiceSettings settings) { createTimeSeriesSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -558,18 +621,21 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } /** Returns the builder for the settings used for calls to listMonitoredResourceDescriptors. */ - public PageStreamingCallSettings.Builder< + public PagedCallSettings.Builder< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> + ListMonitoredResourceDescriptorsPagedResponse> listMonitoredResourceDescriptorsSettings() { return listMonitoredResourceDescriptorsSettings; } @@ -582,8 +648,9 @@ public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) thr } /** Returns the builder for the settings used for calls to listMetricDescriptors. */ - public PageStreamingCallSettings.Builder< - ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> + public PagedCallSettings.Builder< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, + ListMetricDescriptorsPagedResponse> listMetricDescriptorsSettings() { return listMetricDescriptorsSettings; } @@ -607,8 +674,8 @@ public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) thr } /** Returns the builder for the settings used for calls to listTimeSeries. */ - public PageStreamingCallSettings.Builder< - ListTimeSeriesRequest, ListTimeSeriesResponse, TimeSeries> + public PagedCallSettings.Builder< + ListTimeSeriesRequest, ListTimeSeriesResponse, ListTimeSeriesPagedResponse> listTimeSeriesSettings() { return listTimeSeriesSettings; } diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/PagedResponseWrappers.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/PagedResponseWrappers.java new file mode 100644 index 000000000000..17c4060a8297 --- /dev/null +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/PagedResponseWrappers.java @@ -0,0 +1,117 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.monitoring.spi.v3; + +import com.google.api.MetricDescriptor; +import com.google.api.MonitoredResource; +import com.google.api.MonitoredResourceDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseImpl; +import com.google.api.gax.grpc.UnaryCallable; +import com.google.monitoring.v3.Group; +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.ListMetricDescriptorsRequest; +import com.google.monitoring.v3.ListMetricDescriptorsResponse; +import com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest; +import com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse; +import com.google.monitoring.v3.ListTimeSeriesRequest; +import com.google.monitoring.v3.ListTimeSeriesResponse; +import com.google.monitoring.v3.TimeSeries; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers { + + public static class ListGroupsPagedResponse + extends PagedListResponseImpl { + + public ListGroupsPagedResponse( + UnaryCallable callable, + PagedListDescriptor pageDescriptor, + ListGroupsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListGroupMembersPagedResponse + extends PagedListResponseImpl< + ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> { + + public ListGroupMembersPagedResponse( + UnaryCallable callable, + PagedListDescriptor + pageDescriptor, + ListGroupMembersRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListMonitoredResourceDescriptorsPagedResponse + extends PagedListResponseImpl< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> { + + public ListMonitoredResourceDescriptorsPagedResponse( + UnaryCallable< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> + callable, + PagedListDescriptor< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + pageDescriptor, + ListMonitoredResourceDescriptorsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListMetricDescriptorsPagedResponse + extends PagedListResponseImpl< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> { + + public ListMetricDescriptorsPagedResponse( + UnaryCallable callable, + PagedListDescriptor< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> + pageDescriptor, + ListMetricDescriptorsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListTimeSeriesPagedResponse + extends PagedListResponseImpl { + + public ListTimeSeriesPagedResponse( + UnaryCallable callable, + PagedListDescriptor + pageDescriptor, + ListTimeSeriesRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } +} 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 9d1a0e61adb7..e1ea3fad62e0 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 @@ -15,7 +15,7 @@ /** * A client to Stackdriver Monitoring API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    =============== GroupServiceApi =============== * @@ -55,25 +55,5 @@ * } * *

    - * - * ========================== AgentTranslationServiceApi ========================== - * - *

    Service Description: The AgentTranslation API allows `collectd`-based agents to write time - * series data to Cloud Monitoring. See [google.monitoring.v3.MetricService.CreateTimeSeries] - * instead. - * - *

    Sample for AgentTranslationServiceApi: - * - *

    - * 
    - * try (AgentTranslationServiceApi agentTranslationServiceApi = AgentTranslationServiceApi.create()) {
    - *   String formattedName = AgentTranslationServiceApi.formatProjectName("[PROJECT]");
    - *   MonitoredResource resource = MonitoredResource.newBuilder().build();
    - *   String collectdVersion = "";
    - *   List<CollectdPayload> collectdPayloads = new ArrayList<>();
    - *   agentTranslationServiceApi.createCollectdTimeSeries(formattedName, resource, collectdVersion, collectdPayloads);
    - * }
    - * 
    - * 
    */ package com.google.cloud.monitoring.spi.v3; diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceTest.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceTest.java deleted file mode 100644 index 5e622b537d0e..000000000000 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package com.google.cloud.monitoring.spi.v3; - -import com.google.api.MonitoredResource; -import com.google.api.gax.testing.MockGrpcService; -import com.google.api.gax.testing.MockServiceHelper; -import com.google.monitoring.v3.CollectdPayload; -import com.google.monitoring.v3.CreateCollectdTimeSeriesRequest; -import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessageV3; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -@javax.annotation.Generated("by GAPIC") -public class AgentTranslationServiceTest { - private static MockGroupService mockGroupService; - private static MockMetricService mockMetricService; - private static MockAgentTranslationService mockAgentTranslationService; - private static MockServiceHelper serviceHelper; - private AgentTranslationServiceApi api; - - @BeforeClass - public static void startStaticServer() { - mockGroupService = new MockGroupService(); - mockMetricService = new MockMetricService(); - mockAgentTranslationService = new MockAgentTranslationService(); - serviceHelper = - new MockServiceHelper( - "in-process-1", - Arrays.asList( - mockGroupService, mockMetricService, mockAgentTranslationService)); - serviceHelper.start(); - } - - @AfterClass - public static void stopServer() { - serviceHelper.stop(); - } - - @Before - public void setUp() throws IOException { - serviceHelper.reset(); - AgentTranslationServiceSettings settings = - AgentTranslationServiceSettings.defaultBuilder() - .provideChannelWith(serviceHelper.createChannel(), true) - .build(); - api = AgentTranslationServiceApi.create(settings); - } - - @After - public void tearDown() throws Exception { - api.close(); - } - - @Test - @SuppressWarnings("all") - public void createCollectdTimeSeriesTest() { - Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); - expectedResponses.add(expectedResponse); - mockAgentTranslationService.setResponses(expectedResponses); - - String formattedName = AgentTranslationServiceApi.formatProjectName("[PROJECT]"); - MonitoredResource resource = MonitoredResource.newBuilder().build(); - String collectdVersion = "collectdVersion-177050093"; - List collectdPayloads = new ArrayList<>(); - - api.createCollectdTimeSeries(formattedName, resource, collectdVersion, collectdPayloads); - - List actualRequests = mockAgentTranslationService.getRequests(); - Assert.assertEquals(1, actualRequests.size()); - CreateCollectdTimeSeriesRequest actualRequest = - (CreateCollectdTimeSeriesRequest) actualRequests.get(0); - - Assert.assertEquals(formattedName, actualRequest.getName()); - Assert.assertEquals(resource, actualRequest.getResource()); - Assert.assertEquals(collectdVersion, actualRequest.getCollectdVersion()); - Assert.assertEquals(collectdPayloads, actualRequest.getCollectdPayloadsList()); - } -} 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 c3944b8cb0af..016bbc63b15b 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 @@ -14,8 +14,9 @@ package com.google.cloud.monitoring.spi.v3; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupMembersPagedResponse; + import com.google.api.MonitoredResource; -import com.google.api.gax.core.PagedListResponse; import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -25,7 +26,6 @@ import com.google.monitoring.v3.Group; import com.google.monitoring.v3.ListGroupMembersRequest; import com.google.monitoring.v3.ListGroupMembersResponse; -import com.google.monitoring.v3.TimeInterval; import com.google.monitoring.v3.UpdateGroupRequest; import com.google.protobuf.Empty; import com.google.protobuf.GeneratedMessageV3; @@ -44,7 +44,6 @@ public class GroupServiceTest { private static MockGroupService mockGroupService; private static MockMetricService mockMetricService; - private static MockAgentTranslationService mockAgentTranslationService; private static MockServiceHelper serviceHelper; private GroupServiceApi api; @@ -52,12 +51,9 @@ public class GroupServiceTest { public static void startStaticServer() { mockGroupService = new MockGroupService(); mockMetricService = new MockMetricService(); - mockAgentTranslationService = new MockAgentTranslationService(); serviceHelper = new MockServiceHelper( - "in-process-1", - Arrays.asList( - mockGroupService, mockMetricService, mockAgentTranslationService)); + "in-process-1", Arrays.asList(mockGroupService, mockMetricService)); serviceHelper.start(); } @@ -135,9 +131,8 @@ public void createGroupTest() { String formattedName = GroupServiceApi.formatProjectName("[PROJECT]"); Group group = Group.newBuilder().build(); - boolean validateOnly = false; - Group actualResponse = api.createGroup(formattedName, group, validateOnly); + Group actualResponse = api.createGroup(formattedName, group); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockGroupService.getRequests(); @@ -146,7 +141,6 @@ public void createGroupTest() { Assert.assertEquals(formattedName, actualRequest.getName()); Assert.assertEquals(group, actualRequest.getGroup()); - Assert.assertEquals(validateOnly, actualRequest.getValidateOnly()); } @Test @@ -170,9 +164,8 @@ public void updateGroupTest() { mockGroupService.setResponses(expectedResponses); Group group = Group.newBuilder().build(); - boolean validateOnly = false; - Group actualResponse = api.updateGroup(group, validateOnly); + Group actualResponse = api.updateGroup(group); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockGroupService.getRequests(); @@ -180,7 +173,6 @@ public void updateGroupTest() { UpdateGroupRequest actualRequest = (UpdateGroupRequest) actualRequests.get(0); Assert.assertEquals(group, actualRequest.getGroup()); - Assert.assertEquals(validateOnly, actualRequest.getValidateOnly()); } @Test @@ -220,11 +212,8 @@ public void listGroupMembersTest() { mockGroupService.setResponses(expectedResponses); String formattedName = GroupServiceApi.formatGroupName("[PROJECT]", "[GROUP]"); - String filter = "filter-1274492040"; - TimeInterval interval = TimeInterval.newBuilder().build(); - PagedListResponse - pagedListResponse = api.listGroupMembers(formattedName, filter, interval); + ListGroupMembersPagedResponse pagedListResponse = api.listGroupMembers(formattedName); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -235,7 +224,5 @@ public void listGroupMembersTest() { ListGroupMembersRequest actualRequest = (ListGroupMembersRequest) actualRequests.get(0); Assert.assertEquals(formattedName, actualRequest.getName()); - Assert.assertEquals(filter, actualRequest.getFilter()); - Assert.assertEquals(interval, actualRequest.getInterval()); } } 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 fa8034b62219..d3a671e3a5d5 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 @@ -14,9 +14,12 @@ package com.google.cloud.monitoring.spi.v3; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMetricDescriptorsPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse; +import static com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListTimeSeriesPagedResponse; + import com.google.api.MetricDescriptor; import com.google.api.MonitoredResourceDescriptor; -import com.google.api.gax.core.PagedListResponse; import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -29,6 +32,10 @@ import com.google.monitoring.v3.ListMetricDescriptorsResponse; import com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest; import com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse; +import com.google.monitoring.v3.ListTimeSeriesRequest; +import com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView; +import com.google.monitoring.v3.ListTimeSeriesResponse; +import com.google.monitoring.v3.TimeInterval; import com.google.monitoring.v3.TimeSeries; import com.google.protobuf.Empty; import com.google.protobuf.GeneratedMessageV3; @@ -47,7 +54,6 @@ public class MetricServiceTest { private static MockGroupService mockGroupService; private static MockMetricService mockMetricService; - private static MockAgentTranslationService mockAgentTranslationService; private static MockServiceHelper serviceHelper; private MetricServiceApi api; @@ -55,12 +61,9 @@ public class MetricServiceTest { public static void startStaticServer() { mockGroupService = new MockGroupService(); mockMetricService = new MockMetricService(); - mockAgentTranslationService = new MockAgentTranslationService(); serviceHelper = new MockServiceHelper( - "in-process-1", - Arrays.asList( - mockGroupService, mockMetricService, mockAgentTranslationService)); + "in-process-1", Arrays.asList(mockGroupService, mockMetricService)); serviceHelper.start(); } @@ -102,12 +105,9 @@ public void listMonitoredResourceDescriptorsTest() { mockMetricService.setResponses(expectedResponses); String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); - String filter = "filter-1274492040"; - PagedListResponse< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> - pagedListResponse = api.listMonitoredResourceDescriptors(formattedName, filter); + ListMonitoredResourceDescriptorsPagedResponse pagedListResponse = + api.listMonitoredResourceDescriptors(formattedName); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); @@ -120,7 +120,6 @@ public void listMonitoredResourceDescriptorsTest() { (ListMonitoredResourceDescriptorsRequest) actualRequests.get(0); Assert.assertEquals(formattedName, actualRequest.getName()); - Assert.assertEquals(filter, actualRequest.getFilter()); } @Test @@ -174,10 +173,8 @@ public void listMetricDescriptorsTest() { mockMetricService.setResponses(expectedResponses); String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); - String filter = "filter-1274492040"; - PagedListResponse - pagedListResponse = api.listMetricDescriptors(formattedName, filter); + ListMetricDescriptorsPagedResponse pagedListResponse = api.listMetricDescriptors(formattedName); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -189,14 +186,13 @@ public void listMetricDescriptorsTest() { (ListMetricDescriptorsRequest) actualRequests.get(0); Assert.assertEquals(formattedName, actualRequest.getName()); - Assert.assertEquals(filter, actualRequest.getFilter()); } @Test @SuppressWarnings("all") public void getMetricDescriptorTest() { String formattedName2 = - MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]"); + MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); String type = "type3575610"; String unit = "unit3594628"; String description = "description-1724546052"; @@ -214,7 +210,7 @@ public void getMetricDescriptorTest() { mockMetricService.setResponses(expectedResponses); String formattedName = - MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]"); + MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); MetricDescriptor actualResponse = api.getMetricDescriptor(formattedName); Assert.assertEquals(expectedResponse, actualResponse); @@ -270,7 +266,7 @@ public void deleteMetricDescriptorTest() { mockMetricService.setResponses(expectedResponses); String formattedName = - MetricServiceApi.formatMetricDescriptorPathName("[PROJECT]", "[METRIC_DESCRIPTOR_PATH]"); + MetricServiceApi.formatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"); api.deleteMetricDescriptor(formattedName); @@ -282,6 +278,43 @@ public void deleteMetricDescriptorTest() { Assert.assertEquals(formattedName, actualRequest.getName()); } + @Test + @SuppressWarnings("all") + public void listTimeSeriesTest() { + String nextPageToken = ""; + TimeSeries timeSeriesElement = TimeSeries.newBuilder().build(); + List timeSeries = Arrays.asList(timeSeriesElement); + ListTimeSeriesResponse expectedResponse = + ListTimeSeriesResponse.newBuilder() + .setNextPageToken(nextPageToken) + .addAllTimeSeries(timeSeries) + .build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockMetricService.setResponses(expectedResponses); + + String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); + String filter = "filter-1274492040"; + TimeInterval interval = TimeInterval.newBuilder().build(); + ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL; + + ListTimeSeriesPagedResponse pagedListResponse = + api.listTimeSeries(formattedName, filter, interval, view); + + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTimeSeriesList().get(0), resources.get(0)); + + List actualRequests = mockMetricService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListTimeSeriesRequest actualRequest = (ListTimeSeriesRequest) actualRequests.get(0); + + Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(filter, actualRequest.getFilter()); + Assert.assertEquals(interval, actualRequest.getInterval()); + Assert.assertEquals(view, actualRequest.getView()); + } + @Test @SuppressWarnings("all") public void createTimeSeriesTest() { diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationService.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationService.java deleted file mode 100644 index 3455f64948c8..000000000000 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationService.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package com.google.cloud.monitoring.spi.v3; - -import com.google.api.gax.testing.MockGrpcService; -import com.google.protobuf.GeneratedMessageV3; -import io.grpc.ServerServiceDefinition; -import java.util.List; - -@javax.annotation.Generated("by GAPIC") -public class MockAgentTranslationService implements MockGrpcService { - private final MockAgentTranslationServiceImpl serviceImpl; - - public MockAgentTranslationService() { - serviceImpl = new MockAgentTranslationServiceImpl(); - } - - @Override - public List getRequests() { - return serviceImpl.getRequests(); - } - - @Override - public void setResponses(List responses) { - serviceImpl.setResponses(responses); - } - - @Override - public ServerServiceDefinition getServiceDefinition() { - return serviceImpl.bindService(); - } - - @Override - public void reset() { - serviceImpl.reset(); - } -} diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationServiceImpl.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationServiceImpl.java deleted file mode 100644 index 9d1538556a69..000000000000 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationServiceImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package com.google.cloud.monitoring.spi.v3; - -import com.google.common.collect.Lists; -import com.google.monitoring.v3.AgentTranslationServiceGrpc.AgentTranslationServiceImplBase; -import com.google.monitoring.v3.CreateCollectdTimeSeriesRequest; -import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessageV3; -import io.grpc.stub.StreamObserver; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; - -@javax.annotation.Generated("by GAPIC") -public class MockAgentTranslationServiceImpl extends AgentTranslationServiceImplBase { - private ArrayList requests; - private Queue responses; - - public MockAgentTranslationServiceImpl() { - requests = new ArrayList<>(); - responses = new LinkedList<>(); - } - - public List getRequests() { - return requests; - } - - public void setResponses(List responses) { - this.responses = Lists.newLinkedList(responses); - } - - public void reset() { - requests = new ArrayList<>(); - responses = new LinkedList<>(); - } - - @Override - public void createCollectdTimeSeries( - CreateCollectdTimeSeriesRequest request, StreamObserver responseObserver) { - Empty response = (Empty) responses.remove(); - requests.add(request); - responseObserver.onNext(response); - responseObserver.onCompleted(); - } -} diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java index ed59a2b90a72..ec82f6d46822 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java @@ -19,7 +19,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.grpc.ApiCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.api.gax.grpc.ApiException; import com.google.cloud.AuthCredentials; import com.google.cloud.GrpcServiceOptions.ExecutorFactory; @@ -94,7 +94,7 @@ protected ExecutorFactory executorFactory() { } @Override - protected ApiCallSettings.Builder apiCallSettings() { + protected UnaryCallSettings.Builder apiCallSettings() { return super.apiCallSettings(); } @@ -154,7 +154,7 @@ public DefaultPubSubRpc(PubSubOptions options) throws IOException { pubBuilder.provideChannelWith(connectionSettings); subBuilder.provideChannelWith(connectionSettings); } - ApiCallSettings.Builder callSettingsBuilder = internalOptions.apiCallSettings(); + UnaryCallSettings.Builder callSettingsBuilder = internalOptions.apiCallSettings(); pubBuilder.applyToAllApiMethods(callSettingsBuilder); subBuilder.applyToAllApiMethods(callSettingsBuilder); publisherApi = PublisherApi.create(pubBuilder.build()); @@ -183,7 +183,7 @@ public V apply(ApiException exception) { @Override public Future create(Topic topic) { - // TODO: it would be nice if we can get the idempotent information from the ApiCallSettings + // TODO: it would be nice if we can get the idempotent information from the UnaryCallSettings // or from the exception return translate(publisherApi.createTopicCallable().futureCall(topic), true); } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PagedResponseWrappers.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PagedResponseWrappers.java new file mode 100644 index 000000000000..ba9627634656 --- /dev/null +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PagedResponseWrappers.java @@ -0,0 +1,77 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.pubsub.spi.v1; + +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseImpl; +import com.google.api.gax.grpc.UnaryCallable; +import com.google.pubsub.v1.ListSubscriptionsRequest; +import com.google.pubsub.v1.ListSubscriptionsResponse; +import com.google.pubsub.v1.ListTopicSubscriptionsRequest; +import com.google.pubsub.v1.ListTopicSubscriptionsResponse; +import com.google.pubsub.v1.ListTopicsRequest; +import com.google.pubsub.v1.ListTopicsResponse; +import com.google.pubsub.v1.Subscription; +import com.google.pubsub.v1.Topic; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers { + + public static class ListTopicsPagedResponse + extends PagedListResponseImpl { + + public ListTopicsPagedResponse( + UnaryCallable callable, + PagedListDescriptor pageDescriptor, + ListTopicsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListTopicSubscriptionsPagedResponse + extends PagedListResponseImpl< + ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> { + + public ListTopicSubscriptionsPagedResponse( + UnaryCallable callable, + PagedListDescriptor + pageDescriptor, + ListTopicSubscriptionsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } + + public static class ListSubscriptionsPagedResponse + extends PagedListResponseImpl< + ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> { + + public ListSubscriptionsPagedResponse( + UnaryCallable callable, + PagedListDescriptor + pageDescriptor, + ListSubscriptionsRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } +} diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java index be922966c3c3..5edacae38bea 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java @@ -13,8 +13,10 @@ */ package com.google.cloud.pubsub.spi.v1; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse; + +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; @@ -69,8 +71,8 @@ *
  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -98,23 +100,19 @@ public class PublisherApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable createTopicCallable; - private final ApiCallable publishCallable; - private final ApiCallable getTopicCallable; - private final ApiCallable listTopicsCallable; - private final ApiCallable< - ListTopicsRequest, PagedListResponse> - listTopicsPagedCallable; - private final ApiCallable + private final UnaryCallable createTopicCallable; + private final UnaryCallable publishCallable; + private final UnaryCallable getTopicCallable; + private final UnaryCallable listTopicsCallable; + private final UnaryCallable listTopicsPagedCallable; + private final UnaryCallable listTopicSubscriptionsCallable; - private final ApiCallable< - ListTopicSubscriptionsRequest, - PagedListResponse> + private final UnaryCallable listTopicSubscriptionsPagedCallable; - private final ApiCallable deleteTopicCallable; - private final ApiCallable setIamPolicyCallable; - private final ApiCallable getIamPolicyCallable; - private final ApiCallable + private final UnaryCallable deleteTopicCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable testIamPermissionsCallable; private static final PathTemplate PROJECT_PATH_TEMPLATE = @@ -173,31 +171,33 @@ protected PublisherApi(PublisherSettings settings) throws IOException { this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.createTopicCallable = - ApiCallable.create(settings.createTopicSettings(), this.channel, this.executor); + UnaryCallable.create(settings.createTopicSettings(), this.channel, this.executor); this.publishCallable = - ApiCallable.create(settings.publishSettings(), this.channel, this.executor); + UnaryCallable.create(settings.publishSettings(), this.channel, this.executor); if (settings.publishSettings().getBundlerFactory() != null) { closeables.add(settings.publishSettings().getBundlerFactory()); } this.getTopicCallable = - ApiCallable.create(settings.getTopicSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getTopicSettings(), this.channel, this.executor); this.listTopicsCallable = - ApiCallable.create(settings.listTopicsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listTopicsSettings(), this.channel, this.executor); this.listTopicsPagedCallable = - ApiCallable.createPagedVariant(settings.listTopicsSettings(), this.channel, this.executor); + UnaryCallable.createPagedVariant( + settings.listTopicsSettings(), this.channel, this.executor); this.listTopicSubscriptionsCallable = - ApiCallable.create(settings.listTopicSubscriptionsSettings(), this.channel, this.executor); + UnaryCallable.create( + settings.listTopicSubscriptionsSettings(), this.channel, this.executor); this.listTopicSubscriptionsPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listTopicSubscriptionsSettings(), this.channel, this.executor); this.deleteTopicCallable = - ApiCallable.create(settings.deleteTopicSettings(), this.channel, this.executor); + UnaryCallable.create(settings.deleteTopicSettings(), this.channel, this.executor); this.setIamPolicyCallable = - ApiCallable.create(settings.setIamPolicySettings(), this.channel, this.executor); + UnaryCallable.create(settings.setIamPolicySettings(), this.channel, this.executor); this.getIamPolicyCallable = - ApiCallable.create(settings.getIamPolicySettings(), this.channel, this.executor); + UnaryCallable.create(settings.getIamPolicySettings(), this.channel, this.executor); this.testIamPermissionsCallable = - ApiCallable.create(settings.testIamPermissionsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.testIamPermissionsSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -290,7 +290,7 @@ private final Topic createTopic(Topic request) { * } *

  • */ - public final ApiCallable createTopicCallable() { + public final UnaryCallable createTopicCallable() { return createTopicCallable; } @@ -382,7 +382,7 @@ public final PublishResponse publish(PublishRequest request) { * } *
    */ - public final ApiCallable publishCallable() { + public final UnaryCallable publishCallable() { return publishCallable; } @@ -449,7 +449,7 @@ private final Topic getTopic(GetTopicRequest request) { * } * */ - public final ApiCallable getTopicCallable() { + public final UnaryCallable getTopicCallable() { return getTopicCallable; } @@ -471,8 +471,7 @@ public final ApiCallable getTopicCallable() { * @param project The name of the cloud project that topics belong to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse listTopics( - String project) { + public final ListTopicsPagedResponse listTopics(String project) { PROJECT_PATH_TEMPLATE.validate(project, "listTopics"); ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build(); return listTopics(request); @@ -499,8 +498,7 @@ public final PagedListResponse lis * @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 PagedListResponse listTopics( - ListTopicsRequest request) { + public final ListTopicsPagedResponse listTopics(ListTopicsRequest request) { return listTopicsPagedCallable().call(request); } @@ -516,7 +514,7 @@ public final PagedListResponse lis * ListTopicsRequest request = ListTopicsRequest.newBuilder() * .setProject(formattedProject) * .build(); - * ListenableFuture<PagedListResponse<ListTopicsRequest,ListTopicsResponse,Topic>> future = publisherApi.listTopicsPagedCallable().futureCall(request); + * ListenableFuture<ListTopicsPagedResponse> future = publisherApi.listTopicsPagedCallable().futureCall(request); * // Do something * for (Topic element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -524,9 +522,7 @@ public final PagedListResponse lis * } * */ - public final ApiCallable< - ListTopicsRequest, PagedListResponse> - listTopicsPagedCallable() { + public final UnaryCallable listTopicsPagedCallable() { return listTopicsPagedCallable; } @@ -557,7 +553,7 @@ public final PagedListResponse lis * } * */ - public final ApiCallable listTopicsCallable() { + public final UnaryCallable listTopicsCallable() { return listTopicsCallable; } @@ -579,9 +575,7 @@ public final ApiCallable listTopicsCallab * @param topic The name of the topic that subscriptions are attached to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse< - ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> - listTopicSubscriptions(String topic) { + public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topic) { TOPIC_PATH_TEMPLATE.validate(topic, "listTopicSubscriptions"); ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build(); @@ -609,9 +603,8 @@ public final ApiCallable listTopicsCallab * @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 PagedListResponse< - ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> - listTopicSubscriptions(ListTopicSubscriptionsRequest request) { + public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions( + ListTopicSubscriptionsRequest request) { return listTopicSubscriptionsPagedCallable().call(request); } @@ -627,7 +620,7 @@ public final ApiCallable listTopicsCallab * ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder() * .setTopic(formattedTopic) * .build(); - * ListenableFuture<PagedListResponse<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse,String>> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request); + * ListenableFuture<ListTopicSubscriptionsPagedResponse> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request); * // Do something * for (String element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -635,9 +628,7 @@ public final ApiCallable listTopicsCallab * } * */ - public final ApiCallable< - ListTopicSubscriptionsRequest, - PagedListResponse> + public final UnaryCallable listTopicSubscriptionsPagedCallable() { return listTopicSubscriptionsPagedCallable; } @@ -669,7 +660,7 @@ public final ApiCallable listTopicsCallab * } * */ - public final ApiCallable + public final UnaryCallable listTopicSubscriptionsCallable() { return listTopicSubscriptionsCallable; } @@ -746,7 +737,7 @@ private final void deleteTopic(DeleteTopicRequest request) { * } * */ - public final ApiCallable deleteTopicCallable() { + public final UnaryCallable deleteTopicCallable() { return deleteTopicCallable; } @@ -764,11 +755,12 @@ public final ApiCallable deleteTopicCallable() { * } * * - * @param resource REQUIRED: The resource for which policy is being specified. Resource is usually - * specified as a path, such as, projects/{project}/zones/{zone}/disks/{disk}. - * @param policy REQUIRED: The complete policy to be applied to the 'resource'. The size of the - * policy is limited to a few 10s of KB. An empty policy is in general a valid policy but - * certain services (like Projects) might reject them. + * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is + * usually specified as a path. For example, a Project resource is specified as + * `projects/{project}`. + * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the + * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud + * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { @@ -823,14 +815,14 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) { * } * */ - public final ApiCallable setIamPolicyCallable() { + public final UnaryCallable setIamPolicyCallable() { return setIamPolicyCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets the access control policy for a resource. Is empty if the policy or the resource does not - * exist. + * Gets the access control policy for a resource. Returns an empty policy if the resource exists + * and does not have a policy set. * *

    Sample code: * @@ -841,8 +833,9 @@ public final ApiCallable setIamPolicyCallable() { * } * * - * @param resource REQUIRED: The resource for which policy is being requested. Resource is usually - * specified as a path, such as, projects/{project}. + * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is + * usually specified as a path. For example, a Project resource is specified as + * `projects/{project}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { @@ -853,8 +846,8 @@ public final Policy getIamPolicy(String resource) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets the access control policy for a resource. Is empty if the policy or the resource does not - * exist. + * Gets the access control policy for a resource. Returns an empty policy if the resource exists + * and does not have a policy set. * *

    Sample code: * @@ -877,8 +870,8 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets the access control policy for a resource. Is empty if the policy or the resource does not - * exist. + * Gets the access control policy for a resource. Returns an empty policy if the resource exists + * and does not have a policy set. * *

    Sample code: * @@ -894,7 +887,7 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) { * } * */ - public final ApiCallable getIamPolicyCallable() { + public final UnaryCallable getIamPolicyCallable() { return getIamPolicyCallable; } @@ -912,10 +905,12 @@ public final ApiCallable getIamPolicyCallable() { * } * * - * @param resource REQUIRED: The resource for which policy detail is being requested. Resource is - * usually specified as a path, such as, projects/{project}. - * @param permissions The set of permissions to check for the 'resource'. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. + * @param resource REQUIRED: The resource for which the policy detail is being requested. + * `resource` is usually specified as a path. For example, a Project resource is specified as + * `projects/{project}`. + * @param permissions The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more information see + * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final TestIamPermissionsResponse testIamPermissions( @@ -974,7 +969,7 @@ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsReq * } * */ - public final ApiCallable + public final UnaryCallable testIamPermissionsCallable() { return testIamPermissionsCallable; } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java index 8c50b07d0d06..f225e27a2523 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java @@ -13,17 +13,23 @@ */ package com.google.cloud.pubsub.spi.v1; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse; + import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; import com.google.api.gax.grpc.BundlingCallSettings; import com.google.api.gax.grpc.BundlingDescriptor; import com.google.api.gax.grpc.BundlingSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.RequestIssuer; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -98,21 +104,14 @@ public class PublisherSettings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/pubsub") .build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings createTopicSettings; private final BundlingCallSettings publishSettings; private final SimpleCallSettings getTopicSettings; - private final PageStreamingCallSettings + private final PagedCallSettings listTopicsSettings; - private final PageStreamingCallSettings< - ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> + private final PagedCallSettings< + ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, + ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsSettings; private final SimpleCallSettings deleteTopicSettings; private final SimpleCallSettings setIamPolicySettings; @@ -136,14 +135,15 @@ public SimpleCallSettings getTopicSettings() { } /** Returns the object with the settings used for calls to listTopics. */ - public PageStreamingCallSettings + public PagedCallSettings listTopicsSettings() { return listTopicsSettings; } /** Returns the object with the settings used for calls to listTopicSubscriptions. */ - public PageStreamingCallSettings< - ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> + public PagedCallSettings< + ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, + ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsSettings() { return listTopicSubscriptionsSettings; } @@ -219,9 +219,9 @@ private PublisherSettings(Builder settingsBuilder) throws IOException { testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } - private static final PageStreamingDescriptor + private static final PagedListDescriptor LIST_TOPICS_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -253,10 +253,10 @@ public Iterable extractResources(ListTopicsResponse payload) { } }; - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC = - new PageStreamingDescriptor< + new PagedListDescriptor< ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>() { @Override public Object emptyToken() { @@ -295,6 +295,39 @@ public Iterable extractResources(ListTopicSubscriptionsResponse payload) } }; + private static final PagedListResponseFactory< + ListTopicsRequest, ListTopicsResponse, ListTopicsPagedResponse> + LIST_TOPICS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListTopicsRequest, ListTopicsResponse, ListTopicsPagedResponse>() { + @Override + public ListTopicsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListTopicsRequest request, + CallContext context) { + return new ListTopicsPagedResponse( + callable, LIST_TOPICS_PAGE_STR_DESC, request, context); + } + }; + + private static final PagedListResponseFactory< + ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, + ListTopicSubscriptionsPagedResponse> + LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, + ListTopicSubscriptionsPagedResponse>() { + @Override + public ListTopicSubscriptionsPagedResponse createPagedListResponse( + UnaryCallable + callable, + ListTopicSubscriptionsRequest request, + CallContext context) { + return new ListTopicSubscriptionsPagedResponse( + callable, LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC, request, context); + } + }; + private static final BundlingDescriptor PUBLISH_BUNDLING_DESC = new BundlingDescriptor() { @Override @@ -359,15 +392,17 @@ public long countBytes(PublishRequest request) { /** Builder for PublisherSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder createTopicSettings; private final BundlingCallSettings.Builder publishSettings; private final SimpleCallSettings.Builder getTopicSettings; - private final PageStreamingCallSettings.Builder + private final PagedCallSettings.Builder< + ListTopicsRequest, ListTopicsResponse, ListTopicsPagedResponse> listTopicsSettings; - private final PageStreamingCallSettings.Builder< - ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> + private final PagedCallSettings.Builder< + ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, + ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsSettings; private final SimpleCallSettings.Builder deleteTopicSettings; private final SimpleCallSettings.Builder setIamPolicySettings; @@ -422,7 +457,7 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); createTopicSettings = SimpleCallSettings.newBuilder(PublisherGrpc.METHOD_CREATE_TOPIC); @@ -433,13 +468,12 @@ private Builder() { getTopicSettings = SimpleCallSettings.newBuilder(PublisherGrpc.METHOD_GET_TOPIC); listTopicsSettings = - PageStreamingCallSettings.newBuilder( - PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_DESC); + PagedCallSettings.newBuilder(PublisherGrpc.METHOD_LIST_TOPICS, LIST_TOPICS_PAGE_STR_FACT); listTopicSubscriptionsSettings = - PageStreamingCallSettings.newBuilder( + PagedCallSettings.newBuilder( PublisherGrpc.METHOD_LIST_TOPIC_SUBSCRIPTIONS, - LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_DESC); + LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_FACT); deleteTopicSettings = SimpleCallSettings.newBuilder(PublisherGrpc.METHOD_DELETE_TOPIC); @@ -450,8 +484,8 @@ private Builder() { testIamPermissionsSettings = SimpleCallSettings.newBuilder(IAMPolicyGrpc.METHOD_TEST_IAM_PERMISSIONS); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( createTopicSettings, publishSettings, getTopicSettings, @@ -536,8 +570,8 @@ private Builder(PublisherSettings settings) { getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( createTopicSettings, publishSettings, getTopicSettings, @@ -549,9 +583,16 @@ private Builder(PublisherSettings settings) { testIamPermissionsSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -597,11 +638,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } @@ -621,14 +665,15 @@ public SimpleCallSettings.Builder getTopicSettings() { } /** Returns the builder for the settings used for calls to listTopics. */ - public PageStreamingCallSettings.Builder + public PagedCallSettings.Builder listTopicsSettings() { return listTopicsSettings; } /** Returns the builder for the settings used for calls to listTopicSubscriptions. */ - public PageStreamingCallSettings.Builder< - ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String> + public PagedCallSettings.Builder< + ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, + ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsSettings() { return listTopicSubscriptionsSettings; } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java index 3505cd9d1825..6f07efb8d75d 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java @@ -13,8 +13,9 @@ */ package com.google.cloud.pubsub.spi.v1; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse; + +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; @@ -73,8 +74,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -102,22 +103,20 @@ public class SubscriberApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable createSubscriptionCallable; - private final ApiCallable getSubscriptionCallable; - private final ApiCallable + private final UnaryCallable createSubscriptionCallable; + private final UnaryCallable getSubscriptionCallable; + private final UnaryCallable listSubscriptionsCallable; - private final ApiCallable< - ListSubscriptionsRequest, - PagedListResponse> + private final UnaryCallable listSubscriptionsPagedCallable; - private final ApiCallable deleteSubscriptionCallable; - private final ApiCallable modifyAckDeadlineCallable; - private final ApiCallable acknowledgeCallable; - private final ApiCallable pullCallable; - private final ApiCallable modifyPushConfigCallable; - private final ApiCallable setIamPolicyCallable; - private final ApiCallable getIamPolicyCallable; - private final ApiCallable + private final UnaryCallable deleteSubscriptionCallable; + private final UnaryCallable modifyAckDeadlineCallable; + private final UnaryCallable acknowledgeCallable; + private final UnaryCallable pullCallable; + private final UnaryCallable modifyPushConfigCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable testIamPermissionsCallable; private static final PathTemplate PROJECT_PATH_TEMPLATE = @@ -202,29 +201,29 @@ protected SubscriberApi(SubscriberSettings settings) throws IOException { this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.createSubscriptionCallable = - ApiCallable.create(settings.createSubscriptionSettings(), this.channel, this.executor); + UnaryCallable.create(settings.createSubscriptionSettings(), this.channel, this.executor); this.getSubscriptionCallable = - ApiCallable.create(settings.getSubscriptionSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getSubscriptionSettings(), this.channel, this.executor); this.listSubscriptionsCallable = - ApiCallable.create(settings.listSubscriptionsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listSubscriptionsSettings(), this.channel, this.executor); this.listSubscriptionsPagedCallable = - ApiCallable.createPagedVariant( + UnaryCallable.createPagedVariant( settings.listSubscriptionsSettings(), this.channel, this.executor); this.deleteSubscriptionCallable = - ApiCallable.create(settings.deleteSubscriptionSettings(), this.channel, this.executor); + UnaryCallable.create(settings.deleteSubscriptionSettings(), this.channel, this.executor); this.modifyAckDeadlineCallable = - ApiCallable.create(settings.modifyAckDeadlineSettings(), this.channel, this.executor); + UnaryCallable.create(settings.modifyAckDeadlineSettings(), this.channel, this.executor); this.acknowledgeCallable = - ApiCallable.create(settings.acknowledgeSettings(), this.channel, this.executor); - this.pullCallable = ApiCallable.create(settings.pullSettings(), this.channel, this.executor); + UnaryCallable.create(settings.acknowledgeSettings(), this.channel, this.executor); + this.pullCallable = UnaryCallable.create(settings.pullSettings(), this.channel, this.executor); this.modifyPushConfigCallable = - ApiCallable.create(settings.modifyPushConfigSettings(), this.channel, this.executor); + UnaryCallable.create(settings.modifyPushConfigSettings(), this.channel, this.executor); this.setIamPolicyCallable = - ApiCallable.create(settings.setIamPolicySettings(), this.channel, this.executor); + UnaryCallable.create(settings.setIamPolicySettings(), this.channel, this.executor); this.getIamPolicyCallable = - ApiCallable.create(settings.getIamPolicySettings(), this.channel, this.executor); + UnaryCallable.create(settings.getIamPolicySettings(), this.channel, this.executor); this.testIamPermissionsCallable = - ApiCallable.create(settings.testIamPermissionsSettings(), this.channel, this.executor); + UnaryCallable.create(settings.testIamPermissionsSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -365,7 +364,7 @@ public final Subscription createSubscription(Subscription request) { * } * */ - public final ApiCallable createSubscriptionCallable() { + public final UnaryCallable createSubscriptionCallable() { return createSubscriptionCallable; } @@ -433,7 +432,7 @@ private final Subscription getSubscription(GetSubscriptionRequest request) { * } * */ - public final ApiCallable getSubscriptionCallable() { + public final UnaryCallable getSubscriptionCallable() { return getSubscriptionCallable; } @@ -455,8 +454,7 @@ public final ApiCallable getSubscriptionCa * @param project The name of the cloud project that subscriptions belong to. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse - listSubscriptions(String project) { + public final ListSubscriptionsPagedResponse listSubscriptions(String project) { PROJECT_PATH_TEMPLATE.validate(project, "listSubscriptions"); ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder().setProject(project).build(); @@ -484,8 +482,7 @@ public final ApiCallable getSubscriptionCa * @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 PagedListResponse - listSubscriptions(ListSubscriptionsRequest request) { + public final ListSubscriptionsPagedResponse listSubscriptions(ListSubscriptionsRequest request) { return listSubscriptionsPagedCallable().call(request); } @@ -501,7 +498,7 @@ public final ApiCallable getSubscriptionCa * ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder() * .setProject(formattedProject) * .build(); - * ListenableFuture<PagedListResponse<ListSubscriptionsRequest,ListSubscriptionsResponse,Subscription>> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request); + * ListenableFuture<ListSubscriptionsPagedResponse> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request); * // Do something * for (Subscription element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -509,9 +506,7 @@ public final ApiCallable getSubscriptionCa * } * */ - public final ApiCallable< - ListSubscriptionsRequest, - PagedListResponse> + public final UnaryCallable listSubscriptionsPagedCallable() { return listSubscriptionsPagedCallable; } @@ -543,7 +538,7 @@ public final ApiCallable getSubscriptionCa * } * */ - public final ApiCallable + public final UnaryCallable listSubscriptionsCallable() { return listSubscriptionsCallable; } @@ -621,7 +616,7 @@ private final void deleteSubscription(DeleteSubscriptionRequest request) { * } * */ - public final ApiCallable deleteSubscriptionCallable() { + public final UnaryCallable deleteSubscriptionCallable() { return deleteSubscriptionCallable; } @@ -718,7 +713,7 @@ public final void modifyAckDeadline(ModifyAckDeadlineRequest request) { * } * */ - public final ApiCallable modifyAckDeadlineCallable() { + public final UnaryCallable modifyAckDeadlineCallable() { return modifyAckDeadlineCallable; } @@ -805,7 +800,7 @@ public final void acknowledge(AcknowledgeRequest request) { * } * */ - public final ApiCallable acknowledgeCallable() { + public final UnaryCallable acknowledgeCallable() { return acknowledgeCallable; } @@ -895,7 +890,7 @@ public final PullResponse pull(PullRequest request) { * } * */ - public final ApiCallable pullCallable() { + public final UnaryCallable pullCallable() { return pullCallable; } @@ -990,7 +985,7 @@ public final void modifyPushConfig(ModifyPushConfigRequest request) { * } * */ - public final ApiCallable modifyPushConfigCallable() { + public final UnaryCallable modifyPushConfigCallable() { return modifyPushConfigCallable; } @@ -1008,11 +1003,12 @@ public final ApiCallable modifyPushConfigCallabl * } * * - * @param resource REQUIRED: The resource for which policy is being specified. Resource is usually - * specified as a path, such as, projects/{project}/zones/{zone}/disks/{disk}. - * @param policy REQUIRED: The complete policy to be applied to the 'resource'. The size of the - * policy is limited to a few 10s of KB. An empty policy is in general a valid policy but - * certain services (like Projects) might reject them. + * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is + * usually specified as a path. For example, a Project resource is specified as + * `projects/{project}`. + * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the + * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud + * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { @@ -1067,14 +1063,14 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) { * } * */ - public final ApiCallable setIamPolicyCallable() { + public final UnaryCallable setIamPolicyCallable() { return setIamPolicyCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets the access control policy for a resource. Is empty if the policy or the resource does not - * exist. + * Gets the access control policy for a resource. Returns an empty policy if the resource exists + * and does not have a policy set. * *

    Sample code: * @@ -1085,8 +1081,9 @@ public final ApiCallable setIamPolicyCallable() { * } * * - * @param resource REQUIRED: The resource for which policy is being requested. Resource is usually - * specified as a path, such as, projects/{project}. + * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is + * usually specified as a path. For example, a Project resource is specified as + * `projects/{project}`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { @@ -1097,8 +1094,8 @@ public final Policy getIamPolicy(String resource) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets the access control policy for a resource. Is empty if the policy or the resource does not - * exist. + * Gets the access control policy for a resource. Returns an empty policy if the resource exists + * and does not have a policy set. * *

    Sample code: * @@ -1121,8 +1118,8 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Gets the access control policy for a resource. Is empty if the policy or the resource does not - * exist. + * Gets the access control policy for a resource. Returns an empty policy if the resource exists + * and does not have a policy set. * *

    Sample code: * @@ -1138,7 +1135,7 @@ private final Policy getIamPolicy(GetIamPolicyRequest request) { * } * */ - public final ApiCallable getIamPolicyCallable() { + public final UnaryCallable getIamPolicyCallable() { return getIamPolicyCallable; } @@ -1156,10 +1153,12 @@ public final ApiCallable getIamPolicyCallable() { * } * * - * @param resource REQUIRED: The resource for which policy detail is being requested. Resource is - * usually specified as a path, such as, projects/{project}. - * @param permissions The set of permissions to check for the 'resource'. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. + * @param resource REQUIRED: The resource for which the policy detail is being requested. + * `resource` is usually specified as a path. For example, a Project resource is specified as + * `projects/{project}`. + * @param permissions The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more information see + * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final TestIamPermissionsResponse testIamPermissions( @@ -1218,7 +1217,7 @@ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsReq * } * */ - public final ApiCallable + public final UnaryCallable testIamPermissionsCallable() { return testIamPermissionsCallable; } 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 4396e5b692f9..b8f949f1a6e2 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 @@ -13,13 +13,18 @@ */ package com.google.cloud.pubsub.spi.v1; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse; + import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -92,18 +97,10 @@ public class SubscriberSettings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/pubsub") .build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings createSubscriptionSettings; private final SimpleCallSettings getSubscriptionSettings; - private final PageStreamingCallSettings< - ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> + private final PagedCallSettings< + ListSubscriptionsRequest, ListSubscriptionsResponse, ListSubscriptionsPagedResponse> listSubscriptionsSettings; private final SimpleCallSettings deleteSubscriptionSettings; private final SimpleCallSettings modifyAckDeadlineSettings; @@ -126,8 +123,8 @@ public SimpleCallSettings getSubscriptionS } /** Returns the object with the settings used for calls to listSubscriptions. */ - public PageStreamingCallSettings< - ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> + public PagedCallSettings< + ListSubscriptionsRequest, ListSubscriptionsResponse, ListSubscriptionsPagedResponse> listSubscriptionsSettings() { return listSubscriptionsSettings; } @@ -225,10 +222,10 @@ private SubscriberSettings(Builder settingsBuilder) throws IOException { testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } - private static final PageStreamingDescriptor< + private static final PagedListDescriptor< ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> LIST_SUBSCRIPTIONS_PAGE_STR_DESC = - new PageStreamingDescriptor< + new PagedListDescriptor< ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription>() { @Override public Object emptyToken() { @@ -265,15 +262,31 @@ public Iterable extractResources(ListSubscriptionsResponse payload } }; + private static final PagedListResponseFactory< + ListSubscriptionsRequest, ListSubscriptionsResponse, ListSubscriptionsPagedResponse> + LIST_SUBSCRIPTIONS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListSubscriptionsRequest, ListSubscriptionsResponse, + ListSubscriptionsPagedResponse>() { + @Override + public ListSubscriptionsPagedResponse createPagedListResponse( + UnaryCallable callable, + ListSubscriptionsRequest request, + CallContext context) { + return new ListSubscriptionsPagedResponse( + callable, LIST_SUBSCRIPTIONS_PAGE_STR_DESC, request, context); + } + }; + /** Builder for SubscriberSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder createSubscriptionSettings; private final SimpleCallSettings.Builder getSubscriptionSettings; - private final PageStreamingCallSettings.Builder< - ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> + private final PagedCallSettings.Builder< + ListSubscriptionsRequest, ListSubscriptionsResponse, ListSubscriptionsPagedResponse> listSubscriptionsSettings; private final SimpleCallSettings.Builder deleteSubscriptionSettings; @@ -330,7 +343,7 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); createSubscriptionSettings = SimpleCallSettings.newBuilder(SubscriberGrpc.METHOD_CREATE_SUBSCRIPTION); @@ -339,8 +352,8 @@ private Builder() { SimpleCallSettings.newBuilder(SubscriberGrpc.METHOD_GET_SUBSCRIPTION); listSubscriptionsSettings = - PageStreamingCallSettings.newBuilder( - SubscriberGrpc.METHOD_LIST_SUBSCRIPTIONS, LIST_SUBSCRIPTIONS_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + SubscriberGrpc.METHOD_LIST_SUBSCRIPTIONS, LIST_SUBSCRIPTIONS_PAGE_STR_FACT); deleteSubscriptionSettings = SimpleCallSettings.newBuilder(SubscriberGrpc.METHOD_DELETE_SUBSCRIPTION); @@ -362,8 +375,8 @@ private Builder() { testIamPermissionsSettings = SimpleCallSettings.newBuilder(IAMPolicyGrpc.METHOD_TEST_IAM_PERMISSIONS); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( createSubscriptionSettings, getSubscriptionSettings, listSubscriptionsSettings, @@ -453,8 +466,8 @@ private Builder(SubscriberSettings settings) { getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( createSubscriptionSettings, getSubscriptionSettings, listSubscriptionsSettings, @@ -468,9 +481,16 @@ private Builder(SubscriberSettings settings) { testIamPermissionsSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -516,11 +536,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } @@ -536,8 +559,8 @@ public SimpleCallSettings.Builder createSubscription } /** Returns the builder for the settings used for calls to listSubscriptions. */ - public PageStreamingCallSettings.Builder< - ListSubscriptionsRequest, ListSubscriptionsResponse, Subscription> + public PagedCallSettings.Builder< + ListSubscriptionsRequest, ListSubscriptionsResponse, ListSubscriptionsPagedResponse> listSubscriptionsSettings() { return listSubscriptionsSettings; } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/package-info.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/package-info.java index 99a7c0144671..da182b630ccb 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/package-info.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/package-info.java @@ -15,7 +15,7 @@ /** * A client to Google Cloud Pub/Sub API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    ============ PublisherApi ============ * 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 7d76c1a27111..54b07c63362d 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 @@ -14,7 +14,9 @@ package com.google.cloud.pubsub.spi.v1; -import com.google.api.gax.core.PagedListResponse; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse; + import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -173,8 +175,7 @@ public void listTopicsTest() { String formattedProject = PublisherApi.formatProjectName("[PROJECT]"); - PagedListResponse pagedListResponse = - api.listTopics(formattedProject); + ListTopicsPagedResponse pagedListResponse = api.listTopics(formattedProject); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); @@ -204,8 +205,8 @@ public void listTopicSubscriptionsTest() { String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]"); - PagedListResponse - pagedListResponse = api.listTopicSubscriptions(formattedTopic); + ListTopicSubscriptionsPagedResponse pagedListResponse = + api.listTopicSubscriptions(formattedTopic); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); 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 28e25b421ac7..1fa6597ab0db 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 @@ -14,7 +14,8 @@ package com.google.cloud.pubsub.spi.v1; -import com.google.api.gax.core.PagedListResponse; +import static com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse; + import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -169,8 +170,7 @@ public void listSubscriptionsTest() { String formattedProject = SubscriberApi.formatProjectName("[PROJECT]"); - PagedListResponse - pagedListResponse = api.listSubscriptions(formattedProject); + ListSubscriptionsPagedResponse pagedListResponse = api.listSubscriptions(formattedProject); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/PagedResponseWrappers.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/PagedResponseWrappers.java new file mode 100644 index 000000000000..1a294b7d2870 --- /dev/null +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/PagedResponseWrappers.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.speech.spi.v1beta1; + + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers {} diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechApi.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechApi.java index 9ce5e2917edc..1423c4d3afa7 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechApi.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechApi.java @@ -13,10 +13,13 @@ */ package com.google.cloud.speech.spi.v1beta1; -import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.StreamingCallable; +import com.google.api.gax.grpc.UnaryCallable; import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest; import com.google.cloud.speech.v1beta1.RecognitionAudio; import com.google.cloud.speech.v1beta1.RecognitionConfig; +import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; +import com.google.cloud.speech.v1beta1.StreamingRecognizeResponse; import com.google.cloud.speech.v1beta1.SyncRecognizeRequest; import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; import com.google.longrunning.Operation; @@ -57,8 +60,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -86,8 +89,10 @@ public class SpeechApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable syncRecognizeCallable; - private final ApiCallable asyncRecognizeCallable; + private final UnaryCallable syncRecognizeCallable; + private final UnaryCallable asyncRecognizeCallable; + private final StreamingCallable + streamingRecognizeCallable; /** Constructs an instance of SpeechApi with default settings. */ public static final SpeechApi create() throws IOException { @@ -112,9 +117,11 @@ protected SpeechApi(SpeechSettings settings) throws IOException { this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.syncRecognizeCallable = - ApiCallable.create(settings.syncRecognizeSettings(), this.channel, this.executor); + UnaryCallable.create(settings.syncRecognizeSettings(), this.channel, this.executor); this.asyncRecognizeCallable = - ApiCallable.create(settings.asyncRecognizeSettings(), this.channel, this.executor); + UnaryCallable.create(settings.asyncRecognizeSettings(), this.channel, this.executor); + this.streamingRecognizeCallable = + StreamingCallable.create(settings.streamingRecognizeSettings(), this.channel); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -214,7 +221,7 @@ public final SyncRecognizeResponse syncRecognize(SyncRecognizeRequest request) { * } * */ - public final ApiCallable syncRecognizeCallable() { + public final UnaryCallable syncRecognizeCallable() { return syncRecognizeCallable; } @@ -294,10 +301,49 @@ public final Operation asyncRecognize(AsyncRecognizeRequest request) { * } * */ - public final ApiCallable asyncRecognizeCallable() { + public final UnaryCallable asyncRecognizeCallable() { return asyncRecognizeCallable; } + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Perform bidirectional streaming speech-recognition: receive results while sending audio. This + * method is only available via the gRPC API (not REST). + * + *

    Sample code: + * + *

    
    +   * try (SpeechApi speechApi = SpeechApi.create()) {
    +   *   StreamObserver<StreamingRecognizeResponse> responseObserver =
    +   *       new StreamObserver<StreamingRecognizeResponse>() {
    +   *         @Override
    +   *         public void onNext(StreamingRecognizeResponse response) {
    +   *           // Do something when receive a response
    +   *         }
    +   *
    +   *         @Override
    +   *         public void onError(Throwable t) {
    +   *           // Add error-handling
    +   *         }
    +   *
    +   *         @Override
    +   *         public void onCompleted() {
    +   *           // Do something when complete.
    +   *         }
    +   *       };
    +   *   StreamObserver<StreamingRecognizeRequest> requestObserver =
    +   *       speechApi.streamingRecognizeCallable().bidiStreamingCall(responseObserver)});
    +   *
    +   *   StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
    +   *   requestObserver.onNext(request);
    +   * }
    +   * 
    + */ + public final StreamingCallable + streamingRecognizeCallable() { + return streamingRecognizeCallable; + } + /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java index ed78555815e4..ffe6c6adfede 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java @@ -15,12 +15,15 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.StreamingCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest; import com.google.cloud.speech.v1beta1.SpeechGrpc; +import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; +import com.google.cloud.speech.v1beta1.StreamingRecognizeResponse; import com.google.cloud.speech.v1beta1.SyncRecognizeRequest; import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; import com.google.common.collect.ImmutableList; @@ -74,17 +77,11 @@ public class SpeechSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings syncRecognizeSettings; private final SimpleCallSettings asyncRecognizeSettings; + private final StreamingCallSettings + streamingRecognizeSettings; /** Returns the object with the settings used for calls to syncRecognize. */ public SimpleCallSettings syncRecognizeSettings() { @@ -96,6 +93,12 @@ public SimpleCallSettings asyncRecognizeSettin return asyncRecognizeSettings; } + /** Returns the object with the settings used for calls to streamingRecognize. */ + public StreamingCallSettings + streamingRecognizeSettings() { + return streamingRecognizeSettings; + } + /** Returns the default service address. */ public static String getDefaultServiceAddress() { return DEFAULT_SERVICE_ADDRESS; @@ -137,16 +140,20 @@ private SpeechSettings(Builder settingsBuilder) throws IOException { syncRecognizeSettings = settingsBuilder.syncRecognizeSettings().build(); asyncRecognizeSettings = settingsBuilder.asyncRecognizeSettings().build(); + streamingRecognizeSettings = settingsBuilder.streamingRecognizeSettings().build(); } /** Builder for SpeechSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder syncRecognizeSettings; private final SimpleCallSettings.Builder asyncRecognizeSettings; + private final StreamingCallSettings.Builder< + StreamingRecognizeRequest, StreamingRecognizeResponse> + streamingRecognizeSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -180,14 +187,18 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); syncRecognizeSettings = SimpleCallSettings.newBuilder(SpeechGrpc.METHOD_SYNC_RECOGNIZE); asyncRecognizeSettings = SimpleCallSettings.newBuilder(SpeechGrpc.METHOD_ASYNC_RECOGNIZE); - methodSettingsBuilders = - ImmutableList.of(syncRecognizeSettings, asyncRecognizeSettings); + streamingRecognizeSettings = + StreamingCallSettings.newBuilder(SpeechGrpc.METHOD_STREAMING_RECOGNIZE); + + unaryMethodSettingsBuilders = + ImmutableList.of( + syncRecognizeSettings, asyncRecognizeSettings); } private static Builder createDefault() { @@ -211,14 +222,23 @@ private Builder(SpeechSettings settings) { syncRecognizeSettings = settings.syncRecognizeSettings.toBuilder(); asyncRecognizeSettings = settings.asyncRecognizeSettings.toBuilder(); + streamingRecognizeSettings = settings.streamingRecognizeSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of(syncRecognizeSettings, asyncRecognizeSettings); + unaryMethodSettingsBuilders = + ImmutableList.of( + syncRecognizeSettings, asyncRecognizeSettings); + } + + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); } @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -264,11 +284,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } @@ -283,6 +306,12 @@ public SimpleCallSettings.Builder asyncRecogni return asyncRecognizeSettings; } + /** Returns the builder for the settings used for calls to streamingRecognize. */ + public StreamingCallSettings.Builder + streamingRecognizeSettings() { + return streamingRecognizeSettings; + } + @Override public SpeechSettings build() throws IOException { return new SpeechSettings(this); diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/package-info.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/package-info.java index e7348c17639b..392ceaa0b50b 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/package-info.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/package-info.java @@ -15,7 +15,7 @@ /** * A client to Google Cloud Speech API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    ========= SpeechApi ========= * diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java index a33911f8274b..5ac9a8fe8f21 100644 --- a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java @@ -72,8 +72,25 @@ public void asyncRecognize( @Override public StreamObserver streamingRecognize( - StreamObserver responseObserver) { - System.err.println("Streaming method is not supported."); - return null; + final StreamObserver responseObserver) { + final StreamingRecognizeResponse response = (StreamingRecognizeResponse) responses.remove(); + StreamObserver requestObserver = + new StreamObserver() { + @Override + public void onNext(StreamingRecognizeRequest value) { + responseObserver.onNext(response); + } + + @Override + public void onError(Throwable t) { + responseObserver.onError(t); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + return requestObserver; } } diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java index c59e64f80ddc..d75176903fdf 100644 --- a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java @@ -14,15 +14,20 @@ package com.google.cloud.speech.spi.v1beta1; +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.cloud.speech.v1beta1.AsyncRecognizeRequest; import com.google.cloud.speech.v1beta1.RecognitionAudio; import com.google.cloud.speech.v1beta1.RecognitionConfig; +import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; +import com.google.cloud.speech.v1beta1.StreamingRecognizeResponse; import com.google.cloud.speech.v1beta1.SyncRecognizeRequest; import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; import com.google.longrunning.Operation; import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -113,4 +118,31 @@ public void asyncRecognizeTest() { Assert.assertEquals(config, actualRequest.getConfig()); Assert.assertEquals(audio, actualRequest.getAudio()); } + + @Test + @SuppressWarnings("all") + public void streamingRecognizeTest() throws Exception { + int resultIndex = 520358448; + StreamingRecognizeResponse expectedResponse = + StreamingRecognizeResponse.newBuilder().setResultIndex(resultIndex).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockSpeech.setResponses(expectedResponses); + StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + StreamingCallable callable = + api.streamingRecognizeCallable(); + 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)); + Assert.assertEquals(0, responseObserver.errors().size()); + } } diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/PagedResponseWrappers.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/PagedResponseWrappers.java new file mode 100644 index 000000000000..a13a250ba1e8 --- /dev/null +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/PagedResponseWrappers.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.trace.spi.v1; + +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseImpl; +import com.google.api.gax.grpc.UnaryCallable; +import com.google.devtools.cloudtrace.v1.ListTracesRequest; +import com.google.devtools.cloudtrace.v1.ListTracesResponse; +import com.google.devtools.cloudtrace.v1.Trace; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers { + + public static class ListTracesPagedResponse + extends PagedListResponseImpl { + + public ListTracesPagedResponse( + UnaryCallable callable, + PagedListDescriptor pageDescriptor, + ListTracesRequest request, + CallContext context) { + super(callable, pageDescriptor, request, context); + } + } +} diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java index d990e788a3b6..681bdcb89548 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java @@ -13,8 +13,9 @@ */ package com.google.cloud.trace.spi.v1; -import com.google.api.gax.core.PagedListResponse; -import com.google.api.gax.grpc.ApiCallable; +import static com.google.cloud.trace.spi.v1.PagedResponseWrappers.ListTracesPagedResponse; + +import com.google.api.gax.grpc.UnaryCallable; import com.google.devtools.cloudtrace.v1.GetTraceRequest; import com.google.devtools.cloudtrace.v1.ListTracesRequest; import com.google.devtools.cloudtrace.v1.ListTracesResponse; @@ -62,8 +63,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -91,12 +92,10 @@ public class TraceServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable patchTracesCallable; - private final ApiCallable getTraceCallable; - private final ApiCallable listTracesCallable; - private final ApiCallable< - ListTracesRequest, PagedListResponse> - listTracesPagedCallable; + private final UnaryCallable patchTracesCallable; + private final UnaryCallable getTraceCallable; + private final UnaryCallable listTracesCallable; + private final UnaryCallable listTracesPagedCallable; /** Constructs an instance of TraceServiceApi with default settings. */ public static final TraceServiceApi create() throws IOException { @@ -121,13 +120,14 @@ protected TraceServiceApi(TraceServiceSettings settings) throws IOException { this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.patchTracesCallable = - ApiCallable.create(settings.patchTracesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.patchTracesSettings(), this.channel, this.executor); this.getTraceCallable = - ApiCallable.create(settings.getTraceSettings(), this.channel, this.executor); + UnaryCallable.create(settings.getTraceSettings(), this.channel, this.executor); this.listTracesCallable = - ApiCallable.create(settings.listTracesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.listTracesSettings(), this.channel, this.executor); this.listTracesPagedCallable = - ApiCallable.createPagedVariant(settings.listTracesSettings(), this.channel, this.executor); + UnaryCallable.createPagedVariant( + settings.listTracesSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -155,8 +155,8 @@ public final TraceServiceSettings getSettings() { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Sends new traces to Cloud Trace or updates existing traces. If the ID of a trace that you send - * matches that of an existing trace, any fields in the existing trace and its spans are + * Sends new traces to Stackdriver Trace or updates existing traces. If the ID of a trace that you + * send matches that of an existing trace, any fields in the existing trace and its spans are * overwritten by the provided values, and any new fields provided are merged with the existing * trace data. If the ID does not match, a new trace is created. * @@ -182,8 +182,8 @@ public final void patchTraces(String projectId, Traces traces) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Sends new traces to Cloud Trace or updates existing traces. If the ID of a trace that you send - * matches that of an existing trace, any fields in the existing trace and its spans are + * Sends new traces to Stackdriver Trace or updates existing traces. If the ID of a trace that you + * send matches that of an existing trace, any fields in the existing trace and its spans are * overwritten by the provided values, and any new fields provided are merged with the existing * trace data. If the ID does not match, a new trace is created. * @@ -210,8 +210,8 @@ public final void patchTraces(PatchTracesRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Sends new traces to Cloud Trace or updates existing traces. If the ID of a trace that you send - * matches that of an existing trace, any fields in the existing trace and its spans are + * Sends new traces to Stackdriver Trace or updates existing traces. If the ID of a trace that you + * send matches that of an existing trace, any fields in the existing trace and its spans are * overwritten by the provided values, and any new fields provided are merged with the existing * trace data. If the ID does not match, a new trace is created. * @@ -231,7 +231,7 @@ public final void patchTraces(PatchTracesRequest request) { * } * */ - public final ApiCallable patchTracesCallable() { + public final UnaryCallable patchTracesCallable() { return patchTracesCallable; } @@ -304,7 +304,7 @@ private final Trace getTrace(GetTraceRequest request) { * } * */ - public final ApiCallable getTraceCallable() { + public final UnaryCallable getTraceCallable() { return getTraceCallable; } @@ -326,8 +326,7 @@ public final ApiCallable getTraceCallable() { * @param projectId ID of the Cloud project where the trace data is stored. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PagedListResponse listTraces( - String projectId) { + public final ListTracesPagedResponse listTraces(String projectId) { ListTracesRequest request = ListTracesRequest.newBuilder().setProjectId(projectId).build(); return listTraces(request); } @@ -353,8 +352,7 @@ public final PagedListResponse lis * @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 PagedListResponse listTraces( - ListTracesRequest request) { + public final ListTracesPagedResponse listTraces(ListTracesRequest request) { return listTracesPagedCallable().call(request); } @@ -370,7 +368,7 @@ public final PagedListResponse lis * ListTracesRequest request = ListTracesRequest.newBuilder() * .setProjectId(projectId) * .build(); - * ListenableFuture<PagedListResponse<ListTracesRequest,ListTracesResponse,Trace>> future = traceServiceApi.listTracesPagedCallable().futureCall(request); + * ListenableFuture<ListTracesPagedResponse> future = traceServiceApi.listTracesPagedCallable().futureCall(request); * // Do something * for (Trace element : future.get().iterateAllElements()) { * // doThingsWith(element); @@ -378,9 +376,7 @@ public final PagedListResponse lis * } * */ - public final ApiCallable< - ListTracesRequest, PagedListResponse> - listTracesPagedCallable() { + public final UnaryCallable listTracesPagedCallable() { return listTracesPagedCallable; } @@ -411,7 +407,7 @@ public final PagedListResponse lis * } * */ - public final ApiCallable listTracesCallable() { + public final UnaryCallable listTracesCallable() { return listTracesCallable; } diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java index 698295f4b86b..68d5f9a45025 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java @@ -13,13 +13,18 @@ */ package com.google.cloud.trace.spi.v1; +import static com.google.cloud.trace.spi.v1.PagedResponseWrappers.ListTracesPagedResponse; + import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.PageStreamingCallSettings; -import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.CallContext; +import com.google.api.gax.grpc.PagedCallSettings; +import com.google.api.gax.grpc.PagedListDescriptor; +import com.google.api.gax.grpc.PagedListResponseFactory; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; +import com.google.api.gax.grpc.UnaryCallable; import com.google.auth.Credentials; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -82,17 +87,9 @@ public class TraceServiceSettings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/trace.readonly") .build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings patchTracesSettings; private final SimpleCallSettings getTraceSettings; - private final PageStreamingCallSettings + private final PagedCallSettings listTracesSettings; /** Returns the object with the settings used for calls to patchTraces. */ @@ -106,7 +103,7 @@ public SimpleCallSettings getTraceSettings() { } /** Returns the object with the settings used for calls to listTraces. */ - public PageStreamingCallSettings + public PagedCallSettings listTracesSettings() { return listTracesSettings; } @@ -155,9 +152,9 @@ private TraceServiceSettings(Builder settingsBuilder) throws IOException { listTracesSettings = settingsBuilder.listTracesSettings().build(); } - private static final PageStreamingDescriptor + private static final PagedListDescriptor LIST_TRACES_PAGE_STR_DESC = - new PageStreamingDescriptor() { + new PagedListDescriptor() { @Override public Object emptyToken() { return ""; @@ -191,13 +188,29 @@ public Iterable extractResources(ListTracesResponse payload) { } }; + private static final PagedListResponseFactory< + ListTracesRequest, ListTracesResponse, ListTracesPagedResponse> + LIST_TRACES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListTracesRequest, ListTracesResponse, ListTracesPagedResponse>() { + @Override + public ListTracesPagedResponse createPagedListResponse( + UnaryCallable callable, + ListTracesRequest request, + CallContext context) { + return new ListTracesPagedResponse( + callable, LIST_TRACES_PAGE_STR_DESC, request, context); + } + }; + /** Builder for TraceServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder patchTracesSettings; private final SimpleCallSettings.Builder getTraceSettings; - private final PageStreamingCallSettings.Builder + private final PagedCallSettings.Builder< + ListTracesRequest, ListTracesResponse, ListTracesPagedResponse> listTracesSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -232,18 +245,18 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); patchTracesSettings = SimpleCallSettings.newBuilder(TraceServiceGrpc.METHOD_PATCH_TRACES); getTraceSettings = SimpleCallSettings.newBuilder(TraceServiceGrpc.METHOD_GET_TRACE); listTracesSettings = - PageStreamingCallSettings.newBuilder( - TraceServiceGrpc.METHOD_LIST_TRACES, LIST_TRACES_PAGE_STR_DESC); + PagedCallSettings.newBuilder( + TraceServiceGrpc.METHOD_LIST_TRACES, LIST_TRACES_PAGE_STR_FACT); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( patchTracesSettings, getTraceSettings, listTracesSettings); } @@ -252,7 +265,7 @@ private static Builder createDefault() { builder .patchTracesSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); builder @@ -275,14 +288,21 @@ private Builder(TraceServiceSettings settings) { getTraceSettings = settings.getTraceSettings.toBuilder(); listTracesSettings = settings.listTracesSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of( + unaryMethodSettingsBuilders = + ImmutableList.of( patchTracesSettings, getTraceSettings, listTracesSettings); } + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); + } + @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -328,11 +348,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } @@ -347,7 +370,7 @@ public SimpleCallSettings.Builder getTraceSettings() { } /** Returns the builder for the settings used for calls to listTraces. */ - public PageStreamingCallSettings.Builder + public PagedCallSettings.Builder listTracesSettings() { return listTracesSettings; } diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java index ade6ff07dc7a..73666c4ec0f8 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java @@ -15,7 +15,7 @@ /** * A client to Stackdriver Trace API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    =============== TraceServiceApi =============== * diff --git a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java index c11b05b0c269..043d10f8f639 100644 --- a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java +++ b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java @@ -14,7 +14,8 @@ package com.google.cloud.trace.spi.v1; -import com.google.api.gax.core.PagedListResponse; +import static com.google.cloud.trace.spi.v1.PagedResponseWrappers.ListTracesPagedResponse; + import com.google.api.gax.testing.MockGrpcService; import com.google.api.gax.testing.MockServiceHelper; import com.google.common.collect.Lists; @@ -134,8 +135,7 @@ public void listTracesTest() { String projectId = "projectId-1969970175"; - PagedListResponse pagedListResponse = - api.listTraces(projectId); + ListTracesPagedResponse pagedListResponse = api.listTraces(projectId); List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorApi.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorApi.java index 58672211034a..05843467f51d 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorApi.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorApi.java @@ -13,7 +13,7 @@ */ package com.google.cloud.vision.spi.v1; -import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.grpc.UnaryCallable; import com.google.cloud.vision.v1.AnnotateImageRequest; import com.google.cloud.vision.v1.BatchAnnotateImagesRequest; import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; @@ -55,8 +55,8 @@ *

  • A "request object" method. This type of method only takes one parameter, a request object, * which must be constructed before the call. Not every API method will have a request object * method. - *
  • A "callable" method. This type of method takes no parameters and returns an immutable - * ApiCallable object, which can be used to initiate calls to the service. + *
  • A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. * * *

    See the individual methods for example code. @@ -84,7 +84,7 @@ public class ImageAnnotatorApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); - private final ApiCallable + private final UnaryCallable batchAnnotateImagesCallable; /** Constructs an instance of ImageAnnotatorApi with default settings. */ @@ -110,7 +110,7 @@ protected ImageAnnotatorApi(ImageAnnotatorSettings settings) throws IOException this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); this.batchAnnotateImagesCallable = - ApiCallable.create(settings.batchAnnotateImagesSettings(), this.channel, this.executor); + UnaryCallable.create(settings.batchAnnotateImagesSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -201,7 +201,7 @@ private final BatchAnnotateImagesResponse batchAnnotateImages( * } * */ - public final ApiCallable + public final UnaryCallable batchAnnotateImagesCallable() { return batchAnnotateImagesCallable; } diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorSettings.java index e23eb9a78f52..9d4177ce5642 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorSettings.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/ImageAnnotatorSettings.java @@ -15,9 +15,9 @@ import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; -import com.google.api.gax.grpc.ApiCallSettings; import com.google.api.gax.grpc.ServiceApiSettings; import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.api.gax.grpc.UnaryCallSettings; import com.google.auth.Credentials; import com.google.cloud.vision.v1.BatchAnnotateImagesRequest; import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; @@ -72,14 +72,6 @@ public class ImageAnnotatorSettings extends ServiceApiSettings { private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); - /** The default connection settings of the service. */ - public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = - ConnectionSettings.newBuilder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build(); - private final SimpleCallSettings batchAnnotateImagesSettings; @@ -133,7 +125,7 @@ private ImageAnnotatorSettings(Builder settingsBuilder) throws IOException { /** Builder for ImageAnnotatorSettings. */ public static class Builder extends ServiceApiSettings.Builder { - private final ImmutableList methodSettingsBuilders; + private final ImmutableList unaryMethodSettingsBuilders; private final SimpleCallSettings.Builder< BatchAnnotateImagesRequest, BatchAnnotateImagesResponse> @@ -171,13 +163,13 @@ public static class Builder extends ServiceApiSettings.Builder { } private Builder() { - super(DEFAULT_CONNECTION_SETTINGS); + super(s_getDefaultConnectionSettingsBuilder().build()); batchAnnotateImagesSettings = SimpleCallSettings.newBuilder(ImageAnnotatorGrpc.METHOD_BATCH_ANNOTATE_IMAGES); - methodSettingsBuilders = - ImmutableList.of(batchAnnotateImagesSettings); + unaryMethodSettingsBuilders = + ImmutableList.of(batchAnnotateImagesSettings); } private static Builder createDefault() { @@ -196,13 +188,20 @@ private Builder(ImageAnnotatorSettings settings) { batchAnnotateImagesSettings = settings.batchAnnotateImagesSettings.toBuilder(); - methodSettingsBuilders = - ImmutableList.of(batchAnnotateImagesSettings); + unaryMethodSettingsBuilders = + ImmutableList.of(batchAnnotateImagesSettings); + } + + private static ConnectionSettings.Builder s_getDefaultConnectionSettingsBuilder() { + return ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES); } @Override - protected ConnectionSettings getDefaultConnectionSettings() { - return DEFAULT_CONNECTION_SETTINGS; + protected ConnectionSettings.Builder getDefaultConnectionSettingsBuilder() { + return s_getDefaultConnectionSettingsBuilder(); } @Override @@ -248,11 +247,14 @@ public Builder setClientLibHeader(String name, String version) { } /** - * Applies the given settings to all of the API methods in this service. Only values that are - * non-null will be applied, so this method is not capable of un-setting any values. + * Applies the given settings to all of the unary API methods in this service. Only values that + * are non-null will be applied, so this method is not capable of un-setting any values. + * + *

    Note: This method does not support applying settings to streaming methods. */ - public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { - super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + public Builder applyToAllApiMethods(UnaryCallSettings.Builder apiCallSettings) + throws Exception { + super.applyToAllApiMethods(unaryMethodSettingsBuilders, apiCallSettings); return this; } diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/PagedResponseWrappers.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/PagedResponseWrappers.java new file mode 100644 index 000000000000..c6501d1fba69 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/PagedResponseWrappers.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.vision.spi.v1; + + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@javax.annotation.Generated("by GAPIC") +public class PagedResponseWrappers {} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/package-info.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/package-info.java index 96458058a2f6..078a9a31bb4b 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/package-info.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/spi/v1/package-info.java @@ -15,7 +15,7 @@ /** * A client to Google Cloud Vision API. * - *

    The interfaces provided are listed below, along with a usage sample + *

    The interfaces provided are listed below, along with usage samples. * *

    ================= ImageAnnotatorApi ================= *