From ad3a0afec152dc6355ef565e9886643c25dd04f6 Mon Sep 17 00:00:00 2001 From: Michael Bausor Date: Mon, 11 Apr 2016 13:41:06 -0700 Subject: [PATCH] Regenerated logging service Regenerated java logging service Updated pom to reference gax 0.0.9 --- .../logging/spi/v2/ConfigServiceV2Api.java | 258 +++++----- .../spi/v2/ConfigServiceV2Settings.java | 374 ++++++++------- .../logging/spi/v2/LoggingServiceV2Api.java | 328 ++++++------- .../spi/v2/LoggingServiceV2Settings.java | 441 ++++++++--------- .../logging/spi/v2/MetricsServiceV2Api.java | 258 +++++----- .../spi/v2/MetricsServiceV2Settings.java | 380 ++++++++------- gcloud-java-logging/pom.xml | 2 +- .../logging/spi/v2/ConfigServiceV2Api.java | 258 +++++----- .../spi/v2/ConfigServiceV2Settings.java | 375 ++++++++------- .../logging/spi/v2/LoggingServiceV2Api.java | 328 ++++++------- .../spi/v2/LoggingServiceV2Settings.java | 442 +++++++++--------- .../logging/spi/v2/MetricsServiceV2Api.java | 258 +++++----- .../spi/v2/MetricsServiceV2Settings.java | 381 ++++++++------- .../spi/v2/LoggingServiceV2ApiTest.java | 11 +- 14 files changed, 2089 insertions(+), 2005 deletions(-) diff --git a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java index 5c35c9c96c83..cce77bc7cafd 100644 --- a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java +++ b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java @@ -53,105 +53,13 @@ // AUTO-GENERATED DOCUMENTATION AND SERVICE - see instructions at the top of the file for editing. /** - * Service Description: See src/api/google/logging/v2/logging.proto for documentation + * Service Description: * * * */ @javax.annotation.Generated("by GAPIC") public class ConfigServiceV2Api implements AutoCloseable { - - public static class ResourceNames { - private ResourceNames() {} - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a sink resource. - * - * - * - */ - private static final PathTemplate SINK_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/sinks/{sink}"); - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a sink resource. - * - * - * - */ - public static final String formatSinkPath(String project, String sink) { - return SINK_PATH_TEMPLATE.instantiate("project", project, "sink", sink); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a sink resource. - * - * - * - */ - public static final String parseProjectFromSinkPath(String sinkPath) { - return SINK_PATH_TEMPLATE.parse(sinkPath).get("project"); - } - - /** - * Parses the sink from the given fully-qualified path which - * represents a sink resource. - * - * - * - */ - public static final String parseSinkFromSinkPath(String sinkPath) { - return SINK_PATH_TEMPLATE.parse(sinkPath).get("sink"); - } - } - - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -162,9 +70,66 @@ public static final String parseSinkFromSinkPath(String sinkPath) { private final ApiCallable updateSinkCallable; private final ApiCallable deleteSinkCallable; - // =============== - // Factory Methods - // =============== + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); + + private static final PathTemplate SINK_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/sinks/{sink}"); + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a sink resource. + * + * + * + */ + public static final String formatSinkName(String project, String sink) { + return SINK_PATH_TEMPLATE.instantiate("project", project, "sink", sink); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a sink resource. + * + * + * + */ + public static final String parseProjectFromSinkName(String sinkName) { + return SINK_PATH_TEMPLATE.parse(sinkName).get("project"); + } + + /** + * Parses the sink from the given fully-qualified path which + * represents a sink resource. + * + * + * + */ + public static final String parseSinkFromSinkName(String sinkName) { + return SINK_PATH_TEMPLATE.parse(sinkName).get("sink"); + } /** * Constructs an instance of ConfigServiceV2Api with default settings. @@ -172,24 +137,27 @@ public static final String parseSinkFromSinkPath(String sinkPath) { * * */ - public static ConfigServiceV2Api create() throws IOException { - return create(ConfigServiceV2Settings.create()); + public static final ConfigServiceV2Api defaultInstance() throws IOException { + return create(ConfigServiceV2Settings.defaultInstance()); } /** - * Constructs an instance of ConfigServiceV2Api, using the given settings. The channels are - * created based on the settings passed in, or defaults for any settings that are not set. + * Constructs an instance of ConfigServiceV2Api, 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 ConfigServiceV2Api create(ConfigServiceV2Settings settings) throws IOException { + public static final ConfigServiceV2Api create(ConfigServiceV2Settings settings) + throws IOException { return new ConfigServiceV2Api(settings); } /** - * Constructs an instance of ConfigServiceV2Api, using the given settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. + * Constructs an instance of ConfigServiceV2Api, using the given settings. + * This is protected so that it easy to make a subclass, but otherwise, the static + * factory methods should be preferred. * * * @@ -197,26 +165,25 @@ public static ConfigServiceV2Api create(ConfigServiceV2Settings settings) throws protected ConfigServiceV2Api(ConfigServiceV2Settings settings) throws IOException { this.channel = settings.getChannel(); - this.listSinksCallable = settings.listSinksMethod().build(settings); - this.listSinksIterableCallable = settings.listSinksMethod().buildPageStreaming(settings); - this.getSinkCallable = settings.getSinkMethod().build(settings); - this.createSinkCallable = settings.createSinkMethod().build(settings); - this.updateSinkCallable = settings.updateSinkMethod().build(settings); - this.deleteSinkCallable = settings.deleteSinkMethod().build(settings); - - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + this.listSinksCallable = ApiCallable.create(settings.listSinksSettings(), settings); + this.listSinksIterableCallable = + ApiCallable.createIterable(settings.listSinksSettings(), settings); + this.getSinkCallable = ApiCallable.create(settings.getSinkSettings(), settings); + this.createSinkCallable = ApiCallable.create(settings.createSinkSettings(), settings); + this.updateSinkCallable = ApiCallable.create(settings.updateSinkSettings(), settings); + this.deleteSinkCallable = ApiCallable.create(settings.deleteSinkSettings(), settings); + + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- listSinks ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -225,8 +192,12 @@ public void close() throws IOException { * * * + * + * @param projectName Required. The resource name of the project containing the sinks. + * Example: `"projects/my-logging-project"`, `"projects/01234567890"`. + * @throws ApiException if the remote call fails */ - public Iterable listSinks(String projectName) { + public final Iterable listSinks(String projectName) { ListSinksRequest request = ListSinksRequest.newBuilder().setProjectName(projectName).build(); return listSinks(request); } @@ -239,8 +210,9 @@ public Iterable listSinks(String projectName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listSinks(ListSinksRequest request) { + public final Iterable listSinks(ListSinksRequest request) { return listSinksIterableCallable().call(request); } @@ -250,8 +222,9 @@ public Iterable listSinks(ListSinksRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> listSinksIterableCallable() { + public final ApiCallable> listSinksIterableCallable() { return listSinksIterableCallable; } @@ -261,8 +234,9 @@ public ApiCallable> listSinksIterableCallabl * * * + * @throws ApiException if the remote call fails */ - public ApiCallable listSinksCallable() { + public final ApiCallable listSinksCallable() { return listSinksCallable; } @@ -277,8 +251,9 @@ public ApiCallable listSinksCallable() { * * @param sinkName The resource name of the sink to return. * Example: `"projects/my-project-id/sinks/my-sink-id"`. + * @throws ApiException if the remote call fails */ - public LogSink getSink(String sinkName) { + public final LogSink getSink(String sinkName) { GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(sinkName).build(); return getSink(request); @@ -292,6 +267,7 @@ public LogSink getSink(String sinkName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private LogSink getSink(GetSinkRequest request) { return getSinkCallable().call(request); @@ -303,8 +279,9 @@ private LogSink getSink(GetSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable getSinkCallable() { + public final ApiCallable getSinkCallable() { return getSinkCallable; } @@ -323,8 +300,9 @@ public ApiCallable getSinkCallable() { * The new sink must be provided in the request. * @param sink The new sink, which must not have an identifier that already * exists. + * @throws ApiException if the remote call fails */ - public LogSink createSink(String projectName, LogSink sink) { + public final LogSink createSink(String projectName, LogSink sink) { CreateSinkRequest request = CreateSinkRequest.newBuilder().setProjectName(projectName).setSink(sink).build(); @@ -339,6 +317,7 @@ public LogSink createSink(String projectName, LogSink sink) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogSink createSink(CreateSinkRequest request) { return createSinkCallable().call(request); @@ -350,8 +329,9 @@ public LogSink createSink(CreateSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable createSinkCallable() { + public final ApiCallable createSinkCallable() { return createSinkCallable; } @@ -373,8 +353,9 @@ public ApiCallable createSinkCallable() { * @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. + * @throws ApiException if the remote call fails */ - public LogSink updateSink(String sinkName, LogSink sink) { + public final LogSink updateSink(String sinkName, LogSink sink) { UpdateSinkRequest request = UpdateSinkRequest.newBuilder().setSinkName(sinkName).setSink(sink).build(); @@ -389,6 +370,7 @@ public LogSink updateSink(String sinkName, LogSink sink) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogSink updateSink(UpdateSinkRequest request) { return updateSinkCallable().call(request); @@ -400,8 +382,9 @@ public LogSink updateSink(UpdateSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable updateSinkCallable() { + public final ApiCallable updateSinkCallable() { return updateSinkCallable; } @@ -416,8 +399,9 @@ public ApiCallable updateSinkCallable() { * * @param sinkName The resource name of the sink to delete. * Example: `"projects/my-project-id/sinks/my-sink-id"`. + * @throws ApiException if the remote call fails */ - public void deleteSink(String sinkName) { + public final void deleteSink(String sinkName) { DeleteSinkRequest request = DeleteSinkRequest.newBuilder().setSinkName(sinkName).build(); deleteSink(request); @@ -431,6 +415,7 @@ public void deleteSink(String sinkName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private void deleteSink(DeleteSinkRequest request) { deleteSinkCallable().call(request); @@ -442,15 +427,12 @@ private void deleteSink(DeleteSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable deleteSinkCallable() { + public final ApiCallable deleteSinkCallable() { return deleteSinkCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -459,7 +441,7 @@ public ApiCallable deleteSinkCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java index b1248421141f..3569f2b175ec 100644 --- a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java +++ b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java @@ -33,14 +33,13 @@ package com.google.gcloud.logging.spi.v2; -import com.google.api.gax.core.BackoffParams; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.core.RetryParams; +import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; -import com.google.api.gax.grpc.PageDescriptor; +import com.google.api.gax.grpc.PageStreamingCallSettings; +import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; +import com.google.api.gax.grpc.SimpleCallSettings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -55,7 +54,11 @@ import com.google.logging.v2.LogSink; import com.google.logging.v2.UpdateSinkRequest; import com.google.protobuf.Empty; +import io.grpc.ManagedChannel; import io.grpc.Status; +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -63,10 +66,6 @@ @javax.annotation.Generated("by GAPIC") public class ConfigServiceV2Settings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -95,177 +94,68 @@ public class ConfigServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/cloud-platform") .build(); - 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 final PageStreamingCallSettings + listSinksSettings; - private static final ImmutableMap RETRY_PARAM_DEFINITIONS; - - static { - ImmutableMap.Builder definitions = ImmutableMap.builder(); - RetryParams params = null; - params = - RetryParams.newBuilder() - .setRetryBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(100L) - .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) - .build()) - .setTimeoutBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) - .build()) - .setTotalTimeout(30000L) - .build(); - definitions.put("default", params); - RETRY_PARAM_DEFINITIONS = definitions.build(); - } + private final SimpleCallSettings getSinkSettings; + private final SimpleCallSettings createSinkSettings; + private final SimpleCallSettings updateSinkSettings; + private final SimpleCallSettings deleteSinkSettings; - private static class MethodBuilders { - private final PageStreamingApiCallableBuilder - listSinksMethod; - private final ApiCallableBuilder getSinkMethod; - private final ApiCallableBuilder createSinkMethod; - private final ApiCallableBuilder updateSinkMethod; - private final ApiCallableBuilder deleteSinkMethod; - private final ImmutableList allMethods; - - public MethodBuilders() { - listSinksMethod = - new PageStreamingApiCallableBuilder<>( - ConfigServiceV2Grpc.METHOD_LIST_SINKS, LIST_SINKS_PAGE_STR_DESC); - listSinksMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listSinksMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - getSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_GET_SINK); - getSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - getSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - createSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_CREATE_SINK); - createSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - createSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - updateSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_UPDATE_SINK); - updateSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - updateSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - deleteSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_DELETE_SINK); - deleteSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - deleteSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - allMethods = - ImmutableList.builder() - .add( - listSinksMethod, - getSinkMethod, - createSinkMethod, - updateSinkMethod, - deleteSinkMethod) - .build(); - } + public PageStreamingCallSettings + listSinksSettings() { + return listSinksSettings; } - private final MethodBuilders methods; - - // =============== - // Factory Methods - // =============== + public SimpleCallSettings getSinkSettings() { + return getSinkSettings; + } - /** - * Constructs an instance of ConfigServiceV2Settings with default settings. - * - * - * - */ - public static ConfigServiceV2Settings create() { - ConfigServiceV2Settings settings = new ConfigServiceV2Settings(new MethodBuilders()); - settings.provideChannelWith( - ConnectionSettings.builder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build()); - return settings; + public SimpleCallSettings createSinkSettings() { + return createSinkSettings; } - /** - * Constructs an instance of ConfigServiceV2Settings with default settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. - * - * - * - */ - protected ConfigServiceV2Settings(MethodBuilders methods) { - super(methods.allMethods); - this.methods = methods; + public SimpleCallSettings updateSinkSettings() { + return updateSinkSettings; } - /** - * Returns the PageStreamingApiCallableBuilder for the API method listSinks. - * - * - * - */ - public PageStreamingApiCallableBuilder - listSinksMethod() { - return methods.listSinksMethod; + public SimpleCallSettings deleteSinkSettings() { + return deleteSinkSettings; } - /** - * Returns the ApiCallableBuilder for the API method getSink. - * - * - * - */ - public ApiCallableBuilder getSinkMethod() { - return methods.getSinkMethod; + public static ConfigServiceV2Settings defaultInstance() throws IOException { + return newBuilder().build(); } - /** - * Returns the ApiCallableBuilder for the API method createSink. - * - * - * - */ - public ApiCallableBuilder createSinkMethod() { - return methods.createSinkMethod; + public static Builder newBuilder() { + return new Builder(); } - /** - * Returns the ApiCallableBuilder for the API method updateSink. - * - * - * - */ - public ApiCallableBuilder updateSinkMethod() { - return methods.updateSinkMethod; + public Builder toBuilder() { + return new Builder(this); } - /** - * Returns the ApiCallableBuilder for the API method deleteSink. - * - * - * - */ - public ApiCallableBuilder deleteSinkMethod() { - return methods.deleteSinkMethod; + private ConfigServiceV2Settings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getOrBuildChannel(), + settingsBuilder.shouldAutoCloseChannel(), + settingsBuilder.getOrBuildExecutor(), + settingsBuilder.getConnectionSettings(), + settingsBuilder.getGeneratorName(), + settingsBuilder.getGeneratorVersion(), + settingsBuilder.getClientLibName(), + settingsBuilder.getClientLibVersion()); + + listSinksSettings = settingsBuilder.listSinksSettings().build(); + getSinkSettings = settingsBuilder.getSinkSettings().build(); + createSinkSettings = settingsBuilder.createSinkSettings().build(); + updateSinkSettings = settingsBuilder.updateSinkSettings().build(); + deleteSinkSettings = settingsBuilder.deleteSinkSettings().build(); } - private static PageDescriptor + private static PageStreamingDescriptor LIST_SINKS_PAGE_STR_DESC = - new PageDescriptor() { + new PageStreamingDescriptor() { @Override public Object emptyToken() { return ""; @@ -286,4 +176,168 @@ public Iterable extractResources(ListSinksResponse payload) { return payload.getSinksList(); } }; + + public static class Builder extends ServiceApiSettings.Builder { + private final ImmutableList methodSettingsBuilders; + + private PageStreamingCallSettings.Builder + listSinksSettings; + private SimpleCallSettings.Builder getSinkSettings; + private SimpleCallSettings.Builder createSinkSettings; + private SimpleCallSettings.Builder updateSinkSettings; + private SimpleCallSettings.Builder deleteSinkSettings; + + 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.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(2000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("default", settingsBuilder); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + private Builder() { + super( + ConnectionSettings.builder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) + .build()); + + listSinksSettings = + PageStreamingCallSettings.newBuilder( + ConfigServiceV2Grpc.METHOD_LIST_SINKS, LIST_SINKS_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + getSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_GET_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + createSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_CREATE_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + updateSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_UPDATE_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + deleteSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_DELETE_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + methodSettingsBuilders = + ImmutableList.of( + listSinksSettings, + getSinkSettings, + createSinkSettings, + updateSinkSettings, + deleteSinkSettings); + } + + private Builder(ConfigServiceV2Settings settings) { + super(settings); + + listSinksSettings = settings.listSinksSettings.toBuilder(); + getSinkSettings = settings.getSinkSettings.toBuilder(); + createSinkSettings = settings.createSinkSettings.toBuilder(); + updateSinkSettings = settings.updateSinkSettings.toBuilder(); + deleteSinkSettings = settings.deleteSinkSettings.toBuilder(); + + methodSettingsBuilders = + ImmutableList.of( + listSinksSettings, + getSinkSettings, + createSinkSettings, + updateSinkSettings, + deleteSinkSettings); + } + + @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 setExecutor(ScheduledExecutorService executor) { + super.setExecutor(executor); + 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; + } + + public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { + super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + return this; + } + + public PageStreamingCallSettings.Builder + listSinksSettings() { + return listSinksSettings; + } + + public SimpleCallSettings.Builder getSinkSettings() { + return getSinkSettings; + } + + public SimpleCallSettings.Builder createSinkSettings() { + return createSinkSettings; + } + + public SimpleCallSettings.Builder updateSinkSettings() { + return updateSinkSettings; + } + + public SimpleCallSettings.Builder deleteSinkSettings() { + return deleteSinkSettings; + } + + @Override + public ConfigServiceV2Settings build() throws IOException { + return new ConfigServiceV2Settings(this); + } + } } diff --git a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java index cebdeeb1ef1c..b1c6bd36f6ee 100644 --- a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java +++ b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java @@ -43,8 +43,6 @@ import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; -import com.google.logging.v2.ReadLogEntriesRequest; -import com.google.logging.v2.ReadLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -66,66 +64,6 @@ */ @javax.annotation.Generated("by GAPIC") public class LoggingServiceV2Api implements AutoCloseable { - - public static class ResourceNames { - private ResourceNames() {} - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a log resource. - * - * - * - */ - private static final PathTemplate LOG_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/logs/{log}"); - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a log resource. - * - * - * - */ - public static final String formatLogPath(String project, String log) { - return LOG_PATH_TEMPLATE.instantiate("project", project, "log", log); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a log resource. - * - * - * - */ - public static final String parseProjectFromLogPath(String logPath) { - return LOG_PATH_TEMPLATE.parse(logPath).get("project"); - } - - /** - * Parses the log from the given fully-qualified path which - * represents a log resource. - * - * - * - */ - public static final String parseLogFromLogPath(String logPath) { - return LOG_PATH_TEMPLATE.parse(logPath).get("log"); - } - } - - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -135,9 +73,6 @@ public static final String parseLogFromLogPath(String logPath) { private final ApiCallable listLogEntriesCallable; private final ApiCallable> listLogEntriesIterableCallable; - private final ApiCallable readLogEntriesCallable; - private final ApiCallable> - readLogEntriesIterableCallable; private final ApiCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable; @@ -145,9 +80,66 @@ public static final String parseLogFromLogPath(String logPath) { ListMonitoredResourceDescriptorsRequest, Iterable> listMonitoredResourceDescriptorsIterableCallable; - // =============== - // Factory Methods - // =============== + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); + + private static final PathTemplate LOG_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/logs/{log}"); + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a log resource. + * + * + * + */ + public static final String formatLogName(String project, String log) { + return LOG_PATH_TEMPLATE.instantiate("project", project, "log", log); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a log resource. + * + * + * + */ + public static final String parseProjectFromLogName(String logName) { + return LOG_PATH_TEMPLATE.parse(logName).get("project"); + } + + /** + * Parses the log from the given fully-qualified path which + * represents a log resource. + * + * + * + */ + public static final String parseLogFromLogName(String logName) { + return LOG_PATH_TEMPLATE.parse(logName).get("log"); + } /** * Constructs an instance of LoggingServiceV2Api with default settings. @@ -155,24 +147,27 @@ public static final String parseLogFromLogPath(String logPath) { * * */ - public static LoggingServiceV2Api create() throws IOException { - return create(LoggingServiceV2Settings.create()); + public static final LoggingServiceV2Api defaultInstance() throws IOException { + return create(LoggingServiceV2Settings.defaultInstance()); } /** - * Constructs an instance of LoggingServiceV2Api, using the given settings. The channels are - * created based on the settings passed in, or defaults for any settings that are not set. + * Constructs an instance of LoggingServiceV2Api, 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 LoggingServiceV2Api create(LoggingServiceV2Settings settings) throws IOException { + public static final LoggingServiceV2Api create(LoggingServiceV2Settings settings) + throws IOException { return new LoggingServiceV2Api(settings); } /** - * Constructs an instance of LoggingServiceV2Api, using the given settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. + * Constructs an instance of LoggingServiceV2Api, using the given settings. + * This is protected so that it easy to make a subclass, but otherwise, the static + * factory methods should be preferred. * * * @@ -180,32 +175,27 @@ public static LoggingServiceV2Api create(LoggingServiceV2Settings settings) thro protected LoggingServiceV2Api(LoggingServiceV2Settings settings) throws IOException { this.channel = settings.getChannel(); - this.deleteLogCallable = settings.deleteLogMethod().build(settings); - this.writeLogEntriesCallable = settings.writeLogEntriesMethod().build(settings); - this.listLogEntriesCallable = settings.listLogEntriesMethod().build(settings); + this.deleteLogCallable = ApiCallable.create(settings.deleteLogSettings(), settings); + this.writeLogEntriesCallable = ApiCallable.create(settings.writeLogEntriesSettings(), settings); + this.listLogEntriesCallable = ApiCallable.create(settings.listLogEntriesSettings(), settings); this.listLogEntriesIterableCallable = - settings.listLogEntriesMethod().buildPageStreaming(settings); - this.readLogEntriesCallable = settings.readLogEntriesMethod().build(settings); - this.readLogEntriesIterableCallable = - settings.readLogEntriesMethod().buildPageStreaming(settings); + ApiCallable.createIterable(settings.listLogEntriesSettings(), settings); this.listMonitoredResourceDescriptorsCallable = - settings.listMonitoredResourceDescriptorsMethod().build(settings); + ApiCallable.create(settings.listMonitoredResourceDescriptorsSettings(), settings); this.listMonitoredResourceDescriptorsIterableCallable = - settings.listMonitoredResourceDescriptorsMethod().buildPageStreaming(settings); - - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + ApiCallable.createIterable(settings.listMonitoredResourceDescriptorsSettings(), settings); + + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- deleteLog ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -218,8 +208,9 @@ public void close() throws IOException { * * @param logName Required. The resource name of the log to delete. Example: * `"projects/my-project/logs/syslog"`. + * @throws ApiException if the remote call fails */ - public void deleteLog(String logName) { + public final void deleteLog(String logName) { DeleteLogRequest request = DeleteLogRequest.newBuilder().setLogName(logName).build(); deleteLog(request); @@ -234,6 +225,7 @@ public void deleteLog(String logName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private void deleteLog(DeleteLogRequest request) { deleteLogCallable().call(request); @@ -246,8 +238,9 @@ private void deleteLog(DeleteLogRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable deleteLogCallable() { + public final ApiCallable deleteLogCallable() { return deleteLogCallable; } @@ -269,12 +262,13 @@ public ApiCallable deleteLogCallable() { * 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. + * 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. + * @throws ApiException if the remote call fails */ - public WriteLogEntriesResponse writeLogEntries( + public final WriteLogEntriesResponse writeLogEntries( String logName, MonitoredResource resource, Map labels, @@ -299,6 +293,7 @@ public WriteLogEntriesResponse writeLogEntries( * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest request) { return writeLogEntriesCallable().call(request); @@ -311,8 +306,10 @@ public WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable writeLogEntriesCallable() { + public final ApiCallable + writeLogEntriesCallable() { return writeLogEntriesCallable; } @@ -320,15 +317,29 @@ public ApiCallable writeLogEntr // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * + * + * @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 orderBy Optional. How the results should be sorted. Presently, the only permitted + * values are `"timestamp"` (default) and `"timestamp desc"`. The first + * option returns entries in order of increasing values of + * `LogEntry.timestamp` (oldest first), and the second option returns entries + * in order of decreasing timestamps (newest first). Entries with equal + * timestamps are returned in order of `LogEntry.insertId`. + * @throws ApiException if the remote call fails */ - public Iterable listLogEntries(List projectIds, String filter, String orderBy) { + public final Iterable listLogEntries( + List projectIds, String filter, String orderBy) { ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() .addAllProjectIds(projectIds) @@ -340,106 +351,49 @@ public Iterable listLogEntries(List projectIds, String filter, // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listLogEntries(ListLogEntriesRequest request) { + public final Iterable listLogEntries(ListLogEntriesRequest request) { return listLogEntriesIterableCallable().call(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> listLogEntriesIterableCallable() { + public final ApiCallable> + listLogEntriesIterableCallable() { return listLogEntriesIterableCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * + * @throws ApiException if the remote call fails */ - public ApiCallable listLogEntriesCallable() { + public final ApiCallable listLogEntriesCallable() { return listLogEntriesCallable; } - // ----- readLogEntries ----- - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - */ - public Iterable readLogEntries(List projectIds, String filter, String orderBy) { - ReadLogEntriesRequest request = - ReadLogEntriesRequest.newBuilder() - .addAllProjectIds(projectIds) - .setFilter(filter) - .setOrderBy(orderBy) - .build(); - return readLogEntries(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - * - * @param request The request object containing all of the parameters for the API call. - */ - public Iterable readLogEntries(ReadLogEntriesRequest request) { - return readLogEntriesIterableCallable().call(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - */ - public ApiCallable> readLogEntriesIterableCallable() { - return readLogEntriesIterableCallable; - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - */ - public ApiCallable readLogEntriesCallable() { - return readLogEntriesCallable; - } - // ----- listMonitoredResourceDescriptors ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -450,8 +404,9 @@ public ApiCallable readLogEntries * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listMonitoredResourceDescriptors( + public final Iterable listMonitoredResourceDescriptors( ListMonitoredResourceDescriptorsRequest request) { return listMonitoredResourceDescriptorsIterableCallable().call(request); } @@ -462,8 +417,10 @@ public Iterable listMonitoredResourceDescriptors( * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> + public final ApiCallable< + ListMonitoredResourceDescriptorsRequest, Iterable> listMonitoredResourceDescriptorsIterableCallable() { return listMonitoredResourceDescriptorsIterableCallable; } @@ -474,17 +431,14 @@ public Iterable listMonitoredResourceDescriptors( * * * + * @throws ApiException if the remote call fails */ - public ApiCallable< + public final ApiCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable() { return listMonitoredResourceDescriptorsCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -493,7 +447,7 @@ public Iterable listMonitoredResourceDescriptors( * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java index b5e633f8cc6d..6b5827dd9f7f 100644 --- a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java +++ b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java @@ -34,14 +34,13 @@ package com.google.gcloud.logging.spi.v2; import com.google.api.MonitoredResourceDescriptor; -import com.google.api.gax.core.BackoffParams; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.core.RetryParams; +import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; -import com.google.api.gax.grpc.PageDescriptor; +import com.google.api.gax.grpc.PageStreamingCallSettings; +import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; +import com.google.api.gax.grpc.SimpleCallSettings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -54,12 +53,14 @@ import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; import com.google.logging.v2.LoggingServiceV2Grpc; -import com.google.logging.v2.ReadLogEntriesRequest; -import com.google.logging.v2.ReadLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; +import io.grpc.ManagedChannel; import io.grpc.Status; +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -67,10 +68,6 @@ @javax.annotation.Generated("by GAPIC") public class LoggingServiceV2Settings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -99,197 +96,71 @@ public class LoggingServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/cloud-platform") .build(); - 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 final SimpleCallSettings deleteLogSettings; + private final SimpleCallSettings + writeLogEntriesSettings; + private final PageStreamingCallSettings + listLogEntriesSettings; - private static final ImmutableMap RETRY_PARAM_DEFINITIONS; - - static { - ImmutableMap.Builder definitions = ImmutableMap.builder(); - RetryParams params = null; - params = - RetryParams.newBuilder() - .setRetryBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(100L) - .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) - .build()) - .setTimeoutBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) - .build()) - .setTotalTimeout(30000L) - .build(); - definitions.put("default", params); - RETRY_PARAM_DEFINITIONS = definitions.build(); - } + private final PageStreamingCallSettings< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings; - private static class MethodBuilders { - private final ApiCallableBuilder deleteLogMethod; - private final ApiCallableBuilder - writeLogEntriesMethod; - private final PageStreamingApiCallableBuilder< - ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> - listLogEntriesMethod; - private final PageStreamingApiCallableBuilder< - ReadLogEntriesRequest, ReadLogEntriesResponse, LogEntry> - readLogEntriesMethod; - private final PageStreamingApiCallableBuilder< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> - listMonitoredResourceDescriptorsMethod; - private final ImmutableList allMethods; - - public MethodBuilders() { - deleteLogMethod = new ApiCallableBuilder<>(LoggingServiceV2Grpc.METHOD_DELETE_LOG); - deleteLogMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - deleteLogMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - writeLogEntriesMethod = - new ApiCallableBuilder<>(LoggingServiceV2Grpc.METHOD_WRITE_LOG_ENTRIES); - writeLogEntriesMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - writeLogEntriesMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - listLogEntriesMethod = - new PageStreamingApiCallableBuilder<>( - LoggingServiceV2Grpc.METHOD_LIST_LOG_ENTRIES, LIST_LOG_ENTRIES_PAGE_STR_DESC); - listLogEntriesMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listLogEntriesMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - readLogEntriesMethod = - new PageStreamingApiCallableBuilder<>( - LoggingServiceV2Grpc.METHOD_READ_LOG_ENTRIES, READ_LOG_ENTRIES_PAGE_STR_DESC); - readLogEntriesMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - readLogEntriesMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - listMonitoredResourceDescriptorsMethod = - new PageStreamingApiCallableBuilder<>( - LoggingServiceV2Grpc.METHOD_LIST_MONITORED_RESOURCE_DESCRIPTORS, - LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC); - listMonitoredResourceDescriptorsMethod.setRetryableCodes( - RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listMonitoredResourceDescriptorsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - allMethods = - ImmutableList.builder() - .add( - deleteLogMethod, - writeLogEntriesMethod, - listLogEntriesMethod, - readLogEntriesMethod, - listMonitoredResourceDescriptorsMethod) - .build(); - } + public SimpleCallSettings deleteLogSettings() { + return deleteLogSettings; } - private final MethodBuilders methods; - - // =============== - // Factory Methods - // =============== - - /** - * Constructs an instance of LoggingServiceV2Settings with default settings. - * - * - * - */ - public static LoggingServiceV2Settings create() { - LoggingServiceV2Settings settings = new LoggingServiceV2Settings(new MethodBuilders()); - settings.provideChannelWith( - ConnectionSettings.builder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build()); - return settings; + public SimpleCallSettings + writeLogEntriesSettings() { + return writeLogEntriesSettings; } - /** - * Constructs an instance of LoggingServiceV2Settings with default settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. - * - * - * - */ - protected LoggingServiceV2Settings(MethodBuilders methods) { - super(methods.allMethods); - this.methods = methods; + public PageStreamingCallSettings + listLogEntriesSettings() { + return listLogEntriesSettings; } - /** - * Returns the ApiCallableBuilder for the API method deleteLog. - * - * - * - */ - public ApiCallableBuilder deleteLogMethod() { - return methods.deleteLogMethod; + public PageStreamingCallSettings< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings() { + return listMonitoredResourceDescriptorsSettings; } - /** - * Returns the ApiCallableBuilder for the API method writeLogEntries. - * - * - * - */ - public ApiCallableBuilder - writeLogEntriesMethod() { - return methods.writeLogEntriesMethod; + public static LoggingServiceV2Settings defaultInstance() throws IOException { + return newBuilder().build(); } - /** - * Returns the PageStreamingApiCallableBuilder for the API method listLogEntries. - * - * - * - */ - public PageStreamingApiCallableBuilder - listLogEntriesMethod() { - return methods.listLogEntriesMethod; + public static Builder newBuilder() { + return new Builder(); } - /** - * Returns the PageStreamingApiCallableBuilder for the API method readLogEntries. - * - * - * - */ - public PageStreamingApiCallableBuilder - readLogEntriesMethod() { - return methods.readLogEntriesMethod; + public Builder toBuilder() { + return new Builder(this); } - /** - * Returns the PageStreamingApiCallableBuilder for the API method - * listMonitoredResourceDescriptors. - * - * - * - */ - public PageStreamingApiCallableBuilder< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> - listMonitoredResourceDescriptorsMethod() { - return methods.listMonitoredResourceDescriptorsMethod; + private LoggingServiceV2Settings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getOrBuildChannel(), + settingsBuilder.shouldAutoCloseChannel(), + settingsBuilder.getOrBuildExecutor(), + settingsBuilder.getConnectionSettings(), + settingsBuilder.getGeneratorName(), + settingsBuilder.getGeneratorVersion(), + settingsBuilder.getClientLibName(), + settingsBuilder.getClientLibVersion()); + + deleteLogSettings = settingsBuilder.deleteLogSettings().build(); + writeLogEntriesSettings = settingsBuilder.writeLogEntriesSettings().build(); + listLogEntriesSettings = settingsBuilder.listLogEntriesSettings().build(); + listMonitoredResourceDescriptorsSettings = + settingsBuilder.listMonitoredResourceDescriptorsSettings().build(); } - private static PageDescriptor + private static PageStreamingDescriptor LIST_LOG_ENTRIES_PAGE_STR_DESC = - new PageDescriptor() { + new PageStreamingDescriptor() { @Override public Object emptyToken() { return ""; @@ -311,37 +182,11 @@ public Iterable extractResources(ListLogEntriesResponse payload) { } }; - private static PageDescriptor - READ_LOG_ENTRIES_PAGE_STR_DESC = - new PageDescriptor() { - @Override - public Object emptyToken() { - return ""; - } - - @Override - public ReadLogEntriesRequest injectToken(ReadLogEntriesRequest payload, Object token) { - return ReadLogEntriesRequest.newBuilder(payload) - .setResumeToken((String) token) - .build(); - } - - @Override - public Object extractNextToken(ReadLogEntriesResponse payload) { - return payload.getResumeToken(); - } - - @Override - public Iterable extractResources(ReadLogEntriesResponse payload) { - return payload.getEntriesList(); - } - }; - - private static PageDescriptor< + private static PageStreamingDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor> LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC = - new PageDescriptor< + new PageStreamingDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor>() { @Override @@ -368,4 +213,178 @@ public Iterable extractResources( return payload.getResourceDescriptorsList(); } }; + + public static class Builder extends ServiceApiSettings.Builder { + private final ImmutableList methodSettingsBuilders; + + private SimpleCallSettings.Builder deleteLogSettings; + private SimpleCallSettings.Builder + writeLogEntriesSettings; + private PageStreamingCallSettings.Builder< + ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> + listLogEntriesSettings; + private PageStreamingCallSettings.Builder< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings; + + 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.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(2000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("default", settingsBuilder); + settingsBuilder = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.millis(100L)) + .setRetryDelayMultiplier(1.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(7000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("list", settingsBuilder); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + private Builder() { + super( + ConnectionSettings.builder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) + .build()); + + deleteLogSettings = + SimpleCallSettings.newBuilder(LoggingServiceV2Grpc.METHOD_DELETE_LOG) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + writeLogEntriesSettings = + SimpleCallSettings.newBuilder(LoggingServiceV2Grpc.METHOD_WRITE_LOG_ENTRIES) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + listLogEntriesSettings = + PageStreamingCallSettings.newBuilder( + LoggingServiceV2Grpc.METHOD_LIST_LOG_ENTRIES, LIST_LOG_ENTRIES_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("list")); + + listMonitoredResourceDescriptorsSettings = + PageStreamingCallSettings.newBuilder( + LoggingServiceV2Grpc.METHOD_LIST_MONITORED_RESOURCE_DESCRIPTORS, + LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + methodSettingsBuilders = + ImmutableList.of( + deleteLogSettings, + writeLogEntriesSettings, + listLogEntriesSettings, + listMonitoredResourceDescriptorsSettings); + } + + private Builder(LoggingServiceV2Settings settings) { + super(settings); + + deleteLogSettings = settings.deleteLogSettings.toBuilder(); + writeLogEntriesSettings = settings.writeLogEntriesSettings.toBuilder(); + listLogEntriesSettings = settings.listLogEntriesSettings.toBuilder(); + listMonitoredResourceDescriptorsSettings = + settings.listMonitoredResourceDescriptorsSettings.toBuilder(); + + methodSettingsBuilders = + ImmutableList.of( + deleteLogSettings, + writeLogEntriesSettings, + listLogEntriesSettings, + listMonitoredResourceDescriptorsSettings); + } + + @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 setExecutor(ScheduledExecutorService executor) { + super.setExecutor(executor); + 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; + } + + public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { + super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + return this; + } + + public SimpleCallSettings.Builder deleteLogSettings() { + return deleteLogSettings; + } + + public SimpleCallSettings.Builder + writeLogEntriesSettings() { + return writeLogEntriesSettings; + } + + public PageStreamingCallSettings.Builder< + ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> + listLogEntriesSettings() { + return listLogEntriesSettings; + } + + public PageStreamingCallSettings.Builder< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings() { + return listMonitoredResourceDescriptorsSettings; + } + + @Override + public LoggingServiceV2Settings build() throws IOException { + return new LoggingServiceV2Settings(this); + } + } } diff --git a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java index 0352e5ff8786..c17ae8dddb00 100644 --- a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java +++ b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java @@ -53,105 +53,13 @@ // AUTO-GENERATED DOCUMENTATION AND SERVICE - see instructions at the top of the file for editing. /** - * Service Description: See src/api/google/logging/v1/logging.proto for documentation + * Service Description: * * * */ @javax.annotation.Generated("by GAPIC") public class MetricsServiceV2Api implements AutoCloseable { - - public static class ResourceNames { - private ResourceNames() {} - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a metric resource. - * - * - * - */ - private static final PathTemplate METRIC_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/metrics/{metric}"); - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a metric resource. - * - * - * - */ - public static final String formatMetricPath(String project, String metric) { - return METRIC_PATH_TEMPLATE.instantiate("project", project, "metric", metric); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a metric resource. - * - * - * - */ - public static final String parseProjectFromMetricPath(String metricPath) { - return METRIC_PATH_TEMPLATE.parse(metricPath).get("project"); - } - - /** - * Parses the metric from the given fully-qualified path which - * represents a metric resource. - * - * - * - */ - public static final String parseMetricFromMetricPath(String metricPath) { - return METRIC_PATH_TEMPLATE.parse(metricPath).get("metric"); - } - } - - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -163,9 +71,66 @@ public static final String parseMetricFromMetricPath(String metricPath) { private final ApiCallable updateLogMetricCallable; private final ApiCallable deleteLogMetricCallable; - // =============== - // Factory Methods - // =============== + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); + + private static final PathTemplate METRIC_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/metrics/{metric}"); + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a metric resource. + * + * + * + */ + public static final String formatMetricName(String project, String metric) { + return METRIC_PATH_TEMPLATE.instantiate("project", project, "metric", metric); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a metric resource. + * + * + * + */ + public static final String parseProjectFromMetricName(String metricName) { + return METRIC_PATH_TEMPLATE.parse(metricName).get("project"); + } + + /** + * Parses the metric from the given fully-qualified path which + * represents a metric resource. + * + * + * + */ + public static final String parseMetricFromMetricName(String metricName) { + return METRIC_PATH_TEMPLATE.parse(metricName).get("metric"); + } /** * Constructs an instance of MetricsServiceV2Api with default settings. @@ -173,24 +138,27 @@ public static final String parseMetricFromMetricPath(String metricPath) { * * */ - public static MetricsServiceV2Api create() throws IOException { - return create(MetricsServiceV2Settings.create()); + public static final MetricsServiceV2Api defaultInstance() throws IOException { + return create(MetricsServiceV2Settings.defaultInstance()); } /** - * Constructs an instance of MetricsServiceV2Api, using the given settings. The channels are - * created based on the settings passed in, or defaults for any settings that are not set. + * Constructs an instance of MetricsServiceV2Api, 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 MetricsServiceV2Api create(MetricsServiceV2Settings settings) throws IOException { + public static final MetricsServiceV2Api create(MetricsServiceV2Settings settings) + throws IOException { return new MetricsServiceV2Api(settings); } /** - * Constructs an instance of MetricsServiceV2Api, using the given settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. + * Constructs an instance of MetricsServiceV2Api, using the given settings. + * This is protected so that it easy to make a subclass, but otherwise, the static + * factory methods should be preferred. * * * @@ -198,27 +166,25 @@ public static MetricsServiceV2Api create(MetricsServiceV2Settings settings) thro protected MetricsServiceV2Api(MetricsServiceV2Settings settings) throws IOException { this.channel = settings.getChannel(); - this.listLogMetricsCallable = settings.listLogMetricsMethod().build(settings); + this.listLogMetricsCallable = ApiCallable.create(settings.listLogMetricsSettings(), settings); this.listLogMetricsIterableCallable = - settings.listLogMetricsMethod().buildPageStreaming(settings); - this.getLogMetricCallable = settings.getLogMetricMethod().build(settings); - this.createLogMetricCallable = settings.createLogMetricMethod().build(settings); - this.updateLogMetricCallable = settings.updateLogMetricMethod().build(settings); - this.deleteLogMetricCallable = settings.deleteLogMetricMethod().build(settings); - - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + ApiCallable.createIterable(settings.listLogMetricsSettings(), settings); + this.getLogMetricCallable = ApiCallable.create(settings.getLogMetricSettings(), settings); + this.createLogMetricCallable = ApiCallable.create(settings.createLogMetricSettings(), settings); + this.updateLogMetricCallable = ApiCallable.create(settings.updateLogMetricSettings(), settings); + this.deleteLogMetricCallable = ApiCallable.create(settings.deleteLogMetricSettings(), settings); + + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- listLogMetrics ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -227,8 +193,12 @@ public void close() throws IOException { * * * + * + * @param projectName Required. The resource name of the project containing the metrics. + * Example: `"projects/my-project-id"`. + * @throws ApiException if the remote call fails */ - public Iterable listLogMetrics(String projectName) { + public final Iterable listLogMetrics(String projectName) { ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setProjectName(projectName).build(); return listLogMetrics(request); @@ -242,8 +212,9 @@ public Iterable listLogMetrics(String projectName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listLogMetrics(ListLogMetricsRequest request) { + public final Iterable listLogMetrics(ListLogMetricsRequest request) { return listLogMetricsIterableCallable().call(request); } @@ -253,8 +224,10 @@ public Iterable listLogMetrics(ListLogMetricsRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> listLogMetricsIterableCallable() { + public final ApiCallable> + listLogMetricsIterableCallable() { return listLogMetricsIterableCallable; } @@ -264,8 +237,9 @@ public ApiCallable> listLogMetricsIte * * * + * @throws ApiException if the remote call fails */ - public ApiCallable listLogMetricsCallable() { + public final ApiCallable listLogMetricsCallable() { return listLogMetricsCallable; } @@ -280,8 +254,9 @@ public ApiCallable listLogMetrics * * @param metricName The resource name of the desired metric. * Example: `"projects/my-project-id/metrics/my-metric-id"`. + * @throws ApiException if the remote call fails */ - public LogMetric getLogMetric(String metricName) { + public final LogMetric getLogMetric(String metricName) { GetLogMetricRequest request = GetLogMetricRequest.newBuilder().setMetricName(metricName).build(); @@ -296,6 +271,7 @@ public LogMetric getLogMetric(String metricName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private LogMetric getLogMetric(GetLogMetricRequest request) { return getLogMetricCallable().call(request); @@ -307,8 +283,9 @@ private LogMetric getLogMetric(GetLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable getLogMetricCallable() { + public final ApiCallable getLogMetricCallable() { return getLogMetricCallable; } @@ -327,8 +304,9 @@ public ApiCallable getLogMetricCallable() { * The new metric must be provided in the request. * @param metric The new logs-based metric, which must not have an identifier that * already exists. + * @throws ApiException if the remote call fails */ - public LogMetric createLogMetric(String projectName, LogMetric metric) { + public final LogMetric createLogMetric(String projectName, LogMetric metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setProjectName(projectName).setMetric(metric).build(); @@ -343,6 +321,7 @@ public LogMetric createLogMetric(String projectName, LogMetric metric) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogMetric createLogMetric(CreateLogMetricRequest request) { return createLogMetricCallable().call(request); @@ -354,8 +333,9 @@ public LogMetric createLogMetric(CreateLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable createLogMetricCallable() { + public final ApiCallable createLogMetricCallable() { return createLogMetricCallable; } @@ -377,8 +357,9 @@ public ApiCallable createLogMetricCallable() * @param metric The updated metric, whose name must be the same as the * metric identifier in `metricName`. If `metricName` does not * exist, then a new metric is created. + * @throws ApiException if the remote call fails */ - public LogMetric updateLogMetric(String metricName, LogMetric metric) { + public final LogMetric updateLogMetric(String metricName, LogMetric metric) { UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder().setMetricName(metricName).setMetric(metric).build(); @@ -393,6 +374,7 @@ public LogMetric updateLogMetric(String metricName, LogMetric metric) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogMetric updateLogMetric(UpdateLogMetricRequest request) { return updateLogMetricCallable().call(request); @@ -404,8 +386,9 @@ public LogMetric updateLogMetric(UpdateLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable updateLogMetricCallable() { + public final ApiCallable updateLogMetricCallable() { return updateLogMetricCallable; } @@ -420,8 +403,9 @@ public ApiCallable updateLogMetricCallable() * * @param metricName The resource name of the metric to delete. * Example: `"projects/my-project-id/metrics/my-metric-id"`. + * @throws ApiException if the remote call fails */ - public void deleteLogMetric(String metricName) { + public final void deleteLogMetric(String metricName) { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder().setMetricName(metricName).build(); @@ -436,6 +420,7 @@ public void deleteLogMetric(String metricName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private void deleteLogMetric(DeleteLogMetricRequest request) { deleteLogMetricCallable().call(request); @@ -447,15 +432,12 @@ private void deleteLogMetric(DeleteLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable deleteLogMetricCallable() { + public final ApiCallable deleteLogMetricCallable() { return deleteLogMetricCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -464,7 +446,7 @@ public ApiCallable deleteLogMetricCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java index 6035b2a5a53c..1d38024fed11 100644 --- a/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java +++ b/gcloud-java-logging/baseline/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java @@ -33,14 +33,13 @@ package com.google.gcloud.logging.spi.v2; -import com.google.api.gax.core.BackoffParams; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.core.RetryParams; +import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; -import com.google.api.gax.grpc.PageDescriptor; +import com.google.api.gax.grpc.PageStreamingCallSettings; +import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; +import com.google.api.gax.grpc.SimpleCallSettings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -55,7 +54,11 @@ import com.google.logging.v2.MetricsServiceV2Grpc; import com.google.logging.v2.UpdateLogMetricRequest; import com.google.protobuf.Empty; +import io.grpc.ManagedChannel; import io.grpc.Status; +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -63,10 +66,6 @@ @javax.annotation.Generated("by GAPIC") public class MetricsServiceV2Settings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -95,181 +94,68 @@ public class MetricsServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/cloud-platform") .build(); - 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 final PageStreamingCallSettings + listLogMetricsSettings; - private static final ImmutableMap RETRY_PARAM_DEFINITIONS; - - static { - ImmutableMap.Builder definitions = ImmutableMap.builder(); - RetryParams params = null; - params = - RetryParams.newBuilder() - .setRetryBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(100L) - .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) - .build()) - .setTimeoutBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) - .build()) - .setTotalTimeout(30000L) - .build(); - definitions.put("default", params); - RETRY_PARAM_DEFINITIONS = definitions.build(); - } + private final SimpleCallSettings getLogMetricSettings; + private final SimpleCallSettings createLogMetricSettings; + private final SimpleCallSettings updateLogMetricSettings; + private final SimpleCallSettings deleteLogMetricSettings; - private static class MethodBuilders { - private final PageStreamingApiCallableBuilder< - ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> - listLogMetricsMethod; - private final ApiCallableBuilder getLogMetricMethod; - private final ApiCallableBuilder createLogMetricMethod; - private final ApiCallableBuilder updateLogMetricMethod; - private final ApiCallableBuilder deleteLogMetricMethod; - private final ImmutableList allMethods; - - public MethodBuilders() { - listLogMetricsMethod = - new PageStreamingApiCallableBuilder<>( - MetricsServiceV2Grpc.METHOD_LIST_LOG_METRICS, LIST_LOG_METRICS_PAGE_STR_DESC); - listLogMetricsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listLogMetricsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - getLogMetricMethod = new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_GET_LOG_METRIC); - getLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - getLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - createLogMetricMethod = - new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_CREATE_LOG_METRIC); - createLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - createLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - updateLogMetricMethod = - new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_UPDATE_LOG_METRIC); - updateLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - updateLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - deleteLogMetricMethod = - new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_DELETE_LOG_METRIC); - deleteLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - deleteLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - allMethods = - ImmutableList.builder() - .add( - listLogMetricsMethod, - getLogMetricMethod, - createLogMetricMethod, - updateLogMetricMethod, - deleteLogMetricMethod) - .build(); - } + public PageStreamingCallSettings + listLogMetricsSettings() { + return listLogMetricsSettings; } - private final MethodBuilders methods; - - // =============== - // Factory Methods - // =============== + public SimpleCallSettings getLogMetricSettings() { + return getLogMetricSettings; + } - /** - * Constructs an instance of MetricsServiceV2Settings with default settings. - * - * - * - */ - public static MetricsServiceV2Settings create() { - MetricsServiceV2Settings settings = new MetricsServiceV2Settings(new MethodBuilders()); - settings.provideChannelWith( - ConnectionSettings.builder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build()); - return settings; + public SimpleCallSettings createLogMetricSettings() { + return createLogMetricSettings; } - /** - * Constructs an instance of MetricsServiceV2Settings with default settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. - * - * - * - */ - protected MetricsServiceV2Settings(MethodBuilders methods) { - super(methods.allMethods); - this.methods = methods; + public SimpleCallSettings updateLogMetricSettings() { + return updateLogMetricSettings; } - /** - * Returns the PageStreamingApiCallableBuilder for the API method listLogMetrics. - * - * - * - */ - public PageStreamingApiCallableBuilder - listLogMetricsMethod() { - return methods.listLogMetricsMethod; + public SimpleCallSettings deleteLogMetricSettings() { + return deleteLogMetricSettings; } - /** - * Returns the ApiCallableBuilder for the API method getLogMetric. - * - * - * - */ - public ApiCallableBuilder getLogMetricMethod() { - return methods.getLogMetricMethod; + public static MetricsServiceV2Settings defaultInstance() throws IOException { + return newBuilder().build(); } - /** - * Returns the ApiCallableBuilder for the API method createLogMetric. - * - * - * - */ - public ApiCallableBuilder createLogMetricMethod() { - return methods.createLogMetricMethod; + public static Builder newBuilder() { + return new Builder(); } - /** - * Returns the ApiCallableBuilder for the API method updateLogMetric. - * - * - * - */ - public ApiCallableBuilder updateLogMetricMethod() { - return methods.updateLogMetricMethod; + public Builder toBuilder() { + return new Builder(this); } - /** - * Returns the ApiCallableBuilder for the API method deleteLogMetric. - * - * - * - */ - public ApiCallableBuilder deleteLogMetricMethod() { - return methods.deleteLogMetricMethod; + private MetricsServiceV2Settings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getOrBuildChannel(), + settingsBuilder.shouldAutoCloseChannel(), + settingsBuilder.getOrBuildExecutor(), + settingsBuilder.getConnectionSettings(), + settingsBuilder.getGeneratorName(), + settingsBuilder.getGeneratorVersion(), + settingsBuilder.getClientLibName(), + settingsBuilder.getClientLibVersion()); + + listLogMetricsSettings = settingsBuilder.listLogMetricsSettings().build(); + getLogMetricSettings = settingsBuilder.getLogMetricSettings().build(); + createLogMetricSettings = settingsBuilder.createLogMetricSettings().build(); + updateLogMetricSettings = settingsBuilder.updateLogMetricSettings().build(); + deleteLogMetricSettings = settingsBuilder.deleteLogMetricSettings().build(); } - private static PageDescriptor + private static PageStreamingDescriptor LIST_LOG_METRICS_PAGE_STR_DESC = - new PageDescriptor() { + new PageStreamingDescriptor() { @Override public Object emptyToken() { return ""; @@ -290,4 +176,170 @@ public Iterable extractResources(ListLogMetricsResponse payload) { return payload.getMetricsList(); } }; + + public static class Builder extends ServiceApiSettings.Builder { + private final ImmutableList methodSettingsBuilders; + + private PageStreamingCallSettings.Builder< + ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> + listLogMetricsSettings; + private SimpleCallSettings.Builder getLogMetricSettings; + private SimpleCallSettings.Builder createLogMetricSettings; + private SimpleCallSettings.Builder updateLogMetricSettings; + private SimpleCallSettings.Builder deleteLogMetricSettings; + + 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.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(2000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("default", settingsBuilder); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + private Builder() { + super( + ConnectionSettings.builder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) + .build()); + + listLogMetricsSettings = + PageStreamingCallSettings.newBuilder( + MetricsServiceV2Grpc.METHOD_LIST_LOG_METRICS, LIST_LOG_METRICS_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + getLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_GET_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + createLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_CREATE_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + updateLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_UPDATE_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + deleteLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_DELETE_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + methodSettingsBuilders = + ImmutableList.of( + listLogMetricsSettings, + getLogMetricSettings, + createLogMetricSettings, + updateLogMetricSettings, + deleteLogMetricSettings); + } + + private Builder(MetricsServiceV2Settings settings) { + super(settings); + + listLogMetricsSettings = settings.listLogMetricsSettings.toBuilder(); + getLogMetricSettings = settings.getLogMetricSettings.toBuilder(); + createLogMetricSettings = settings.createLogMetricSettings.toBuilder(); + updateLogMetricSettings = settings.updateLogMetricSettings.toBuilder(); + deleteLogMetricSettings = settings.deleteLogMetricSettings.toBuilder(); + + methodSettingsBuilders = + ImmutableList.of( + listLogMetricsSettings, + getLogMetricSettings, + createLogMetricSettings, + updateLogMetricSettings, + deleteLogMetricSettings); + } + + @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 setExecutor(ScheduledExecutorService executor) { + super.setExecutor(executor); + 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; + } + + public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { + super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + return this; + } + + public PageStreamingCallSettings.Builder< + ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> + listLogMetricsSettings() { + return listLogMetricsSettings; + } + + public SimpleCallSettings.Builder getLogMetricSettings() { + return getLogMetricSettings; + } + + public SimpleCallSettings.Builder createLogMetricSettings() { + return createLogMetricSettings; + } + + public SimpleCallSettings.Builder updateLogMetricSettings() { + return updateLogMetricSettings; + } + + public SimpleCallSettings.Builder deleteLogMetricSettings() { + return deleteLogMetricSettings; + } + + @Override + public MetricsServiceV2Settings build() throws IOException { + return new MetricsServiceV2Settings(this); + } + } } diff --git a/gcloud-java-logging/pom.xml b/gcloud-java-logging/pom.xml index 745a2a2f394e..213c597648fa 100644 --- a/gcloud-java-logging/pom.xml +++ b/gcloud-java-logging/pom.xml @@ -20,7 +20,7 @@ com.google.api gax - 0.0.4 + 0.0.9 com.google.api.grpc diff --git a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java index 509c94ce1d97..dc27c969e049 100644 --- a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java +++ b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Api.java @@ -55,105 +55,13 @@ // AUTO-GENERATED DOCUMENTATION AND SERVICE - see instructions at the top of the file for editing. /** - * Service Description: See src/api/google/logging/v2/logging.proto for documentation + * Service Description: * * * */ @javax.annotation.Generated("by GAPIC") public class ConfigServiceV2Api implements AutoCloseable { - - public static class ResourceNames { - private ResourceNames() {} - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a sink resource. - * - * - * - */ - private static final PathTemplate SINK_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/sinks/{sink}"); - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a sink resource. - * - * - * - */ - public static final String formatSinkPath(String project, String sink) { - return SINK_PATH_TEMPLATE.instantiate("project", project, "sink", sink); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a sink resource. - * - * - * - */ - public static final String parseProjectFromSinkPath(String sinkPath) { - return SINK_PATH_TEMPLATE.parse(sinkPath).get("project"); - } - - /** - * Parses the sink from the given fully-qualified path which - * represents a sink resource. - * - * - * - */ - public static final String parseSinkFromSinkPath(String sinkPath) { - return SINK_PATH_TEMPLATE.parse(sinkPath).get("sink"); - } - } - - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -164,9 +72,66 @@ public static final String parseSinkFromSinkPath(String sinkPath) { private final ApiCallable updateSinkCallable; private final ApiCallable deleteSinkCallable; - // =============== - // Factory Methods - // =============== + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); + + private static final PathTemplate SINK_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/sinks/{sink}"); + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a sink resource. + * + * + * + */ + public static final String formatSinkName(String project, String sink) { + return SINK_PATH_TEMPLATE.instantiate("project", project, "sink", sink); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a sink resource. + * + * + * + */ + public static final String parseProjectFromSinkName(String sinkName) { + return SINK_PATH_TEMPLATE.parse(sinkName).get("project"); + } + + /** + * Parses the sink from the given fully-qualified path which + * represents a sink resource. + * + * + * + */ + public static final String parseSinkFromSinkName(String sinkName) { + return SINK_PATH_TEMPLATE.parse(sinkName).get("sink"); + } /** * Constructs an instance of ConfigServiceV2Api with default settings. @@ -174,24 +139,27 @@ public static final String parseSinkFromSinkPath(String sinkPath) { * * */ - public static ConfigServiceV2Api create() throws IOException { - return create(ConfigServiceV2Settings.create()); + public static final ConfigServiceV2Api defaultInstance() throws IOException { + return create(ConfigServiceV2Settings.defaultInstance()); } /** - * Constructs an instance of ConfigServiceV2Api, using the given settings. The channels are - * created based on the settings passed in, or defaults for any settings that are not set. + * Constructs an instance of ConfigServiceV2Api, 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 ConfigServiceV2Api create(ConfigServiceV2Settings settings) throws IOException { + public static final ConfigServiceV2Api create(ConfigServiceV2Settings settings) + throws IOException { return new ConfigServiceV2Api(settings); } /** - * Constructs an instance of ConfigServiceV2Api, using the given settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. + * Constructs an instance of ConfigServiceV2Api, using the given settings. + * This is protected so that it easy to make a subclass, but otherwise, the static + * factory methods should be preferred. * * * @@ -199,26 +167,25 @@ public static ConfigServiceV2Api create(ConfigServiceV2Settings settings) throws protected ConfigServiceV2Api(ConfigServiceV2Settings settings) throws IOException { this.channel = settings.getChannel(); - this.listSinksCallable = settings.listSinksMethod().build(settings); - this.listSinksIterableCallable = settings.listSinksMethod().buildPageStreaming(settings); - this.getSinkCallable = settings.getSinkMethod().build(settings); - this.createSinkCallable = settings.createSinkMethod().build(settings); - this.updateSinkCallable = settings.updateSinkMethod().build(settings); - this.deleteSinkCallable = settings.deleteSinkMethod().build(settings); - - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + this.listSinksCallable = ApiCallable.create(settings.listSinksSettings(), settings); + this.listSinksIterableCallable = + ApiCallable.createIterable(settings.listSinksSettings(), settings); + this.getSinkCallable = ApiCallable.create(settings.getSinkSettings(), settings); + this.createSinkCallable = ApiCallable.create(settings.createSinkSettings(), settings); + this.updateSinkCallable = ApiCallable.create(settings.updateSinkSettings(), settings); + this.deleteSinkCallable = ApiCallable.create(settings.deleteSinkSettings(), settings); + + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- listSinks ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -227,8 +194,12 @@ public void close() throws IOException { * * * + * + * @param projectName Required. The resource name of the project containing the sinks. + * Example: `"projects/my-logging-project"`, `"projects/01234567890"`. + * @throws ApiException if the remote call fails */ - public Iterable listSinks(String projectName) { + public final Iterable listSinks(String projectName) { ListSinksRequest request = ListSinksRequest.newBuilder().setProjectName(projectName).build(); return listSinks(request); } @@ -241,8 +212,9 @@ public Iterable listSinks(String projectName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listSinks(ListSinksRequest request) { + public final Iterable listSinks(ListSinksRequest request) { return listSinksIterableCallable().call(request); } @@ -252,8 +224,9 @@ public Iterable listSinks(ListSinksRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> listSinksIterableCallable() { + public final ApiCallable> listSinksIterableCallable() { return listSinksIterableCallable; } @@ -263,8 +236,9 @@ public ApiCallable> listSinksIterableCallabl * * * + * @throws ApiException if the remote call fails */ - public ApiCallable listSinksCallable() { + public final ApiCallable listSinksCallable() { return listSinksCallable; } @@ -279,8 +253,9 @@ public ApiCallable listSinksCallable() { * * @param sinkName The resource name of the sink to return. * Example: `"projects/my-project-id/sinks/my-sink-id"`. + * @throws ApiException if the remote call fails */ - public LogSink getSink(String sinkName) { + public final LogSink getSink(String sinkName) { GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(sinkName).build(); return getSink(request); @@ -294,6 +269,7 @@ public LogSink getSink(String sinkName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private LogSink getSink(GetSinkRequest request) { return getSinkCallable().call(request); @@ -305,8 +281,9 @@ private LogSink getSink(GetSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable getSinkCallable() { + public final ApiCallable getSinkCallable() { return getSinkCallable; } @@ -325,8 +302,9 @@ public ApiCallable getSinkCallable() { * The new sink must be provided in the request. * @param sink The new sink, which must not have an identifier that already * exists. + * @throws ApiException if the remote call fails */ - public LogSink createSink(String projectName, LogSink sink) { + public final LogSink createSink(String projectName, LogSink sink) { CreateSinkRequest request = CreateSinkRequest.newBuilder().setProjectName(projectName).setSink(sink).build(); @@ -341,6 +319,7 @@ public LogSink createSink(String projectName, LogSink sink) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogSink createSink(CreateSinkRequest request) { return createSinkCallable().call(request); @@ -352,8 +331,9 @@ public LogSink createSink(CreateSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable createSinkCallable() { + public final ApiCallable createSinkCallable() { return createSinkCallable; } @@ -375,8 +355,9 @@ public ApiCallable createSinkCallable() { * @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. + * @throws ApiException if the remote call fails */ - public LogSink updateSink(String sinkName, LogSink sink) { + public final LogSink updateSink(String sinkName, LogSink sink) { UpdateSinkRequest request = UpdateSinkRequest.newBuilder().setSinkName(sinkName).setSink(sink).build(); @@ -391,6 +372,7 @@ public LogSink updateSink(String sinkName, LogSink sink) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogSink updateSink(UpdateSinkRequest request) { return updateSinkCallable().call(request); @@ -402,8 +384,9 @@ public LogSink updateSink(UpdateSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable updateSinkCallable() { + public final ApiCallable updateSinkCallable() { return updateSinkCallable; } @@ -418,8 +401,9 @@ public ApiCallable updateSinkCallable() { * * @param sinkName The resource name of the sink to delete. * Example: `"projects/my-project-id/sinks/my-sink-id"`. + * @throws ApiException if the remote call fails */ - public void deleteSink(String sinkName) { + public final void deleteSink(String sinkName) { DeleteSinkRequest request = DeleteSinkRequest.newBuilder().setSinkName(sinkName).build(); deleteSink(request); @@ -433,6 +417,7 @@ public void deleteSink(String sinkName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private void deleteSink(DeleteSinkRequest request) { deleteSinkCallable().call(request); @@ -444,15 +429,12 @@ private void deleteSink(DeleteSinkRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable deleteSinkCallable() { + public final ApiCallable deleteSinkCallable() { return deleteSinkCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -461,7 +443,7 @@ public ApiCallable deleteSinkCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java index a8abc907f31e..3569f2b175ec 100644 --- a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java +++ b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/ConfigServiceV2Settings.java @@ -33,14 +33,13 @@ package com.google.gcloud.logging.spi.v2; -import com.google.api.gax.core.BackoffParams; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.core.RetryParams; +import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; -import com.google.api.gax.grpc.PageDescriptor; +import com.google.api.gax.grpc.PageStreamingCallSettings; +import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; +import com.google.api.gax.grpc.SimpleCallSettings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -55,8 +54,11 @@ import com.google.logging.v2.LogSink; import com.google.logging.v2.UpdateSinkRequest; import com.google.protobuf.Empty; - +import io.grpc.ManagedChannel; import io.grpc.Status; +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -64,10 +66,6 @@ @javax.annotation.Generated("by GAPIC") public class ConfigServiceV2Settings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -96,177 +94,68 @@ public class ConfigServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/cloud-platform") .build(); - 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 final PageStreamingCallSettings + listSinksSettings; - private static final ImmutableMap RETRY_PARAM_DEFINITIONS; - - static { - ImmutableMap.Builder definitions = ImmutableMap.builder(); - RetryParams params = null; - params = - RetryParams.newBuilder() - .setRetryBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(100L) - .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) - .build()) - .setTimeoutBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) - .build()) - .setTotalTimeout(30000L) - .build(); - definitions.put("default", params); - RETRY_PARAM_DEFINITIONS = definitions.build(); - } + private final SimpleCallSettings getSinkSettings; + private final SimpleCallSettings createSinkSettings; + private final SimpleCallSettings updateSinkSettings; + private final SimpleCallSettings deleteSinkSettings; - private static class MethodBuilders { - private final PageStreamingApiCallableBuilder - listSinksMethod; - private final ApiCallableBuilder getSinkMethod; - private final ApiCallableBuilder createSinkMethod; - private final ApiCallableBuilder updateSinkMethod; - private final ApiCallableBuilder deleteSinkMethod; - private final ImmutableList allMethods; - - public MethodBuilders() { - listSinksMethod = - new PageStreamingApiCallableBuilder<>( - ConfigServiceV2Grpc.METHOD_LIST_SINKS, LIST_SINKS_PAGE_STR_DESC); - listSinksMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listSinksMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - getSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_GET_SINK); - getSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - getSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - createSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_CREATE_SINK); - createSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - createSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - updateSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_UPDATE_SINK); - updateSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - updateSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - deleteSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_DELETE_SINK); - deleteSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - deleteSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - allMethods = - ImmutableList.builder() - .add( - listSinksMethod, - getSinkMethod, - createSinkMethod, - updateSinkMethod, - deleteSinkMethod) - .build(); - } + public PageStreamingCallSettings + listSinksSettings() { + return listSinksSettings; } - private final MethodBuilders methods; - - // =============== - // Factory Methods - // =============== + public SimpleCallSettings getSinkSettings() { + return getSinkSettings; + } - /** - * Constructs an instance of ConfigServiceV2Settings with default settings. - * - * - * - */ - public static ConfigServiceV2Settings create() { - ConfigServiceV2Settings settings = new ConfigServiceV2Settings(new MethodBuilders()); - settings.provideChannelWith( - ConnectionSettings.builder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build()); - return settings; + public SimpleCallSettings createSinkSettings() { + return createSinkSettings; } - /** - * Constructs an instance of ConfigServiceV2Settings with default settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. - * - * - * - */ - protected ConfigServiceV2Settings(MethodBuilders methods) { - super(methods.allMethods); - this.methods = methods; + public SimpleCallSettings updateSinkSettings() { + return updateSinkSettings; } - /** - * Returns the PageStreamingApiCallableBuilder for the API method listSinks. - * - * - * - */ - public PageStreamingApiCallableBuilder - listSinksMethod() { - return methods.listSinksMethod; + public SimpleCallSettings deleteSinkSettings() { + return deleteSinkSettings; } - /** - * Returns the ApiCallableBuilder for the API method getSink. - * - * - * - */ - public ApiCallableBuilder getSinkMethod() { - return methods.getSinkMethod; + public static ConfigServiceV2Settings defaultInstance() throws IOException { + return newBuilder().build(); } - /** - * Returns the ApiCallableBuilder for the API method createSink. - * - * - * - */ - public ApiCallableBuilder createSinkMethod() { - return methods.createSinkMethod; + public static Builder newBuilder() { + return new Builder(); } - /** - * Returns the ApiCallableBuilder for the API method updateSink. - * - * - * - */ - public ApiCallableBuilder updateSinkMethod() { - return methods.updateSinkMethod; + public Builder toBuilder() { + return new Builder(this); } - /** - * Returns the ApiCallableBuilder for the API method deleteSink. - * - * - * - */ - public ApiCallableBuilder deleteSinkMethod() { - return methods.deleteSinkMethod; + private ConfigServiceV2Settings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getOrBuildChannel(), + settingsBuilder.shouldAutoCloseChannel(), + settingsBuilder.getOrBuildExecutor(), + settingsBuilder.getConnectionSettings(), + settingsBuilder.getGeneratorName(), + settingsBuilder.getGeneratorVersion(), + settingsBuilder.getClientLibName(), + settingsBuilder.getClientLibVersion()); + + listSinksSettings = settingsBuilder.listSinksSettings().build(); + getSinkSettings = settingsBuilder.getSinkSettings().build(); + createSinkSettings = settingsBuilder.createSinkSettings().build(); + updateSinkSettings = settingsBuilder.updateSinkSettings().build(); + deleteSinkSettings = settingsBuilder.deleteSinkSettings().build(); } - private static PageDescriptor + private static PageStreamingDescriptor LIST_SINKS_PAGE_STR_DESC = - new PageDescriptor() { + new PageStreamingDescriptor() { @Override public Object emptyToken() { return ""; @@ -287,4 +176,168 @@ public Iterable extractResources(ListSinksResponse payload) { return payload.getSinksList(); } }; + + public static class Builder extends ServiceApiSettings.Builder { + private final ImmutableList methodSettingsBuilders; + + private PageStreamingCallSettings.Builder + listSinksSettings; + private SimpleCallSettings.Builder getSinkSettings; + private SimpleCallSettings.Builder createSinkSettings; + private SimpleCallSettings.Builder updateSinkSettings; + private SimpleCallSettings.Builder deleteSinkSettings; + + 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.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(2000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("default", settingsBuilder); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + private Builder() { + super( + ConnectionSettings.builder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) + .build()); + + listSinksSettings = + PageStreamingCallSettings.newBuilder( + ConfigServiceV2Grpc.METHOD_LIST_SINKS, LIST_SINKS_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + getSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_GET_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + createSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_CREATE_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + updateSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_UPDATE_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + deleteSinkSettings = + SimpleCallSettings.newBuilder(ConfigServiceV2Grpc.METHOD_DELETE_SINK) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + methodSettingsBuilders = + ImmutableList.of( + listSinksSettings, + getSinkSettings, + createSinkSettings, + updateSinkSettings, + deleteSinkSettings); + } + + private Builder(ConfigServiceV2Settings settings) { + super(settings); + + listSinksSettings = settings.listSinksSettings.toBuilder(); + getSinkSettings = settings.getSinkSettings.toBuilder(); + createSinkSettings = settings.createSinkSettings.toBuilder(); + updateSinkSettings = settings.updateSinkSettings.toBuilder(); + deleteSinkSettings = settings.deleteSinkSettings.toBuilder(); + + methodSettingsBuilders = + ImmutableList.of( + listSinksSettings, + getSinkSettings, + createSinkSettings, + updateSinkSettings, + deleteSinkSettings); + } + + @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 setExecutor(ScheduledExecutorService executor) { + super.setExecutor(executor); + 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; + } + + public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { + super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + return this; + } + + public PageStreamingCallSettings.Builder + listSinksSettings() { + return listSinksSettings; + } + + public SimpleCallSettings.Builder getSinkSettings() { + return getSinkSettings; + } + + public SimpleCallSettings.Builder createSinkSettings() { + return createSinkSettings; + } + + public SimpleCallSettings.Builder updateSinkSettings() { + return updateSinkSettings; + } + + public SimpleCallSettings.Builder deleteSinkSettings() { + return deleteSinkSettings; + } + + @Override + public ConfigServiceV2Settings build() throws IOException { + return new ConfigServiceV2Settings(this); + } + } } diff --git a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java index 84fbfa124f95..1079cd07c435 100644 --- a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java +++ b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Api.java @@ -43,8 +43,6 @@ import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; -import com.google.logging.v2.ReadLogEntriesRequest; -import com.google.logging.v2.ReadLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -68,66 +66,6 @@ */ @javax.annotation.Generated("by GAPIC") public class LoggingServiceV2Api implements AutoCloseable { - - public static class ResourceNames { - private ResourceNames() {} - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a log resource. - * - * - * - */ - private static final PathTemplate LOG_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/logs/{log}"); - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a log resource. - * - * - * - */ - public static final String formatLogPath(String project, String log) { - return LOG_PATH_TEMPLATE.instantiate("project", project, "log", log); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a log resource. - * - * - * - */ - public static final String parseProjectFromLogPath(String logPath) { - return LOG_PATH_TEMPLATE.parse(logPath).get("project"); - } - - /** - * Parses the log from the given fully-qualified path which - * represents a log resource. - * - * - * - */ - public static final String parseLogFromLogPath(String logPath) { - return LOG_PATH_TEMPLATE.parse(logPath).get("log"); - } - } - - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -137,9 +75,6 @@ public static final String parseLogFromLogPath(String logPath) { private final ApiCallable listLogEntriesCallable; private final ApiCallable> listLogEntriesIterableCallable; - private final ApiCallable readLogEntriesCallable; - private final ApiCallable> - readLogEntriesIterableCallable; private final ApiCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable; @@ -147,9 +82,66 @@ public static final String parseLogFromLogPath(String logPath) { ListMonitoredResourceDescriptorsRequest, Iterable> listMonitoredResourceDescriptorsIterableCallable; - // =============== - // Factory Methods - // =============== + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); + + private static final PathTemplate LOG_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/logs/{log}"); + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a log resource. + * + * + * + */ + public static final String formatLogName(String project, String log) { + return LOG_PATH_TEMPLATE.instantiate("project", project, "log", log); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a log resource. + * + * + * + */ + public static final String parseProjectFromLogName(String logName) { + return LOG_PATH_TEMPLATE.parse(logName).get("project"); + } + + /** + * Parses the log from the given fully-qualified path which + * represents a log resource. + * + * + * + */ + public static final String parseLogFromLogName(String logName) { + return LOG_PATH_TEMPLATE.parse(logName).get("log"); + } /** * Constructs an instance of LoggingServiceV2Api with default settings. @@ -157,24 +149,27 @@ public static final String parseLogFromLogPath(String logPath) { * * */ - public static LoggingServiceV2Api create() throws IOException { - return create(LoggingServiceV2Settings.create()); + public static final LoggingServiceV2Api defaultInstance() throws IOException { + return create(LoggingServiceV2Settings.defaultInstance()); } /** - * Constructs an instance of LoggingServiceV2Api, using the given settings. The channels are - * created based on the settings passed in, or defaults for any settings that are not set. + * Constructs an instance of LoggingServiceV2Api, 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 LoggingServiceV2Api create(LoggingServiceV2Settings settings) throws IOException { + public static final LoggingServiceV2Api create(LoggingServiceV2Settings settings) + throws IOException { return new LoggingServiceV2Api(settings); } /** - * Constructs an instance of LoggingServiceV2Api, using the given settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. + * Constructs an instance of LoggingServiceV2Api, using the given settings. + * This is protected so that it easy to make a subclass, but otherwise, the static + * factory methods should be preferred. * * * @@ -182,32 +177,27 @@ public static LoggingServiceV2Api create(LoggingServiceV2Settings settings) thro protected LoggingServiceV2Api(LoggingServiceV2Settings settings) throws IOException { this.channel = settings.getChannel(); - this.deleteLogCallable = settings.deleteLogMethod().build(settings); - this.writeLogEntriesCallable = settings.writeLogEntriesMethod().build(settings); - this.listLogEntriesCallable = settings.listLogEntriesMethod().build(settings); + this.deleteLogCallable = ApiCallable.create(settings.deleteLogSettings(), settings); + this.writeLogEntriesCallable = ApiCallable.create(settings.writeLogEntriesSettings(), settings); + this.listLogEntriesCallable = ApiCallable.create(settings.listLogEntriesSettings(), settings); this.listLogEntriesIterableCallable = - settings.listLogEntriesMethod().buildPageStreaming(settings); - this.readLogEntriesCallable = settings.readLogEntriesMethod().build(settings); - this.readLogEntriesIterableCallable = - settings.readLogEntriesMethod().buildPageStreaming(settings); + ApiCallable.createIterable(settings.listLogEntriesSettings(), settings); this.listMonitoredResourceDescriptorsCallable = - settings.listMonitoredResourceDescriptorsMethod().build(settings); + ApiCallable.create(settings.listMonitoredResourceDescriptorsSettings(), settings); this.listMonitoredResourceDescriptorsIterableCallable = - settings.listMonitoredResourceDescriptorsMethod().buildPageStreaming(settings); - - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + ApiCallable.createIterable(settings.listMonitoredResourceDescriptorsSettings(), settings); + + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- deleteLog ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -220,8 +210,9 @@ public void close() throws IOException { * * @param logName Required. The resource name of the log to delete. Example: * `"projects/my-project/logs/syslog"`. + * @throws ApiException if the remote call fails */ - public void deleteLog(String logName) { + public final void deleteLog(String logName) { DeleteLogRequest request = DeleteLogRequest.newBuilder().setLogName(logName).build(); deleteLog(request); @@ -236,6 +227,7 @@ public void deleteLog(String logName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private void deleteLog(DeleteLogRequest request) { deleteLogCallable().call(request); @@ -248,8 +240,9 @@ private void deleteLog(DeleteLogRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable deleteLogCallable() { + public final ApiCallable deleteLogCallable() { return deleteLogCallable; } @@ -271,12 +264,13 @@ public ApiCallable deleteLogCallable() { * 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. + * 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. + * @throws ApiException if the remote call fails */ - public WriteLogEntriesResponse writeLogEntries( + public final WriteLogEntriesResponse writeLogEntries( String logName, MonitoredResource resource, Map labels, @@ -301,6 +295,7 @@ public WriteLogEntriesResponse writeLogEntries( * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest request) { return writeLogEntriesCallable().call(request); @@ -313,8 +308,10 @@ public WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable writeLogEntriesCallable() { + public final ApiCallable + writeLogEntriesCallable() { return writeLogEntriesCallable; } @@ -322,15 +319,29 @@ public ApiCallable writeLogEntr // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * + * + * @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 orderBy Optional. How the results should be sorted. Presently, the only permitted + * values are `"timestamp"` (default) and `"timestamp desc"`. The first + * option returns entries in order of increasing values of + * `LogEntry.timestamp` (oldest first), and the second option returns entries + * in order of decreasing timestamps (newest first). Entries with equal + * timestamps are returned in order of `LogEntry.insertId`. + * @throws ApiException if the remote call fails */ - public Iterable listLogEntries(List projectIds, String filter, String orderBy) { + public final Iterable listLogEntries( + List projectIds, String filter, String orderBy) { ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() .addAllProjectIds(projectIds) @@ -342,106 +353,49 @@ public Iterable listLogEntries(List projectIds, String filter, // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listLogEntries(ListLogEntriesRequest request) { + public final Iterable listLogEntries(ListLogEntriesRequest request) { return listLogEntriesIterableCallable().call(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> listLogEntriesIterableCallable() { + public final ApiCallable> + listLogEntriesIterableCallable() { return listLogEntriesIterableCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. /** - * Lists log entries. - * Use this method to examine log entries from Cloud Logging. - * See [Exporting Logs](/logging/docs/export) for other ways to copy - * log entries out of Cloud Logging. + * Lists log entries. Use this method to retrieve log entries from Cloud + * Logging. For ways to export log entries, see + * [Exporting Logs](/logging/docs/export). * * * + * @throws ApiException if the remote call fails */ - public ApiCallable listLogEntriesCallable() { + public final ApiCallable listLogEntriesCallable() { return listLogEntriesCallable; } - // ----- readLogEntries ----- - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - */ - public Iterable readLogEntries(List projectIds, String filter, String orderBy) { - ReadLogEntriesRequest request = - ReadLogEntriesRequest.newBuilder() - .addAllProjectIds(projectIds) - .setFilter(filter) - .setOrderBy(orderBy) - .build(); - return readLogEntries(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - * - * @param request The request object containing all of the parameters for the API call. - */ - public Iterable readLogEntries(ReadLogEntriesRequest request) { - return readLogEntriesIterableCallable().call(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - */ - public ApiCallable> readLogEntriesIterableCallable() { - return readLogEntriesIterableCallable; - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. - /** - * Streaming read of log entries. Similar to `List`, this method is intended - * for a large volume of log entries. - * - * - * - */ - public ApiCallable readLogEntriesCallable() { - return readLogEntriesCallable; - } - // ----- listMonitoredResourceDescriptors ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -452,8 +406,9 @@ public ApiCallable readLogEntries * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listMonitoredResourceDescriptors( + public final Iterable listMonitoredResourceDescriptors( ListMonitoredResourceDescriptorsRequest request) { return listMonitoredResourceDescriptorsIterableCallable().call(request); } @@ -464,8 +419,10 @@ public Iterable listMonitoredResourceDescriptors( * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> + public final ApiCallable< + ListMonitoredResourceDescriptorsRequest, Iterable> listMonitoredResourceDescriptorsIterableCallable() { return listMonitoredResourceDescriptorsIterableCallable; } @@ -476,17 +433,14 @@ public Iterable listMonitoredResourceDescriptors( * * * + * @throws ApiException if the remote call fails */ - public ApiCallable< + public final ApiCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable() { return listMonitoredResourceDescriptorsCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -495,7 +449,7 @@ public Iterable listMonitoredResourceDescriptors( * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java index 4ebf708598b8..6b5827dd9f7f 100644 --- a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java +++ b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2Settings.java @@ -34,14 +34,13 @@ package com.google.gcloud.logging.spi.v2; import com.google.api.MonitoredResourceDescriptor; -import com.google.api.gax.core.BackoffParams; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.core.RetryParams; +import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; -import com.google.api.gax.grpc.PageDescriptor; +import com.google.api.gax.grpc.PageStreamingCallSettings; +import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; +import com.google.api.gax.grpc.SimpleCallSettings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -54,13 +53,14 @@ import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; import com.google.logging.v2.LoggingServiceV2Grpc; -import com.google.logging.v2.ReadLogEntriesRequest; -import com.google.logging.v2.ReadLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; - +import io.grpc.ManagedChannel; import io.grpc.Status; +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -68,10 +68,6 @@ @javax.annotation.Generated("by GAPIC") public class LoggingServiceV2Settings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -100,197 +96,71 @@ public class LoggingServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/cloud-platform") .build(); - 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 final SimpleCallSettings deleteLogSettings; + private final SimpleCallSettings + writeLogEntriesSettings; + private final PageStreamingCallSettings + listLogEntriesSettings; - private static final ImmutableMap RETRY_PARAM_DEFINITIONS; - - static { - ImmutableMap.Builder definitions = ImmutableMap.builder(); - RetryParams params = null; - params = - RetryParams.newBuilder() - .setRetryBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(100L) - .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) - .build()) - .setTimeoutBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) - .build()) - .setTotalTimeout(30000L) - .build(); - definitions.put("default", params); - RETRY_PARAM_DEFINITIONS = definitions.build(); - } + private final PageStreamingCallSettings< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings; - private static class MethodBuilders { - private final ApiCallableBuilder deleteLogMethod; - private final ApiCallableBuilder - writeLogEntriesMethod; - private final PageStreamingApiCallableBuilder< - ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> - listLogEntriesMethod; - private final PageStreamingApiCallableBuilder< - ReadLogEntriesRequest, ReadLogEntriesResponse, LogEntry> - readLogEntriesMethod; - private final PageStreamingApiCallableBuilder< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> - listMonitoredResourceDescriptorsMethod; - private final ImmutableList allMethods; - - public MethodBuilders() { - deleteLogMethod = new ApiCallableBuilder<>(LoggingServiceV2Grpc.METHOD_DELETE_LOG); - deleteLogMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - deleteLogMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - writeLogEntriesMethod = - new ApiCallableBuilder<>(LoggingServiceV2Grpc.METHOD_WRITE_LOG_ENTRIES); - writeLogEntriesMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - writeLogEntriesMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - listLogEntriesMethod = - new PageStreamingApiCallableBuilder<>( - LoggingServiceV2Grpc.METHOD_LIST_LOG_ENTRIES, LIST_LOG_ENTRIES_PAGE_STR_DESC); - listLogEntriesMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listLogEntriesMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - readLogEntriesMethod = - new PageStreamingApiCallableBuilder<>( - LoggingServiceV2Grpc.METHOD_READ_LOG_ENTRIES, READ_LOG_ENTRIES_PAGE_STR_DESC); - readLogEntriesMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - readLogEntriesMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - listMonitoredResourceDescriptorsMethod = - new PageStreamingApiCallableBuilder<>( - LoggingServiceV2Grpc.METHOD_LIST_MONITORED_RESOURCE_DESCRIPTORS, - LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC); - listMonitoredResourceDescriptorsMethod.setRetryableCodes( - RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listMonitoredResourceDescriptorsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - allMethods = - ImmutableList.builder() - .add( - deleteLogMethod, - writeLogEntriesMethod, - listLogEntriesMethod, - readLogEntriesMethod, - listMonitoredResourceDescriptorsMethod) - .build(); - } + public SimpleCallSettings deleteLogSettings() { + return deleteLogSettings; } - private final MethodBuilders methods; - - // =============== - // Factory Methods - // =============== - - /** - * Constructs an instance of LoggingServiceV2Settings with default settings. - * - * - * - */ - public static LoggingServiceV2Settings create() { - LoggingServiceV2Settings settings = new LoggingServiceV2Settings(new MethodBuilders()); - settings.provideChannelWith( - ConnectionSettings.builder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build()); - return settings; + public SimpleCallSettings + writeLogEntriesSettings() { + return writeLogEntriesSettings; } - /** - * Constructs an instance of LoggingServiceV2Settings with default settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. - * - * - * - */ - protected LoggingServiceV2Settings(MethodBuilders methods) { - super(methods.allMethods); - this.methods = methods; + public PageStreamingCallSettings + listLogEntriesSettings() { + return listLogEntriesSettings; } - /** - * Returns the ApiCallableBuilder for the API method deleteLog. - * - * - * - */ - public ApiCallableBuilder deleteLogMethod() { - return methods.deleteLogMethod; + public PageStreamingCallSettings< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings() { + return listMonitoredResourceDescriptorsSettings; } - /** - * Returns the ApiCallableBuilder for the API method writeLogEntries. - * - * - * - */ - public ApiCallableBuilder - writeLogEntriesMethod() { - return methods.writeLogEntriesMethod; + public static LoggingServiceV2Settings defaultInstance() throws IOException { + return newBuilder().build(); } - /** - * Returns the PageStreamingApiCallableBuilder for the API method listLogEntries. - * - * - * - */ - public PageStreamingApiCallableBuilder - listLogEntriesMethod() { - return methods.listLogEntriesMethod; + public static Builder newBuilder() { + return new Builder(); } - /** - * Returns the PageStreamingApiCallableBuilder for the API method readLogEntries. - * - * - * - */ - public PageStreamingApiCallableBuilder - readLogEntriesMethod() { - return methods.readLogEntriesMethod; + public Builder toBuilder() { + return new Builder(this); } - /** - * Returns the PageStreamingApiCallableBuilder for the API method - * listMonitoredResourceDescriptors. - * - * - * - */ - public PageStreamingApiCallableBuilder< - ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, - MonitoredResourceDescriptor> - listMonitoredResourceDescriptorsMethod() { - return methods.listMonitoredResourceDescriptorsMethod; + private LoggingServiceV2Settings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getOrBuildChannel(), + settingsBuilder.shouldAutoCloseChannel(), + settingsBuilder.getOrBuildExecutor(), + settingsBuilder.getConnectionSettings(), + settingsBuilder.getGeneratorName(), + settingsBuilder.getGeneratorVersion(), + settingsBuilder.getClientLibName(), + settingsBuilder.getClientLibVersion()); + + deleteLogSettings = settingsBuilder.deleteLogSettings().build(); + writeLogEntriesSettings = settingsBuilder.writeLogEntriesSettings().build(); + listLogEntriesSettings = settingsBuilder.listLogEntriesSettings().build(); + listMonitoredResourceDescriptorsSettings = + settingsBuilder.listMonitoredResourceDescriptorsSettings().build(); } - private static PageDescriptor + private static PageStreamingDescriptor LIST_LOG_ENTRIES_PAGE_STR_DESC = - new PageDescriptor() { + new PageStreamingDescriptor() { @Override public Object emptyToken() { return ""; @@ -312,37 +182,11 @@ public Iterable extractResources(ListLogEntriesResponse payload) { } }; - private static PageDescriptor - READ_LOG_ENTRIES_PAGE_STR_DESC = - new PageDescriptor() { - @Override - public Object emptyToken() { - return ""; - } - - @Override - public ReadLogEntriesRequest injectToken(ReadLogEntriesRequest payload, Object token) { - return ReadLogEntriesRequest.newBuilder(payload) - .setResumeToken((String) token) - .build(); - } - - @Override - public Object extractNextToken(ReadLogEntriesResponse payload) { - return payload.getResumeToken(); - } - - @Override - public Iterable extractResources(ReadLogEntriesResponse payload) { - return payload.getEntriesList(); - } - }; - - private static PageDescriptor< + private static PageStreamingDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor> LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC = - new PageDescriptor< + new PageStreamingDescriptor< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor>() { @Override @@ -369,4 +213,178 @@ public Iterable extractResources( return payload.getResourceDescriptorsList(); } }; + + public static class Builder extends ServiceApiSettings.Builder { + private final ImmutableList methodSettingsBuilders; + + private SimpleCallSettings.Builder deleteLogSettings; + private SimpleCallSettings.Builder + writeLogEntriesSettings; + private PageStreamingCallSettings.Builder< + ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> + listLogEntriesSettings; + private PageStreamingCallSettings.Builder< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings; + + 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.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(2000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("default", settingsBuilder); + settingsBuilder = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.millis(100L)) + .setRetryDelayMultiplier(1.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(7000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("list", settingsBuilder); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + private Builder() { + super( + ConnectionSettings.builder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) + .build()); + + deleteLogSettings = + SimpleCallSettings.newBuilder(LoggingServiceV2Grpc.METHOD_DELETE_LOG) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + writeLogEntriesSettings = + SimpleCallSettings.newBuilder(LoggingServiceV2Grpc.METHOD_WRITE_LOG_ENTRIES) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + listLogEntriesSettings = + PageStreamingCallSettings.newBuilder( + LoggingServiceV2Grpc.METHOD_LIST_LOG_ENTRIES, LIST_LOG_ENTRIES_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("list")); + + listMonitoredResourceDescriptorsSettings = + PageStreamingCallSettings.newBuilder( + LoggingServiceV2Grpc.METHOD_LIST_MONITORED_RESOURCE_DESCRIPTORS, + LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + methodSettingsBuilders = + ImmutableList.of( + deleteLogSettings, + writeLogEntriesSettings, + listLogEntriesSettings, + listMonitoredResourceDescriptorsSettings); + } + + private Builder(LoggingServiceV2Settings settings) { + super(settings); + + deleteLogSettings = settings.deleteLogSettings.toBuilder(); + writeLogEntriesSettings = settings.writeLogEntriesSettings.toBuilder(); + listLogEntriesSettings = settings.listLogEntriesSettings.toBuilder(); + listMonitoredResourceDescriptorsSettings = + settings.listMonitoredResourceDescriptorsSettings.toBuilder(); + + methodSettingsBuilders = + ImmutableList.of( + deleteLogSettings, + writeLogEntriesSettings, + listLogEntriesSettings, + listMonitoredResourceDescriptorsSettings); + } + + @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 setExecutor(ScheduledExecutorService executor) { + super.setExecutor(executor); + 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; + } + + public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { + super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + return this; + } + + public SimpleCallSettings.Builder deleteLogSettings() { + return deleteLogSettings; + } + + public SimpleCallSettings.Builder + writeLogEntriesSettings() { + return writeLogEntriesSettings; + } + + public PageStreamingCallSettings.Builder< + ListLogEntriesRequest, ListLogEntriesResponse, LogEntry> + listLogEntriesSettings() { + return listLogEntriesSettings; + } + + public PageStreamingCallSettings.Builder< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptorsSettings() { + return listMonitoredResourceDescriptorsSettings; + } + + @Override + public LoggingServiceV2Settings build() throws IOException { + return new LoggingServiceV2Settings(this); + } + } } diff --git a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java index 3ebddfc51fb6..18821de2028f 100644 --- a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java +++ b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Api.java @@ -55,105 +55,13 @@ // AUTO-GENERATED DOCUMENTATION AND SERVICE - see instructions at the top of the file for editing. /** - * Service Description: See src/api/google/logging/v1/logging.proto for documentation + * Service Description: * * * */ @javax.annotation.Generated("by GAPIC") public class MetricsServiceV2Api implements AutoCloseable { - - public static class ResourceNames { - private ResourceNames() {} - - // ======================= - // ResourceNames Constants - // ======================= - - /** - * A PathTemplate representing the fully-qualified path to represent - * a project resource. - * - * - * - */ - private static final PathTemplate PROJECT_PATH_TEMPLATE = - PathTemplate.create("projects/{project}"); - - /** - * A PathTemplate representing the fully-qualified path to represent - * a metric resource. - * - * - * - */ - private static final PathTemplate METRIC_PATH_TEMPLATE = - PathTemplate.create("projects/{project}/metrics/{metric}"); - - // ============================== - // Resource Name Helper Functions - // ============================== - - /** - * Formats a string containing the fully-qualified path to represent - * a project resource. - * - * - * - */ - public static final String formatProjectPath(String project) { - return PROJECT_PATH_TEMPLATE.instantiate("project", project); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a metric resource. - * - * - * - */ - public static final String formatMetricPath(String project, String metric) { - return METRIC_PATH_TEMPLATE.instantiate("project", project, "metric", metric); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a project resource. - * - * - * - */ - public static final String parseProjectFromProjectPath(String projectPath) { - return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); - } - - /** - * Parses the project from the given fully-qualified path which - * represents a metric resource. - * - * - * - */ - public static final String parseProjectFromMetricPath(String metricPath) { - return METRIC_PATH_TEMPLATE.parse(metricPath).get("project"); - } - - /** - * Parses the metric from the given fully-qualified path which - * represents a metric resource. - * - * - * - */ - public static final String parseMetricFromMetricPath(String metricPath) { - return METRIC_PATH_TEMPLATE.parse(metricPath).get("metric"); - } - } - - // ======== - // Members - // ======== - private final ManagedChannel channel; private final List closeables = new ArrayList<>(); @@ -165,9 +73,66 @@ public static final String parseMetricFromMetricPath(String metricPath) { private final ApiCallable updateLogMetricCallable; private final ApiCallable deleteLogMetricCallable; - // =============== - // Factory Methods - // =============== + private static final PathTemplate PROJECT_PATH_TEMPLATE = + PathTemplate.create("projects/{project}"); + + private static final PathTemplate METRIC_PATH_TEMPLATE = + PathTemplate.create("projects/{project}/metrics/{metric}"); + + /** + * Formats a string containing the fully-qualified path to represent + * a project resource. + * + * + * + */ + public static final String formatProjectName(String project) { + return PROJECT_PATH_TEMPLATE.instantiate("project", project); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a metric resource. + * + * + * + */ + public static final String formatMetricName(String project, String metric) { + return METRIC_PATH_TEMPLATE.instantiate("project", project, "metric", metric); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a project resource. + * + * + * + */ + public static final String parseProjectFromProjectName(String projectName) { + return PROJECT_PATH_TEMPLATE.parse(projectName).get("project"); + } + + /** + * Parses the project from the given fully-qualified path which + * represents a metric resource. + * + * + * + */ + public static final String parseProjectFromMetricName(String metricName) { + return METRIC_PATH_TEMPLATE.parse(metricName).get("project"); + } + + /** + * Parses the metric from the given fully-qualified path which + * represents a metric resource. + * + * + * + */ + public static final String parseMetricFromMetricName(String metricName) { + return METRIC_PATH_TEMPLATE.parse(metricName).get("metric"); + } /** * Constructs an instance of MetricsServiceV2Api with default settings. @@ -175,24 +140,27 @@ public static final String parseMetricFromMetricPath(String metricPath) { * * */ - public static MetricsServiceV2Api create() throws IOException { - return create(MetricsServiceV2Settings.create()); + public static final MetricsServiceV2Api defaultInstance() throws IOException { + return create(MetricsServiceV2Settings.defaultInstance()); } /** - * Constructs an instance of MetricsServiceV2Api, using the given settings. The channels are - * created based on the settings passed in, or defaults for any settings that are not set. + * Constructs an instance of MetricsServiceV2Api, 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 MetricsServiceV2Api create(MetricsServiceV2Settings settings) throws IOException { + public static final MetricsServiceV2Api create(MetricsServiceV2Settings settings) + throws IOException { return new MetricsServiceV2Api(settings); } /** - * Constructs an instance of MetricsServiceV2Api, using the given settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. + * Constructs an instance of MetricsServiceV2Api, using the given settings. + * This is protected so that it easy to make a subclass, but otherwise, the static + * factory methods should be preferred. * * * @@ -200,27 +168,25 @@ public static MetricsServiceV2Api create(MetricsServiceV2Settings settings) thro protected MetricsServiceV2Api(MetricsServiceV2Settings settings) throws IOException { this.channel = settings.getChannel(); - this.listLogMetricsCallable = settings.listLogMetricsMethod().build(settings); + this.listLogMetricsCallable = ApiCallable.create(settings.listLogMetricsSettings(), settings); this.listLogMetricsIterableCallable = - settings.listLogMetricsMethod().buildPageStreaming(settings); - this.getLogMetricCallable = settings.getLogMetricMethod().build(settings); - this.createLogMetricCallable = settings.createLogMetricMethod().build(settings); - this.updateLogMetricCallable = settings.updateLogMetricMethod().build(settings); - this.deleteLogMetricCallable = settings.deleteLogMetricMethod().build(settings); - - closeables.add( - new Closeable() { - @Override - public void close() throws IOException { - channel.shutdown(); - } - }); + ApiCallable.createIterable(settings.listLogMetricsSettings(), settings); + this.getLogMetricCallable = ApiCallable.create(settings.getLogMetricSettings(), settings); + this.createLogMetricCallable = ApiCallable.create(settings.createLogMetricSettings(), settings); + this.updateLogMetricCallable = ApiCallable.create(settings.updateLogMetricSettings(), settings); + this.deleteLogMetricCallable = ApiCallable.create(settings.deleteLogMetricSettings(), settings); + + if (settings.shouldAutoCloseChannel()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } } - // ============= - // Service Calls - // ============= - // ----- listLogMetrics ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. @@ -229,8 +195,12 @@ public void close() throws IOException { * * * + * + * @param projectName Required. The resource name of the project containing the metrics. + * Example: `"projects/my-project-id"`. + * @throws ApiException if the remote call fails */ - public Iterable listLogMetrics(String projectName) { + public final Iterable listLogMetrics(String projectName) { ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setProjectName(projectName).build(); return listLogMetrics(request); @@ -244,8 +214,9 @@ public Iterable listLogMetrics(String projectName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ - public Iterable listLogMetrics(ListLogMetricsRequest request) { + public final Iterable listLogMetrics(ListLogMetricsRequest request) { return listLogMetricsIterableCallable().call(request); } @@ -255,8 +226,10 @@ public Iterable listLogMetrics(ListLogMetricsRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable> listLogMetricsIterableCallable() { + public final ApiCallable> + listLogMetricsIterableCallable() { return listLogMetricsIterableCallable; } @@ -266,8 +239,9 @@ public ApiCallable> listLogMetricsIte * * * + * @throws ApiException if the remote call fails */ - public ApiCallable listLogMetricsCallable() { + public final ApiCallable listLogMetricsCallable() { return listLogMetricsCallable; } @@ -282,8 +256,9 @@ public ApiCallable listLogMetrics * * @param metricName The resource name of the desired metric. * Example: `"projects/my-project-id/metrics/my-metric-id"`. + * @throws ApiException if the remote call fails */ - public LogMetric getLogMetric(String metricName) { + public final LogMetric getLogMetric(String metricName) { GetLogMetricRequest request = GetLogMetricRequest.newBuilder().setMetricName(metricName).build(); @@ -298,6 +273,7 @@ public LogMetric getLogMetric(String metricName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private LogMetric getLogMetric(GetLogMetricRequest request) { return getLogMetricCallable().call(request); @@ -309,8 +285,9 @@ private LogMetric getLogMetric(GetLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable getLogMetricCallable() { + public final ApiCallable getLogMetricCallable() { return getLogMetricCallable; } @@ -329,8 +306,9 @@ public ApiCallable getLogMetricCallable() { * The new metric must be provided in the request. * @param metric The new logs-based metric, which must not have an identifier that * already exists. + * @throws ApiException if the remote call fails */ - public LogMetric createLogMetric(String projectName, LogMetric metric) { + public final LogMetric createLogMetric(String projectName, LogMetric metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setProjectName(projectName).setMetric(metric).build(); @@ -345,6 +323,7 @@ public LogMetric createLogMetric(String projectName, LogMetric metric) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogMetric createLogMetric(CreateLogMetricRequest request) { return createLogMetricCallable().call(request); @@ -356,8 +335,9 @@ public LogMetric createLogMetric(CreateLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable createLogMetricCallable() { + public final ApiCallable createLogMetricCallable() { return createLogMetricCallable; } @@ -379,8 +359,9 @@ public ApiCallable createLogMetricCallable() * @param metric The updated metric, whose name must be the same as the * metric identifier in `metricName`. If `metricName` does not * exist, then a new metric is created. + * @throws ApiException if the remote call fails */ - public LogMetric updateLogMetric(String metricName, LogMetric metric) { + public final LogMetric updateLogMetric(String metricName, LogMetric metric) { UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder().setMetricName(metricName).setMetric(metric).build(); @@ -395,6 +376,7 @@ public LogMetric updateLogMetric(String metricName, LogMetric metric) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ public LogMetric updateLogMetric(UpdateLogMetricRequest request) { return updateLogMetricCallable().call(request); @@ -406,8 +388,9 @@ public LogMetric updateLogMetric(UpdateLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable updateLogMetricCallable() { + public final ApiCallable updateLogMetricCallable() { return updateLogMetricCallable; } @@ -422,8 +405,9 @@ public ApiCallable updateLogMetricCallable() * * @param metricName The resource name of the metric to delete. * Example: `"projects/my-project-id/metrics/my-metric-id"`. + * @throws ApiException if the remote call fails */ - public void deleteLogMetric(String metricName) { + public final void deleteLogMetric(String metricName) { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder().setMetricName(metricName).build(); @@ -438,6 +422,7 @@ public void deleteLogMetric(String metricName) { * * * @param request The request object containing all of the parameters for the API call. + * @throws ApiException if the remote call fails */ private void deleteLogMetric(DeleteLogMetricRequest request) { deleteLogMetricCallable().call(request); @@ -449,15 +434,12 @@ private void deleteLogMetric(DeleteLogMetricRequest request) { * * * + * @throws ApiException if the remote call fails */ - public ApiCallable deleteLogMetricCallable() { + public final ApiCallable deleteLogMetricCallable() { return deleteLogMetricCallable; } - // ======== - // Cleanup - // ======== - /** * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately * cancelled. @@ -466,7 +448,7 @@ public ApiCallable deleteLogMetricCallable() { * */ @Override - public void close() throws Exception { + public final void close() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } diff --git a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java index 804279ddfff0..1d38024fed11 100644 --- a/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java +++ b/gcloud-java-logging/src/main/java/com/google/gcloud/logging/spi/v2/MetricsServiceV2Settings.java @@ -33,14 +33,13 @@ package com.google.gcloud.logging.spi.v2; -import com.google.api.gax.core.BackoffParams; import com.google.api.gax.core.ConnectionSettings; -import com.google.api.gax.core.RetryParams; +import com.google.api.gax.core.RetrySettings; import com.google.api.gax.grpc.ApiCallSettings; -import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; -import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; -import com.google.api.gax.grpc.PageDescriptor; +import com.google.api.gax.grpc.PageStreamingCallSettings; +import com.google.api.gax.grpc.PageStreamingDescriptor; import com.google.api.gax.grpc.ServiceApiSettings; +import com.google.api.gax.grpc.SimpleCallSettings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -55,8 +54,11 @@ import com.google.logging.v2.MetricsServiceV2Grpc; import com.google.logging.v2.UpdateLogMetricRequest; import com.google.protobuf.Empty; - +import io.grpc.ManagedChannel; import io.grpc.Status; +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import org.joda.time.Duration; // Manually-added imports: add custom (non-generated) imports after this point. @@ -64,10 +66,6 @@ @javax.annotation.Generated("by GAPIC") public class MetricsServiceV2Settings extends ServiceApiSettings { - // ========= - // Constants - // ========= - /** * The default address of the service. * @@ -96,181 +94,68 @@ public class MetricsServiceV2Settings extends ServiceApiSettings { .add("https://www.googleapis.com/auth/cloud-platform") .build(); - 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 final PageStreamingCallSettings + listLogMetricsSettings; - private static final ImmutableMap RETRY_PARAM_DEFINITIONS; - - static { - ImmutableMap.Builder definitions = ImmutableMap.builder(); - RetryParams params = null; - params = - RetryParams.newBuilder() - .setRetryBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(100L) - .setDelayMultiplier(1.2) - .setMaxDelayMillis(1000L) - .build()) - .setTimeoutBackoff( - BackoffParams.newBuilder() - .setInitialDelayMillis(300L) - .setDelayMultiplier(1.3) - .setMaxDelayMillis(3000L) - .build()) - .setTotalTimeout(30000L) - .build(); - definitions.put("default", params); - RETRY_PARAM_DEFINITIONS = definitions.build(); - } + private final SimpleCallSettings getLogMetricSettings; + private final SimpleCallSettings createLogMetricSettings; + private final SimpleCallSettings updateLogMetricSettings; + private final SimpleCallSettings deleteLogMetricSettings; - private static class MethodBuilders { - private final PageStreamingApiCallableBuilder< - ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> - listLogMetricsMethod; - private final ApiCallableBuilder getLogMetricMethod; - private final ApiCallableBuilder createLogMetricMethod; - private final ApiCallableBuilder updateLogMetricMethod; - private final ApiCallableBuilder deleteLogMetricMethod; - private final ImmutableList allMethods; - - public MethodBuilders() { - listLogMetricsMethod = - new PageStreamingApiCallableBuilder<>( - MetricsServiceV2Grpc.METHOD_LIST_LOG_METRICS, LIST_LOG_METRICS_PAGE_STR_DESC); - listLogMetricsMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - listLogMetricsMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - getLogMetricMethod = new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_GET_LOG_METRIC); - getLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - getLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - createLogMetricMethod = - new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_CREATE_LOG_METRIC); - createLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - createLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - updateLogMetricMethod = - new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_UPDATE_LOG_METRIC); - updateLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); - updateLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - deleteLogMetricMethod = - new ApiCallableBuilder<>(MetricsServiceV2Grpc.METHOD_DELETE_LOG_METRIC); - deleteLogMetricMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); - deleteLogMetricMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); - - allMethods = - ImmutableList.builder() - .add( - listLogMetricsMethod, - getLogMetricMethod, - createLogMetricMethod, - updateLogMetricMethod, - deleteLogMetricMethod) - .build(); - } + public PageStreamingCallSettings + listLogMetricsSettings() { + return listLogMetricsSettings; } - private final MethodBuilders methods; - - // =============== - // Factory Methods - // =============== + public SimpleCallSettings getLogMetricSettings() { + return getLogMetricSettings; + } - /** - * Constructs an instance of MetricsServiceV2Settings with default settings. - * - * - * - */ - public static MetricsServiceV2Settings create() { - MetricsServiceV2Settings settings = new MetricsServiceV2Settings(new MethodBuilders()); - settings.provideChannelWith( - ConnectionSettings.builder() - .setServiceAddress(DEFAULT_SERVICE_ADDRESS) - .setPort(DEFAULT_SERVICE_PORT) - .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) - .build()); - return settings; + public SimpleCallSettings createLogMetricSettings() { + return createLogMetricSettings; } - /** - * Constructs an instance of MetricsServiceV2Settings with default settings. This is protected so - * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. - * - * - * - */ - protected MetricsServiceV2Settings(MethodBuilders methods) { - super(methods.allMethods); - this.methods = methods; + public SimpleCallSettings updateLogMetricSettings() { + return updateLogMetricSettings; } - /** - * Returns the PageStreamingApiCallableBuilder for the API method listLogMetrics. - * - * - * - */ - public PageStreamingApiCallableBuilder - listLogMetricsMethod() { - return methods.listLogMetricsMethod; + public SimpleCallSettings deleteLogMetricSettings() { + return deleteLogMetricSettings; } - /** - * Returns the ApiCallableBuilder for the API method getLogMetric. - * - * - * - */ - public ApiCallableBuilder getLogMetricMethod() { - return methods.getLogMetricMethod; + public static MetricsServiceV2Settings defaultInstance() throws IOException { + return newBuilder().build(); } - /** - * Returns the ApiCallableBuilder for the API method createLogMetric. - * - * - * - */ - public ApiCallableBuilder createLogMetricMethod() { - return methods.createLogMetricMethod; + public static Builder newBuilder() { + return new Builder(); } - /** - * Returns the ApiCallableBuilder for the API method updateLogMetric. - * - * - * - */ - public ApiCallableBuilder updateLogMetricMethod() { - return methods.updateLogMetricMethod; + public Builder toBuilder() { + return new Builder(this); } - /** - * Returns the ApiCallableBuilder for the API method deleteLogMetric. - * - * - * - */ - public ApiCallableBuilder deleteLogMetricMethod() { - return methods.deleteLogMetricMethod; + private MetricsServiceV2Settings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getOrBuildChannel(), + settingsBuilder.shouldAutoCloseChannel(), + settingsBuilder.getOrBuildExecutor(), + settingsBuilder.getConnectionSettings(), + settingsBuilder.getGeneratorName(), + settingsBuilder.getGeneratorVersion(), + settingsBuilder.getClientLibName(), + settingsBuilder.getClientLibVersion()); + + listLogMetricsSettings = settingsBuilder.listLogMetricsSettings().build(); + getLogMetricSettings = settingsBuilder.getLogMetricSettings().build(); + createLogMetricSettings = settingsBuilder.createLogMetricSettings().build(); + updateLogMetricSettings = settingsBuilder.updateLogMetricSettings().build(); + deleteLogMetricSettings = settingsBuilder.deleteLogMetricSettings().build(); } - private static PageDescriptor + private static PageStreamingDescriptor LIST_LOG_METRICS_PAGE_STR_DESC = - new PageDescriptor() { + new PageStreamingDescriptor() { @Override public Object emptyToken() { return ""; @@ -291,4 +176,170 @@ public Iterable extractResources(ListLogMetricsResponse payload) { return payload.getMetricsList(); } }; + + public static class Builder extends ServiceApiSettings.Builder { + private final ImmutableList methodSettingsBuilders; + + private PageStreamingCallSettings.Builder< + ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> + listLogMetricsSettings; + private SimpleCallSettings.Builder getLogMetricSettings; + private SimpleCallSettings.Builder createLogMetricSettings; + private SimpleCallSettings.Builder updateLogMetricSettings; + private SimpleCallSettings.Builder deleteLogMetricSettings; + + 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.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(2000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("default", settingsBuilder); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + private Builder() { + super( + ConnectionSettings.builder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) + .build()); + + listLogMetricsSettings = + PageStreamingCallSettings.newBuilder( + MetricsServiceV2Grpc.METHOD_LIST_LOG_METRICS, LIST_LOG_METRICS_PAGE_STR_DESC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + getLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_GET_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + createLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_CREATE_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + updateLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_UPDATE_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + deleteLogMetricSettings = + SimpleCallSettings.newBuilder(MetricsServiceV2Grpc.METHOD_DELETE_LOG_METRIC) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + methodSettingsBuilders = + ImmutableList.of( + listLogMetricsSettings, + getLogMetricSettings, + createLogMetricSettings, + updateLogMetricSettings, + deleteLogMetricSettings); + } + + private Builder(MetricsServiceV2Settings settings) { + super(settings); + + listLogMetricsSettings = settings.listLogMetricsSettings.toBuilder(); + getLogMetricSettings = settings.getLogMetricSettings.toBuilder(); + createLogMetricSettings = settings.createLogMetricSettings.toBuilder(); + updateLogMetricSettings = settings.updateLogMetricSettings.toBuilder(); + deleteLogMetricSettings = settings.deleteLogMetricSettings.toBuilder(); + + methodSettingsBuilders = + ImmutableList.of( + listLogMetricsSettings, + getLogMetricSettings, + createLogMetricSettings, + updateLogMetricSettings, + deleteLogMetricSettings); + } + + @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 setExecutor(ScheduledExecutorService executor) { + super.setExecutor(executor); + 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; + } + + public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { + super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + return this; + } + + public PageStreamingCallSettings.Builder< + ListLogMetricsRequest, ListLogMetricsResponse, LogMetric> + listLogMetricsSettings() { + return listLogMetricsSettings; + } + + public SimpleCallSettings.Builder getLogMetricSettings() { + return getLogMetricSettings; + } + + public SimpleCallSettings.Builder createLogMetricSettings() { + return createLogMetricSettings; + } + + public SimpleCallSettings.Builder updateLogMetricSettings() { + return updateLogMetricSettings; + } + + public SimpleCallSettings.Builder deleteLogMetricSettings() { + return deleteLogMetricSettings; + } + + @Override + public MetricsServiceV2Settings build() throws IOException { + return new MetricsServiceV2Settings(this); + } + } } diff --git a/gcloud-java-logging/src/test/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2ApiTest.java b/gcloud-java-logging/src/test/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2ApiTest.java index e290fe79dadc..1379bd4b558d 100644 --- a/gcloud-java-logging/src/test/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2ApiTest.java +++ b/gcloud-java-logging/src/test/java/com/google/gcloud/logging/spi/v2/LoggingServiceV2ApiTest.java @@ -49,8 +49,9 @@ public static void stopServer() { @Before public void setUp() throws IOException { loggingHelper.reset(); - LoggingServiceV2Settings settings = LoggingServiceV2Settings.create(); - settings.provideChannelWith(loggingHelper.createChannel()); + LoggingServiceV2Settings settings = LoggingServiceV2Settings.newBuilder() + .provideChannelWith(loggingHelper.createChannel(), true) + .build(); loggingApi = LoggingServiceV2Api.create(settings); } @@ -61,7 +62,7 @@ public void tearDown() throws Exception { @Test public void testWriteLog() { - String logName = LoggingServiceV2Api.ResourceNames.formatLogPath("my-project", "my-log"); + String logName = LoggingServiceV2Api.formatLogName("my-project", "my-log"); MonitoredResource resource = MonitoredResource.newBuilder().build(); List entries = new ArrayList<>(); entries.add(LogEntry.newBuilder().setLogName(logName).setTextPayload("foobar").build()); @@ -70,7 +71,7 @@ public void testWriteLog() { @Test public void testListLog() { - String logName = LoggingServiceV2Api.ResourceNames.formatLogPath("my-project", "my-log"); + String logName = LoggingServiceV2Api.formatLogName("my-project", "my-log"); MonitoredResource resource = MonitoredResource.newBuilder().build(); List entries = new ArrayList<>(); entries.add(LogEntry.newBuilder().setLogName(logName).setTextPayload("foobar").build()); @@ -90,7 +91,7 @@ public void testListNoLog() { @Test public void testDeleteLog() { - String logName = LoggingServiceV2Api.ResourceNames.formatLogPath("my-project", "my-log"); + String logName = LoggingServiceV2Api.formatLogName("my-project", "my-log"); MonitoredResource resource = MonitoredResource.newBuilder().build(); List entries = new ArrayList<>(); entries.add(LogEntry.newBuilder().setLogName(logName).setTextPayload("foobar").build());