From 6678f242dc1713510f372bc119428ff92dd6b4a7 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Tue, 16 Feb 2021 14:37:08 -0800 Subject: [PATCH 1/2] chore: Update googleapis to 2bea43 and integration tests --- repositories.bzl | 4 +- test/integration/BUILD.bazel | 6 +- .../goldens/asset/AssetServiceClient.java | 151 ++++ .../goldens/asset/AssetServiceClientTest.java | 106 +++ .../goldens/asset/AssetServiceSettings.java | 43 ++ .../goldens/asset/AssetServiceStub.java | 24 + .../asset/AssetServiceStubSettings.java | 138 +++- .../goldens/asset/GrpcAssetServiceStub.java | 102 +++ .../goldens/asset/MockAssetServiceImpl.java | 42 ++ .../goldens/logging/ConfigClient.java | 577 +++++++++++++++- .../goldens/logging/ConfigClientTest.java | 437 ++++++++++++ .../goldens/logging/ConfigServiceV2Stub.java | 47 ++ .../logging/ConfigServiceV2StubSettings.java | 245 +++++++ .../goldens/logging/ConfigSettings.java | 93 +++ .../logging/GrpcConfigServiceV2Stub.java | 264 +++++++ .../logging/GrpcLoggingServiceV2Stub.java | 30 + .../goldens/logging/LogViewName.java | 643 ++++++++++++++++++ .../goldens/logging/LoggingClient.java | 39 ++ .../goldens/logging/LoggingClientTest.java | 68 ++ .../goldens/logging/LoggingServiceV2Stub.java | 8 + .../logging/LoggingServiceV2StubSettings.java | 40 ++ .../goldens/logging/LoggingSettings.java | 15 + .../logging/MockConfigServiceV2Impl.java | 173 +++++ .../logging/MockLoggingServiceV2Impl.java | 39 ++ 24 files changed, 3315 insertions(+), 19 deletions(-) create mode 100644 test/integration/goldens/logging/LogViewName.java diff --git a/repositories.bzl b/repositories.bzl index 9b1a8cd45b..e246cef5cc 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -59,9 +59,9 @@ def gapic_generator_java_repositories(): _maybe( http_archive, name = "com_google_googleapis", - strip_prefix = "googleapis-bda7ce951def5ae6e5c4258d0e569188dd4ae02b", + strip_prefix = "googleapis-2bea43cdc7a4443876380732980d83cd8d560582", urls = [ - "https://github.com/googleapis/googleapis/archive/bda7ce951def5ae6e5c4258d0e569188dd4ae02b.zip", + "https://github.com/googleapis/googleapis/archive/2bea43cdc7a4443876380732980d83cd8d560582.zip", ], ) diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 449f19b19d..be61adbdee 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -1,8 +1,8 @@ load( "@com_google_googleapis_imports//:imports.bzl", - java_gapic_assembly_gradle_pkg = "java_gapic_assembly_gradle_pkg2", - java_gapic_library = "java_gapic_library2", - java_gapic_test = "java_gapic_test2", + "java_gapic_assembly_gradle_pkg", + "java_gapic_library", + "java_gapic_test", ) load( "//:rules_bazel/java/integration_test.bzl", diff --git a/test/integration/goldens/asset/AssetServiceClient.java b/test/integration/goldens/asset/AssetServiceClient.java index c22e2a50dc..b500f19330 100644 --- a/test/integration/goldens/asset/AssetServiceClient.java +++ b/test/integration/goldens/asset/AssetServiceClient.java @@ -1060,6 +1060,157 @@ public final SearchAllIamPoliciesPagedResponse searchAllIamPolicies( return stub.searchAllIamPoliciesCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Analyzes IAM policies to answer which identities have what accesses on which resources. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   AnalyzeIamPolicyRequest request =
+   *       AnalyzeIamPolicyRequest.newBuilder()
+   *           .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build())
+   *           .setExecutionTimeout(Duration.newBuilder().build())
+   *           .build();
+   *   AnalyzeIamPolicyResponse response = assetServiceClient.analyzeIamPolicy(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AnalyzeIamPolicyResponse analyzeIamPolicy(AnalyzeIamPolicyRequest request) { + return analyzeIamPolicyCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Analyzes IAM policies to answer which identities have what accesses on which resources. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   AnalyzeIamPolicyRequest request =
+   *       AnalyzeIamPolicyRequest.newBuilder()
+   *           .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build())
+   *           .setExecutionTimeout(Duration.newBuilder().build())
+   *           .build();
+   *   ApiFuture future =
+   *       assetServiceClient.analyzeIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   AnalyzeIamPolicyResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + analyzeIamPolicyCallable() { + return stub.analyzeIamPolicyCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Analyzes IAM policies asynchronously to answer which identities have what accesses on which + * resources, and writes the analysis results to a Google Cloud Storage or a BigQuery destination. + * For Cloud Storage destination, the output format is the JSON format that represents a + * [AnalyzeIamPolicyResponse][google.cloud.asset.v1.AnalyzeIamPolicyResponse]. This method + * implements the [google.longrunning.Operation][google.longrunning.Operation], which allows you + * to track the operation status. We recommend intervals of at least 2 seconds with exponential + * backoff retry to poll the operation result. The metadata contains the request to help callers + * to map responses to requests. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   AnalyzeIamPolicyLongrunningRequest request =
+   *       AnalyzeIamPolicyLongrunningRequest.newBuilder()
+   *           .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build())
+   *           .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build())
+   *           .build();
+   *   AnalyzeIamPolicyLongrunningResponse response =
+   *       assetServiceClient.analyzeIamPolicyLongrunningAsync(request).get();
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture< + AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningAsync(AnalyzeIamPolicyLongrunningRequest request) { + return analyzeIamPolicyLongrunningOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Analyzes IAM policies asynchronously to answer which identities have what accesses on which + * resources, and writes the analysis results to a Google Cloud Storage or a BigQuery destination. + * For Cloud Storage destination, the output format is the JSON format that represents a + * [AnalyzeIamPolicyResponse][google.cloud.asset.v1.AnalyzeIamPolicyResponse]. This method + * implements the [google.longrunning.Operation][google.longrunning.Operation], which allows you + * to track the operation status. We recommend intervals of at least 2 seconds with exponential + * backoff retry to poll the operation result. The metadata contains the request to help callers + * to map responses to requests. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   AnalyzeIamPolicyLongrunningRequest request =
+   *       AnalyzeIamPolicyLongrunningRequest.newBuilder()
+   *           .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build())
+   *           .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build())
+   *           .build();
+   *   OperationFuture
+   *       future =
+   *           assetServiceClient.analyzeIamPolicyLongrunningOperationCallable().futureCall(request);
+   *   // Do something.
+   *   AnalyzeIamPolicyLongrunningResponse response = future.get();
+   * }
+   * }
+ */ + public final OperationCallable< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationCallable() { + return stub.analyzeIamPolicyLongrunningOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Analyzes IAM policies asynchronously to answer which identities have what accesses on which + * resources, and writes the analysis results to a Google Cloud Storage or a BigQuery destination. + * For Cloud Storage destination, the output format is the JSON format that represents a + * [AnalyzeIamPolicyResponse][google.cloud.asset.v1.AnalyzeIamPolicyResponse]. This method + * implements the [google.longrunning.Operation][google.longrunning.Operation], which allows you + * to track the operation status. We recommend intervals of at least 2 seconds with exponential + * backoff retry to poll the operation result. The metadata contains the request to help callers + * to map responses to requests. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   AnalyzeIamPolicyLongrunningRequest request =
+   *       AnalyzeIamPolicyLongrunningRequest.newBuilder()
+   *           .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build())
+   *           .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build())
+   *           .build();
+   *   ApiFuture future =
+   *       assetServiceClient.analyzeIamPolicyLongrunningCallable().futureCall(request);
+   *   // Do something.
+   *   Operation response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + analyzeIamPolicyLongrunningCallable() { + return stub.analyzeIamPolicyLongrunningCallable(); + } + @Override public final void close() { stub.close(); diff --git a/test/integration/goldens/asset/AssetServiceClientTest.java b/test/integration/goldens/asset/AssetServiceClientTest.java index b2f1a516c8..e94fde4a24 100644 --- a/test/integration/goldens/asset/AssetServiceClientTest.java +++ b/test/integration/goldens/asset/AssetServiceClientTest.java @@ -31,6 +31,7 @@ import com.google.longrunning.Operation; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Any; +import com.google.protobuf.Duration; import com.google.protobuf.Empty; import com.google.protobuf.Timestamp; import com.google.type.Expr; @@ -581,4 +582,109 @@ public void searchAllIamPoliciesExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void analyzeIamPolicyTest() throws Exception { + AnalyzeIamPolicyResponse expectedResponse = + AnalyzeIamPolicyResponse.newBuilder() + .setMainAnalysis(AnalyzeIamPolicyResponse.IamPolicyAnalysis.newBuilder().build()) + .addAllServiceAccountImpersonationAnalysis( + new ArrayList()) + .setFullyExplored(true) + .build(); + mockAssetService.addResponse(expectedResponse); + + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setExecutionTimeout(Duration.newBuilder().build()) + .build(); + + AnalyzeIamPolicyResponse actualResponse = client.analyzeIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockAssetService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnalyzeIamPolicyRequest actualRequest = ((AnalyzeIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getAnalysisQuery(), actualRequest.getAnalysisQuery()); + Assert.assertEquals(request.getExecutionTimeout(), actualRequest.getExecutionTimeout()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void analyzeIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockAssetService.addException(exception); + + try { + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setExecutionTimeout(Duration.newBuilder().build()) + .build(); + client.analyzeIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void analyzeIamPolicyLongrunningTest() throws Exception { + AnalyzeIamPolicyLongrunningResponse expectedResponse = + AnalyzeIamPolicyLongrunningResponse.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("analyzeIamPolicyLongrunningTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockAssetService.addResponse(resultOperation); + + AnalyzeIamPolicyLongrunningRequest request = + AnalyzeIamPolicyLongrunningRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + + AnalyzeIamPolicyLongrunningResponse actualResponse = + client.analyzeIamPolicyLongrunningAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockAssetService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnalyzeIamPolicyLongrunningRequest actualRequest = + ((AnalyzeIamPolicyLongrunningRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getAnalysisQuery(), actualRequest.getAnalysisQuery()); + Assert.assertEquals(request.getOutputConfig(), actualRequest.getOutputConfig()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void analyzeIamPolicyLongrunningExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockAssetService.addException(exception); + + try { + AnalyzeIamPolicyLongrunningRequest request = + AnalyzeIamPolicyLongrunningRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + client.analyzeIamPolicyLongrunningAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } } diff --git a/test/integration/goldens/asset/AssetServiceSettings.java b/test/integration/goldens/asset/AssetServiceSettings.java index be010b730a..943b984856 100644 --- a/test/integration/goldens/asset/AssetServiceSettings.java +++ b/test/integration/goldens/asset/AssetServiceSettings.java @@ -131,6 +131,28 @@ public UnaryCallSettings deleteFeedSettings() { return ((AssetServiceStubSettings) getStubSettings()).searchAllIamPoliciesSettings(); } + /** Returns the object with the settings used for calls to analyzeIamPolicy. */ + public UnaryCallSettings + analyzeIamPolicySettings() { + return ((AssetServiceStubSettings) getStubSettings()).analyzeIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to analyzeIamPolicyLongrunning. */ + public UnaryCallSettings + analyzeIamPolicyLongrunningSettings() { + return ((AssetServiceStubSettings) getStubSettings()).analyzeIamPolicyLongrunningSettings(); + } + + /** Returns the object with the settings used for calls to analyzeIamPolicyLongrunning. */ + public OperationCallSettings< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationSettings() { + return ((AssetServiceStubSettings) getStubSettings()) + .analyzeIamPolicyLongrunningOperationSettings(); + } + public static final AssetServiceSettings create(AssetServiceStubSettings stub) throws IOException { return new AssetServiceSettings.Builder(stub.toBuilder()).build(); @@ -288,6 +310,27 @@ public UnaryCallSettings.Builder deleteFeedSettings() return getStubSettingsBuilder().searchAllIamPoliciesSettings(); } + /** Returns the builder for the settings used for calls to analyzeIamPolicy. */ + public UnaryCallSettings.Builder + analyzeIamPolicySettings() { + return getStubSettingsBuilder().analyzeIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to analyzeIamPolicyLongrunning. */ + public UnaryCallSettings.Builder + analyzeIamPolicyLongrunningSettings() { + return getStubSettingsBuilder().analyzeIamPolicyLongrunningSettings(); + } + + /** Returns the builder for the settings used for calls to analyzeIamPolicyLongrunning. */ + public OperationCallSettings.Builder< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationSettings() { + return getStubSettingsBuilder().analyzeIamPolicyLongrunningOperationSettings(); + } + @Override public AssetServiceSettings build() throws IOException { return new AssetServiceSettings(this); diff --git a/test/integration/goldens/asset/AssetServiceStub.java b/test/integration/goldens/asset/AssetServiceStub.java index 274dfb3911..649aeed469 100644 --- a/test/integration/goldens/asset/AssetServiceStub.java +++ b/test/integration/goldens/asset/AssetServiceStub.java @@ -22,6 +22,10 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; +import com.google.cloud.asset.v1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyResponse; import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; import com.google.cloud.asset.v1.CreateFeedRequest; @@ -109,6 +113,26 @@ public UnaryCallable deleteFeedCallable() { throw new UnsupportedOperationException("Not implemented: searchAllIamPoliciesCallable()"); } + public UnaryCallable + analyzeIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: analyzeIamPolicyCallable()"); + } + + public OperationCallable< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationCallable() { + throw new UnsupportedOperationException( + "Not implemented: analyzeIamPolicyLongrunningOperationCallable()"); + } + + public UnaryCallable + analyzeIamPolicyLongrunningCallable() { + throw new UnsupportedOperationException( + "Not implemented: analyzeIamPolicyLongrunningCallable()"); + } + @Override public abstract void close(); } diff --git a/test/integration/goldens/asset/AssetServiceStubSettings.java b/test/integration/goldens/asset/AssetServiceStubSettings.java index 6b6094255d..3b36724e36 100644 --- a/test/integration/goldens/asset/AssetServiceStubSettings.java +++ b/test/integration/goldens/asset/AssetServiceStubSettings.java @@ -45,6 +45,10 @@ import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; +import com.google.cloud.asset.v1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyResponse; import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; import com.google.cloud.asset.v1.CreateFeedRequest; @@ -130,6 +134,15 @@ public class AssetServiceStubSettings extends StubSettings searchAllIamPoliciesSettings; + private final UnaryCallSettings + analyzeIamPolicySettings; + private final UnaryCallSettings + analyzeIamPolicyLongrunningSettings; + private final OperationCallSettings< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationSettings; private static final PagedListDescriptor< SearchAllResourcesRequest, SearchAllResourcesResponse, ResourceSearchResult> @@ -319,6 +332,27 @@ public UnaryCallSettings deleteFeedSettings() { return searchAllIamPoliciesSettings; } + /** Returns the object with the settings used for calls to analyzeIamPolicy. */ + public UnaryCallSettings + analyzeIamPolicySettings() { + return analyzeIamPolicySettings; + } + + /** Returns the object with the settings used for calls to analyzeIamPolicyLongrunning. */ + public UnaryCallSettings + analyzeIamPolicyLongrunningSettings() { + return analyzeIamPolicyLongrunningSettings; + } + + /** Returns the object with the settings used for calls to analyzeIamPolicyLongrunning. */ + public OperationCallSettings< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationSettings() { + return analyzeIamPolicyLongrunningOperationSettings; + } + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public AssetServiceStub createStub() throws IOException { if (getTransportChannelProvider() @@ -398,6 +432,11 @@ protected AssetServiceStubSettings(Builder settingsBuilder) throws IOException { deleteFeedSettings = settingsBuilder.deleteFeedSettings().build(); searchAllResourcesSettings = settingsBuilder.searchAllResourcesSettings().build(); searchAllIamPoliciesSettings = settingsBuilder.searchAllIamPoliciesSettings().build(); + analyzeIamPolicySettings = settingsBuilder.analyzeIamPolicySettings().build(); + analyzeIamPolicyLongrunningSettings = + settingsBuilder.analyzeIamPolicyLongrunningSettings().build(); + analyzeIamPolicyLongrunningOperationSettings = + settingsBuilder.analyzeIamPolicyLongrunningOperationSettings().build(); } /** Builder for AssetServiceStubSettings. */ @@ -423,6 +462,15 @@ public static class Builder extends StubSettings.Builder searchAllIamPoliciesSettings; + private final UnaryCallSettings.Builder + analyzeIamPolicySettings; + private final UnaryCallSettings.Builder + analyzeIamPolicyLongrunningSettings; + private final OperationCallSettings.Builder< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -441,6 +489,9 @@ public static class Builder extends StubSettings.BuildernewArrayList( StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); + definitions.put( + "retry_policy_3_codes", + ImmutableSet.copyOf(Lists.newArrayList(StatusCode.Code.UNAVAILABLE))); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } @@ -479,6 +530,17 @@ public static class Builder extends StubSettings.Builder>of( @@ -511,7 +576,9 @@ protected Builder(ClientContext clientContext) { updateFeedSettings, deleteFeedSettings, searchAllResourcesSettings, - searchAllIamPoliciesSettings); + searchAllIamPoliciesSettings, + analyzeIamPolicySettings, + analyzeIamPolicyLongrunningSettings); initDefaults(this); } @@ -528,6 +595,11 @@ protected Builder(AssetServiceStubSettings settings) { deleteFeedSettings = settings.deleteFeedSettings.toBuilder(); searchAllResourcesSettings = settings.searchAllResourcesSettings.toBuilder(); searchAllIamPoliciesSettings = settings.searchAllIamPoliciesSettings.toBuilder(); + analyzeIamPolicySettings = settings.analyzeIamPolicySettings.toBuilder(); + analyzeIamPolicyLongrunningSettings = + settings.analyzeIamPolicyLongrunningSettings.toBuilder(); + analyzeIamPolicyLongrunningOperationSettings = + settings.analyzeIamPolicyLongrunningOperationSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -539,7 +611,9 @@ protected Builder(AssetServiceStubSettings settings) { updateFeedSettings, deleteFeedSettings, searchAllResourcesSettings, - searchAllIamPoliciesSettings); + searchAllIamPoliciesSettings, + analyzeIamPolicySettings, + analyzeIamPolicyLongrunningSettings); } private static Builder createDefault() { @@ -599,6 +673,16 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params")); + builder + .analyzeIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_3_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_3_params")); + + builder + .analyzeIamPolicyLongrunningSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder .exportAssetsOperationSettings() .setInitialCallSettings( @@ -623,6 +707,33 @@ private static Builder initDefaults(Builder builder) { .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder + .analyzeIamPolicyLongrunningOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + . + newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create( + AnalyzeIamPolicyLongrunningResponse.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create( + AnalyzeIamPolicyLongrunningRequest.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(5000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + return builder; } @@ -703,6 +814,29 @@ public UnaryCallSettings.Builder deleteFeedSettings() return searchAllIamPoliciesSettings; } + /** Returns the builder for the settings used for calls to analyzeIamPolicy. */ + public UnaryCallSettings.Builder + analyzeIamPolicySettings() { + return analyzeIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to analyzeIamPolicyLongrunning. */ + public UnaryCallSettings.Builder + analyzeIamPolicyLongrunningSettings() { + return analyzeIamPolicyLongrunningSettings; + } + + /** Returns the builder for the settings used for calls to analyzeIamPolicyLongrunning. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationSettings() { + return analyzeIamPolicyLongrunningOperationSettings; + } + @Override public AssetServiceStubSettings build() throws IOException { return new AssetServiceStubSettings(this); diff --git a/test/integration/goldens/asset/GrpcAssetServiceStub.java b/test/integration/goldens/asset/GrpcAssetServiceStub.java index baaefdd441..ad389d9bf0 100644 --- a/test/integration/goldens/asset/GrpcAssetServiceStub.java +++ b/test/integration/goldens/asset/GrpcAssetServiceStub.java @@ -27,6 +27,10 @@ import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; +import com.google.cloud.asset.v1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyResponse; import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; import com.google.cloud.asset.v1.CreateFeedRequest; @@ -144,6 +148,27 @@ public class GrpcAssetServiceStub extends AssetServiceStub { ProtoUtils.marshaller(SearchAllIamPoliciesResponse.getDefaultInstance())) .build(); + private static final MethodDescriptor + analyzeIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.asset.v1.AssetService/AnalyzeIamPolicy") + .setRequestMarshaller( + ProtoUtils.marshaller(AnalyzeIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(AnalyzeIamPolicyResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + analyzeIamPolicyLongrunningMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.asset.v1.AssetService/AnalyzeIamPolicyLongrunning") + .setRequestMarshaller( + ProtoUtils.marshaller(AnalyzeIamPolicyLongrunningRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private final UnaryCallable exportAssetsCallable; private final OperationCallable exportAssetsOperationCallable; @@ -162,6 +187,15 @@ public class GrpcAssetServiceStub extends AssetServiceStub { searchAllIamPoliciesCallable; private final UnaryCallable searchAllIamPoliciesPagedCallable; + private final UnaryCallable + analyzeIamPolicyCallable; + private final UnaryCallable + analyzeIamPolicyLongrunningCallable; + private final OperationCallable< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -326,6 +360,39 @@ public Map extract(SearchAllIamPoliciesRequest request) { } }) .build(); + GrpcCallSettings + analyzeIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(analyzeIamPolicyMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(AnalyzeIamPolicyRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put( + "analysis_query.scope", + String.valueOf(request.getAnalysisQuery().getScope())); + return params.build(); + } + }) + .build(); + GrpcCallSettings + analyzeIamPolicyLongrunningTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(analyzeIamPolicyLongrunningMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract( + AnalyzeIamPolicyLongrunningRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put( + "analysis_query.scope", + String.valueOf(request.getAnalysisQuery().getScope())); + return params.build(); + } + }) + .build(); this.exportAssetsCallable = callableFactory.createUnaryCallable( @@ -376,6 +443,20 @@ public Map extract(SearchAllIamPoliciesRequest request) { searchAllIamPoliciesTransportSettings, settings.searchAllIamPoliciesSettings(), clientContext); + this.analyzeIamPolicyCallable = + callableFactory.createUnaryCallable( + analyzeIamPolicyTransportSettings, settings.analyzeIamPolicySettings(), clientContext); + this.analyzeIamPolicyLongrunningCallable = + callableFactory.createUnaryCallable( + analyzeIamPolicyLongrunningTransportSettings, + settings.analyzeIamPolicyLongrunningSettings(), + clientContext); + this.analyzeIamPolicyLongrunningOperationCallable = + callableFactory.createOperationCallable( + analyzeIamPolicyLongrunningTransportSettings, + settings.analyzeIamPolicyLongrunningOperationSettings(), + clientContext, + operationsStub); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -451,6 +532,27 @@ public UnaryCallable deleteFeedCallable() { return searchAllIamPoliciesPagedCallable; } + @Override + public UnaryCallable + analyzeIamPolicyCallable() { + return analyzeIamPolicyCallable; + } + + @Override + public UnaryCallable + analyzeIamPolicyLongrunningCallable() { + return analyzeIamPolicyLongrunningCallable; + } + + @Override + public OperationCallable< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningRequest> + analyzeIamPolicyLongrunningOperationCallable() { + return analyzeIamPolicyLongrunningOperationCallable; + } + @Override public final void close() { shutdown(); diff --git a/test/integration/goldens/asset/MockAssetServiceImpl.java b/test/integration/goldens/asset/MockAssetServiceImpl.java index 46798d0326..8141dec690 100644 --- a/test/integration/goldens/asset/MockAssetServiceImpl.java +++ b/test/integration/goldens/asset/MockAssetServiceImpl.java @@ -241,4 +241,46 @@ public void searchAllIamPolicies( Exception.class.getName()))); } } + + @Override + public void analyzeIamPolicy( + AnalyzeIamPolicyRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof AnalyzeIamPolicyResponse) { + requests.add(request); + responseObserver.onNext(((AnalyzeIamPolicyResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method AnalyzeIamPolicy, expected %s or %s", + response.getClass().getName(), + AnalyzeIamPolicyResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void analyzeIamPolicyLongrunning( + AnalyzeIamPolicyLongrunningRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext(((Operation) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method AnalyzeIamPolicyLongrunning, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); + } + } } diff --git a/test/integration/goldens/logging/ConfigClient.java b/test/integration/goldens/logging/ConfigClient.java index ec7a1fb4e7..886f3acaa2 100644 --- a/test/integration/goldens/logging/ConfigClient.java +++ b/test/integration/goldens/logging/ConfigClient.java @@ -32,35 +32,45 @@ import com.google.logging.v2.BillingAccountLocationName; import com.google.logging.v2.BillingAccountName; import com.google.logging.v2.CmekSettings; +import com.google.logging.v2.CreateBucketRequest; import com.google.logging.v2.CreateExclusionRequest; import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.CreateViewRequest; +import com.google.logging.v2.DeleteBucketRequest; import com.google.logging.v2.DeleteExclusionRequest; import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.DeleteViewRequest; import com.google.logging.v2.FolderLocationName; import com.google.logging.v2.FolderName; import com.google.logging.v2.GetBucketRequest; import com.google.logging.v2.GetCmekSettingsRequest; import com.google.logging.v2.GetExclusionRequest; import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.GetViewRequest; import com.google.logging.v2.ListBucketsRequest; import com.google.logging.v2.ListBucketsResponse; import com.google.logging.v2.ListExclusionsRequest; import com.google.logging.v2.ListExclusionsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.ListViewsRequest; +import com.google.logging.v2.ListViewsResponse; import com.google.logging.v2.LocationName; import com.google.logging.v2.LogBucket; import com.google.logging.v2.LogExclusion; import com.google.logging.v2.LogExclusionName; import com.google.logging.v2.LogSink; import com.google.logging.v2.LogSinkName; +import com.google.logging.v2.LogView; import com.google.logging.v2.OrganizationLocationName; import com.google.logging.v2.OrganizationName; import com.google.logging.v2.ProjectName; +import com.google.logging.v2.UndeleteBucketRequest; import com.google.logging.v2.UpdateBucketRequest; import com.google.logging.v2.UpdateCmekSettingsRequest; import com.google.logging.v2.UpdateExclusionRequest; import com.google.logging.v2.UpdateSinkRequest; +import com.google.logging.v2.UpdateViewRequest; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -185,7 +195,7 @@ public ConfigServiceV2Stub getStub() { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -218,7 +228,7 @@ public final ListBucketsPagedResponse listBuckets(BillingAccountLocationName par // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -250,7 +260,7 @@ public final ListBucketsPagedResponse listBuckets(FolderLocationName parent) { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -282,7 +292,7 @@ public final ListBucketsPagedResponse listBuckets(LocationName parent) { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -314,7 +324,7 @@ public final ListBucketsPagedResponse listBuckets(OrganizationLocationName paren // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -345,7 +355,7 @@ public final ListBucketsPagedResponse listBuckets(String parent) { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -374,7 +384,7 @@ public final ListBucketsPagedResponse listBuckets(ListBucketsRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -403,7 +413,7 @@ public final ListBucketsPagedResponse listBuckets(ListBucketsRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Lists buckets (Beta). + * Lists buckets. * *

Sample code: * @@ -430,7 +440,7 @@ public final UnaryCallable listBucketsC // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Gets a bucket (Beta). + * Gets a bucket. * *

Sample code: * @@ -455,7 +465,7 @@ public final LogBucket getBucket(GetBucketRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Gets a bucket (Beta). + * Gets a bucket. * *

Sample code: * @@ -477,6 +487,61 @@ public final UnaryCallable getBucketCallable() { return stub.getBucketCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a bucket that can be used to store log entries. Once a bucket has been created, the + * region cannot be changed. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   CreateBucketRequest request =
+   *       CreateBucketRequest.newBuilder()
+   *           .setParent(
+   *               LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
+   *                   .toString())
+   *           .setBucketId("bucketId-1603305307")
+   *           .setBucket(LogBucket.newBuilder().build())
+   *           .build();
+   *   LogBucket response = configClient.createBucket(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final LogBucket createBucket(CreateBucketRequest request) { + return createBucketCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a bucket that can be used to store log entries. Once a bucket has been created, the + * region cannot be changed. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   CreateBucketRequest request =
+   *       CreateBucketRequest.newBuilder()
+   *           .setParent(
+   *               LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
+   *                   .toString())
+   *           .setBucketId("bucketId-1603305307")
+   *           .setBucket(LogBucket.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = configClient.createBucketCallable().futureCall(request);
+   *   // Do something.
+   *   LogBucket response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable createBucketCallable() { + return stub.createBucketCallable(); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Updates a bucket. This method replaces the following fields in the existing bucket with values @@ -488,7 +553,7 @@ public final UnaryCallable getBucketCallable() { *

If the bucket has a LifecycleState of DELETE_REQUESTED, FAILED_PRECONDITION will be * returned. * - *

A buckets region may not be modified after it is created. This method is in Beta. + *

A buckets region may not be modified after it is created. * *

Sample code: * @@ -524,7 +589,7 @@ public final LogBucket updateBucket(UpdateBucketRequest request) { *

If the bucket has a LifecycleState of DELETE_REQUESTED, FAILED_PRECONDITION will be * returned. * - *

A buckets region may not be modified after it is created. This method is in Beta. + *

A buckets region may not be modified after it is created. * *

Sample code: * @@ -548,6 +613,414 @@ public final UnaryCallable updateBucketCallable( return stub.updateBucketCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a bucket. Moves the bucket to the DELETE_REQUESTED state. After 7 days, the bucket will + * be purged and all logs in the bucket will be permanently deleted. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   DeleteBucketRequest request =
+   *       DeleteBucketRequest.newBuilder()
+   *           .setName(
+   *               LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
+   *                   .toString())
+   *           .build();
+   *   configClient.deleteBucket(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBucket(DeleteBucketRequest request) { + deleteBucketCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a bucket. Moves the bucket to the DELETE_REQUESTED state. After 7 days, the bucket will + * be purged and all logs in the bucket will be permanently deleted. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   DeleteBucketRequest request =
+   *       DeleteBucketRequest.newBuilder()
+   *           .setName(
+   *               LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
+   *                   .toString())
+   *           .build();
+   *   ApiFuture future = configClient.deleteBucketCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteBucketCallable() { + return stub.deleteBucketCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Undeletes a bucket. A bucket that has been deleted may be undeleted within the grace period of + * 7 days. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   UndeleteBucketRequest request =
+   *       UndeleteBucketRequest.newBuilder()
+   *           .setName(
+   *               LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
+   *                   .toString())
+   *           .build();
+   *   configClient.undeleteBucket(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void undeleteBucket(UndeleteBucketRequest request) { + undeleteBucketCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Undeletes a bucket. A bucket that has been deleted may be undeleted within the grace period of + * 7 days. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   UndeleteBucketRequest request =
+   *       UndeleteBucketRequest.newBuilder()
+   *           .setName(
+   *               LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
+   *                   .toString())
+   *           .build();
+   *   ApiFuture future = configClient.undeleteBucketCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable undeleteBucketCallable() { + return stub.undeleteBucketCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists views on a bucket. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String parent = "parent-995424086";
+   *   for (LogView element : configClient.listViews(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @param parent Required. The bucket whose views are to be listed: + *

"projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]" + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListViewsPagedResponse listViews(String parent) { + ListViewsRequest request = ListViewsRequest.newBuilder().setParent(parent).build(); + return listViews(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists views on a bucket. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ListViewsRequest request =
+   *       ListViewsRequest.newBuilder()
+   *           .setParent("parent-995424086")
+   *           .setPageToken("pageToken873572522")
+   *           .setPageSize(883849137)
+   *           .build();
+   *   for (LogView element : configClient.listViews(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListViewsPagedResponse listViews(ListViewsRequest request) { + return listViewsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists views on a bucket. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ListViewsRequest request =
+   *       ListViewsRequest.newBuilder()
+   *           .setParent("parent-995424086")
+   *           .setPageToken("pageToken873572522")
+   *           .setPageSize(883849137)
+   *           .build();
+   *   ApiFuture future = configClient.listViewsPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (LogView element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listViewsPagedCallable() { + return stub.listViewsPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists views on a bucket. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   while (true) {
+   *     ListViewsResponse response = configClient.listViewsCallable().call(request);
+   *     for (LogView element : response.getResponsesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listViewsCallable() { + return stub.listViewsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets a view. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   GetViewRequest request =
+   *       GetViewRequest.newBuilder()
+   *           .setName(
+   *               LogViewName.ofProjectLocationBucketViewName(
+   *                       "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]")
+   *                   .toString())
+   *           .build();
+   *   LogView response = configClient.getView(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final LogView getView(GetViewRequest request) { + return getViewCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets a view. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   GetViewRequest request =
+   *       GetViewRequest.newBuilder()
+   *           .setName(
+   *               LogViewName.ofProjectLocationBucketViewName(
+   *                       "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]")
+   *                   .toString())
+   *           .build();
+   *   ApiFuture future = configClient.getViewCallable().futureCall(request);
+   *   // Do something.
+   *   LogView response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getViewCallable() { + return stub.getViewCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a view over logs in a bucket. A bucket may contain a maximum of 50 views. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   CreateViewRequest request =
+   *       CreateViewRequest.newBuilder()
+   *           .setParent("parent-995424086")
+   *           .setViewId("viewId-816632160")
+   *           .setView(LogView.newBuilder().build())
+   *           .build();
+   *   LogView response = configClient.createView(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final LogView createView(CreateViewRequest request) { + return createViewCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a view over logs in a bucket. A bucket may contain a maximum of 50 views. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   CreateViewRequest request =
+   *       CreateViewRequest.newBuilder()
+   *           .setParent("parent-995424086")
+   *           .setViewId("viewId-816632160")
+   *           .setView(LogView.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = configClient.createViewCallable().futureCall(request);
+   *   // Do something.
+   *   LogView response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable createViewCallable() { + return stub.createViewCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a view. This method replaces the following fields in the existing view with values from + * the new view: `filter`. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   UpdateViewRequest request =
+   *       UpdateViewRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setView(LogView.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   LogView response = configClient.updateView(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final LogView updateView(UpdateViewRequest request) { + return updateViewCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a view. This method replaces the following fields in the existing view with values from + * the new view: `filter`. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   UpdateViewRequest request =
+   *       UpdateViewRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setView(LogView.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = configClient.updateViewCallable().futureCall(request);
+   *   // Do something.
+   *   LogView response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable updateViewCallable() { + return stub.updateViewCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a view from a bucket. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   DeleteViewRequest request =
+   *       DeleteViewRequest.newBuilder()
+   *           .setName(
+   *               LogViewName.ofProjectLocationBucketViewName(
+   *                       "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]")
+   *                   .toString())
+   *           .build();
+   *   configClient.deleteView(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteView(DeleteViewRequest request) { + deleteViewCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a view from a bucket. + * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   DeleteViewRequest request =
+   *       DeleteViewRequest.newBuilder()
+   *           .setName(
+   *               LogViewName.ofProjectLocationBucketViewName(
+   *                       "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]")
+   *                   .toString())
+   *           .build();
+   *   ApiFuture future = configClient.deleteViewCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteViewCallable() { + return stub.deleteViewCallable(); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists sinks. @@ -2421,6 +2894,86 @@ protected ListBucketsFixedSizeCollection createCollection( } } + public static class ListViewsPagedResponse + extends AbstractPagedListResponse< + ListViewsRequest, + ListViewsResponse, + LogView, + ListViewsPage, + ListViewsFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListViewsPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListViewsPagedResponse apply(ListViewsPage input) { + return new ListViewsPagedResponse(input); + } + }, + MoreExecutors.directExecutor()); + } + + private ListViewsPagedResponse(ListViewsPage page) { + super(page, ListViewsFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListViewsPage + extends AbstractPage { + + private ListViewsPage( + PageContext context, + ListViewsResponse response) { + super(context, response); + } + + private static ListViewsPage createEmptyPage() { + return new ListViewsPage(null, null); + } + + @Override + protected ListViewsPage createPage( + PageContext context, + ListViewsResponse response) { + return new ListViewsPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListViewsFixedSizeCollection + extends AbstractFixedSizeCollection< + ListViewsRequest, + ListViewsResponse, + LogView, + ListViewsPage, + ListViewsFixedSizeCollection> { + + private ListViewsFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListViewsFixedSizeCollection createEmptyCollection() { + return new ListViewsFixedSizeCollection(null, 0); + } + + @Override + protected ListViewsFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListViewsFixedSizeCollection(pages, collectionSize); + } + } + public static class ListSinksPagedResponse extends AbstractPagedListResponse< ListSinksRequest, diff --git a/test/integration/goldens/logging/ConfigClientTest.java b/test/integration/goldens/logging/ConfigClientTest.java index 3ba857b117..dfe3204d89 100644 --- a/test/integration/goldens/logging/ConfigClientTest.java +++ b/test/integration/goldens/logging/ConfigClientTest.java @@ -19,6 +19,7 @@ import static com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse; +import static com.google.cloud.logging.v2.ConfigClient.ListViewsPagedResponse; import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.GaxGrpcProperties; @@ -32,16 +33,21 @@ import com.google.logging.v2.BillingAccountName; import com.google.logging.v2.CmekSettings; import com.google.logging.v2.CmekSettingsName; +import com.google.logging.v2.CreateBucketRequest; import com.google.logging.v2.CreateExclusionRequest; import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.CreateViewRequest; +import com.google.logging.v2.DeleteBucketRequest; import com.google.logging.v2.DeleteExclusionRequest; import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.DeleteViewRequest; import com.google.logging.v2.FolderLocationName; import com.google.logging.v2.FolderName; import com.google.logging.v2.GetBucketRequest; import com.google.logging.v2.GetCmekSettingsRequest; import com.google.logging.v2.GetExclusionRequest; import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.GetViewRequest; import com.google.logging.v2.LifecycleState; import com.google.logging.v2.ListBucketsRequest; import com.google.logging.v2.ListBucketsResponse; @@ -49,6 +55,8 @@ import com.google.logging.v2.ListExclusionsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.ListViewsRequest; +import com.google.logging.v2.ListViewsResponse; import com.google.logging.v2.LocationName; import com.google.logging.v2.LogBucket; import com.google.logging.v2.LogBucketName; @@ -56,19 +64,24 @@ import com.google.logging.v2.LogExclusionName; import com.google.logging.v2.LogSink; import com.google.logging.v2.LogSinkName; +import com.google.logging.v2.LogView; +import com.google.logging.v2.LogViewName; import com.google.logging.v2.OrganizationLocationName; import com.google.logging.v2.OrganizationName; import com.google.logging.v2.ProjectName; +import com.google.logging.v2.UndeleteBucketRequest; import com.google.logging.v2.UpdateBucketRequest; import com.google.logging.v2.UpdateCmekSettingsRequest; import com.google.logging.v2.UpdateExclusionRequest; import com.google.logging.v2.UpdateSinkRequest; +import com.google.logging.v2.UpdateViewRequest; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import com.google.protobuf.Timestamp; import io.grpc.StatusRuntimeException; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -351,6 +364,7 @@ public void getBucketTest() throws Exception { .setCreateTime(Timestamp.newBuilder().build()) .setUpdateTime(Timestamp.newBuilder().build()) .setRetentionDays(1544391896) + .setLocked(true) .setLifecycleState(LifecycleState.forNumber(0)) .build(); mockConfigServiceV2.addResponse(expectedResponse); @@ -395,6 +409,68 @@ public void getBucketExceptionTest() throws Exception { } } + @Test + public void createBucketTest() throws Exception { + LogBucket expectedResponse = + LogBucket.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetentionDays(1544391896) + .setLocked(true) + .setLifecycleState(LifecycleState.forNumber(0)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + CreateBucketRequest request = + CreateBucketRequest.newBuilder() + .setParent( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .setBucketId("bucketId-1603305307") + .setBucket(LogBucket.newBuilder().build()) + .build(); + + LogBucket actualResponse = client.createBucket(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBucketRequest actualRequest = ((CreateBucketRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getParent(), actualRequest.getParent()); + Assert.assertEquals(request.getBucketId(), actualRequest.getBucketId()); + Assert.assertEquals(request.getBucket(), actualRequest.getBucket()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBucketExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + CreateBucketRequest request = + CreateBucketRequest.newBuilder() + .setParent( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .setBucketId("bucketId-1603305307") + .setBucket(LogBucket.newBuilder().build()) + .build(); + client.createBucket(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + @Test public void updateBucketTest() throws Exception { LogBucket expectedResponse = @@ -406,6 +482,7 @@ public void updateBucketTest() throws Exception { .setCreateTime(Timestamp.newBuilder().build()) .setUpdateTime(Timestamp.newBuilder().build()) .setRetentionDays(1544391896) + .setLocked(true) .setLifecycleState(LifecycleState.forNumber(0)) .build(); mockConfigServiceV2.addResponse(expectedResponse); @@ -456,6 +533,355 @@ public void updateBucketExceptionTest() throws Exception { } } + @Test + public void deleteBucketTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockConfigServiceV2.addResponse(expectedResponse); + + DeleteBucketRequest request = + DeleteBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .build(); + + client.deleteBucket(request); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBucketRequest actualRequest = ((DeleteBucketRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBucketExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + DeleteBucketRequest request = + DeleteBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .build(); + client.deleteBucket(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void undeleteBucketTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockConfigServiceV2.addResponse(expectedResponse); + + UndeleteBucketRequest request = + UndeleteBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .build(); + + client.undeleteBucket(request); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UndeleteBucketRequest actualRequest = ((UndeleteBucketRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void undeleteBucketExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + UndeleteBucketRequest request = + UndeleteBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .build(); + client.undeleteBucket(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listViewsTest() throws Exception { + LogView responsesElement = LogView.newBuilder().build(); + ListViewsResponse expectedResponse = + ListViewsResponse.newBuilder() + .setNextPageToken("") + .addAllViews(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListViewsPagedResponse pagedListResponse = client.listViews(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getViewsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListViewsRequest actualRequest = ((ListViewsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listViewsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + client.listViews(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getViewTest() throws Exception { + LogView expectedResponse = + LogView.newBuilder() + .setName( + LogViewName.ofProjectLocationBucketViewName( + "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]") + .toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setFilter("filter-1274492040") + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + GetViewRequest request = + GetViewRequest.newBuilder() + .setName( + LogViewName.ofProjectLocationBucketViewName( + "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]") + .toString()) + .build(); + + LogView actualResponse = client.getView(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetViewRequest actualRequest = ((GetViewRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getViewExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + GetViewRequest request = + GetViewRequest.newBuilder() + .setName( + LogViewName.ofProjectLocationBucketViewName( + "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]") + .toString()) + .build(); + client.getView(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createViewTest() throws Exception { + LogView expectedResponse = + LogView.newBuilder() + .setName( + LogViewName.ofProjectLocationBucketViewName( + "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]") + .toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setFilter("filter-1274492040") + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + CreateViewRequest request = + CreateViewRequest.newBuilder() + .setParent("parent-995424086") + .setViewId("viewId-816632160") + .setView(LogView.newBuilder().build()) + .build(); + + LogView actualResponse = client.createView(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateViewRequest actualRequest = ((CreateViewRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getParent(), actualRequest.getParent()); + Assert.assertEquals(request.getViewId(), actualRequest.getViewId()); + Assert.assertEquals(request.getView(), actualRequest.getView()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createViewExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + CreateViewRequest request = + CreateViewRequest.newBuilder() + .setParent("parent-995424086") + .setViewId("viewId-816632160") + .setView(LogView.newBuilder().build()) + .build(); + client.createView(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateViewTest() throws Exception { + LogView expectedResponse = + LogView.newBuilder() + .setName( + LogViewName.ofProjectLocationBucketViewName( + "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]") + .toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setFilter("filter-1274492040") + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + UpdateViewRequest request = + UpdateViewRequest.newBuilder() + .setName("name3373707") + .setView(LogView.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + LogView actualResponse = client.updateView(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateViewRequest actualRequest = ((UpdateViewRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getView(), actualRequest.getView()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateViewExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + UpdateViewRequest request = + UpdateViewRequest.newBuilder() + .setName("name3373707") + .setView(LogView.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.updateView(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteViewTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockConfigServiceV2.addResponse(expectedResponse); + + DeleteViewRequest request = + DeleteViewRequest.newBuilder() + .setName( + LogViewName.ofProjectLocationBucketViewName( + "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]") + .toString()) + .build(); + + client.deleteView(request); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteViewRequest actualRequest = ((DeleteViewRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteViewExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + DeleteViewRequest request = + DeleteViewRequest.newBuilder() + .setName( + LogViewName.ofProjectLocationBucketViewName( + "[PROJECT]", "[LOCATION]", "[BUCKET]", "[VIEW]") + .toString()) + .build(); + client.deleteView(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + @Test public void listSinksTest() throws Exception { LogSink responsesElement = LogSink.newBuilder().build(); @@ -685,6 +1111,7 @@ public void getSinkTest() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -731,6 +1158,7 @@ public void getSinkTest2() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -777,6 +1205,7 @@ public void createSinkTest() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -826,6 +1255,7 @@ public void createSinkTest2() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -875,6 +1305,7 @@ public void createSinkTest3() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -924,6 +1355,7 @@ public void createSinkTest4() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -973,6 +1405,7 @@ public void createSinkTest5() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -1022,6 +1455,7 @@ public void updateSinkTest() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -1071,6 +1505,7 @@ public void updateSinkTest2() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -1120,6 +1555,7 @@ public void updateSinkTest3() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) @@ -1172,6 +1608,7 @@ public void updateSinkTest4() throws Exception { .setFilter("filter-1274492040") .setDescription("description-1724546052") .setDisabled(true) + .addAllExclusions(new ArrayList()) .setWriterIdentity("writerIdentity925193809") .setIncludeChildren(true) .setCreateTime(Timestamp.newBuilder().build()) diff --git a/test/integration/goldens/logging/ConfigServiceV2Stub.java b/test/integration/goldens/logging/ConfigServiceV2Stub.java index e0e867e11d..bcdcb70987 100644 --- a/test/integration/goldens/logging/ConfigServiceV2Stub.java +++ b/test/integration/goldens/logging/ConfigServiceV2Stub.java @@ -19,31 +19,42 @@ import static com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse; +import static com.google.cloud.logging.v2.ConfigClient.ListViewsPagedResponse; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.rpc.UnaryCallable; import com.google.logging.v2.CmekSettings; +import com.google.logging.v2.CreateBucketRequest; import com.google.logging.v2.CreateExclusionRequest; import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.CreateViewRequest; +import com.google.logging.v2.DeleteBucketRequest; import com.google.logging.v2.DeleteExclusionRequest; import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.DeleteViewRequest; import com.google.logging.v2.GetBucketRequest; import com.google.logging.v2.GetCmekSettingsRequest; import com.google.logging.v2.GetExclusionRequest; import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.GetViewRequest; import com.google.logging.v2.ListBucketsRequest; import com.google.logging.v2.ListBucketsResponse; import com.google.logging.v2.ListExclusionsRequest; import com.google.logging.v2.ListExclusionsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.ListViewsRequest; +import com.google.logging.v2.ListViewsResponse; import com.google.logging.v2.LogBucket; import com.google.logging.v2.LogExclusion; import com.google.logging.v2.LogSink; +import com.google.logging.v2.LogView; +import com.google.logging.v2.UndeleteBucketRequest; import com.google.logging.v2.UpdateBucketRequest; import com.google.logging.v2.UpdateCmekSettingsRequest; import com.google.logging.v2.UpdateExclusionRequest; import com.google.logging.v2.UpdateSinkRequest; +import com.google.logging.v2.UpdateViewRequest; import com.google.protobuf.Empty; import javax.annotation.Generated; @@ -68,10 +79,46 @@ public UnaryCallable getBucketCallable() { throw new UnsupportedOperationException("Not implemented: getBucketCallable()"); } + public UnaryCallable createBucketCallable() { + throw new UnsupportedOperationException("Not implemented: createBucketCallable()"); + } + public UnaryCallable updateBucketCallable() { throw new UnsupportedOperationException("Not implemented: updateBucketCallable()"); } + public UnaryCallable deleteBucketCallable() { + throw new UnsupportedOperationException("Not implemented: deleteBucketCallable()"); + } + + public UnaryCallable undeleteBucketCallable() { + throw new UnsupportedOperationException("Not implemented: undeleteBucketCallable()"); + } + + public UnaryCallable listViewsPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listViewsPagedCallable()"); + } + + public UnaryCallable listViewsCallable() { + throw new UnsupportedOperationException("Not implemented: listViewsCallable()"); + } + + public UnaryCallable getViewCallable() { + throw new UnsupportedOperationException("Not implemented: getViewCallable()"); + } + + public UnaryCallable createViewCallable() { + throw new UnsupportedOperationException("Not implemented: createViewCallable()"); + } + + public UnaryCallable updateViewCallable() { + throw new UnsupportedOperationException("Not implemented: updateViewCallable()"); + } + + public UnaryCallable deleteViewCallable() { + throw new UnsupportedOperationException("Not implemented: deleteViewCallable()"); + } + public UnaryCallable listSinksPagedCallable() { throw new UnsupportedOperationException("Not implemented: listSinksPagedCallable()"); } diff --git a/test/integration/goldens/logging/ConfigServiceV2StubSettings.java b/test/integration/goldens/logging/ConfigServiceV2StubSettings.java index 353b972407..770bba339d 100644 --- a/test/integration/goldens/logging/ConfigServiceV2StubSettings.java +++ b/test/integration/goldens/logging/ConfigServiceV2StubSettings.java @@ -19,6 +19,7 @@ import static com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse; +import static com.google.cloud.logging.v2.ConfigClient.ListViewsPagedResponse; import com.google.api.core.ApiFunction; import com.google.api.core.ApiFuture; @@ -47,27 +48,37 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.logging.v2.CmekSettings; +import com.google.logging.v2.CreateBucketRequest; import com.google.logging.v2.CreateExclusionRequest; import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.CreateViewRequest; +import com.google.logging.v2.DeleteBucketRequest; import com.google.logging.v2.DeleteExclusionRequest; import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.DeleteViewRequest; import com.google.logging.v2.GetBucketRequest; import com.google.logging.v2.GetCmekSettingsRequest; import com.google.logging.v2.GetExclusionRequest; import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.GetViewRequest; import com.google.logging.v2.ListBucketsRequest; import com.google.logging.v2.ListBucketsResponse; import com.google.logging.v2.ListExclusionsRequest; import com.google.logging.v2.ListExclusionsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.ListViewsRequest; +import com.google.logging.v2.ListViewsResponse; import com.google.logging.v2.LogBucket; import com.google.logging.v2.LogExclusion; import com.google.logging.v2.LogSink; +import com.google.logging.v2.LogView; +import com.google.logging.v2.UndeleteBucketRequest; import com.google.logging.v2.UpdateBucketRequest; import com.google.logging.v2.UpdateCmekSettingsRequest; import com.google.logging.v2.UpdateExclusionRequest; import com.google.logging.v2.UpdateSinkRequest; +import com.google.logging.v2.UpdateViewRequest; import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; @@ -120,7 +131,16 @@ public class ConfigServiceV2StubSettings extends StubSettings listBucketsSettings; private final UnaryCallSettings getBucketSettings; + private final UnaryCallSettings createBucketSettings; private final UnaryCallSettings updateBucketSettings; + private final UnaryCallSettings deleteBucketSettings; + private final UnaryCallSettings undeleteBucketSettings; + private final PagedCallSettings + listViewsSettings; + private final UnaryCallSettings getViewSettings; + private final UnaryCallSettings createViewSettings; + private final UnaryCallSettings updateViewSettings; + private final UnaryCallSettings deleteViewSettings; private final PagedCallSettings listSinksSettings; private final UnaryCallSettings getSinkSettings; @@ -174,6 +194,42 @@ public Iterable extractResources(ListBucketsResponse payload) { } }; + private static final PagedListDescriptor + LIST_VIEWS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListViewsRequest injectToken(ListViewsRequest payload, String token) { + return ListViewsRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListViewsRequest injectPageSize(ListViewsRequest payload, int pageSize) { + return ListViewsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListViewsRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListViewsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListViewsResponse payload) { + return payload.getViewsList() == null + ? ImmutableList.of() + : payload.getViewsList(); + } + }; + private static final PagedListDescriptor LIST_SINKS_PAGE_STR_DESC = new PagedListDescriptor() { @@ -265,6 +321,23 @@ public ApiFuture getFuturePagedResponse( } }; + private static final PagedListResponseFactory< + ListViewsRequest, ListViewsResponse, ListViewsPagedResponse> + LIST_VIEWS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListViewsRequest, ListViewsResponse, ListViewsPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListViewsRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_VIEWS_PAGE_STR_DESC, request, context); + return ListViewsPagedResponse.createAsync(pageContext, futureResponse); + } + }; + private static final PagedListResponseFactory< ListSinksRequest, ListSinksResponse, ListSinksPagedResponse> LIST_SINKS_PAGE_STR_FACT = @@ -310,11 +383,52 @@ public UnaryCallSettings getBucketSettings() { return getBucketSettings; } + /** Returns the object with the settings used for calls to createBucket. */ + public UnaryCallSettings createBucketSettings() { + return createBucketSettings; + } + /** Returns the object with the settings used for calls to updateBucket. */ public UnaryCallSettings updateBucketSettings() { return updateBucketSettings; } + /** Returns the object with the settings used for calls to deleteBucket. */ + public UnaryCallSettings deleteBucketSettings() { + return deleteBucketSettings; + } + + /** Returns the object with the settings used for calls to undeleteBucket. */ + public UnaryCallSettings undeleteBucketSettings() { + return undeleteBucketSettings; + } + + /** Returns the object with the settings used for calls to listViews. */ + public PagedCallSettings + listViewsSettings() { + return listViewsSettings; + } + + /** Returns the object with the settings used for calls to getView. */ + public UnaryCallSettings getViewSettings() { + return getViewSettings; + } + + /** Returns the object with the settings used for calls to createView. */ + public UnaryCallSettings createViewSettings() { + return createViewSettings; + } + + /** Returns the object with the settings used for calls to updateView. */ + public UnaryCallSettings updateViewSettings() { + return updateViewSettings; + } + + /** Returns the object with the settings used for calls to deleteView. */ + public UnaryCallSettings deleteViewSettings() { + return deleteViewSettings; + } + /** Returns the object with the settings used for calls to listSinks. */ public PagedCallSettings listSinksSettings() { @@ -449,7 +563,15 @@ protected ConfigServiceV2StubSettings(Builder settingsBuilder) throws IOExceptio listBucketsSettings = settingsBuilder.listBucketsSettings().build(); getBucketSettings = settingsBuilder.getBucketSettings().build(); + createBucketSettings = settingsBuilder.createBucketSettings().build(); updateBucketSettings = settingsBuilder.updateBucketSettings().build(); + deleteBucketSettings = settingsBuilder.deleteBucketSettings().build(); + undeleteBucketSettings = settingsBuilder.undeleteBucketSettings().build(); + listViewsSettings = settingsBuilder.listViewsSettings().build(); + getViewSettings = settingsBuilder.getViewSettings().build(); + createViewSettings = settingsBuilder.createViewSettings().build(); + updateViewSettings = settingsBuilder.updateViewSettings().build(); + deleteViewSettings = settingsBuilder.deleteViewSettings().build(); listSinksSettings = settingsBuilder.listSinksSettings().build(); getSinkSettings = settingsBuilder.getSinkSettings().build(); createSinkSettings = settingsBuilder.createSinkSettings().build(); @@ -471,7 +593,17 @@ public static class Builder extends StubSettings.Builder listBucketsSettings; private final UnaryCallSettings.Builder getBucketSettings; + private final UnaryCallSettings.Builder createBucketSettings; private final UnaryCallSettings.Builder updateBucketSettings; + private final UnaryCallSettings.Builder deleteBucketSettings; + private final UnaryCallSettings.Builder undeleteBucketSettings; + private final PagedCallSettings.Builder< + ListViewsRequest, ListViewsResponse, ListViewsPagedResponse> + listViewsSettings; + private final UnaryCallSettings.Builder getViewSettings; + private final UnaryCallSettings.Builder createViewSettings; + private final UnaryCallSettings.Builder updateViewSettings; + private final UnaryCallSettings.Builder deleteViewSettings; private final PagedCallSettings.Builder< ListSinksRequest, ListSinksResponse, ListSinksPagedResponse> listSinksSettings; @@ -549,7 +681,15 @@ protected Builder(ClientContext clientContext) { listBucketsSettings = PagedCallSettings.newBuilder(LIST_BUCKETS_PAGE_STR_FACT); getBucketSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + createBucketSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); updateBucketSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteBucketSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + undeleteBucketSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listViewsSettings = PagedCallSettings.newBuilder(LIST_VIEWS_PAGE_STR_FACT); + getViewSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + createViewSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + updateViewSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteViewSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); listSinksSettings = PagedCallSettings.newBuilder(LIST_SINKS_PAGE_STR_FACT); getSinkSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); createSinkSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); @@ -567,7 +707,15 @@ protected Builder(ClientContext clientContext) { ImmutableList.>of( listBucketsSettings, getBucketSettings, + createBucketSettings, updateBucketSettings, + deleteBucketSettings, + undeleteBucketSettings, + listViewsSettings, + getViewSettings, + createViewSettings, + updateViewSettings, + deleteViewSettings, listSinksSettings, getSinkSettings, createSinkSettings, @@ -588,7 +736,15 @@ protected Builder(ConfigServiceV2StubSettings settings) { listBucketsSettings = settings.listBucketsSettings.toBuilder(); getBucketSettings = settings.getBucketSettings.toBuilder(); + createBucketSettings = settings.createBucketSettings.toBuilder(); updateBucketSettings = settings.updateBucketSettings.toBuilder(); + deleteBucketSettings = settings.deleteBucketSettings.toBuilder(); + undeleteBucketSettings = settings.undeleteBucketSettings.toBuilder(); + listViewsSettings = settings.listViewsSettings.toBuilder(); + getViewSettings = settings.getViewSettings.toBuilder(); + createViewSettings = settings.createViewSettings.toBuilder(); + updateViewSettings = settings.updateViewSettings.toBuilder(); + deleteViewSettings = settings.deleteViewSettings.toBuilder(); listSinksSettings = settings.listSinksSettings.toBuilder(); getSinkSettings = settings.getSinkSettings.toBuilder(); createSinkSettings = settings.createSinkSettings.toBuilder(); @@ -606,7 +762,15 @@ protected Builder(ConfigServiceV2StubSettings settings) { ImmutableList.>of( listBucketsSettings, getBucketSettings, + createBucketSettings, updateBucketSettings, + deleteBucketSettings, + undeleteBucketSettings, + listViewsSettings, + getViewSettings, + createViewSettings, + updateViewSettings, + deleteViewSettings, listSinksSettings, getSinkSettings, createSinkSettings, @@ -643,11 +807,51 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder + .createBucketSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder .updateBucketSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder + .deleteBucketSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .undeleteBucketSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .listViewsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getViewSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .createViewSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .updateViewSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .deleteViewSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder .listSinksSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_3_codes")) @@ -739,11 +943,52 @@ public UnaryCallSettings.Builder getBucketSettings( return getBucketSettings; } + /** Returns the builder for the settings used for calls to createBucket. */ + public UnaryCallSettings.Builder createBucketSettings() { + return createBucketSettings; + } + /** Returns the builder for the settings used for calls to updateBucket. */ public UnaryCallSettings.Builder updateBucketSettings() { return updateBucketSettings; } + /** Returns the builder for the settings used for calls to deleteBucket. */ + public UnaryCallSettings.Builder deleteBucketSettings() { + return deleteBucketSettings; + } + + /** Returns the builder for the settings used for calls to undeleteBucket. */ + public UnaryCallSettings.Builder undeleteBucketSettings() { + return undeleteBucketSettings; + } + + /** Returns the builder for the settings used for calls to listViews. */ + public PagedCallSettings.Builder + listViewsSettings() { + return listViewsSettings; + } + + /** Returns the builder for the settings used for calls to getView. */ + public UnaryCallSettings.Builder getViewSettings() { + return getViewSettings; + } + + /** Returns the builder for the settings used for calls to createView. */ + public UnaryCallSettings.Builder createViewSettings() { + return createViewSettings; + } + + /** Returns the builder for the settings used for calls to updateView. */ + public UnaryCallSettings.Builder updateViewSettings() { + return updateViewSettings; + } + + /** Returns the builder for the settings used for calls to deleteView. */ + public UnaryCallSettings.Builder deleteViewSettings() { + return deleteViewSettings; + } + /** Returns the builder for the settings used for calls to listSinks. */ public PagedCallSettings.Builder listSinksSettings() { diff --git a/test/integration/goldens/logging/ConfigSettings.java b/test/integration/goldens/logging/ConfigSettings.java index ed2eac3c75..290860c3b1 100644 --- a/test/integration/goldens/logging/ConfigSettings.java +++ b/test/integration/goldens/logging/ConfigSettings.java @@ -19,6 +19,7 @@ import static com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse; +import static com.google.cloud.logging.v2.ConfigClient.ListViewsPagedResponse; import com.google.api.core.ApiFunction; import com.google.api.core.BetaApi; @@ -34,27 +35,37 @@ import com.google.api.gax.rpc.UnaryCallSettings; import com.google.cloud.logging.v2.stub.ConfigServiceV2StubSettings; import com.google.logging.v2.CmekSettings; +import com.google.logging.v2.CreateBucketRequest; import com.google.logging.v2.CreateExclusionRequest; import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.CreateViewRequest; +import com.google.logging.v2.DeleteBucketRequest; import com.google.logging.v2.DeleteExclusionRequest; import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.DeleteViewRequest; import com.google.logging.v2.GetBucketRequest; import com.google.logging.v2.GetCmekSettingsRequest; import com.google.logging.v2.GetExclusionRequest; import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.GetViewRequest; import com.google.logging.v2.ListBucketsRequest; import com.google.logging.v2.ListBucketsResponse; import com.google.logging.v2.ListExclusionsRequest; import com.google.logging.v2.ListExclusionsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.ListViewsRequest; +import com.google.logging.v2.ListViewsResponse; import com.google.logging.v2.LogBucket; import com.google.logging.v2.LogExclusion; import com.google.logging.v2.LogSink; +import com.google.logging.v2.LogView; +import com.google.logging.v2.UndeleteBucketRequest; import com.google.logging.v2.UpdateBucketRequest; import com.google.logging.v2.UpdateCmekSettingsRequest; import com.google.logging.v2.UpdateExclusionRequest; import com.google.logging.v2.UpdateSinkRequest; +import com.google.logging.v2.UpdateViewRequest; import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; @@ -105,11 +116,52 @@ public UnaryCallSettings getBucketSettings() { return ((ConfigServiceV2StubSettings) getStubSettings()).getBucketSettings(); } + /** Returns the object with the settings used for calls to createBucket. */ + public UnaryCallSettings createBucketSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).createBucketSettings(); + } + /** Returns the object with the settings used for calls to updateBucket. */ public UnaryCallSettings updateBucketSettings() { return ((ConfigServiceV2StubSettings) getStubSettings()).updateBucketSettings(); } + /** Returns the object with the settings used for calls to deleteBucket. */ + public UnaryCallSettings deleteBucketSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).deleteBucketSettings(); + } + + /** Returns the object with the settings used for calls to undeleteBucket. */ + public UnaryCallSettings undeleteBucketSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).undeleteBucketSettings(); + } + + /** Returns the object with the settings used for calls to listViews. */ + public PagedCallSettings + listViewsSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).listViewsSettings(); + } + + /** Returns the object with the settings used for calls to getView. */ + public UnaryCallSettings getViewSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).getViewSettings(); + } + + /** Returns the object with the settings used for calls to createView. */ + public UnaryCallSettings createViewSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).createViewSettings(); + } + + /** Returns the object with the settings used for calls to updateView. */ + public UnaryCallSettings updateViewSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).updateViewSettings(); + } + + /** Returns the object with the settings used for calls to deleteView. */ + public UnaryCallSettings deleteViewSettings() { + return ((ConfigServiceV2StubSettings) getStubSettings()).deleteViewSettings(); + } + /** Returns the object with the settings used for calls to listSinks. */ public PagedCallSettings listSinksSettings() { @@ -282,11 +334,52 @@ public UnaryCallSettings.Builder getBucketSettings( return getStubSettingsBuilder().getBucketSettings(); } + /** Returns the builder for the settings used for calls to createBucket. */ + public UnaryCallSettings.Builder createBucketSettings() { + return getStubSettingsBuilder().createBucketSettings(); + } + /** Returns the builder for the settings used for calls to updateBucket. */ public UnaryCallSettings.Builder updateBucketSettings() { return getStubSettingsBuilder().updateBucketSettings(); } + /** Returns the builder for the settings used for calls to deleteBucket. */ + public UnaryCallSettings.Builder deleteBucketSettings() { + return getStubSettingsBuilder().deleteBucketSettings(); + } + + /** Returns the builder for the settings used for calls to undeleteBucket. */ + public UnaryCallSettings.Builder undeleteBucketSettings() { + return getStubSettingsBuilder().undeleteBucketSettings(); + } + + /** Returns the builder for the settings used for calls to listViews. */ + public PagedCallSettings.Builder + listViewsSettings() { + return getStubSettingsBuilder().listViewsSettings(); + } + + /** Returns the builder for the settings used for calls to getView. */ + public UnaryCallSettings.Builder getViewSettings() { + return getStubSettingsBuilder().getViewSettings(); + } + + /** Returns the builder for the settings used for calls to createView. */ + public UnaryCallSettings.Builder createViewSettings() { + return getStubSettingsBuilder().createViewSettings(); + } + + /** Returns the builder for the settings used for calls to updateView. */ + public UnaryCallSettings.Builder updateViewSettings() { + return getStubSettingsBuilder().updateViewSettings(); + } + + /** Returns the builder for the settings used for calls to deleteView. */ + public UnaryCallSettings.Builder deleteViewSettings() { + return getStubSettingsBuilder().deleteViewSettings(); + } + /** Returns the builder for the settings used for calls to listSinks. */ public PagedCallSettings.Builder listSinksSettings() { diff --git a/test/integration/goldens/logging/GrpcConfigServiceV2Stub.java b/test/integration/goldens/logging/GrpcConfigServiceV2Stub.java index 1516b53b47..f11f4885f6 100644 --- a/test/integration/goldens/logging/GrpcConfigServiceV2Stub.java +++ b/test/integration/goldens/logging/GrpcConfigServiceV2Stub.java @@ -19,6 +19,7 @@ import static com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListExclusionsPagedResponse; import static com.google.cloud.logging.v2.ConfigClient.ListSinksPagedResponse; +import static com.google.cloud.logging.v2.ConfigClient.ListViewsPagedResponse; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; @@ -29,27 +30,37 @@ import com.google.api.gax.rpc.UnaryCallable; import com.google.common.collect.ImmutableMap; import com.google.logging.v2.CmekSettings; +import com.google.logging.v2.CreateBucketRequest; import com.google.logging.v2.CreateExclusionRequest; import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.CreateViewRequest; +import com.google.logging.v2.DeleteBucketRequest; import com.google.logging.v2.DeleteExclusionRequest; import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.DeleteViewRequest; import com.google.logging.v2.GetBucketRequest; import com.google.logging.v2.GetCmekSettingsRequest; import com.google.logging.v2.GetExclusionRequest; import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.GetViewRequest; import com.google.logging.v2.ListBucketsRequest; import com.google.logging.v2.ListBucketsResponse; import com.google.logging.v2.ListExclusionsRequest; import com.google.logging.v2.ListExclusionsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.ListViewsRequest; +import com.google.logging.v2.ListViewsResponse; import com.google.logging.v2.LogBucket; import com.google.logging.v2.LogExclusion; import com.google.logging.v2.LogSink; +import com.google.logging.v2.LogView; +import com.google.logging.v2.UndeleteBucketRequest; import com.google.logging.v2.UpdateBucketRequest; import com.google.logging.v2.UpdateCmekSettingsRequest; import com.google.logging.v2.UpdateExclusionRequest; import com.google.logging.v2.UpdateSinkRequest; +import com.google.logging.v2.UpdateViewRequest; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; @@ -85,6 +96,15 @@ public class GrpcConfigServiceV2Stub extends ConfigServiceV2Stub { .setResponseMarshaller(ProtoUtils.marshaller(LogBucket.getDefaultInstance())) .build(); + private static final MethodDescriptor + createBucketMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/CreateBucket") + .setRequestMarshaller(ProtoUtils.marshaller(CreateBucketRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(LogBucket.getDefaultInstance())) + .build(); + private static final MethodDescriptor updateBucketMethodDescriptor = MethodDescriptor.newBuilder() @@ -94,6 +114,65 @@ public class GrpcConfigServiceV2Stub extends ConfigServiceV2Stub { .setResponseMarshaller(ProtoUtils.marshaller(LogBucket.getDefaultInstance())) .build(); + private static final MethodDescriptor deleteBucketMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/DeleteBucket") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteBucketRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + undeleteBucketMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/UndeleteBucket") + .setRequestMarshaller( + ProtoUtils.marshaller(UndeleteBucketRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listViewsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/ListViews") + .setRequestMarshaller(ProtoUtils.marshaller(ListViewsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListViewsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getViewMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/GetView") + .setRequestMarshaller(ProtoUtils.marshaller(GetViewRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(LogView.getDefaultInstance())) + .build(); + + private static final MethodDescriptor createViewMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/CreateView") + .setRequestMarshaller(ProtoUtils.marshaller(CreateViewRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(LogView.getDefaultInstance())) + .build(); + + private static final MethodDescriptor updateViewMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/UpdateView") + .setRequestMarshaller(ProtoUtils.marshaller(UpdateViewRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(LogView.getDefaultInstance())) + .build(); + + private static final MethodDescriptor deleteViewMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.logging.v2.ConfigServiceV2/DeleteView") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteViewRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor listSinksMethodDescriptor = MethodDescriptor.newBuilder() @@ -209,7 +288,16 @@ public class GrpcConfigServiceV2Stub extends ConfigServiceV2Stub { private final UnaryCallable listBucketsPagedCallable; private final UnaryCallable getBucketCallable; + private final UnaryCallable createBucketCallable; private final UnaryCallable updateBucketCallable; + private final UnaryCallable deleteBucketCallable; + private final UnaryCallable undeleteBucketCallable; + private final UnaryCallable listViewsCallable; + private final UnaryCallable listViewsPagedCallable; + private final UnaryCallable getViewCallable; + private final UnaryCallable createViewCallable; + private final UnaryCallable updateViewCallable; + private final UnaryCallable deleteViewCallable; private final UnaryCallable listSinksCallable; private final UnaryCallable listSinksPagedCallable; private final UnaryCallable getSinkCallable; @@ -296,6 +384,19 @@ public Map extract(GetBucketRequest request) { } }) .build(); + GrpcCallSettings createBucketTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createBucketMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateBucketRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) + .build(); GrpcCallSettings updateBucketTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(updateBucketMethodDescriptor) @@ -309,6 +410,97 @@ public Map extract(UpdateBucketRequest request) { } }) .build(); + GrpcCallSettings deleteBucketTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteBucketMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteBucketRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) + .build(); + GrpcCallSettings undeleteBucketTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(undeleteBucketMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(UndeleteBucketRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) + .build(); + GrpcCallSettings listViewsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listViewsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListViewsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) + .build(); + GrpcCallSettings getViewTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getViewMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetViewRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) + .build(); + GrpcCallSettings createViewTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createViewMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateViewRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) + .build(); + GrpcCallSettings updateViewTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateViewMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(UpdateViewRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) + .build(); + GrpcCallSettings deleteViewTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteViewMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteViewRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) + .build(); GrpcCallSettings listSinksTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listSinksMethodDescriptor) @@ -476,9 +668,36 @@ public Map extract(UpdateCmekSettingsRequest request) { this.getBucketCallable = callableFactory.createUnaryCallable( getBucketTransportSettings, settings.getBucketSettings(), clientContext); + this.createBucketCallable = + callableFactory.createUnaryCallable( + createBucketTransportSettings, settings.createBucketSettings(), clientContext); this.updateBucketCallable = callableFactory.createUnaryCallable( updateBucketTransportSettings, settings.updateBucketSettings(), clientContext); + this.deleteBucketCallable = + callableFactory.createUnaryCallable( + deleteBucketTransportSettings, settings.deleteBucketSettings(), clientContext); + this.undeleteBucketCallable = + callableFactory.createUnaryCallable( + undeleteBucketTransportSettings, settings.undeleteBucketSettings(), clientContext); + this.listViewsCallable = + callableFactory.createUnaryCallable( + listViewsTransportSettings, settings.listViewsSettings(), clientContext); + this.listViewsPagedCallable = + callableFactory.createPagedCallable( + listViewsTransportSettings, settings.listViewsSettings(), clientContext); + this.getViewCallable = + callableFactory.createUnaryCallable( + getViewTransportSettings, settings.getViewSettings(), clientContext); + this.createViewCallable = + callableFactory.createUnaryCallable( + createViewTransportSettings, settings.createViewSettings(), clientContext); + this.updateViewCallable = + callableFactory.createUnaryCallable( + updateViewTransportSettings, settings.updateViewSettings(), clientContext); + this.deleteViewCallable = + callableFactory.createUnaryCallable( + deleteViewTransportSettings, settings.deleteViewSettings(), clientContext); this.listSinksCallable = callableFactory.createUnaryCallable( listSinksTransportSettings, settings.listSinksSettings(), clientContext); @@ -547,11 +766,56 @@ public UnaryCallable getBucketCallable() { return getBucketCallable; } + @Override + public UnaryCallable createBucketCallable() { + return createBucketCallable; + } + @Override public UnaryCallable updateBucketCallable() { return updateBucketCallable; } + @Override + public UnaryCallable deleteBucketCallable() { + return deleteBucketCallable; + } + + @Override + public UnaryCallable undeleteBucketCallable() { + return undeleteBucketCallable; + } + + @Override + public UnaryCallable listViewsCallable() { + return listViewsCallable; + } + + @Override + public UnaryCallable listViewsPagedCallable() { + return listViewsPagedCallable; + } + + @Override + public UnaryCallable getViewCallable() { + return getViewCallable; + } + + @Override + public UnaryCallable createViewCallable() { + return createViewCallable; + } + + @Override + public UnaryCallable updateViewCallable() { + return updateViewCallable; + } + + @Override + public UnaryCallable deleteViewCallable() { + return deleteViewCallable; + } + @Override public UnaryCallable listSinksCallable() { return listSinksCallable; diff --git a/test/integration/goldens/logging/GrpcLoggingServiceV2Stub.java b/test/integration/goldens/logging/GrpcLoggingServiceV2Stub.java index 671ea68695..0beb2c9208 100644 --- a/test/integration/goldens/logging/GrpcLoggingServiceV2Stub.java +++ b/test/integration/goldens/logging/GrpcLoggingServiceV2Stub.java @@ -24,6 +24,7 @@ import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.UnaryCallable; @@ -35,6 +36,8 @@ import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.longrunning.stub.GrpcOperationsStub; @@ -110,6 +113,17 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub { .setResponseMarshaller(ProtoUtils.marshaller(ListLogsResponse.getDefaultInstance())) .build(); + private static final MethodDescriptor + tailLogEntriesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.BIDI_STREAMING) + .setFullMethodName("google.logging.v2.LoggingServiceV2/TailLogEntries") + .setRequestMarshaller( + ProtoUtils.marshaller(TailLogEntriesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(TailLogEntriesResponse.getDefaultInstance())) + .build(); + private final UnaryCallable deleteLogCallable; private final UnaryCallable writeLogEntriesCallable; @@ -124,6 +138,8 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub { listMonitoredResourceDescriptorsPagedCallable; private final UnaryCallable listLogsCallable; private final UnaryCallable listLogsPagedCallable; + private final BidiStreamingCallable + tailLogEntriesCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -213,6 +229,11 @@ public Map extract(ListLogsRequest request) { } }) .build(); + GrpcCallSettings + tailLogEntriesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(tailLogEntriesMethodDescriptor) + .build(); this.deleteLogCallable = callableFactory.createUnaryCallable( @@ -242,6 +263,9 @@ public Map extract(ListLogsRequest request) { this.listLogsPagedCallable = callableFactory.createPagedCallable( listLogsTransportSettings, settings.listLogsSettings(), clientContext); + this.tailLogEntriesCallable = + callableFactory.createBidiStreamingCallable( + tailLogEntriesTransportSettings, settings.tailLogEntriesSettings(), clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -296,6 +320,12 @@ public UnaryCallable listLogsPagedCallab return listLogsPagedCallable; } + @Override + public BidiStreamingCallable + tailLogEntriesCallable() { + return tailLogEntriesCallable; + } + @Override public final void close() { shutdown(); diff --git a/test/integration/goldens/logging/LogViewName.java b/test/integration/goldens/logging/LogViewName.java new file mode 100644 index 0000000000..a38321aabe --- /dev/null +++ b/test/integration/goldens/logging/LogViewName.java @@ -0,0 +1,643 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.logging.v2; + +import com.google.api.core.BetaApi; +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.pathtemplate.ValidationException; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class LogViewName implements ResourceName { + private static final PathTemplate PROJECT_LOCATION_BUCKET_VIEW = + PathTemplate.createWithoutUrlEncoding( + "projects/{project}/locations/{location}/buckets/{bucket}/views/{view}"); + private static final PathTemplate ORGANIZATION_LOCATION_BUCKET_VIEW = + PathTemplate.createWithoutUrlEncoding( + "organizations/{organization}/locations/{location}/buckets/{bucket}/views/{view}"); + private static final PathTemplate FOLDER_LOCATION_BUCKET_VIEW = + PathTemplate.createWithoutUrlEncoding( + "folders/{folder}/locations/{location}/buckets/{bucket}/views/{view}"); + private static final PathTemplate BILLING_ACCOUNT_LOCATION_BUCKET_VIEW = + PathTemplate.createWithoutUrlEncoding( + "billingAccounts/{billing_account}/locations/{location}/buckets/{bucket}/views/{view}"); + private volatile Map fieldValuesMap; + private PathTemplate pathTemplate; + private String fixedValue; + private final String project; + private final String location; + private final String bucket; + private final String view; + private final String organization; + private final String folder; + private final String billingAccount; + + @Deprecated + protected LogViewName() { + project = null; + location = null; + bucket = null; + view = null; + organization = null; + folder = null; + billingAccount = null; + } + + private LogViewName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + location = Preconditions.checkNotNull(builder.getLocation()); + bucket = Preconditions.checkNotNull(builder.getBucket()); + view = Preconditions.checkNotNull(builder.getView()); + organization = null; + folder = null; + billingAccount = null; + pathTemplate = PROJECT_LOCATION_BUCKET_VIEW; + } + + private LogViewName(OrganizationLocationBucketViewBuilder builder) { + organization = Preconditions.checkNotNull(builder.getOrganization()); + location = Preconditions.checkNotNull(builder.getLocation()); + bucket = Preconditions.checkNotNull(builder.getBucket()); + view = Preconditions.checkNotNull(builder.getView()); + project = null; + folder = null; + billingAccount = null; + pathTemplate = ORGANIZATION_LOCATION_BUCKET_VIEW; + } + + private LogViewName(FolderLocationBucketViewBuilder builder) { + folder = Preconditions.checkNotNull(builder.getFolder()); + location = Preconditions.checkNotNull(builder.getLocation()); + bucket = Preconditions.checkNotNull(builder.getBucket()); + view = Preconditions.checkNotNull(builder.getView()); + project = null; + organization = null; + billingAccount = null; + pathTemplate = FOLDER_LOCATION_BUCKET_VIEW; + } + + private LogViewName(BillingAccountLocationBucketViewBuilder builder) { + billingAccount = Preconditions.checkNotNull(builder.getBillingAccount()); + location = Preconditions.checkNotNull(builder.getLocation()); + bucket = Preconditions.checkNotNull(builder.getBucket()); + view = Preconditions.checkNotNull(builder.getView()); + project = null; + organization = null; + folder = null; + pathTemplate = BILLING_ACCOUNT_LOCATION_BUCKET_VIEW; + } + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public String getBucket() { + return bucket; + } + + public String getView() { + return view; + } + + public String getOrganization() { + return organization; + } + + public String getFolder() { + return folder; + } + + public String getBillingAccount() { + return billingAccount; + } + + public static Builder newBuilder() { + return new Builder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static Builder newProjectLocationBucketViewBuilder() { + return new Builder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static OrganizationLocationBucketViewBuilder newOrganizationLocationBucketViewBuilder() { + return new OrganizationLocationBucketViewBuilder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static FolderLocationBucketViewBuilder newFolderLocationBucketViewBuilder() { + return new FolderLocationBucketViewBuilder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static BillingAccountLocationBucketViewBuilder + newBillingAccountLocationBucketViewBuilder() { + return new BillingAccountLocationBucketViewBuilder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static LogViewName of(String project, String location, String bucket, String view) { + return newBuilder() + .setProject(project) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static LogViewName ofProjectLocationBucketViewName( + String project, String location, String bucket, String view) { + return newBuilder() + .setProject(project) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static LogViewName ofOrganizationLocationBucketViewName( + String organization, String location, String bucket, String view) { + return newOrganizationLocationBucketViewBuilder() + .setOrganization(organization) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static LogViewName ofFolderLocationBucketViewName( + String folder, String location, String bucket, String view) { + return newFolderLocationBucketViewBuilder() + .setFolder(folder) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static LogViewName ofBillingAccountLocationBucketViewName( + String billingAccount, String location, String bucket, String view) { + return newBillingAccountLocationBucketViewBuilder() + .setBillingAccount(billingAccount) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build(); + } + + public static String format(String project, String location, String bucket, String view) { + return newBuilder() + .setProject(project) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build() + .toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatProjectLocationBucketViewName( + String project, String location, String bucket, String view) { + return newBuilder() + .setProject(project) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build() + .toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatOrganizationLocationBucketViewName( + String organization, String location, String bucket, String view) { + return newOrganizationLocationBucketViewBuilder() + .setOrganization(organization) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build() + .toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatFolderLocationBucketViewName( + String folder, String location, String bucket, String view) { + return newFolderLocationBucketViewBuilder() + .setFolder(folder) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build() + .toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatBillingAccountLocationBucketViewName( + String billingAccount, String location, String bucket, String view) { + return newBillingAccountLocationBucketViewBuilder() + .setBillingAccount(billingAccount) + .setLocation(location) + .setBucket(bucket) + .setView(view) + .build() + .toString(); + } + + public static LogViewName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + if (PROJECT_LOCATION_BUCKET_VIEW.matches(formattedString)) { + Map matchMap = PROJECT_LOCATION_BUCKET_VIEW.match(formattedString); + return ofProjectLocationBucketViewName( + matchMap.get("project"), + matchMap.get("location"), + matchMap.get("bucket"), + matchMap.get("view")); + } else if (ORGANIZATION_LOCATION_BUCKET_VIEW.matches(formattedString)) { + Map matchMap = ORGANIZATION_LOCATION_BUCKET_VIEW.match(formattedString); + return ofOrganizationLocationBucketViewName( + matchMap.get("organization"), + matchMap.get("location"), + matchMap.get("bucket"), + matchMap.get("view")); + } else if (FOLDER_LOCATION_BUCKET_VIEW.matches(formattedString)) { + Map matchMap = FOLDER_LOCATION_BUCKET_VIEW.match(formattedString); + return ofFolderLocationBucketViewName( + matchMap.get("folder"), + matchMap.get("location"), + matchMap.get("bucket"), + matchMap.get("view")); + } else if (BILLING_ACCOUNT_LOCATION_BUCKET_VIEW.matches(formattedString)) { + Map matchMap = BILLING_ACCOUNT_LOCATION_BUCKET_VIEW.match(formattedString); + return ofBillingAccountLocationBucketViewName( + matchMap.get("billing_account"), + matchMap.get("location"), + matchMap.get("bucket"), + matchMap.get("view")); + } + throw new ValidationException("LogViewName.parse: formattedString not in valid format"); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (LogViewName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PROJECT_LOCATION_BUCKET_VIEW.matches(formattedString) + || ORGANIZATION_LOCATION_BUCKET_VIEW.matches(formattedString) + || FOLDER_LOCATION_BUCKET_VIEW.matches(formattedString) + || BILLING_ACCOUNT_LOCATION_BUCKET_VIEW.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (project != null) { + fieldMapBuilder.put("project", project); + } + if (location != null) { + fieldMapBuilder.put("location", location); + } + if (bucket != null) { + fieldMapBuilder.put("bucket", bucket); + } + if (view != null) { + fieldMapBuilder.put("view", view); + } + if (organization != null) { + fieldMapBuilder.put("organization", organization); + } + if (folder != null) { + fieldMapBuilder.put("folder", folder); + } + if (billingAccount != null) { + fieldMapBuilder.put("billing_account", billingAccount); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + LogViewName that = ((LogViewName) o); + return Objects.equals(this.project, that.project) + && Objects.equals(this.location, that.location) + && Objects.equals(this.bucket, that.bucket) + && Objects.equals(this.view, that.view) + && Objects.equals(this.organization, that.organization) + && Objects.equals(this.folder, that.folder) + && Objects.equals(this.billingAccount, that.billingAccount); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(fixedValue); + h *= 1000003; + h ^= Objects.hashCode(project); + h *= 1000003; + h ^= Objects.hashCode(location); + h *= 1000003; + h ^= Objects.hashCode(bucket); + h *= 1000003; + h ^= Objects.hashCode(view); + h *= 1000003; + h ^= Objects.hashCode(organization); + h *= 1000003; + h ^= Objects.hashCode(folder); + h *= 1000003; + h ^= Objects.hashCode(billingAccount); + return h; + } + + /** Builder for projects/{project}/locations/{location}/buckets/{bucket}/views/{view}. */ + public static class Builder { + private String project; + private String location; + private String bucket; + private String view; + + protected Builder() {} + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public String getBucket() { + return bucket; + } + + public String getView() { + return view; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + public Builder setLocation(String location) { + this.location = location; + return this; + } + + public Builder setBucket(String bucket) { + this.bucket = bucket; + return this; + } + + public Builder setView(String view) { + this.view = view; + return this; + } + + private Builder(LogViewName logViewName) { + Preconditions.checkArgument( + Objects.equals(logViewName.pathTemplate, PROJECT_LOCATION_BUCKET_VIEW), + "toBuilder is only supported when LogViewName has the pattern of projects/{project}/locations/{location}/buckets/{bucket}/views/{view}"); + project = logViewName.project; + location = logViewName.location; + bucket = logViewName.bucket; + view = logViewName.view; + } + + public LogViewName build() { + return new LogViewName(this); + } + } + + /** + * Builder for organizations/{organization}/locations/{location}/buckets/{bucket}/views/{view}. + */ + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static class OrganizationLocationBucketViewBuilder { + private String organization; + private String location; + private String bucket; + private String view; + + protected OrganizationLocationBucketViewBuilder() {} + + public String getOrganization() { + return organization; + } + + public String getLocation() { + return location; + } + + public String getBucket() { + return bucket; + } + + public String getView() { + return view; + } + + public OrganizationLocationBucketViewBuilder setOrganization(String organization) { + this.organization = organization; + return this; + } + + public OrganizationLocationBucketViewBuilder setLocation(String location) { + this.location = location; + return this; + } + + public OrganizationLocationBucketViewBuilder setBucket(String bucket) { + this.bucket = bucket; + return this; + } + + public OrganizationLocationBucketViewBuilder setView(String view) { + this.view = view; + return this; + } + + public LogViewName build() { + return new LogViewName(this); + } + } + + /** Builder for folders/{folder}/locations/{location}/buckets/{bucket}/views/{view}. */ + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static class FolderLocationBucketViewBuilder { + private String folder; + private String location; + private String bucket; + private String view; + + protected FolderLocationBucketViewBuilder() {} + + public String getFolder() { + return folder; + } + + public String getLocation() { + return location; + } + + public String getBucket() { + return bucket; + } + + public String getView() { + return view; + } + + public FolderLocationBucketViewBuilder setFolder(String folder) { + this.folder = folder; + return this; + } + + public FolderLocationBucketViewBuilder setLocation(String location) { + this.location = location; + return this; + } + + public FolderLocationBucketViewBuilder setBucket(String bucket) { + this.bucket = bucket; + return this; + } + + public FolderLocationBucketViewBuilder setView(String view) { + this.view = view; + return this; + } + + public LogViewName build() { + return new LogViewName(this); + } + } + + /** + * Builder for + * billingAccounts/{billing_account}/locations/{location}/buckets/{bucket}/views/{view}. + */ + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static class BillingAccountLocationBucketViewBuilder { + private String billingAccount; + private String location; + private String bucket; + private String view; + + protected BillingAccountLocationBucketViewBuilder() {} + + public String getBillingAccount() { + return billingAccount; + } + + public String getLocation() { + return location; + } + + public String getBucket() { + return bucket; + } + + public String getView() { + return view; + } + + public BillingAccountLocationBucketViewBuilder setBillingAccount(String billingAccount) { + this.billingAccount = billingAccount; + return this; + } + + public BillingAccountLocationBucketViewBuilder setLocation(String location) { + this.location = location; + return this; + } + + public BillingAccountLocationBucketViewBuilder setBucket(String bucket) { + this.bucket = bucket; + return this; + } + + public BillingAccountLocationBucketViewBuilder setView(String view) { + this.view = view; + return this; + } + + public LogViewName build() { + return new LogViewName(this); + } + } +} diff --git a/test/integration/goldens/logging/LoggingClient.java b/test/integration/goldens/logging/LoggingClient.java index 393a9faffd..9d5b313747 100644 --- a/test/integration/goldens/logging/LoggingClient.java +++ b/test/integration/goldens/logging/LoggingClient.java @@ -26,6 +26,7 @@ import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; import com.google.api.gax.paging.AbstractPagedListResponse; +import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.PageContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.logging.v2.stub.LoggingServiceV2Stub; @@ -44,6 +45,8 @@ import com.google.logging.v2.LogName; import com.google.logging.v2.OrganizationName; import com.google.logging.v2.ProjectName; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -508,6 +511,11 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * entries: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" + *

May alternatively be one or more views + * projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID] + * organization/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID] + * billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID] + * folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID] *

Projects listed in the `project_ids` field are added to this list. * @param filter Optional. A filter that chooses which log entries to return. See [Advanced Logs * Queries](https://cloud.google.com/logging/docs/view/advanced-queries). Only log entries @@ -859,6 +867,7 @@ public final ListLogsPagedResponse listLogs(String parent) { * .setParent(LogName.ofProjectLogName("[PROJECT]", "[LOG]").toString()) * .setPageSize(883849137) * .setPageToken("pageToken873572522") + * .addAllResourceNames(new ArrayList()) * .build(); * for (String element : loggingClient.listLogs(request).iterateAll()) { * // doThingsWith(element); @@ -887,6 +896,7 @@ public final ListLogsPagedResponse listLogs(ListLogsRequest request) { * .setParent(LogName.ofProjectLogName("[PROJECT]", "[LOG]").toString()) * .setPageSize(883849137) * .setPageToken("pageToken873572522") + * .addAllResourceNames(new ArrayList()) * .build(); * ApiFuture future = loggingClient.listLogsPagedCallable().futureCall(request); * // Do something. @@ -928,6 +938,35 @@ public final UnaryCallable listLogsCallable() return stub.listLogsCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Streaming read of log entries as they are ingested. Until the stream is terminated, it will + * continue reading logs. + * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   BidiStream bidiStream =
+   *       loggingClient.tailLogEntriesCallable().call();
+   *   TailLogEntriesRequest request =
+   *       TailLogEntriesRequest.newBuilder()
+   *           .addAllResourceNames(new ArrayList())
+   *           .setFilter("filter-1274492040")
+   *           .setBufferWindow(Duration.newBuilder().build())
+   *           .build();
+   *   bidiStream.send(request);
+   *   for (TailLogEntriesResponse response : bidiStream) {
+   *     // Do something when a response is received.
+   *   }
+   * }
+   * }
+ */ + public final BidiStreamingCallable + tailLogEntriesCallable() { + return stub.tailLogEntriesCallable(); + } + @Override public final void close() { stub.close(); diff --git a/test/integration/goldens/logging/LoggingClientTest.java b/test/integration/goldens/logging/LoggingClientTest.java index 0bcc1d8353..8fa29abd3d 100644 --- a/test/integration/goldens/logging/LoggingClientTest.java +++ b/test/integration/goldens/logging/LoggingClientTest.java @@ -27,8 +27,12 @@ import com.google.api.gax.grpc.testing.LocalChannelProvider; import com.google.api.gax.grpc.testing.MockGrpcService; import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.grpc.testing.MockStreamObserver; import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiStreamObserver; +import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; import com.google.common.collect.Lists; import com.google.logging.v2.BillingAccountName; import com.google.logging.v2.DeleteLogRequest; @@ -43,9 +47,12 @@ import com.google.logging.v2.LogName; import com.google.logging.v2.OrganizationName; import com.google.logging.v2.ProjectName; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Duration; import com.google.protobuf.Empty; import io.grpc.StatusRuntimeException; import java.io.IOException; @@ -55,6 +62,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ExecutionException; import javax.annotation.Generated; import org.junit.After; import org.junit.AfterClass; @@ -585,4 +593,64 @@ public void listLogsExceptionTest5() throws Exception { // Expected exception. } } + + @Test + public void tailLogEntriesTest() throws Exception { + TailLogEntriesResponse expectedResponse = + TailLogEntriesResponse.newBuilder() + .addAllEntries(new ArrayList()) + .addAllSuppressionInfo(new ArrayList()) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + TailLogEntriesRequest request = + TailLogEntriesRequest.newBuilder() + .addAllResourceNames(new ArrayList()) + .setFilter("filter-1274492040") + .setBufferWindow(Duration.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = + client.tailLogEntriesCallable(); + ApiStreamObserver requestObserver = + callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + requestObserver.onCompleted(); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void tailLogEntriesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + TailLogEntriesRequest request = + TailLogEntriesRequest.newBuilder() + .addAllResourceNames(new ArrayList()) + .setFilter("filter-1274492040") + .setBufferWindow(Duration.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = + client.tailLogEntriesCallable(); + ApiStreamObserver requestObserver = + callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } } diff --git a/test/integration/goldens/logging/LoggingServiceV2Stub.java b/test/integration/goldens/logging/LoggingServiceV2Stub.java index 7a18b2cc33..3ebddb7ed0 100644 --- a/test/integration/goldens/logging/LoggingServiceV2Stub.java +++ b/test/integration/goldens/logging/LoggingServiceV2Stub.java @@ -21,6 +21,7 @@ import static com.google.cloud.logging.v2.LoggingClient.ListMonitoredResourceDescriptorsPagedResponse; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.logging.v2.DeleteLogRequest; import com.google.logging.v2.ListLogEntriesRequest; @@ -29,6 +30,8 @@ import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -82,6 +85,11 @@ public UnaryCallable listLogsCallable() { throw new UnsupportedOperationException("Not implemented: listLogsCallable()"); } + public BidiStreamingCallable + tailLogEntriesCallable() { + throw new UnsupportedOperationException("Not implemented: tailLogEntriesCallable()"); + } + @Override public abstract void close(); } diff --git a/test/integration/goldens/logging/LoggingServiceV2StubSettings.java b/test/integration/goldens/logging/LoggingServiceV2StubSettings.java index c956de3687..5d4b58ba32 100644 --- a/test/integration/goldens/logging/LoggingServiceV2StubSettings.java +++ b/test/integration/goldens/logging/LoggingServiceV2StubSettings.java @@ -47,6 +47,7 @@ import com.google.api.gax.rpc.PagedListDescriptor; import com.google.api.gax.rpc.PagedListResponseFactory; import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StreamingCallSettings; import com.google.api.gax.rpc.StubSettings; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; @@ -63,6 +64,8 @@ import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -129,6 +132,8 @@ public class LoggingServiceV2StubSettings extends StubSettings listLogsSettings; + private final StreamingCallSettings + tailLogEntriesSettings; private static final PagedListDescriptor LIST_LOG_ENTRIES_PAGE_STR_DESC = @@ -411,6 +416,12 @@ public UnaryCallSettings deleteLogSettings() { return listLogsSettings; } + /** Returns the object with the settings used for calls to tailLogEntries. */ + public StreamingCallSettings + tailLogEntriesSettings() { + return tailLogEntriesSettings; + } + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public LoggingServiceV2Stub createStub() throws IOException { if (getTransportChannelProvider() @@ -486,6 +497,7 @@ protected LoggingServiceV2StubSettings(Builder settingsBuilder) throws IOExcepti listMonitoredResourceDescriptorsSettings = settingsBuilder.listMonitoredResourceDescriptorsSettings().build(); listLogsSettings = settingsBuilder.listLogsSettings().build(); + tailLogEntriesSettings = settingsBuilder.tailLogEntriesSettings().build(); } /** Builder for LoggingServiceV2StubSettings. */ @@ -505,6 +517,8 @@ public static class Builder extends StubSettings.Builder listLogsSettings; + private final StreamingCallSettings.Builder + tailLogEntriesSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -518,6 +532,13 @@ public static class Builder extends StubSettings.BuildernewArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, + StatusCode.Code.INTERNAL, + StatusCode.Code.UNAVAILABLE))); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } @@ -537,6 +558,17 @@ public static class Builder extends StubSettings.Builder>of( @@ -575,6 +608,7 @@ protected Builder(LoggingServiceV2StubSettings settings) { listMonitoredResourceDescriptorsSettings = settings.listMonitoredResourceDescriptorsSettings.toBuilder(); listLogsSettings = settings.listLogsSettings.toBuilder(); + tailLogEntriesSettings = settings.tailLogEntriesSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -690,6 +724,12 @@ public UnaryCallSettings.Builder deleteLogSettings() { return listLogsSettings; } + /** Returns the builder for the settings used for calls to tailLogEntries. */ + public StreamingCallSettings.Builder + tailLogEntriesSettings() { + return tailLogEntriesSettings; + } + @Override public LoggingServiceV2StubSettings build() throws IOException { return new LoggingServiceV2StubSettings(this); diff --git a/test/integration/goldens/logging/LoggingSettings.java b/test/integration/goldens/logging/LoggingSettings.java index 0ffa52a7ca..8740bacda1 100644 --- a/test/integration/goldens/logging/LoggingSettings.java +++ b/test/integration/goldens/logging/LoggingSettings.java @@ -30,6 +30,7 @@ import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.StreamingCallSettings; import com.google.api.gax.rpc.StubSettings; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; @@ -41,6 +42,8 @@ import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -116,6 +119,12 @@ public UnaryCallSettings deleteLogSettings() { return ((LoggingServiceV2StubSettings) getStubSettings()).listLogsSettings(); } + /** Returns the object with the settings used for calls to tailLogEntries. */ + public StreamingCallSettings + tailLogEntriesSettings() { + return ((LoggingServiceV2StubSettings) getStubSettings()).tailLogEntriesSettings(); + } + public static final LoggingSettings create(LoggingServiceV2StubSettings stub) throws IOException { return new LoggingSettings.Builder(stub.toBuilder()).build(); } @@ -246,6 +255,12 @@ public UnaryCallSettings.Builder deleteLogSettings() { return getStubSettingsBuilder().listLogsSettings(); } + /** Returns the builder for the settings used for calls to tailLogEntries. */ + public StreamingCallSettings.Builder + tailLogEntriesSettings() { + return getStubSettingsBuilder().tailLogEntriesSettings(); + } + @Override public LoggingSettings build() throws IOException { return new LoggingSettings(this); diff --git a/test/integration/goldens/logging/MockConfigServiceV2Impl.java b/test/integration/goldens/logging/MockConfigServiceV2Impl.java index fdbf74ac4d..df9005f82d 100644 --- a/test/integration/goldens/logging/MockConfigServiceV2Impl.java +++ b/test/integration/goldens/logging/MockConfigServiceV2Impl.java @@ -19,27 +19,37 @@ import com.google.api.core.BetaApi; import com.google.logging.v2.CmekSettings; import com.google.logging.v2.ConfigServiceV2Grpc.ConfigServiceV2ImplBase; +import com.google.logging.v2.CreateBucketRequest; import com.google.logging.v2.CreateExclusionRequest; import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.CreateViewRequest; +import com.google.logging.v2.DeleteBucketRequest; import com.google.logging.v2.DeleteExclusionRequest; import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.DeleteViewRequest; import com.google.logging.v2.GetBucketRequest; import com.google.logging.v2.GetCmekSettingsRequest; import com.google.logging.v2.GetExclusionRequest; import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.GetViewRequest; import com.google.logging.v2.ListBucketsRequest; import com.google.logging.v2.ListBucketsResponse; import com.google.logging.v2.ListExclusionsRequest; import com.google.logging.v2.ListExclusionsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.ListViewsRequest; +import com.google.logging.v2.ListViewsResponse; import com.google.logging.v2.LogBucket; import com.google.logging.v2.LogExclusion; import com.google.logging.v2.LogSink; +import com.google.logging.v2.LogView; +import com.google.logging.v2.UndeleteBucketRequest; import com.google.logging.v2.UpdateBucketRequest; import com.google.logging.v2.UpdateCmekSettingsRequest; import com.google.logging.v2.UpdateExclusionRequest; import com.google.logging.v2.UpdateSinkRequest; +import com.google.logging.v2.UpdateViewRequest; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Empty; import io.grpc.stub.StreamObserver; @@ -122,6 +132,27 @@ public void getBucket(GetBucketRequest request, StreamObserver respon } } + @Override + public void createBucket( + CreateBucketRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogBucket) { + requests.add(request); + responseObserver.onNext(((LogBucket) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateBucket, expected %s or %s", + response.getClass().getName(), + LogBucket.class.getName(), + Exception.class.getName()))); + } + } + @Override public void updateBucket( UpdateBucketRequest request, StreamObserver responseObserver) { @@ -143,6 +174,148 @@ public void updateBucket( } } + @Override + public void deleteBucket(DeleteBucketRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteBucket, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void undeleteBucket( + UndeleteBucketRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UndeleteBucket, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listViews( + ListViewsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListViewsResponse) { + requests.add(request); + responseObserver.onNext(((ListViewsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListViews, expected %s or %s", + response.getClass().getName(), + ListViewsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getView(GetViewRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogView) { + requests.add(request); + responseObserver.onNext(((LogView) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetView, expected %s or %s", + response.getClass().getName(), + LogView.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void createView(CreateViewRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogView) { + requests.add(request); + responseObserver.onNext(((LogView) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateView, expected %s or %s", + response.getClass().getName(), + LogView.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void updateView(UpdateViewRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogView) { + requests.add(request); + responseObserver.onNext(((LogView) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateView, expected %s or %s", + response.getClass().getName(), + LogView.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteView(DeleteViewRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteView, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + @Override public void listSinks( ListSinksRequest request, StreamObserver responseObserver) { diff --git a/test/integration/goldens/logging/MockLoggingServiceV2Impl.java b/test/integration/goldens/logging/MockLoggingServiceV2Impl.java index ece59015b9..4a0913eab0 100644 --- a/test/integration/goldens/logging/MockLoggingServiceV2Impl.java +++ b/test/integration/goldens/logging/MockLoggingServiceV2Impl.java @@ -25,6 +25,8 @@ import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LoggingServiceV2Grpc.LoggingServiceV2ImplBase; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.AbstractMessage; @@ -171,4 +173,41 @@ public void listLogs(ListLogsRequest request, StreamObserver r Exception.class.getName()))); } } + + @Override + public StreamObserver tailLogEntries( + final StreamObserver responseObserver) { + StreamObserver requestObserver = + new StreamObserver() { + @Override + public void onNext(TailLogEntriesRequest value) { + requests.add(value); + final Object response = responses.remove(); + if (response instanceof TailLogEntriesResponse) { + responseObserver.onNext(((TailLogEntriesResponse) response)); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method TailLogEntries, expected %s or %s", + response.getClass().getName(), + TailLogEntriesResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void onError(Throwable t) { + responseObserver.onError(t); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + return requestObserver; + } } From 5cc07a43b63ba8fbe30010543f91585dde326543 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Tue, 16 Feb 2021 14:51:10 -0800 Subject: [PATCH 2/2] fix: update more tests --- .../composer/goldens/LoggingClientTest.golden | 63 +++++++++++++++++++ .../LoggingServiceV2StubSettings.golden | 40 ++++++++++++ 2 files changed, 103 insertions(+) diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingClientTest.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingClientTest.golden index 0432c8afca..da4e0e0674 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingClientTest.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingClientTest.golden @@ -11,8 +11,12 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.testing.LocalChannelProvider; import com.google.api.gax.grpc.testing.MockGrpcService; import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.grpc.testing.MockStreamObserver; import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiStreamObserver; +import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; import com.google.common.collect.Lists; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Empty; @@ -28,6 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ExecutionException; import javax.annotation.Generated; import org.junit.After; import org.junit.AfterClass; @@ -558,4 +563,62 @@ public class LoggingServiceV2ClientTest { // Expected exception. } } + + @Test + public void tailLogEntriesTest() throws Exception { + TailLogEntriesResponse expectedResponse = + TailLogEntriesResponse.newBuilder() + .addAllEntries(new ArrayList()) + .addAllSuppressionInfo(new ArrayList()) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + TailLogEntriesRequest request = + TailLogEntriesRequest.newBuilder() + .addAllResourceNames(new ArrayList()) + .setFilter("filter-1274492040") + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = + client.tailLogEntriesCallable(); + ApiStreamObserver requestObserver = + callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + requestObserver.onCompleted(); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void tailLogEntriesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + TailLogEntriesRequest request = + TailLogEntriesRequest.newBuilder() + .addAllResourceNames(new ArrayList()) + .setFilter("filter-1274492040") + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = + client.tailLogEntriesCallable(); + ApiStreamObserver requestObserver = + callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } } diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingServiceV2StubSettings.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingServiceV2StubSettings.golden index 29c1fe7941..4033943f64 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingServiceV2StubSettings.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingServiceV2StubSettings.golden @@ -31,6 +31,7 @@ import com.google.api.gax.rpc.PagedCallSettings; import com.google.api.gax.rpc.PagedListDescriptor; import com.google.api.gax.rpc.PagedListResponseFactory; import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StreamingCallSettings; import com.google.api.gax.rpc.StubSettings; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; @@ -47,6 +48,8 @@ import com.google.logging.v2.ListLogsResponse; import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.LogEntry; +import com.google.logging.v2.TailLogEntriesRequest; +import com.google.logging.v2.TailLogEntriesResponse; import com.google.logging.v2.WriteLogEntriesRequest; import com.google.logging.v2.WriteLogEntriesResponse; import com.google.protobuf.Empty; @@ -113,6 +116,8 @@ public class LoggingServiceV2StubSettings extends StubSettings listLogsSettings; + private final StreamingCallSettings + tailLogEntriesSettings; private static final PagedListDescriptor LIST_LOG_ENTRIES_PAGE_STR_DESC = @@ -395,6 +400,12 @@ public class LoggingServiceV2StubSettings extends StubSettings + tailLogEntriesSettings() { + return tailLogEntriesSettings; + } + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public LoggingServiceV2Stub createStub() throws IOException { if (getTransportChannelProvider() @@ -470,6 +481,7 @@ public class LoggingServiceV2StubSettings extends StubSettings listLogsSettings; + private final StreamingCallSettings.Builder + tailLogEntriesSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -502,6 +516,13 @@ public class LoggingServiceV2StubSettings extends StubSettingsnewArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, + StatusCode.Code.INTERNAL, + StatusCode.Code.UNAVAILABLE))); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } @@ -521,6 +542,17 @@ public class LoggingServiceV2StubSettings extends StubSettings>of( @@ -559,6 +592,7 @@ public class LoggingServiceV2StubSettings extends StubSettings>of( @@ -674,6 +708,12 @@ public class LoggingServiceV2StubSettings extends StubSettings + tailLogEntriesSettings() { + return tailLogEntriesSettings; + } + @Override public LoggingServiceV2StubSettings build() throws IOException { return new LoggingServiceV2StubSettings(this);