diff --git a/.circleci/config.yml b/.circleci/config.yml index 4eb1d2231cc6..bb1c01f41222 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -79,6 +79,19 @@ jobs: - run: name: Run integration tests for google-cloud-bigquery command: ./utilities/verify_single_it.sh google-cloud-bigquery + + bigtable_it: + working_directory: ~/googleapis + <<: *anchor_docker + <<: *anchor_auth_vars + steps: + - checkout + - run: + <<: *anchor_run_decrypt + - run: + name: Run integration tests for google-cloud-bigtable + command: ./utilities/verify_single_it.sh google-cloud-bigtable -Dbigtable.env=prod -Dbigtable.table=projects/gcloud-devel/instances/google-cloud-bigtable/tables/integration-tests + compute_it: working_directory: ~/googleapis <<: *anchor_docker @@ -220,6 +233,10 @@ workflows: filters: branches: only: master + - bigtable_it: + filters: + branches: + only: master - compute_it: filters: branches: diff --git a/README.md b/README.md index 5785cb403e4a..b2cf0ba13a37 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services. - [Client Library Documentation][client-lib-docs] This library supports the following Google Cloud Platform services with clients at a [GA](#versioning) quality level: +- [BigQuery](google-cloud-bigquery) (GA) - [Stackdriver Logging](google-cloud-logging) (GA) - [Cloud Datastore](google-cloud-datastore) (GA) - [Cloud Natural Language](google-cloud-language) (GA) @@ -22,7 +23,6 @@ This library supports the following Google Cloud Platform services with clients This library supports the following Google Cloud Platform services with clients at a [Beta](#versioning) quality level: -- [BigQuery](google-cloud-bigquery) (Beta) - [Cloud Data Loss Prevention](google-cloud-dlp) (Beta) - [Stackdriver Error Reporting](google-cloud-errorreporting) (Beta) - [Cloud Firestore](google-cloud-firestore) (Beta) @@ -31,6 +31,7 @@ This library supports the following Google Cloud Platform services with clients - [Cloud Spanner](google-cloud-spanner) (Beta) - [Cloud Video Intelligence](google-cloud-video-intelligence) (Beta) - [Stackdriver Trace](google-cloud-trace) (Beta) +- [Text-to-Speech](google-cloud-texttospeech) (Beta) This library supports the following Google Cloud Platform services with clients at an [Alpha](#versioning) quality level: @@ -58,22 +59,28 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud:0.38.0-alpha' +compile 'com.google.cloud:google-cloud:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) It also works just as well to declare a dependency only on the specific clients that you need. See the README of each client for instructions. +If you're using IntelliJ or Eclipse, you can add client libraries to your project using these IDE plugins: +* [Cloud Tools for IntelliJ](https://cloud.google.com/tools/intellij/docs/client-libraries) +* [Cloud Tools for Eclipse](https://cloud.google.com/eclipse/docs/libraries) + +Besides adding client libraries, the plugins provide additional functionality, such as service account key management. Refer to the documentation for each plugin for more details. + These client libraries can be used on App Engine standard for Java 8 runtime, App Engine flexible (including the Compat runtime). Most of the libraries do not work on the App Engine standard for Java 7 runtime, however, Datastore, Storage, and Bigquery should work. If you are running into problems with version conflicts, see [Version Management](#version-management). @@ -285,7 +292,7 @@ The easiest way to solve version conflicts is to use google-cloud's BOM. In Mave com.google.cloud google-cloud-bom - 0.38.0-alpha + 0.43.0-alpha pom import diff --git a/RELEASING.md b/RELEASING.md index a674e9c4b6e1..84c850162c1d 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -109,11 +109,9 @@ Go to the [releases page](https://github.com/GoogleCloudPlatform/google-cloud-ja Ensure that the format is consistent with previous releases (for an example, see the [0.1.0 release](https://github.com/GoogleCloudPlatform/google-cloud-java/releases/tag/v0.1.0)). After adding any missing updates and reformatting as necessary, publish the draft. -11. Create a new draft for the next release. Note any commits not included in the release that have been submitted before the release commit, to ensure they are documented in the next release. +11. Run `python utilities/bump_versions.py next_snapshot patch` to include "-SNAPSHOT" in the current project version (Alternatively, update the versions in `versions.txt` to the correct versions for the next release.). Then, run `python utilities/replace_versions.py` to update the `pom.xml` files. (If you see updates in `README.md` files at this step, you probably did something wrong.) -12. Run `python utilities/bump_versions next_snapshot patch` to include "-SNAPSHOT" in the current project version (Alternatively, update the versions in `versions.txt` to the correct versions for the next release.). Then, run `python utilities/replace_versions.py` to update the `pom.xml` files. (If you see updates in `README.md` files at this step, you probably did something wrong.) - -13. Create and merge in another PR to reflect the updated project version. For an example of what this PR should look like, see [#227](https://github.com/GoogleCloudPlatform/google-cloud-java/pull/227). +13. Create and merge in another PR to reflect the updated project version. Improvements ============ diff --git a/TESTING.md b/TESTING.md index 5b77b99ac43e..f5a8242b6cae 100644 --- a/TESTING.md +++ b/TESTING.md @@ -3,6 +3,7 @@ This library provides tools to help write tests for code that uses the following google-cloud services: - [BigQuery](#testing-code-that-uses-bigquery) +- [Bigtable](#testing-code-that-uses-bigtable) - [Compute](#testing-code-that-uses-compute) - [Datastore](#testing-code-that-uses-datastore) - [DNS](#testing-code-that-uses-dns) @@ -41,6 +42,29 @@ Here is an example that clears the dataset created in Step 3. RemoteBigQueryHelper.forceDelete(bigquery, dataset); ``` +### Testing code that uses Bigtable + +Bigtable integration tests can either be run against an emulator or a real Bigtable table. The +target environment can be selected via the `bigtable.env` system property. By default it is set to +`emulator` and the other option is `prod`. + +To use the `emulator` environment, please install the gcloud sdk and use it to install the +`cbtemulator` via `gcloud components install bigtable`. + +To use the `prod` environment: +1. Set up the target table using `google-cloud-bigtable/scripts/setup-test-table.sh` +2. Download the [JSON service account credentials file][create-service-account] from the Google + Developer's Console. +3. Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the path of the credentials file +4. Set the system property `bigtable.env=prod` and `bigtable.table` to the full table name you + created earlier. Example: + ```shell + mvn verify -am -pl google-cloud-bigtable \ + -Dbigtable.env=prod \ + -Dbigtable.table=projects/my-project/instances/my-instance/tables/my-table + ``` + + ### Testing code that uses Compute Currently, there isn't an emulator for Google Compute, so an alternative is to create a test diff --git a/google-cloud-bigquery/README.md b/google-cloud-bigquery/README.md index 895b18f5f7d7..377cfa544547 100644 --- a/google-cloud-bigquery/README.md +++ b/google-cloud-bigquery/README.md @@ -12,9 +12,6 @@ Java idiomatic client for [Google Cloud BigQuery][cloud-bigquery]. - [Product Documentation][bigquery-product-docs] - [Client Library Documentation][bigquery-client-lib-docs] -> Note: This client is a work-in-progress, and may occasionally -> make backwards-incompatible changes. - Quickstart ---------- [//]: # ({x-version-update-start:google-cloud-bigquery:released}) @@ -23,16 +20,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-bigquery - 0.38.0-beta + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-bigquery:0.38.0-beta' +compile 'com.google.cloud:google-cloud-bigquery:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index 8e4eac774420..6d453e5255bd 100644 --- a/google-cloud-bigquery/pom.xml +++ b/google-cloud-bigquery/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-bigquery - 0.38.1-beta-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud BigQuery https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-bigquery diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java index 9d69342f754a..7f216910f8d9 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java @@ -522,7 +522,7 @@ public int hashCode() { * } catch (BigQueryException e) { * // the dataset was not created * } - * } + * } * * @throws BigQueryException upon failure */ @@ -538,7 +538,7 @@ public int hashCode() { * String fieldName = "string_field"; * TableId tableId = TableId.of(datasetName, tableName); * // Table field definition - * Field field = Field.of(fieldName, Field.Type.string()); + * Field field = Field.of(fieldName, LegacySQLTypeName.STRING); * // Table schema definition * Schema schema = Schema.of(field); * TableDefinition tableDefinition = StandardTableDefinition.of(schema); @@ -553,6 +553,32 @@ public int hashCode() { /** * Creates a new job. * + *

Example of loading a newline-delimited-json file with textual fields from GCS to a table. + *

 {@code
+   * String datasetName = "my_dataset_name";
+   * String tableName = "my_table_name";
+   * String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json";
+   * TableId tableId = TableId.of(datasetName, tableName);
+   * // Table field definition
+   * Field[] fields = new Field[] {
+   *     Field.of("name", LegacySQLTypeName.STRING),
+   *     Field.of("post_abbr", LegacySQLTypeName.STRING)
+   * };
+   * // Table schema definition
+   * Schema schema = Schema.of(fields);
+   * LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri)
+   *     .setFormatOptions(FormatOptions.json())
+   *     .setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
+   *     .setSchema(schema)
+   *     .build();
+   * // Load the table
+   * Job remoteLoadJob = bigquery.create(JobInfo.of(configuration));
+   * remoteLoadJob = remoteLoadJob.waitFor();
+   * // Check the table
+   * System.out.println("State: " + remoteLoadJob.getStatus().getState());
+   * return ((StandardTableDefinition) bigquery.getTable(tableId).getDefinition()).getNumRows();
+   * }
+ * *

Example of creating a query job. *

 {@code
    * String query = "SELECT field FROM my_dataset_name.my_table_name";
@@ -861,8 +887,7 @@ public int hashCode() {
    * Lists the table's rows.
    *
    * 

Example of listing table rows, specifying the page size. - * - *

{@code
+   * 
 {@code
    * String datasetName = "my_dataset_name";
    * String tableName = "my_table_name";
    * // This example reads the result 100 rows per RPC call. If there's no need to limit the number,
@@ -882,8 +907,7 @@ public int hashCode() {
    * Lists the table's rows.
    *
    * 

Example of listing table rows, specifying the page size. - * - *

{@code
+   * 
 {@code
    * String datasetName = "my_dataset_name";
    * String tableName = "my_table_name";
    * TableId tableIdObject = TableId.of(datasetName, tableName);
@@ -891,7 +915,7 @@ public int hashCode() {
    * // simply omit the option.
    * TableResult tableData =
    *     bigquery.listTableData(tableIdObject, TableDataListOption.pageSize(100));
-   * for (FieldValueList row : rowIterator.hasNext()) {
+   * for (FieldValueList row : tableData.iterateAll()) {
    *   // do something with the row
    * }
    * }
@@ -904,17 +928,16 @@ public int hashCode() { * Lists the table's rows. If the {@code schema} is not {@code null}, it is available to the * {@link FieldValueList} iterated over. * - *

Example of listing table rows. - * - *

{@code
+   * 

Example of listing table rows with schema. + *

 {@code
    * String datasetName = "my_dataset_name";
    * String tableName = "my_table_name";
    * Schema schema = ...;
-   * String field = "my_field";
+   * String field = "field";
    * TableResult tableData =
    *     bigquery.listTableData(datasetName, tableName, schema);
    * for (FieldValueList row : tableData.iterateAll()) {
-   *   row.get(field)
+   *   row.get(field);
    * }
    * }
* @@ -927,9 +950,8 @@ TableResult listTableData( * Lists the table's rows. If the {@code schema} is not {@code null}, it is available to the * {@link FieldValueList} iterated over. * - *

Example of listing table rows. - * - *

{@code
+   * 

Example of listing table rows with schema. + *

 {@code
    * Schema schema =
    *     Schema.of(
    *         Field.of("word", LegacySQLTypeName.STRING),
@@ -1047,28 +1069,21 @@ TableResult listTableData(
    * queries. Since dry-run queries are not actually executed, there's no way to retrieve results.
    *
    * 

Example of running a query. - * - *

{@code
-   * String query = "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare`";
-   * QueryJobConfiguration queryConfig = QueryJobConfiguration.of(query);
-   *
-   * // To run the legacy syntax queries use the following code instead:
-   * //   String query = "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]"
-   * //   QueryJobConfiguration queryConfig =
-   * //       QueryJobConfiguration.newBuilder(query).setUseLegacySql(true).build();
-   *
+   * 
 {@code
+   * String query = "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]";
+   * QueryJobConfiguration queryConfig =
+   *     QueryJobConfiguration.newBuilder(query).setUseLegacySql(true).build();
    * for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
    *   // do something with the data
    * }
    * }
* *

Example of running a query with query parameters. - * - *

{@code
-   * String query =
-   *     "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > ?";
+   * 
 {@code
+   * String query = "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > @wordCount";
+   * // Note, standard SQL is required to use query parameters. Legacy SQL will not work.
    * QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query)
-   *     .addPositionalParameter(QueryParameterValue.int64(5))
+   *     .addNamedParameter("wordCount", QueryParameterValue.int64(5))
    *     .build();
    * for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
    *   // do something with the data
@@ -1092,18 +1107,6 @@ TableResult query(QueryJobConfiguration configuration, JobOption... options)
    * 

See {@link #query(QueryJobConfiguration, JobOption...)} for examples on populating a {@link * QueryJobConfiguration}. * - *

The recommended way to create a randomly generated JobId is the following: - * - *

{@code
-   * JobId jobId = JobId.of();
-   * }
- * - * For a user specified job id with an optional prefix use the following: - * - *
{@code
-   * JobId jobId = JobId.of("my_prefix-my_unique_job_id");
-   * }
- * * @throws BigQueryException upon failure * @throws InterruptedException if the current thread gets interrupted while waiting for the query * to complete diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java index 0ca5d571c66b..7d88dc8cc1ac 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java @@ -19,89 +19,106 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.services.bigquery.model.JobReference; - +import com.google.auto.value.AutoValue; import java.io.Serializable; -import java.util.Objects; import java.util.UUID; +import javax.annotation.Nullable; -/** - * Google BigQuery Job identity. - */ -public final class JobId implements Serializable { - - private static final long serialVersionUID = 1225914835379688976L; +/** Google BigQuery Job identity. */ +@AutoValue +public abstract class JobId implements Serializable { - private final String project; - private final String job; + private static final long serialVersionUID = 1225914835379688977L; + JobId() { + // Users cannot extend this, but AutoValue can. + } /** - * Returns project's user-defined id. + * Returns job's project id. + * + *

When sending requests with null project, the client will attempt to infer the project name + * from the environment. */ - public String getProject() { - return project; - } + @Nullable + public abstract String getProject(); + /** + * Returns the job's id. + * + *

The server returns null job id for dry-run queries. + */ + @Nullable + public abstract String getJob(); /** - * Returns the job's user-defined id. + * Returns the job's location. + * + *

When sending requests, the location must be specified for jobs whose location not "US" or + * "EU". */ - public String getJob() { - return job; + @Nullable + abstract String getLocation(); + + public abstract Builder toBuilder(); + + public static Builder newBuilder() { + return new AutoValue_JobId.Builder(); } - private JobId(String project, String job) { - this.project = project; - this.job = job; + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setProject(String project); + + public abstract Builder setJob(String job); + + /** {@code setJob} to a pseudo-random string. */ + public Builder setRandomJob() { + return setJob(UUID.randomUUID().toString()); + } + + abstract Builder setLocation(String location); + + public abstract JobId build(); } /** * Creates a job identity given project's and job's user-defined id. */ public static JobId of(String project, String job) { - return new JobId(checkNotNull(project), checkNotNull(job)); + return newBuilder().setProject(checkNotNull(project)).setJob(checkNotNull(job)).build(); } /** * Creates a job identity given only its user-defined id. */ public static JobId of(String job) { - return new JobId(null, checkNotNull(job)); + return newBuilder().setJob(checkNotNull(job)).build(); } /** * Creates a job identity with autogenerated id and no project specified. */ public static JobId of() { - return new JobId(null, UUID.randomUUID().toString()); - } - - @Override - public boolean equals(Object obj) { - return obj == this - || obj instanceof JobId - && Objects.equals(toPb(), ((JobId) obj).toPb()); - } - - @Override - public int hashCode() { - return Objects.hash(project, job); - } - - @Override - public String toString() { - return toPb().toString(); + return newBuilder().setRandomJob().build(); } JobId setProjectId(String projectId) { - return getProject() != null ? this : JobId.of(projectId, getJob()); + return getProject() != null ? this : toBuilder().setProject(projectId).build(); } JobReference toPb() { - return new JobReference().setProjectId(project).setJobId(job); + return new JobReference() + .setProjectId(getProject()) + .setJobId(getJob()) + .setLocation(getLocation()); } static JobId fromPb(JobReference jobRef) { - return new JobId(jobRef.getProjectId(), jobRef.getJobId()); + return newBuilder() + .setProject(jobRef.getProjectId()) + .setJob(jobRef.getJobId()) + .setLocation(jobRef.getLocation()) + .build(); } } diff --git a/google-cloud-bigquerydatatransfer/README.md b/google-cloud-bigquerydatatransfer/README.md index c7813669d0ef..db12e48a8cee 100644 --- a/google-cloud-bigquerydatatransfer/README.md +++ b/google-cloud-bigquerydatatransfer/README.md @@ -25,16 +25,16 @@ Add this to your pom.xml file com.google.cloud google-cloud-bigquerydatatransfer - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-bigquerydatatransfer:0.38.0-beta' +compile 'com.google.cloud:google-cloud-bigquerydatatransfer:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquerydatatransfer" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquerydatatransfer" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-bigquerydatatransfer/pom.xml b/google-cloud-bigquerydatatransfer/pom.xml index 849324840592..cb423a1148d7 100644 --- a/google-cloud-bigquerydatatransfer/pom.xml +++ b/google-cloud-bigquerydatatransfer/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-bigquerydatatransfer - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Bigquery Data Transfer https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquerydatatransfer @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-bigquerydatatransfer diff --git a/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/DataTransferServiceSettings.java b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/DataTransferServiceSettings.java index ac89036b8dda..84d13ea60c10 100644 --- a/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/DataTransferServiceSettings.java +++ b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/DataTransferServiceSettings.java @@ -58,7 +58,7 @@ * * DataTransferServiceSettings.Builder dataTransferServiceSettingsBuilder = * DataTransferServiceSettings.newBuilder(); - * dataTransferServiceSettingsBuilder.getDataSourceSettings().getRetrySettingsBuilder() + * dataTransferServiceSettingsBuilder.getDataSourceSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * DataTransferServiceSettings dataTransferServiceSettings = dataTransferServiceSettingsBuilder.build(); * diff --git a/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/DataTransferServiceStubSettings.java b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/DataTransferServiceStubSettings.java index 86d72ae109b2..1221d16238ca 100644 --- a/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/DataTransferServiceStubSettings.java +++ b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/DataTransferServiceStubSettings.java @@ -96,7 +96,7 @@ * * DataTransferServiceStubSettings.Builder dataTransferServiceSettingsBuilder = * DataTransferServiceStubSettings.newBuilder(); - * dataTransferServiceSettingsBuilder.getDataSourceSettings().getRetrySettingsBuilder() + * dataTransferServiceSettingsBuilder.getDataSourceSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * DataTransferServiceStubSettings dataTransferServiceSettings = dataTransferServiceSettingsBuilder.build(); * diff --git a/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/GrpcDataTransferServiceCallableFactory.java b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/GrpcDataTransferServiceCallableFactory.java new file mode 100644 index 000000000000..758ef1a94644 --- /dev/null +++ b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/GrpcDataTransferServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.bigquery.datatransfer.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for BigQuery Data Transfer API. + * + *

This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcDataTransferServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/GrpcDataTransferServiceStub.java b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/GrpcDataTransferServiceStub.java index 3fa4109c1507..cd72c1dc8f24 100644 --- a/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/GrpcDataTransferServiceStub.java +++ b/google-cloud-bigquerydatatransfer/src/main/java/com/google/cloud/bigquery/datatransfer/v1/stub/GrpcDataTransferServiceStub.java @@ -24,7 +24,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.bigquery.datatransfer.v1.CheckValidCredsRequest; @@ -235,6 +235,8 @@ public class GrpcDataTransferServiceStub extends DataTransferServiceStub { private final UnaryCallable checkValidCredsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcDataTransferServiceStub create(DataTransferServiceStubSettings settings) throws IOException { return new GrpcDataTransferServiceStub(settings, ClientContext.create(settings)); @@ -246,6 +248,12 @@ public static final GrpcDataTransferServiceStub create(ClientContext clientConte DataTransferServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcDataTransferServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcDataTransferServiceStub( + DataTransferServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcDataTransferServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -253,6 +261,20 @@ public static final GrpcDataTransferServiceStub create(ClientContext clientConte */ protected GrpcDataTransferServiceStub( DataTransferServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcDataTransferServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcDataTransferServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcDataTransferServiceStub( + DataTransferServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings getDataSourceTransportSettings = GrpcCallSettings.newBuilder() @@ -316,71 +338,71 @@ protected GrpcDataTransferServiceStub( .build(); this.getDataSourceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getDataSourceTransportSettings, settings.getDataSourceSettings(), clientContext); this.listDataSourcesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listDataSourcesTransportSettings, settings.listDataSourcesSettings(), clientContext); this.listDataSourcesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listDataSourcesTransportSettings, settings.listDataSourcesSettings(), clientContext); this.createTransferConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createTransferConfigTransportSettings, settings.createTransferConfigSettings(), clientContext); this.updateTransferConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateTransferConfigTransportSettings, settings.updateTransferConfigSettings(), clientContext); this.deleteTransferConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteTransferConfigTransportSettings, settings.deleteTransferConfigSettings(), clientContext); this.getTransferConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getTransferConfigTransportSettings, settings.getTransferConfigSettings(), clientContext); this.listTransferConfigsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTransferConfigsTransportSettings, settings.listTransferConfigsSettings(), clientContext); this.listTransferConfigsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTransferConfigsTransportSettings, settings.listTransferConfigsSettings(), clientContext); this.scheduleTransferRunsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( scheduleTransferRunsTransportSettings, settings.scheduleTransferRunsSettings(), clientContext); this.getTransferRunCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getTransferRunTransportSettings, settings.getTransferRunSettings(), clientContext); this.deleteTransferRunCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteTransferRunTransportSettings, settings.deleteTransferRunSettings(), clientContext); this.listTransferRunsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTransferRunsTransportSettings, settings.listTransferRunsSettings(), clientContext); this.listTransferRunsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTransferRunsTransportSettings, settings.listTransferRunsSettings(), clientContext); this.listTransferLogsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTransferLogsTransportSettings, settings.listTransferLogsSettings(), clientContext); this.listTransferLogsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTransferLogsTransportSettings, settings.listTransferLogsSettings(), clientContext); this.checkValidCredsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( checkValidCredsTransportSettings, settings.checkValidCredsSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-bigquerydatatransfer/src/test/java/com/google/cloud/bigquery/datatransfer/v1/DataTransferServiceSmokeTest.java b/google-cloud-bigquerydatatransfer/src/test/java/com/google/cloud/bigquery/datatransfer/v1/DataTransferServiceSmokeTest.java new file mode 100644 index 000000000000..15b439b9cf7b --- /dev/null +++ b/google-cloud-bigquerydatatransfer/src/test/java/com/google/cloud/bigquery/datatransfer/v1/DataTransferServiceSmokeTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2018 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.cloud.bigquery.datatransfer.v1; + +import static com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListDataSourcesPagedResponse; + +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class DataTransferServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (DataTransferServiceClient client = DataTransferServiceClient.create()) { + ParentName parent = ProjectName.of(projectId); + + ListDataSourcesPagedResponse pagedResponse = client.listDataSources(parent); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-bigtable/DEVELOPING.md b/google-cloud-bigtable/DEVELOPING.md index 2f20ea31ef1c..3c59561ac646 100644 --- a/google-cloud-bigtable/DEVELOPING.md +++ b/google-cloud-bigtable/DEVELOPING.md @@ -43,7 +43,7 @@ by constraining the api, the surface api can be made more ergonomic: * stub/EnhancedBigtableStub: wraps the autogenerated GrpcBigtableStub. It layers logical structure on top of the protocol level requests and responses. It is responsible for adapting ReadRows chunks to logical rows and for converting between raw protobufs and user facing wrappers. -* wrappers/: contains user facing wrappers for the protobufs. Each wrapper has a toProto method +* models/: contains user facing wrappers for the protobufs. Each wrapper has a toProto method that will return the corresponding proto. * internal/: contains internal implementation details. The end user doesn't directly interact with these classes. It contains things like RequestContext, that is used by all toProto methods to diff --git a/google-cloud-bigtable/README.md b/google-cloud-bigtable/README.md new file mode 100644 index 000000000000..beb2a4823d44 --- /dev/null +++ b/google-cloud-bigtable/README.md @@ -0,0 +1,174 @@ +# Google Cloud Java Client for Bigtable + +Java idiomatic client for [Cloud Bigtable][cloud-bigtable]. Please note that this client is under +heavy development and is not ready for production use. Please continue to use the +[HBase API client](https://github.com/GoogleCloudPlatform/cloud-bigtable-client) for production. + +[[![CircleCI](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master.svg?style=shield)](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master) +[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/google-cloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/google-cloud-java?branch=master) +[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigtable.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigtable.svg) +[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) +[![Dependency Status](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772/badge.svg?style=flat)](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772) + +- [Product Documentation][bigtable-product-docs] +- [Client Library Documentation][bigtable-client-lib-docs] + +> Note: This client is under heavy development and should not be used in production. + +## Quickstart + +[//]: # ({x-version-update-start:google-cloud-bigtable:released}) +If you are using Maven, add this to your pom.xml file +```xml + + com.google.cloud + google-cloud-bigtable + 0.43.0-alpha + +``` +If you are using Gradle, add this to your dependencies +```Groovy +compile 'com.google.cloud:google-cloud-bigtable:0.43.0-alpha' +``` +If you are using SBT, add this to your dependencies +```Scala +libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "0.43.0-alpha" +``` +[//]: # ({x-version-update-end}) + +## Authentication + +See the +[Authentication](https://github.com/GoogleCloudPlatform/google-cloud-java#authentication) +section in the base directory's README. + +## About Cloud Bigtable + +[Cloud Bigtable][cloud-bigtable] Cloud Bigtable is Google's NoSQL Big Data database service. It's +the same database that powers many core Google services, including Search, Analytics, Maps, and +Gmail. + +Be sure to activate the Cloud Bigtable API and the Cloud Bigtable Admin API on the Developer's +Console to use Cloud Bigtable from your project. + +See the [Bigtable client lib docs][bigtable-client-lib-docs] to learn how to +interact with Cloud Bigtable using this Client Library. + +## Getting Started +#### Prerequisites +For this tutorial, you will need a +[Google Developers Console](https://console.developers.google.com/) project with the Cloud Bigtable +API enabled. You will need to +[enable billing](https://support.google.com/cloud/answer/6158867?hl=en) to use Google Cloud Bigtable. +[Follow these instructions](https://cloud.google.com/docs/authentication#preparation) to get your +project set up. You will also need to set up the local development environment by [installing the +Google Cloud SDK](https://cloud.google.com/sdk/) and running the following commands in command line: +`gcloud auth login`. + +#### Calling Cloud Bigtable + +The Cloud Bigtable API is split into 3 parts: Data API, Instance Admin API and Table Admin API. + +Here is a code snippet showing simple usage of the Data API. Add the following imports +at the top of your file: + +```java +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import com.google.cloud.bigtable.data.v2.models.InstanceName; +import com.google.cloud.bigtable.data.v2.models.Query; +import com.google.cloud.bigtable.data.v2.models.Row; + +``` + +Then, to make a query to Bigtable, use the following code: +```java +// Instantiates a client +String projectId = "my-instance"; +String instanceId = "my-database"; +String tableId = "my-table"; + +// Create the client +BigtableDataClient dataClient = BigtableDataClient.create( + InstanceName.of(projectId, instanceId)); + +try { + // Query a table + Query query = Query.create(tableId) + .range("a", "z") + .limit(26); + + for (Row row : dataClient.readRows(query)) { + System.out.println(row.getKey()); + } +} finally { + dataClient.close(); +} +``` + +The Admin APIs are similar. Here is a code snippet showing how to create a table. Add the following +imports at the top of your file: + +```java +import com.google.bigtable.admin.v2.ColumnFamily; +import com.google.bigtable.admin.v2.InstanceName; +import com.google.bigtable.admin.v2.Table; +import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; +``` + +Then, to create a table, use the following code: +```java +String projectId = "my-instance"; +String instanceId = "my-database"; + +BigtableTableAdminClient tableAdminClient = BigtableTableAdminClient.create(); + +try { + tableAdminClient.createTable( + InstanceName.of(projectId, instanceId), + "new-table-id", + Table.newBuilder() + .putColumnFamilies("my-family", ColumnFamily.getDefaultInstance()) + .build() + ); +} finally { + tableAdminClient.close(); +} +``` + +## Troubleshooting + +To get help, follow the instructions in the [shared Troubleshooting +document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting). + +Transport +--------- +Bigtable uses gRPC for the transport layer. + +## Java Versions + +Java 7 or above is required for using this client. + +## Versioning + +This library follows [Semantic Versioning](http://semver.org/). + +It is currently in major version zero (`0.y.z`), which means that anything may +change at any time and the public API should not be considered stable. + +## Contributing + +Contributions to this library are always welcome and highly encouraged. + +See [CONTRIBUTING] for more information on how to get started and [DEVELOPING] for a layout of the +codebase. + +## License + +Apache 2.0 - See [LICENSE] for more information. + +[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CONTRIBUTING.md +[LICENSE]: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/LICENSE +[cloud-platform]: https://cloud.google.com/ +[cloud-bigtable]: https://cloud.google.com/bigtable/ +[bigtable-product-docs]: https://cloud.google.com/bigtable/docs/ +[bigtable-client-lib-docs]: https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/bigtable/package-summary.html diff --git a/google-cloud-bigtable/autogen_files.lst b/google-cloud-bigtable/autogen_files.lst index 3fa294ad3c58..ef763544fed7 100644 --- a/google-cloud-bigtable/autogen_files.lst +++ b/google-cloud-bigtable/autogen_files.lst @@ -1,26 +1,26 @@ -src/test/java/com/google/cloud/bigtable/data/v2/MockBigtable.java -src/test/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClientTest.java src/test/java/com/google/cloud/bigtable/data/v2/MockBigtableImpl.java -src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClient.java +src/test/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClientTest.java +src/test/java/com/google/cloud/bigtable/data/v2/MockBigtable.java +src/main/java/com/google/cloud/bigtable/data/v2/package-info.java src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataSettings.java -src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStub.java src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableStub.java -src/main/java/com/google/cloud/bigtable/data/v2/package-info.java -src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdminImpl.java -src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdmin.java -src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdminImpl.java -src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java -src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java +src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClient.java src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdmin.java +src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java +src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java +src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdminImpl.java +src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdmin.java +src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdminImpl.java +src/main/java/com/google/cloud/bigtable/admin/v2/package-info.java src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java -src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java -src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStub.java -src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStubSettings.java -src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStubSettings.java src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java +src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStub.java -src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClient.java +src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStubSettings.java +src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStubSettings.java src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java -src/main/java/com/google/cloud/bigtable/admin/v2/package-info.java +src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java +src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClient.java diff --git a/google-cloud-bigtable/handwritten_files.lst b/google-cloud-bigtable/handwritten_files.lst index 7549a50a2469..acf082236813 100644 --- a/google-cloud-bigtable/handwritten_files.lst +++ b/google-cloud-bigtable/handwritten_files.lst @@ -1,49 +1,76 @@ src/test/resources/com/google/cloud/bigtable/data/v2/stub/readrows/read-rows-acceptance-test.json -src/test/java/com/google/cloud/bigtable/gaxx/.DS_Store src/test/java/com/google/cloud/bigtable/gaxx/reframing/ReframingResponseObserverTest.java -src/test/java/com/google/cloud/bigtable/gaxx/testing/FakeStreamingApi.java src/test/java/com/google/cloud/bigtable/gaxx/testing/FakeStatusCode.java -src/test/java/com/google/cloud/bigtable/gaxx/testing/MockStreamingApi.java src/test/java/com/google/cloud/bigtable/gaxx/testing/package-info.java -src/test/java/com/google/cloud/bigtable/data/v2/internal/RegexUtilTest.java -src/test/java/com/google/cloud/bigtable/data/v2/internal/ByteStringComparatorTest.java -src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java -src/test/java/com/google/cloud/bigtable/data/v2/models/FiltersTest.java -src/test/java/com/google/cloud/bigtable/data/v2/models/RowMutationTest.java -src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java -src/test/java/com/google/cloud/bigtable/data/v2/models/RangeTest.java -src/test/java/com/google/cloud/bigtable/data/v2/models/RowTest.java -src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapterTest.java -src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +src/test/java/com/google/cloud/bigtable/gaxx/testing/MockStreamingApi.java +src/test/java/com/google/cloud/bigtable/gaxx/testing/FakeStreamingApi.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/CheckAndMutateRowCallableTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/BulkMutateRowsRetryTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/RowMergingCallableTest.java src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsMergingAcceptanceTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsUserCallableTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/FilterMarkerRowsCallableTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java +src/test/java/com/google/cloud/bigtable/data/v2/stub/ReadModifyWriteRowCallableTest.java src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java +src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/FiltersTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapterTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/ConditionalRowMutationTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/MutationTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/RowTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/RowMutationTest.java +src/test/java/com/google/cloud/bigtable/data/v2/models/RangeTest.java +src/test/java/com/google/cloud/bigtable/data/v2/internal/RegexUtilTest.java +src/test/java/com/google/cloud/bigtable/data/v2/internal/ByteStringComparatorTest.java +src/main/java/com/google/cloud/bigtable/gaxx/package-info.java +src/main/java/com/google/cloud/bigtable/gaxx/reframing/package-info.java src/main/java/com/google/cloud/bigtable/gaxx/reframing/IncompleteStreamException.java src/main/java/com/google/cloud/bigtable/gaxx/reframing/ReframingResponseObserver.java src/main/java/com/google/cloud/bigtable/gaxx/reframing/Reframer.java -src/main/java/com/google/cloud/bigtable/gaxx/reframing/package-info.java -src/main/java/com/google/cloud/bigtable/gaxx/package-info.java -src/main/java/com/google/cloud/bigtable/data/.DS_Store -src/main/java/com/google/cloud/bigtable/data/v2/.DS_Store -src/main/java/com/google/cloud/bigtable/data/v2/internal/ByteStringComparator.java -src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContext.java -src/main/java/com/google/cloud/bigtable/data/v2/internal/RegexUtil.java -src/main/java/com/google/cloud/bigtable/data/v2/models/MutationApi.java -src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java -src/main/java/com/google/cloud/bigtable/data/v2/models/RowAdapter.java -src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapter.java -src/main/java/com/google/cloud/bigtable/data/v2/models/Filters.java -src/main/java/com/google/cloud/bigtable/data/v2/models/Row.java -src/main/java/com/google/cloud/bigtable/data/v2/models/Validations.java -src/main/java/com/google/cloud/bigtable/data/v2/models/KeyOffset.java -src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java -src/main/java/com/google/cloud/bigtable/data/v2/models/RowCell.java -src/main/java/com/google/cloud/bigtable/data/v2/models/Range.java -src/main/java/com/google/cloud/bigtable/data/v2/models/RowMutation.java src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java +src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/CheckAndMutateRowCallable.java src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsUserFacingCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/package-info.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsSpoolingCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/RowMergingCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/package-info.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/RowMerger.java src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/StateMachine.java -src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java -src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryCompletedCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsUserCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/FilterMarkerRowsCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/stub/ReadModifyWriteRowCallable.java +src/main/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRow.java +src/main/java/com/google/cloud/bigtable/data/v2/models/RowCell.java +src/main/java/com/google/cloud/bigtable/data/v2/models/Validations.java +src/main/java/com/google/cloud/bigtable/data/v2/models/RowMutation.java +src/main/java/com/google/cloud/bigtable/data/v2/models/BulkMutationBatcher.java +src/main/java/com/google/cloud/bigtable/data/v2/models/Mutation.java +src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultRowAdapter.java +src/main/java/com/google/cloud/bigtable/data/v2/models/RowAdapter.java +src/main/java/com/google/cloud/bigtable/data/v2/models/KeyOffset.java +src/main/java/com/google/cloud/bigtable/data/v2/models/Range.java +src/main/java/com/google/cloud/bigtable/data/v2/models/ConditionalRowMutation.java +src/main/java/com/google/cloud/bigtable/data/v2/models/Filters.java +src/main/java/com/google/cloud/bigtable/data/v2/models/MutationApi.java +src/main/java/com/google/cloud/bigtable/data/v2/models/Row.java +src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java +src/main/java/com/google/cloud/bigtable/data/v2/internal/ByteStringComparator.java +src/main/java/com/google/cloud/bigtable/data/v2/internal/DummyBatchingDescriptor.java +src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContext.java +src/main/java/com/google/cloud/bigtable/data/v2/internal/RegexUtil.java diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index 94422b725c1a..3ae99eaf00ed 100644 --- a/google-cloud-bigtable/pom.xml +++ b/google-cloud-bigtable/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-bigtable - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Bigtable https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigtable @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-bigtable @@ -127,6 +127,24 @@ + + org.apache.maven.plugins + maven-failsafe-plugin + 2.19.1 + + + + integration-test + verify + + + + + classes + true + 2 + + org.apache.maven.plugins maven-javadoc-plugin diff --git a/google-cloud-bigtable/scripts/setup-test-table.sh b/google-cloud-bigtable/scripts/setup-test-table.sh new file mode 100755 index 000000000000..1ebedb0f6007 --- /dev/null +++ b/google-cloud-bigtable/scripts/setup-test-table.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Set up a table to use for integration tests. + +set -x + +# Format: projects//instances//tables/ +TABLE_NAME=$1 + +if [[ ${TABLE_NAME} =~ projects\/([^/]+)\/instances\/([^/]+)\/tables\/([^/]+) ]]; then + PROJECT_ID=${BASH_REMATCH[1]} + INSTANCE_ID=${BASH_REMATCH[2]} + TABLE_ID=${BASH_REMATCH[3]} +else + echo "Invalid table name: $TABLE_NAME" 1>&2 + exit 1 +fi + +cbt -project $PROJECT_ID -instance $INSTANCE_ID createtable $TABLE_ID +cbt -project $PROJECT_ID -instance $INSTANCE_ID createfamily $TABLE_ID cf +cbt -project $PROJECT_ID -instance $INSTANCE_ID setgcpolicy $TABLE_ID cf maxversions=1 diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java index 10d5166d050c..c26b67906cb3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java @@ -86,7 +86,7 @@ * * BigtableInstanceAdminSettings.Builder bigtableInstanceAdminSettingsBuilder = * BigtableInstanceAdminSettings.newBuilder(); - * bigtableInstanceAdminSettingsBuilder.getInstanceSettings().getRetrySettingsBuilder() + * bigtableInstanceAdminSettingsBuilder.getInstanceSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * BigtableInstanceAdminSettings bigtableInstanceAdminSettings = bigtableInstanceAdminSettingsBuilder.build(); * diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index d7191798cffb..88c154f2b216 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -338,7 +338,7 @@ public final UnaryCallable createTableCallable() { * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) { * InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); * String tableId = ""; - * String sourceSnapshot = ""; + * SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); * Table response = bigtableTableAdminClient.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get(); * } *

@@ -353,13 +353,13 @@ public final UnaryCallable createTableCallable() { * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final OperationFuture createTableFromSnapshotAsync( - InstanceName parent, String tableId, String sourceSnapshot) { + InstanceName parent, String tableId, SnapshotName sourceSnapshot) { CreateTableFromSnapshotRequest request = CreateTableFromSnapshotRequest.newBuilder() .setParent(parent == null ? null : parent.toString()) .setTableId(tableId) - .setSourceSnapshot(sourceSnapshot) + .setSourceSnapshot(sourceSnapshot == null ? null : sourceSnapshot.toString()) .build(); return createTableFromSnapshotAsync(request); } @@ -380,8 +380,8 @@ public final OperationFuture createTable * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) { * InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); * String tableId = ""; - * String sourceSnapshot = ""; - * Table response = bigtableTableAdminClient.createTableFromSnapshotAsync(parent.toString(), tableId, sourceSnapshot).get(); + * SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); + * Table response = bigtableTableAdminClient.createTableFromSnapshotAsync(parent.toString(), tableId, sourceSnapshot.toString()).get(); * } *
* @@ -422,11 +422,11 @@ public final OperationFuture createTable * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) { * InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); * String tableId = ""; - * String sourceSnapshot = ""; + * SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); * CreateTableFromSnapshotRequest request = CreateTableFromSnapshotRequest.newBuilder() * .setParent(parent.toString()) * .setTableId(tableId) - * .setSourceSnapshot(sourceSnapshot) + * .setSourceSnapshot(sourceSnapshot.toString()) * .build(); * Table response = bigtableTableAdminClient.createTableFromSnapshotAsync(request).get(); * } @@ -456,11 +456,11 @@ public final OperationFuture createTable * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) { * InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); * String tableId = ""; - * String sourceSnapshot = ""; + * SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); * CreateTableFromSnapshotRequest request = CreateTableFromSnapshotRequest.newBuilder() * .setParent(parent.toString()) * .setTableId(tableId) - * .setSourceSnapshot(sourceSnapshot) + * .setSourceSnapshot(sourceSnapshot.toString()) * .build(); * OperationFuture<Operation> future = bigtableTableAdminClient.createTableFromSnapshotOperationCallable().futureCall(request); * // Do something @@ -490,11 +490,11 @@ public final OperationFuture createTable * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) { * InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); * String tableId = ""; - * String sourceSnapshot = ""; + * SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); * CreateTableFromSnapshotRequest request = CreateTableFromSnapshotRequest.newBuilder() * .setParent(parent.toString()) * .setTableId(tableId) - * .setSourceSnapshot(sourceSnapshot) + * .setSourceSnapshot(sourceSnapshot.toString()) * .build(); * ApiFuture<Operation> future = bigtableTableAdminClient.createTableFromSnapshotCallable().futureCall(request); * // Do something @@ -1260,13 +1260,103 @@ public final CheckConsistencyResponse checkConsistency(CheckConsistencyRequest r *

    * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
    *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
-   *   String cluster = "";
-   *   String snapshotId = "";
+   *   ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
+   *   String description = "";
+   *   Snapshot response = bigtableTableAdminClient.snapshotTableAsync(name, cluster, snapshotId, description).get();
+   * }
+   * 
+ * + * @param name The unique name of the table to have the snapshot taken. Values are of the form + * `projects/<project>/instances/<instance>/tables/<table>`. + * @param cluster The name of the cluster where the snapshot will be created in. Values are of the + * form `projects/<project>/instances/<instance>/clusters/<cluster>`. + * @param snapshotId The ID by which the new snapshot should be referred to within the parent + * cluster, e.g., `mysnapshot` of the form: `[_a-zA-Z0-9][-_.a-zA-Z0-9]*` rather than + * `projects/<project>/instances/<instance>/clusters/<cluster>/snapshots/mysnapshot`. + * @param description Description of the snapshot. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture snapshotTableAsync( + TableName name, ClusterName cluster, SnapshotName snapshotId, String description) { + + SnapshotTableRequest request = + SnapshotTableRequest.newBuilder() + .setName(name == null ? null : name.toString()) + .setCluster(cluster == null ? null : cluster.toString()) + .setSnapshotId(snapshotId == null ? null : snapshotId.toString()) + .setDescription(description) + .build(); + return snapshotTableAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * This is a private alpha release of Cloud Bigtable snapshots. This feature is not currently + * available to most Cloud Bigtable customers. This feature might be changed in + * backward-incompatible ways and is not recommended for production use. It is not subject to any + * SLA or deprecation policy. + * + *

Creates a new snapshot in the specified cluster from the specified source table. The cluster + * and the table must be in the same instance. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
+   *   String description = "";
+   *   Snapshot response = bigtableTableAdminClient.snapshotTableAsync(name.toString(), cluster.toString(), snapshotId.toString(), description).get();
+   * }
+   * 
+ * + * @param name The unique name of the table to have the snapshot taken. Values are of the form + * `projects/<project>/instances/<instance>/tables/<table>`. + * @param cluster The name of the cluster where the snapshot will be created in. Values are of the + * form `projects/<project>/instances/<instance>/clusters/<cluster>`. + * @param snapshotId The ID by which the new snapshot should be referred to within the parent + * cluster, e.g., `mysnapshot` of the form: `[_a-zA-Z0-9][-_.a-zA-Z0-9]*` rather than + * `projects/<project>/instances/<instance>/clusters/<cluster>/snapshots/mysnapshot`. + * @param description Description of the snapshot. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture snapshotTableAsync( + String name, String cluster, String snapshotId, String description) { + + SnapshotTableRequest request = + SnapshotTableRequest.newBuilder() + .setName(name) + .setCluster(cluster) + .setSnapshotId(snapshotId) + .setDescription(description) + .build(); + return snapshotTableAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * This is a private alpha release of Cloud Bigtable snapshots. This feature is not currently + * available to most Cloud Bigtable customers. This feature might be changed in + * backward-incompatible ways and is not recommended for production use. It is not subject to any + * SLA or deprecation policy. + * + *

Creates a new snapshot in the specified cluster from the specified source table. The cluster + * and the table must be in the same instance. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
    *   String description = "";
    *   SnapshotTableRequest request = SnapshotTableRequest.newBuilder()
    *     .setName(name.toString())
-   *     .setCluster(cluster)
-   *     .setSnapshotId(snapshotId)
+   *     .setCluster(cluster.toString())
+   *     .setSnapshotId(snapshotId.toString())
    *     .setDescription(description)
    *     .build();
    *   Snapshot response = bigtableTableAdminClient.snapshotTableAsync(request).get();
@@ -1296,13 +1386,13 @@ public final OperationFuture snapshotTableAsync
    * 

    * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
    *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
-   *   String cluster = "";
-   *   String snapshotId = "";
+   *   ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
    *   String description = "";
    *   SnapshotTableRequest request = SnapshotTableRequest.newBuilder()
    *     .setName(name.toString())
-   *     .setCluster(cluster)
-   *     .setSnapshotId(snapshotId)
+   *     .setCluster(cluster.toString())
+   *     .setSnapshotId(snapshotId.toString())
    *     .setDescription(description)
    *     .build();
    *   OperationFuture<Operation> future = bigtableTableAdminClient.snapshotTableOperationCallable().futureCall(request);
@@ -1331,13 +1421,13 @@ public final OperationFuture snapshotTableAsync
    * 

    * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
    *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
-   *   String cluster = "";
-   *   String snapshotId = "";
+   *   ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
    *   String description = "";
    *   SnapshotTableRequest request = SnapshotTableRequest.newBuilder()
    *     .setName(name.toString())
-   *     .setCluster(cluster)
-   *     .setSnapshotId(snapshotId)
+   *     .setCluster(cluster.toString())
+   *     .setSnapshotId(snapshotId.toString())
    *     .setDescription(description)
    *     .build();
    *   ApiFuture<Operation> future = bigtableTableAdminClient.snapshotTableCallable().futureCall(request);
diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java
index 7449b96c6327..33503291d325 100644
--- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java
+++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java
@@ -78,7 +78,7 @@
  * 
  * BigtableTableAdminSettings.Builder bigtableTableAdminSettingsBuilder =
  *     BigtableTableAdminSettings.newBuilder();
- * bigtableTableAdminSettingsBuilder.createTableSettings().getRetrySettingsBuilder()
+ * bigtableTableAdminSettingsBuilder.createTableSettings().getRetrySettings().toBuilder()
  *     .setTotalTimeout(Duration.ofSeconds(30));
  * BigtableTableAdminSettings bigtableTableAdminSettings = bigtableTableAdminSettingsBuilder.build();
  * 
diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStubSettings.java
index 53825d6d0cec..c3278d00d99a 100644
--- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStubSettings.java
+++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStubSettings.java
@@ -104,7 +104,7 @@
  * 
  * BigtableInstanceAdminStubSettings.Builder bigtableInstanceAdminSettingsBuilder =
  *     BigtableInstanceAdminStubSettings.newBuilder();
- * bigtableInstanceAdminSettingsBuilder.getInstanceSettings().getRetrySettingsBuilder()
+ * bigtableInstanceAdminSettingsBuilder.getInstanceSettings().getRetrySettings().toBuilder()
  *     .setTotalTimeout(Duration.ofSeconds(30));
  * BigtableInstanceAdminStubSettings bigtableInstanceAdminSettings = bigtableInstanceAdminSettingsBuilder.build();
  * 
diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStubSettings.java
index 297ccc5020f6..9d0c607fadc2 100644
--- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStubSettings.java
+++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStubSettings.java
@@ -96,7 +96,7 @@
  * 
  * BigtableTableAdminStubSettings.Builder bigtableTableAdminSettingsBuilder =
  *     BigtableTableAdminStubSettings.newBuilder();
- * bigtableTableAdminSettingsBuilder.createTableSettings().getRetrySettingsBuilder()
+ * bigtableTableAdminSettingsBuilder.createTableSettings().getRetrySettings().toBuilder()
  *     .setTotalTimeout(Duration.ofSeconds(30));
  * BigtableTableAdminStubSettings bigtableTableAdminSettings = bigtableTableAdminSettingsBuilder.build();
  * 
@@ -594,7 +594,7 @@ private static Builder initDefaults(Builder builder) {
 
       builder
           .checkConsistencySettings()
-          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
+          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
 
       builder
diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminCallableFactory.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminCallableFactory.java
new file mode 100644
index 000000000000..fa9c6f4adf1d
--- /dev/null
+++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminCallableFactory.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2018 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.cloud.bigtable.admin.v2.stub;
+
+import com.google.api.core.BetaApi;
+import com.google.api.gax.grpc.GrpcCallSettings;
+import com.google.api.gax.grpc.GrpcCallableFactory;
+import com.google.api.gax.grpc.GrpcStubCallableFactory;
+import com.google.api.gax.rpc.BatchingCallSettings;
+import com.google.api.gax.rpc.BidiStreamingCallable;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.ClientStreamingCallable;
+import com.google.api.gax.rpc.OperationCallSettings;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.PagedCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallable;
+import com.google.api.gax.rpc.StreamingCallSettings;
+import com.google.api.gax.rpc.UnaryCallSettings;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.longrunning.Operation;
+import com.google.longrunning.stub.OperationsStub;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS
+/**
+ * gRPC callable factory implementation for Cloud Bigtable Admin API.
+ *
+ * 

This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcBigtableInstanceAdminCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java index b00c2ca06246..d23e548f3c8b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java @@ -21,9 +21,10 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.admin.v2.AppProfile; import com.google.bigtable.admin.v2.Cluster; @@ -50,6 +51,7 @@ import com.google.bigtable.admin.v2.UpdateAppProfileRequest; import com.google.bigtable.admin.v2.UpdateClusterMetadata; import com.google.bigtable.admin.v2.UpdateInstanceMetadata; +import com.google.common.collect.ImmutableMap; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; @@ -61,6 +63,7 @@ import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; import java.io.IOException; +import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -267,6 +270,8 @@ public class GrpcBigtableInstanceAdminStub extends BigtableInstanceAdminStub { private final UnaryCallable testIamPermissionsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcBigtableInstanceAdminStub create( BigtableInstanceAdminStubSettings settings) throws IOException { return new GrpcBigtableInstanceAdminStub(settings, ClientContext.create(settings)); @@ -278,6 +283,12 @@ public static final GrpcBigtableInstanceAdminStub create(ClientContext clientCon BigtableInstanceAdminStubSettings.newBuilder().build(), clientContext); } + public static final GrpcBigtableInstanceAdminStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcBigtableInstanceAdminStub( + BigtableInstanceAdminStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcBigtableInstanceAdminStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -285,172 +296,350 @@ public static final GrpcBigtableInstanceAdminStub create(ClientContext clientCon */ protected GrpcBigtableInstanceAdminStub( BigtableInstanceAdminStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcBigtableInstanceAdminCallableFactory()); + } + + /** + * Constructs an instance of GrpcBigtableInstanceAdminStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcBigtableInstanceAdminStub( + BigtableInstanceAdminStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings createInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings getInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings listInstancesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listInstancesMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListInstancesRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings partialUpdateInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(partialUpdateInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(PartialUpdateInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put( + "instance.name", String.valueOf(request.getInstance().getName())); + return params.build(); + } + }) .build(); GrpcCallSettings deleteInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings createClusterTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createClusterMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateClusterRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings getClusterTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getClusterMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetClusterRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings listClustersTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listClustersMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListClustersRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings updateClusterTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(updateClusterMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(Cluster request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings deleteClusterTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteClusterMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteClusterRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings createAppProfileTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createAppProfileMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateAppProfileRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings getAppProfileTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getAppProfileMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetAppProfileRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings listAppProfilesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listAppProfilesMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListAppProfilesRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings updateAppProfileTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(updateAppProfileMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(UpdateAppProfileRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put( + "app_profile.name", String.valueOf(request.getAppProfile().getName())); + return params.build(); + } + }) .build(); GrpcCallSettings deleteAppProfileTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteAppProfileMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteAppProfileRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings getIamPolicyTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetIamPolicyRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("resource", String.valueOf(request.getResource())); + return params.build(); + } + }) .build(); GrpcCallSettings setIamPolicyTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(SetIamPolicyRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("resource", String.valueOf(request.getResource())); + return params.build(); + } + }) .build(); GrpcCallSettings testIamPermissionsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(TestIamPermissionsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("resource", String.valueOf(request.getResource())); + return params.build(); + } + }) .build(); this.createInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createInstanceTransportSettings, settings.createInstanceSettings(), clientContext); this.createInstanceOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( createInstanceTransportSettings, settings.createInstanceOperationSettings(), clientContext, this.operationsStub); this.getInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); this.listInstancesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); this.partialUpdateInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( partialUpdateInstanceTransportSettings, settings.partialUpdateInstanceSettings(), clientContext); this.partialUpdateInstanceOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( partialUpdateInstanceTransportSettings, settings.partialUpdateInstanceOperationSettings(), clientContext, this.operationsStub); this.deleteInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); this.createClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createClusterTransportSettings, settings.createClusterSettings(), clientContext); this.createClusterOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( createClusterTransportSettings, settings.createClusterOperationSettings(), clientContext, this.operationsStub); this.getClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getClusterTransportSettings, settings.getClusterSettings(), clientContext); this.listClustersCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listClustersTransportSettings, settings.listClustersSettings(), clientContext); this.updateClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateClusterTransportSettings, settings.updateClusterSettings(), clientContext); this.updateClusterOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( updateClusterTransportSettings, settings.updateClusterOperationSettings(), clientContext, this.operationsStub); this.deleteClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteClusterTransportSettings, settings.deleteClusterSettings(), clientContext); this.createAppProfileCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createAppProfileTransportSettings, settings.createAppProfileSettings(), clientContext); this.getAppProfileCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getAppProfileTransportSettings, settings.getAppProfileSettings(), clientContext); this.listAppProfilesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listAppProfilesTransportSettings, settings.listAppProfilesSettings(), clientContext); this.listAppProfilesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listAppProfilesTransportSettings, settings.listAppProfilesSettings(), clientContext); this.updateAppProfileCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateAppProfileTransportSettings, settings.updateAppProfileSettings(), clientContext); this.updateAppProfileOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( updateAppProfileTransportSettings, settings.updateAppProfileOperationSettings(), clientContext, this.operationsStub); this.deleteAppProfileCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteAppProfileTransportSettings, settings.deleteAppProfileSettings(), clientContext); this.getIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); this.setIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); this.testIamPermissionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( testIamPermissionsTransportSettings, settings.testIamPermissionsSettings(), clientContext); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminCallableFactory.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminCallableFactory.java new file mode 100644 index 000000000000..26ec31a3ff3b --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.bigtable.admin.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Bigtable Admin API. + * + *

This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcBigtableTableAdminCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java index 7a3a23dd033c..8898182d332d 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java @@ -22,9 +22,10 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.CheckConsistencyResponse; @@ -47,12 +48,14 @@ import com.google.bigtable.admin.v2.SnapshotTableMetadata; import com.google.bigtable.admin.v2.SnapshotTableRequest; import com.google.bigtable.admin.v2.Table; +import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; import java.io.IOException; +import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -208,6 +211,8 @@ public class GrpcBigtableTableAdminStub extends BigtableTableAdminStub { listSnapshotsPagedCallable; private final UnaryCallable deleteSnapshotCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcBigtableTableAdminStub create(BigtableTableAdminStubSettings settings) throws IOException { return new GrpcBigtableTableAdminStub(settings, ClientContext.create(settings)); @@ -219,6 +224,12 @@ public static final GrpcBigtableTableAdminStub create(ClientContext clientContex BigtableTableAdminStubSettings.newBuilder().build(), clientContext); } + public static final GrpcBigtableTableAdminStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcBigtableTableAdminStub( + BigtableTableAdminStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcBigtableTableAdminStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -226,127 +237,258 @@ public static final GrpcBigtableTableAdminStub create(ClientContext clientContex */ protected GrpcBigtableTableAdminStub( BigtableTableAdminStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcBigtableTableAdminCallableFactory()); + } + + /** + * Constructs an instance of GrpcBigtableTableAdminStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcBigtableTableAdminStub( + BigtableTableAdminStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings createTableTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createTableMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateTableRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings createTableFromSnapshotTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createTableFromSnapshotMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateTableFromSnapshotRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings listTablesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listTablesMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListTablesRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings getTableTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getTableMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetTableRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings deleteTableTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteTableMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteTableRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings modifyColumnFamiliesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(modifyColumnFamiliesMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ModifyColumnFamiliesRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings dropRowRangeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(dropRowRangeMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DropRowRangeRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings generateConsistencyTokenTransportSettings = GrpcCallSettings .newBuilder() .setMethodDescriptor(generateConsistencyTokenMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GenerateConsistencyTokenRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings checkConsistencyTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(checkConsistencyMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CheckConsistencyRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings snapshotTableTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(snapshotTableMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(SnapshotTableRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings getSnapshotTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getSnapshotMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetSnapshotRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings listSnapshotsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listSnapshotsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListSnapshotsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings deleteSnapshotTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteSnapshotMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteSnapshotRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); this.createTableCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createTableTransportSettings, settings.createTableSettings(), clientContext); this.createTableFromSnapshotCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createTableFromSnapshotTransportSettings, settings.createTableFromSnapshotSettings(), clientContext); this.createTableFromSnapshotOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( createTableFromSnapshotTransportSettings, settings.createTableFromSnapshotOperationSettings(), clientContext, this.operationsStub); this.listTablesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTablesTransportSettings, settings.listTablesSettings(), clientContext); this.listTablesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTablesTransportSettings, settings.listTablesSettings(), clientContext); this.getTableCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getTableTransportSettings, settings.getTableSettings(), clientContext); this.deleteTableCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteTableTransportSettings, settings.deleteTableSettings(), clientContext); this.modifyColumnFamiliesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( modifyColumnFamiliesTransportSettings, settings.modifyColumnFamiliesSettings(), clientContext); this.dropRowRangeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( dropRowRangeTransportSettings, settings.dropRowRangeSettings(), clientContext); this.generateConsistencyTokenCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( generateConsistencyTokenTransportSettings, settings.generateConsistencyTokenSettings(), clientContext); this.checkConsistencyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( checkConsistencyTransportSettings, settings.checkConsistencySettings(), clientContext); this.snapshotTableCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( snapshotTableTransportSettings, settings.snapshotTableSettings(), clientContext); this.snapshotTableOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( snapshotTableTransportSettings, settings.snapshotTableOperationSettings(), clientContext, this.operationsStub); this.getSnapshotCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getSnapshotTransportSettings, settings.getSnapshotSettings(), clientContext); this.listSnapshotsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listSnapshotsTransportSettings, settings.listSnapshotsSettings(), clientContext); this.listSnapshotsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listSnapshotsTransportSettings, settings.listSnapshotsSettings(), clientContext); this.deleteSnapshotCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteSnapshotTransportSettings, settings.deleteSnapshotSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataSettings.java index 7b7d61298e4f..316450c906e3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataSettings.java @@ -63,7 +63,7 @@ * * BaseBigtableDataSettings.Builder baseBigtableDataSettingsBuilder = * BaseBigtableDataSettings.newBuilder(); - * baseBigtableDataSettingsBuilder.mutateRowSettings().getRetrySettingsBuilder() + * baseBigtableDataSettingsBuilder.mutateRowSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * BaseBigtableDataSettings baseBigtableDataSettings = baseBigtableDataSettingsBuilder.build(); * diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java index 14b8a9642432..a3e8f5a93017 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java @@ -22,7 +22,7 @@ import com.google.api.gax.rpc.ServerStream; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.cloud.bigtable.data.v2.models.BulkMutationBatcher; import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; import com.google.cloud.bigtable.data.v2.models.KeyOffset; @@ -32,6 +32,7 @@ import com.google.cloud.bigtable.data.v2.models.RowAdapter; import com.google.cloud.bigtable.data.v2.models.RowMutation; import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub; +import com.google.protobuf.ByteString; import java.io.IOException; import java.util.List; @@ -126,6 +127,44 @@ public static BigtableDataClient create(BigtableDataSettings settings) throws IO this.stub = stub; } + /** + * Convenience method for asynchronously reading a single row. If the row does not exist, the + * future's value will be null. + * + *

Sample code: + * + *

{@code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableClient bigtableClient = BigtableClient.create(instanceName)) {
+   *   String tableId = "[TABLE]";
+   *
+   *   ApiFuture result = bigtableClient.readRow(tableId,  "key");
+   * }
+   * }
+ */ + public ApiFuture readRowAsync(String tableId, String rowKey) { + return readRowAsync(tableId, ByteString.copyFromUtf8(rowKey)); + } + + /** + * Convenience method for asynchronously reading a single row. If the row does not exist, the + * future's value will be null. + * + *

Sample code: + * + *

{@code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableClient bigtableClient = BigtableClient.create(instanceName)) {
+   *   String tableId = "[TABLE]";
+   *
+   *   ApiFuture result = bigtableClient.readRow(tableId,  ByteString.copyFromUtf8("key"));
+   * }
+   * }
+ */ + public ApiFuture readRowAsync(String tableId, ByteString rowKey) { + return readRowsCallable().first().futureCall(Query.create(tableId).rowKey(rowKey)); + } + /** * Convenience method for synchronous streaming the results of a {@link Query}. * diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java index 1067141b1486..b54fc80ab974 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java @@ -19,7 +19,7 @@ import com.google.api.gax.rpc.ClientSettings; import com.google.api.gax.rpc.ServerStreamingCallSettings; import com.google.api.gax.rpc.UnaryCallSettings; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; import com.google.cloud.bigtable.data.v2.models.KeyOffset; import com.google.cloud.bigtable.data.v2.models.Query; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContext.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContext.java index b8667d3f5188..eabef9c766f8 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContext.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContext.java @@ -17,7 +17,7 @@ import com.google.api.core.InternalApi; import com.google.auto.value.AutoValue; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; /** * Contains information necessary to construct Bigtable protobuf requests from user facing models. diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/InstanceName.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/InstanceName.java new file mode 100644 index 000000000000..8465d5eb8e92 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/InstanceName.java @@ -0,0 +1,188 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.models; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.api.resourcenames.ResourceNameType; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +// Copied from com.google.bigtable.admin.v2 +// TODO: figure out how to unify admin & data resource names +/** Typesafe representation of a fully qualified Bigtable instance name */ +public class InstanceName implements ResourceName { + private static final PathTemplate PATH_TEMPLATE = + PathTemplate.createWithoutUrlEncoding("projects/{project}/instances/{instance}"); + + private volatile Map fieldValuesMap; + + private final String project; + private final String instance; + + public String getProject() { + return project; + } + + public String getInstance() { + return instance; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + private InstanceName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + instance = Preconditions.checkNotNull(builder.getInstance()); + } + + public static InstanceName of(String project, String instance) { + return newBuilder().setProject(project).setInstance(instance).build(); + } + + public static String format(String project, String instance) { + return newBuilder().setProject(project).setInstance(instance).build().toString(); + } + + public static InstanceName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PATH_TEMPLATE.validatedMatch( + formattedString, "InstanceName.parse: formattedString not in valid format"); + return of(matchMap.get("project"), matchMap.get("instance")); + } + + 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 (InstanceName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PATH_TEMPLATE.matches(formattedString); + } + + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + fieldMapBuilder.put("project", project); + fieldMapBuilder.put("instance", instance); + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + /** @deprecated This method is only present to satisfy the ResourceName interface. */ + @Deprecated + public ResourceNameType getType() { + throw new UnsupportedOperationException("InstanceName.getType() not supported"); + } + + @Override + public String toString() { + return PATH_TEMPLATE.instantiate("project", project, "instance", instance); + } + + /** Builder for InstanceName. */ + public static class Builder { + + private String project; + private String instance; + + public String getProject() { + return project; + } + + public String getInstance() { + return instance; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + public Builder setInstance(String instance) { + this.instance = instance; + return this; + } + + private Builder() {} + + private Builder(InstanceName instanceName) { + project = instanceName.project; + instance = instanceName.instance; + } + + public InstanceName build() { + return new InstanceName(this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof InstanceName) { + InstanceName that = (InstanceName) o; + return (this.project.equals(that.project)) && (this.instance.equals(that.instance)); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= project.hashCode(); + h *= 1000003; + h ^= instance.hashCode(); + return h; + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/MutateRowsException.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/MutateRowsException.java new file mode 100644 index 000000000000..d1c0eda844c2 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/MutateRowsException.java @@ -0,0 +1,105 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.models; + +import com.google.api.core.InternalApi; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.StatusCode; +import com.google.auto.value.AutoValue; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.common.base.Preconditions; +import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Thrown by the MutateRows when at least one Mutation failed. If the last failure was caused by an + * RPC error (as opposed to a single entry failing), then this exception's cause will be set to that + * error and {@link #getFailedMutations()} will contain synthetic errors for all of the entries that + * were part of that RPC. + */ +public final class MutateRowsException extends ApiException { + // Synthetic status to use for this ApiException subclass. + private static final StatusCode LOCAL_STATUS = + new StatusCode() { + @Override + public Code getCode() { + return Code.INTERNAL; + } + + @Override + public Object getTransportCode() { + return null; + } + }; + + private final List failedMutations; + + /** + * This constructor is considered an internal implementation detail and not meant to be used by + * applications. + */ + @InternalApi + public MutateRowsException( + @Nullable Throwable rpcError, + @Nonnull List failedMutations, + boolean retryable) { + super("Some mutations failed to apply", rpcError, LOCAL_STATUS, retryable); + Preconditions.checkNotNull(failedMutations); + Preconditions.checkArgument(!failedMutations.isEmpty(), "failedMutations can't be empty"); + this.failedMutations = failedMutations; + } + + /** + * Retrieve all of the failed mutations. This list will contain failures for all of the mutations + * that have failed across all of the retry attempts so far. + */ + @Nonnull + public List getFailedMutations() { + return failedMutations; + } + + /** + * Identifies which mutation failed and the reason it failed. The mutation is identified by it's + * index in the original request's {@link MutateRowsRequest#getEntriesList()}. + */ + @AutoValue + public abstract static class FailedMutation { + /** + * This method is considered an internal implementation detail and not meant to be used by + * applications. + */ + @InternalApi + @Nonnull + public static FailedMutation create(int index, ApiException error) { + return new AutoValue_MutateRowsException_FailedMutation(index, error); + } + + /** + * The index of the mutation in the original request's {@link + * MutateRowsRequest#getEntriesList()}. + */ + public abstract int getIndex(); + + /** + * The error that prevented this mutation from being applied. Please note, that if the entire + * RPC attempt failed, all mutations that were part of the attempt will have take on the same + * error. + */ + @Nonnull + public abstract ApiException getError(); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java index da951c91da3d..2671f40913bb 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java @@ -72,7 +72,7 @@ * * BigtableStubSettings.Builder baseBigtableDataSettingsBuilder = * BigtableStubSettings.newBuilder(); - * baseBigtableDataSettingsBuilder.mutateRowSettings().getRetrySettingsBuilder() + * baseBigtableDataSettingsBuilder.mutateRowSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * BigtableStubSettings baseBigtableDataSettings = baseBigtableDataSettingsBuilder.build(); * diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index d26658cad0b0..f3aef39f6268 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -15,10 +15,11 @@ */ package com.google.cloud.bigtable.data.v2.stub; -import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; -import com.google.api.gax.retrying.RetrySettings; -import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.retrying.ExponentialRetryAlgorithm; +import com.google.api.gax.retrying.RetryAlgorithm; +import com.google.api.gax.retrying.RetryingExecutor; +import com.google.api.gax.retrying.ScheduledRetryingExecutor; import com.google.api.gax.rpc.BatchingCallSettings; import com.google.api.gax.rpc.Callables; import com.google.api.gax.rpc.ClientContext; @@ -26,7 +27,6 @@ import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.v2.MutateRowsRequest; -import com.google.bigtable.v2.MutateRowsResponse; import com.google.bigtable.v2.ReadRowsRequest; import com.google.bigtable.v2.SampleRowKeysRequest; import com.google.bigtable.v2.SampleRowKeysResponse; @@ -40,13 +40,14 @@ import com.google.cloud.bigtable.data.v2.models.RowAdapter; import com.google.cloud.bigtable.data.v2.models.RowMutation; import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor; -import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsSpoolingCallable; +import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsRetryingCallable; import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsUserFacingCallable; import com.google.cloud.bigtable.data.v2.stub.readrows.FilterMarkerRowsCallable; import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsResumptionStrategy; import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsRetryCompletedCallable; import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable; import com.google.cloud.bigtable.data.v2.stub.readrows.RowMergingCallable; +import com.google.cloud.bigtable.gaxx.retrying.ApiResultRetryAlgorithm; import java.io.IOException; import java.util.List; import org.threeten.bp.Duration; @@ -84,7 +85,9 @@ public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings) BigtableStubSettings.newBuilder() .setTransportChannelProvider(settings.getTransportChannelProvider()) .setEndpoint(settings.getEndpoint()) - .setCredentialsProvider(settings.getCredentialsProvider()); + .setCredentialsProvider(settings.getCredentialsProvider()) + .setStreamWatchdogProvider(settings.getStreamWatchdogProvider()) + .setStreamWatchdogCheckInterval(settings.getStreamWatchdogCheckInterval()); // ReadRow retries are handled in the overlay: disable retries in the base layer (but make // sure to preserve the exception callable settings). @@ -92,7 +95,6 @@ public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings) .readRowsSettings() .setSimpleTimeoutNoRetries(Duration.ofHours(2)) .setRetryableCodes(settings.readRowsSettings().getRetryableCodes()) - .setTimeoutCheckInterval(Duration.ZERO) .setIdleTimeout(Duration.ZERO); // SampleRowKeys retries are handled in the overlay: disable retries in the base layer (but make @@ -115,7 +117,6 @@ public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings) .mutateRowsSettings() .setSimpleTimeoutNoRetries(Duration.ofHours(2)) .setRetryableCodes(settings.mutateRowsSettings().getRetryableCodes()) - .setTimeoutCheckInterval(Duration.ZERO) .setIdleTimeout(Duration.ZERO); // CheckAndMutateRow is a simple passthrough @@ -182,7 +183,6 @@ public ServerStreamingCallable createReadRowsCallable( .setResumptionStrategy(new ReadRowsResumptionStrategy<>(rowAdapter)) .setRetryableCodes(settings.readRowsSettings().getRetryableCodes()) .setRetrySettings(settings.readRowsSettings().getRetrySettings()) - .setTimeoutCheckInterval(settings.readRowsSettings().getTimeoutCheckInterval()) .setIdleTimeout(settings.readRowsSettings().getIdleTimeout()) .build(); @@ -252,28 +252,41 @@ private UnaryCallable createMutateRowCallable() { *
  • Convert a {@link RowMutation} into a {@link MutateRowsRequest} with a single entry. *
  • Using gax's {@link com.google.api.gax.rpc.BatchingCallable} to spool the requests and * aggregate the {@link MutateRowsRequest.Entry}s. - *
  • Spool the streamed responses. + *
  • Process the response and schedule retries. At the end of each attempt, entries that have + * been applied, are filtered from the next attempt. Also, any entries that failed with a + * nontransient error, are filtered from the next attempt. This will continue until there + * are no more entries or there are no more retry attempts left. + *
  • Wrap batch failures in a {@link + * com.google.cloud.bigtable.data.v2.models.MutateRowsException}. *
  • Split the responses using {@link MutateRowsBatchingDescriptor}. - *
  • Apply retries to individual mutations * */ private UnaryCallable createMutateRowsCallable() { - MutateRowsSpoolingCallable spooling = new MutateRowsSpoolingCallable(stub.mutateRowsCallable()); + RetryAlgorithm retryAlgorithm = + new RetryAlgorithm<>( + new ApiResultRetryAlgorithm(), + new ExponentialRetryAlgorithm( + settings.mutateRowsSettings().getRetrySettings(), clientContext.getClock())); + RetryingExecutor retryingExecutor = + new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); + + UnaryCallable retrying = + new MutateRowsRetryingCallable( + clientContext.getDefaultCallContext(), + stub.mutateRowsCallable(), + retryingExecutor, + settings.mutateRowsSettings().getRetryableCodes()); // recreate BatchingCallSettings with the correct descriptor - BatchingCallSettings.Builder batchingCallSettings = - BatchingCallSettings.newBuilder( - new MutateRowsBatchingDescriptor(settings.mutateRowsSettings().getRetryableCodes())) + BatchingCallSettings.Builder batchingCallSettings = + BatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor()) .setBatchingSettings(settings.mutateRowsSettings().getBatchingSettings()); - UnaryCallable batching = - Callables.batching(spooling, batchingCallSettings.build(), clientContext); - - UnaryCallable retrying = - Callables.retrying(batching, settings.mutateRowsSettings(), clientContext); + UnaryCallable batching = + Callables.batching(retrying, batchingCallSettings.build(), clientContext); MutateRowsUserFacingCallable userFacing = - new MutateRowsUserFacingCallable(retrying, requestContext); + new MutateRowsUserFacingCallable(batching, requestContext); return userFacing.withDefaultCallContext(clientContext.getDefaultCallContext()); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java index 271d207a8082..cab0ae54c935 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java @@ -26,7 +26,7 @@ import com.google.api.gax.rpc.StatusCode.Code; import com.google.api.gax.rpc.StubSettings; import com.google.api.gax.rpc.UnaryCallSettings; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.cloud.bigtable.data.v2.internal.DummyBatchingDescriptor; import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; import com.google.cloud.bigtable.data.v2.models.KeyOffset; @@ -80,16 +80,16 @@ public class EnhancedBigtableStubSettings extends StubSettings DEFAULT_RETRY_CODES = ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE, Code.ABORTED); + // Copy of default retrying settings in the yaml private static final RetrySettings DEFAULT_RETRY_SETTINGS = RetrySettings.newBuilder() - .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRetryDelay(Duration.ofMillis(100)) + .setInitialRetryDelay(Duration.ofMillis(100L)) .setRetryDelayMultiplier(1.3) - .setMaxRetryDelay(Duration.ofMinutes(1)) - .setInitialRpcTimeout(Duration.ofSeconds(20)) - .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(20)) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(20000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(20000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) .build(); private final InstanceName instanceName; @@ -201,14 +201,16 @@ private Builder() { .setChannelsPerCpu(2) .setMaxInboundMessageSize(MAX_MESSAGE_SIZE) .build()); + setStreamWatchdogCheckInterval(baseDefaults.getStreamWatchdogCheckInterval()); + setStreamWatchdogProvider(baseDefaults.getStreamWatchdogProvider()); // Per-method settings using baseSettings for defaults. readRowsSettings = ServerStreamingCallSettings.newBuilder(); /* TODO: copy timeouts, retryCodes & retrySettings from baseSettings.readRows once it exists in GAPIC */ readRowsSettings .setRetryableCodes(DEFAULT_RETRY_CODES) - .setRetrySettings(DEFAULT_RETRY_SETTINGS) - .setTimeoutCheckInterval(Duration.ofSeconds(10)) + .setRetrySettings( + DEFAULT_RETRY_SETTINGS.toBuilder().setTotalTimeout(Duration.ofHours(1)).build()) .setIdleTimeout(Duration.ofMinutes(5)); sampleRowKeysSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); @@ -217,14 +219,8 @@ private Builder() { .setRetryableCodes(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE, Code.ABORTED) .setRetrySettings(DEFAULT_RETRY_SETTINGS); - // NOTE: This client enforces client side timestamps, which makes all mutations retryable. - // However, since the base GAPIC client allows for server side timestamps, it is not - // configured to enable retries. So the retry settings have to be defined here instead of - // being copied from the BigtableStubSettings. mutateRowSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); - mutateRowSettings - .setRetryableCodes(DEFAULT_RETRY_CODES) - .setRetrySettings(DEFAULT_RETRY_SETTINGS); + copyRetrySettings(baseDefaults.mutateRowSettings(), mutateRowSettings); /* TODO: copy retryCodes & retrySettings from baseSettings.mutateRows once it exists in GAPIC */ mutateRowsSettings = diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableCallableFactory.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableCallableFactory.java new file mode 100644 index 000000000000..88cd02be55b3 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Bigtable API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcBigtableCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableStub.java index 71c5ca012855..62ebc399222c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableStub.java @@ -19,8 +19,9 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.v2.CheckAndMutateRowRequest; @@ -35,9 +36,11 @@ import com.google.bigtable.v2.ReadRowsResponse; import com.google.bigtable.v2.SampleRowKeysRequest; import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.common.collect.ImmutableMap; import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; import java.io.IOException; +import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -118,6 +121,8 @@ public class GrpcBigtableStub extends BigtableStub { private final UnaryCallable readModifyWriteRowCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcBigtableStub create(BigtableStubSettings settings) throws IOException { return new GrpcBigtableStub(settings, ClientContext.create(settings)); } @@ -126,59 +131,132 @@ public static final GrpcBigtableStub create(ClientContext clientContext) throws return new GrpcBigtableStub(BigtableStubSettings.newBuilder().build(), clientContext); } + public static final GrpcBigtableStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcBigtableStub( + BigtableStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcBigtableStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcBigtableStub(BigtableStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcBigtableCallableFactory()); + } + + /** + * Constructs an instance of GrpcBigtableStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcBigtableStub( + BigtableStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings readRowsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(readRowsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ReadRowsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("table_name", String.valueOf(request.getTableName())); + return params.build(); + } + }) .build(); GrpcCallSettings sampleRowKeysTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(sampleRowKeysMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(SampleRowKeysRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("table_name", String.valueOf(request.getTableName())); + return params.build(); + } + }) .build(); GrpcCallSettings mutateRowTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(mutateRowMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(MutateRowRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("table_name", String.valueOf(request.getTableName())); + return params.build(); + } + }) .build(); GrpcCallSettings mutateRowsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(mutateRowsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(MutateRowsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("table_name", String.valueOf(request.getTableName())); + return params.build(); + } + }) .build(); GrpcCallSettings checkAndMutateRowTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(checkAndMutateRowMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CheckAndMutateRowRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("table_name", String.valueOf(request.getTableName())); + return params.build(); + } + }) .build(); GrpcCallSettings readModifyWriteRowTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(readModifyWriteRowMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ReadModifyWriteRowRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("table_name", String.valueOf(request.getTableName())); + return params.build(); + } + }) .build(); this.readRowsCallable = - GrpcCallableFactory.createServerStreamingCallable( + callableFactory.createServerStreamingCallable( readRowsTransportSettings, settings.readRowsSettings(), clientContext); this.sampleRowKeysCallable = - GrpcCallableFactory.createServerStreamingCallable( + callableFactory.createServerStreamingCallable( sampleRowKeysTransportSettings, settings.sampleRowKeysSettings(), clientContext); this.mutateRowCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( mutateRowTransportSettings, settings.mutateRowSettings(), clientContext); this.mutateRowsCallable = - GrpcCallableFactory.createServerStreamingCallable( + callableFactory.createServerStreamingCallable( mutateRowsTransportSettings, settings.mutateRowsSettings(), clientContext); this.checkAndMutateRowCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( checkAndMutateRowTransportSettings, settings.checkAndMutateRowSettings(), clientContext); this.readModifyWriteRowCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( readModifyWriteRowTransportSettings, settings.readModifyWriteRowSettings(), clientContext); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java new file mode 100644 index 000000000000..1023e9ad7d3b --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java @@ -0,0 +1,330 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.stub.mutaterows; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.api.gax.retrying.RetryingFuture; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsRequest.Builder; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.bigtable.v2.MutateRowsResponse.Entry; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation; +import com.google.cloud.bigtable.gaxx.retrying.NonCancellableFuture; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.rpc.Code; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +// TODO: Try to generalize this using a BatchingDescriptor +/** + * A stateful {@link Callable} that can be used with gax's {@link + * com.google.api.gax.retrying.RetryingExecutor} and {@link RetryingFuture}. + * + *

    For every {@link #call()}, it will: + * + *

      + *
    • Send the current request to the {@link #innerCallable} + *
    • On RPC completion it will inspect the response. If any entries failed (including the whole + * RPC), it will update its internal state so that the next {@link #call()} will only contain + * entries that have transient failures. + *
    + * + *

    Expected usage: + * + *

    {@code
    + * MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(
    + *   stub.mutateRowsCallable().all(),
    + *   request,
    + *   clientContext.getDefaultCallContext(),
    + *   ImmutableSet.of(Code.UNAVAILABLE));
    + *
    + * RetryingExecutor retryingExecutor = ...;
    + * RetryingFuture retryingFuture = retryingExecutor.createFuture(attemptCallable);
    + * retryCallable.setExternalFuture(retryingFuture);
    + * retryCallable.call();
    + *
    + * try {
    + *   retryingFuture.get();
    + * } catch(ExecutionException executionError) {
    + *   MutateRowsException e = (MutateRowsException) executionError.getCause();
    + *
    + *   for (FailedMutation m : e.getFailedMutations() {
    + *     // handle permanent failures
    + *   }
    + * }
    + * }
    + * + *

    Package-private for internal use. + */ +class MutateRowsAttemptCallable implements Callable { + // Synthetic status for Mutations that didn't get a result (because the whole RPC failed). It will + // be exposed in MutateRowsException's FailedMutations. + private static final StatusCode LOCAL_UNKNOWN_STATUS = + new StatusCode() { + @Override + public Code getCode() { + return Code.UNKNOWN; + } + + @Override + public Object getTransportCode() { + return null; + } + }; + + // Everything needed to issue an RPC + private final UnaryCallable> innerCallable; + private final ApiCallContext callContext; + private MutateRowsRequest currentRequest; + + // Everything needed to build a retry request + private List originalIndexes; + private final Set retryableCodes; + private final List permanentFailures; + + // Parent controller + private RetryingFuture externalFuture; + + // Simple wrappers for handling result futures + private final ApiFunction, Void> attemptSuccessfulCallback = + new ApiFunction, Void>() { + @Override + public Void apply(List responses) { + handleAttemptSuccess(responses); + return null; + } + }; + + private final ApiFunction> attemptFailedCallback = + new ApiFunction>() { + @Override + public List apply(Throwable throwable) { + handleAttemptError(throwable); + return null; + } + }; + + MutateRowsAttemptCallable( + @Nonnull UnaryCallable> innerCallable, + @Nonnull MutateRowsRequest originalRequest, + @Nullable ApiCallContext callContext, + @Nonnull Set retryableCodes) { + this.innerCallable = Preconditions.checkNotNull(innerCallable); + this.currentRequest = Preconditions.checkNotNull(originalRequest); + this.callContext = callContext; + this.retryableCodes = Preconditions.checkNotNull(retryableCodes); + + permanentFailures = Lists.newArrayList(); + } + + public void setExternalFuture(RetryingFuture externalFuture) { + this.externalFuture = externalFuture; + } + + /** + * Send the current request and the parent {@link RetryingFuture} with this attempt's future. + * + *

    On RPC completion this method will preprocess all errors (both RPC level and entry level) + * and wrap them in a {@link MutateRowsException}. Please note that the results of the RPC are + * only available in the attempt future that is set on the parent {@link RetryingFuture} and the + * return of this method should just be ignored. + */ + @Override + public Void call() { + try { + Preconditions.checkNotNull( + externalFuture, "External future must be set before starting an attempt"); + + Preconditions.checkState( + currentRequest.getEntriesCount() > 0, "Request doesn't have any mutations to send"); + + // Configure the deadline + ApiCallContext currentCallContext = null; + if (callContext != null) { + currentCallContext = + callContext.withTimeout(externalFuture.getAttemptSettings().getRpcTimeout()); + } + + // Handle concurrent cancellation + externalFuture.setAttemptFuture(new NonCancellableFuture()); + if (externalFuture.isDone()) { + return null; + } + + // Make the actual call + ApiFuture> innerFuture = + innerCallable.futureCall(currentRequest, currentCallContext); + + // Handle RPC level errors by wrapping them in a MutateRowsException + ApiFuture> catching = + ApiFutures.catching(innerFuture, Throwable.class, attemptFailedCallback); + + // Inspect the results and either propagate the success, or prepare to retry the failed + // mutations + ApiFuture transformed = ApiFutures.transform(catching, attemptSuccessfulCallback); + + // Notify the parent of the attempt + externalFuture.setAttemptFuture(transformed); + } catch (Throwable e) { + externalFuture.setAttemptFuture(ApiFutures.immediateFailedFuture(e)); + } + + return null; + } + + /** + * Handle an RPC level failure by generating a {@link FailedMutation} for each expected entry. The + * newly generated {@link FailedMutation}s will be combined with the permanentFailures to give the + * caller the whole picture since the first call. This method will always throw a {@link + * MutateRowsException}. + */ + private void handleAttemptError(Throwable rpcError) { + ApiException entryError = createSyntheticErrorForRpcFailure(rpcError); + ImmutableList.Builder allFailures = ImmutableList.builder(); + MutateRowsRequest lastRequest = currentRequest; + + allFailures.addAll(permanentFailures); + + Builder builder = lastRequest.toBuilder().clearEntries(); + List newOriginalIndexes = Lists.newArrayList(); + + for (int i = 0; i < currentRequest.getEntriesCount(); i++) { + int origIndex = getOriginalIndex(i); + + FailedMutation failedMutation = FailedMutation.create(origIndex, entryError); + allFailures.add(failedMutation); + + if (!failedMutation.getError().isRetryable()) { + permanentFailures.add(failedMutation); + } else { + // Schedule the mutation entry for the next RPC by adding it to the request builder and + // recording its original index + newOriginalIndexes.add(origIndex); + builder.addEntries(lastRequest.getEntries(i)); + } + } + + currentRequest = builder.build(); + originalIndexes = newOriginalIndexes; + + throw new MutateRowsException(rpcError, allFailures.build(), entryError.isRetryable()); + } + + /** + * Handle entry level failures. All new response entries are inspected for failure. If any + * transient failures are found, their corresponding mutations are scheduled for the next RPC. The + * caller is notified of both new found errors and pre-existing permanent errors in the thrown + * {@link MutateRowsException}. If no errors exist, then the attempt future is successfully + * completed. + */ + private void handleAttemptSuccess(List responses) { + List allFailures = Lists.newArrayList(permanentFailures); + MutateRowsRequest lastRequest = currentRequest; + + Builder builder = lastRequest.toBuilder().clearEntries(); + List newOriginalIndexes = Lists.newArrayList(); + + for (MutateRowsResponse response : responses) { + for (Entry entry : response.getEntriesList()) { + if (entry.getStatus().getCode() == Code.OK_VALUE) { + continue; + } + + int origIndex = getOriginalIndex((int) entry.getIndex()); + + FailedMutation failedMutation = + FailedMutation.create(origIndex, createEntryError(entry.getStatus())); + + allFailures.add(failedMutation); + + if (!failedMutation.getError().isRetryable()) { + permanentFailures.add(failedMutation); + } else { + // Schedule the mutation entry for the next RPC by adding it to the request builder and + // recording it's original index + newOriginalIndexes.add(origIndex); + builder.addEntries(lastRequest.getEntries((int) entry.getIndex())); + } + } + } + + currentRequest = builder.build(); + originalIndexes = newOriginalIndexes; + + if (!allFailures.isEmpty()) { + boolean isRetryable = builder.getEntriesCount() > 0; + throw new MutateRowsException(null, allFailures, isRetryable); + } + } + + /** + * Remap the entry index in the current attempt back to its original index in the first request. + */ + private int getOriginalIndex(int index) { + return (originalIndexes != null) ? originalIndexes.get(index) : index; + } + + /** Convert an entry's status from a protobuf to an {@link ApiException}. */ + private ApiException createEntryError(com.google.rpc.Status protoStatus) { + io.grpc.Status grpcStatus = + io.grpc.Status.fromCodeValue(protoStatus.getCode()) + .withDescription(protoStatus.getMessage()); + + StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode()); + + return ApiExceptionFactory.createException( + grpcStatus.asRuntimeException(), + gaxStatusCode, + retryableCodes.contains(gaxStatusCode.getCode())); + } + + /** + * Create a synthetic {@link ApiException} for an individual entry. When the entire RPC fails, it + * implies that all entries failed as well. This helper is used to make that behavior explicit. + * The generated exception will have the overall error as its cause. + */ + private static ApiException createSyntheticErrorForRpcFailure(Throwable overallRequestError) { + if (overallRequestError instanceof ApiException) { + ApiException requestApiException = (ApiException) overallRequestError; + + return ApiExceptionFactory.createException( + "Didn't receive a result for this mutation entry", + overallRequestError, + requestApiException.getStatusCode(), + requestApiException.isRetryable()); + } + + return ApiExceptionFactory.createException( + "Didn't receive a result for this mutation entry", + overallRequestError, + LOCAL_UNKNOWN_STATUS, + false); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java index cab22ffa95b2..f9979d84d0e8 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java @@ -18,52 +18,28 @@ import com.google.api.core.InternalApi; import com.google.api.gax.batching.PartitionKey; import com.google.api.gax.batching.RequestBuilder; -import com.google.api.gax.grpc.GrpcStatusCode; import com.google.api.gax.rpc.ApiException; -import com.google.api.gax.rpc.ApiExceptionFactory; import com.google.api.gax.rpc.BatchedRequestIssuer; import com.google.api.gax.rpc.BatchingDescriptor; -import com.google.api.gax.rpc.StatusCode; import com.google.bigtable.v2.MutateRowsRequest; -import com.google.bigtable.v2.MutateRowsResponse; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import com.google.common.primitives.Ints; -import com.google.rpc.Code; -import com.google.rpc.Status; -import io.grpc.StatusException; -import io.grpc.StatusRuntimeException; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation; +import com.google.common.base.Function; +import com.google.common.collect.Maps; import java.util.Collection; -import java.util.Set; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; /** - * A custom implementation of a {@link BatchingDescriptor} to split individual results of a bulk - * MutateRowsResponse. Each individual result will be matched with its issuer. Since the embedded - * results bypass gax's result processing chains, this class is responsible for wrapping errors in - * {@link ApiException}s and marking each error as retryable. + * A custom implementation of a {@link BatchingDescriptor} to split individual results in a {@link + * MutateRowsException}. Each individual result will be matched with its issuer. * *

    This class is considered an internal implementation detail and not meant to be used by * applications directly. */ @InternalApi -public class MutateRowsBatchingDescriptor - implements BatchingDescriptor { - - // Shared response to notify individual issuers of a successful mutation. - private static final MutateRowsResponse OK_RESPONSE = - MutateRowsResponse.newBuilder() - .addEntries( - MutateRowsResponse.Entry.newBuilder() - .setIndex(0) - .setStatus(Status.newBuilder().setCode(Code.OK_VALUE))) - .build(); - - private final ImmutableSet retryableCodes; - - public MutateRowsBatchingDescriptor(Set retryableCodes) { - this.retryableCodes = ImmutableSet.copyOf(retryableCodes); - } - +public class MutateRowsBatchingDescriptor implements BatchingDescriptor { /** Return the target table name. This will be used to combine batcheable requests */ @Override public PartitionKey getBatchPartitionKey(MutateRowsRequest request) { @@ -76,44 +52,58 @@ public RequestBuilder getRequestBuilder() { return new MyRequestBuilder(); } - /** {@inheritDoc} */ @Override public void splitResponse( - MutateRowsResponse batchResponse, - Collection> batch) { - - // Sort the result entries by index. - Status[] sortedEntries = new Status[batchResponse.getEntriesCount()]; + Void batchResponse, Collection> batch) { - for (MutateRowsResponse.Entry entry : batchResponse.getEntriesList()) { - int index = Ints.checkedCast(entry.getIndex()); - Preconditions.checkState( - sortedEntries[index] == null, "Got multiple results for the same sub-mutation"); - sortedEntries[index] = entry.getStatus(); + for (BatchedRequestIssuer issuer : batch) { + issuer.setResponse(null); } + } - // Notify all of issuers of the corresponding result. - int i = 0; - for (BatchedRequestIssuer issuer : batch) { - Status entry = sortedEntries[i++]; - Preconditions.checkState(entry != null, "Missing result for entry"); + @Override + public void splitException( + Throwable throwable, Collection> batch) { - if (entry.getCode() == Code.OK_VALUE) { - issuer.setResponse(OK_RESPONSE); - } else { - issuer.setException(createElementException(entry)); + if (!(throwable instanceof MutateRowsException)) { + for (BatchedRequestIssuer issuer : batch) { + issuer.setException(throwable); } + return; } - } - /** {@inheritDoc} */ - @Override - public void splitException( - Throwable throwable, Collection> batch) { - throwable = createElementException(throwable); + List failedMutations = ((MutateRowsException) throwable).getFailedMutations(); + + Map errorsByIndex = + Maps.uniqueIndex( + failedMutations, + new Function() { + @Nullable + @Override + public Integer apply(@Nullable FailedMutation input) { + return input.getIndex(); + } + }); - for (BatchedRequestIssuer responder : batch) { - responder.setException(throwable); + int i = 0; + for (BatchedRequestIssuer issuer : batch) { + // NOTE: the gax batching api doesn't allow for a single issuer to get different exceptions + // for different entries. However this does not affect this client because BulkMutationBatcher + // only allows a single mutation per call. So just use the last error per entry. + ApiException lastError = null; + + for (int j = 0; j < issuer.getMessageCount(); j++) { + FailedMutation failure = errorsByIndex.get(i++); + if (failure != null) { + lastError = failure.getError(); + } + } + + if (lastError == null) { + issuer.setResponse(null); + } else { + issuer.setException(lastError); + } } } @@ -129,38 +119,6 @@ public long countBytes(MutateRowsRequest request) { return request.getSerializedSize(); } - /** Convert an element error Status into an ApiException */ - private ApiException createElementException(Status protoStatus) { - Preconditions.checkArgument(protoStatus.getCode() != Code.OK_VALUE, "OK is not an error"); - - StatusRuntimeException throwable = - io.grpc.Status.fromCodeValue(protoStatus.getCode()) - .withDescription(protoStatus.getMessage()) - .asRuntimeException(); - - return createElementException(throwable); - } - - /** Convert a Throwable into an ApiException, marking it as retryable when appropriate. */ - private ApiException createElementException(Throwable throwable) { - final io.grpc.Status.Code code; - - if (throwable instanceof ApiException) { - return (ApiException) throwable; - } else if (throwable instanceof StatusRuntimeException) { - code = ((StatusRuntimeException) throwable).getStatus().getCode(); - } else if (throwable instanceof StatusException) { - code = ((StatusException) throwable).getStatus().getCode(); - } else { - code = io.grpc.Status.Code.UNKNOWN; - } - - GrpcStatusCode gaxStatusCode = GrpcStatusCode.of(code); - boolean isRetryable = retryableCodes.contains(gaxStatusCode.getCode()); - - return ApiExceptionFactory.createException(throwable, gaxStatusCode, isRetryable); - } - /** A {@link com.google.api.gax.batching.RequestBuilder} that can aggregate MutateRowsRequest */ static class MyRequestBuilder implements RequestBuilder { private MutateRowsRequest.Builder builder; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryingCallable.java new file mode 100644 index 000000000000..ab5b872af962 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsRetryingCallable.java @@ -0,0 +1,76 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.stub.mutaterows; + +import com.google.api.core.InternalApi; +import com.google.api.gax.retrying.RetryingExecutor; +import com.google.api.gax.retrying.RetryingFuture; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StatusCode.Code; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import java.util.Set; +import javax.annotation.Nonnull; + +/** + * A UnaryCallable wrapper around {@link MutateRowsAttemptCallable}. + * + *

    This class is considered an internal implementation detail and not meant to be used by + * applications directly. + * + * @see MutateRowsAttemptCallable for more details. + */ +@InternalApi +public class MutateRowsRetryingCallable extends UnaryCallable { + private final ApiCallContext callContextPrototype; + private final ServerStreamingCallable callable; + private final RetryingExecutor executor; + private final ImmutableSet retryCodes; + + public MutateRowsRetryingCallable( + @Nonnull ApiCallContext callContextPrototype, + @Nonnull ServerStreamingCallable callable, + @Nonnull RetryingExecutor executor, + @Nonnull Set retryCodes) { + this.callContextPrototype = Preconditions.checkNotNull(callContextPrototype); + this.callable = Preconditions.checkNotNull(callable); + this.executor = Preconditions.checkNotNull(executor); + this.retryCodes = ImmutableSet.copyOf(retryCodes); + } + + @Override + public RetryingFuture futureCall(MutateRowsRequest request, ApiCallContext inputContext) { + ApiCallContext context = callContextPrototype.nullToSelf(inputContext); + MutateRowsAttemptCallable retryCallable = + new MutateRowsAttemptCallable(callable.all(), request, context, retryCodes); + + RetryingFuture retryingFuture = executor.createFuture(retryCallable); + retryCallable.setExternalFuture(retryingFuture); + retryCallable.call(); + + return retryingFuture; + } + + @Override + public String toString() { + return String.format("retrying(%s)", callable); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsSpoolingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsSpoolingCallable.java deleted file mode 100644 index 303d274ada4a..000000000000 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsSpoolingCallable.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2018 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.cloud.bigtable.data.v2.stub.mutaterows; - -import com.google.api.core.ApiFunction; -import com.google.api.core.ApiFuture; -import com.google.api.core.ApiFutures; -import com.google.api.core.InternalApi; -import com.google.api.gax.rpc.ApiCallContext; -import com.google.api.gax.rpc.ServerStreamingCallable; -import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.v2.MutateRowsRequest; -import com.google.bigtable.v2.MutateRowsResponse; -import java.util.List; - -/** - * Converts a stream of {@link MutateRowsResponse}s into a unary MutateRowsResponse. This is - * necessary to adapt Cloud Bigtable API to work with gax's batching infrastructure. - * - *

    This class is considered an internal implementation detail and not meant to be used by - * applications. - */ -@InternalApi -public class MutateRowsSpoolingCallable - extends UnaryCallable { - - private final ServerStreamingCallable inner; - - public MutateRowsSpoolingCallable( - ServerStreamingCallable inner) { - this.inner = inner; - } - - @Override - public ApiFuture futureCall( - MutateRowsRequest request, ApiCallContext context) { - ApiFuture> rawResponse = inner.all().futureCall(request, context); - - return ApiFutures.transform( - rawResponse, - new ApiFunction, MutateRowsResponse>() { - @Override - public MutateRowsResponse apply(List input) { - return convertResponse(input); - } - }); - } - - private MutateRowsResponse convertResponse(List responses) { - if (responses.size() == 1) { - return responses.get(0); - } else { - MutateRowsResponse.Builder fullResponseBuilder = MutateRowsResponse.newBuilder(); - for (MutateRowsResponse subResponse : responses) { - fullResponseBuilder.addAllEntries(subResponse.getEntriesList()); - } - return fullResponseBuilder.build(); - } - } -} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsUserFacingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsUserFacingCallable.java index 1d53dd955864..ca9773ac99c8 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsUserFacingCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsUserFacingCallable.java @@ -15,14 +15,11 @@ */ package com.google.cloud.bigtable.data.v2.stub.mutaterows; -import com.google.api.core.ApiFunction; import com.google.api.core.ApiFuture; -import com.google.api.core.ApiFutures; import com.google.api.core.InternalApi; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.v2.MutateRowsRequest; -import com.google.bigtable.v2.MutateRowsResponse; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.models.RowMutation; @@ -34,11 +31,11 @@ */ @InternalApi public class MutateRowsUserFacingCallable extends UnaryCallable { - private final UnaryCallable inner; + private final UnaryCallable inner; private final RequestContext requestContext; public MutateRowsUserFacingCallable( - UnaryCallable inner, RequestContext requestContext) { + UnaryCallable inner, RequestContext requestContext) { this.inner = inner; this.requestContext = requestContext; @@ -46,16 +43,6 @@ public MutateRowsUserFacingCallable( @Override public ApiFuture futureCall(RowMutation request, ApiCallContext context) { - ApiFuture rawResponse = - inner.futureCall(request.toBulkProto(requestContext), context); - - return ApiFutures.transform( - rawResponse, - new ApiFunction() { - @Override - public Void apply(MutateRowsResponse mutateRowsResponse) { - return null; - } - }); + return inner.futureCall(request.toBulkProto(requestContext), context); } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java index dfc1ea1ef5d1..5ec34504cb87 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsResumptionStrategy.java @@ -57,7 +57,7 @@ public StreamResumptionStrategy createNew() { } @Override - public void onProgress(RowT response) { + public RowT processResponse(RowT response) { // Last key can come from both the last processed row key and a synthetic row marker. The // synthetic row marker is emitted when the server has read a lot of data that was filtered out. // The row marker can be used to trim the start of the scan, but does not contribute to the row @@ -67,6 +67,7 @@ public void onProgress(RowT response) { // Only real rows count towards the rows limit. numProcessed++; } + return response; } /** diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/package-info.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/package-info.java index 453a79576b57..e109cc76d4a1 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/package-info.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/package-info.java @@ -13,11 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * General purpose utilities that might be moved to gax at some point in the future. - * - *

    TransportProviderWrapper: Enables the use of crosscutting hacks like - * ResourcePrefixInterceptor. It wraps a GRPC channel provider and decorates the provided channels - * with interceptors. - */ +/** General purpose utilities that might be moved to gax at some point in the future. */ package com.google.cloud.bigtable.gaxx; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/reframing/package-info.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/reframing/package-info.java index 7577ae43e768..db5b7a4238a2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/reframing/package-info.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/reframing/package-info.java @@ -17,7 +17,7 @@ * Mediates message flow between two {@link com.google.api.gax.rpc.ResponseObserver}s. * *

    It is intended for situations when a stream needs to be transformed in such a way where the - * incoming responses do not map 1:1 to the output responses. This is used to convert transform + * incoming responses do not map 1:1 to the output responses. This is used to transform * ReadRowsResponse chunks into logical rows, but is generic enough to be used for other purposes. */ package com.google.cloud.bigtable.gaxx.reframing; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/ApiResultRetryAlgorithm.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/ApiResultRetryAlgorithm.java new file mode 100644 index 000000000000..776208d95026 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/ApiResultRetryAlgorithm.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018 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.cloud.bigtable.gaxx.retrying; + +import com.google.api.gax.retrying.ResultRetryAlgorithm; +import com.google.api.gax.retrying.TimedAttemptSettings; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.DeadlineExceededException; +import org.threeten.bp.Duration; + +public class ApiResultRetryAlgorithm implements ResultRetryAlgorithm { + // Duration to sleep on if the error is DEADLINE_EXCEEDED. + public static final Duration DEADLINE_SLEEP_DURATION = Duration.ofMillis(1); + + @Override + public TimedAttemptSettings createNextAttempt( + Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { + if (prevThrowable != null && prevThrowable instanceof DeadlineExceededException) { + return TimedAttemptSettings.newBuilder() + .setGlobalSettings(prevSettings.getGlobalSettings()) + .setRetryDelay(prevSettings.getRetryDelay()) + .setRpcTimeout(prevSettings.getRpcTimeout()) + .setRandomizedRetryDelay(DEADLINE_SLEEP_DURATION) + .setAttemptCount(prevSettings.getAttemptCount() + 1) + .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) + .build(); + } + return null; + } + + @Override + public boolean shouldRetry(Throwable prevThrowable, ResponseT prevResponse) { + return (prevThrowable instanceof ApiException) && ((ApiException) prevThrowable).isRetryable(); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/NonCancellableFuture.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/NonCancellableFuture.java new file mode 100644 index 000000000000..539695a1c32c --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/NonCancellableFuture.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018 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.cloud.bigtable.gaxx.retrying; + +import com.google.api.core.AbstractApiFuture; +import com.google.api.core.InternalApi; + +// TODO: Remove this class once the gax version becomes public +/** + * A future which cannot be cancelled from the external package. Its a copy of {@link + * com.google.api.gax.retrying.NonCancellableFuture}, which is marked as {@link InternalApi}. + * + *

    For internal use, public for technical reasons. + * + * @param future response type + */ +@InternalApi +public final class NonCancellableFuture extends AbstractApiFuture { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + void cancelPrivately() { + super.cancel(false); + } + + boolean setPrivately(ResponseT value) { + return super.set(value); + } + + boolean setExceptionPrivately(Throwable throwable) { + return super.setException(throwable); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/package-info.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/package-info.java new file mode 100644 index 000000000000..c7013607ab5e --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/package-info.java @@ -0,0 +1,28 @@ +/* + * Copyright 2018 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A client for Cloud Bigtable. + * + *

    This client is composed of two parts: the Data API and the Admin API. The Admin API provides + * direct access to the protobuf based API, while the Data API has a higher level wrapper around the + * raw GRPC stubs. + * + * @see com.google.cloud.bigtable.data.v2.BigtableDataClient For the data client. + * @see com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient For instance instance admin client. + * @see com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient For table admin client. + */ +package com.google.cloud.bigtable; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java index b76ddeda059d..b1820ecd17b4 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java @@ -46,6 +46,7 @@ import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification; import com.google.bigtable.admin.v2.Snapshot; import com.google.bigtable.admin.v2.SnapshotName; +import com.google.bigtable.admin.v2.SnapshotTableRequest; import com.google.bigtable.admin.v2.Table; import com.google.bigtable.admin.v2.TableName; import com.google.common.collect.Lists; @@ -168,7 +169,8 @@ public void createTableFromSnapshotTest() throws Exception { InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); String tableId = "tableId-895419604"; - String sourceSnapshot = "sourceSnapshot-947679896"; + SnapshotName sourceSnapshot = + SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); Table actualResponse = client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get(); @@ -181,7 +183,7 @@ public void createTableFromSnapshotTest() throws Exception { Assert.assertEquals(parent, InstanceName.parse(actualRequest.getParent())); Assert.assertEquals(tableId, actualRequest.getTableId()); - Assert.assertEquals(sourceSnapshot, actualRequest.getSourceSnapshot()); + Assert.assertEquals(sourceSnapshot, SnapshotName.parse(actualRequest.getSourceSnapshot())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -197,7 +199,8 @@ public void createTableFromSnapshotExceptionTest() throws Exception { try { InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); String tableId = "tableId-895419604"; - String sourceSnapshot = "sourceSnapshot-947679896"; + SnapshotName sourceSnapshot = + SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get(); Assert.fail("No exception raised"); @@ -458,15 +461,80 @@ public void checkConsistencyExceptionTest() throws Exception { } } + @Test + @SuppressWarnings("all") + public void snapshotTableTest() throws Exception { + SnapshotName name2 = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); + long dataSizeBytes = 2110122398L; + String description2 = "description2568623279"; + Snapshot expectedResponse = + Snapshot.newBuilder() + .setName(name2.toString()) + .setDataSizeBytes(dataSizeBytes) + .setDescription(description2) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("snapshotTableTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockBigtableTableAdmin.addResponse(resultOperation); + + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); + String description = "description-1724546052"; + + Snapshot actualResponse = + client.snapshotTableAsync(name, cluster, snapshotId, description).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableTableAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SnapshotTableRequest actualRequest = (SnapshotTableRequest) actualRequests.get(0); + + Assert.assertEquals(name, TableName.parse(actualRequest.getName())); + Assert.assertEquals(cluster, ClusterName.parse(actualRequest.getCluster())); + Assert.assertEquals(snapshotId, SnapshotName.parse(actualRequest.getSnapshotId())); + Assert.assertEquals(description, actualRequest.getDescription()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void snapshotTableExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableTableAdmin.addException(exception); + + try { + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + SnapshotName snapshotId = + SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); + String description = "description-1724546052"; + + client.snapshotTableAsync(name, cluster, snapshotId, description).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()); + } + } + @Test @SuppressWarnings("all") public void getSnapshotTest() { - String name2 = "name2-1052831874"; + SnapshotName name2 = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); long dataSizeBytes = 2110122398L; String description = "description-1724546052"; Snapshot expectedResponse = Snapshot.newBuilder() - .setName(name2) + .setName(name2.toString()) .setDataSizeBytes(dataSizeBytes) .setDescription(description) .build(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java index 2672a858b101..eb7f086de71d 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java @@ -24,9 +24,13 @@ import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.ReadRowsRequest; +import com.google.bigtable.v2.RowSet; +import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.models.BulkMutationBatcher; import com.google.cloud.bigtable.data.v2.models.BulkMutationBatcher.BulkMutationFailure; import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.cloud.bigtable.data.v2.models.KeyOffset; import com.google.cloud.bigtable.data.v2.models.Mutation; import com.google.cloud.bigtable.data.v2.models.Query; @@ -34,12 +38,15 @@ import com.google.cloud.bigtable.data.v2.models.Row; import com.google.cloud.bigtable.data.v2.models.RowMutation; import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub; +import com.google.protobuf.ByteString; import io.grpc.Status.Code; import java.util.List; import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; @@ -48,7 +55,10 @@ @RunWith(MockitoJUnitRunner.class) public class BigtableDataClientTest { @Mock private EnhancedBigtableStub mockStub; - @Mock private ServerStreamingCallable mockReadRowsCallable; + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private ServerStreamingCallable mockReadRowsCallable; + @Mock private UnaryCallable> mockSampleRowKeysCallable; @Mock private UnaryCallable mockMutateRowCallable; @Mock private UnaryCallable mockCheckAndMutateRowCallable; @@ -79,6 +89,44 @@ public void proxyReadRowsCallableTest() { assertThat(bigtableDataClient.readRowsCallable()).isSameAs(mockReadRowsCallable); } + @Test + public void proxyReadRowAsyncTest() { + bigtableDataClient.readRowAsync("fake-table", ByteString.copyFromUtf8("fake-row-key")); + + ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); + Mockito.verify(mockReadRowsCallable.first()).futureCall(requestCaptor.capture()); + + RequestContext ctx = + RequestContext.create(InstanceName.of("fake-project", "fake-instance"), "fake-profile"); + // NOTE: limit(1) is added by the mocked first() call, so it's not tested here + assertThat(requestCaptor.getValue().toProto(ctx)) + .isEqualTo( + ReadRowsRequest.newBuilder() + .setTableName("projects/fake-project/instances/fake-instance/tables/fake-table") + .setAppProfileId("fake-profile") + .setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("fake-row-key"))) + .build()); + } + + @Test + public void proxyReadRowStrAsyncTest() { + bigtableDataClient.readRowAsync("fake-table", "fake-row-key"); + + ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); + Mockito.verify(mockReadRowsCallable.first()).futureCall(requestCaptor.capture()); + + RequestContext ctx = + RequestContext.create(InstanceName.of("fake-project", "fake-instance"), "fake-profile"); + // NOTE: limit(1) is added by the mocked first() call, so it's not tested here + assertThat(requestCaptor.getValue().toProto(ctx)) + .isEqualTo( + ReadRowsRequest.newBuilder() + .setTableName("projects/fake-project/instances/fake-instance/tables/fake-table") + .setAppProfileId("fake-profile") + .setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("fake-row-key"))) + .build()); + } + @Test public void proxyReadRowsSyncTest() { Query query = Query.create("fake-table"); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutationBatcherIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutationBatcherIT.java new file mode 100644 index 000000000000..b0d82d8d9388 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutationBatcherIT.java @@ -0,0 +1,70 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it; + +import com.google.api.gax.rpc.ServerStream; +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import com.google.cloud.bigtable.data.v2.it.env.TestEnvRule; +import com.google.cloud.bigtable.data.v2.models.BulkMutationBatcher; +import com.google.cloud.bigtable.data.v2.models.Query; +import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.RowCell; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import com.google.common.collect.Lists; +import com.google.common.truth.Truth; +import com.google.protobuf.ByteString; +import java.util.List; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class BulkMutationBatcherIT { + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); + + @Test + public void test() throws Exception { + BigtableDataClient client = testEnvRule.env().getDataClient(); + String tableId = testEnvRule.env().getTableName().getTable(); + String family = testEnvRule.env().getFamilyId(); + String rowPrefix = testEnvRule.env().getRowPrefix(); + + try (BulkMutationBatcher batcher = client.newBulkMutationBatcher()) { + for (int i = 0; i < 10; i++) { + batcher.add( + RowMutation.create(tableId, rowPrefix + "-" + i).setCell(family, "q", 10_000, "value")); + } + } + + List expectedRows = Lists.newArrayList(); + for (int i = 0; i < 10; i++) { + expectedRows.add( + Row.create( + ByteString.copyFromUtf8(rowPrefix + "-" + i), + Lists.newArrayList( + RowCell.create( + family, + ByteString.copyFromUtf8("q"), + 10_000, + Lists.newArrayList(), + ByteString.copyFromUtf8("value"))))); + } + ServerStream actualRows = client.readRows(Query.create(tableId).prefix(rowPrefix)); + + Truth.assertThat(actualRows).containsExactlyElementsIn(expectedRows); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/CheckAndMutateIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/CheckAndMutateIT.java new file mode 100644 index 000000000000..2b65517f232d --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/CheckAndMutateIT.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it; + +import static com.google.cloud.bigtable.data.v2.models.Filters.FILTERS; +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.bigtable.data.v2.it.env.TestEnvRule; +import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; +import com.google.cloud.bigtable.data.v2.models.Mutation; +import com.google.cloud.bigtable.data.v2.models.Query; +import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import com.google.protobuf.ByteString; +import java.util.concurrent.TimeUnit; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class CheckAndMutateIT { + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); + + @Test + public void test() throws Exception { + String tableId = testEnvRule.env().getTableName().getTable(); + String rowKey = testEnvRule.env().getRowPrefix(); + String familyId = testEnvRule.env().getFamilyId(); + + testEnvRule + .env() + .getDataClient() + .mutateRowCallable() + .call( + RowMutation.create(tableId, rowKey) + .setCell(familyId, "q1", "val1") + .setCell(familyId, "q2", "val2")); + + testEnvRule + .env() + .getDataClient() + .checkAndMutateRowAsync( + ConditionalRowMutation.create(tableId, rowKey) + .condition(FILTERS.qualifier().exactMatch("q1")) + .then(Mutation.create().setCell(familyId, "q3", "q1"))) + .get(1, TimeUnit.MINUTES); + + Row row = + testEnvRule + .env() + .getDataClient() + .readRowsCallable() + .first() + .call(Query.create(tableId).rowKey(rowKey)); + + assertThat(row.getCells()).hasSize(3); + assertThat(row.getCells().get(2).getValue()).isEqualTo(ByteString.copyFromUtf8("q1")); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/MutateRowIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/MutateRowIT.java new file mode 100644 index 000000000000..4fdfef18e665 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/MutateRowIT.java @@ -0,0 +1,70 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.bigtable.data.v2.it.env.TestEnvRule; +import com.google.cloud.bigtable.data.v2.models.Query; +import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import com.google.protobuf.ByteString; +import java.util.concurrent.TimeUnit; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class MutateRowIT { + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); + + @Test + public void test() throws Exception { + String rowKey = testEnvRule.env().getRowPrefix() + "testA"; + String familyId = testEnvRule.env().getFamilyId(); + + testEnvRule + .env() + .getDataClient() + .mutateRowAsync( + RowMutation.create(testEnvRule.env().getTableName().getTable(), rowKey) + .setCell(familyId, "q", "myVal") + .setCell(familyId, "q2", "myVal2") + .setCell(familyId, "q3", "myVal3")) + .get(1, TimeUnit.MINUTES); + + testEnvRule + .env() + .getDataClient() + .mutateRowAsync( + RowMutation.create(testEnvRule.env().getTableName().getTable(), rowKey) + .deleteCells(familyId, "q2")) + .get(1, TimeUnit.MINUTES); + + Row row = + testEnvRule + .env() + .getDataClient() + .readRowsCallable() + .first() + .call(Query.create(testEnvRule.env().getTableName().getTable()).rowKey(rowKey)); + + assertThat(row.getCells()).hasSize(2); + assertThat(row.getCells().get(0).getValue()).isEqualTo(ByteString.copyFromUtf8("myVal")); + assertThat(row.getCells().get(1).getValue()).isEqualTo(ByteString.copyFromUtf8("myVal3")); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java new file mode 100644 index 000000000000..a4fab6e2ac08 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java @@ -0,0 +1,144 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.core.SettableApiFuture; +import com.google.api.gax.rpc.ResponseObserver; +import com.google.api.gax.rpc.StreamController; +import com.google.cloud.bigtable.data.v2.it.env.TestEnvRule; +import com.google.cloud.bigtable.data.v2.models.Query; +import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.RowCell; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.protobuf.ByteString; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ReadIT { + private String prefix; + + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); + + @Before + public void setUp() { + prefix = testEnvRule.env().getRowPrefix(); + } + + @Test + public void readEmpty() throws Throwable { + String uniqueKey = prefix + "-readEmpty"; + + Query query = Query.create(testEnvRule.env().getTableName().getTable()).rowKey(uniqueKey); + + // Sync + ArrayList rows = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query)); + assertThat(rows).isEmpty(); + + // Async + AccumulatingObserver observer = new AccumulatingObserver(); + testEnvRule.env().getDataClient().readRowsAsync(query, observer); + observer.awaitCompletion(); + assertThat(observer.responses).isEmpty(); + } + + @Test + public void read() throws Throwable { + int numRows = 5; + List expectedRows = Lists.newArrayList(); + String uniqueKey = prefix + "-read"; + + long timestampMicros = System.nanoTime() * 1_000; + + for (int i = 0; i < numRows; i++) { + testEnvRule + .env() + .getDataClient() + .mutateRowCallable() + .call( + RowMutation.create(testEnvRule.env().getTableName().getTable(), uniqueKey + "-" + i) + .setCell(testEnvRule.env().getFamilyId(), "q", timestampMicros, "my-value")); + + expectedRows.add( + Row.create( + ByteString.copyFromUtf8(uniqueKey + "-" + i), + ImmutableList.of( + RowCell.create( + testEnvRule.env().getFamilyId(), + ByteString.copyFromUtf8("q"), + timestampMicros, + ImmutableList.of(), + ByteString.copyFromUtf8("my-value"))))); + } + + // Sync + Query query = + Query.create(testEnvRule.env().getTableName().getTable()) + .range(uniqueKey + "-0", uniqueKey + "-" + numRows); + ArrayList actualResults = + Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query)); + + assertThat(actualResults).containsExactlyElementsIn(expectedRows); + + // Async + AccumulatingObserver observer = new AccumulatingObserver(); + testEnvRule.env().getDataClient().readRowsAsync(query, observer); + observer.awaitCompletion(); + assertThat(observer.responses).containsExactlyElementsIn(expectedRows); + } + + static class AccumulatingObserver implements ResponseObserver { + final List responses = Lists.newArrayList(); + final SettableApiFuture completionFuture = SettableApiFuture.create(); + + void awaitCompletion() throws Throwable { + try { + completionFuture.get(10, TimeUnit.MINUTES); + } catch (ExecutionException e) { + throw e.getCause(); + } + } + + @Override + public void onStart(StreamController controller) {} + + @Override + public void onResponse(Row row) { + responses.add(row); + } + + @Override + public void onError(Throwable t) { + completionFuture.setException(t); + } + + @Override + public void onComplete() { + completionFuture.set(null); + } + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadModifyWriteIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadModifyWriteIT.java new file mode 100644 index 000000000000..296f43e2ddbe --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadModifyWriteIT.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.bigtable.data.v2.it.env.TestEnvRule; +import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; +import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.protobuf.ByteString; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ReadModifyWriteIT { + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); + + @Test + public void test() throws InterruptedException, ExecutionException, TimeoutException { + String tableId = testEnvRule.env().getTableName().getTable(); + String family = testEnvRule.env().getFamilyId(); + String rowKey = testEnvRule.env().getRowPrefix(); + + Row row = + testEnvRule + .env() + .getDataClient() + .readModifyWriteRowAsync( + ReadModifyWriteRow.create(tableId, rowKey) + .append(family, "q1", "a") + .increment(family, "q2", 3)) + .get(1, TimeUnit.MINUTES); + + assertThat(row.getCells()).hasSize(2); + assertThat(row.getCells().get(0).getValue()).isEqualTo(ByteString.copyFromUtf8("a")); + assertThat(row.getCells().get(1).getValue()) + .isEqualTo(ByteString.copyFrom(new byte[] {0, 0, 0, 0, 0, 0, 0, 3})); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/SampleRowsIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/SampleRowsIT.java new file mode 100644 index 000000000000..e77fcdd98a16 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/SampleRowsIT.java @@ -0,0 +1,65 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import com.google.cloud.bigtable.data.v2.it.env.TestEnvRule; +import com.google.cloud.bigtable.data.v2.models.KeyOffset; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import com.google.common.collect.Lists; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class SampleRowsIT { + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); + + @Test + public void test() throws InterruptedException, ExecutionException, TimeoutException { + BigtableDataClient client = testEnvRule.env().getDataClient(); + + // Create some data so that sample row keys has something to show + List> futures = Lists.newArrayList(); + for (int i = 0; i < 10; i++) { + ApiFuture future = + client.mutateRowAsync( + RowMutation.create( + testEnvRule.env().getTableName().getTable(), + testEnvRule.env().getRowPrefix() + "-" + i) + .setCell(testEnvRule.env().getFamilyId(), "", "value")); + futures.add(future); + } + ApiFutures.allAsList(futures).get(1, TimeUnit.MINUTES); + + ApiFuture> future = + client.sampleRowKeysAsync(testEnvRule.env().getTableName().getTable()); + + List results = future.get(1, TimeUnit.MINUTES); + + assertThat(results).isNotEmpty(); + assertThat(results.get(results.size() - 1).getOffsetBytes()).isGreaterThan(0L); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/Emulator.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/Emulator.java new file mode 100644 index 000000000000..476fe8974b51 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/Emulator.java @@ -0,0 +1,231 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it.env; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.FixedTransportChannelProvider; +import com.google.cloud.bigtable.data.v2.models.InstanceName; +import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; +import com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings; +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import com.google.cloud.bigtable.data.v2.BigtableDataSettings; +import com.google.common.io.CharStreams; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** Java wrapper around the gcloud bigtable emulator. */ +// TODO(igorbernstein): Clean this up and externalize this in a separate artifact +// TODO(igorbernstein): Stop depending on gcloud for the binary, instead wrap it in a jar. +class Emulator { + private static final Logger LOGGER = Logger.getLogger(Emulator.class.getName()); + + private final Path executable; + private Process process; + private boolean isStopped = true; + private ManagedChannel channel; + private BigtableTableAdminClient tableAdminClient; + private BigtableDataClient dataClient; + + private static final InstanceName INSTANCE_NAME = + InstanceName.of("fake-project", "fake-instance"); + + // Use the gcloud installed emulator + static Emulator createGCloud() { + final Path gcloudSdkPath; + + try { + gcloudSdkPath = getGcloudSdkPath(); + } catch (Exception e) { + throw new RuntimeException("Failed to get the gcloud SDK path. Is it installed?", e); + } + + Path emulatorPath = + gcloudSdkPath.resolve(Paths.get("platform", "bigtable-emulator", "cbtemulator")); + + if (!Files.exists(emulatorPath)) { + throw new RuntimeException( + "cbtemulator is not installed, please install with `gcloud components install bigtable`"); + } + + return new Emulator(emulatorPath); + } + + private Emulator(Path executable) { + this.executable = executable; + } + + void start() throws Exception { + int availablePort = getAvailablePort(); + + process = Runtime.getRuntime().exec(executable + " -port " + "" + availablePort); + pipeStreamToLog(process.getInputStream(), Level.INFO); + pipeStreamToLog(process.getErrorStream(), Level.WARNING); + isStopped = false; + + waitForPort(availablePort); + + channel = createChannel(availablePort); + + tableAdminClient = + BigtableTableAdminClient.create( + configureClient(BigtableTableAdminSettings.newBuilder()).build()); + + dataClient = + BigtableDataClient.create( + configureClient(BigtableDataSettings.newBuilder().setInstanceName(INSTANCE_NAME)) + .build()); + + Runtime.getRuntime() + .addShutdownHook( + new Thread() { + @Override + public void run() { + if (!isStopped) { + isStopped = true; + process.destroy(); + } + } + }); + } + + void stop() throws Exception { + try { + dataClient.close(); + tableAdminClient.close(); + channel.shutdownNow(); + channel.awaitTermination(1, TimeUnit.MINUTES); + } finally { + isStopped = true; + process.destroy(); + } + } + + BigtableDataClient getDataClient() { + return dataClient; + } + + BigtableTableAdminClient getTableAdminClient() { + return tableAdminClient; + } + + // + private static Path getGcloudSdkPath() throws Exception { + Process p = Runtime.getRuntime().exec("gcloud info --format=value(installation.sdk_root)"); + pipeStreamToLog(p.getErrorStream(), Level.WARNING); + + String sdkRoot = bufferOutput(p.getInputStream()).get(1, TimeUnit.MINUTES).trim(); + + if (p.waitFor() != 0) { + throw new RuntimeException("Failed to get sdk root, is gcloud sdk installed?"); + } + return Paths.get(sdkRoot); + } + + private static int getAvailablePort() { + try (ServerSocket serverSocket = new ServerSocket(0)) { + return serverSocket.getLocalPort(); + } catch (IOException e) { + throw new RuntimeException("Failed to find open port"); + } + } + + private void waitForPort(int port) throws InterruptedException, TimeoutException { + for (int i = 0; i < 100; i++) { + try (Socket ignored = new Socket("localhost", port)) { + return; + } catch (IOException e) { + Thread.sleep(200); + } + } + + throw new TimeoutException("Timed out waiting for server to start"); + } + + private ManagedChannel createChannel(int port) { + // NOTE: usePlaintext is currently @ExperimentalAPI. In grpc 1.11 it be became parameterless. + // In 1.12 it should be stable. See https://github.com/grpc/grpc-java/issues/1772 for discussion + return ManagedChannelBuilder.forAddress("localhost", port) + .usePlaintext(true) + .maxInboundMessageSize(256 * 1024 * 1024) + .build(); + } + + private > T configureClient(T settings) { + settings + .setCredentialsProvider(new NoCredentialsProvider()) + .setTransportChannelProvider( + FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel))); + + return settings; + } + + private static void pipeStreamToLog(final InputStream stream, final Level level) { + final BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + + Thread thread = + new Thread( + new Runnable() { + @Override + public void run() { + try { + String line; + while ((line = reader.readLine()) != null) { + LOGGER.log(level, line); + } + } catch (IOException e) { + LOGGER.log(Level.WARNING, "Failed to read process stream", e); + } + } + }); + thread.setDaemon(true); + thread.start(); + } + + private static Future bufferOutput(final InputStream stream) { + FutureTask task = + new FutureTask<>( + new Callable() { + @Override + public String call() throws Exception { + return CharStreams.toString(new InputStreamReader(stream)); + } + }); + task.run(); + + return task; + } + // +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/EmulatorEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/EmulatorEnv.java new file mode 100644 index 000000000000..4181adc16ce1 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/EmulatorEnv.java @@ -0,0 +1,76 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it.env; + +import com.google.bigtable.admin.v2.ColumnFamily; +import com.google.bigtable.admin.v2.CreateTableRequest; +import com.google.cloud.bigtable.data.v2.models.InstanceName; +import com.google.bigtable.admin.v2.Table; +import com.google.bigtable.v2.TableName; +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import java.io.IOException; +import java.util.concurrent.TimeoutException; + +public class EmulatorEnv implements TestEnv { + private static final InstanceName INSTANCE_NAME = + InstanceName.of("fake-project", "fake-instance"); + private static final String TABLE_ID = "default-table"; + private static final String FAMILY_ID = "cf"; + + private Emulator emulator; + + @Override + public void start() throws Exception { + emulator = Emulator.createGCloud(); + emulator.start(); + + emulator + .getTableAdminClient() + .createTable( + CreateTableRequest.newBuilder() + .setParent(INSTANCE_NAME.toString()) + .setTableId(TABLE_ID) + .setTable( + Table.newBuilder() + .putColumnFamilies(FAMILY_ID, ColumnFamily.getDefaultInstance())) + .build()); + } + + @Override + public void stop() throws Exception { + emulator.stop(); + } + + @Override + public TableName getTableName() { + return TableName.of(INSTANCE_NAME.getProject(), INSTANCE_NAME.getInstance(), TABLE_ID); + } + + @Override + public String getRowPrefix() { + return "fake-"; + } + + @Override + public BigtableDataClient getDataClient() { + return emulator.getDataClient(); + } + + @Override + public String getFamilyId() { + return FAMILY_ID; + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/ProdEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/ProdEnv.java new file mode 100644 index 000000000000..cdd35c9a9b1b --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/ProdEnv.java @@ -0,0 +1,120 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it.env; + +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.gax.rpc.ServerStream; +import com.google.cloud.bigtable.data.v2.models.InstanceName; +import com.google.bigtable.v2.TableName; +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import com.google.cloud.bigtable.data.v2.models.Query; +import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Test environment that uses an existing bigtable table. The table must have a pre-existing family + * {@code cf}. The target table is configured via the system properties: + * + *

      + *
    • {@code bigtable.project} + *
    • {@code bigtable.instance} + *
    • {@code bigtable.table} + *
    + */ +public class ProdEnv implements TestEnv { + private static final String TABLE_PROPERTY_NAME = "bigtable.table"; + + private TableName tableName; + private static final String FAMILY_ID = "cf"; + private String rowPrefix; + + private BigtableDataClient dataClient; + + static ProdEnv fromSystemProperties() { + String tableNameStr = getRequiredProperty(TABLE_PROPERTY_NAME); + TableName tableName = TableName.parse(tableNameStr); + + return new ProdEnv(tableName); + } + + ProdEnv(TableName tableName) { + this.tableName = tableName; + } + + @Override + public void start() throws IOException { + rowPrefix = UUID.randomUUID() + "-"; + dataClient = + BigtableDataClient.create(InstanceName.of(tableName.getProject(), tableName.getInstance())); + } + + @Override + public void stop() throws Exception { + deleteRows(); + dataClient.close(); + } + + @Override + public BigtableDataClient getDataClient() { + return dataClient; + } + + @Override + public TableName getTableName() { + return tableName; + } + + @Override + public String getFamilyId() { + return FAMILY_ID; + } + + @Override + public String getRowPrefix() { + return rowPrefix; + } + + private void deleteRows() throws InterruptedException, ExecutionException, TimeoutException { + Query query = Query.create(tableName.getTable()).prefix(rowPrefix); + + List> futures = Lists.newArrayList(); + ServerStream rows = dataClient.readRows(query); + for (Row row : rows) { + ApiFuture future = + dataClient.mutateRowAsync( + RowMutation.create(tableName.getTable(), row.getKey()).deleteRow()); + futures.add(future); + } + + ApiFutures.allAsList(futures).get(10, TimeUnit.MINUTES); + } + + private static String getRequiredProperty(String prop) { + String value = System.getProperty(prop); + if (value == null || value.isEmpty()) { + throw new RuntimeException("Missing system property: " + prop); + } + return value; + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/TestEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/TestEnv.java new file mode 100644 index 000000000000..ccc4eb7336fe --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/TestEnv.java @@ -0,0 +1,40 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it.env; + +import com.google.bigtable.v2.TableName; +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import java.io.IOException; +import java.util.concurrent.TimeoutException; + +/** + * Defines the interface of a target environment. + * + *

    This allows for integration tests to run against either production or an emulator. + */ +public interface TestEnv { + void start() throws Exception; + + void stop() throws Exception; + + BigtableDataClient getDataClient(); + + TableName getTableName(); + + String getFamilyId(); + + String getRowPrefix(); +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/TestEnvRule.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/TestEnvRule.java new file mode 100644 index 000000000000..06f4c6d3ef54 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/env/TestEnvRule.java @@ -0,0 +1,76 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.it.env; + +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.rules.ExternalResource; + +/** + * Simple JUnit rule to start and stop the target test environment. + * + *

    The environment can be specified via the system property {@code bigtable.env}. The choices + * are: + * + *

      + *
    • {@code emulator}: uses the cbtemulator component that can be installed by gcloud + *
    • {@code prod}: uses a pre-existing production table. The target table is defined using + * system properties listed in {@link ProdEnv} and application default credentials + *
    + * + *

    By default, {@code emulator} will be used + */ +public class TestEnvRule extends ExternalResource { + private static final Logger LOGGER = Logger.getLogger(TestEnvRule.class.getName()); + + private static final String ENV_PROPERTY = "bigtable.env"; + + private TestEnv testEnv; + + @Override + protected void before() throws Throwable { + String env = System.getProperty(ENV_PROPERTY, "emulator"); + + switch (env) { + case "emulator": + testEnv = new EmulatorEnv(); + break; + case "prod": + testEnv = ProdEnv.fromSystemProperties(); + break; + default: + throw new IllegalArgumentException( + String.format( + "Unknown env: %s. Please set the system property %s to either 'emulator' or 'prod'.", + env, ENV_PROPERTY)); + } + testEnv.start(); + } + + @Override + protected void after() { + try { + testEnv.stop(); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Failed to stop the environment", e); + } + testEnv = null; + } + + public TestEnv env() { + return testEnv; + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ConditionalRowMutationTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ConditionalRowMutationTest.java index 1502e0164b1b..d2407c76ec30 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ConditionalRowMutationTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ConditionalRowMutationTest.java @@ -17,7 +17,7 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.CheckAndMutateRowRequest; import com.google.bigtable.v2.Mutation.DeleteFromColumn; import com.google.bigtable.v2.RowFilter; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java index 0c33f19379ba..057ac662f819 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/QueryTest.java @@ -18,7 +18,7 @@ import static com.google.cloud.bigtable.data.v2.models.Filters.FILTERS; import static com.google.common.truth.Truth.assertThat; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.ReadRowsRequest; import com.google.bigtable.v2.ReadRowsRequest.Builder; import com.google.bigtable.v2.RowFilter; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java index c696e3e32989..5c4dfc618205 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java @@ -17,7 +17,7 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.ReadModifyWriteRowRequest; import com.google.bigtable.v2.ReadModifyWriteRule; import com.google.bigtable.v2.TableName; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RowMutationTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RowMutationTest.java index bd6513fd7d7f..416a17c9c8e5 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RowMutationTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/RowMutationTest.java @@ -17,7 +17,7 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.MutateRowRequest; import com.google.bigtable.v2.MutateRowsRequest; import com.google.bigtable.v2.TableName; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CheckAndMutateRowCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CheckAndMutateRowCallableTest.java index 2a0b7af4a7a0..001b02d085be 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CheckAndMutateRowCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CheckAndMutateRowCallableTest.java @@ -23,7 +23,7 @@ import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.NotFoundException; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.CheckAndMutateRowRequest; import com.google.bigtable.v2.CheckAndMutateRowResponse; import com.google.bigtable.v2.Mutation.DeleteFromRow; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java index 4e9e49aacb78..dac9f71bd69e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java @@ -25,7 +25,8 @@ import com.google.api.gax.rpc.ServerStreamingCallSettings; import com.google.api.gax.rpc.StatusCode.Code; import com.google.api.gax.rpc.UnaryCallSettings; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.api.gax.rpc.WatchdogProvider; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; import com.google.cloud.bigtable.data.v2.models.KeyOffset; import com.google.cloud.bigtable.data.v2.models.Query; @@ -62,18 +63,42 @@ public void settingsAreNotLostTest() { String appProfileId = "my-app-profile-id"; String endpoint = "some.other.host:123"; CredentialsProvider credentialsProvider = Mockito.mock(CredentialsProvider.class); + WatchdogProvider watchdogProvider = Mockito.mock(WatchdogProvider.class); + Duration watchdogInterval = Duration.ofSeconds(12); EnhancedBigtableStubSettings.Builder builder = EnhancedBigtableStubSettings.newBuilder() .setInstanceName(instanceName) .setAppProfileId(appProfileId) .setEndpoint(endpoint) - .setCredentialsProvider(credentialsProvider); + .setCredentialsProvider(credentialsProvider) + .setStreamWatchdogProvider(watchdogProvider) + .setStreamWatchdogCheckInterval(watchdogInterval); - verifyBuilder(builder, instanceName, appProfileId, endpoint, credentialsProvider); - verifySettings(builder.build(), instanceName, appProfileId, endpoint, credentialsProvider); verifyBuilder( - builder.build().toBuilder(), instanceName, appProfileId, endpoint, credentialsProvider); + builder, + instanceName, + appProfileId, + endpoint, + credentialsProvider, + watchdogProvider, + watchdogInterval); + verifySettings( + builder.build(), + instanceName, + appProfileId, + endpoint, + credentialsProvider, + watchdogProvider, + watchdogInterval); + verifyBuilder( + builder.build().toBuilder(), + instanceName, + appProfileId, + endpoint, + credentialsProvider, + watchdogProvider, + watchdogInterval); } private void verifyBuilder( @@ -81,11 +106,15 @@ private void verifyBuilder( InstanceName instanceName, String appProfileId, String endpoint, - CredentialsProvider credentialsProvider) { + CredentialsProvider credentialsProvider, + WatchdogProvider watchdogProvider, + Duration watchdogInterval) { assertThat(builder.getInstanceName()).isEqualTo(instanceName); assertThat(builder.getAppProfileId()).isEqualTo(appProfileId); assertThat(builder.getEndpoint()).isEqualTo(endpoint); assertThat(builder.getCredentialsProvider()).isEqualTo(credentialsProvider); + assertThat(builder.getStreamWatchdogProvider()).isSameAs(watchdogProvider); + assertThat(builder.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); } private void verifySettings( @@ -93,11 +122,15 @@ private void verifySettings( InstanceName instanceName, String appProfileId, String endpoint, - CredentialsProvider credentialsProvider) { + CredentialsProvider credentialsProvider, + WatchdogProvider watchdogProvider, + Duration watchdogInterval) { assertThat(settings.getInstanceName()).isEqualTo(instanceName); assertThat(settings.getAppProfileId()).isEqualTo(appProfileId); assertThat(settings.getEndpoint()).isEqualTo(endpoint); assertThat(settings.getCredentialsProvider()).isEqualTo(credentialsProvider); + assertThat(settings.getStreamWatchdogProvider()).isSameAs(watchdogProvider); + assertThat(settings.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); } @Test @@ -132,29 +165,22 @@ public void readRowsIsNotLostTest() { builder .readRowsSettings() - .setTimeoutCheckInterval(Duration.ofSeconds(10)) .setIdleTimeout(Duration.ofMinutes(5)) .setRetryableCodes(Code.ABORTED, Code.DEADLINE_EXCEEDED) .setRetrySettings(retrySettings) .build(); - assertThat(builder.readRowsSettings().getTimeoutCheckInterval()) - .isEqualTo(Duration.ofSeconds(10)); assertThat(builder.readRowsSettings().getIdleTimeout()).isEqualTo(Duration.ofMinutes(5)); assertThat(builder.readRowsSettings().getRetryableCodes()) .containsAllOf(Code.ABORTED, Code.DEADLINE_EXCEEDED); assertThat(builder.readRowsSettings().getRetrySettings()).isEqualTo(retrySettings); - assertThat(builder.build().readRowsSettings().getTimeoutCheckInterval()) - .isEqualTo(Duration.ofSeconds(10)); assertThat(builder.build().readRowsSettings().getIdleTimeout()) .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().readRowsSettings().getRetryableCodes()) .containsAllOf(Code.ABORTED, Code.DEADLINE_EXCEEDED); assertThat(builder.build().readRowsSettings().getRetrySettings()).isEqualTo(retrySettings); - assertThat(builder.build().toBuilder().readRowsSettings().getTimeoutCheckInterval()) - .isEqualTo(Duration.ofSeconds(10)); assertThat(builder.build().toBuilder().readRowsSettings().getIdleTimeout()) .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().toBuilder().readRowsSettings().getRetryableCodes()) @@ -367,9 +393,8 @@ public void checkAndMutateRowSettingsAreSane() { } private void verifyRetrySettingAreSane(Set retryCodes, RetrySettings retrySettings) { - assertThat(retryCodes).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE, Code.ABORTED); + assertThat(retryCodes).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); - assertThat(retrySettings.getMaxAttempts()).isGreaterThan(1); assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java index 3b0784135fdc..fb22f7167097 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/MutateRowCallableTest.java @@ -18,7 +18,7 @@ import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.MutateRowRequest; import com.google.bigtable.v2.MutateRowResponse; import com.google.cloud.bigtable.data.v2.internal.RequestContext; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/ReadModifyWriteRowCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/ReadModifyWriteRowCallableTest.java index 05e11bf0e06b..0b8b912af77b 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/ReadModifyWriteRowCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/ReadModifyWriteRowCallableTest.java @@ -23,7 +23,7 @@ import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.NotFoundException; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.Cell; import com.google.bigtable.v2.Column; import com.google.bigtable.v2.Family; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/ResourceHeaderTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/ResourceHeaderTest.java new file mode 100644 index 000000000000..275e801e4e5f --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/ResourceHeaderTest.java @@ -0,0 +1,136 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.stub; + +import static com.google.common.truth.Truth.assertWithMessage; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.testing.InProcessServer; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.bigtable.v2.BigtableGrpc; +import com.google.bigtable.v2.TableName; +import com.google.cloud.bigtable.data.v2.BigtableDataClient; +import com.google.cloud.bigtable.data.v2.BigtableDataSettings; +import com.google.cloud.bigtable.data.v2.models.BulkMutationBatcher; +import com.google.cloud.bigtable.data.v2.models.BulkMutationBatcher.BulkMutationFailure; +import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; +import com.google.cloud.bigtable.data.v2.models.InstanceName; +import com.google.cloud.bigtable.data.v2.models.Mutation; +import com.google.cloud.bigtable.data.v2.models.Query; +import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import java.util.concurrent.TimeoutException; +import java.util.regex.Pattern; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ResourceHeaderTest { + private static final String NAME = "resource-header-test:123"; + private static final TableName TABLE_NAME = + TableName.of("fake-project", "fake-instance", "fake-table"); + private static final Pattern EXPECTED_HEADER_PATTERN = + Pattern.compile(".*" + TABLE_NAME.toString() + ".*"); + private static final String HEADER_NAME = "x-goog-request-params"; + + private InProcessServer server; + private LocalChannelProvider channelProvider; + private BigtableDataClient client; + + @Before + public void setUp() throws Exception { + server = new InProcessServer<>(new BigtableGrpc.BigtableImplBase() {}, NAME); + server.start(); + channelProvider = LocalChannelProvider.create(NAME); + + BigtableDataSettings.Builder settings = + BigtableDataSettings.newBuilder() + .setInstanceName(InstanceName.of(TABLE_NAME.getProject(), TABLE_NAME.getInstance())) + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()); + + // Force immediate flush + settings + .bulkMutationsSettings() + .setBatchingSettings( + settings + .bulkMutationsSettings() + .getBatchingSettings() + .toBuilder() + .setElementCountThreshold(1L) + .build()); + + client = BigtableDataClient.create(settings.build()); + } + + @After + public void tearDown() throws Exception { + client.close(); + server.stop(); + server.blockUntilShutdown(); + } + + @Test + public void readRowsTest() { + client.readRows(Query.create(TABLE_NAME.getTable())); + verifyHeaderSent(); + } + + @Test + public void sampleRowKeysTest() { + client.sampleRowKeysAsync(TABLE_NAME.getTable()); + verifyHeaderSent(); + } + + @Test + public void mutateRowTest() { + client.mutateRowAsync(RowMutation.create(TABLE_NAME.getTable(), "fake-key").deleteRow()); + verifyHeaderSent(); + } + + @Test + public void mutateRowsTest() throws TimeoutException, InterruptedException { + try (BulkMutationBatcher batcher = client.newBulkMutationBatcher()) { + batcher.add(RowMutation.create(TABLE_NAME.getTable(), "fake-key").deleteRow()); + } catch (BulkMutationFailure e) { + // Ignore the errors: none of the methods are actually implemented + } + verifyHeaderSent(); + } + + @Test + public void checkAndMutateRowTest() { + client.checkAndMutateRowAsync( + ConditionalRowMutation.create(TABLE_NAME.getTable(), "fake-key") + .then(Mutation.create().deleteRow())); + verifyHeaderSent(); + } + + @Test + public void readModifyWriteTest() { + client.readModifyWriteRowAsync( + ReadModifyWriteRow.create(TABLE_NAME.getTable(), "fake-key").increment("cf", "q", 1)); + verifyHeaderSent(); + } + + private void verifyHeaderSent() { + boolean headerSent = channelProvider.isHeaderSent(HEADER_NAME, EXPECTED_HEADER_PATTERN); + assertWithMessage("Header was sent").that(headerSent).isTrue(); + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java index aa0ec3debbd3..145724039e71 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java @@ -23,7 +23,7 @@ import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.NotFoundException; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.SampleRowKeysRequest; import com.google.bigtable.v2.SampleRowKeysResponse; import com.google.cloud.bigtable.data.v2.internal.RequestContext; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/BulkMutateRowsRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/BulkMutateRowsRetryTest.java index a95200260a4a..a5fd4ce810d0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/BulkMutateRowsRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/BulkMutateRowsRetryTest.java @@ -26,7 +26,7 @@ import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.FixedTransportChannelProvider; import com.google.api.gax.rpc.StatusCode; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.BigtableGrpc; import com.google.bigtable.v2.MutateRowsRequest; import com.google.bigtable.v2.MutateRowsRequest.Entry; @@ -110,17 +110,17 @@ public void setUp() throws Exception { } @Test - public void simpleNoErrorsTest() throws Exception { + public void simpleNoErrorsTest() { service.expectations.add(RpcExpectation.create().addEntry("key1", Code.OK)); ApiFuture result = bulkMutations.add(RowMutation.create(TABLE_ID, "key1")); verifyOk(result); - assertThat(service.expectations).isEmpty(); + service.verifyOk(); } @Test - public void batchingNoErrorsTest() throws Exception { + public void batchingNoErrorsTest() { service.expectations.add( RpcExpectation.create().addEntry("key1", Code.OK).addEntry("key2", Code.OK)); @@ -130,22 +130,22 @@ public void batchingNoErrorsTest() throws Exception { verifyOk(result1); verifyOk(result2); - assertThat(service.expectations).isEmpty(); + service.verifyOk(); } @Test - public void fullRequestRetryTest() throws Exception { + public void fullRequestRetryTest() { service.expectations.add(RpcExpectation.create(Code.DEADLINE_EXCEEDED).addEntry("key1", null)); service.expectations.add(RpcExpectation.create().addEntry("key1", Code.OK)); ApiFuture result = bulkMutations.add(RowMutation.create(TABLE_ID, "key1")); verifyOk(result); - assertThat(service.expectations).isEmpty(); + service.verifyOk(); } @Test - public void partialRetryTest() throws Exception { + public void partialRetryTest() { service.expectations.add( RpcExpectation.create().addEntry("key1", Code.DEADLINE_EXCEEDED).addEntry("key2", Code.OK)); service.expectations.add(RpcExpectation.create().addEntry("key1", Code.OK)); @@ -155,11 +155,11 @@ public void partialRetryTest() throws Exception { verifyOk(result1); verifyOk(result2); - assertThat(service.expectations).isEmpty(); + service.verifyOk(); } @Test - public void partialNoRetriesTest() throws Exception { + public void partialNoRetriesTest() { service.expectations.add( RpcExpectation.create().addEntry("key1", Code.INVALID_ARGUMENT).addEntry("key2", Code.OK)); @@ -169,11 +169,11 @@ public void partialNoRetriesTest() throws Exception { verifyError(result1, StatusCode.Code.INVALID_ARGUMENT); verifyOk(result2); - assertThat(service.expectations).isEmpty(); + service.verifyOk(); } @Test - public void partialRetryFailsEventuallyTest() throws Exception { + public void partialRetryFailsEventuallyTest() { // Create a bunch of failures RpcExpectation rpcExpectation = RpcExpectation.create().addEntry("key1", Code.DEADLINE_EXCEEDED); @@ -184,11 +184,11 @@ public void partialRetryFailsEventuallyTest() throws Exception { ApiFuture result1 = bulkMutations.add(RowMutation.create(TABLE_ID, "key1")); verifyError(result1, StatusCode.Code.DEADLINE_EXCEEDED); - assertThat(service.expectations).isEmpty(); + service.verifyOk(); } @Test - public void elementCountTest() throws Exception { + public void elementCountTest() { // First request RpcExpectation rpcExpectation1 = RpcExpectation.create(); int i = 0; @@ -209,7 +209,7 @@ public void elementCountTest() throws Exception { } verifyOk(ApiFutures.allAsList(results)); - assertThat(service.expectations).isEmpty(); + service.verifyOk(); } private void verifyOk(ApiFuture result) { @@ -267,10 +267,26 @@ RpcExpectation addEntry(String key, Code code) { static class TestBigtableService extends BigtableGrpc.BigtableImplBase { Queue expectations = Queues.newArrayDeque(); + private final List errors = Lists.newArrayList(); + + void verifyOk() { + assertThat(expectations).isEmpty(); + assertThat(errors).isEmpty(); + } @Override public void mutateRows( MutateRowsRequest request, StreamObserver responseObserver) { + try { + mutateRowsUnsafe(request, responseObserver); + } catch (Throwable t) { + errors.add(t); + throw t; + } + } + + private void mutateRowsUnsafe( + MutateRowsRequest request, StreamObserver responseObserver) { RpcExpectation expectedRpc = expectations.poll(); // Make sure that this isn't an extra request. diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java new file mode 100644 index 000000000000..ae4397c4db48 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java @@ -0,0 +1,387 @@ +/* + * Copyright 2018 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.cloud.bigtable.data.v2.stub.mutaterows; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.core.AbstractApiFuture; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.gax.grpc.GrpcCallContext; +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.retrying.RetryingFuture; +import com.google.api.gax.retrying.TimedAttemptSettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.StatusCode.Code; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.gax.rpc.UnavailableException; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsRequest.Entry; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.protobuf.ByteString; +import com.google.rpc.Status; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; + +@RunWith(JUnit4.class) +public class MutateRowsAttemptCallableTest { + private static final Status OK_STATUS_PROTO = + Status.newBuilder().setCode(com.google.rpc.Code.OK_VALUE).build(); + + private static final Status TRANSIENT_ERROR_STATUS_PROTO = + Status.newBuilder().setCode(com.google.rpc.Code.UNAVAILABLE_VALUE).build(); + + private static final Status PERMENANT_ERROR_STATUS_PROTO = + Status.newBuilder().setCode(com.google.rpc.Code.INVALID_ARGUMENT_VALUE).build(); + + private MockInnerCallable innerCallable; + private Set retryCodes; + private ApiCallContext callContext; + private MockRetryingFuture parentFuture; + + @Before + public void setUp() { + innerCallable = new MockInnerCallable(); + retryCodes = ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); + callContext = GrpcCallContext.createDefault(); + parentFuture = new MockRetryingFuture(); + } + + @Test + public void singleEntrySuccessTest() throws Exception { + MutateRowsRequest request = + MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).build(); + innerCallable.response.add( + MutateRowsResponse.newBuilder() + .addEntries( + MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)) + .build()); + + MutateRowsAttemptCallable attemptCallable = + new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes); + attemptCallable.setExternalFuture(parentFuture); + attemptCallable.call(); + + // Attempt completed successfully and the useless response has been suppressed + assertThat(parentFuture.attemptFuture.get()).isNull(); + // innerCallable received the request + assertThat(innerCallable.lastRequest).isEqualTo(request); + } + + @Test + public void mixedTest() { + // Setup the request & response + MutateRowsRequest request = + MutateRowsRequest.newBuilder() + .addEntries(Entry.getDefaultInstance()) + .addEntries(Entry.getDefaultInstance()) + .addEntries(Entry.getDefaultInstance()) + .build(); + + innerCallable.response.add( + MutateRowsResponse.newBuilder() + .addEntries( + MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)) + .addEntries( + MutateRowsResponse.Entry.newBuilder() + .setIndex(1) + .setStatus(TRANSIENT_ERROR_STATUS_PROTO)) + .addEntries( + MutateRowsResponse.Entry.newBuilder() + .setIndex(2) + .setStatus(PERMENANT_ERROR_STATUS_PROTO)) + .build()); + + MutateRowsAttemptCallable attemptCallable = + new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes); + attemptCallable.setExternalFuture(parentFuture); + + // Make the only call + attemptCallable.call(); + + // Overall error expectations + Throwable actualError = null; + try { + parentFuture.attemptFuture.get(); + } catch (Throwable t) { + actualError = t.getCause(); + } + + assertThat(actualError).isInstanceOf(MutateRowsException.class); + assertThat(((MutateRowsException) actualError).isRetryable()).isTrue(); + + // Entry expectations + @SuppressWarnings("ConstantConditions") + List failedMutations = ((MutateRowsException) actualError).getFailedMutations(); + assertThat(failedMutations).hasSize(2); + + assertThat(failedMutations.get(0).getIndex()).isEqualTo(1); + assertThat(failedMutations.get(0).getError().getStatusCode().getCode()) + .isEqualTo(Code.UNAVAILABLE); + assertThat(failedMutations.get(0).getError().isRetryable()).isTrue(); + + assertThat(failedMutations.get(1).getIndex()).isEqualTo(2); + assertThat(failedMutations.get(1).getError().getStatusCode().getCode()) + .isEqualTo(Code.INVALID_ARGUMENT); + assertThat(failedMutations.get(1).getError().isRetryable()).isFalse(); + } + + @Test + public void nextAttemptTest() { + // Setup the request & response for the first call + MutateRowsRequest request = + MutateRowsRequest.newBuilder() + .addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("0-ok"))) + .addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("1-unavailable"))) + .addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("2-invalid"))) + .build(); + + innerCallable.response.add( + MutateRowsResponse.newBuilder() + .addEntries( + MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)) + .addEntries( + MutateRowsResponse.Entry.newBuilder() + .setIndex(1) + .setStatus(TRANSIENT_ERROR_STATUS_PROTO)) + .addEntries( + MutateRowsResponse.Entry.newBuilder() + .setIndex(2) + .setStatus(PERMENANT_ERROR_STATUS_PROTO)) + .build()); + + MutateRowsAttemptCallable attemptCallable = + new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes); + attemptCallable.setExternalFuture(parentFuture); + + // Make the first call + attemptCallable.call(); + + // Setup the request & response for the next call + innerCallable.response = + Lists.newArrayList( + MutateRowsResponse.newBuilder() + .addEntries( + MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)) + .build()); + attemptCallable.call(); + + // Make sure that only the entry with the transient error is resubmitted + assertThat(innerCallable.lastRequest.getEntriesCount()).isEqualTo(1); + assertThat(innerCallable.lastRequest.getEntries(0).getRowKey()) + .isEqualTo(ByteString.copyFromUtf8("1-unavailable")); + + // Overall error expectations + Throwable actualError = null; + try { + parentFuture.attemptFuture.get(); + } catch (Throwable t) { + actualError = t.getCause(); + } + assertThat(actualError).isInstanceOf(MutateRowsException.class); + assertThat(((MutateRowsException) actualError).isRetryable()).isFalse(); + + // Entry expectations + @SuppressWarnings("ConstantConditions") + List failedMutations = ((MutateRowsException) actualError).getFailedMutations(); + assertThat(failedMutations).hasSize(1); + + assertThat(failedMutations.get(0).getIndex()).isEqualTo(2); + assertThat(failedMutations.get(0).getError().getStatusCode().getCode()) + .isEqualTo(Code.INVALID_ARGUMENT); + assertThat(failedMutations.get(0).getError().isRetryable()).isFalse(); + } + + @Test + public void rpcRetryableError() { + // Setup the request & response + MutateRowsRequest request = + MutateRowsRequest.newBuilder() + .addEntries(Entry.getDefaultInstance()) + .addEntries(Entry.getDefaultInstance()) + .build(); + + final UnavailableException rpcError = + new UnavailableException( + "fake error", null, GrpcStatusCode.of(io.grpc.Status.Code.UNAVAILABLE), true); + + UnaryCallable> innerCallable = + new UnaryCallable>() { + @Override + public ApiFuture> futureCall( + MutateRowsRequest request, ApiCallContext context) { + return ApiFutures.immediateFailedFuture(rpcError); + } + }; + + // Make the call + MutateRowsAttemptCallable attemptCallable = + new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes); + attemptCallable.setExternalFuture(parentFuture); + attemptCallable.call(); + + // Overall expectations: retryable error + Throwable actualError = null; + try { + parentFuture.attemptFuture.get(); + } catch (Throwable t) { + actualError = t.getCause(); + } + assertThat(actualError).isInstanceOf(MutateRowsException.class); + assertThat(((MutateRowsException) actualError).isRetryable()).isTrue(); + + // Entry expectations: both entries failed with an error whose cause is the rpc error + @SuppressWarnings("ConstantConditions") + List failedMutations = ((MutateRowsException) actualError).getFailedMutations(); + assertThat(failedMutations).hasSize(2); + + assertThat(failedMutations.get(0).getIndex()).isEqualTo(0); + assertThat(failedMutations.get(0).getError().isRetryable()).isTrue(); + assertThat(failedMutations.get(0).getError().getCause()).isEqualTo(rpcError); + + assertThat(failedMutations.get(1).getIndex()).isEqualTo(1); + assertThat(failedMutations.get(1).getError().isRetryable()).isTrue(); + assertThat(failedMutations.get(1).getError().getCause()).isEqualTo(rpcError); + } + + @Test + public void rpcPermanentError() { + // Setup the request & response + MutateRowsRequest request = + MutateRowsRequest.newBuilder() + .addEntries(Entry.getDefaultInstance()) + .addEntries(Entry.getDefaultInstance()) + .build(); + + final UnavailableException rpcError = + new UnavailableException( + "fake error", null, GrpcStatusCode.of(io.grpc.Status.Code.INVALID_ARGUMENT), false); + + UnaryCallable> innerCallable = + new UnaryCallable>() { + @Override + public ApiFuture> futureCall( + MutateRowsRequest request, ApiCallContext context) { + return ApiFutures.immediateFailedFuture(rpcError); + } + }; + + // Make the call + MutateRowsAttemptCallable attemptCallable = + new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes); + attemptCallable.setExternalFuture(parentFuture); + attemptCallable.call(); + + // Overall expectations: retryable error + Throwable actualError = null; + try { + parentFuture.attemptFuture.get(); + } catch (Throwable t) { + actualError = t.getCause(); + } + assertThat(actualError).isInstanceOf(MutateRowsException.class); + assertThat(((MutateRowsException) actualError).isRetryable()).isFalse(); + + // Entry expectations: both entries failed with an error whose cause is the rpc error + @SuppressWarnings("ConstantConditions") + List failedMutations = ((MutateRowsException) actualError).getFailedMutations(); + assertThat(failedMutations).hasSize(2); + + assertThat(failedMutations.get(0).getIndex()).isEqualTo(0); + assertThat(failedMutations.get(0).getError().isRetryable()).isFalse(); + assertThat(failedMutations.get(0).getError().getCause()).isEqualTo(rpcError); + + assertThat(failedMutations.get(1).getIndex()).isEqualTo(1); + assertThat(failedMutations.get(1).getError().isRetryable()).isFalse(); + assertThat(failedMutations.get(1).getError().getCause()).isEqualTo(rpcError); + } + + // + static class MockInnerCallable + extends UnaryCallable> { + List response = Lists.newArrayList(); + MutateRowsRequest lastRequest; + ApiCallContext lastContext; + + @Override + public ApiFuture> futureCall( + MutateRowsRequest request, ApiCallContext context) { + lastRequest = request; + lastContext = context; + + return ApiFutures.immediateFuture(response); + } + } + + static class MockRetryingFuture extends AbstractApiFuture implements RetryingFuture { + ApiFuture attemptFuture; + + final TimedAttemptSettings timedAttemptSettings; + + MockRetryingFuture() { + this(Duration.ofSeconds(5)); + } + + MockRetryingFuture(Duration totalTimeout) { + this.timedAttemptSettings = + TimedAttemptSettings.newBuilder() + .setRpcTimeout(Duration.ofSeconds(1)) + .setRetryDelay(Duration.ZERO) + .setRandomizedRetryDelay(Duration.ZERO) + .setAttemptCount(0) + .setFirstAttemptStartTimeNanos(0) + .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build()) + .build(); + } + + @Override + public void setAttemptFuture(ApiFuture attemptFuture) { + this.attemptFuture = attemptFuture; + } + + @Override + public TimedAttemptSettings getAttemptSettings() { + return timedAttemptSettings; + } + + @Override + public Callable getCallable() { + throw new UnsupportedOperationException("not used"); + } + + @Override + public ApiFuture peekAttemptResult() { + throw new UnsupportedOperationException("not used"); + } + + @Override + public ApiFuture getAttemptResult() { + throw new UnsupportedOperationException("not used"); + } + } + // +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java index 52820eb19e8a..67d4ebf0a0a6 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java @@ -23,21 +23,21 @@ import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.BatchedFuture; import com.google.api.gax.rpc.BatchedRequestIssuer; -import com.google.api.gax.rpc.StatusCode.Code; +import com.google.api.gax.rpc.DeadlineExceededException; +import com.google.api.gax.rpc.UnavailableException; import com.google.bigtable.v2.MutateRowsRequest; import com.google.bigtable.v2.MutateRowsRequest.Entry; import com.google.bigtable.v2.MutateRowsRequest.Entry.Builder; -import com.google.bigtable.v2.MutateRowsResponse; import com.google.bigtable.v2.Mutation; import com.google.bigtable.v2.Mutation.SetCell; import com.google.bigtable.v2.TableName; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException; +import com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; import com.google.protobuf.ByteString; import io.grpc.Status; -import io.grpc.StatusRuntimeException; import java.util.List; -import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -50,14 +50,12 @@ public class MutateRowsBatchingDescriptorTest { private static final TableName TABLE_NAME = TableName.of("fake-project", "fake-instance", "fake-table"); - private static final Set RETRYABLE_CODES = - ImmutableSet.of(Code.UNAVAILABLE, Code.DEADLINE_EXCEEDED, Code.RESOURCE_EXHAUSTED); private MutateRowsBatchingDescriptor descriptor; @Before - public void setUp() throws Exception { - descriptor = new MutateRowsBatchingDescriptor(RETRYABLE_CODES); + public void setUp() { + descriptor = new MutateRowsBatchingDescriptor(); } @Test @@ -106,17 +104,14 @@ public void requestBuilderTest() { } @Test - public void splitExceptionTest() throws TimeoutException, InterruptedException { - BatchedFuture result1 = BatchedFuture.create(); - BatchedRequestIssuer issuer1 = new BatchedRequestIssuer<>(result1, 1); - BatchedFuture result2 = BatchedFuture.create(); - BatchedRequestIssuer issuer2 = new BatchedRequestIssuer<>(result2, 1); - - ImmutableList> issuers = - new ImmutableList.Builder>() - .add(issuer1) - .add(issuer2) - .build(); + public void splitRpcExceptionTest() throws Exception { + BatchedFuture result1 = BatchedFuture.create(); + BatchedRequestIssuer issuer1 = new BatchedRequestIssuer<>(result1, 1); + BatchedFuture result2 = BatchedFuture.create(); + BatchedRequestIssuer issuer2 = new BatchedRequestIssuer<>(result2, 1); + + ImmutableList> issuers = + new ImmutableList.Builder>().add(issuer1).add(issuer2).build(); ApiException serverError = new ApiException(null, GrpcStatusCode.of(Status.Code.UNAVAILABLE), true); @@ -142,74 +137,30 @@ public void splitExceptionTest() throws TimeoutException, InterruptedException { } @Test - public void splitResponseOkTest() - throws InterruptedException, ExecutionException, TimeoutException { - BatchedFuture result1 = BatchedFuture.create(); - BatchedRequestIssuer issuer1 = new BatchedRequestIssuer<>(result1, 1); - BatchedFuture result2 = BatchedFuture.create(); - BatchedRequestIssuer issuer2 = new BatchedRequestIssuer<>(result2, 1); - - List> issuers = - new ImmutableList.Builder>() - .add(issuer1) - .add(issuer2) - .build(); - - MutateRowsResponse.Entry.Builder okEntryBuilder = - MutateRowsResponse.Entry.newBuilder() - .setStatus(com.google.rpc.Status.newBuilder().setCode(com.google.rpc.Code.OK_VALUE)); - - MutateRowsResponse response = - MutateRowsResponse.newBuilder() - .addEntries(okEntryBuilder.setIndex(0).build()) - .addEntries(okEntryBuilder.setIndex(1).build()) - .build(); - - descriptor.splitResponse(response, issuers); - issuer1.sendResult(); - issuer2.sendResult(); - - assertThat(result1.get(1, TimeUnit.SECONDS)) - .isEqualTo( - MutateRowsResponse.newBuilder().addEntries(okEntryBuilder.setIndex(0).build()).build()); + public void splitEntryErrorTest() throws Exception { + BatchedFuture result1 = BatchedFuture.create(); + BatchedRequestIssuer issuer1 = new BatchedRequestIssuer<>(result1, 1); + BatchedFuture result2 = BatchedFuture.create(); + BatchedRequestIssuer issuer2 = new BatchedRequestIssuer<>(result2, 1); + + List> issuers = + new ImmutableList.Builder>().add(issuer1).add(issuer2).build(); + + MutateRowsException serverError = + new MutateRowsException( + null, + Lists.newArrayList( + FailedMutation.create( + 0, + new UnavailableException( + null, GrpcStatusCode.of(Status.Code.UNAVAILABLE), true)), + FailedMutation.create( + 1, + new DeadlineExceededException( + null, GrpcStatusCode.of(Status.Code.DEADLINE_EXCEEDED), true))), + true); - assertThat(result2.get(1, TimeUnit.SECONDS)) - .isEqualTo( - MutateRowsResponse.newBuilder().addEntries(okEntryBuilder.setIndex(0).build()).build()); - } - - @Test - public void splitResponseErrorWrapTest() - throws InterruptedException, ExecutionException, TimeoutException { - MutateRowsResponse batchResponse = - MutateRowsResponse.newBuilder() - .addEntries( - MutateRowsResponse.Entry.newBuilder() - .setIndex(0) - .setStatus( - com.google.rpc.Status.newBuilder() - .setCode(com.google.rpc.Code.DEADLINE_EXCEEDED_VALUE))) - .addEntries( - MutateRowsResponse.Entry.newBuilder() - .setIndex(1) - .setStatus( - com.google.rpc.Status.newBuilder() - .setCode(com.google.rpc.Code.INTERNAL_VALUE))) - .build(); - - BatchedFuture result1 = BatchedFuture.create(); - BatchedRequestIssuer issuer1 = new BatchedRequestIssuer<>(result1, 1); - - BatchedFuture result2 = BatchedFuture.create(); - BatchedRequestIssuer issuer2 = new BatchedRequestIssuer<>(result2, 1); - - List> issuers = - new ImmutableList.Builder>() - .add(issuer1) - .add(issuer2) - .build(); - - descriptor.splitResponse(batchResponse, issuers); + descriptor.splitException(serverError, issuers); issuer1.sendResult(); issuer2.sendResult(); @@ -220,13 +171,7 @@ public void splitResponseErrorWrapTest() } catch (ExecutionException e) { actualError1 = e.getCause(); } - - assertThat(actualError1).isInstanceOf(ApiException.class); - assertThat(((ApiException) actualError1).isRetryable()).isTrue(); - - assertThat(actualError1.getCause()).isInstanceOf(StatusRuntimeException.class); - assertThat(((StatusRuntimeException) actualError1.getCause()).getStatus().getCode()) - .isEqualTo(Status.Code.DEADLINE_EXCEEDED); + assertThat(actualError1).isEqualTo(serverError.getFailedMutations().get(0).getError()); Throwable actualError2 = null; @@ -235,13 +180,27 @@ public void splitResponseErrorWrapTest() } catch (ExecutionException e) { actualError2 = e.getCause(); } + assertThat(actualError2).isEqualTo(serverError.getFailedMutations().get(1).getError()); + } + + @Test + public void splitResponseOkTest() + throws InterruptedException, ExecutionException, TimeoutException { + BatchedFuture result1 = BatchedFuture.create(); + BatchedRequestIssuer issuer1 = new BatchedRequestIssuer<>(result1, 1); + BatchedFuture result2 = BatchedFuture.create(); + BatchedRequestIssuer issuer2 = new BatchedRequestIssuer<>(result2, 1); + + List> issuers = + new ImmutableList.Builder>().add(issuer1).add(issuer2).build(); + + descriptor.splitResponse(null, issuers); + issuer1.sendResult(); + issuer2.sendResult(); - assertThat(actualError2).isInstanceOf(ApiException.class); - assertThat(((ApiException) actualError2).isRetryable()).isFalse(); + assertThat(result1.get(1, TimeUnit.SECONDS)).isEqualTo(null); - assertThat(actualError2.getCause()).isInstanceOf(StatusRuntimeException.class); - assertThat(((StatusRuntimeException) actualError2.getCause()).getStatus().getCode()) - .isEqualTo(Status.Code.INTERNAL); + assertThat(result2.get(1, TimeUnit.SECONDS)).isEqualTo(null); } private static MutateRowsRequest createRequest(int count) { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java index 34cade35b043..bf042c74f3dd 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsFirstCallableTest.java @@ -18,7 +18,7 @@ import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.models.Query; import com.google.cloud.bigtable.data.v2.models.Row; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java index f37975b6c267..38437002507b 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsRetryTest.java @@ -20,7 +20,7 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.rpc.FixedTransportChannelProvider; import com.google.api.gax.rpc.ServerStream; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.BigtableGrpc; import com.google.bigtable.v2.ReadRowsRequest; import com.google.bigtable.v2.ReadRowsResponse; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsUserCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsUserCallableTest.java index 38ab33353f79..d531fbec5b89 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsUserCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsUserCallableTest.java @@ -15,7 +15,7 @@ */ package com.google.cloud.bigtable.data.v2.stub.readrows; -import com.google.bigtable.admin.v2.InstanceName; +import com.google.cloud.bigtable.data.v2.models.InstanceName; import com.google.bigtable.v2.ReadRowsRequest; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.cloud.bigtable.data.v2.models.Query; diff --git a/google-cloud-bom/README.md b/google-cloud-bom/README.md index 3b1492123f0b..279fb4200823 100644 --- a/google-cloud-bom/README.md +++ b/google-cloud-bom/README.md @@ -13,7 +13,7 @@ To use it in Maven, add the following to your POM: com.google.cloud google-cloud-bom - 0.38.0-alpha + 0.43.0-alpha pom import diff --git a/google-cloud-bom/pom.xml b/google-cloud-bom/pom.xml index 0506160c7c03..b6672db43f90 100644 --- a/google-cloud-bom/pom.xml +++ b/google-cloud-bom/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-bom pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT Google Cloud Java BOM https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bom @@ -124,56 +124,57 @@ - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 1.20.1-SNAPSHOT - 1.20.1-SNAPSHOT - 1.20.1-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 1.20.1-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 1.20.1-SNAPSHOT - 1.20.1-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 1.20.1-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 1.20.1-SNAPSHOT - 0.38.1-beta-SNAPSHOT - 1.20.1-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 1.25.1-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 1.25.1-SNAPSHOT + 1.25.1-SNAPSHOT + 1.25.1-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 1.25.1-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 1.25.1-SNAPSHOT + 1.25.1-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 1.25.1-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 1.25.1-SNAPSHOT + 0.43.1-beta-SNAPSHOT + 1.25.1-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT - 1.4.0 - 1.19.0 - 1.19.0 - 0.36.0 - 0.3.0 - 1.2.0 + 1.5.0 + 1.23.0 + 1.23.0 + 0.40.0 + 0.8.0 + 1.7.0 @@ -397,6 +398,16 @@ grpc-google-cloud-dlp-v2beta1 ${generated-proto-beta.version} + + com.google.api.grpc + proto-google-cloud-dlp-v2 + ${generated-proto-beta.version} + + + com.google.api.grpc + grpc-google-cloud-dlp-v2 + ${generated-proto-beta.version} + com.google.cloud google-cloud-dialogflow @@ -707,6 +718,27 @@ ${storage.version} test-jar + + com.google.cloud + google-cloud-texttospeech + ${texttospeech.version} + + + com.google.cloud + google-cloud-texttospeech + ${texttospeech.version} + test-jar + + + com.google.api.grpc + proto-google-cloud-texttospeech-v1beta1 + ${generated-proto-beta.version} + + + com.google.api.grpc + grpc-google-cloud-texttospeech-v1beta1 + ${generated-proto-beta.version} + com.google.cloud google-cloud-trace @@ -780,6 +812,16 @@ grpc-google-cloud-vision-v1p1beta1 ${generated-proto-beta.version} + + com.google.api.grpc + proto-google-cloud-vision-v1p2beta1 + ${generated-proto-ga.version} + + + com.google.api.grpc + grpc-google-cloud-vision-v1p2beta1 + ${generated-proto-ga.version} + com.google.cloud google-cloud-video-intelligence @@ -806,6 +848,11 @@ proto-google-cloud-video-intelligence-v1 ${generated-proto-beta.version} + + com.google.api.grpc + proto-google-cloud-video-intelligence-v1p1beta1 + ${generated-proto-beta.version} + com.google.api.grpc grpc-google-cloud-video-intelligence-v1beta1 @@ -821,6 +868,11 @@ grpc-google-cloud-video-intelligence-v1 ${generated-proto-beta.version} + + com.google.api.grpc + grpc-google-cloud-video-intelligence-v1p1beta1 + ${generated-proto-beta.version} + com.google.api.grpc proto-google-common-protos diff --git a/google-cloud-compute/README.md b/google-cloud-compute/README.md index ecb9f6cd4ac3..4115657cc323 100644 --- a/google-cloud-compute/README.md +++ b/google-cloud-compute/README.md @@ -25,16 +25,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-compute - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-compute:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-compute:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-compute" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-compute" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-compute/pom.xml b/google-cloud-compute/pom.xml index 646e1da09092..cb1f654b6cad 100644 --- a/google-cloud-compute/pom.xml +++ b/google-cloud-compute/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-compute - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Compute https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-compute @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-compute diff --git a/google-cloud-container/README.md b/google-cloud-container/README.md index 25ace2208df0..46c1c51e6d42 100644 --- a/google-cloud-container/README.md +++ b/google-cloud-container/README.md @@ -24,16 +24,16 @@ Add this to your pom.xml file com.google.cloud google-cloud-container - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-container:0.38.0-beta' +compile 'com.google.cloud:google-cloud-container:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-container" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-container" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-container/pom.xml b/google-cloud-container/pom.xml index 80cc49804ecd..ad483b991433 100644 --- a/google-cloud-container/pom.xml +++ b/google-cloud-container/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-container - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Container https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-container @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-container diff --git a/google-cloud-container/src/main/java/com/google/cloud/container/v1/ClusterManagerSettings.java b/google-cloud-container/src/main/java/com/google/cloud/container/v1/ClusterManagerSettings.java index af5b08cf9300..b11a472615b4 100644 --- a/google-cloud-container/src/main/java/com/google/cloud/container/v1/ClusterManagerSettings.java +++ b/google-cloud-container/src/main/java/com/google/cloud/container/v1/ClusterManagerSettings.java @@ -88,7 +88,7 @@ * * ClusterManagerSettings.Builder clusterManagerSettingsBuilder = * ClusterManagerSettings.newBuilder(); - * clusterManagerSettingsBuilder.listClustersSettings().getRetrySettingsBuilder() + * clusterManagerSettingsBuilder.listClustersSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ClusterManagerSettings clusterManagerSettings = clusterManagerSettingsBuilder.build(); * diff --git a/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/ClusterManagerStubSettings.java b/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/ClusterManagerStubSettings.java index 5f85d168312a..684d8d58e842 100644 --- a/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/ClusterManagerStubSettings.java +++ b/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/ClusterManagerStubSettings.java @@ -97,7 +97,7 @@ * * ClusterManagerStubSettings.Builder clusterManagerSettingsBuilder = * ClusterManagerStubSettings.newBuilder(); - * clusterManagerSettingsBuilder.listClustersSettings().getRetrySettingsBuilder() + * clusterManagerSettingsBuilder.listClustersSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ClusterManagerStubSettings clusterManagerSettings = clusterManagerSettingsBuilder.build(); * diff --git a/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/GrpcClusterManagerCallableFactory.java b/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/GrpcClusterManagerCallableFactory.java new file mode 100644 index 000000000000..a8291bbdaf2c --- /dev/null +++ b/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/GrpcClusterManagerCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.container.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.container.v1.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Container Engine API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcClusterManagerCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/GrpcClusterManagerStub.java b/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/GrpcClusterManagerStub.java index 6ce04fc5771f..dd1f19df11b7 100644 --- a/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/GrpcClusterManagerStub.java +++ b/google-cloud-container/src/main/java/com/google/cloud/container/v1/stub/GrpcClusterManagerStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.container.v1.CancelOperationRequest; @@ -376,6 +376,8 @@ public class GrpcClusterManagerStub extends ClusterManagerStub { private final UnaryCallable setNetworkPolicyCallable; private final UnaryCallable setMaintenancePolicyCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcClusterManagerStub create(ClusterManagerStubSettings settings) throws IOException { return new GrpcClusterManagerStub(settings, ClientContext.create(settings)); @@ -387,6 +389,12 @@ public static final GrpcClusterManagerStub create(ClientContext clientContext) ClusterManagerStubSettings.newBuilder().build(), clientContext); } + public static final GrpcClusterManagerStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcClusterManagerStub( + ClusterManagerStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcClusterManagerStub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -394,6 +402,20 @@ public static final GrpcClusterManagerStub create(ClientContext clientContext) */ protected GrpcClusterManagerStub(ClusterManagerStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcClusterManagerCallableFactory()); + } + + /** + * Constructs an instance of GrpcClusterManagerStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcClusterManagerStub( + ClusterManagerStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listClustersTransportSettings = GrpcCallSettings.newBuilder() @@ -521,106 +543,106 @@ protected GrpcClusterManagerStub(ClusterManagerStubSettings settings, ClientCont .build(); this.listClustersCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listClustersTransportSettings, settings.listClustersSettings(), clientContext); this.getClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getClusterTransportSettings, settings.getClusterSettings(), clientContext); this.createClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createClusterTransportSettings, settings.createClusterSettings(), clientContext); this.updateClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateClusterTransportSettings, settings.updateClusterSettings(), clientContext); this.updateNodePoolCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateNodePoolTransportSettings, settings.updateNodePoolSettings(), clientContext); this.setNodePoolAutoscalingCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setNodePoolAutoscalingTransportSettings, settings.setNodePoolAutoscalingSettings(), clientContext); this.setLoggingServiceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setLoggingServiceTransportSettings, settings.setLoggingServiceSettings(), clientContext); this.setMonitoringServiceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setMonitoringServiceTransportSettings, settings.setMonitoringServiceSettings(), clientContext); this.setAddonsConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setAddonsConfigTransportSettings, settings.setAddonsConfigSettings(), clientContext); this.setLocationsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setLocationsTransportSettings, settings.setLocationsSettings(), clientContext); this.updateMasterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateMasterTransportSettings, settings.updateMasterSettings(), clientContext); this.setMasterAuthCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setMasterAuthTransportSettings, settings.setMasterAuthSettings(), clientContext); this.deleteClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteClusterTransportSettings, settings.deleteClusterSettings(), clientContext); this.listOperationsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listOperationsTransportSettings, settings.listOperationsSettings(), clientContext); this.getOperationCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getOperationTransportSettings, settings.getOperationSettings(), clientContext); this.cancelOperationCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( cancelOperationTransportSettings, settings.cancelOperationSettings(), clientContext); this.getServerConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getServerConfigTransportSettings, settings.getServerConfigSettings(), clientContext); this.listNodePoolsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listNodePoolsTransportSettings, settings.listNodePoolsSettings(), clientContext); this.getNodePoolCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getNodePoolTransportSettings, settings.getNodePoolSettings(), clientContext); this.createNodePoolCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createNodePoolTransportSettings, settings.createNodePoolSettings(), clientContext); this.deleteNodePoolCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteNodePoolTransportSettings, settings.deleteNodePoolSettings(), clientContext); this.rollbackNodePoolUpgradeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( rollbackNodePoolUpgradeTransportSettings, settings.rollbackNodePoolUpgradeSettings(), clientContext); this.setNodePoolManagementCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setNodePoolManagementTransportSettings, settings.setNodePoolManagementSettings(), clientContext); this.setLabelsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setLabelsTransportSettings, settings.setLabelsSettings(), clientContext); this.setLegacyAbacCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setLegacyAbacTransportSettings, settings.setLegacyAbacSettings(), clientContext); this.startIPRotationCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( startIPRotationTransportSettings, settings.startIPRotationSettings(), clientContext); this.completeIPRotationCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( completeIPRotationTransportSettings, settings.completeIPRotationSettings(), clientContext); this.setNodePoolSizeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setNodePoolSizeTransportSettings, settings.setNodePoolSizeSettings(), clientContext); this.setNetworkPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setNetworkPolicyTransportSettings, settings.setNetworkPolicySettings(), clientContext); this.setMaintenancePolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setMaintenancePolicyTransportSettings, settings.setMaintenancePolicySettings(), clientContext); diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/ClusterManagerSmokeTest.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/ClusterManagerSmokeTest.java new file mode 100644 index 000000000000..2abb7b4e7807 --- /dev/null +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/ClusterManagerSmokeTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2018 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.cloud.container.v1; + +import com.google.common.base.Preconditions; +import com.google.container.v1.ListClustersResponse; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ClusterManagerSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (ClusterManagerClient client = ClusterManagerClient.create()) { + String projectId2 = projectId; + String zone = "us-central1-a"; + + ListClustersResponse response = client.listClusters(projectId2, zone); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-contrib/README.md b/google-cloud-contrib/README.md index 6d38b07cd30c..dd464f1d2437 100644 --- a/google-cloud-contrib/README.md +++ b/google-cloud-contrib/README.md @@ -26,16 +26,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-contrib - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-contrib:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-contrib:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-contrib" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-contrib" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-contrib/google-cloud-logging-logback/README.md b/google-cloud-contrib/google-cloud-logging-logback/README.md index 13f62da37248..091d3741e44c 100644 --- a/google-cloud-contrib/google-cloud-logging-logback/README.md +++ b/google-cloud-contrib/google-cloud-logging-logback/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-logging-logback - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-logging-logback:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-logging-logback:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-contrib/google-cloud-logging-logback/pom.xml b/google-cloud-contrib/google-cloud-logging-logback/pom.xml index af5906a99a11..f79448a4fe58 100644 --- a/google-cloud-contrib/google-cloud-logging-logback/pom.xml +++ b/google-cloud-contrib/google-cloud-logging-logback/pom.xml @@ -5,7 +5,7 @@ 4.0.0 google-cloud-logging-logback - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Logging Logback Appender https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-contrib/google-cloud-logging-logback @@ -20,7 +20,7 @@ com.google.cloud google-cloud-contrib - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT diff --git a/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java b/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java index 9ac47ae617f4..8124754055c1 100644 --- a/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java +++ b/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java @@ -67,12 +67,14 @@ public class LoggingAppender extends UnsynchronizedAppenderBase { private volatile Logging logging; private List loggingEnhancers; + private List loggingEventEnhancers; private WriteOption[] defaultWriteOptions; private Level flushLevel; private String log; private String resourceType; private Set enhancerClassNames = new HashSet<>(); + private Set loggingEventEnhancerClassNames = new HashSet<>(); /** * Batched logging requests get immediately flushed for logs at or above this level. @@ -114,6 +116,11 @@ public void setResourceType(String resourceType) { public void addEnhancer(String enhancerClassName) { this.enhancerClassNames.add(enhancerClassName); } + + public void addLoggingEventEnhancer(String enhancerClassName) { + this.loggingEventEnhancerClassNames.add(enhancerClassName); + } + Level getFlushLevel() { return (flushLevel != null) ? flushLevel : Level.ERROR; @@ -128,11 +135,19 @@ MonitoredResource getMonitoredResource(String projectId) { } List getLoggingEnhancers() { - List loggingEnhancers = new ArrayList<>(); - if (enhancerClassNames != null) { - for (String enhancerClassName : enhancerClassNames) { + return getEnhancers(enhancerClassNames); + } + + List getLoggingEventEnhancers() { + return getEnhancers(loggingEventEnhancerClassNames); + } + + List getEnhancers(Set classNames) { + List loggingEnhancers = new ArrayList<>(); + if (classNames != null) { + for (String enhancerClassName : classNames) { if (enhancerClassName != null) { - LoggingEnhancer enhancer = getEnhancer(enhancerClassName); + T enhancer = getEnhancer(enhancerClassName); if (enhancer != null) { loggingEnhancers.add(enhancer); } @@ -142,10 +157,10 @@ List getLoggingEnhancers() { return loggingEnhancers; } - private LoggingEnhancer getEnhancer(String enhancerClassName) { + private T getEnhancer(String enhancerClassName) { try { - Class clz = - (Class) + Class clz = + (Class) Loader.loadClass(enhancerClassName.trim()); return clz.newInstance(); } catch (Exception ex) { @@ -170,6 +185,9 @@ public synchronized void start() { List resourceEnhancers = MonitoredResourceUtil.getResourceEnhancers(); loggingEnhancers.addAll(resourceEnhancers); loggingEnhancers.addAll(getLoggingEnhancers()); + loggingEventEnhancers = new ArrayList<>(); + loggingEventEnhancers.addAll(getLoggingEventEnhancers()); + super.start(); } @@ -227,6 +245,12 @@ private LogEntry logEntryFor(ILoggingEvent e) { } } + if (loggingEventEnhancers != null) { + for (LoggingEventEnhancer enhancer : loggingEventEnhancers) { + enhancer.enhanceLogEntry(builder, e); + } + } + return builder.build(); } diff --git a/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingEventEnhancer.java b/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingEventEnhancer.java new file mode 100644 index 000000000000..53aa518b4bb0 --- /dev/null +++ b/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingEventEnhancer.java @@ -0,0 +1,29 @@ +/* + * Copyright 2017 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.logging.logback; + +import com.google.cloud.logging.LogEntry; + +import ch.qos.logback.classic.spi.ILoggingEvent; + +/** + * An enhancer for {@linkplain ILoggingEvent} log entries. + * Used to add custom labels to the {@link LogEntry.Builder}. + */ +public interface LoggingEventEnhancer { + void enhanceLogEntry(LogEntry.Builder builder, ILoggingEvent e); +} diff --git a/google-cloud-contrib/google-cloud-nio-examples/README.md b/google-cloud-contrib/google-cloud-nio-examples/README.md index 9fcd05da76c2..7d3d83399cff 100644 --- a/google-cloud-contrib/google-cloud-nio-examples/README.md +++ b/google-cloud-contrib/google-cloud-nio-examples/README.md @@ -23,12 +23,12 @@ To run this example: [//]: # ({x-version-update-start:google-cloud-nio:current}) ``` - java -cp google-cloud-contrib/google-cloud-nio/target/google-cloud-nio-0.38.1-alpha-SNAPSHOT.jar:google-cloud-contrib/google-cloud-nio-examples/target/google-cloud-nio-examples-0.38.1-alpha-SNAPSHOT.jar com.google.cloud.nio.examples.ListFilesystems + java -cp google-cloud-contrib/google-cloud-nio/target/google-cloud-nio-0.43.1-alpha-SNAPSHOT.jar:google-cloud-contrib/google-cloud-nio-examples/target/google-cloud-nio-examples-0.43.1-alpha-SNAPSHOT.jar com.google.cloud.nio.examples.ListFilesystems ``` Notice that it lists Google Cloud Storage, which it wouldn't if you ran it without the NIO jar: ``` - java -cp google-cloud-contrib/google-cloud-nio-examples/target/google-cloud-nio-examples-0.38.1-alpha-SNAPSHOT.jar com.google.cloud.nio.examples.ListFilesystems + java -cp google-cloud-contrib/google-cloud-nio-examples/target/google-cloud-nio-examples-0.43.1-alpha-SNAPSHOT.jar com.google.cloud.nio.examples.ListFilesystems ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-contrib/google-cloud-nio-examples/pom.xml b/google-cloud-contrib/google-cloud-nio-examples/pom.xml index 86578dc47ef0..36f29b3c0270 100644 --- a/google-cloud-contrib/google-cloud-nio-examples/pom.xml +++ b/google-cloud-contrib/google-cloud-nio-examples/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-nio-examples - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud NIO Examples https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-contrib/google-cloud-nio-examples @@ -12,7 +12,7 @@ com.google.cloud google-cloud-contrib - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-nio-examples diff --git a/google-cloud-contrib/google-cloud-nio/README.md b/google-cloud-contrib/google-cloud-nio/README.md index 6b060ecb3519..9789d8227c20 100644 --- a/google-cloud-contrib/google-cloud-nio/README.md +++ b/google-cloud-contrib/google-cloud-nio/README.md @@ -28,16 +28,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-nio - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-nio:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-nio:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-nio" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-nio" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-contrib/google-cloud-nio/pom.xml b/google-cloud-contrib/google-cloud-nio/pom.xml index c242ff75dae5..13b4c989a5ef 100644 --- a/google-cloud-contrib/google-cloud-nio/pom.xml +++ b/google-cloud-contrib/google-cloud-nio/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-nio - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud NIO https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-contrib/google-cloud-nio @@ -12,7 +12,7 @@ com.google.cloud google-cloud-contrib - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-nio diff --git a/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcher.java b/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcher.java new file mode 100644 index 000000000000..e52c917d178b --- /dev/null +++ b/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcher.java @@ -0,0 +1,545 @@ +/* + * Copyright 2018 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.storage.contrib.nio; + +import com.google.common.base.Preconditions; +import com.google.common.base.Stopwatch; + +import java.io.Closeable; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.NonWritableChannelException; +import java.nio.channels.SeekableByteChannel; +import java.util.ArrayList; +import java.util.List; +import java.util.UnknownFormatConversionException; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; + + +/** + * SeekableByteChannelPrefetcher wraps an existing SeekableByteChannel to add prefetching. + * The prefetching is done on a different thread, so you can write simple code that repeatedly + * calls read() to get data, processes it, and then calls read again -- and yet this + * simple code overlaps computation and communication for you. + * (Of course this is only worthwhile if the underlying SeekableByteChannel doesn't already + * implement prefetching). + */ +public final class SeekableByteChannelPrefetcher implements SeekableByteChannel { + + // Only one thread at a time should use chan. + // To ensure this is the case, only the prefetching thread uses it. + private final SeekableByteChannel chan; + private final int bufSize; + private final ExecutorService exec; + private final long size; + private final List full = new ArrayList<>(); + private WorkUnit fetching; + // total number of buffers + private final static int BUF_COUNT = 2; + // where we pretend to be, wrt returning bytes from read() + private long position; + private boolean open; + private Stopwatch betweenCallsToRead = Stopwatch.createUnstarted(); + private static int prefetcherCount; + + // statistics, for profiling. + // time spent blocking the user because we're waiting on the network + private long msWaitingForData; + // time spent blocking the user because we're copying bytes + private long msCopyingData; + // total number of bytes returned by read (if the user asks for the same bytes multiple times, they count) + private long bytesReturned; + // total number of bytes read over the network (whether returned to the user or not) + private long bytesRead ; + // time spend in between calls to Read, ie. presumably while the user is processing the data we returned. + private long msBetweenCallsToRead ; + // number of times we had the user's data already ready, didn't have to grab it from the net. + private long nbHit; + // number of times we had already started to prefetch the user's data (but it hadn't arrived yet). + private long nbNearHit; + // number of times we don't have what the user's asking for, we have to wait for a prefetch to finish, + // and the prefetch didn't return what the user wanted (either they are going backward, or jumping forward) + private long nbMiss; + // number of times the user asks for data with a lower index than what we already have + // (so they're not following the expected pattern of increasing indexes) + private long nbGoingBack; + // number of times the user asks for data past the end of the file + private long nbReadsPastEnd; + // timing statistics have an overhead, so only turn them on when debugging performance + // issues. + private static final boolean trackTime = false; + + + public static class Statistics { + // statistics, for profiling. + // time spent blocking the user because we're waiting on the network + public final long msWaitingForData; + // time spent blocking the user because we're copying bytes + public final long msCopyingData; + // total number of bytes returned by read (if the user asks for the same bytes multiple times, they count) + public final long bytesReturned; + // total number of bytes read over the network (whether returned to the user or not) + public final long bytesRead; + // time spend in between calls to Read, ie. presumably while the user is processing the data we returned. + public final long msBetweenCallsToRead; + // number of times we had the user's data already ready, didn't have to grab it from the net. + public final long nbHit; + // number of times we had already started to prefetch the user's data (but it hadn't arrived yet). + public final long nbNearHit; + // number of times we don't have what the user's asking for, we have to wait for a prefetch to finish, + // and the prefetch didn't return what the user wanted (either they are going backward, or jumping forward) + public final long nbMiss; + // number of times the user asks for data with a lower index than what we already have + // (so they're not following the expected pattern of increasing indexes) + public final long nbGoingBack; + // number of times the user asks for data past the end of the file + public final long nbReadsPastEnd; + + private Statistics(long msWaitingForData, long msCopyingData, long bytesReturned, + long bytesRead, long msBetweenCallsToRead, long nbHit, + long nbNearHit, long nbMiss, long nbGoingBack, long nbReadsPastEnd) { + this.msWaitingForData = msWaitingForData; + this.msCopyingData = msCopyingData; + this.bytesReturned = bytesReturned; + this.bytesRead = bytesRead; + this.msBetweenCallsToRead = msBetweenCallsToRead; + this.nbHit = nbHit; + this.nbNearHit = nbNearHit; + this.nbMiss = nbMiss; + this.nbGoingBack = nbGoingBack; + this.nbReadsPastEnd = nbReadsPastEnd; + } + + public String toString() { + try { + double returnedPct = (bytesRead > 0 ? 100.0 * bytesReturned / bytesRead : 100.0); + return String + .format("Bytes read: %12d\n returned: %12d ( %3.2f %% )", bytesRead, bytesReturned, + returnedPct) + + String.format("\nReads past the end: %3d", nbReadsPastEnd) + + String.format("\nReads forcing re-fetching of an earlier block: %3d", nbGoingBack) + // A near-hit is when we're already fetching the data the user is asking for, + // but we're not done loading it in. + + String + .format("\nCache\n hits: %12d\n near-hits: %12d\n misses: %12d", nbHit, + nbNearHit, nbMiss); + } catch (UnknownFormatConversionException x) { + // let's not crash the whole program, instead just return no info + return "(error while formatting statistics)"; + } + } + + + } + + + /** + * Wraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, using the provided buffer size + * + * @param bufferSizeMB buffer size in MB + * @param channel channel to wrap in the prefetcher + * @return wrapped channel + */ + public static SeekableByteChannel addPrefetcher(int bufferSizeMB, SeekableByteChannel channel) throws IOException { + return new SeekableByteChannelPrefetcher(channel, bufferSizeMB * 1024 * 1024); + } + + /** + * WorkUnit holds a buffer and the instructions for what to put in it. + * + *

    Use it like this: + *

      + *
    1. call() + *
    2. the data is now in buf, you can access it directly + *
    3. if need more, call resetForIndex(...) and go back to the top. + *
    4. else, call close() + *
    + */ + private static class WorkUnit implements Callable, Closeable { + public final ByteBuffer buf; + public long blockIndex; + private final SeekableByteChannel chan; + private final int blockSize; + private Future futureBuf; + + public WorkUnit(SeekableByteChannel chan, int blockSize, long blockIndex) { + this.chan = chan; + this.buf = ByteBuffer.allocate(blockSize); + this.futureBuf = null; + this.blockSize = blockSize; + this.blockIndex = blockIndex; + } + + @Override + public ByteBuffer call() throws IOException { + long pos = ((long)blockSize) * blockIndex; + if (pos > chan.size()) { + return null; + } + if (pos < 0) { + // This should never happen, if the code's correct. + throw new IllegalArgumentException("blockIndex " + blockIndex + " has position " + pos + ": negative position is not valid."); + } + chan.position(pos); + // read until buffer is full, or EOF + while (chan.read(buf) >= 0 && buf.hasRemaining()) {} + return buf; + } + + public ByteBuffer getBuf() throws ExecutionException, InterruptedException { + return futureBuf.get(); + } + + public WorkUnit resetForIndex(long blockIndex) { + this.blockIndex = blockIndex; + buf.clear(); + futureBuf = null; + return this; + } + + + @Override + public void close() throws IOException { + chan.close(); + } + } + + /** + * Wraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, + * using the provided buffer size. + * + * @param bufSize buffer size in bytes + * @param chan channel to wrap in the prefetcher + */ + private SeekableByteChannelPrefetcher(SeekableByteChannel chan, int bufSize) throws IOException { + Preconditions.checkArgument(!(chan instanceof SeekableByteChannelPrefetcher),"Cannot wrap a prefetcher with a prefetcher."); + + if (!chan.isOpen()) { + throw new IllegalArgumentException("channel must be open"); + } + this.chan = chan; + if (bufSize <= 0) { + throw new IllegalArgumentException("bufSize must be positive"); + } + this.size = chan.size(); + if (bufSize > this.size) { + this.bufSize = (int)this.size; + } else { + this.bufSize = bufSize; + } + this.open = true; + int prefetcherIndex = prefetcherCount++; + // Make sure the prefetching thread's name indicate what it is and + // which prefetcher it belongs to (for debugging purposes only, naturally). + String nameFormat = "nio-prefetcher-" + prefetcherIndex + "-thread-%d"; + ThreadFactory threadFactory = new ThreadFactoryBuilder() + .setNameFormat(nameFormat) + .setDaemon(true) + .build(); + // Single thread to ensure no concurrent access to chan. + exec = Executors.newFixedThreadPool(1, threadFactory); + } + + public Statistics getStatistics() { + return new Statistics(msWaitingForData, msCopyingData, bytesReturned, + bytesRead, msBetweenCallsToRead, nbHit, + nbNearHit, nbMiss, nbGoingBack, nbReadsPastEnd); + } + + // if we don't already have that block and the fetching thread is idle, + // make sure it now goes looking for that block index. + private void ensureFetching(long blockIndex) { + if (fetching != null) { + if (fetching.futureBuf.isDone()) { + full.add(fetching); + fetching = null; + } else { + return; + } + } + for (WorkUnit w : full) { + if (w.blockIndex == blockIndex) { + return; + } + } + if (full.size() < BUF_COUNT) { + fetching = new WorkUnit(chan, bufSize, blockIndex); + } else { + // reuse the oldest full buffer + fetching = full.remove(0); + fetching.resetForIndex(blockIndex); + } + bytesRead += bufSize; + fetching.futureBuf = exec.submit(fetching); + } + + // Return a buffer at this position, blocking if necessary. + // Start a background read of the buffer after this one (if there isn't one already). + public ByteBuffer fetch(long position) throws InterruptedException, ExecutionException { + long blockIndex = position / bufSize; + boolean goingBack = false; + for (WorkUnit w : full) { + if (w.blockIndex == blockIndex) { + ensureFetching(blockIndex+1); + nbHit++; + return w.buf; + } else if (w.blockIndex > blockIndex) { + goingBack = true; + } + } + if (goingBack) { + // user is asking for a block with a lower index than we've already fetched - + // in other words they are not following the expected pattern of increasing indexes. + nbGoingBack++; + } + if (null == fetching) { + ensureFetching(blockIndex); + } + WorkUnit candidate = fetching; + // block until we have the buffer + ByteBuffer buf = candidate.getBuf(); + full.add(candidate); + fetching = null; + if (candidate.blockIndex == blockIndex) { + // this is who we were waiting for + nbNearHit++; + ensureFetching(blockIndex+1); + return buf; + } else { + // wrong block. Let's fetch the right one now. + nbMiss++; + ensureFetching(blockIndex); + candidate = fetching; + buf = candidate.getBuf(); + full.add(candidate); + fetching = null; + ensureFetching(blockIndex+1); + return buf; + } + } + + + /** + * Reads a sequence of bytes from this channel into the given buffer. + * + *

    Bytes are read starting at this channel's current position, and + * then the position is updated with the number of bytes actually read. + * Otherwise this method behaves exactly as specified in the {@link + * java.nio.channels.ReadableByteChannel} interface. + * + * @param dst buffer to write into + */ + @Override + public synchronized int read(ByteBuffer dst) throws IOException { + if (!open) { + throw new ClosedChannelException(); + } + try { + if (trackTime) { + msBetweenCallsToRead += betweenCallsToRead.elapsed(TimeUnit.MILLISECONDS); + } + ByteBuffer src; + try { + Stopwatch waitingForData; + if (trackTime) { + waitingForData = Stopwatch.createStarted(); + } + src = fetch(position); + if (trackTime) { + msWaitingForData += waitingForData.elapsed(TimeUnit.MILLISECONDS); + } + } catch (InterruptedException e) { + // Restore interrupted status + Thread.currentThread().interrupt(); + return 0; + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + if (null == src) { + // the caller is asking for a block past EOF + nbReadsPastEnd++; + return -1; // EOF + } + Stopwatch copyingData; + if (trackTime) { + copyingData = Stopwatch.createStarted(); + } + // src.position is how far we've written into the array + long blockIndex = position / bufSize; + int offset = (int)(position - (blockIndex * bufSize)); + // src |==============---------------------| + // :<---src.pos-->------src.limit----->: + // |---:--position-> + // :<--offset--> + // ^ blockIndex*bufSize + int availableToCopy = src.position() - offset; + if (availableToCopy < 0) { + // the caller is asking to read past the end of the file + nbReadsPastEnd++; + return -1; // EOF + } + int bytesToCopy = dst.remaining(); + byte[] array = src.array(); + if (availableToCopy < bytesToCopy) { + bytesToCopy = availableToCopy; + } + dst.put(array, offset, bytesToCopy); + position += bytesToCopy; + if (trackTime) { + msCopyingData += copyingData.elapsed(TimeUnit.MILLISECONDS); + } + bytesReturned += bytesToCopy; + if (availableToCopy == 0) { + // EOF + return -1; + } + return bytesToCopy; + } finally { + if (trackTime) { + betweenCallsToRead.reset(); + betweenCallsToRead.start(); + } + } + } + + /** + * Writing isn't supported. + */ + @Override + public int write(ByteBuffer src) throws IOException { + throw new NonWritableChannelException(); + } + + /** + * Returns this channel's position. + * + * @return This channel's position, + * a non-negative integer counting the number of bytes + * from the beginning of the entity to the current position + * @throws ClosedChannelException If this channel is closed + * @throws IOException If some other I/O error occurs + */ + @Override + public long position() throws IOException { + if (!open) throw new ClosedChannelException(); + return position; + } + + /** + * Sets this channel's position. + *

    + *

    Setting the position to a value that is greater than the current size + * is legal but does not change the size of the entity. A later attempt to + * read bytes at such a position will immediately return an end-of-file + * indication. A later attempt to write bytes at such a position will cause + * the entity to grow to accommodate the new bytes; the values of any bytes + * between the previous end-of-file and the newly-written bytes are + * unspecified. + * + *

    Setting the channel's position is not recommended when connected to + * an entity, typically a file, that is opened with the {@link + * java.nio.file.StandardOpenOption#APPEND APPEND} option. When opened for + * append, the position is first advanced to the end before writing. + * + * @param newPosition The new position, a non-negative integer counting + * the number of bytes from the beginning of the entity + * @return This channel + * @throws ClosedChannelException If this channel is closed + * @throws IllegalArgumentException If the new position is negative + * @throws IOException If some other I/O error occurs + */ + @Override + public SeekableByteChannel position(long newPosition) throws IOException { + if (!open) throw new ClosedChannelException(); + position = newPosition; + return this; + } + + /** + * Returns the current size of entity to which this channel is connected. + * + * @return The current size, measured in bytes + * @throws ClosedChannelException If this channel is closed + * @throws IOException If some other I/O error occurs + */ + @Override + public long size() throws IOException { + if (!open) throw new ClosedChannelException(); + return size; + } + + /** + * Not supported. + */ + @Override + public SeekableByteChannel truncate(long size) throws IOException { + throw new NonWritableChannelException(); + } + + /** + * Tells whether or not this channel is open. + * + * @return true if, and only if, this channel is open + */ + @Override + public boolean isOpen() { + return open; + } + + /** + * Closes this channel. + *

    + *

    After a channel is closed, any further attempt to invoke I/O + * operations upon it will cause a {@link ClosedChannelException} to be + * thrown. + *

    + *

    If this channel is already closed then invoking this method has no + * effect. + *

    + *

    This method may be invoked at any time. If some other thread has + * already invoked it, however, then another invocation will block until + * the first invocation is complete, after which it will return without + * effect.

    + * + * @throws IOException If an I/O error occurs + */ + @Override + public void close() throws IOException { + if (open) { + // stop accepting work, interrupt worker thread. + exec.shutdownNow(); + try { + // give worker thread a bit of time to process the interruption. + exec.awaitTermination(1, TimeUnit.SECONDS); + } catch (InterruptedException e) { + // Restore interrupted status + Thread.currentThread().interrupt(); + } + chan.close(); + open = false; + } + } +} diff --git a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcherTest.java b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcherTest.java new file mode 100644 index 000000000000..3f00f34bda54 --- /dev/null +++ b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcherTest.java @@ -0,0 +1,190 @@ +/* + * Copyright 2016 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.storage.contrib.nio; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; + + +@RunWith(JUnit4.class) +public class SeekableByteChannelPrefetcherTest { + // A file big enough to try seeks on. + private static Path input; + + /** + * Sets up an input file to play with. + */ + @BeforeClass + public static void setUp() throws IOException { + // create input, fill with data + input = Files.createTempFile("tmp_big_file", ".tmp"); + try (BufferedOutputStream writer = new BufferedOutputStream(Files.newOutputStream(input))) { + byte[] buffer = new byte[1024]; + for (int i=0; i 0 && countdown > 0) { + countdown--; + } + } + +} diff --git a/google-cloud-contrib/pom.xml b/google-cloud-contrib/pom.xml index 518c659cffb1..9b5281145d8a 100644 --- a/google-cloud-contrib/pom.xml +++ b/google-cloud-contrib/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-contrib - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT pom Google Cloud Contributions https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-contrib @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-contrib diff --git a/google-cloud-core-grpc/pom.xml b/google-cloud-core-grpc/pom.xml index 93fa3d4e1d2f..c7ddf00d7480 100644 --- a/google-cloud-core-grpc/pom.xml +++ b/google-cloud-core-grpc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-grpc - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Core gRPC https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-grpc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-core-grpc diff --git a/google-cloud-core-http/pom.xml b/google-cloud-core-http/pom.xml index ae11557bad1d..a5b625b08e41 100644 --- a/google-cloud-core-http/pom.xml +++ b/google-cloud-core-http/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core-http - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Core HTTP https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-core-http diff --git a/google-cloud-core/README.md b/google-cloud-core/README.md index 0e065c058d5b..d801c41e3b7e 100644 --- a/google-cloud-core/README.md +++ b/google-cloud-core/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-core - 1.20.0 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-core:1.20.0' +compile 'com.google.cloud:google-cloud-core:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-core" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 7dc12a582189..bb28ccf06a81 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-core - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Core https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-core diff --git a/google-cloud-dataproc/README.md b/google-cloud-dataproc/README.md index da683bca0fe1..17470b651310 100644 --- a/google-cloud-dataproc/README.md +++ b/google-cloud-dataproc/README.md @@ -24,16 +24,16 @@ Add this to your pom.xml file com.google.cloud google-cloud-dataproc - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-dataproc:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-dataproc:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dataproc" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-dataproc" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-dataproc/pom.xml b/google-cloud-dataproc/pom.xml index f72ba982c85d..e422f8a96f37 100644 --- a/google-cloud-dataproc/pom.xml +++ b/google-cloud-dataproc/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-dataproc - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Dataproc https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-dataproc @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-dataproc diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/ClusterControllerSettings.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/ClusterControllerSettings.java index d51d844f7436..a530d9240fef 100644 --- a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/ClusterControllerSettings.java +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/ClusterControllerSettings.java @@ -56,7 +56,7 @@ * * ClusterControllerSettings.Builder clusterControllerSettingsBuilder = * ClusterControllerSettings.newBuilder(); - * clusterControllerSettingsBuilder.getClusterSettings().getRetrySettingsBuilder() + * clusterControllerSettingsBuilder.getClusterSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ClusterControllerSettings clusterControllerSettings = clusterControllerSettingsBuilder.build(); * diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/JobControllerSettings.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/JobControllerSettings.java index bc8e1ca673fc..cbe821d59af4 100644 --- a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/JobControllerSettings.java +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/JobControllerSettings.java @@ -54,7 +54,7 @@ * * JobControllerSettings.Builder jobControllerSettingsBuilder = * JobControllerSettings.newBuilder(); - * jobControllerSettingsBuilder.submitJobSettings().getRetrySettingsBuilder() + * jobControllerSettingsBuilder.submitJobSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * JobControllerSettings jobControllerSettings = jobControllerSettingsBuilder.build(); * diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/ClusterControllerStubSettings.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/ClusterControllerStubSettings.java index 7abefde3ca4e..03a8c5cdcee5 100644 --- a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/ClusterControllerStubSettings.java +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/ClusterControllerStubSettings.java @@ -84,7 +84,7 @@ * * ClusterControllerStubSettings.Builder clusterControllerSettingsBuilder = * ClusterControllerStubSettings.newBuilder(); - * clusterControllerSettingsBuilder.getClusterSettings().getRetrySettingsBuilder() + * clusterControllerSettingsBuilder.getClusterSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ClusterControllerStubSettings clusterControllerSettings = clusterControllerSettingsBuilder.build(); * diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcClusterControllerCallableFactory.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcClusterControllerCallableFactory.java new file mode 100644 index 000000000000..43dac92b4639 --- /dev/null +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcClusterControllerCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dataproc.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Dataproc API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcClusterControllerCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcClusterControllerStub.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcClusterControllerStub.java index 8d04c9184cde..235499c5b2ca 100644 --- a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcClusterControllerStub.java +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcClusterControllerStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -127,6 +127,8 @@ public class GrpcClusterControllerStub extends ClusterControllerStub { private final OperationCallable diagnoseClusterOperationCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcClusterControllerStub create(ClusterControllerStubSettings settings) throws IOException { return new GrpcClusterControllerStub(settings, ClientContext.create(settings)); @@ -138,6 +140,12 @@ public static final GrpcClusterControllerStub create(ClientContext clientContext ClusterControllerStubSettings.newBuilder().build(), clientContext); } + public static final GrpcClusterControllerStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcClusterControllerStub( + ClusterControllerStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcClusterControllerStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -145,7 +153,21 @@ public static final GrpcClusterControllerStub create(ClientContext clientContext */ protected GrpcClusterControllerStub( ClusterControllerStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcClusterControllerCallableFactory()); + } + + /** + * Constructs an instance of GrpcClusterControllerStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcClusterControllerStub( + ClusterControllerStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings createClusterTransportSettings = GrpcCallSettings.newBuilder() @@ -173,46 +195,46 @@ protected GrpcClusterControllerStub( .build(); this.createClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createClusterTransportSettings, settings.createClusterSettings(), clientContext); this.createClusterOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( createClusterTransportSettings, settings.createClusterOperationSettings(), clientContext, this.operationsStub); this.updateClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateClusterTransportSettings, settings.updateClusterSettings(), clientContext); this.updateClusterOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( updateClusterTransportSettings, settings.updateClusterOperationSettings(), clientContext, this.operationsStub); this.deleteClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteClusterTransportSettings, settings.deleteClusterSettings(), clientContext); this.deleteClusterOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( deleteClusterTransportSettings, settings.deleteClusterOperationSettings(), clientContext, this.operationsStub); this.getClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getClusterTransportSettings, settings.getClusterSettings(), clientContext); this.listClustersCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listClustersTransportSettings, settings.listClustersSettings(), clientContext); this.listClustersPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listClustersTransportSettings, settings.listClustersSettings(), clientContext); this.diagnoseClusterCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( diagnoseClusterTransportSettings, settings.diagnoseClusterSettings(), clientContext); this.diagnoseClusterOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( diagnoseClusterTransportSettings, settings.diagnoseClusterOperationSettings(), clientContext, diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcJobControllerCallableFactory.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcJobControllerCallableFactory.java new file mode 100644 index 000000000000..9358631f0765 --- /dev/null +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcJobControllerCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dataproc.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Dataproc API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcJobControllerCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcJobControllerStub.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcJobControllerStub.java index 6629210292c1..40426a10ef19 100644 --- a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcJobControllerStub.java +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/GrpcJobControllerStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.dataproc.v1.CancelJobRequest; @@ -103,6 +103,8 @@ public class GrpcJobControllerStub extends JobControllerStub { private final UnaryCallable cancelJobCallable; private final UnaryCallable deleteJobCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcJobControllerStub create(JobControllerStubSettings settings) throws IOException { return new GrpcJobControllerStub(settings, ClientContext.create(settings)); @@ -112,6 +114,12 @@ public static final GrpcJobControllerStub create(ClientContext clientContext) th return new GrpcJobControllerStub(JobControllerStubSettings.newBuilder().build(), clientContext); } + public static final GrpcJobControllerStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcJobControllerStub( + JobControllerStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcJobControllerStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -119,6 +127,20 @@ public static final GrpcJobControllerStub create(ClientContext clientContext) th */ protected GrpcJobControllerStub(JobControllerStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcJobControllerCallableFactory()); + } + + /** + * Constructs an instance of GrpcJobControllerStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcJobControllerStub( + JobControllerStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings submitJobTransportSettings = GrpcCallSettings.newBuilder() @@ -146,25 +168,25 @@ protected GrpcJobControllerStub(JobControllerStubSettings settings, ClientContex .build(); this.submitJobCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( submitJobTransportSettings, settings.submitJobSettings(), clientContext); this.getJobCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getJobTransportSettings, settings.getJobSettings(), clientContext); this.listJobsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listJobsTransportSettings, settings.listJobsSettings(), clientContext); this.listJobsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listJobsTransportSettings, settings.listJobsSettings(), clientContext); this.updateJobCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateJobTransportSettings, settings.updateJobSettings(), clientContext); this.cancelJobCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( cancelJobTransportSettings, settings.cancelJobSettings(), clientContext); this.deleteJobCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteJobTransportSettings, settings.deleteJobSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/JobControllerStubSettings.java b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/JobControllerStubSettings.java index fe9eaf3a5a28..7addb1fc98c8 100644 --- a/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/JobControllerStubSettings.java +++ b/google-cloud-dataproc/src/main/java/com/google/cloud/dataproc/v1/stub/JobControllerStubSettings.java @@ -77,7 +77,7 @@ * * JobControllerStubSettings.Builder jobControllerSettingsBuilder = * JobControllerStubSettings.newBuilder(); - * jobControllerSettingsBuilder.submitJobSettings().getRetrySettingsBuilder() + * jobControllerSettingsBuilder.submitJobSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * JobControllerStubSettings jobControllerSettings = jobControllerSettingsBuilder.build(); * diff --git a/google-cloud-dataproc/src/test/java/com/google/cloud/dataproc/v1/ClusterControllerSmokeTest.java b/google-cloud-dataproc/src/test/java/com/google/cloud/dataproc/v1/ClusterControllerSmokeTest.java new file mode 100644 index 000000000000..54f74094e0bf --- /dev/null +++ b/google-cloud-dataproc/src/test/java/com/google/cloud/dataproc/v1/ClusterControllerSmokeTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2018 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.cloud.dataproc.v1; + +import static com.google.cloud.dataproc.v1.ClusterControllerClient.ListClustersPagedResponse; + +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ClusterControllerSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (ClusterControllerClient client = ClusterControllerClient.create()) { + String projectId2 = projectId; + String region = "global"; + + ListClustersPagedResponse pagedResponse = client.listClusters(projectId2, region); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-datastore/README.md b/google-cloud-datastore/README.md index a22484dcb08d..92d930630125 100644 --- a/google-cloud-datastore/README.md +++ b/google-cloud-datastore/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-datastore - 1.20.0 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-datastore:1.20.0' +compile 'com.google.cloud:google-cloud-datastore:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-datastore/pom.xml b/google-cloud-datastore/pom.xml index 7700059cb37c..bbea8ed611af 100644 --- a/google-cloud-datastore/pom.xml +++ b/google-cloud-datastore/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-datastore - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Datastore https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-datastore @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-datastore @@ -40,6 +40,10 @@ + + io.grpc + grpc-core + ${project.groupId} google-cloud-core diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java index fc63f781e52f..c3c40a3d3e2f 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java @@ -27,7 +27,7 @@ import com.google.common.primitives.Booleans; import com.google.common.primitives.Doubles; import com.google.common.primitives.Longs; - +import io.grpc.Status; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -282,9 +282,9 @@ public Builder setBinding(String name, Key... value) { * @param value a {@link FullEntity} object or a list of {@link FullEntity} objects that binds * to a given name */ + @Deprecated public Builder setBinding(String name, FullEntity... value) { - namedBindings.put(name, toBinding(EntityValue.MARSHALLER, Arrays.asList(value))); - return this; + throw new DatastoreException(Status.Code.UNIMPLEMENTED.value(), "Binding entities is not supported.", "UNIMPLEMENTED"); } /** @@ -378,9 +378,9 @@ public Builder addBinding(Key... value) { * @param value a {@link FullEntity} object or a list of {@link FullEntity} objects to be set as * a new positional binding */ + @Deprecated public Builder addBinding(FullEntity... value) { - positionalBindings.add(toBinding(EntityValue.MARSHALLER, Arrays.asList(value))); - return this; + throw new DatastoreException(Status.Code.UNIMPLEMENTED.value(), "Binding entities is not supported.", "UNIMPLEMENTED"); } /** diff --git a/google-cloud-dialogflow/README.md b/google-cloud-dialogflow/README.md index 49a6a8e9bd4e..81b0aadd4783 100644 --- a/google-cloud-dialogflow/README.md +++ b/google-cloud-dialogflow/README.md @@ -25,16 +25,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-dialogflow - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-dialogflow:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-dialogflow:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-dialogflow/pom.xml b/google-cloud-dialogflow/pom.xml index 9111f0a17903..e620079665ab 100644 --- a/google-cloud-dialogflow/pom.xml +++ b/google-cloud-dialogflow/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-dialogflow - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Dialog Flow API https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-dialogflow @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-dialogflow-v2beta1 diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/AgentsSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/AgentsSettings.java index d71709cdfae5..9394c65c58f0 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/AgentsSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/AgentsSettings.java @@ -57,7 +57,7 @@ * * AgentsSettings.Builder agentsSettingsBuilder = * AgentsSettings.newBuilder(); - * agentsSettingsBuilder.getAgentSettings().getRetrySettingsBuilder() + * agentsSettingsBuilder.getAgentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * AgentsSettings agentsSettings = agentsSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/ContextsSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/ContextsSettings.java index b7f4ab6c571a..ce833dba8b54 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/ContextsSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/ContextsSettings.java @@ -54,7 +54,7 @@ * * ContextsSettings.Builder contextsSettingsBuilder = * ContextsSettings.newBuilder(); - * contextsSettingsBuilder.getContextSettings().getRetrySettingsBuilder() + * contextsSettingsBuilder.getContextSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ContextsSettings contextsSettings = contextsSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/EntityTypesSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/EntityTypesSettings.java index cf024fba0b29..beb9b888758d 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/EntityTypesSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/EntityTypesSettings.java @@ -57,7 +57,7 @@ * * EntityTypesSettings.Builder entityTypesSettingsBuilder = * EntityTypesSettings.newBuilder(); - * entityTypesSettingsBuilder.getEntityTypeSettings().getRetrySettingsBuilder() + * entityTypesSettingsBuilder.getEntityTypeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * EntityTypesSettings entityTypesSettings = entityTypesSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/IntentsSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/IntentsSettings.java index 77a038c41cf7..2e30f8128970 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/IntentsSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/IntentsSettings.java @@ -57,7 +57,7 @@ * * IntentsSettings.Builder intentsSettingsBuilder = * IntentsSettings.newBuilder(); - * intentsSettingsBuilder.getIntentSettings().getRetrySettingsBuilder() + * intentsSettingsBuilder.getIntentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * IntentsSettings intentsSettings = intentsSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionEntityTypesSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionEntityTypesSettings.java index 5e747d7ba2ab..84c6f739f23f 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionEntityTypesSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionEntityTypesSettings.java @@ -54,7 +54,7 @@ * * SessionEntityTypesSettings.Builder sessionEntityTypesSettingsBuilder = * SessionEntityTypesSettings.newBuilder(); - * sessionEntityTypesSettingsBuilder.getSessionEntityTypeSettings().getRetrySettingsBuilder() + * sessionEntityTypesSettingsBuilder.getSessionEntityTypeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SessionEntityTypesSettings sessionEntityTypesSettings = sessionEntityTypesSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionsSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionsSettings.java index 10b728c684b9..6d5679e05800 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionsSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/SessionsSettings.java @@ -51,7 +51,7 @@ * * SessionsSettings.Builder sessionsSettingsBuilder = * SessionsSettings.newBuilder(); - * sessionsSettingsBuilder.detectIntentSettings().getRetrySettingsBuilder() + * sessionsSettingsBuilder.detectIntentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SessionsSettings sessionsSettings = sessionsSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/AgentsStubSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/AgentsStubSettings.java index 4a1062269935..fd6a46f944e1 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/AgentsStubSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/AgentsStubSettings.java @@ -84,7 +84,7 @@ * * AgentsStubSettings.Builder agentsSettingsBuilder = * AgentsStubSettings.newBuilder(); - * agentsSettingsBuilder.getAgentSettings().getRetrySettingsBuilder() + * agentsSettingsBuilder.getAgentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * AgentsStubSettings agentsSettings = agentsSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/ContextsStubSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/ContextsStubSettings.java index b426f79b9ee7..6f68c9b66b2c 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/ContextsStubSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/ContextsStubSettings.java @@ -77,7 +77,7 @@ * * ContextsStubSettings.Builder contextsSettingsBuilder = * ContextsStubSettings.newBuilder(); - * contextsSettingsBuilder.getContextSettings().getRetrySettingsBuilder() + * contextsSettingsBuilder.getContextSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ContextsStubSettings contextsSettings = contextsSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/EntityTypesStubSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/EntityTypesStubSettings.java index 21edbf54b33a..98fd63103608 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/EntityTypesStubSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/EntityTypesStubSettings.java @@ -88,7 +88,7 @@ * * EntityTypesStubSettings.Builder entityTypesSettingsBuilder = * EntityTypesStubSettings.newBuilder(); - * entityTypesSettingsBuilder.getEntityTypeSettings().getRetrySettingsBuilder() + * entityTypesSettingsBuilder.getEntityTypeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * EntityTypesStubSettings entityTypesSettings = entityTypesSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcAgentsCallableFactory.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcAgentsCallableFactory.java new file mode 100644 index 000000000000..7027e18f0931 --- /dev/null +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcAgentsCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dialogflow.v2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Dialogflow API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcAgentsCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcAgentsStub.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcAgentsStub.java index 0253ed14cefd..9f4f9601b9fb 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcAgentsStub.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcAgentsStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -117,6 +117,8 @@ public class GrpcAgentsStub extends AgentsStub { private final UnaryCallable restoreAgentCallable; private final OperationCallable restoreAgentOperationCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcAgentsStub create(AgentsStubSettings settings) throws IOException { return new GrpcAgentsStub(settings, ClientContext.create(settings)); } @@ -125,13 +127,32 @@ public static final GrpcAgentsStub create(ClientContext clientContext) throws IO return new GrpcAgentsStub(AgentsStubSettings.newBuilder().build(), clientContext); } + public static final GrpcAgentsStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcAgentsStub( + AgentsStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcAgentsStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcAgentsStub(AgentsStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcAgentsCallableFactory()); + } + + /** + * Constructs an instance of GrpcAgentsStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcAgentsStub( + AgentsStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings getAgentTransportSettings = GrpcCallSettings.newBuilder() @@ -159,46 +180,46 @@ protected GrpcAgentsStub(AgentsStubSettings settings, ClientContext clientContex .build(); this.getAgentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getAgentTransportSettings, settings.getAgentSettings(), clientContext); this.searchAgentsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( searchAgentsTransportSettings, settings.searchAgentsSettings(), clientContext); this.searchAgentsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( searchAgentsTransportSettings, settings.searchAgentsSettings(), clientContext); this.trainAgentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( trainAgentTransportSettings, settings.trainAgentSettings(), clientContext); this.trainAgentOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( trainAgentTransportSettings, settings.trainAgentOperationSettings(), clientContext, this.operationsStub); this.exportAgentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( exportAgentTransportSettings, settings.exportAgentSettings(), clientContext); this.exportAgentOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( exportAgentTransportSettings, settings.exportAgentOperationSettings(), clientContext, this.operationsStub); this.importAgentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( importAgentTransportSettings, settings.importAgentSettings(), clientContext); this.importAgentOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( importAgentTransportSettings, settings.importAgentOperationSettings(), clientContext, this.operationsStub); this.restoreAgentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( restoreAgentTransportSettings, settings.restoreAgentSettings(), clientContext); this.restoreAgentOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( restoreAgentTransportSettings, settings.restoreAgentOperationSettings(), clientContext, diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcContextsCallableFactory.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcContextsCallableFactory.java new file mode 100644 index 000000000000..76a65115e303 --- /dev/null +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcContextsCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dialogflow.v2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Dialogflow API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcContextsCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcContextsStub.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcContextsStub.java index 278b7c3d48f7..26595cdc9de3 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcContextsStub.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcContextsStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.dialogflow.v2beta1.Context; @@ -111,6 +111,8 @@ public class GrpcContextsStub extends ContextsStub { private final UnaryCallable deleteContextCallable; private final UnaryCallable deleteAllContextsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcContextsStub create(ContextsStubSettings settings) throws IOException { return new GrpcContextsStub(settings, ClientContext.create(settings)); } @@ -119,12 +121,31 @@ public static final GrpcContextsStub create(ClientContext clientContext) throws return new GrpcContextsStub(ContextsStubSettings.newBuilder().build(), clientContext); } + public static final GrpcContextsStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcContextsStub( + ContextsStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcContextsStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcContextsStub(ContextsStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcContextsCallableFactory()); + } + + /** + * Constructs an instance of GrpcContextsStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcContextsStub( + ContextsStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listContextsTransportSettings = GrpcCallSettings.newBuilder() @@ -152,25 +173,25 @@ protected GrpcContextsStub(ContextsStubSettings settings, ClientContext clientCo .build(); this.listContextsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listContextsTransportSettings, settings.listContextsSettings(), clientContext); this.listContextsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listContextsTransportSettings, settings.listContextsSettings(), clientContext); this.getContextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getContextTransportSettings, settings.getContextSettings(), clientContext); this.createContextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createContextTransportSettings, settings.createContextSettings(), clientContext); this.updateContextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateContextTransportSettings, settings.updateContextSettings(), clientContext); this.deleteContextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteContextTransportSettings, settings.deleteContextSettings(), clientContext); this.deleteAllContextsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteAllContextsTransportSettings, settings.deleteAllContextsSettings(), clientContext); diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcEntityTypesCallableFactory.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcEntityTypesCallableFactory.java new file mode 100644 index 000000000000..3d2f58dfd397 --- /dev/null +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcEntityTypesCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dialogflow.v2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Dialogflow API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcEntityTypesCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcEntityTypesStub.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcEntityTypesStub.java index fad14ff854e6..4afec22e4536 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcEntityTypesStub.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcEntityTypesStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -182,6 +182,8 @@ public class GrpcEntityTypesStub extends EntityTypesStub { private final OperationCallable batchDeleteEntitiesOperationCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcEntityTypesStub create(EntityTypesStubSettings settings) throws IOException { return new GrpcEntityTypesStub(settings, ClientContext.create(settings)); @@ -191,6 +193,12 @@ public static final GrpcEntityTypesStub create(ClientContext clientContext) thro return new GrpcEntityTypesStub(EntityTypesStubSettings.newBuilder().build(), clientContext); } + public static final GrpcEntityTypesStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcEntityTypesStub( + EntityTypesStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcEntityTypesStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -198,7 +206,21 @@ public static final GrpcEntityTypesStub create(ClientContext clientContext) thro */ protected GrpcEntityTypesStub(EntityTypesStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcEntityTypesCallableFactory()); + } + + /** + * Constructs an instance of GrpcEntityTypesStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcEntityTypesStub( + EntityTypesStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings listEntityTypesTransportSettings = @@ -245,74 +267,74 @@ protected GrpcEntityTypesStub(EntityTypesStubSettings settings, ClientContext cl .build(); this.listEntityTypesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listEntityTypesTransportSettings, settings.listEntityTypesSettings(), clientContext); this.listEntityTypesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listEntityTypesTransportSettings, settings.listEntityTypesSettings(), clientContext); this.getEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getEntityTypeTransportSettings, settings.getEntityTypeSettings(), clientContext); this.createEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createEntityTypeTransportSettings, settings.createEntityTypeSettings(), clientContext); this.updateEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateEntityTypeTransportSettings, settings.updateEntityTypeSettings(), clientContext); this.deleteEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteEntityTypeTransportSettings, settings.deleteEntityTypeSettings(), clientContext); this.batchUpdateEntityTypesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchUpdateEntityTypesTransportSettings, settings.batchUpdateEntityTypesSettings(), clientContext); this.batchUpdateEntityTypesOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( batchUpdateEntityTypesTransportSettings, settings.batchUpdateEntityTypesOperationSettings(), clientContext, this.operationsStub); this.batchDeleteEntityTypesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchDeleteEntityTypesTransportSettings, settings.batchDeleteEntityTypesSettings(), clientContext); this.batchDeleteEntityTypesOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( batchDeleteEntityTypesTransportSettings, settings.batchDeleteEntityTypesOperationSettings(), clientContext, this.operationsStub); this.batchCreateEntitiesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchCreateEntitiesTransportSettings, settings.batchCreateEntitiesSettings(), clientContext); this.batchCreateEntitiesOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( batchCreateEntitiesTransportSettings, settings.batchCreateEntitiesOperationSettings(), clientContext, this.operationsStub); this.batchUpdateEntitiesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchUpdateEntitiesTransportSettings, settings.batchUpdateEntitiesSettings(), clientContext); this.batchUpdateEntitiesOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( batchUpdateEntitiesTransportSettings, settings.batchUpdateEntitiesOperationSettings(), clientContext, this.operationsStub); this.batchDeleteEntitiesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchDeleteEntitiesTransportSettings, settings.batchDeleteEntitiesSettings(), clientContext); this.batchDeleteEntitiesOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( batchDeleteEntitiesTransportSettings, settings.batchDeleteEntitiesOperationSettings(), clientContext, diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcIntentsCallableFactory.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcIntentsCallableFactory.java new file mode 100644 index 000000000000..66412a32fda6 --- /dev/null +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcIntentsCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dialogflow.v2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Dialogflow API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcIntentsCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcIntentsStub.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcIntentsStub.java index 36baf9d93788..b1c1226755cb 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcIntentsStub.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcIntentsStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -128,6 +128,8 @@ public class GrpcIntentsStub extends IntentsStub { private final OperationCallable batchDeleteIntentsOperationCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcIntentsStub create(IntentsStubSettings settings) throws IOException { return new GrpcIntentsStub(settings, ClientContext.create(settings)); } @@ -136,13 +138,32 @@ public static final GrpcIntentsStub create(ClientContext clientContext) throws I return new GrpcIntentsStub(IntentsStubSettings.newBuilder().build(), clientContext); } + public static final GrpcIntentsStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcIntentsStub( + IntentsStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcIntentsStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcIntentsStub(IntentsStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcIntentsCallableFactory()); + } + + /** + * Constructs an instance of GrpcIntentsStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcIntentsStub( + IntentsStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings listIntentsTransportSettings = GrpcCallSettings.newBuilder() @@ -174,41 +195,41 @@ protected GrpcIntentsStub(IntentsStubSettings settings, ClientContext clientCont .build(); this.listIntentsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listIntentsTransportSettings, settings.listIntentsSettings(), clientContext); this.listIntentsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listIntentsTransportSettings, settings.listIntentsSettings(), clientContext); this.getIntentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getIntentTransportSettings, settings.getIntentSettings(), clientContext); this.createIntentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createIntentTransportSettings, settings.createIntentSettings(), clientContext); this.updateIntentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateIntentTransportSettings, settings.updateIntentSettings(), clientContext); this.deleteIntentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteIntentTransportSettings, settings.deleteIntentSettings(), clientContext); this.batchUpdateIntentsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchUpdateIntentsTransportSettings, settings.batchUpdateIntentsSettings(), clientContext); this.batchUpdateIntentsOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( batchUpdateIntentsTransportSettings, settings.batchUpdateIntentsOperationSettings(), clientContext, this.operationsStub); this.batchDeleteIntentsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchDeleteIntentsTransportSettings, settings.batchDeleteIntentsSettings(), clientContext); this.batchDeleteIntentsOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( batchDeleteIntentsTransportSettings, settings.batchDeleteIntentsOperationSettings(), clientContext, diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionEntityTypesCallableFactory.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionEntityTypesCallableFactory.java new file mode 100644 index 000000000000..b38d40fee056 --- /dev/null +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionEntityTypesCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dialogflow.v2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Dialogflow API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcSessionEntityTypesCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionEntityTypesStub.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionEntityTypesStub.java index adc40e95b1f3..235aeb86b925 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionEntityTypesStub.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionEntityTypesStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.dialogflow.v2beta1.CreateSessionEntityTypeRequest; @@ -117,6 +117,8 @@ public class GrpcSessionEntityTypesStub extends SessionEntityTypesStub { private final UnaryCallable deleteSessionEntityTypeCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcSessionEntityTypesStub create(SessionEntityTypesStubSettings settings) throws IOException { return new GrpcSessionEntityTypesStub(settings, ClientContext.create(settings)); @@ -128,6 +130,12 @@ public static final GrpcSessionEntityTypesStub create(ClientContext clientContex SessionEntityTypesStubSettings.newBuilder().build(), clientContext); } + public static final GrpcSessionEntityTypesStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSessionEntityTypesStub( + SessionEntityTypesStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcSessionEntityTypesStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -135,6 +143,20 @@ public static final GrpcSessionEntityTypesStub create(ClientContext clientContex */ protected GrpcSessionEntityTypesStub( SessionEntityTypesStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcSessionEntityTypesCallableFactory()); + } + + /** + * Constructs an instance of GrpcSessionEntityTypesStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcSessionEntityTypesStub( + SessionEntityTypesStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listSessionEntityTypesTransportSettings = @@ -164,32 +186,32 @@ protected GrpcSessionEntityTypesStub( .build(); this.listSessionEntityTypesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listSessionEntityTypesTransportSettings, settings.listSessionEntityTypesSettings(), clientContext); this.listSessionEntityTypesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listSessionEntityTypesTransportSettings, settings.listSessionEntityTypesSettings(), clientContext); this.getSessionEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getSessionEntityTypeTransportSettings, settings.getSessionEntityTypeSettings(), clientContext); this.createSessionEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createSessionEntityTypeTransportSettings, settings.createSessionEntityTypeSettings(), clientContext); this.updateSessionEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateSessionEntityTypeTransportSettings, settings.updateSessionEntityTypeSettings(), clientContext); this.deleteSessionEntityTypeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteSessionEntityTypeTransportSettings, settings.deleteSessionEntityTypeSettings(), clientContext); diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionsCallableFactory.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionsCallableFactory.java new file mode 100644 index 000000000000..96096138ffef --- /dev/null +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionsCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dialogflow.v2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Dialogflow API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcSessionsCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionsStub.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionsStub.java index 5c4f2a4c8300..a16c856ee7cf 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionsStub.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/GrpcSessionsStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +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.UnaryCallable; @@ -69,6 +69,8 @@ public class GrpcSessionsStub extends SessionsStub { private final BidiStreamingCallable streamingDetectIntentCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcSessionsStub create(SessionsStubSettings settings) throws IOException { return new GrpcSessionsStub(settings, ClientContext.create(settings)); } @@ -77,12 +79,31 @@ public static final GrpcSessionsStub create(ClientContext clientContext) throws return new GrpcSessionsStub(SessionsStubSettings.newBuilder().build(), clientContext); } + public static final GrpcSessionsStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSessionsStub( + SessionsStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcSessionsStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcSessionsStub(SessionsStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcSessionsCallableFactory()); + } + + /** + * Constructs an instance of GrpcSessionsStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcSessionsStub( + SessionsStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings detectIntentTransportSettings = GrpcCallSettings.newBuilder() @@ -96,10 +117,10 @@ protected GrpcSessionsStub(SessionsStubSettings settings, ClientContext clientCo .build(); this.detectIntentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( detectIntentTransportSettings, settings.detectIntentSettings(), clientContext); this.streamingDetectIntentCallable = - GrpcCallableFactory.createBidiStreamingCallable( + callableFactory.createBidiStreamingCallable( streamingDetectIntentTransportSettings, settings.streamingDetectIntentSettings(), clientContext); diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/IntentsStubSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/IntentsStubSettings.java index 9a85ac5e627f..f6a7b01a65ba 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/IntentsStubSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/IntentsStubSettings.java @@ -85,7 +85,7 @@ * * IntentsStubSettings.Builder intentsSettingsBuilder = * IntentsStubSettings.newBuilder(); - * intentsSettingsBuilder.getIntentSettings().getRetrySettingsBuilder() + * intentsSettingsBuilder.getIntentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * IntentsStubSettings intentsSettings = intentsSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionEntityTypesStubSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionEntityTypesStubSettings.java index 292b2aac32fa..f0fe09c5512c 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionEntityTypesStubSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionEntityTypesStubSettings.java @@ -76,7 +76,7 @@ * * SessionEntityTypesStubSettings.Builder sessionEntityTypesSettingsBuilder = * SessionEntityTypesStubSettings.newBuilder(); - * sessionEntityTypesSettingsBuilder.getSessionEntityTypeSettings().getRetrySettingsBuilder() + * sessionEntityTypesSettingsBuilder.getSessionEntityTypeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SessionEntityTypesStubSettings sessionEntityTypesSettings = sessionEntityTypesSettingsBuilder.build(); * diff --git a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionsStubSettings.java b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionsStubSettings.java index 3b5900e21b36..7c33c6e0f4c0 100644 --- a/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionsStubSettings.java +++ b/google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2beta1/stub/SessionsStubSettings.java @@ -64,7 +64,7 @@ * * SessionsStubSettings.Builder sessionsSettingsBuilder = * SessionsStubSettings.newBuilder(); - * sessionsSettingsBuilder.detectIntentSettings().getRetrySettingsBuilder() + * sessionsSettingsBuilder.detectIntentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SessionsStubSettings sessionsSettings = sessionsSettingsBuilder.build(); * diff --git a/google-cloud-dlp/README.md b/google-cloud-dlp/README.md index f871bdd16517..7cdf9e6a56b5 100644 --- a/google-cloud-dlp/README.md +++ b/google-cloud-dlp/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-dlp - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-dlp:0.38.0-beta' +compile 'com.google.cloud:google-cloud-dlp:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dlp" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-dlp" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-dlp/pom.xml b/google-cloud-dlp/pom.xml index 0e238f382096..d6d6eb12242d 100644 --- a/google-cloud-dlp/pom.xml +++ b/google-cloud-dlp/pom.xml @@ -2,17 +2,17 @@ 4.0.0 google-cloud-dlp - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Data Loss Prevention API https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-dlp - Java idiomatic client for Cloud Data Loss Prevention API v2beta1. + Java idiomatic client for Cloud Data Loss Prevention API v2. com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-dlp-v2beta1 @@ -30,6 +30,10 @@ com.google.api.grpc proto-google-cloud-dlp-v2beta1 + + com.google.api.grpc + proto-google-cloud-dlp-v2 + io.grpc grpc-netty-shaded @@ -68,6 +72,11 @@ grpc-google-cloud-dlp-v2beta1 test + + com.google.api.grpc + grpc-google-cloud-dlp-v2 + test + com.google.api gax-grpc diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/DlpServiceClient.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/DlpServiceClient.java new file mode 100644 index 000000000000..50a16f16c109 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/DlpServiceClient.java @@ -0,0 +1,1836 @@ +/* + * Copyright 2018 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.cloud.dlp.v2; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +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.PageContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.dlp.v2.stub.DlpServiceStub; +import com.google.cloud.dlp.v2.stub.DlpServiceStubSettings; +import com.google.privacy.dlp.v2.CancelDlpJobRequest; +import com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.CreateDlpJobRequest; +import com.google.privacy.dlp.v2.CreateInspectTemplateRequest; +import com.google.privacy.dlp.v2.CreateJobTriggerRequest; +import com.google.privacy.dlp.v2.DeidentifyContentRequest; +import com.google.privacy.dlp.v2.DeidentifyContentResponse; +import com.google.privacy.dlp.v2.DeidentifyTemplate; +import com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.DeleteDlpJobRequest; +import com.google.privacy.dlp.v2.DeleteInspectTemplateRequest; +import com.google.privacy.dlp.v2.DeleteJobTriggerRequest; +import com.google.privacy.dlp.v2.DlpJob; +import com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.GetDlpJobRequest; +import com.google.privacy.dlp.v2.GetInspectTemplateRequest; +import com.google.privacy.dlp.v2.GetJobTriggerRequest; +import com.google.privacy.dlp.v2.InspectContentRequest; +import com.google.privacy.dlp.v2.InspectContentResponse; +import com.google.privacy.dlp.v2.InspectTemplate; +import com.google.privacy.dlp.v2.JobTrigger; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse; +import com.google.privacy.dlp.v2.ListDlpJobsRequest; +import com.google.privacy.dlp.v2.ListDlpJobsResponse; +import com.google.privacy.dlp.v2.ListInfoTypesRequest; +import com.google.privacy.dlp.v2.ListInfoTypesResponse; +import com.google.privacy.dlp.v2.ListInspectTemplatesRequest; +import com.google.privacy.dlp.v2.ListInspectTemplatesResponse; +import com.google.privacy.dlp.v2.ListJobTriggersRequest; +import com.google.privacy.dlp.v2.ListJobTriggersResponse; +import com.google.privacy.dlp.v2.RedactImageRequest; +import com.google.privacy.dlp.v2.RedactImageResponse; +import com.google.privacy.dlp.v2.ReidentifyContentRequest; +import com.google.privacy.dlp.v2.ReidentifyContentResponse; +import com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.UpdateInspectTemplateRequest; +import com.google.privacy.dlp.v2.UpdateJobTriggerRequest; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: The Cloud Data Loss Prevention (DLP) API is a service that allows clients to + * detect the presence of Personally Identifiable Information (PII) and other privacy-sensitive data + * in user-supplied, unstructured data streams, like text blocks or images. The service also + * includes methods for sensitive data redaction and scheduling of data scans on Google Cloud + * Platform based data sets. + * + *

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

    + * 
    + * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    + *   ProjectName parent = ProjectName.of("[PROJECT]");
    + *   InspectContentRequest request = InspectContentRequest.newBuilder()
    + *     .setParent(parent.toString())
    + *     .build();
    + *   InspectContentResponse response = dlpServiceClient.inspectContent(request);
    + * }
    + * 
    + * 
    + * + *

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

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

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

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

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

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

    To customize credentials: + * + *

    + * 
    + * DlpServiceSettings dlpServiceSettings =
    + *     DlpServiceSettings.newBuilder()
    + *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
    + *         .build();
    + * DlpServiceClient dlpServiceClient =
    + *     DlpServiceClient.create(dlpServiceSettings);
    + * 
    + * 
    + * + * To customize the endpoint: + * + *
    + * 
    + * DlpServiceSettings dlpServiceSettings =
    + *     DlpServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
    + * DlpServiceClient dlpServiceClient =
    + *     DlpServiceClient.create(dlpServiceSettings);
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class DlpServiceClient implements BackgroundResource { + private final DlpServiceSettings settings; + private final DlpServiceStub stub; + + /** Constructs an instance of DlpServiceClient with default settings. */ + public static final DlpServiceClient create() throws IOException { + return create(DlpServiceSettings.newBuilder().build()); + } + + /** + * Constructs an instance of DlpServiceClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final DlpServiceClient create(DlpServiceSettings settings) throws IOException { + return new DlpServiceClient(settings); + } + + /** + * Constructs an instance of DlpServiceClient, using the given stub for making calls. This is for + * advanced usage - prefer to use DlpServiceSettings}. + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final DlpServiceClient create(DlpServiceStub stub) { + return new DlpServiceClient(stub); + } + + /** + * Constructs an instance of DlpServiceClient, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected DlpServiceClient(DlpServiceSettings settings) throws IOException { + this.settings = settings; + this.stub = ((DlpServiceStubSettings) settings.getStubSettings()).createStub(); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected DlpServiceClient(DlpServiceStub stub) { + this.settings = null; + this.stub = stub; + } + + public final DlpServiceSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public DlpServiceStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Finds potentially sensitive info in content. This method has limits on input size, processing + * time, and output size. [How-to guide for text](/dlp/docs/inspecting-text), [How-to guide for + * images](/dlp/docs/inspecting-images) + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   InspectContentRequest request = InspectContentRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   InspectContentResponse response = dlpServiceClient.inspectContent(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 InspectContentResponse inspectContent(InspectContentRequest request) { + return inspectContentCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Finds potentially sensitive info in content. This method has limits on input size, processing + * time, and output size. [How-to guide for text](/dlp/docs/inspecting-text), [How-to guide for + * images](/dlp/docs/inspecting-images) + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   InspectContentRequest request = InspectContentRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<InspectContentResponse> future = dlpServiceClient.inspectContentCallable().futureCall(request);
    +   *   // Do something
    +   *   InspectContentResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + inspectContentCallable() { + return stub.inspectContentCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Redacts potentially sensitive info from an image. This method has limits on input size, + * processing time, and output size. [How-to guide](/dlp/docs/redacting-sensitive-data-images) + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   RedactImageRequest request = RedactImageRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   RedactImageResponse response = dlpServiceClient.redactImage(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 RedactImageResponse redactImage(RedactImageRequest request) { + return redactImageCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Redacts potentially sensitive info from an image. This method has limits on input size, + * processing time, and output size. [How-to guide](/dlp/docs/redacting-sensitive-data-images) + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   RedactImageRequest request = RedactImageRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<RedactImageResponse> future = dlpServiceClient.redactImageCallable().futureCall(request);
    +   *   // Do something
    +   *   RedactImageResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable redactImageCallable() { + return stub.redactImageCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * De-identifies potentially sensitive info from a ContentItem. This method has limits on input + * size and output size. [How-to guide](/dlp/docs/deidentify-sensitive-data) + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   DeidentifyContentResponse response = dlpServiceClient.deidentifyContent(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 DeidentifyContentResponse deidentifyContent(DeidentifyContentRequest request) { + return deidentifyContentCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * De-identifies potentially sensitive info from a ContentItem. This method has limits on input + * size and output size. [How-to guide](/dlp/docs/deidentify-sensitive-data) + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<DeidentifyContentResponse> future = dlpServiceClient.deidentifyContentCallable().futureCall(request);
    +   *   // Do something
    +   *   DeidentifyContentResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + deidentifyContentCallable() { + return stub.deidentifyContentCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Re-identifies content that has been de-identified. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ReidentifyContentRequest request = ReidentifyContentRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ReidentifyContentResponse response = dlpServiceClient.reidentifyContent(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 ReidentifyContentResponse reidentifyContent(ReidentifyContentRequest request) { + return reidentifyContentCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Re-identifies content that has been de-identified. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ReidentifyContentRequest request = ReidentifyContentRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<ReidentifyContentResponse> future = dlpServiceClient.reidentifyContentCallable().futureCall(request);
    +   *   // Do something
    +   *   ReidentifyContentResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + reidentifyContentCallable() { + return stub.reidentifyContentCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns a list of the sensitive information types that the DLP API supports. For more + * information, see [Listing supported predefined infoTypes](/dlp/docs/listing-infotypes). + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ListInfoTypesRequest request = ListInfoTypesRequest.newBuilder().build();
    +   *   ListInfoTypesResponse response = dlpServiceClient.listInfoTypes(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 ListInfoTypesResponse listInfoTypes(ListInfoTypesRequest request) { + return listInfoTypesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns a list of the sensitive information types that the DLP API supports. For more + * information, see [Listing supported predefined infoTypes](/dlp/docs/listing-infotypes). + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ListInfoTypesRequest request = ListInfoTypesRequest.newBuilder().build();
    +   *   ApiFuture<ListInfoTypesResponse> future = dlpServiceClient.listInfoTypesCallable().futureCall(request);
    +   *   // Do something
    +   *   ListInfoTypesResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable listInfoTypesCallable() { + return stub.listInfoTypesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates an inspect template for re-using frequently used configuration for inspecting content, + * images, and storage. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   CreateInspectTemplateRequest request = CreateInspectTemplateRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   InspectTemplate response = dlpServiceClient.createInspectTemplate(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 InspectTemplate createInspectTemplate(CreateInspectTemplateRequest request) { + return createInspectTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates an inspect template for re-using frequently used configuration for inspecting content, + * images, and storage. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   CreateInspectTemplateRequest request = CreateInspectTemplateRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<InspectTemplate> future = dlpServiceClient.createInspectTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   InspectTemplate response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + createInspectTemplateCallable() { + return stub.createInspectTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the inspect template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   InspectTemplateName name = OrganizationInspectTemplateName.of("[ORGANIZATION]", "[INSPECT_TEMPLATE]");
    +   *   UpdateInspectTemplateRequest request = UpdateInspectTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   InspectTemplate response = dlpServiceClient.updateInspectTemplate(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 InspectTemplate updateInspectTemplate(UpdateInspectTemplateRequest request) { + return updateInspectTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the inspect template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   InspectTemplateName name = OrganizationInspectTemplateName.of("[ORGANIZATION]", "[INSPECT_TEMPLATE]");
    +   *   UpdateInspectTemplateRequest request = UpdateInspectTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<InspectTemplate> future = dlpServiceClient.updateInspectTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   InspectTemplate response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + updateInspectTemplateCallable() { + return stub.updateInspectTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets an inspect template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   GetInspectTemplateRequest request = GetInspectTemplateRequest.newBuilder().build();
    +   *   InspectTemplate response = dlpServiceClient.getInspectTemplate(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 InspectTemplate getInspectTemplate(GetInspectTemplateRequest request) { + return getInspectTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets an inspect template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   GetInspectTemplateRequest request = GetInspectTemplateRequest.newBuilder().build();
    +   *   ApiFuture<InspectTemplate> future = dlpServiceClient.getInspectTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   InspectTemplate response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + getInspectTemplateCallable() { + return stub.getInspectTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists inspect templates. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   ListInspectTemplatesRequest request = ListInspectTemplatesRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   for (InspectTemplate element : dlpServiceClient.listInspectTemplates(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 ListInspectTemplatesPagedResponse listInspectTemplates( + ListInspectTemplatesRequest request) { + return listInspectTemplatesPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists inspect templates. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   ListInspectTemplatesRequest request = ListInspectTemplatesRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<ListInspectTemplatesPagedResponse> future = dlpServiceClient.listInspectTemplatesPagedCallable().futureCall(request);
    +   *   // Do something
    +   *   for (InspectTemplate element : future.get().iterateAll()) {
    +   *     // doThingsWith(element);
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable + listInspectTemplatesPagedCallable() { + return stub.listInspectTemplatesPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists inspect templates. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   ListInspectTemplatesRequest request = ListInspectTemplatesRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   while (true) {
    +   *     ListInspectTemplatesResponse response = dlpServiceClient.listInspectTemplatesCallable().call(request);
    +   *     for (InspectTemplate element : response.getInspectTemplatesList()) {
    +   *       // doThingsWith(element);
    +   *     }
    +   *     String nextPageToken = response.getNextPageToken();
    +   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
    +   *       request = request.toBuilder().setPageToken(nextPageToken).build();
    +   *     } else {
    +   *       break;
    +   *     }
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable + listInspectTemplatesCallable() { + return stub.listInspectTemplatesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes an inspect template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   InspectTemplateName name = OrganizationInspectTemplateName.of("[ORGANIZATION]", "[INSPECT_TEMPLATE]");
    +   *   DeleteInspectTemplateRequest request = DeleteInspectTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   dlpServiceClient.deleteInspectTemplate(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 deleteInspectTemplate(DeleteInspectTemplateRequest request) { + deleteInspectTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes an inspect template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   InspectTemplateName name = OrganizationInspectTemplateName.of("[ORGANIZATION]", "[INSPECT_TEMPLATE]");
    +   *   DeleteInspectTemplateRequest request = DeleteInspectTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<Void> future = dlpServiceClient.deleteInspectTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable deleteInspectTemplateCallable() { + return stub.deleteInspectTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a de-identify template for re-using frequently used configuration for Deidentifying + * content, images, and storage. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   CreateDeidentifyTemplateRequest request = CreateDeidentifyTemplateRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   DeidentifyTemplate response = dlpServiceClient.createDeidentifyTemplate(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 DeidentifyTemplate createDeidentifyTemplate( + CreateDeidentifyTemplateRequest request) { + return createDeidentifyTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a de-identify template for re-using frequently used configuration for Deidentifying + * content, images, and storage. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   CreateDeidentifyTemplateRequest request = CreateDeidentifyTemplateRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<DeidentifyTemplate> future = dlpServiceClient.createDeidentifyTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   DeidentifyTemplate response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + createDeidentifyTemplateCallable() { + return stub.createDeidentifyTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the de-identify template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DeidentifyTemplateName name = OrganizationDeidentifyTemplateName.of("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    +   *   UpdateDeidentifyTemplateRequest request = UpdateDeidentifyTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   DeidentifyTemplate response = dlpServiceClient.updateDeidentifyTemplate(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 DeidentifyTemplate updateDeidentifyTemplate( + UpdateDeidentifyTemplateRequest request) { + return updateDeidentifyTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the de-identify template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DeidentifyTemplateName name = OrganizationDeidentifyTemplateName.of("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    +   *   UpdateDeidentifyTemplateRequest request = UpdateDeidentifyTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<DeidentifyTemplate> future = dlpServiceClient.updateDeidentifyTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   DeidentifyTemplate response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + updateDeidentifyTemplateCallable() { + return stub.updateDeidentifyTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets a de-identify template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DeidentifyTemplateName name = OrganizationDeidentifyTemplateName.of("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    +   *   GetDeidentifyTemplateRequest request = GetDeidentifyTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   DeidentifyTemplate response = dlpServiceClient.getDeidentifyTemplate(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 DeidentifyTemplate getDeidentifyTemplate(GetDeidentifyTemplateRequest request) { + return getDeidentifyTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets a de-identify template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DeidentifyTemplateName name = OrganizationDeidentifyTemplateName.of("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    +   *   GetDeidentifyTemplateRequest request = GetDeidentifyTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<DeidentifyTemplate> future = dlpServiceClient.getDeidentifyTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   DeidentifyTemplate response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + getDeidentifyTemplateCallable() { + return stub.getDeidentifyTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists de-identify templates. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   ListDeidentifyTemplatesRequest request = ListDeidentifyTemplatesRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   for (DeidentifyTemplate element : dlpServiceClient.listDeidentifyTemplates(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 ListDeidentifyTemplatesPagedResponse listDeidentifyTemplates( + ListDeidentifyTemplatesRequest request) { + return listDeidentifyTemplatesPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists de-identify templates. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   ListDeidentifyTemplatesRequest request = ListDeidentifyTemplatesRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<ListDeidentifyTemplatesPagedResponse> future = dlpServiceClient.listDeidentifyTemplatesPagedCallable().futureCall(request);
    +   *   // Do something
    +   *   for (DeidentifyTemplate element : future.get().iterateAll()) {
    +   *     // doThingsWith(element);
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable + listDeidentifyTemplatesPagedCallable() { + return stub.listDeidentifyTemplatesPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists de-identify templates. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
    +   *   ListDeidentifyTemplatesRequest request = ListDeidentifyTemplatesRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   while (true) {
    +   *     ListDeidentifyTemplatesResponse response = dlpServiceClient.listDeidentifyTemplatesCallable().call(request);
    +   *     for (DeidentifyTemplate element : response.getDeidentifyTemplatesList()) {
    +   *       // doThingsWith(element);
    +   *     }
    +   *     String nextPageToken = response.getNextPageToken();
    +   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
    +   *       request = request.toBuilder().setPageToken(nextPageToken).build();
    +   *     } else {
    +   *       break;
    +   *     }
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable + listDeidentifyTemplatesCallable() { + return stub.listDeidentifyTemplatesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a de-identify template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DeidentifyTemplateName name = OrganizationDeidentifyTemplateName.of("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    +   *   DeleteDeidentifyTemplateRequest request = DeleteDeidentifyTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   dlpServiceClient.deleteDeidentifyTemplate(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 deleteDeidentifyTemplate(DeleteDeidentifyTemplateRequest request) { + deleteDeidentifyTemplateCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a de-identify template. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DeidentifyTemplateName name = OrganizationDeidentifyTemplateName.of("[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]");
    +   *   DeleteDeidentifyTemplateRequest request = DeleteDeidentifyTemplateRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<Void> future = dlpServiceClient.deleteDeidentifyTemplateCallable().futureCall(request);
    +   *   // Do something
    +   *   future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + deleteDeidentifyTemplateCallable() { + return stub.deleteDeidentifyTemplateCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a new job to inspect storage or calculate risk metrics [How-to + * guide](/dlp/docs/compute-risk-analysis). + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   CreateDlpJobRequest request = CreateDlpJobRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   DlpJob response = dlpServiceClient.createDlpJob(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 DlpJob createDlpJob(CreateDlpJobRequest request) { + return createDlpJobCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a new job to inspect storage or calculate risk metrics [How-to + * guide](/dlp/docs/compute-risk-analysis). + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   CreateDlpJobRequest request = CreateDlpJobRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<DlpJob> future = dlpServiceClient.createDlpJobCallable().futureCall(request);
    +   *   // Do something
    +   *   DlpJob response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable createDlpJobCallable() { + return stub.createDlpJobCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists DlpJobs that match the specified filter in the request. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ListDlpJobsRequest request = ListDlpJobsRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   for (DlpJob element : dlpServiceClient.listDlpJobs(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 ListDlpJobsPagedResponse listDlpJobs(ListDlpJobsRequest request) { + return listDlpJobsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists DlpJobs that match the specified filter in the request. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ListDlpJobsRequest request = ListDlpJobsRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<ListDlpJobsPagedResponse> future = dlpServiceClient.listDlpJobsPagedCallable().futureCall(request);
    +   *   // Do something
    +   *   for (DlpJob element : future.get().iterateAll()) {
    +   *     // doThingsWith(element);
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable + listDlpJobsPagedCallable() { + return stub.listDlpJobsPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists DlpJobs that match the specified filter in the request. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ListDlpJobsRequest request = ListDlpJobsRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   while (true) {
    +   *     ListDlpJobsResponse response = dlpServiceClient.listDlpJobsCallable().call(request);
    +   *     for (DlpJob element : response.getJobsList()) {
    +   *       // doThingsWith(element);
    +   *     }
    +   *     String nextPageToken = response.getNextPageToken();
    +   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
    +   *       request = request.toBuilder().setPageToken(nextPageToken).build();
    +   *     } else {
    +   *       break;
    +   *     }
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable listDlpJobsCallable() { + return stub.listDlpJobsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets the latest state of a long-running DlpJob. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DlpJobName name = DlpJobName.of("[PROJECT]", "[DLP_JOB]");
    +   *   GetDlpJobRequest request = GetDlpJobRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   DlpJob response = dlpServiceClient.getDlpJob(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 DlpJob getDlpJob(GetDlpJobRequest request) { + return getDlpJobCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets the latest state of a long-running DlpJob. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DlpJobName name = DlpJobName.of("[PROJECT]", "[DLP_JOB]");
    +   *   GetDlpJobRequest request = GetDlpJobRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<DlpJob> future = dlpServiceClient.getDlpJobCallable().futureCall(request);
    +   *   // Do something
    +   *   DlpJob response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable getDlpJobCallable() { + return stub.getDlpJobCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a long-running DlpJob. This method indicates that the client is no longer interested in + * the DlpJob result. The job will be cancelled if possible. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DlpJobName name = DlpJobName.of("[PROJECT]", "[DLP_JOB]");
    +   *   DeleteDlpJobRequest request = DeleteDlpJobRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   dlpServiceClient.deleteDlpJob(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 deleteDlpJob(DeleteDlpJobRequest request) { + deleteDlpJobCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a long-running DlpJob. This method indicates that the client is no longer interested in + * the DlpJob result. The job will be cancelled if possible. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DlpJobName name = DlpJobName.of("[PROJECT]", "[DLP_JOB]");
    +   *   DeleteDlpJobRequest request = DeleteDlpJobRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<Void> future = dlpServiceClient.deleteDlpJobCallable().futureCall(request);
    +   *   // Do something
    +   *   future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable deleteDlpJobCallable() { + return stub.deleteDlpJobCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Starts asynchronous cancellation on a long-running DlpJob. The server makes a best effort to + * cancel the DlpJob, but success is not guaranteed. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DlpJobName name = DlpJobName.of("[PROJECT]", "[DLP_JOB]");
    +   *   CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   dlpServiceClient.cancelDlpJob(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 cancelDlpJob(CancelDlpJobRequest request) { + cancelDlpJobCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Starts asynchronous cancellation on a long-running DlpJob. The server makes a best effort to + * cancel the DlpJob, but success is not guaranteed. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   DlpJobName name = DlpJobName.of("[PROJECT]", "[DLP_JOB]");
    +   *   CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<Void> future = dlpServiceClient.cancelDlpJobCallable().futureCall(request);
    +   *   // Do something
    +   *   future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable cancelDlpJobCallable() { + return stub.cancelDlpJobCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists job triggers. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ListJobTriggersRequest request = ListJobTriggersRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   for (JobTrigger element : dlpServiceClient.listJobTriggers(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 ListJobTriggersPagedResponse listJobTriggers(ListJobTriggersRequest request) { + return listJobTriggersPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists job triggers. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ListJobTriggersRequest request = ListJobTriggersRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<ListJobTriggersPagedResponse> future = dlpServiceClient.listJobTriggersPagedCallable().futureCall(request);
    +   *   // Do something
    +   *   for (JobTrigger element : future.get().iterateAll()) {
    +   *     // doThingsWith(element);
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable + listJobTriggersPagedCallable() { + return stub.listJobTriggersPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists job triggers. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   ListJobTriggersRequest request = ListJobTriggersRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   while (true) {
    +   *     ListJobTriggersResponse response = dlpServiceClient.listJobTriggersCallable().call(request);
    +   *     for (JobTrigger element : response.getJobTriggersList()) {
    +   *       // doThingsWith(element);
    +   *     }
    +   *     String nextPageToken = response.getNextPageToken();
    +   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
    +   *       request = request.toBuilder().setPageToken(nextPageToken).build();
    +   *     } else {
    +   *       break;
    +   *     }
    +   *   }
    +   * }
    +   * 
    + */ + public final UnaryCallable + listJobTriggersCallable() { + return stub.listJobTriggersCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets a job trigger. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectJobTriggerName name = ProjectJobTriggerName.of("[PROJECT]", "[JOB_TRIGGER]");
    +   *   GetJobTriggerRequest request = GetJobTriggerRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   JobTrigger response = dlpServiceClient.getJobTrigger(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 JobTrigger getJobTrigger(GetJobTriggerRequest request) { + return getJobTriggerCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets a job trigger. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectJobTriggerName name = ProjectJobTriggerName.of("[PROJECT]", "[JOB_TRIGGER]");
    +   *   GetJobTriggerRequest request = GetJobTriggerRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<JobTrigger> future = dlpServiceClient.getJobTriggerCallable().futureCall(request);
    +   *   // Do something
    +   *   JobTrigger response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable getJobTriggerCallable() { + return stub.getJobTriggerCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a job trigger. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectJobTriggerName name = ProjectJobTriggerName.of("[PROJECT]", "[JOB_TRIGGER]");
    +   *   DeleteJobTriggerRequest request = DeleteJobTriggerRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   dlpServiceClient.deleteJobTrigger(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 deleteJobTrigger(DeleteJobTriggerRequest request) { + deleteJobTriggerCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a job trigger. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectJobTriggerName name = ProjectJobTriggerName.of("[PROJECT]", "[JOB_TRIGGER]");
    +   *   DeleteJobTriggerRequest request = DeleteJobTriggerRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<Void> future = dlpServiceClient.deleteJobTriggerCallable().futureCall(request);
    +   *   // Do something
    +   *   future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable deleteJobTriggerCallable() { + return stub.deleteJobTriggerCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates a job trigger. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectJobTriggerName name = ProjectJobTriggerName.of("[PROJECT]", "[JOB_TRIGGER]");
    +   *   UpdateJobTriggerRequest request = UpdateJobTriggerRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   JobTrigger response = dlpServiceClient.updateJobTrigger(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 JobTrigger updateJobTrigger(UpdateJobTriggerRequest request) { + return updateJobTriggerCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates a job trigger. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectJobTriggerName name = ProjectJobTriggerName.of("[PROJECT]", "[JOB_TRIGGER]");
    +   *   UpdateJobTriggerRequest request = UpdateJobTriggerRequest.newBuilder()
    +   *     .setName(name.toString())
    +   *     .build();
    +   *   ApiFuture<JobTrigger> future = dlpServiceClient.updateJobTriggerCallable().futureCall(request);
    +   *   // Do something
    +   *   JobTrigger response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable updateJobTriggerCallable() { + return stub.updateJobTriggerCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a job trigger to run DLP actions such as scanning storage for sensitive information on + * a set schedule. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   CreateJobTriggerRequest request = CreateJobTriggerRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   JobTrigger response = dlpServiceClient.createJobTrigger(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 JobTrigger createJobTrigger(CreateJobTriggerRequest request) { + return createJobTriggerCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a job trigger to run DLP actions such as scanning storage for sensitive information on + * a set schedule. + * + *

    Sample code: + * + *

    
    +   * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    +   *   ProjectName parent = ProjectName.of("[PROJECT]");
    +   *   CreateJobTriggerRequest request = CreateJobTriggerRequest.newBuilder()
    +   *     .setParent(parent.toString())
    +   *     .build();
    +   *   ApiFuture<JobTrigger> future = dlpServiceClient.createJobTriggerCallable().futureCall(request);
    +   *   // Do something
    +   *   JobTrigger response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable createJobTriggerCallable() { + return stub.createJobTriggerCallable(); + } + + @Override + public final void close() throws Exception { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } + + public static class ListInspectTemplatesPagedResponse + extends AbstractPagedListResponse< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, InspectTemplate, + ListInspectTemplatesPage, ListInspectTemplatesFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext + context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListInspectTemplatesPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListInspectTemplatesPagedResponse apply(ListInspectTemplatesPage input) { + return new ListInspectTemplatesPagedResponse(input); + } + }); + } + + private ListInspectTemplatesPagedResponse(ListInspectTemplatesPage page) { + super(page, ListInspectTemplatesFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListInspectTemplatesPage + extends AbstractPage< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, InspectTemplate, + ListInspectTemplatesPage> { + + private ListInspectTemplatesPage( + PageContext + context, + ListInspectTemplatesResponse response) { + super(context, response); + } + + private static ListInspectTemplatesPage createEmptyPage() { + return new ListInspectTemplatesPage(null, null); + } + + @Override + protected ListInspectTemplatesPage createPage( + PageContext + context, + ListInspectTemplatesResponse response) { + return new ListInspectTemplatesPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext + context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListInspectTemplatesFixedSizeCollection + extends AbstractFixedSizeCollection< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, InspectTemplate, + ListInspectTemplatesPage, ListInspectTemplatesFixedSizeCollection> { + + private ListInspectTemplatesFixedSizeCollection( + List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListInspectTemplatesFixedSizeCollection createEmptyCollection() { + return new ListInspectTemplatesFixedSizeCollection(null, 0); + } + + @Override + protected ListInspectTemplatesFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListInspectTemplatesFixedSizeCollection(pages, collectionSize); + } + } + + public static class ListDeidentifyTemplatesPagedResponse + extends AbstractPagedListResponse< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate, + ListDeidentifyTemplatesPage, ListDeidentifyTemplatesFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate> + context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListDeidentifyTemplatesPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListDeidentifyTemplatesPagedResponse apply(ListDeidentifyTemplatesPage input) { + return new ListDeidentifyTemplatesPagedResponse(input); + } + }); + } + + private ListDeidentifyTemplatesPagedResponse(ListDeidentifyTemplatesPage page) { + super(page, ListDeidentifyTemplatesFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListDeidentifyTemplatesPage + extends AbstractPage< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate, + ListDeidentifyTemplatesPage> { + + private ListDeidentifyTemplatesPage( + PageContext< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate> + context, + ListDeidentifyTemplatesResponse response) { + super(context, response); + } + + private static ListDeidentifyTemplatesPage createEmptyPage() { + return new ListDeidentifyTemplatesPage(null, null); + } + + @Override + protected ListDeidentifyTemplatesPage createPage( + PageContext< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate> + context, + ListDeidentifyTemplatesResponse response) { + return new ListDeidentifyTemplatesPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate> + context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListDeidentifyTemplatesFixedSizeCollection + extends AbstractFixedSizeCollection< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate, + ListDeidentifyTemplatesPage, ListDeidentifyTemplatesFixedSizeCollection> { + + private ListDeidentifyTemplatesFixedSizeCollection( + List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListDeidentifyTemplatesFixedSizeCollection createEmptyCollection() { + return new ListDeidentifyTemplatesFixedSizeCollection(null, 0); + } + + @Override + protected ListDeidentifyTemplatesFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListDeidentifyTemplatesFixedSizeCollection(pages, collectionSize); + } + } + + public static class ListDlpJobsPagedResponse + extends AbstractPagedListResponse< + ListDlpJobsRequest, ListDlpJobsResponse, DlpJob, ListDlpJobsPage, + ListDlpJobsFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListDlpJobsPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListDlpJobsPagedResponse apply(ListDlpJobsPage input) { + return new ListDlpJobsPagedResponse(input); + } + }); + } + + private ListDlpJobsPagedResponse(ListDlpJobsPage page) { + super(page, ListDlpJobsFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListDlpJobsPage + extends AbstractPage { + + private ListDlpJobsPage( + PageContext context, + ListDlpJobsResponse response) { + super(context, response); + } + + private static ListDlpJobsPage createEmptyPage() { + return new ListDlpJobsPage(null, null); + } + + @Override + protected ListDlpJobsPage createPage( + PageContext context, + ListDlpJobsResponse response) { + return new ListDlpJobsPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListDlpJobsFixedSizeCollection + extends AbstractFixedSizeCollection< + ListDlpJobsRequest, ListDlpJobsResponse, DlpJob, ListDlpJobsPage, + ListDlpJobsFixedSizeCollection> { + + private ListDlpJobsFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListDlpJobsFixedSizeCollection createEmptyCollection() { + return new ListDlpJobsFixedSizeCollection(null, 0); + } + + @Override + protected ListDlpJobsFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListDlpJobsFixedSizeCollection(pages, collectionSize); + } + } + + public static class ListJobTriggersPagedResponse + extends AbstractPagedListResponse< + ListJobTriggersRequest, ListJobTriggersResponse, JobTrigger, ListJobTriggersPage, + ListJobTriggersFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListJobTriggersPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListJobTriggersPagedResponse apply(ListJobTriggersPage input) { + return new ListJobTriggersPagedResponse(input); + } + }); + } + + private ListJobTriggersPagedResponse(ListJobTriggersPage page) { + super(page, ListJobTriggersFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListJobTriggersPage + extends AbstractPage< + ListJobTriggersRequest, ListJobTriggersResponse, JobTrigger, ListJobTriggersPage> { + + private ListJobTriggersPage( + PageContext context, + ListJobTriggersResponse response) { + super(context, response); + } + + private static ListJobTriggersPage createEmptyPage() { + return new ListJobTriggersPage(null, null); + } + + @Override + protected ListJobTriggersPage createPage( + PageContext context, + ListJobTriggersResponse response) { + return new ListJobTriggersPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListJobTriggersFixedSizeCollection + extends AbstractFixedSizeCollection< + ListJobTriggersRequest, ListJobTriggersResponse, JobTrigger, ListJobTriggersPage, + ListJobTriggersFixedSizeCollection> { + + private ListJobTriggersFixedSizeCollection( + List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListJobTriggersFixedSizeCollection createEmptyCollection() { + return new ListJobTriggersFixedSizeCollection(null, 0); + } + + @Override + protected ListJobTriggersFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListJobTriggersFixedSizeCollection(pages, collectionSize); + } + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/DlpServiceSettings.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/DlpServiceSettings.java new file mode 100644 index 000000000000..7167697f9b28 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/DlpServiceSettings.java @@ -0,0 +1,500 @@ +/* + * Copyright 2018 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.cloud.dlp.v2; + +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDlpJobsPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListInspectTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListJobTriggersPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +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.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.dlp.v2.stub.DlpServiceStubSettings; +import com.google.privacy.dlp.v2.CancelDlpJobRequest; +import com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.CreateDlpJobRequest; +import com.google.privacy.dlp.v2.CreateInspectTemplateRequest; +import com.google.privacy.dlp.v2.CreateJobTriggerRequest; +import com.google.privacy.dlp.v2.DeidentifyContentRequest; +import com.google.privacy.dlp.v2.DeidentifyContentResponse; +import com.google.privacy.dlp.v2.DeidentifyTemplate; +import com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.DeleteDlpJobRequest; +import com.google.privacy.dlp.v2.DeleteInspectTemplateRequest; +import com.google.privacy.dlp.v2.DeleteJobTriggerRequest; +import com.google.privacy.dlp.v2.DlpJob; +import com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.GetDlpJobRequest; +import com.google.privacy.dlp.v2.GetInspectTemplateRequest; +import com.google.privacy.dlp.v2.GetJobTriggerRequest; +import com.google.privacy.dlp.v2.InspectContentRequest; +import com.google.privacy.dlp.v2.InspectContentResponse; +import com.google.privacy.dlp.v2.InspectTemplate; +import com.google.privacy.dlp.v2.JobTrigger; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse; +import com.google.privacy.dlp.v2.ListDlpJobsRequest; +import com.google.privacy.dlp.v2.ListDlpJobsResponse; +import com.google.privacy.dlp.v2.ListInfoTypesRequest; +import com.google.privacy.dlp.v2.ListInfoTypesResponse; +import com.google.privacy.dlp.v2.ListInspectTemplatesRequest; +import com.google.privacy.dlp.v2.ListInspectTemplatesResponse; +import com.google.privacy.dlp.v2.ListJobTriggersRequest; +import com.google.privacy.dlp.v2.ListJobTriggersResponse; +import com.google.privacy.dlp.v2.RedactImageRequest; +import com.google.privacy.dlp.v2.RedactImageResponse; +import com.google.privacy.dlp.v2.ReidentifyContentRequest; +import com.google.privacy.dlp.v2.ReidentifyContentResponse; +import com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.UpdateInspectTemplateRequest; +import com.google.privacy.dlp.v2.UpdateJobTriggerRequest; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link DlpServiceClient}. + * + *

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

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

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

    + * 
    + * DlpServiceSettings.Builder dlpServiceSettingsBuilder =
    + *     DlpServiceSettings.newBuilder();
    + * dlpServiceSettingsBuilder.inspectContentSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * DlpServiceSettings dlpServiceSettings = dlpServiceSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class DlpServiceSettings extends ClientSettings { + /** Returns the object with the settings used for calls to inspectContent. */ + public UnaryCallSettings inspectContentSettings() { + return ((DlpServiceStubSettings) getStubSettings()).inspectContentSettings(); + } + + /** Returns the object with the settings used for calls to redactImage. */ + public UnaryCallSettings redactImageSettings() { + return ((DlpServiceStubSettings) getStubSettings()).redactImageSettings(); + } + + /** Returns the object with the settings used for calls to deidentifyContent. */ + public UnaryCallSettings + deidentifyContentSettings() { + return ((DlpServiceStubSettings) getStubSettings()).deidentifyContentSettings(); + } + + /** Returns the object with the settings used for calls to reidentifyContent. */ + public UnaryCallSettings + reidentifyContentSettings() { + return ((DlpServiceStubSettings) getStubSettings()).reidentifyContentSettings(); + } + + /** Returns the object with the settings used for calls to listInfoTypes. */ + public UnaryCallSettings listInfoTypesSettings() { + return ((DlpServiceStubSettings) getStubSettings()).listInfoTypesSettings(); + } + + /** Returns the object with the settings used for calls to createInspectTemplate. */ + public UnaryCallSettings + createInspectTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).createInspectTemplateSettings(); + } + + /** Returns the object with the settings used for calls to updateInspectTemplate. */ + public UnaryCallSettings + updateInspectTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).updateInspectTemplateSettings(); + } + + /** Returns the object with the settings used for calls to getInspectTemplate. */ + public UnaryCallSettings + getInspectTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).getInspectTemplateSettings(); + } + + /** Returns the object with the settings used for calls to listInspectTemplates. */ + public PagedCallSettings< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse> + listInspectTemplatesSettings() { + return ((DlpServiceStubSettings) getStubSettings()).listInspectTemplatesSettings(); + } + + /** Returns the object with the settings used for calls to deleteInspectTemplate. */ + public UnaryCallSettings deleteInspectTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).deleteInspectTemplateSettings(); + } + + /** Returns the object with the settings used for calls to createDeidentifyTemplate. */ + public UnaryCallSettings + createDeidentifyTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).createDeidentifyTemplateSettings(); + } + + /** Returns the object with the settings used for calls to updateDeidentifyTemplate. */ + public UnaryCallSettings + updateDeidentifyTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).updateDeidentifyTemplateSettings(); + } + + /** Returns the object with the settings used for calls to getDeidentifyTemplate. */ + public UnaryCallSettings + getDeidentifyTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).getDeidentifyTemplateSettings(); + } + + /** Returns the object with the settings used for calls to listDeidentifyTemplates. */ + public PagedCallSettings< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse> + listDeidentifyTemplatesSettings() { + return ((DlpServiceStubSettings) getStubSettings()).listDeidentifyTemplatesSettings(); + } + + /** Returns the object with the settings used for calls to deleteDeidentifyTemplate. */ + public UnaryCallSettings + deleteDeidentifyTemplateSettings() { + return ((DlpServiceStubSettings) getStubSettings()).deleteDeidentifyTemplateSettings(); + } + + /** Returns the object with the settings used for calls to createDlpJob. */ + public UnaryCallSettings createDlpJobSettings() { + return ((DlpServiceStubSettings) getStubSettings()).createDlpJobSettings(); + } + + /** Returns the object with the settings used for calls to listDlpJobs. */ + public PagedCallSettings + listDlpJobsSettings() { + return ((DlpServiceStubSettings) getStubSettings()).listDlpJobsSettings(); + } + + /** Returns the object with the settings used for calls to getDlpJob. */ + public UnaryCallSettings getDlpJobSettings() { + return ((DlpServiceStubSettings) getStubSettings()).getDlpJobSettings(); + } + + /** Returns the object with the settings used for calls to deleteDlpJob. */ + public UnaryCallSettings deleteDlpJobSettings() { + return ((DlpServiceStubSettings) getStubSettings()).deleteDlpJobSettings(); + } + + /** Returns the object with the settings used for calls to cancelDlpJob. */ + public UnaryCallSettings cancelDlpJobSettings() { + return ((DlpServiceStubSettings) getStubSettings()).cancelDlpJobSettings(); + } + + /** Returns the object with the settings used for calls to listJobTriggers. */ + public PagedCallSettings< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse> + listJobTriggersSettings() { + return ((DlpServiceStubSettings) getStubSettings()).listJobTriggersSettings(); + } + + /** Returns the object with the settings used for calls to getJobTrigger. */ + public UnaryCallSettings getJobTriggerSettings() { + return ((DlpServiceStubSettings) getStubSettings()).getJobTriggerSettings(); + } + + /** Returns the object with the settings used for calls to deleteJobTrigger. */ + public UnaryCallSettings deleteJobTriggerSettings() { + return ((DlpServiceStubSettings) getStubSettings()).deleteJobTriggerSettings(); + } + + /** Returns the object with the settings used for calls to updateJobTrigger. */ + public UnaryCallSettings updateJobTriggerSettings() { + return ((DlpServiceStubSettings) getStubSettings()).updateJobTriggerSettings(); + } + + /** Returns the object with the settings used for calls to createJobTrigger. */ + public UnaryCallSettings createJobTriggerSettings() { + return ((DlpServiceStubSettings) getStubSettings()).createJobTriggerSettings(); + } + + public static final DlpServiceSettings create(DlpServiceStubSettings stub) throws IOException { + return new DlpServiceSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return DlpServiceStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return DlpServiceStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DlpServiceStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return DlpServiceStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return DlpServiceStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return DlpServiceStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return DlpServiceStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected DlpServiceSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for DlpServiceSettings. */ + public static class Builder extends ClientSettings.Builder { + protected Builder() throws IOException { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(DlpServiceStubSettings.newBuilder(clientContext)); + } + + private static Builder createDefault() { + return new Builder(DlpServiceStubSettings.newBuilder()); + } + + protected Builder(DlpServiceSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(DlpServiceStubSettings.Builder stubSettings) { + super(stubSettings); + } + + public DlpServiceStubSettings.Builder getStubSettingsBuilder() { + return ((DlpServiceStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to inspectContent. */ + public UnaryCallSettings.Builder + inspectContentSettings() { + return getStubSettingsBuilder().inspectContentSettings(); + } + + /** Returns the builder for the settings used for calls to redactImage. */ + public UnaryCallSettings.Builder + redactImageSettings() { + return getStubSettingsBuilder().redactImageSettings(); + } + + /** Returns the builder for the settings used for calls to deidentifyContent. */ + public UnaryCallSettings.Builder + deidentifyContentSettings() { + return getStubSettingsBuilder().deidentifyContentSettings(); + } + + /** Returns the builder for the settings used for calls to reidentifyContent. */ + public UnaryCallSettings.Builder + reidentifyContentSettings() { + return getStubSettingsBuilder().reidentifyContentSettings(); + } + + /** Returns the builder for the settings used for calls to listInfoTypes. */ + public UnaryCallSettings.Builder + listInfoTypesSettings() { + return getStubSettingsBuilder().listInfoTypesSettings(); + } + + /** Returns the builder for the settings used for calls to createInspectTemplate. */ + public UnaryCallSettings.Builder + createInspectTemplateSettings() { + return getStubSettingsBuilder().createInspectTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to updateInspectTemplate. */ + public UnaryCallSettings.Builder + updateInspectTemplateSettings() { + return getStubSettingsBuilder().updateInspectTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to getInspectTemplate. */ + public UnaryCallSettings.Builder + getInspectTemplateSettings() { + return getStubSettingsBuilder().getInspectTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to listInspectTemplates. */ + public PagedCallSettings.Builder< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse> + listInspectTemplatesSettings() { + return getStubSettingsBuilder().listInspectTemplatesSettings(); + } + + /** Returns the builder for the settings used for calls to deleteInspectTemplate. */ + public UnaryCallSettings.Builder + deleteInspectTemplateSettings() { + return getStubSettingsBuilder().deleteInspectTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to createDeidentifyTemplate. */ + public UnaryCallSettings.Builder + createDeidentifyTemplateSettings() { + return getStubSettingsBuilder().createDeidentifyTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to updateDeidentifyTemplate. */ + public UnaryCallSettings.Builder + updateDeidentifyTemplateSettings() { + return getStubSettingsBuilder().updateDeidentifyTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to getDeidentifyTemplate. */ + public UnaryCallSettings.Builder + getDeidentifyTemplateSettings() { + return getStubSettingsBuilder().getDeidentifyTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to listDeidentifyTemplates. */ + public PagedCallSettings.Builder< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse> + listDeidentifyTemplatesSettings() { + return getStubSettingsBuilder().listDeidentifyTemplatesSettings(); + } + + /** Returns the builder for the settings used for calls to deleteDeidentifyTemplate. */ + public UnaryCallSettings.Builder + deleteDeidentifyTemplateSettings() { + return getStubSettingsBuilder().deleteDeidentifyTemplateSettings(); + } + + /** Returns the builder for the settings used for calls to createDlpJob. */ + public UnaryCallSettings.Builder createDlpJobSettings() { + return getStubSettingsBuilder().createDlpJobSettings(); + } + + /** Returns the builder for the settings used for calls to listDlpJobs. */ + public PagedCallSettings.Builder< + ListDlpJobsRequest, ListDlpJobsResponse, ListDlpJobsPagedResponse> + listDlpJobsSettings() { + return getStubSettingsBuilder().listDlpJobsSettings(); + } + + /** Returns the builder for the settings used for calls to getDlpJob. */ + public UnaryCallSettings.Builder getDlpJobSettings() { + return getStubSettingsBuilder().getDlpJobSettings(); + } + + /** Returns the builder for the settings used for calls to deleteDlpJob. */ + public UnaryCallSettings.Builder deleteDlpJobSettings() { + return getStubSettingsBuilder().deleteDlpJobSettings(); + } + + /** Returns the builder for the settings used for calls to cancelDlpJob. */ + public UnaryCallSettings.Builder cancelDlpJobSettings() { + return getStubSettingsBuilder().cancelDlpJobSettings(); + } + + /** Returns the builder for the settings used for calls to listJobTriggers. */ + public PagedCallSettings.Builder< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse> + listJobTriggersSettings() { + return getStubSettingsBuilder().listJobTriggersSettings(); + } + + /** Returns the builder for the settings used for calls to getJobTrigger. */ + public UnaryCallSettings.Builder getJobTriggerSettings() { + return getStubSettingsBuilder().getJobTriggerSettings(); + } + + /** Returns the builder for the settings used for calls to deleteJobTrigger. */ + public UnaryCallSettings.Builder deleteJobTriggerSettings() { + return getStubSettingsBuilder().deleteJobTriggerSettings(); + } + + /** Returns the builder for the settings used for calls to updateJobTrigger. */ + public UnaryCallSettings.Builder + updateJobTriggerSettings() { + return getStubSettingsBuilder().updateJobTriggerSettings(); + } + + /** Returns the builder for the settings used for calls to createJobTrigger. */ + public UnaryCallSettings.Builder + createJobTriggerSettings() { + return getStubSettingsBuilder().createJobTriggerSettings(); + } + + @Override + public DlpServiceSettings build() throws IOException { + return new DlpServiceSettings(this); + } + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/package-info.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/package-info.java new file mode 100644 index 000000000000..3b2e5d890c52 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/package-info.java @@ -0,0 +1,44 @@ +/* + * Copyright 2018 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. + */ + +/** + * A client to Cloud Data Loss Prevention (DLP) API. + * + *

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

    ================ DlpServiceClient ================ + * + *

    Service Description: The Cloud Data Loss Prevention (DLP) API is a service that allows clients + * to detect the presence of Personally Identifiable Information (PII) and other privacy-sensitive + * data in user-supplied, unstructured data streams, like text blocks or images. The service also + * includes methods for sensitive data redaction and scheduling of data scans on Google Cloud + * Platform based data sets. + * + *

    Sample for DlpServiceClient: + * + *

    + * 
    + * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
    + *   ProjectName parent = ProjectName.of("[PROJECT]");
    + *   InspectContentRequest request = InspectContentRequest.newBuilder()
    + *     .setParent(parent.toString())
    + *     .build();
    + *   InspectContentResponse response = dlpServiceClient.inspectContent(request);
    + * }
    + * 
    + * 
    + */ +package com.google.cloud.dlp.v2; diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/DlpServiceStub.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/DlpServiceStub.java new file mode 100644 index 000000000000..6bfe5d967c64 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/DlpServiceStub.java @@ -0,0 +1,205 @@ +/* + * Copyright 2018 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.cloud.dlp.v2.stub; + +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDlpJobsPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListInspectTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListJobTriggersPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.privacy.dlp.v2.CancelDlpJobRequest; +import com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.CreateDlpJobRequest; +import com.google.privacy.dlp.v2.CreateInspectTemplateRequest; +import com.google.privacy.dlp.v2.CreateJobTriggerRequest; +import com.google.privacy.dlp.v2.DeidentifyContentRequest; +import com.google.privacy.dlp.v2.DeidentifyContentResponse; +import com.google.privacy.dlp.v2.DeidentifyTemplate; +import com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.DeleteDlpJobRequest; +import com.google.privacy.dlp.v2.DeleteInspectTemplateRequest; +import com.google.privacy.dlp.v2.DeleteJobTriggerRequest; +import com.google.privacy.dlp.v2.DlpJob; +import com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.GetDlpJobRequest; +import com.google.privacy.dlp.v2.GetInspectTemplateRequest; +import com.google.privacy.dlp.v2.GetJobTriggerRequest; +import com.google.privacy.dlp.v2.InspectContentRequest; +import com.google.privacy.dlp.v2.InspectContentResponse; +import com.google.privacy.dlp.v2.InspectTemplate; +import com.google.privacy.dlp.v2.JobTrigger; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse; +import com.google.privacy.dlp.v2.ListDlpJobsRequest; +import com.google.privacy.dlp.v2.ListDlpJobsResponse; +import com.google.privacy.dlp.v2.ListInfoTypesRequest; +import com.google.privacy.dlp.v2.ListInfoTypesResponse; +import com.google.privacy.dlp.v2.ListInspectTemplatesRequest; +import com.google.privacy.dlp.v2.ListInspectTemplatesResponse; +import com.google.privacy.dlp.v2.ListJobTriggersRequest; +import com.google.privacy.dlp.v2.ListJobTriggersResponse; +import com.google.privacy.dlp.v2.RedactImageRequest; +import com.google.privacy.dlp.v2.RedactImageResponse; +import com.google.privacy.dlp.v2.ReidentifyContentRequest; +import com.google.privacy.dlp.v2.ReidentifyContentResponse; +import com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.UpdateInspectTemplateRequest; +import com.google.privacy.dlp.v2.UpdateJobTriggerRequest; +import com.google.protobuf.Empty; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Cloud Data Loss Prevention (DLP) API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public abstract class DlpServiceStub implements BackgroundResource { + + public UnaryCallable inspectContentCallable() { + throw new UnsupportedOperationException("Not implemented: inspectContentCallable()"); + } + + public UnaryCallable redactImageCallable() { + throw new UnsupportedOperationException("Not implemented: redactImageCallable()"); + } + + public UnaryCallable + deidentifyContentCallable() { + throw new UnsupportedOperationException("Not implemented: deidentifyContentCallable()"); + } + + public UnaryCallable + reidentifyContentCallable() { + throw new UnsupportedOperationException("Not implemented: reidentifyContentCallable()"); + } + + public UnaryCallable listInfoTypesCallable() { + throw new UnsupportedOperationException("Not implemented: listInfoTypesCallable()"); + } + + public UnaryCallable + createInspectTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: createInspectTemplateCallable()"); + } + + public UnaryCallable + updateInspectTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: updateInspectTemplateCallable()"); + } + + public UnaryCallable getInspectTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: getInspectTemplateCallable()"); + } + + public UnaryCallable + listInspectTemplatesPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listInspectTemplatesPagedCallable()"); + } + + public UnaryCallable + listInspectTemplatesCallable() { + throw new UnsupportedOperationException("Not implemented: listInspectTemplatesCallable()"); + } + + public UnaryCallable deleteInspectTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: deleteInspectTemplateCallable()"); + } + + public UnaryCallable + createDeidentifyTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: createDeidentifyTemplateCallable()"); + } + + public UnaryCallable + updateDeidentifyTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: updateDeidentifyTemplateCallable()"); + } + + public UnaryCallable + getDeidentifyTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: getDeidentifyTemplateCallable()"); + } + + public UnaryCallable + listDeidentifyTemplatesPagedCallable() { + throw new UnsupportedOperationException( + "Not implemented: listDeidentifyTemplatesPagedCallable()"); + } + + public UnaryCallable + listDeidentifyTemplatesCallable() { + throw new UnsupportedOperationException("Not implemented: listDeidentifyTemplatesCallable()"); + } + + public UnaryCallable deleteDeidentifyTemplateCallable() { + throw new UnsupportedOperationException("Not implemented: deleteDeidentifyTemplateCallable()"); + } + + public UnaryCallable createDlpJobCallable() { + throw new UnsupportedOperationException("Not implemented: createDlpJobCallable()"); + } + + public UnaryCallable listDlpJobsPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listDlpJobsPagedCallable()"); + } + + public UnaryCallable listDlpJobsCallable() { + throw new UnsupportedOperationException("Not implemented: listDlpJobsCallable()"); + } + + public UnaryCallable getDlpJobCallable() { + throw new UnsupportedOperationException("Not implemented: getDlpJobCallable()"); + } + + public UnaryCallable deleteDlpJobCallable() { + throw new UnsupportedOperationException("Not implemented: deleteDlpJobCallable()"); + } + + public UnaryCallable cancelDlpJobCallable() { + throw new UnsupportedOperationException("Not implemented: cancelDlpJobCallable()"); + } + + public UnaryCallable + listJobTriggersPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listJobTriggersPagedCallable()"); + } + + public UnaryCallable listJobTriggersCallable() { + throw new UnsupportedOperationException("Not implemented: listJobTriggersCallable()"); + } + + public UnaryCallable getJobTriggerCallable() { + throw new UnsupportedOperationException("Not implemented: getJobTriggerCallable()"); + } + + public UnaryCallable deleteJobTriggerCallable() { + throw new UnsupportedOperationException("Not implemented: deleteJobTriggerCallable()"); + } + + public UnaryCallable updateJobTriggerCallable() { + throw new UnsupportedOperationException("Not implemented: updateJobTriggerCallable()"); + } + + public UnaryCallable createJobTriggerCallable() { + throw new UnsupportedOperationException("Not implemented: createJobTriggerCallable()"); + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/DlpServiceStubSettings.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/DlpServiceStubSettings.java new file mode 100644 index 000000000000..72a5bc039c08 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/DlpServiceStubSettings.java @@ -0,0 +1,1190 @@ +/* + * Copyright 2018 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.cloud.dlp.v2.stub; + +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDlpJobsPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListInspectTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListJobTriggersPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.PageContext; +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.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.privacy.dlp.v2.CancelDlpJobRequest; +import com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.CreateDlpJobRequest; +import com.google.privacy.dlp.v2.CreateInspectTemplateRequest; +import com.google.privacy.dlp.v2.CreateJobTriggerRequest; +import com.google.privacy.dlp.v2.DeidentifyContentRequest; +import com.google.privacy.dlp.v2.DeidentifyContentResponse; +import com.google.privacy.dlp.v2.DeidentifyTemplate; +import com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.DeleteDlpJobRequest; +import com.google.privacy.dlp.v2.DeleteInspectTemplateRequest; +import com.google.privacy.dlp.v2.DeleteJobTriggerRequest; +import com.google.privacy.dlp.v2.DlpJob; +import com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.GetDlpJobRequest; +import com.google.privacy.dlp.v2.GetInspectTemplateRequest; +import com.google.privacy.dlp.v2.GetJobTriggerRequest; +import com.google.privacy.dlp.v2.InspectContentRequest; +import com.google.privacy.dlp.v2.InspectContentResponse; +import com.google.privacy.dlp.v2.InspectTemplate; +import com.google.privacy.dlp.v2.JobTrigger; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse; +import com.google.privacy.dlp.v2.ListDlpJobsRequest; +import com.google.privacy.dlp.v2.ListDlpJobsResponse; +import com.google.privacy.dlp.v2.ListInfoTypesRequest; +import com.google.privacy.dlp.v2.ListInfoTypesResponse; +import com.google.privacy.dlp.v2.ListInspectTemplatesRequest; +import com.google.privacy.dlp.v2.ListInspectTemplatesResponse; +import com.google.privacy.dlp.v2.ListJobTriggersRequest; +import com.google.privacy.dlp.v2.ListJobTriggersResponse; +import com.google.privacy.dlp.v2.RedactImageRequest; +import com.google.privacy.dlp.v2.RedactImageResponse; +import com.google.privacy.dlp.v2.ReidentifyContentRequest; +import com.google.privacy.dlp.v2.ReidentifyContentResponse; +import com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.UpdateInspectTemplateRequest; +import com.google.privacy.dlp.v2.UpdateJobTriggerRequest; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link DlpServiceStub}. + * + *

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

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

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

    + * 
    + * DlpServiceStubSettings.Builder dlpServiceSettingsBuilder =
    + *     DlpServiceStubSettings.newBuilder();
    + * dlpServiceSettingsBuilder.inspectContentSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * DlpServiceStubSettings dlpServiceSettings = dlpServiceSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class DlpServiceStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + + private final UnaryCallSettings + inspectContentSettings; + private final UnaryCallSettings redactImageSettings; + private final UnaryCallSettings + deidentifyContentSettings; + private final UnaryCallSettings + reidentifyContentSettings; + private final UnaryCallSettings + listInfoTypesSettings; + private final UnaryCallSettings + createInspectTemplateSettings; + private final UnaryCallSettings + updateInspectTemplateSettings; + private final UnaryCallSettings + getInspectTemplateSettings; + private final PagedCallSettings< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse> + listInspectTemplatesSettings; + private final UnaryCallSettings + deleteInspectTemplateSettings; + private final UnaryCallSettings + createDeidentifyTemplateSettings; + private final UnaryCallSettings + updateDeidentifyTemplateSettings; + private final UnaryCallSettings + getDeidentifyTemplateSettings; + private final PagedCallSettings< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse> + listDeidentifyTemplatesSettings; + private final UnaryCallSettings + deleteDeidentifyTemplateSettings; + private final UnaryCallSettings createDlpJobSettings; + private final PagedCallSettings + listDlpJobsSettings; + private final UnaryCallSettings getDlpJobSettings; + private final UnaryCallSettings deleteDlpJobSettings; + private final UnaryCallSettings cancelDlpJobSettings; + private final PagedCallSettings< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse> + listJobTriggersSettings; + private final UnaryCallSettings getJobTriggerSettings; + private final UnaryCallSettings deleteJobTriggerSettings; + private final UnaryCallSettings updateJobTriggerSettings; + private final UnaryCallSettings createJobTriggerSettings; + + /** Returns the object with the settings used for calls to inspectContent. */ + public UnaryCallSettings inspectContentSettings() { + return inspectContentSettings; + } + + /** Returns the object with the settings used for calls to redactImage. */ + public UnaryCallSettings redactImageSettings() { + return redactImageSettings; + } + + /** Returns the object with the settings used for calls to deidentifyContent. */ + public UnaryCallSettings + deidentifyContentSettings() { + return deidentifyContentSettings; + } + + /** Returns the object with the settings used for calls to reidentifyContent. */ + public UnaryCallSettings + reidentifyContentSettings() { + return reidentifyContentSettings; + } + + /** Returns the object with the settings used for calls to listInfoTypes. */ + public UnaryCallSettings listInfoTypesSettings() { + return listInfoTypesSettings; + } + + /** Returns the object with the settings used for calls to createInspectTemplate. */ + public UnaryCallSettings + createInspectTemplateSettings() { + return createInspectTemplateSettings; + } + + /** Returns the object with the settings used for calls to updateInspectTemplate. */ + public UnaryCallSettings + updateInspectTemplateSettings() { + return updateInspectTemplateSettings; + } + + /** Returns the object with the settings used for calls to getInspectTemplate. */ + public UnaryCallSettings + getInspectTemplateSettings() { + return getInspectTemplateSettings; + } + + /** Returns the object with the settings used for calls to listInspectTemplates. */ + public PagedCallSettings< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse> + listInspectTemplatesSettings() { + return listInspectTemplatesSettings; + } + + /** Returns the object with the settings used for calls to deleteInspectTemplate. */ + public UnaryCallSettings deleteInspectTemplateSettings() { + return deleteInspectTemplateSettings; + } + + /** Returns the object with the settings used for calls to createDeidentifyTemplate. */ + public UnaryCallSettings + createDeidentifyTemplateSettings() { + return createDeidentifyTemplateSettings; + } + + /** Returns the object with the settings used for calls to updateDeidentifyTemplate. */ + public UnaryCallSettings + updateDeidentifyTemplateSettings() { + return updateDeidentifyTemplateSettings; + } + + /** Returns the object with the settings used for calls to getDeidentifyTemplate. */ + public UnaryCallSettings + getDeidentifyTemplateSettings() { + return getDeidentifyTemplateSettings; + } + + /** Returns the object with the settings used for calls to listDeidentifyTemplates. */ + public PagedCallSettings< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse> + listDeidentifyTemplatesSettings() { + return listDeidentifyTemplatesSettings; + } + + /** Returns the object with the settings used for calls to deleteDeidentifyTemplate. */ + public UnaryCallSettings + deleteDeidentifyTemplateSettings() { + return deleteDeidentifyTemplateSettings; + } + + /** Returns the object with the settings used for calls to createDlpJob. */ + public UnaryCallSettings createDlpJobSettings() { + return createDlpJobSettings; + } + + /** Returns the object with the settings used for calls to listDlpJobs. */ + public PagedCallSettings + listDlpJobsSettings() { + return listDlpJobsSettings; + } + + /** Returns the object with the settings used for calls to getDlpJob. */ + public UnaryCallSettings getDlpJobSettings() { + return getDlpJobSettings; + } + + /** Returns the object with the settings used for calls to deleteDlpJob. */ + public UnaryCallSettings deleteDlpJobSettings() { + return deleteDlpJobSettings; + } + + /** Returns the object with the settings used for calls to cancelDlpJob. */ + public UnaryCallSettings cancelDlpJobSettings() { + return cancelDlpJobSettings; + } + + /** Returns the object with the settings used for calls to listJobTriggers. */ + public PagedCallSettings< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse> + listJobTriggersSettings() { + return listJobTriggersSettings; + } + + /** Returns the object with the settings used for calls to getJobTrigger. */ + public UnaryCallSettings getJobTriggerSettings() { + return getJobTriggerSettings; + } + + /** Returns the object with the settings used for calls to deleteJobTrigger. */ + public UnaryCallSettings deleteJobTriggerSettings() { + return deleteJobTriggerSettings; + } + + /** Returns the object with the settings used for calls to updateJobTrigger. */ + public UnaryCallSettings updateJobTriggerSettings() { + return updateJobTriggerSettings; + } + + /** Returns the object with the settings used for calls to createJobTrigger. */ + public UnaryCallSettings createJobTriggerSettings() { + return createJobTriggerSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public DlpServiceStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcDlpServiceStub.create(this); + } else { + throw new UnsupportedOperationException( + "Transport not supported: " + getTransportChannelProvider().getTransportName()); + } + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "dlp.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(DlpServiceStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected DlpServiceStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + inspectContentSettings = settingsBuilder.inspectContentSettings().build(); + redactImageSettings = settingsBuilder.redactImageSettings().build(); + deidentifyContentSettings = settingsBuilder.deidentifyContentSettings().build(); + reidentifyContentSettings = settingsBuilder.reidentifyContentSettings().build(); + listInfoTypesSettings = settingsBuilder.listInfoTypesSettings().build(); + createInspectTemplateSettings = settingsBuilder.createInspectTemplateSettings().build(); + updateInspectTemplateSettings = settingsBuilder.updateInspectTemplateSettings().build(); + getInspectTemplateSettings = settingsBuilder.getInspectTemplateSettings().build(); + listInspectTemplatesSettings = settingsBuilder.listInspectTemplatesSettings().build(); + deleteInspectTemplateSettings = settingsBuilder.deleteInspectTemplateSettings().build(); + createDeidentifyTemplateSettings = settingsBuilder.createDeidentifyTemplateSettings().build(); + updateDeidentifyTemplateSettings = settingsBuilder.updateDeidentifyTemplateSettings().build(); + getDeidentifyTemplateSettings = settingsBuilder.getDeidentifyTemplateSettings().build(); + listDeidentifyTemplatesSettings = settingsBuilder.listDeidentifyTemplatesSettings().build(); + deleteDeidentifyTemplateSettings = settingsBuilder.deleteDeidentifyTemplateSettings().build(); + createDlpJobSettings = settingsBuilder.createDlpJobSettings().build(); + listDlpJobsSettings = settingsBuilder.listDlpJobsSettings().build(); + getDlpJobSettings = settingsBuilder.getDlpJobSettings().build(); + deleteDlpJobSettings = settingsBuilder.deleteDlpJobSettings().build(); + cancelDlpJobSettings = settingsBuilder.cancelDlpJobSettings().build(); + listJobTriggersSettings = settingsBuilder.listJobTriggersSettings().build(); + getJobTriggerSettings = settingsBuilder.getJobTriggerSettings().build(); + deleteJobTriggerSettings = settingsBuilder.deleteJobTriggerSettings().build(); + updateJobTriggerSettings = settingsBuilder.updateJobTriggerSettings().build(); + createJobTriggerSettings = settingsBuilder.createJobTriggerSettings().build(); + } + + private static final PagedListDescriptor< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, InspectTemplate> + LIST_INSPECT_TEMPLATES_PAGE_STR_DESC = + new PagedListDescriptor< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, InspectTemplate>() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListInspectTemplatesRequest injectToken( + ListInspectTemplatesRequest payload, String token) { + return ListInspectTemplatesRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListInspectTemplatesRequest injectPageSize( + ListInspectTemplatesRequest payload, int pageSize) { + return ListInspectTemplatesRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListInspectTemplatesRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListInspectTemplatesResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources( + ListInspectTemplatesResponse payload) { + return payload.getInspectTemplatesList(); + } + }; + + private static final PagedListDescriptor< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, DeidentifyTemplate> + LIST_DEIDENTIFY_TEMPLATES_PAGE_STR_DESC = + new PagedListDescriptor< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + DeidentifyTemplate>() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListDeidentifyTemplatesRequest injectToken( + ListDeidentifyTemplatesRequest payload, String token) { + return ListDeidentifyTemplatesRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListDeidentifyTemplatesRequest injectPageSize( + ListDeidentifyTemplatesRequest payload, int pageSize) { + return ListDeidentifyTemplatesRequest.newBuilder(payload) + .setPageSize(pageSize) + .build(); + } + + @Override + public Integer extractPageSize(ListDeidentifyTemplatesRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListDeidentifyTemplatesResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources( + ListDeidentifyTemplatesResponse payload) { + return payload.getDeidentifyTemplatesList(); + } + }; + + private static final PagedListDescriptor + LIST_DLP_JOBS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListDlpJobsRequest injectToken(ListDlpJobsRequest payload, String token) { + return ListDlpJobsRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListDlpJobsRequest injectPageSize(ListDlpJobsRequest payload, int pageSize) { + return ListDlpJobsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListDlpJobsRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListDlpJobsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListDlpJobsResponse payload) { + return payload.getJobsList(); + } + }; + + private static final PagedListDescriptor< + ListJobTriggersRequest, ListJobTriggersResponse, JobTrigger> + LIST_JOB_TRIGGERS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListJobTriggersRequest injectToken( + ListJobTriggersRequest payload, String token) { + return ListJobTriggersRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListJobTriggersRequest injectPageSize( + ListJobTriggersRequest payload, int pageSize) { + return ListJobTriggersRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListJobTriggersRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListJobTriggersResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListJobTriggersResponse payload) { + return payload.getJobTriggersList(); + } + }; + + private static final PagedListResponseFactory< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse> + LIST_INSPECT_TEMPLATES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListInspectTemplatesRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, InspectTemplate> + pageContext = + PageContext.create( + callable, LIST_INSPECT_TEMPLATES_PAGE_STR_DESC, request, context); + return ListInspectTemplatesPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + private static final PagedListResponseFactory< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse> + LIST_DEIDENTIFY_TEMPLATES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable + callable, + ListDeidentifyTemplatesRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + DeidentifyTemplate> + pageContext = + PageContext.create( + callable, LIST_DEIDENTIFY_TEMPLATES_PAGE_STR_DESC, request, context); + return ListDeidentifyTemplatesPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + private static final PagedListResponseFactory< + ListDlpJobsRequest, ListDlpJobsResponse, ListDlpJobsPagedResponse> + LIST_DLP_JOBS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListDlpJobsRequest, ListDlpJobsResponse, ListDlpJobsPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListDlpJobsRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_DLP_JOBS_PAGE_STR_DESC, request, context); + return ListDlpJobsPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + private static final PagedListResponseFactory< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse> + LIST_JOB_TRIGGERS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListJobTriggersRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_JOB_TRIGGERS_PAGE_STR_DESC, request, context); + return ListJobTriggersPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Builder for DlpServiceStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder + inspectContentSettings; + private final UnaryCallSettings.Builder + redactImageSettings; + private final UnaryCallSettings.Builder + deidentifyContentSettings; + private final UnaryCallSettings.Builder + reidentifyContentSettings; + private final UnaryCallSettings.Builder + listInfoTypesSettings; + private final UnaryCallSettings.Builder + createInspectTemplateSettings; + private final UnaryCallSettings.Builder + updateInspectTemplateSettings; + private final UnaryCallSettings.Builder + getInspectTemplateSettings; + private final PagedCallSettings.Builder< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse> + listInspectTemplatesSettings; + private final UnaryCallSettings.Builder + deleteInspectTemplateSettings; + private final UnaryCallSettings.Builder + createDeidentifyTemplateSettings; + private final UnaryCallSettings.Builder + updateDeidentifyTemplateSettings; + private final UnaryCallSettings.Builder + getDeidentifyTemplateSettings; + private final PagedCallSettings.Builder< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse> + listDeidentifyTemplatesSettings; + private final UnaryCallSettings.Builder + deleteDeidentifyTemplateSettings; + private final UnaryCallSettings.Builder createDlpJobSettings; + private final PagedCallSettings.Builder< + ListDlpJobsRequest, ListDlpJobsResponse, ListDlpJobsPagedResponse> + listDlpJobsSettings; + private final UnaryCallSettings.Builder getDlpJobSettings; + private final UnaryCallSettings.Builder deleteDlpJobSettings; + private final UnaryCallSettings.Builder cancelDlpJobSettings; + private final PagedCallSettings.Builder< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse> + listJobTriggersSettings; + private final UnaryCallSettings.Builder getJobTriggerSettings; + private final UnaryCallSettings.Builder + deleteJobTriggerSettings; + private final UnaryCallSettings.Builder + updateJobTriggerSettings; + private final UnaryCallSettings.Builder + createJobTriggerSettings; + + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "idempotent", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); + definitions.put("non_idempotent", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(20000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(20000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("default", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + inspectContentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + redactImageSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + deidentifyContentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + reidentifyContentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listInfoTypesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createInspectTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + updateInspectTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + getInspectTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listInspectTemplatesSettings = + PagedCallSettings.newBuilder(LIST_INSPECT_TEMPLATES_PAGE_STR_FACT); + + deleteInspectTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createDeidentifyTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + updateDeidentifyTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + getDeidentifyTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listDeidentifyTemplatesSettings = + PagedCallSettings.newBuilder(LIST_DEIDENTIFY_TEMPLATES_PAGE_STR_FACT); + + deleteDeidentifyTemplateSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createDlpJobSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listDlpJobsSettings = PagedCallSettings.newBuilder(LIST_DLP_JOBS_PAGE_STR_FACT); + + getDlpJobSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + deleteDlpJobSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + cancelDlpJobSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listJobTriggersSettings = PagedCallSettings.newBuilder(LIST_JOB_TRIGGERS_PAGE_STR_FACT); + + getJobTriggerSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + deleteJobTriggerSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + updateJobTriggerSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createJobTriggerSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + inspectContentSettings, + redactImageSettings, + deidentifyContentSettings, + reidentifyContentSettings, + listInfoTypesSettings, + createInspectTemplateSettings, + updateInspectTemplateSettings, + getInspectTemplateSettings, + listInspectTemplatesSettings, + deleteInspectTemplateSettings, + createDeidentifyTemplateSettings, + updateDeidentifyTemplateSettings, + getDeidentifyTemplateSettings, + listDeidentifyTemplatesSettings, + deleteDeidentifyTemplateSettings, + createDlpJobSettings, + listDlpJobsSettings, + getDlpJobSettings, + deleteDlpJobSettings, + cancelDlpJobSettings, + listJobTriggersSettings, + getJobTriggerSettings, + deleteJobTriggerSettings, + updateJobTriggerSettings, + createJobTriggerSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .inspectContentSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .redactImageSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deidentifyContentSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .reidentifyContentSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listInfoTypesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .createInspectTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .updateInspectTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getInspectTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listInspectTemplatesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deleteInspectTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .createDeidentifyTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .updateDeidentifyTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getDeidentifyTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listDeidentifyTemplatesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deleteDeidentifyTemplateSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .createDlpJobSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listDlpJobsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getDlpJobSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deleteDlpJobSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .cancelDlpJobSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listJobTriggersSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getJobTriggerSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deleteJobTriggerSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .updateJobTriggerSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .createJobTriggerSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + return builder; + } + + protected Builder(DlpServiceStubSettings settings) { + super(settings); + + inspectContentSettings = settings.inspectContentSettings.toBuilder(); + redactImageSettings = settings.redactImageSettings.toBuilder(); + deidentifyContentSettings = settings.deidentifyContentSettings.toBuilder(); + reidentifyContentSettings = settings.reidentifyContentSettings.toBuilder(); + listInfoTypesSettings = settings.listInfoTypesSettings.toBuilder(); + createInspectTemplateSettings = settings.createInspectTemplateSettings.toBuilder(); + updateInspectTemplateSettings = settings.updateInspectTemplateSettings.toBuilder(); + getInspectTemplateSettings = settings.getInspectTemplateSettings.toBuilder(); + listInspectTemplatesSettings = settings.listInspectTemplatesSettings.toBuilder(); + deleteInspectTemplateSettings = settings.deleteInspectTemplateSettings.toBuilder(); + createDeidentifyTemplateSettings = settings.createDeidentifyTemplateSettings.toBuilder(); + updateDeidentifyTemplateSettings = settings.updateDeidentifyTemplateSettings.toBuilder(); + getDeidentifyTemplateSettings = settings.getDeidentifyTemplateSettings.toBuilder(); + listDeidentifyTemplatesSettings = settings.listDeidentifyTemplatesSettings.toBuilder(); + deleteDeidentifyTemplateSettings = settings.deleteDeidentifyTemplateSettings.toBuilder(); + createDlpJobSettings = settings.createDlpJobSettings.toBuilder(); + listDlpJobsSettings = settings.listDlpJobsSettings.toBuilder(); + getDlpJobSettings = settings.getDlpJobSettings.toBuilder(); + deleteDlpJobSettings = settings.deleteDlpJobSettings.toBuilder(); + cancelDlpJobSettings = settings.cancelDlpJobSettings.toBuilder(); + listJobTriggersSettings = settings.listJobTriggersSettings.toBuilder(); + getJobTriggerSettings = settings.getJobTriggerSettings.toBuilder(); + deleteJobTriggerSettings = settings.deleteJobTriggerSettings.toBuilder(); + updateJobTriggerSettings = settings.updateJobTriggerSettings.toBuilder(); + createJobTriggerSettings = settings.createJobTriggerSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + inspectContentSettings, + redactImageSettings, + deidentifyContentSettings, + reidentifyContentSettings, + listInfoTypesSettings, + createInspectTemplateSettings, + updateInspectTemplateSettings, + getInspectTemplateSettings, + listInspectTemplatesSettings, + deleteInspectTemplateSettings, + createDeidentifyTemplateSettings, + updateDeidentifyTemplateSettings, + getDeidentifyTemplateSettings, + listDeidentifyTemplatesSettings, + deleteDeidentifyTemplateSettings, + createDlpJobSettings, + listDlpJobsSettings, + getDlpJobSettings, + deleteDlpJobSettings, + cancelDlpJobSettings, + listJobTriggersSettings, + getJobTriggerSettings, + deleteJobTriggerSettings, + updateJobTriggerSettings, + createJobTriggerSettings); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to inspectContent. */ + public UnaryCallSettings.Builder + inspectContentSettings() { + return inspectContentSettings; + } + + /** Returns the builder for the settings used for calls to redactImage. */ + public UnaryCallSettings.Builder + redactImageSettings() { + return redactImageSettings; + } + + /** Returns the builder for the settings used for calls to deidentifyContent. */ + public UnaryCallSettings.Builder + deidentifyContentSettings() { + return deidentifyContentSettings; + } + + /** Returns the builder for the settings used for calls to reidentifyContent. */ + public UnaryCallSettings.Builder + reidentifyContentSettings() { + return reidentifyContentSettings; + } + + /** Returns the builder for the settings used for calls to listInfoTypes. */ + public UnaryCallSettings.Builder + listInfoTypesSettings() { + return listInfoTypesSettings; + } + + /** Returns the builder for the settings used for calls to createInspectTemplate. */ + public UnaryCallSettings.Builder + createInspectTemplateSettings() { + return createInspectTemplateSettings; + } + + /** Returns the builder for the settings used for calls to updateInspectTemplate. */ + public UnaryCallSettings.Builder + updateInspectTemplateSettings() { + return updateInspectTemplateSettings; + } + + /** Returns the builder for the settings used for calls to getInspectTemplate. */ + public UnaryCallSettings.Builder + getInspectTemplateSettings() { + return getInspectTemplateSettings; + } + + /** Returns the builder for the settings used for calls to listInspectTemplates. */ + public PagedCallSettings.Builder< + ListInspectTemplatesRequest, ListInspectTemplatesResponse, + ListInspectTemplatesPagedResponse> + listInspectTemplatesSettings() { + return listInspectTemplatesSettings; + } + + /** Returns the builder for the settings used for calls to deleteInspectTemplate. */ + public UnaryCallSettings.Builder + deleteInspectTemplateSettings() { + return deleteInspectTemplateSettings; + } + + /** Returns the builder for the settings used for calls to createDeidentifyTemplate. */ + public UnaryCallSettings.Builder + createDeidentifyTemplateSettings() { + return createDeidentifyTemplateSettings; + } + + /** Returns the builder for the settings used for calls to updateDeidentifyTemplate. */ + public UnaryCallSettings.Builder + updateDeidentifyTemplateSettings() { + return updateDeidentifyTemplateSettings; + } + + /** Returns the builder for the settings used for calls to getDeidentifyTemplate. */ + public UnaryCallSettings.Builder + getDeidentifyTemplateSettings() { + return getDeidentifyTemplateSettings; + } + + /** Returns the builder for the settings used for calls to listDeidentifyTemplates. */ + public PagedCallSettings.Builder< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse, + ListDeidentifyTemplatesPagedResponse> + listDeidentifyTemplatesSettings() { + return listDeidentifyTemplatesSettings; + } + + /** Returns the builder for the settings used for calls to deleteDeidentifyTemplate. */ + public UnaryCallSettings.Builder + deleteDeidentifyTemplateSettings() { + return deleteDeidentifyTemplateSettings; + } + + /** Returns the builder for the settings used for calls to createDlpJob. */ + public UnaryCallSettings.Builder createDlpJobSettings() { + return createDlpJobSettings; + } + + /** Returns the builder for the settings used for calls to listDlpJobs. */ + public PagedCallSettings.Builder< + ListDlpJobsRequest, ListDlpJobsResponse, ListDlpJobsPagedResponse> + listDlpJobsSettings() { + return listDlpJobsSettings; + } + + /** Returns the builder for the settings used for calls to getDlpJob. */ + public UnaryCallSettings.Builder getDlpJobSettings() { + return getDlpJobSettings; + } + + /** Returns the builder for the settings used for calls to deleteDlpJob. */ + public UnaryCallSettings.Builder deleteDlpJobSettings() { + return deleteDlpJobSettings; + } + + /** Returns the builder for the settings used for calls to cancelDlpJob. */ + public UnaryCallSettings.Builder cancelDlpJobSettings() { + return cancelDlpJobSettings; + } + + /** Returns the builder for the settings used for calls to listJobTriggers. */ + public PagedCallSettings.Builder< + ListJobTriggersRequest, ListJobTriggersResponse, ListJobTriggersPagedResponse> + listJobTriggersSettings() { + return listJobTriggersSettings; + } + + /** Returns the builder for the settings used for calls to getJobTrigger. */ + public UnaryCallSettings.Builder getJobTriggerSettings() { + return getJobTriggerSettings; + } + + /** Returns the builder for the settings used for calls to deleteJobTrigger. */ + public UnaryCallSettings.Builder deleteJobTriggerSettings() { + return deleteJobTriggerSettings; + } + + /** Returns the builder for the settings used for calls to updateJobTrigger. */ + public UnaryCallSettings.Builder + updateJobTriggerSettings() { + return updateJobTriggerSettings; + } + + /** Returns the builder for the settings used for calls to createJobTrigger. */ + public UnaryCallSettings.Builder + createJobTriggerSettings() { + return createJobTriggerSettings; + } + + @Override + public DlpServiceStubSettings build() throws IOException { + return new DlpServiceStubSettings(this); + } + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/GrpcDlpServiceCallableFactory.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/GrpcDlpServiceCallableFactory.java new file mode 100644 index 000000000000..bdbd80542487 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/GrpcDlpServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dlp.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Data Loss Prevention (DLP) API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcDlpServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/GrpcDlpServiceStub.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/GrpcDlpServiceStub.java new file mode 100644 index 000000000000..2d1d85bb2038 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2/stub/GrpcDlpServiceStub.java @@ -0,0 +1,790 @@ +/* + * Copyright 2018 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.cloud.dlp.v2.stub; + +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDeidentifyTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListDlpJobsPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListInspectTemplatesPagedResponse; +import static com.google.cloud.dlp.v2.DlpServiceClient.ListJobTriggersPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +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.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.privacy.dlp.v2.CancelDlpJobRequest; +import com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.CreateDlpJobRequest; +import com.google.privacy.dlp.v2.CreateInspectTemplateRequest; +import com.google.privacy.dlp.v2.CreateJobTriggerRequest; +import com.google.privacy.dlp.v2.DeidentifyContentRequest; +import com.google.privacy.dlp.v2.DeidentifyContentResponse; +import com.google.privacy.dlp.v2.DeidentifyTemplate; +import com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.DeleteDlpJobRequest; +import com.google.privacy.dlp.v2.DeleteInspectTemplateRequest; +import com.google.privacy.dlp.v2.DeleteJobTriggerRequest; +import com.google.privacy.dlp.v2.DlpJob; +import com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.GetDlpJobRequest; +import com.google.privacy.dlp.v2.GetInspectTemplateRequest; +import com.google.privacy.dlp.v2.GetJobTriggerRequest; +import com.google.privacy.dlp.v2.InspectContentRequest; +import com.google.privacy.dlp.v2.InspectContentResponse; +import com.google.privacy.dlp.v2.InspectTemplate; +import com.google.privacy.dlp.v2.JobTrigger; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse; +import com.google.privacy.dlp.v2.ListDlpJobsRequest; +import com.google.privacy.dlp.v2.ListDlpJobsResponse; +import com.google.privacy.dlp.v2.ListInfoTypesRequest; +import com.google.privacy.dlp.v2.ListInfoTypesResponse; +import com.google.privacy.dlp.v2.ListInspectTemplatesRequest; +import com.google.privacy.dlp.v2.ListInspectTemplatesResponse; +import com.google.privacy.dlp.v2.ListJobTriggersRequest; +import com.google.privacy.dlp.v2.ListJobTriggersResponse; +import com.google.privacy.dlp.v2.RedactImageRequest; +import com.google.privacy.dlp.v2.RedactImageResponse; +import com.google.privacy.dlp.v2.ReidentifyContentRequest; +import com.google.privacy.dlp.v2.ReidentifyContentResponse; +import com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.UpdateInspectTemplateRequest; +import com.google.privacy.dlp.v2.UpdateJobTriggerRequest; +import com.google.protobuf.Empty; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC stub implementation for Cloud Data Loss Prevention (DLP) API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class GrpcDlpServiceStub extends DlpServiceStub { + + private static final MethodDescriptor + inspectContentMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/InspectContent") + .setRequestMarshaller( + ProtoUtils.marshaller(InspectContentRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(InspectContentResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + redactImageMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/RedactImage") + .setRequestMarshaller(ProtoUtils.marshaller(RedactImageRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(RedactImageResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + deidentifyContentMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/DeidentifyContent") + .setRequestMarshaller( + ProtoUtils.marshaller(DeidentifyContentRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(DeidentifyContentResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + reidentifyContentMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/ReidentifyContent") + .setRequestMarshaller( + ProtoUtils.marshaller(ReidentifyContentRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ReidentifyContentResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listInfoTypesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/ListInfoTypes") + .setRequestMarshaller( + ProtoUtils.marshaller(ListInfoTypesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListInfoTypesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + createInspectTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/CreateInspectTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateInspectTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(InspectTemplate.getDefaultInstance())) + .build(); + private static final MethodDescriptor + updateInspectTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/UpdateInspectTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(UpdateInspectTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(InspectTemplate.getDefaultInstance())) + .build(); + private static final MethodDescriptor + getInspectTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/GetInspectTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(GetInspectTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(InspectTemplate.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listInspectTemplatesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/ListInspectTemplates") + .setRequestMarshaller( + ProtoUtils.marshaller(ListInspectTemplatesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListInspectTemplatesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + deleteInspectTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/DeleteInspectTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(DeleteInspectTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor + createDeidentifyTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/CreateDeidentifyTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateDeidentifyTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(DeidentifyTemplate.getDefaultInstance())) + .build(); + private static final MethodDescriptor + updateDeidentifyTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/UpdateDeidentifyTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(UpdateDeidentifyTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(DeidentifyTemplate.getDefaultInstance())) + .build(); + private static final MethodDescriptor + getDeidentifyTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/GetDeidentifyTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(GetDeidentifyTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(DeidentifyTemplate.getDefaultInstance())) + .build(); + private static final MethodDescriptor< + ListDeidentifyTemplatesRequest, ListDeidentifyTemplatesResponse> + listDeidentifyTemplatesMethodDescriptor = + MethodDescriptor + .newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/ListDeidentifyTemplates") + .setRequestMarshaller( + ProtoUtils.marshaller(ListDeidentifyTemplatesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListDeidentifyTemplatesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + deleteDeidentifyTemplateMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/DeleteDeidentifyTemplate") + .setRequestMarshaller( + ProtoUtils.marshaller(DeleteDeidentifyTemplateRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor createDlpJobMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/CreateDlpJob") + .setRequestMarshaller(ProtoUtils.marshaller(CreateDlpJobRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(DlpJob.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listDlpJobsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/ListDlpJobs") + .setRequestMarshaller(ProtoUtils.marshaller(ListDlpJobsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListDlpJobsResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor getDlpJobMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/GetDlpJob") + .setRequestMarshaller(ProtoUtils.marshaller(GetDlpJobRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(DlpJob.getDefaultInstance())) + .build(); + private static final MethodDescriptor deleteDlpJobMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/DeleteDlpJob") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteDlpJobRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor cancelDlpJobMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/CancelDlpJob") + .setRequestMarshaller(ProtoUtils.marshaller(CancelDlpJobRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listJobTriggersMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/ListJobTriggers") + .setRequestMarshaller( + ProtoUtils.marshaller(ListJobTriggersRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListJobTriggersResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + getJobTriggerMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/GetJobTrigger") + .setRequestMarshaller( + ProtoUtils.marshaller(GetJobTriggerRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(JobTrigger.getDefaultInstance())) + .build(); + private static final MethodDescriptor + deleteJobTriggerMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/DeleteJobTrigger") + .setRequestMarshaller( + ProtoUtils.marshaller(DeleteJobTriggerRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor + updateJobTriggerMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/UpdateJobTrigger") + .setRequestMarshaller( + ProtoUtils.marshaller(UpdateJobTriggerRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(JobTrigger.getDefaultInstance())) + .build(); + private static final MethodDescriptor + createJobTriggerMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.privacy.dlp.v2.DlpService/CreateJobTrigger") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateJobTriggerRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(JobTrigger.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + + private final UnaryCallable inspectContentCallable; + private final UnaryCallable redactImageCallable; + private final UnaryCallable + deidentifyContentCallable; + private final UnaryCallable + reidentifyContentCallable; + private final UnaryCallable listInfoTypesCallable; + private final UnaryCallable + createInspectTemplateCallable; + private final UnaryCallable + updateInspectTemplateCallable; + private final UnaryCallable + getInspectTemplateCallable; + private final UnaryCallable + listInspectTemplatesCallable; + private final UnaryCallable + listInspectTemplatesPagedCallable; + private final UnaryCallable deleteInspectTemplateCallable; + private final UnaryCallable + createDeidentifyTemplateCallable; + private final UnaryCallable + updateDeidentifyTemplateCallable; + private final UnaryCallable + getDeidentifyTemplateCallable; + private final UnaryCallable + listDeidentifyTemplatesCallable; + private final UnaryCallable + listDeidentifyTemplatesPagedCallable; + private final UnaryCallable + deleteDeidentifyTemplateCallable; + private final UnaryCallable createDlpJobCallable; + private final UnaryCallable listDlpJobsCallable; + private final UnaryCallable + listDlpJobsPagedCallable; + private final UnaryCallable getDlpJobCallable; + private final UnaryCallable deleteDlpJobCallable; + private final UnaryCallable cancelDlpJobCallable; + private final UnaryCallable + listJobTriggersCallable; + private final UnaryCallable + listJobTriggersPagedCallable; + private final UnaryCallable getJobTriggerCallable; + private final UnaryCallable deleteJobTriggerCallable; + private final UnaryCallable updateJobTriggerCallable; + private final UnaryCallable createJobTriggerCallable; + + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcDlpServiceStub create(DlpServiceStubSettings settings) + throws IOException { + return new GrpcDlpServiceStub(settings, ClientContext.create(settings)); + } + + public static final GrpcDlpServiceStub create(ClientContext clientContext) throws IOException { + return new GrpcDlpServiceStub(DlpServiceStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcDlpServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcDlpServiceStub( + DlpServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcDlpServiceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcDlpServiceStub(DlpServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcDlpServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcDlpServiceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcDlpServiceStub( + DlpServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + GrpcCallSettings + inspectContentTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(inspectContentMethodDescriptor) + .build(); + GrpcCallSettings redactImageTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(redactImageMethodDescriptor) + .build(); + GrpcCallSettings + deidentifyContentTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deidentifyContentMethodDescriptor) + .build(); + GrpcCallSettings + reidentifyContentTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(reidentifyContentMethodDescriptor) + .build(); + GrpcCallSettings listInfoTypesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listInfoTypesMethodDescriptor) + .build(); + GrpcCallSettings + createInspectTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createInspectTemplateMethodDescriptor) + .build(); + GrpcCallSettings + updateInspectTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateInspectTemplateMethodDescriptor) + .build(); + GrpcCallSettings + getInspectTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getInspectTemplateMethodDescriptor) + .build(); + GrpcCallSettings + listInspectTemplatesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listInspectTemplatesMethodDescriptor) + .build(); + GrpcCallSettings deleteInspectTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteInspectTemplateMethodDescriptor) + .build(); + GrpcCallSettings + createDeidentifyTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createDeidentifyTemplateMethodDescriptor) + .build(); + GrpcCallSettings + updateDeidentifyTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateDeidentifyTemplateMethodDescriptor) + .build(); + GrpcCallSettings + getDeidentifyTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getDeidentifyTemplateMethodDescriptor) + .build(); + GrpcCallSettings + listDeidentifyTemplatesTransportSettings = + GrpcCallSettings + .newBuilder() + .setMethodDescriptor(listDeidentifyTemplatesMethodDescriptor) + .build(); + GrpcCallSettings + deleteDeidentifyTemplateTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteDeidentifyTemplateMethodDescriptor) + .build(); + GrpcCallSettings createDlpJobTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createDlpJobMethodDescriptor) + .build(); + GrpcCallSettings listDlpJobsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listDlpJobsMethodDescriptor) + .build(); + GrpcCallSettings getDlpJobTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getDlpJobMethodDescriptor) + .build(); + GrpcCallSettings deleteDlpJobTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteDlpJobMethodDescriptor) + .build(); + GrpcCallSettings cancelDlpJobTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(cancelDlpJobMethodDescriptor) + .build(); + GrpcCallSettings + listJobTriggersTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listJobTriggersMethodDescriptor) + .build(); + GrpcCallSettings getJobTriggerTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getJobTriggerMethodDescriptor) + .build(); + GrpcCallSettings deleteJobTriggerTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteJobTriggerMethodDescriptor) + .build(); + GrpcCallSettings updateJobTriggerTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateJobTriggerMethodDescriptor) + .build(); + GrpcCallSettings createJobTriggerTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createJobTriggerMethodDescriptor) + .build(); + + this.inspectContentCallable = + callableFactory.createUnaryCallable( + inspectContentTransportSettings, settings.inspectContentSettings(), clientContext); + this.redactImageCallable = + callableFactory.createUnaryCallable( + redactImageTransportSettings, settings.redactImageSettings(), clientContext); + this.deidentifyContentCallable = + callableFactory.createUnaryCallable( + deidentifyContentTransportSettings, + settings.deidentifyContentSettings(), + clientContext); + this.reidentifyContentCallable = + callableFactory.createUnaryCallable( + reidentifyContentTransportSettings, + settings.reidentifyContentSettings(), + clientContext); + this.listInfoTypesCallable = + callableFactory.createUnaryCallable( + listInfoTypesTransportSettings, settings.listInfoTypesSettings(), clientContext); + this.createInspectTemplateCallable = + callableFactory.createUnaryCallable( + createInspectTemplateTransportSettings, + settings.createInspectTemplateSettings(), + clientContext); + this.updateInspectTemplateCallable = + callableFactory.createUnaryCallable( + updateInspectTemplateTransportSettings, + settings.updateInspectTemplateSettings(), + clientContext); + this.getInspectTemplateCallable = + callableFactory.createUnaryCallable( + getInspectTemplateTransportSettings, + settings.getInspectTemplateSettings(), + clientContext); + this.listInspectTemplatesCallable = + callableFactory.createUnaryCallable( + listInspectTemplatesTransportSettings, + settings.listInspectTemplatesSettings(), + clientContext); + this.listInspectTemplatesPagedCallable = + callableFactory.createPagedCallable( + listInspectTemplatesTransportSettings, + settings.listInspectTemplatesSettings(), + clientContext); + this.deleteInspectTemplateCallable = + callableFactory.createUnaryCallable( + deleteInspectTemplateTransportSettings, + settings.deleteInspectTemplateSettings(), + clientContext); + this.createDeidentifyTemplateCallable = + callableFactory.createUnaryCallable( + createDeidentifyTemplateTransportSettings, + settings.createDeidentifyTemplateSettings(), + clientContext); + this.updateDeidentifyTemplateCallable = + callableFactory.createUnaryCallable( + updateDeidentifyTemplateTransportSettings, + settings.updateDeidentifyTemplateSettings(), + clientContext); + this.getDeidentifyTemplateCallable = + callableFactory.createUnaryCallable( + getDeidentifyTemplateTransportSettings, + settings.getDeidentifyTemplateSettings(), + clientContext); + this.listDeidentifyTemplatesCallable = + callableFactory.createUnaryCallable( + listDeidentifyTemplatesTransportSettings, + settings.listDeidentifyTemplatesSettings(), + clientContext); + this.listDeidentifyTemplatesPagedCallable = + callableFactory.createPagedCallable( + listDeidentifyTemplatesTransportSettings, + settings.listDeidentifyTemplatesSettings(), + clientContext); + this.deleteDeidentifyTemplateCallable = + callableFactory.createUnaryCallable( + deleteDeidentifyTemplateTransportSettings, + settings.deleteDeidentifyTemplateSettings(), + clientContext); + this.createDlpJobCallable = + callableFactory.createUnaryCallable( + createDlpJobTransportSettings, settings.createDlpJobSettings(), clientContext); + this.listDlpJobsCallable = + callableFactory.createUnaryCallable( + listDlpJobsTransportSettings, settings.listDlpJobsSettings(), clientContext); + this.listDlpJobsPagedCallable = + callableFactory.createPagedCallable( + listDlpJobsTransportSettings, settings.listDlpJobsSettings(), clientContext); + this.getDlpJobCallable = + callableFactory.createUnaryCallable( + getDlpJobTransportSettings, settings.getDlpJobSettings(), clientContext); + this.deleteDlpJobCallable = + callableFactory.createUnaryCallable( + deleteDlpJobTransportSettings, settings.deleteDlpJobSettings(), clientContext); + this.cancelDlpJobCallable = + callableFactory.createUnaryCallable( + cancelDlpJobTransportSettings, settings.cancelDlpJobSettings(), clientContext); + this.listJobTriggersCallable = + callableFactory.createUnaryCallable( + listJobTriggersTransportSettings, settings.listJobTriggersSettings(), clientContext); + this.listJobTriggersPagedCallable = + callableFactory.createPagedCallable( + listJobTriggersTransportSettings, settings.listJobTriggersSettings(), clientContext); + this.getJobTriggerCallable = + callableFactory.createUnaryCallable( + getJobTriggerTransportSettings, settings.getJobTriggerSettings(), clientContext); + this.deleteJobTriggerCallable = + callableFactory.createUnaryCallable( + deleteJobTriggerTransportSettings, settings.deleteJobTriggerSettings(), clientContext); + this.updateJobTriggerCallable = + callableFactory.createUnaryCallable( + updateJobTriggerTransportSettings, settings.updateJobTriggerSettings(), clientContext); + this.createJobTriggerCallable = + callableFactory.createUnaryCallable( + createJobTriggerTransportSettings, settings.createJobTriggerSettings(), clientContext); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public UnaryCallable inspectContentCallable() { + return inspectContentCallable; + } + + public UnaryCallable redactImageCallable() { + return redactImageCallable; + } + + public UnaryCallable + deidentifyContentCallable() { + return deidentifyContentCallable; + } + + public UnaryCallable + reidentifyContentCallable() { + return reidentifyContentCallable; + } + + public UnaryCallable listInfoTypesCallable() { + return listInfoTypesCallable; + } + + public UnaryCallable + createInspectTemplateCallable() { + return createInspectTemplateCallable; + } + + public UnaryCallable + updateInspectTemplateCallable() { + return updateInspectTemplateCallable; + } + + public UnaryCallable getInspectTemplateCallable() { + return getInspectTemplateCallable; + } + + public UnaryCallable + listInspectTemplatesPagedCallable() { + return listInspectTemplatesPagedCallable; + } + + public UnaryCallable + listInspectTemplatesCallable() { + return listInspectTemplatesCallable; + } + + public UnaryCallable deleteInspectTemplateCallable() { + return deleteInspectTemplateCallable; + } + + public UnaryCallable + createDeidentifyTemplateCallable() { + return createDeidentifyTemplateCallable; + } + + public UnaryCallable + updateDeidentifyTemplateCallable() { + return updateDeidentifyTemplateCallable; + } + + public UnaryCallable + getDeidentifyTemplateCallable() { + return getDeidentifyTemplateCallable; + } + + public UnaryCallable + listDeidentifyTemplatesPagedCallable() { + return listDeidentifyTemplatesPagedCallable; + } + + public UnaryCallable + listDeidentifyTemplatesCallable() { + return listDeidentifyTemplatesCallable; + } + + public UnaryCallable deleteDeidentifyTemplateCallable() { + return deleteDeidentifyTemplateCallable; + } + + public UnaryCallable createDlpJobCallable() { + return createDlpJobCallable; + } + + public UnaryCallable listDlpJobsPagedCallable() { + return listDlpJobsPagedCallable; + } + + public UnaryCallable listDlpJobsCallable() { + return listDlpJobsCallable; + } + + public UnaryCallable getDlpJobCallable() { + return getDlpJobCallable; + } + + public UnaryCallable deleteDlpJobCallable() { + return deleteDlpJobCallable; + } + + public UnaryCallable cancelDlpJobCallable() { + return cancelDlpJobCallable; + } + + public UnaryCallable + listJobTriggersPagedCallable() { + return listJobTriggersPagedCallable; + } + + public UnaryCallable listJobTriggersCallable() { + return listJobTriggersCallable; + } + + public UnaryCallable getJobTriggerCallable() { + return getJobTriggerCallable; + } + + public UnaryCallable deleteJobTriggerCallable() { + return deleteJobTriggerCallable; + } + + public UnaryCallable updateJobTriggerCallable() { + return updateJobTriggerCallable; + } + + public UnaryCallable createJobTriggerCallable() { + return createJobTriggerCallable; + } + + @Override + public final void close() throws Exception { + shutdown(); + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/Colors.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/Colors.java new file mode 100644 index 000000000000..1ec834cf27d1 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/Colors.java @@ -0,0 +1,35 @@ +/* + * Copyright 2018 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.cloud.dlp.v2beta1; + +import com.google.privacy.dlp.v2beta1.Color; + +public class Colors { + + private Colors() {} + + public static final Color asDlpColor(java.awt.Color c) { + return Color.newBuilder() + .setBlue(c.getBlue()) + .setGreen(c.getGreen()) + .setRed(c.getRed()) + .build(); + } + + public static final java.awt.Color asAwtColor(Color c) { + return new java.awt.Color(c.getRed() / 255, c.getGreen() / 255, c.getBlue() / 255); + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/DlpServiceSettings.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/DlpServiceSettings.java index 4c9c53ff5312..d93f1eae39b3 100644 --- a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/DlpServiceSettings.java +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/DlpServiceSettings.java @@ -70,7 +70,7 @@ * * DlpServiceSettings.Builder dlpServiceSettingsBuilder = * DlpServiceSettings.newBuilder(); - * dlpServiceSettingsBuilder.inspectContentSettings().getRetrySettingsBuilder() + * dlpServiceSettingsBuilder.inspectContentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * DlpServiceSettings dlpServiceSettings = dlpServiceSettingsBuilder.build(); * diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStubSettings.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStubSettings.java index efb18ae9b16c..22dbfeee6ee7 100644 --- a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStubSettings.java +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStubSettings.java @@ -82,7 +82,7 @@ * * DlpServiceStubSettings.Builder dlpServiceSettingsBuilder = * DlpServiceStubSettings.newBuilder(); - * dlpServiceSettingsBuilder.inspectContentSettings().getRetrySettingsBuilder() + * dlpServiceSettingsBuilder.inspectContentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * DlpServiceStubSettings dlpServiceSettings = dlpServiceSettingsBuilder.build(); * diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceCallableFactory.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceCallableFactory.java new file mode 100644 index 000000000000..8377692425a8 --- /dev/null +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.dlp.v2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for DLP API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcDlpServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java index c3f95fea4b44..88235fe17088 100644 --- a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -161,6 +161,8 @@ public class GrpcDlpServiceStub extends DlpServiceStub { private final UnaryCallable listRootCategoriesCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcDlpServiceStub create(DlpServiceStubSettings settings) throws IOException { return new GrpcDlpServiceStub(settings, ClientContext.create(settings)); @@ -170,6 +172,12 @@ public static final GrpcDlpServiceStub create(ClientContext clientContext) throw return new GrpcDlpServiceStub(DlpServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcDlpServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcDlpServiceStub( + DlpServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcDlpServiceStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -177,7 +185,21 @@ public static final GrpcDlpServiceStub create(ClientContext clientContext) throw */ protected GrpcDlpServiceStub(DlpServiceStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcDlpServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcDlpServiceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcDlpServiceStub( + DlpServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings inspectContentTransportSettings = @@ -219,48 +241,48 @@ protected GrpcDlpServiceStub(DlpServiceStubSettings settings, ClientContext clie .build(); this.inspectContentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( inspectContentTransportSettings, settings.inspectContentSettings(), clientContext); this.redactContentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( redactContentTransportSettings, settings.redactContentSettings(), clientContext); this.deidentifyContentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deidentifyContentTransportSettings, settings.deidentifyContentSettings(), clientContext); this.analyzeDataSourceRiskCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeDataSourceRiskTransportSettings, settings.analyzeDataSourceRiskSettings(), clientContext); this.analyzeDataSourceRiskOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( analyzeDataSourceRiskTransportSettings, settings.analyzeDataSourceRiskOperationSettings(), clientContext, this.operationsStub); this.createInspectOperationCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createInspectOperationTransportSettings, settings.createInspectOperationSettings(), clientContext); this.createInspectOperationOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( createInspectOperationTransportSettings, settings.createInspectOperationOperationSettings(), clientContext, this.operationsStub); this.listInspectFindingsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listInspectFindingsTransportSettings, settings.listInspectFindingsSettings(), clientContext); this.listInfoTypesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listInfoTypesTransportSettings, settings.listInfoTypesSettings(), clientContext); this.listRootCategoriesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listRootCategoriesTransportSettings, settings.listRootCategoriesSettings(), clientContext); diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/DlpServiceClientTest.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/DlpServiceClientTest.java new file mode 100644 index 000000000000..c9972fde0df6 --- /dev/null +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/DlpServiceClientTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2018 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.cloud.dlp.v2; + +import com.google.api.gax.core.NoCredentialsProvider; +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 java.io.IOException; +import java.util.Arrays; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +@javax.annotation.Generated("by GAPIC") +public class DlpServiceClientTest { + private static MockDlpService mockDlpService; + private static MockServiceHelper serviceHelper; + private DlpServiceClient client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockDlpService = new MockDlpService(); + serviceHelper = + new MockServiceHelper("in-process-1", Arrays.asList(mockDlpService)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + channelProvider = serviceHelper.createChannelProvider(); + DlpServiceSettings settings = + DlpServiceSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = DlpServiceClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } +} diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/MockDlpService.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/MockDlpService.java new file mode 100644 index 000000000000..d321a1b2ef35 --- /dev/null +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/MockDlpService.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 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.cloud.dlp.v2; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockDlpService implements MockGrpcService { + private final MockDlpServiceImpl serviceImpl; + + public MockDlpService() { + serviceImpl = new MockDlpServiceImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(GeneratedMessageV3 response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/MockDlpServiceImpl.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/MockDlpServiceImpl.java new file mode 100644 index 000000000000..f8dd8118173f --- /dev/null +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2/MockDlpServiceImpl.java @@ -0,0 +1,474 @@ +/* + * Copyright 2018 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.cloud.dlp.v2; + +import com.google.api.core.BetaApi; +import com.google.privacy.dlp.v2.CancelDlpJobRequest; +import com.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.CreateDlpJobRequest; +import com.google.privacy.dlp.v2.CreateInspectTemplateRequest; +import com.google.privacy.dlp.v2.CreateJobTriggerRequest; +import com.google.privacy.dlp.v2.DeidentifyContentRequest; +import com.google.privacy.dlp.v2.DeidentifyContentResponse; +import com.google.privacy.dlp.v2.DeidentifyTemplate; +import com.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.DeleteDlpJobRequest; +import com.google.privacy.dlp.v2.DeleteInspectTemplateRequest; +import com.google.privacy.dlp.v2.DeleteJobTriggerRequest; +import com.google.privacy.dlp.v2.DlpJob; +import com.google.privacy.dlp.v2.DlpServiceGrpc.DlpServiceImplBase; +import com.google.privacy.dlp.v2.GetDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.GetDlpJobRequest; +import com.google.privacy.dlp.v2.GetInspectTemplateRequest; +import com.google.privacy.dlp.v2.GetJobTriggerRequest; +import com.google.privacy.dlp.v2.InspectContentRequest; +import com.google.privacy.dlp.v2.InspectContentResponse; +import com.google.privacy.dlp.v2.InspectTemplate; +import com.google.privacy.dlp.v2.JobTrigger; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest; +import com.google.privacy.dlp.v2.ListDeidentifyTemplatesResponse; +import com.google.privacy.dlp.v2.ListDlpJobsRequest; +import com.google.privacy.dlp.v2.ListDlpJobsResponse; +import com.google.privacy.dlp.v2.ListInfoTypesRequest; +import com.google.privacy.dlp.v2.ListInfoTypesResponse; +import com.google.privacy.dlp.v2.ListInspectTemplatesRequest; +import com.google.privacy.dlp.v2.ListInspectTemplatesResponse; +import com.google.privacy.dlp.v2.ListJobTriggersRequest; +import com.google.privacy.dlp.v2.ListJobTriggersResponse; +import com.google.privacy.dlp.v2.RedactImageRequest; +import com.google.privacy.dlp.v2.RedactImageResponse; +import com.google.privacy.dlp.v2.ReidentifyContentRequest; +import com.google.privacy.dlp.v2.ReidentifyContentResponse; +import com.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest; +import com.google.privacy.dlp.v2.UpdateInspectTemplateRequest; +import com.google.privacy.dlp.v2.UpdateJobTriggerRequest; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockDlpServiceImpl extends DlpServiceImplBase { + private ArrayList requests; + private Queue responses; + + public MockDlpServiceImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(GeneratedMessageV3 response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void inspectContent( + InspectContentRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof InspectContentResponse) { + requests.add(request); + responseObserver.onNext((InspectContentResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void redactImage( + RedactImageRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof RedactImageResponse) { + requests.add(request); + responseObserver.onNext((RedactImageResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deidentifyContent( + DeidentifyContentRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof DeidentifyContentResponse) { + requests.add(request); + responseObserver.onNext((DeidentifyContentResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void reidentifyContent( + ReidentifyContentRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ReidentifyContentResponse) { + requests.add(request); + responseObserver.onNext((ReidentifyContentResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listInfoTypes( + ListInfoTypesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListInfoTypesResponse) { + requests.add(request); + responseObserver.onNext((ListInfoTypesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void createInspectTemplate( + CreateInspectTemplateRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof InspectTemplate) { + requests.add(request); + responseObserver.onNext((InspectTemplate) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateInspectTemplate( + UpdateInspectTemplateRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof InspectTemplate) { + requests.add(request); + responseObserver.onNext((InspectTemplate) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getInspectTemplate( + GetInspectTemplateRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof InspectTemplate) { + requests.add(request); + responseObserver.onNext((InspectTemplate) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listInspectTemplates( + ListInspectTemplatesRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListInspectTemplatesResponse) { + requests.add(request); + responseObserver.onNext((ListInspectTemplatesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteInspectTemplate( + DeleteInspectTemplateRequest 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("Unrecognized response type")); + } + } + + @Override + public void createDeidentifyTemplate( + CreateDeidentifyTemplateRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof DeidentifyTemplate) { + requests.add(request); + responseObserver.onNext((DeidentifyTemplate) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateDeidentifyTemplate( + UpdateDeidentifyTemplateRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof DeidentifyTemplate) { + requests.add(request); + responseObserver.onNext((DeidentifyTemplate) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getDeidentifyTemplate( + GetDeidentifyTemplateRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof DeidentifyTemplate) { + requests.add(request); + responseObserver.onNext((DeidentifyTemplate) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listDeidentifyTemplates( + ListDeidentifyTemplatesRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListDeidentifyTemplatesResponse) { + requests.add(request); + responseObserver.onNext((ListDeidentifyTemplatesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteDeidentifyTemplate( + DeleteDeidentifyTemplateRequest 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("Unrecognized response type")); + } + } + + @Override + public void createJobTrigger( + CreateJobTriggerRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof JobTrigger) { + requests.add(request); + responseObserver.onNext((JobTrigger) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateJobTrigger( + UpdateJobTriggerRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof JobTrigger) { + requests.add(request); + responseObserver.onNext((JobTrigger) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getJobTrigger( + GetJobTriggerRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof JobTrigger) { + requests.add(request); + responseObserver.onNext((JobTrigger) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listJobTriggers( + ListJobTriggersRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListJobTriggersResponse) { + requests.add(request); + responseObserver.onNext((ListJobTriggersResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteJobTrigger( + DeleteJobTriggerRequest 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("Unrecognized response type")); + } + } + + @Override + public void createDlpJob(CreateDlpJobRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof DlpJob) { + requests.add(request); + responseObserver.onNext((DlpJob) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listDlpJobs( + ListDlpJobsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListDlpJobsResponse) { + requests.add(request); + responseObserver.onNext((ListDlpJobsResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getDlpJob(GetDlpJobRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof DlpJob) { + requests.add(request); + responseObserver.onNext((DlpJob) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteDlpJob(DeleteDlpJobRequest 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("Unrecognized response type")); + } + } + + @Override + public void cancelDlpJob(CancelDlpJobRequest 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("Unrecognized response type")); + } + } +} diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/ColorTest.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/ColorTest.java new file mode 100644 index 000000000000..dce909ca675d --- /dev/null +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/ColorTest.java @@ -0,0 +1,26 @@ +package com.google.cloud.dlp.v2beta1; + +import com.google.privacy.dlp.v2beta1.Color; +import org.junit.Assert; +import org.junit.Test; + +public class ColorTest { + + @Test + public void asDlpColorTest() { + Color got = Colors.asDlpColor(new java.awt.Color(1, 2, 3)); + Assert.assertEquals(got.getBlue(), 3, 0); + Assert.assertEquals(got.getGreen(), 2, 0); + Assert.assertEquals(got.getRed(), 1, 0); + } + + @Test + public void asAwtColorTest() { + java.awt.Color got = + Colors.asAwtColor(Color.newBuilder().setRed(1).setGreen(2).setBlue(3).build()); + + Assert.assertEquals(got.getBlue(), 3, 0); + Assert.assertEquals(got.getGreen(), 2, 0); + Assert.assertEquals(got.getRed(), 1, 0); + } +} diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceSmokeTest.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceSmokeTest.java new file mode 100644 index 000000000000..69d078aeac26 --- /dev/null +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceSmokeTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2018 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.cloud.dlp.v2beta1; + +import com.google.common.base.Preconditions; +import com.google.privacy.dlp.v2beta1.ContentItem; +import com.google.privacy.dlp.v2beta1.InspectConfig; +import com.google.privacy.dlp.v2beta1.InspectContentResponse; +import com.google.privacy.dlp.v2beta1.Likelihood; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class DlpServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (DlpServiceClient client = DlpServiceClient.create()) { + Likelihood minLikelihood = Likelihood.POSSIBLE; + InspectConfig inspectConfig = + InspectConfig.newBuilder().setMinLikelihood(minLikelihood).build(); + String type = "text/plain"; + String value = "my phone number is 215-512-1212"; + ContentItem itemsElement = ContentItem.newBuilder().setType(type).setValue(value).build(); + List items = Arrays.asList(itemsElement); + + InspectContentResponse response = client.inspectContent(inspectConfig, items); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-dns/README.md b/google-cloud-dns/README.md index cb22879fd006..52136836d36e 100644 --- a/google-cloud-dns/README.md +++ b/google-cloud-dns/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-dns - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-dns:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-dns:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dns" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-dns" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-dns/pom.xml b/google-cloud-dns/pom.xml index 043e5be62778..9d390c90167a 100644 --- a/google-cloud-dns/pom.xml +++ b/google-cloud-dns/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-dns - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud DNS https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-dns @@ -14,7 +14,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-dns diff --git a/google-cloud-errorreporting/README.md b/google-cloud-errorreporting/README.md index 81b1013e61c0..6330e3d00180 100644 --- a/google-cloud-errorreporting/README.md +++ b/google-cloud-errorreporting/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-errorreporting - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-errorreporting:0.38.0-beta' +compile 'com.google.cloud:google-cloud-errorreporting:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-errorreporting" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-errorreporting" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-errorreporting/pom.xml b/google-cloud-errorreporting/pom.xml index e2089a80b052..9d971c7d35a7 100644 --- a/google-cloud-errorreporting/pom.xml +++ b/google-cloud-errorreporting/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-errorreporting - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Error Reporting https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-errorreporting @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-errorreporting diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorGroupServiceSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorGroupServiceSettings.java index b3c948dc5491..d57dc10e4d7d 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorGroupServiceSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorGroupServiceSettings.java @@ -54,7 +54,7 @@ * * ErrorGroupServiceSettings.Builder errorGroupServiceSettingsBuilder = * ErrorGroupServiceSettings.newBuilder(); - * errorGroupServiceSettingsBuilder.getGroupSettings().getRetrySettingsBuilder() + * errorGroupServiceSettingsBuilder.getGroupSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ErrorGroupServiceSettings errorGroupServiceSettings = errorGroupServiceSettingsBuilder.build(); * diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorStatsServiceSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorStatsServiceSettings.java index 2ad1e868cb8c..a41f0beeef00 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorStatsServiceSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ErrorStatsServiceSettings.java @@ -61,7 +61,7 @@ * * ErrorStatsServiceSettings.Builder errorStatsServiceSettingsBuilder = * ErrorStatsServiceSettings.newBuilder(); - * errorStatsServiceSettingsBuilder.deleteEventsSettings().getRetrySettingsBuilder() + * errorStatsServiceSettingsBuilder.deleteEventsSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ErrorStatsServiceSettings errorStatsServiceSettings = errorStatsServiceSettingsBuilder.build(); * diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ReportErrorsServiceSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ReportErrorsServiceSettings.java index 6c873b0200e2..7dde70553e04 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ReportErrorsServiceSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/ReportErrorsServiceSettings.java @@ -53,7 +53,7 @@ * * ReportErrorsServiceSettings.Builder reportErrorsServiceSettingsBuilder = * ReportErrorsServiceSettings.newBuilder(); - * reportErrorsServiceSettingsBuilder.reportErrorEventSettings().getRetrySettingsBuilder() + * reportErrorsServiceSettingsBuilder.reportErrorEventSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ReportErrorsServiceSettings reportErrorsServiceSettings = reportErrorsServiceSettingsBuilder.build(); * diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorGroupServiceStubSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorGroupServiceStubSettings.java index 671cec904f92..bb54687561c7 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorGroupServiceStubSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorGroupServiceStubSettings.java @@ -63,7 +63,7 @@ * * ErrorGroupServiceStubSettings.Builder errorGroupServiceSettingsBuilder = * ErrorGroupServiceStubSettings.newBuilder(); - * errorGroupServiceSettingsBuilder.getGroupSettings().getRetrySettingsBuilder() + * errorGroupServiceSettingsBuilder.getGroupSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ErrorGroupServiceStubSettings errorGroupServiceSettings = errorGroupServiceSettingsBuilder.build(); * diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorStatsServiceStubSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorStatsServiceStubSettings.java index f5b844ee910b..5ab1fd7de5e5 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorStatsServiceStubSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ErrorStatsServiceStubSettings.java @@ -78,7 +78,7 @@ * * ErrorStatsServiceStubSettings.Builder errorStatsServiceSettingsBuilder = * ErrorStatsServiceStubSettings.newBuilder(); - * errorStatsServiceSettingsBuilder.deleteEventsSettings().getRetrySettingsBuilder() + * errorStatsServiceSettingsBuilder.deleteEventsSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ErrorStatsServiceStubSettings errorStatsServiceSettings = errorStatsServiceSettingsBuilder.build(); * diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorGroupServiceCallableFactory.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorGroupServiceCallableFactory.java new file mode 100644 index 000000000000..33878be5d6f2 --- /dev/null +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorGroupServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.errorreporting.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Error Reporting API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcErrorGroupServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorGroupServiceStub.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorGroupServiceStub.java index 47449bc737df..bc9df2be291b 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorGroupServiceStub.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorGroupServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup; @@ -64,6 +64,8 @@ public class GrpcErrorGroupServiceStub extends ErrorGroupServiceStub { private final UnaryCallable getGroupCallable; private final UnaryCallable updateGroupCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcErrorGroupServiceStub create(ErrorGroupServiceStubSettings settings) throws IOException { return new GrpcErrorGroupServiceStub(settings, ClientContext.create(settings)); @@ -75,6 +77,12 @@ public static final GrpcErrorGroupServiceStub create(ClientContext clientContext ErrorGroupServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcErrorGroupServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcErrorGroupServiceStub( + ErrorGroupServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcErrorGroupServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -82,6 +90,20 @@ public static final GrpcErrorGroupServiceStub create(ClientContext clientContext */ protected GrpcErrorGroupServiceStub( ErrorGroupServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcErrorGroupServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcErrorGroupServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcErrorGroupServiceStub( + ErrorGroupServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings getGroupTransportSettings = GrpcCallSettings.newBuilder() @@ -93,10 +115,10 @@ protected GrpcErrorGroupServiceStub( .build(); this.getGroupCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getGroupTransportSettings, settings.getGroupSettings(), clientContext); this.updateGroupCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateGroupTransportSettings, settings.updateGroupSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorStatsServiceCallableFactory.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorStatsServiceCallableFactory.java new file mode 100644 index 000000000000..2a07578f9c7c --- /dev/null +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorStatsServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.errorreporting.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Error Reporting API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcErrorStatsServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorStatsServiceStub.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorStatsServiceStub.java index c04284054076..06e08c61ee48 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorStatsServiceStub.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcErrorStatsServiceStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsRequest; @@ -87,6 +87,8 @@ public class GrpcErrorStatsServiceStub extends ErrorStatsServiceStub { private final UnaryCallable listEventsPagedCallable; private final UnaryCallable deleteEventsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcErrorStatsServiceStub create(ErrorStatsServiceStubSettings settings) throws IOException { return new GrpcErrorStatsServiceStub(settings, ClientContext.create(settings)); @@ -98,6 +100,12 @@ public static final GrpcErrorStatsServiceStub create(ClientContext clientContext ErrorStatsServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcErrorStatsServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcErrorStatsServiceStub( + ErrorStatsServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcErrorStatsServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -105,6 +113,20 @@ public static final GrpcErrorStatsServiceStub create(ClientContext clientContext */ protected GrpcErrorStatsServiceStub( ErrorStatsServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcErrorStatsServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcErrorStatsServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcErrorStatsServiceStub( + ErrorStatsServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listGroupStatsTransportSettings = @@ -121,19 +143,19 @@ protected GrpcErrorStatsServiceStub( .build(); this.listGroupStatsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listGroupStatsTransportSettings, settings.listGroupStatsSettings(), clientContext); this.listGroupStatsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listGroupStatsTransportSettings, settings.listGroupStatsSettings(), clientContext); this.listEventsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listEventsTransportSettings, settings.listEventsSettings(), clientContext); this.listEventsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listEventsTransportSettings, settings.listEventsSettings(), clientContext); this.deleteEventsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteEventsTransportSettings, settings.deleteEventsSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcReportErrorsServiceCallableFactory.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcReportErrorsServiceCallableFactory.java new file mode 100644 index 000000000000..c90f958d30e6 --- /dev/null +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcReportErrorsServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.errorreporting.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Error Reporting API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcReportErrorsServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcReportErrorsServiceStub.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcReportErrorsServiceStub.java index 4b36610709a3..cc598ac92801 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcReportErrorsServiceStub.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/GrpcReportErrorsServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest; @@ -57,6 +57,8 @@ public class GrpcReportErrorsServiceStub extends ReportErrorsServiceStub { private final UnaryCallable reportErrorEventCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcReportErrorsServiceStub create(ReportErrorsServiceStubSettings settings) throws IOException { return new GrpcReportErrorsServiceStub(settings, ClientContext.create(settings)); @@ -68,6 +70,12 @@ public static final GrpcReportErrorsServiceStub create(ClientContext clientConte ReportErrorsServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcReportErrorsServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcReportErrorsServiceStub( + ReportErrorsServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcReportErrorsServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -75,6 +83,20 @@ public static final GrpcReportErrorsServiceStub create(ClientContext clientConte */ protected GrpcReportErrorsServiceStub( ReportErrorsServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcReportErrorsServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcReportErrorsServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcReportErrorsServiceStub( + ReportErrorsServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings reportErrorEventTransportSettings = @@ -83,7 +105,7 @@ protected GrpcReportErrorsServiceStub( .build(); this.reportErrorEventCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( reportErrorEventTransportSettings, settings.reportErrorEventSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ReportErrorsServiceStubSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ReportErrorsServiceStubSettings.java index d7056afa25a4..344330372bae 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ReportErrorsServiceStubSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/v1beta1/stub/ReportErrorsServiceStubSettings.java @@ -62,7 +62,7 @@ * * ReportErrorsServiceStubSettings.Builder reportErrorsServiceSettingsBuilder = * ReportErrorsServiceStubSettings.newBuilder(); - * reportErrorsServiceSettingsBuilder.reportErrorEventSettings().getRetrySettingsBuilder() + * reportErrorsServiceSettingsBuilder.reportErrorEventSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ReportErrorsServiceStubSettings reportErrorsServiceSettings = reportErrorsServiceSettingsBuilder.build(); * diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/v1beta1/ReportErrorsServiceSmokeTest.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/v1beta1/ReportErrorsServiceSmokeTest.java new file mode 100644 index 000000000000..5b0d905065db --- /dev/null +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/v1beta1/ReportErrorsServiceSmokeTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2018 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.cloud.errorreporting.v1beta1; + +import com.google.common.base.Preconditions; +import com.google.devtools.clouderrorreporting.v1beta1.ErrorContext; +import com.google.devtools.clouderrorreporting.v1beta1.ProjectName; +import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse; +import com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent; +import com.google.devtools.clouderrorreporting.v1beta1.ServiceContext; +import com.google.devtools.clouderrorreporting.v1beta1.SourceLocation; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ReportErrorsServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (ReportErrorsServiceClient client = ReportErrorsServiceClient.create()) { + ProjectName projectName = ProjectName.of(projectId); + String message = "[MESSAGE]"; + String service = "[SERVICE]"; + ServiceContext serviceContext = ServiceContext.newBuilder().setService(service).build(); + String filePath = "path/to/file.lang"; + int lineNumber = 42; + String functionName = "meaningOfLife"; + SourceLocation reportLocation = + SourceLocation.newBuilder() + .setFilePath(filePath) + .setLineNumber(lineNumber) + .setFunctionName(functionName) + .build(); + ErrorContext context = ErrorContext.newBuilder().setReportLocation(reportLocation).build(); + ReportedErrorEvent event = + ReportedErrorEvent.newBuilder() + .setMessage(message) + .setServiceContext(serviceContext) + .setContext(context) + .build(); + + ReportErrorEventResponse response = client.reportErrorEvent(projectName, event); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-examples/README.md b/google-cloud-examples/README.md index 5ce8aeab447e..0d77abcfb81d 100644 --- a/google-cloud-examples/README.md +++ b/google-cloud-examples/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-examples - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-examples:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-examples:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-examples" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-examples" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-examples/pom.xml b/google-cloud-examples/pom.xml index b1c7d52934a3..8c59d160c698 100644 --- a/google-cloud-examples/pom.xml +++ b/google-cloud-examples/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-examples - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Examples https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-examples diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java index d6701804a6f9..ea95c59bbcf9 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java @@ -25,6 +25,8 @@ import com.google.api.client.util.Charsets; import com.google.api.gax.paging.Page; import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.JobInfo.CreateDisposition; +import com.google.cloud.bigquery.LoadJobConfiguration; import com.google.cloud.bigquery.TableResult; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQuery.DatasetListOption; @@ -378,6 +380,38 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath) // [END writeFileToTable] } + /** + * Example of loading a newline-delimited-json file with textual fields from GCS to a table. + */ + // [TARGET create(JobInfo, JobOption...)] + // [VARIABLE "my_dataset_name"] + // [VARIABLE "my_table_name"] + public Long writeRemoteFileToTable(String datasetName, String tableName) + throws InterruptedException { + // [START bigquery_load_table_gcs_json] + String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; + TableId tableId = TableId.of(datasetName, tableName); + // Table field definition + Field[] fields = new Field[] { + Field.of("name", LegacySQLTypeName.STRING), + Field.of("post_abbr", LegacySQLTypeName.STRING) + }; + // Table schema definition + Schema schema = Schema.of(fields); + LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri) + .setFormatOptions(FormatOptions.json()) + .setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED) + .setSchema(schema) + .build(); + // Load the table + Job remoteLoadJob = bigquery.create(JobInfo.of(configuration)); + remoteLoadJob = remoteLoadJob.waitFor(); + // Check the table + System.out.println("State: " + remoteLoadJob.getStatus().getState()); + return ((StandardTableDefinition) bigquery.getTable(tableId).getDefinition()).getNumRows(); + // [END bigquery_load_table_gcs_json] + } + /** * Example of inserting rows into a table without running a load job. */ @@ -470,7 +504,9 @@ public TableResult listTableDataFromId(String datasetName, String tableName) { return tableData; } - /** Example of listing table rows with schema. */ + /** + * Example of listing table rows with schema. + */ // [TARGET listTableData(String, String, Schema, TableDataListOption...)] // [VARIABLE "my_dataset_name"] // [VARIABLE "my_table_name"] @@ -488,7 +524,9 @@ public TableResult listTableDataSchema( return tableData; } - /** Example of listing table rows with schema. */ + /** + * Example of listing table rows with schema. + */ // [TARGET listTableData(TableId, Schema, TableDataListOption...)] public FieldValueList listTableDataSchemaId() { // [START listTableDataSchemaId] @@ -607,8 +645,10 @@ public boolean cancelJobFromId(String jobName) { return success; } - /** Example of running a query. */ - // [TARGET query(QueryJobConfiguration, QueryOption...)] + /** + * Example of running a query. + */ + // [TARGET query(QueryJobConfiguration, JobOption...)] // [VARIABLE "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]"] public void runQuery(String query) throws InterruptedException { // [START runQuery] @@ -620,10 +660,11 @@ public void runQuery(String query) throws InterruptedException { // [END runQuery] } - /** Example of running a query with query parameters. */ - // [TARGET query(QueryJobConfiguration, QueryOption...)] - // [VARIABLE "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where - // word_count > @wordCount"] + /** + * Example of running a query with query parameters. + */ + // [TARGET query(QueryJobConfiguration, JobOption...)] + // [VARIABLE "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > @wordCount"] public void runQueryWithParameters(String query) throws InterruptedException { // [START runQueryWithParameters] // Note, standard SQL is required to use query parameters. Legacy SQL will not work. diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java index d6ef4eb9d9d8..c42e2c627abd 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java @@ -1032,7 +1032,7 @@ public List listBlobAcls(String bucketName, String blobName, long blobGener * Example of default auth */ public Page authListBuckets() { - // [START authListBucket] + // [START auth_cloud_implicit] // If you don't specify credentials when constructing the client, the // client library will look for credentials in the environment. @@ -1042,7 +1042,7 @@ public Page authListBuckets() { for (Bucket bucket : buckets.iterateAll()) { // do something with the info } - // [END authListBucket] + // [END auth_cloud_implicit] return buckets; } diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java index d5c081f8368f..2ef79ed95a83 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import com.google.api.gax.paging.Page; @@ -48,6 +49,7 @@ import java.net.URISyntaxException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Iterator; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -197,6 +199,24 @@ public void testWriteAndListTableData() assertTrue(bigquerySnippets.deleteTable(DATASET, tableName)); } + @Test + public void testWriteRemoteJsonToTable() throws InterruptedException { + String datasetName = "test_dataset"; + String tableName = "us_states"; + Table table = bigquery.getTable(datasetName, tableName); + assertNull(table); + + Long result = bigquerySnippets.writeRemoteFileToTable(datasetName, tableName); + table = bigquery.getTable(datasetName, tableName); + assertNotNull(table); + ArrayList tableFieldNames = new ArrayList<>(); + for (Field field: table.getDefinition().getSchema().getFields()) { + tableFieldNames.add(field.getName()); + } + bigquery.delete(table.getTableId()); + assertEquals(Long.valueOf(50), result); + } + @Test public void testInsertAllAndListTableData() throws IOException, InterruptedException { String tableName = "test_insert_all_and_list_table_data"; diff --git a/google-cloud-firestore/README.md b/google-cloud-firestore/README.md index cff92cce126d..028e2fe6c0bb 100644 --- a/google-cloud-firestore/README.md +++ b/google-cloud-firestore/README.md @@ -14,16 +14,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-firestore - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-firestore:0.38.0-beta' +compile 'com.google.cloud:google-cloud-firestore:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml index 7e7ae2faf555..b3df53fa2f5f 100644 --- a/google-cloud-firestore/pom.xml +++ b/google-cloud-firestore/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-firestore - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Firestore https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-firestore @@ -15,7 +15,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-firestore diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java index 7b0c419a3c88..dd23461964d2 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java @@ -274,7 +274,7 @@ private static T[] replaceInArray(T[] arr, int pos, T value) { /** * This does a linear scan which is simpler than a binary search. For a small collection size this - * still should be as fast a as binary search. + * still should be as fast as binary search. */ private int findKeyOrInsertPosition(K key) { int newPos = 0; @@ -286,7 +286,7 @@ private int findKeyOrInsertPosition(K key) { /** * This does a linear scan which is simpler than a binary search. For a small collection size this - * still should be as fast a as binary search. + * still should be as fast as binary search. */ private int findKey(K key) { int i = 0; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreSettings.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreSettings.java index 4a539e8bd850..f243c97f5b2e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreSettings.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreSettings.java @@ -79,7 +79,7 @@ * * FirestoreSettings.Builder firestoreSettingsBuilder = * FirestoreSettings.newBuilder(); - * firestoreSettingsBuilder.updateDocumentSettings().getRetrySettingsBuilder() + * firestoreSettingsBuilder.updateDocumentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * FirestoreSettings firestoreSettings = firestoreSettingsBuilder.build(); * diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/FirestoreStubSettings.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/FirestoreStubSettings.java index 2ac69b5b6407..7874328df33c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/FirestoreStubSettings.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/FirestoreStubSettings.java @@ -94,7 +94,7 @@ * * FirestoreStubSettings.Builder firestoreSettingsBuilder = * FirestoreStubSettings.newBuilder(); - * firestoreSettingsBuilder.updateDocumentSettings().getRetrySettingsBuilder() + * firestoreSettingsBuilder.updateDocumentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * FirestoreStubSettings firestoreSettings = firestoreSettingsBuilder.build(); * diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/GrpcFirestoreCallableFactory.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/GrpcFirestoreCallableFactory.java new file mode 100644 index 000000000000..471efbdcbf03 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/GrpcFirestoreCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.firestore.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Firestore API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcFirestoreCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/GrpcFirestoreStub.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/GrpcFirestoreStub.java index 15bab6b0342f..ef85c46300ca 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/GrpcFirestoreStub.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/stub/GrpcFirestoreStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +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.ServerStreamingCallable; @@ -200,6 +200,8 @@ public class GrpcFirestoreStub extends FirestoreStub { private final UnaryCallable listCollectionIdsPagedCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcFirestoreStub create(FirestoreStubSettings settings) throws IOException { return new GrpcFirestoreStub(settings, ClientContext.create(settings)); } @@ -208,6 +210,12 @@ public static final GrpcFirestoreStub create(ClientContext clientContext) throws return new GrpcFirestoreStub(FirestoreStubSettings.newBuilder().build(), clientContext); } + public static final GrpcFirestoreStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcFirestoreStub( + FirestoreStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcFirestoreStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -215,6 +223,20 @@ public static final GrpcFirestoreStub create(ClientContext clientContext) throws */ protected GrpcFirestoreStub(FirestoreStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcFirestoreCallableFactory()); + } + + /** + * Constructs an instance of GrpcFirestoreStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcFirestoreStub( + FirestoreStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings getDocumentTransportSettings = GrpcCallSettings.newBuilder() @@ -273,53 +295,53 @@ protected GrpcFirestoreStub(FirestoreStubSettings settings, ClientContext client .build(); this.getDocumentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getDocumentTransportSettings, settings.getDocumentSettings(), clientContext); this.listDocumentsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listDocumentsTransportSettings, settings.listDocumentsSettings(), clientContext); this.listDocumentsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listDocumentsTransportSettings, settings.listDocumentsSettings(), clientContext); this.createDocumentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createDocumentTransportSettings, settings.createDocumentSettings(), clientContext); this.updateDocumentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateDocumentTransportSettings, settings.updateDocumentSettings(), clientContext); this.deleteDocumentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteDocumentTransportSettings, settings.deleteDocumentSettings(), clientContext); this.batchGetDocumentsCallable = - GrpcCallableFactory.createServerStreamingCallable( + callableFactory.createServerStreamingCallable( batchGetDocumentsTransportSettings, settings.batchGetDocumentsSettings(), clientContext); this.beginTransactionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( beginTransactionTransportSettings, settings.beginTransactionSettings(), clientContext); this.commitCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( commitTransportSettings, settings.commitSettings(), clientContext); this.rollbackCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( rollbackTransportSettings, settings.rollbackSettings(), clientContext); this.runQueryCallable = - GrpcCallableFactory.createServerStreamingCallable( + callableFactory.createServerStreamingCallable( runQueryTransportSettings, settings.runQuerySettings(), clientContext); this.writeCallable = - GrpcCallableFactory.createBidiStreamingCallable( + callableFactory.createBidiStreamingCallable( writeTransportSettings, settings.writeSettings(), clientContext); this.listenCallable = - GrpcCallableFactory.createBidiStreamingCallable( + callableFactory.createBidiStreamingCallable( listenTransportSettings, settings.listenSettings(), clientContext); this.listCollectionIdsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listCollectionIdsTransportSettings, settings.listCollectionIdsSettings(), clientContext); this.listCollectionIdsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listCollectionIdsTransportSettings, settings.listCollectionIdsSettings(), clientContext); diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java index af0aee0fe0df..740f2d8f1e11 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java @@ -85,8 +85,7 @@ public class ConformanceTest { private interface ConformanceTestCase extends Test, Describable {} /** Excluded tests by test description. */ - private final Set excludedTests = - Collections.singleton("set: MergeAll cannot be specified with empty data."); // b/73495873 + private final Set excludedTests = Collections.emptySet(); /** If non-empty, only runs tests included in this set. */ private final Set includedTests = Collections.emptySet(); @@ -208,6 +207,8 @@ private Object convertValue(Object data) { return convertMap((Map) data); } else if (data instanceof List) { return convertArray((List) data); + } else if ("NaN".equals(data)) { + return Double.NaN; } else if ("Delete".equals(data)) { return FieldValue.delete(); } else if ("ServerTimestamp".equals(data)) { diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/OrderTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/OrderTest.java index d19585c68ac1..0043fa977d6d 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/OrderTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/OrderTest.java @@ -89,7 +89,7 @@ public void verifyOrder() { groups[38] = new Value[] {referenceValue("projects/p1/databases/dkkkkklkjnjkkk1/documents/c2/doc1")}; groups[39] = new Value[] {referenceValue("projects/p2/databases/d2/documents/c1/doc1")}; - groups[40] = new Value[] {referenceValue("projects/p2/databases/d2/documents/cl1-/doc1")}; + groups[40] = new Value[] {referenceValue("projects/p2/databases/d2/documents/c1-/doc1")}; // geo points groups[41] = new Value[] {geoPointValue(-90, -180)}; diff --git a/google-cloud-firestore/src/test/resources/test-suite.binproto b/google-cloud-firestore/src/test/resources/test-suite.binproto index 06bcd2989c30..6ed663ef9663 100644 Binary files a/google-cloud-firestore/src/test/resources/test-suite.binproto and b/google-cloud-firestore/src/test/resources/test-suite.binproto differ diff --git a/google-cloud-language/README.md b/google-cloud-language/README.md index 77df12ea8c24..112593c8ba20 100644 --- a/google-cloud-language/README.md +++ b/google-cloud-language/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-language - 1.20.0 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-language:1.20.0' +compile 'com.google.cloud:google-cloud-language:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-language" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-language" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-language/pom.xml b/google-cloud-language/pom.xml index 1249c1f2658e..27bb35c78860 100644 --- a/google-cloud-language/pom.xml +++ b/google-cloud-language/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-language - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Natural Language https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-language @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-language diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceSettings.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceSettings.java index 374dc93a8e7c..7c855f2cd83f 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceSettings.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1/LanguageServiceSettings.java @@ -50,7 +50,7 @@ * * LanguageServiceSettings.Builder languageServiceSettingsBuilder = * LanguageServiceSettings.newBuilder(); - * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettingsBuilder() + * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * LanguageServiceSettings languageServiceSettings = languageServiceSettingsBuilder.build(); * diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/GrpcLanguageServiceCallableFactory.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/GrpcLanguageServiceCallableFactory.java new file mode 100644 index 000000000000..dd78404e1ebc --- /dev/null +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/GrpcLanguageServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.language.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Natural Language API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcLanguageServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/GrpcLanguageServiceStub.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/GrpcLanguageServiceStub.java index ace9554e31f0..b8aa0f76a347 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/GrpcLanguageServiceStub.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/GrpcLanguageServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.language.v1.AnalyzeEntitiesRequest; @@ -123,6 +123,8 @@ public class GrpcLanguageServiceStub extends LanguageServiceStub { private final UnaryCallable classifyTextCallable; private final UnaryCallable annotateTextCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcLanguageServiceStub create(LanguageServiceStubSettings settings) throws IOException { return new GrpcLanguageServiceStub(settings, ClientContext.create(settings)); @@ -134,6 +136,12 @@ public static final GrpcLanguageServiceStub create(ClientContext clientContext) LanguageServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcLanguageServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcLanguageServiceStub( + LanguageServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcLanguageServiceStub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -141,6 +149,20 @@ public static final GrpcLanguageServiceStub create(ClientContext clientContext) */ protected GrpcLanguageServiceStub( LanguageServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcLanguageServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcLanguageServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcLanguageServiceStub( + LanguageServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings analyzeSentimentTransportSettings = @@ -172,24 +194,24 @@ protected GrpcLanguageServiceStub( .build(); this.analyzeSentimentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeSentimentTransportSettings, settings.analyzeSentimentSettings(), clientContext); this.analyzeEntitiesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeEntitiesTransportSettings, settings.analyzeEntitiesSettings(), clientContext); this.analyzeEntitySentimentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeEntitySentimentTransportSettings, settings.analyzeEntitySentimentSettings(), clientContext); this.analyzeSyntaxCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeSyntaxTransportSettings, settings.analyzeSyntaxSettings(), clientContext); this.classifyTextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( classifyTextTransportSettings, settings.classifyTextSettings(), clientContext); this.annotateTextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( annotateTextTransportSettings, settings.annotateTextSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/LanguageServiceStubSettings.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/LanguageServiceStubSettings.java index af452951d375..b279a9e1705d 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/LanguageServiceStubSettings.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1/stub/LanguageServiceStubSettings.java @@ -71,7 +71,7 @@ * * LanguageServiceStubSettings.Builder languageServiceSettingsBuilder = * LanguageServiceStubSettings.newBuilder(); - * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettingsBuilder() + * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * LanguageServiceStubSettings languageServiceSettings = languageServiceSettingsBuilder.build(); * diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/LanguageServiceSettings.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/LanguageServiceSettings.java index 51c8f87f56a3..ab0f59c85084 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/LanguageServiceSettings.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/LanguageServiceSettings.java @@ -50,7 +50,7 @@ * * LanguageServiceSettings.Builder languageServiceSettingsBuilder = * LanguageServiceSettings.newBuilder(); - * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettingsBuilder() + * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * LanguageServiceSettings languageServiceSettings = languageServiceSettingsBuilder.build(); * diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/GrpcLanguageServiceCallableFactory.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/GrpcLanguageServiceCallableFactory.java new file mode 100644 index 000000000000..c30441552c82 --- /dev/null +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/GrpcLanguageServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.language.v1beta2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Natural Language API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcLanguageServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/GrpcLanguageServiceStub.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/GrpcLanguageServiceStub.java index ed14d24a6fdb..7681b65a0332 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/GrpcLanguageServiceStub.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/GrpcLanguageServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.language.v1beta2.AnalyzeEntitiesRequest; @@ -124,6 +124,8 @@ public class GrpcLanguageServiceStub extends LanguageServiceStub { private final UnaryCallable classifyTextCallable; private final UnaryCallable annotateTextCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcLanguageServiceStub create(LanguageServiceStubSettings settings) throws IOException { return new GrpcLanguageServiceStub(settings, ClientContext.create(settings)); @@ -135,6 +137,12 @@ public static final GrpcLanguageServiceStub create(ClientContext clientContext) LanguageServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcLanguageServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcLanguageServiceStub( + LanguageServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcLanguageServiceStub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -142,6 +150,20 @@ public static final GrpcLanguageServiceStub create(ClientContext clientContext) */ protected GrpcLanguageServiceStub( LanguageServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcLanguageServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcLanguageServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcLanguageServiceStub( + LanguageServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings analyzeSentimentTransportSettings = @@ -173,24 +195,24 @@ protected GrpcLanguageServiceStub( .build(); this.analyzeSentimentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeSentimentTransportSettings, settings.analyzeSentimentSettings(), clientContext); this.analyzeEntitiesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeEntitiesTransportSettings, settings.analyzeEntitiesSettings(), clientContext); this.analyzeEntitySentimentCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeEntitySentimentTransportSettings, settings.analyzeEntitySentimentSettings(), clientContext); this.analyzeSyntaxCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( analyzeSyntaxTransportSettings, settings.analyzeSyntaxSettings(), clientContext); this.classifyTextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( classifyTextTransportSettings, settings.classifyTextSettings(), clientContext); this.annotateTextCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( annotateTextTransportSettings, settings.annotateTextSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/LanguageServiceStubSettings.java b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/LanguageServiceStubSettings.java index 5cbc116ac478..4f1a991a92e1 100644 --- a/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/LanguageServiceStubSettings.java +++ b/google-cloud-language/src/main/java/com/google/cloud/language/v1beta2/stub/LanguageServiceStubSettings.java @@ -71,7 +71,7 @@ * * LanguageServiceStubSettings.Builder languageServiceSettingsBuilder = * LanguageServiceStubSettings.newBuilder(); - * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettingsBuilder() + * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * LanguageServiceStubSettings languageServiceSettings = languageServiceSettingsBuilder.build(); * diff --git a/google-cloud-language/src/test/java/com/google/cloud/language/v1/LanguageServiceSmokeTest.java b/google-cloud-language/src/test/java/com/google/cloud/language/v1/LanguageServiceSmokeTest.java new file mode 100644 index 000000000000..39c2bd431fae --- /dev/null +++ b/google-cloud-language/src/test/java/com/google/cloud/language/v1/LanguageServiceSmokeTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2018 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.cloud.language.v1; + +import com.google.cloud.language.v1.Document.Type; +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class LanguageServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (LanguageServiceClient client = LanguageServiceClient.create()) { + String content = "Hello, world!"; + Document.Type type = Document.Type.PLAIN_TEXT; + Document document = Document.newBuilder().setContent(content).setType(type).build(); + + AnalyzeSentimentResponse response = client.analyzeSentiment(document); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-language/src/test/java/com/google/cloud/language/v1beta2/LanguageServiceSmokeTest.java b/google-cloud-language/src/test/java/com/google/cloud/language/v1beta2/LanguageServiceSmokeTest.java new file mode 100644 index 000000000000..a20365302d20 --- /dev/null +++ b/google-cloud-language/src/test/java/com/google/cloud/language/v1beta2/LanguageServiceSmokeTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2018 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.cloud.language.v1beta2; + +import com.google.cloud.language.v1beta2.Document.Type; +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class LanguageServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (LanguageServiceClient client = LanguageServiceClient.create()) { + String content = "Hello, world!"; + Document.Type type = Document.Type.PLAIN_TEXT; + Document document = Document.newBuilder().setContent(content).setType(type).build(); + + AnalyzeSentimentResponse response = client.analyzeSentiment(document); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-logging/README.md b/google-cloud-logging/README.md index ba1d7a20894f..34505acc0097 100644 --- a/google-cloud-logging/README.md +++ b/google-cloud-logging/README.md @@ -21,16 +21,16 @@ Add this to your pom.xml file com.google.cloud google-cloud-logging - 1.20.0 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-logging:1.20.0' +compile 'com.google.cloud:google-cloud-logging:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-logging/pom.xml b/google-cloud-logging/pom.xml index 1faaa4c9550d..3aec11c77710 100644 --- a/google-cloud-logging/pom.xml +++ b/google-cloud-logging/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-logging - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Logging https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-logging @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-logging @@ -52,6 +52,11 @@ test-jar test + + com.google.truth + truth + test + com.google.api.grpc grpc-google-cloud-logging-v2 diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java index 5ae71a48c97d..b6153a9a639b 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java @@ -18,12 +18,11 @@ import com.google.api.core.ApiFuture; import com.google.api.gax.paging.AsyncPage; +import com.google.api.gax.paging.Page; import com.google.cloud.MonitoredResource; import com.google.cloud.MonitoredResourceDescriptor; -import com.google.api.gax.paging.Page; import com.google.cloud.Service; import com.google.common.collect.ImmutableMap; - import java.util.Map; public interface Logging extends AutoCloseable, Service { @@ -147,7 +146,8 @@ final class EntryListOption extends Option { private static final long serialVersionUID = -1561159676386917050L; enum OptionType implements Option.OptionType { - PAGE_SIZE, PAGE_TOKEN, ORDER_BY, FILTER; + ORDER_BY, + FILTER; @SuppressWarnings("unchecked") T get(Map options) { @@ -155,7 +155,7 @@ T get(Map options) { } } - private EntryListOption(OptionType option, Object value) { + private EntryListOption(Option.OptionType option, Object value) { super(option, value); } @@ -163,14 +163,14 @@ private EntryListOption(OptionType option, Object value) { * Returns an option to specify the maximum number of log entries returned per page. */ public static EntryListOption pageSize(int pageSize) { - return new EntryListOption(OptionType.PAGE_SIZE, pageSize); + return new EntryListOption(ListOption.OptionType.PAGE_SIZE, pageSize); } /** * Returns an option to specify the page token from which to start listing log entries. */ public static EntryListOption pageToken(String pageToken) { - return new EntryListOption(OptionType.PAGE_TOKEN, pageToken); + return new EntryListOption(ListOption.OptionType.PAGE_TOKEN, pageToken); } /** diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java index a901ad4bd7ed..32eb71c2861b 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java @@ -30,11 +30,11 @@ import com.google.api.core.ApiFutureCallback; import com.google.api.core.ApiFutures; import com.google.api.gax.paging.AsyncPage; +import com.google.api.gax.paging.Page; import com.google.cloud.AsyncPageImpl; import com.google.cloud.BaseService; import com.google.cloud.MonitoredResource; import com.google.cloud.MonitoredResourceDescriptor; -import com.google.api.gax.paging.Page; import com.google.cloud.PageImpl; import com.google.cloud.logging.spi.v2.LoggingRpc; import com.google.common.base.Function; @@ -59,13 +59,10 @@ import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; import com.google.logging.v2.ListSinksRequest; import com.google.logging.v2.ListSinksResponse; -import com.google.logging.v2.LogName; -import com.google.logging.v2.MetricName; import com.google.logging.v2.ProjectLogName; import com.google.logging.v2.ProjectMetricName; import com.google.logging.v2.ProjectName; import com.google.logging.v2.ProjectSinkName; -import com.google.logging.v2.SinkName; import com.google.logging.v2.UpdateLogMetricRequest; import com.google.logging.v2.UpdateSinkRequest; import com.google.logging.v2.WriteLogEntriesRequest; @@ -597,10 +594,10 @@ private ApiFuture writeAsync(Iterable logEntries, WriteOption... WRITE_RESPONSE_TO_VOID_FUNCTION); } - private static ListLogEntriesRequest listLogEntriesRequest(LoggingOptions serviceOptions, - Map options) { + static ListLogEntriesRequest listLogEntriesRequest( + String projectId, Map options) { ListLogEntriesRequest.Builder builder = ListLogEntriesRequest.newBuilder(); - builder.addProjectIds(serviceOptions.getProjectId()); + builder.addProjectIds(projectId); Integer pageSize = PAGE_SIZE.get(options); if (pageSize != null) { builder.setPageSize(pageSize); @@ -622,7 +619,8 @@ private static ListLogEntriesRequest listLogEntriesRequest(LoggingOptions servic private static ApiFuture> listLogEntriesAsync( final LoggingOptions serviceOptions, final Map options) { - final ListLogEntriesRequest request = listLogEntriesRequest(serviceOptions, options); + final ListLogEntriesRequest request = + listLogEntriesRequest(serviceOptions.getProjectId(), options); ApiFuture list = serviceOptions.getLoggingRpcV2().list(request); return transform(list, new Function>() { @Override diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/ConfigSettings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/ConfigSettings.java index 0874112c0258..4cdc24d28b25 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/ConfigSettings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/ConfigSettings.java @@ -69,7 +69,7 @@ * * ConfigSettings.Builder configSettingsBuilder = * ConfigSettings.newBuilder(); - * configSettingsBuilder.getSinkSettings().getRetrySettingsBuilder() + * configSettingsBuilder.getSinkSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ConfigSettings configSettings = configSettingsBuilder.build(); * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/LoggingSettings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/LoggingSettings.java index d0ba254b9965..a547c2525a4d 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/LoggingSettings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/LoggingSettings.java @@ -66,7 +66,7 @@ * * LoggingSettings.Builder loggingSettingsBuilder = * LoggingSettings.newBuilder(); - * loggingSettingsBuilder.deleteLogSettings().getRetrySettingsBuilder() + * loggingSettingsBuilder.deleteLogSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * LoggingSettings loggingSettings = loggingSettingsBuilder.build(); * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/MetricsSettings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/MetricsSettings.java index 5887f84bc1ac..c8d72d51d5e7 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/MetricsSettings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/MetricsSettings.java @@ -61,7 +61,7 @@ * * MetricsSettings.Builder metricsSettingsBuilder = * MetricsSettings.newBuilder(); - * metricsSettingsBuilder.getLogMetricSettings().getRetrySettingsBuilder() + * metricsSettingsBuilder.getLogMetricSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * MetricsSettings metricsSettings = metricsSettingsBuilder.build(); * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/ConfigServiceV2StubSettings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/ConfigServiceV2StubSettings.java index ab82fef0e20b..872ab54f9731 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/ConfigServiceV2StubSettings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/ConfigServiceV2StubSettings.java @@ -84,7 +84,7 @@ * * ConfigServiceV2StubSettings.Builder configSettingsBuilder = * ConfigServiceV2StubSettings.newBuilder(); - * configSettingsBuilder.getSinkSettings().getRetrySettingsBuilder() + * configSettingsBuilder.getSinkSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ConfigServiceV2StubSettings configSettings = configSettingsBuilder.build(); * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2CallableFactory.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2CallableFactory.java new file mode 100644 index 000000000000..4594dda96bfa --- /dev/null +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2CallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.logging.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Logging API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcConfigServiceV2CallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java index 83de9f3cdc56..2a3d96ee0644 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.logging.v2.CreateExclusionRequest; @@ -154,6 +154,8 @@ public class GrpcConfigServiceV2Stub extends ConfigServiceV2Stub { private final UnaryCallable updateExclusionCallable; private final UnaryCallable deleteExclusionCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcConfigServiceV2Stub create(ConfigServiceV2StubSettings settings) throws IOException { return new GrpcConfigServiceV2Stub(settings, ClientContext.create(settings)); @@ -165,6 +167,12 @@ public static final GrpcConfigServiceV2Stub create(ClientContext clientContext) ConfigServiceV2StubSettings.newBuilder().build(), clientContext); } + public static final GrpcConfigServiceV2Stub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcConfigServiceV2Stub( + ConfigServiceV2StubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcConfigServiceV2Stub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -172,6 +180,20 @@ public static final GrpcConfigServiceV2Stub create(ClientContext clientContext) */ protected GrpcConfigServiceV2Stub( ConfigServiceV2StubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcConfigServiceV2CallableFactory()); + } + + /** + * Constructs an instance of GrpcConfigServiceV2Stub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcConfigServiceV2Stub( + ConfigServiceV2StubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listSinksTransportSettings = GrpcCallSettings.newBuilder() @@ -216,40 +238,40 @@ protected GrpcConfigServiceV2Stub( .build(); this.listSinksCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listSinksTransportSettings, settings.listSinksSettings(), clientContext); this.listSinksPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listSinksTransportSettings, settings.listSinksSettings(), clientContext); this.getSinkCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getSinkTransportSettings, settings.getSinkSettings(), clientContext); this.createSinkCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createSinkTransportSettings, settings.createSinkSettings(), clientContext); this.updateSinkCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateSinkTransportSettings, settings.updateSinkSettings(), clientContext); this.deleteSinkCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteSinkTransportSettings, settings.deleteSinkSettings(), clientContext); this.listExclusionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listExclusionsTransportSettings, settings.listExclusionsSettings(), clientContext); this.listExclusionsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listExclusionsTransportSettings, settings.listExclusionsSettings(), clientContext); this.getExclusionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getExclusionTransportSettings, settings.getExclusionSettings(), clientContext); this.createExclusionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createExclusionTransportSettings, settings.createExclusionSettings(), clientContext); this.updateExclusionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateExclusionTransportSettings, settings.updateExclusionSettings(), clientContext); this.deleteExclusionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteExclusionTransportSettings, settings.deleteExclusionSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2CallableFactory.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2CallableFactory.java new file mode 100644 index 000000000000..256d4e6200ed --- /dev/null +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2CallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.logging.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Logging API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcLoggingServiceV2CallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java index 6e521fffc34b..3af51d94e7d6 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java @@ -23,7 +23,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.logging.v2.DeleteLogRequest; @@ -121,6 +121,8 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub { private final UnaryCallable listLogsCallable; private final UnaryCallable listLogsPagedCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcLoggingServiceV2Stub create(LoggingServiceV2StubSettings settings) throws IOException { return new GrpcLoggingServiceV2Stub(settings, ClientContext.create(settings)); @@ -132,6 +134,12 @@ public static final GrpcLoggingServiceV2Stub create(ClientContext clientContext) LoggingServiceV2StubSettings.newBuilder().build(), clientContext); } + public static final GrpcLoggingServiceV2Stub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcLoggingServiceV2Stub( + LoggingServiceV2StubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcLoggingServiceV2Stub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -139,6 +147,20 @@ public static final GrpcLoggingServiceV2Stub create(ClientContext clientContext) */ protected GrpcLoggingServiceV2Stub( LoggingServiceV2StubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcLoggingServiceV2CallableFactory()); + } + + /** + * Constructs an instance of GrpcLoggingServiceV2Stub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcLoggingServiceV2Stub( + LoggingServiceV2StubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings deleteLogTransportSettings = GrpcCallSettings.newBuilder() @@ -168,32 +190,32 @@ protected GrpcLoggingServiceV2Stub( .build(); this.deleteLogCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteLogTransportSettings, settings.deleteLogSettings(), clientContext); this.writeLogEntriesCallable = - GrpcCallableFactory.createBatchingCallable( + callableFactory.createBatchingCallable( writeLogEntriesTransportSettings, settings.writeLogEntriesSettings(), clientContext); this.listLogEntriesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listLogEntriesTransportSettings, settings.listLogEntriesSettings(), clientContext); this.listLogEntriesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listLogEntriesTransportSettings, settings.listLogEntriesSettings(), clientContext); this.listMonitoredResourceDescriptorsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listMonitoredResourceDescriptorsTransportSettings, settings.listMonitoredResourceDescriptorsSettings(), clientContext); this.listMonitoredResourceDescriptorsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listMonitoredResourceDescriptorsTransportSettings, settings.listMonitoredResourceDescriptorsSettings(), clientContext); this.listLogsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listLogsTransportSettings, settings.listLogsSettings(), clientContext); this.listLogsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listLogsTransportSettings, settings.listLogsSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2CallableFactory.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2CallableFactory.java new file mode 100644 index 000000000000..de9e82478c16 --- /dev/null +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2CallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.logging.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Logging API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcMetricsServiceV2CallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java index eb139d761cd6..8101974b9d36 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.logging.v2.CreateLogMetricRequest; @@ -104,6 +104,8 @@ public class GrpcMetricsServiceV2Stub extends MetricsServiceV2Stub { private final UnaryCallable updateLogMetricCallable; private final UnaryCallable deleteLogMetricCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcMetricsServiceV2Stub create(MetricsServiceV2StubSettings settings) throws IOException { return new GrpcMetricsServiceV2Stub(settings, ClientContext.create(settings)); @@ -115,6 +117,12 @@ public static final GrpcMetricsServiceV2Stub create(ClientContext clientContext) MetricsServiceV2StubSettings.newBuilder().build(), clientContext); } + public static final GrpcMetricsServiceV2Stub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcMetricsServiceV2Stub( + MetricsServiceV2StubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcMetricsServiceV2Stub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -122,6 +130,20 @@ public static final GrpcMetricsServiceV2Stub create(ClientContext clientContext) */ protected GrpcMetricsServiceV2Stub( MetricsServiceV2StubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcMetricsServiceV2CallableFactory()); + } + + /** + * Constructs an instance of GrpcMetricsServiceV2Stub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcMetricsServiceV2Stub( + MetricsServiceV2StubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listLogMetricsTransportSettings = @@ -146,22 +168,22 @@ protected GrpcMetricsServiceV2Stub( .build(); this.listLogMetricsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listLogMetricsTransportSettings, settings.listLogMetricsSettings(), clientContext); this.listLogMetricsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listLogMetricsTransportSettings, settings.listLogMetricsSettings(), clientContext); this.getLogMetricCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getLogMetricTransportSettings, settings.getLogMetricSettings(), clientContext); this.createLogMetricCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createLogMetricTransportSettings, settings.createLogMetricSettings(), clientContext); this.updateLogMetricCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateLogMetricTransportSettings, settings.updateLogMetricSettings(), clientContext); this.deleteLogMetricCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteLogMetricTransportSettings, settings.deleteLogMetricSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/LoggingServiceV2StubSettings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/LoggingServiceV2StubSettings.java index f2b347a97d8a..9f165f9224d9 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/LoggingServiceV2StubSettings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/LoggingServiceV2StubSettings.java @@ -91,7 +91,7 @@ * * LoggingServiceV2StubSettings.Builder loggingSettingsBuilder = * LoggingServiceV2StubSettings.newBuilder(); - * loggingSettingsBuilder.deleteLogSettings().getRetrySettingsBuilder() + * loggingSettingsBuilder.deleteLogSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * LoggingServiceV2StubSettings loggingSettings = loggingSettingsBuilder.build(); * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/MetricsServiceV2StubSettings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/MetricsServiceV2StubSettings.java index 9d8fbe8f9549..e1049f1ef1be 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/MetricsServiceV2StubSettings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/v2/stub/MetricsServiceV2StubSettings.java @@ -76,7 +76,7 @@ * * MetricsServiceV2StubSettings.Builder metricsSettingsBuilder = * MetricsServiceV2StubSettings.newBuilder(); - * metricsSettingsBuilder.getLogMetricSettings().getRetrySettingsBuilder() + * metricsSettingsBuilder.getLogMetricSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * MetricsServiceV2StubSettings metricsSettings = metricsSettingsBuilder.build(); * diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java index 5d118cb55f7b..b08ea2ed9cf6 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java @@ -20,15 +20,15 @@ import static com.google.cloud.logging.Logging.SortingField; import static com.google.cloud.logging.Logging.SortingOrder; import static com.google.cloud.logging.Logging.WriteOption; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import com.google.cloud.MonitoredResource; import com.google.cloud.logging.Logging.ListOption; import com.google.common.collect.ImmutableMap; - -import org.junit.Test; - +import com.google.logging.v2.ListLogEntriesRequest; import java.util.Map; +import org.junit.Test; public class LoggingTest { @@ -56,11 +56,11 @@ public void testListOption() { public void testEntryListOption() { EntryListOption listOption = EntryListOption.pageToken(PAGE_TOKEN); assertEquals(PAGE_TOKEN, listOption.getValue()); - assertEquals(EntryListOption.OptionType.PAGE_TOKEN, listOption.getOptionType()); + assertEquals(ListOption.OptionType.PAGE_TOKEN, listOption.getOptionType()); // page size listOption = EntryListOption.pageSize(PAGE_SIZE); assertEquals(PAGE_SIZE, listOption.getValue()); - assertEquals(EntryListOption.OptionType.PAGE_SIZE, listOption.getOptionType()); + assertEquals(ListOption.OptionType.PAGE_SIZE, listOption.getOptionType()); // filter listOption = EntryListOption.filter(FILTER); assertEquals(FILTER, listOption.getValue()); @@ -72,6 +72,14 @@ public void testEntryListOption() { listOption = EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.DESCENDING); assertEquals("timestamp desc", listOption.getValue()); assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.getOptionType()); + + ListLogEntriesRequest request = + LoggingImpl.listLogEntriesRequest( + "some-project-id", + LoggingImpl.optionMap( + EntryListOption.pageToken(PAGE_TOKEN), EntryListOption.pageSize(PAGE_SIZE))); + assertThat(request.getPageToken()).isEqualTo(PAGE_TOKEN); + assertThat(request.getPageSize()).isEqualTo(PAGE_SIZE); } @Test diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/v2/LoggingSmokeTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/v2/LoggingSmokeTest.java new file mode 100644 index 000000000000..3f9d7db78003 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/v2/LoggingSmokeTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2018 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.cloud.logging.v2; + +import com.google.api.MonitoredResource; +import com.google.common.base.Preconditions; +import com.google.logging.v2.LogEntry; +import com.google.logging.v2.LogName; +import com.google.logging.v2.ProjectLogName; +import com.google.logging.v2.WriteLogEntriesResponse; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class LoggingSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (LoggingClient client = LoggingClient.create()) { + LogName logName = ProjectLogName.of(projectId, "test-" + System.currentTimeMillis()); + MonitoredResource resource = MonitoredResource.newBuilder().build(); + Map labels = new HashMap<>(); + List entries = new ArrayList<>(); + + WriteLogEntriesResponse response = client.writeLogEntries(logName, resource, labels, entries); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-monitoring/README.md b/google-cloud-monitoring/README.md index 222f6080e612..8dda1a852e99 100644 --- a/google-cloud-monitoring/README.md +++ b/google-cloud-monitoring/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-monitoring - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-monitoring:0.38.0-beta' +compile 'com.google.cloud:google-cloud-monitoring:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-monitoring" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-monitoring" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-monitoring/pom.xml b/google-cloud-monitoring/pom.xml index 2ebbb15cf0d6..6d075bb5c2a6 100644 --- a/google-cloud-monitoring/pom.xml +++ b/google-cloud-monitoring/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-monitoring - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Monitoring https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-monitoring @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-monitoring diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/AlertPolicyServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/AlertPolicyServiceSettings.java index 8021727dbcf6..21f56fb6eea7 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/AlertPolicyServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/AlertPolicyServiceSettings.java @@ -61,7 +61,7 @@ * * AlertPolicyServiceSettings.Builder alertPolicyServiceSettingsBuilder = * AlertPolicyServiceSettings.newBuilder(); - * alertPolicyServiceSettingsBuilder.getAlertPolicySettings().getRetrySettingsBuilder() + * alertPolicyServiceSettingsBuilder.getAlertPolicySettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * AlertPolicyServiceSettings alertPolicyServiceSettings = alertPolicyServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/GroupServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/GroupServiceSettings.java index c22bf0d7adca..86b4a4e9040a 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/GroupServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/GroupServiceSettings.java @@ -64,7 +64,7 @@ * * GroupServiceSettings.Builder groupServiceSettingsBuilder = * GroupServiceSettings.newBuilder(); - * groupServiceSettingsBuilder.getGroupSettings().getRetrySettingsBuilder() + * groupServiceSettingsBuilder.getGroupSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * GroupServiceSettings groupServiceSettings = groupServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/MetricServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/MetricServiceSettings.java index 6e44667a69de..6e69ced8d8d0 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/MetricServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/MetricServiceSettings.java @@ -69,7 +69,7 @@ * * MetricServiceSettings.Builder metricServiceSettingsBuilder = * MetricServiceSettings.newBuilder(); - * metricServiceSettingsBuilder.getMonitoredResourceDescriptorSettings().getRetrySettingsBuilder() + * metricServiceSettingsBuilder.getMonitoredResourceDescriptorSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * MetricServiceSettings metricServiceSettings = metricServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/NotificationChannelServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/NotificationChannelServiceSettings.java index 532523aca84b..77ab4b0d8f25 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/NotificationChannelServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/NotificationChannelServiceSettings.java @@ -66,7 +66,7 @@ * * NotificationChannelServiceSettings.Builder notificationChannelServiceSettingsBuilder = * NotificationChannelServiceSettings.newBuilder(); - * notificationChannelServiceSettingsBuilder.getNotificationChannelDescriptorSettings().getRetrySettingsBuilder() + * notificationChannelServiceSettingsBuilder.getNotificationChannelDescriptorSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * NotificationChannelServiceSettings notificationChannelServiceSettings = notificationChannelServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/UptimeCheckServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/UptimeCheckServiceSettings.java index 3538d2d12cc4..a02cc3768fb2 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/UptimeCheckServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/UptimeCheckServiceSettings.java @@ -64,7 +64,7 @@ * * UptimeCheckServiceSettings.Builder uptimeCheckServiceSettingsBuilder = * UptimeCheckServiceSettings.newBuilder(); - * uptimeCheckServiceSettingsBuilder.getUptimeCheckConfigSettings().getRetrySettingsBuilder() + * uptimeCheckServiceSettingsBuilder.getUptimeCheckConfigSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * UptimeCheckServiceSettings uptimeCheckServiceSettings = uptimeCheckServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/AlertPolicyServiceStubSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/AlertPolicyServiceStubSettings.java index 2774f0ff7a16..7f7e9599ca4f 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/AlertPolicyServiceStubSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/AlertPolicyServiceStubSettings.java @@ -76,7 +76,7 @@ * * AlertPolicyServiceStubSettings.Builder alertPolicyServiceSettingsBuilder = * AlertPolicyServiceStubSettings.newBuilder(); - * alertPolicyServiceSettingsBuilder.getAlertPolicySettings().getRetrySettingsBuilder() + * alertPolicyServiceSettingsBuilder.getAlertPolicySettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * AlertPolicyServiceStubSettings alertPolicyServiceSettings = alertPolicyServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GroupServiceStubSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GroupServiceStubSettings.java index fa3d1772cac8..e6877dcc6d40 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GroupServiceStubSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GroupServiceStubSettings.java @@ -80,7 +80,7 @@ * * GroupServiceStubSettings.Builder groupServiceSettingsBuilder = * GroupServiceStubSettings.newBuilder(); - * groupServiceSettingsBuilder.getGroupSettings().getRetrySettingsBuilder() + * groupServiceSettingsBuilder.getGroupSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * GroupServiceStubSettings groupServiceSettings = groupServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcAlertPolicyServiceCallableFactory.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcAlertPolicyServiceCallableFactory.java new file mode 100644 index 000000000000..20beb8e47ab1 --- /dev/null +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcAlertPolicyServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.monitoring.v3.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Monitoring API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcAlertPolicyServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcAlertPolicyServiceStub.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcAlertPolicyServiceStub.java index cc9253db22b6..f1e754413a99 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcAlertPolicyServiceStub.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcAlertPolicyServiceStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.monitoring.v3.AlertPolicy; @@ -106,6 +106,8 @@ public class GrpcAlertPolicyServiceStub extends AlertPolicyServiceStub { private final UnaryCallable deleteAlertPolicyCallable; private final UnaryCallable updateAlertPolicyCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcAlertPolicyServiceStub create(AlertPolicyServiceStubSettings settings) throws IOException { return new GrpcAlertPolicyServiceStub(settings, ClientContext.create(settings)); @@ -117,6 +119,12 @@ public static final GrpcAlertPolicyServiceStub create(ClientContext clientContex AlertPolicyServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcAlertPolicyServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcAlertPolicyServiceStub( + AlertPolicyServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcAlertPolicyServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -124,6 +132,20 @@ public static final GrpcAlertPolicyServiceStub create(ClientContext clientContex */ protected GrpcAlertPolicyServiceStub( AlertPolicyServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcAlertPolicyServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcAlertPolicyServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcAlertPolicyServiceStub( + AlertPolicyServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listAlertPoliciesTransportSettings = @@ -148,30 +170,30 @@ protected GrpcAlertPolicyServiceStub( .build(); this.listAlertPoliciesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listAlertPoliciesTransportSettings, settings.listAlertPoliciesSettings(), clientContext); this.listAlertPoliciesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listAlertPoliciesTransportSettings, settings.listAlertPoliciesSettings(), clientContext); this.getAlertPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getAlertPolicyTransportSettings, settings.getAlertPolicySettings(), clientContext); this.createAlertPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createAlertPolicyTransportSettings, settings.createAlertPolicySettings(), clientContext); this.deleteAlertPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteAlertPolicyTransportSettings, settings.deleteAlertPolicySettings(), clientContext); this.updateAlertPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateAlertPolicyTransportSettings, settings.updateAlertPolicySettings(), clientContext); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcGroupServiceCallableFactory.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcGroupServiceCallableFactory.java new file mode 100644 index 000000000000..8526afc9011c --- /dev/null +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcGroupServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.monitoring.v3.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Monitoring API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcGroupServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcGroupServiceStub.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcGroupServiceStub.java index 16164f3fd6ad..b654ff471402 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcGroupServiceStub.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcGroupServiceStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.monitoring.v3.CreateGroupRequest; @@ -111,6 +111,8 @@ public class GrpcGroupServiceStub extends GroupServiceStub { private final UnaryCallable listGroupMembersPagedCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcGroupServiceStub create(GroupServiceStubSettings settings) throws IOException { return new GrpcGroupServiceStub(settings, ClientContext.create(settings)); @@ -120,6 +122,12 @@ public static final GrpcGroupServiceStub create(ClientContext clientContext) thr return new GrpcGroupServiceStub(GroupServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcGroupServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcGroupServiceStub( + GroupServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcGroupServiceStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -127,6 +135,20 @@ public static final GrpcGroupServiceStub create(ClientContext clientContext) thr */ protected GrpcGroupServiceStub(GroupServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcGroupServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcGroupServiceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcGroupServiceStub( + GroupServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listGroupsTransportSettings = GrpcCallSettings.newBuilder() @@ -155,28 +177,28 @@ protected GrpcGroupServiceStub(GroupServiceStubSettings settings, ClientContext .build(); this.listGroupsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listGroupsTransportSettings, settings.listGroupsSettings(), clientContext); this.listGroupsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listGroupsTransportSettings, settings.listGroupsSettings(), clientContext); this.getGroupCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getGroupTransportSettings, settings.getGroupSettings(), clientContext); this.createGroupCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createGroupTransportSettings, settings.createGroupSettings(), clientContext); this.updateGroupCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateGroupTransportSettings, settings.updateGroupSettings(), clientContext); this.deleteGroupCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteGroupTransportSettings, settings.deleteGroupSettings(), clientContext); this.listGroupMembersCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listGroupMembersTransportSettings, settings.listGroupMembersSettings(), clientContext); this.listGroupMembersPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listGroupMembersTransportSettings, settings.listGroupMembersSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcMetricServiceCallableFactory.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcMetricServiceCallableFactory.java new file mode 100644 index 000000000000..f34cac5b8710 --- /dev/null +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcMetricServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.monitoring.v3.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Monitoring API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcMetricServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcMetricServiceStub.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcMetricServiceStub.java index a22571467ccf..47b85d134b3d 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcMetricServiceStub.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcMetricServiceStub.java @@ -25,7 +25,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.monitoring.v3.CreateMetricDescriptorRequest; @@ -166,6 +166,8 @@ public class GrpcMetricServiceStub extends MetricServiceStub { listTimeSeriesPagedCallable; private final UnaryCallable createTimeSeriesCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcMetricServiceStub create(MetricServiceStubSettings settings) throws IOException { return new GrpcMetricServiceStub(settings, ClientContext.create(settings)); @@ -175,6 +177,12 @@ public static final GrpcMetricServiceStub create(ClientContext clientContext) th return new GrpcMetricServiceStub(MetricServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcMetricServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcMetricServiceStub( + MetricServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcMetricServiceStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -182,6 +190,20 @@ public static final GrpcMetricServiceStub create(ClientContext clientContext) th */ protected GrpcMetricServiceStub(MetricServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcMetricServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcMetricServiceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcMetricServiceStub( + MetricServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> @@ -228,53 +250,53 @@ protected GrpcMetricServiceStub(MetricServiceStubSettings settings, ClientContex .build(); this.listMonitoredResourceDescriptorsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listMonitoredResourceDescriptorsTransportSettings, settings.listMonitoredResourceDescriptorsSettings(), clientContext); this.listMonitoredResourceDescriptorsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listMonitoredResourceDescriptorsTransportSettings, settings.listMonitoredResourceDescriptorsSettings(), clientContext); this.getMonitoredResourceDescriptorCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getMonitoredResourceDescriptorTransportSettings, settings.getMonitoredResourceDescriptorSettings(), clientContext); this.listMetricDescriptorsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listMetricDescriptorsTransportSettings, settings.listMetricDescriptorsSettings(), clientContext); this.listMetricDescriptorsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listMetricDescriptorsTransportSettings, settings.listMetricDescriptorsSettings(), clientContext); this.getMetricDescriptorCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getMetricDescriptorTransportSettings, settings.getMetricDescriptorSettings(), clientContext); this.createMetricDescriptorCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createMetricDescriptorTransportSettings, settings.createMetricDescriptorSettings(), clientContext); this.deleteMetricDescriptorCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteMetricDescriptorTransportSettings, settings.deleteMetricDescriptorSettings(), clientContext); this.listTimeSeriesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTimeSeriesTransportSettings, settings.listTimeSeriesSettings(), clientContext); this.listTimeSeriesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTimeSeriesTransportSettings, settings.listTimeSeriesSettings(), clientContext); this.createTimeSeriesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createTimeSeriesTransportSettings, settings.createTimeSeriesSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcNotificationChannelServiceCallableFactory.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcNotificationChannelServiceCallableFactory.java new file mode 100644 index 000000000000..3ae221dc4080 --- /dev/null +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcNotificationChannelServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.monitoring.v3.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Monitoring API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcNotificationChannelServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcNotificationChannelServiceStub.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcNotificationChannelServiceStub.java index a428cc92fbbb..d93c1178ae22 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcNotificationChannelServiceStub.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcNotificationChannelServiceStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.monitoring.v3.CreateNotificationChannelRequest; @@ -167,6 +167,8 @@ public class GrpcNotificationChannelServiceStub extends NotificationChannelServi private final UnaryCallable deleteNotificationChannelCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcNotificationChannelServiceStub create( NotificationChannelServiceStubSettings settings) throws IOException { return new GrpcNotificationChannelServiceStub(settings, ClientContext.create(settings)); @@ -178,6 +180,14 @@ public static final GrpcNotificationChannelServiceStub create(ClientContext clie NotificationChannelServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcNotificationChannelServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcNotificationChannelServiceStub( + NotificationChannelServiceStubSettings.newBuilder().build(), + clientContext, + callableFactory); + } + /** * Constructs an instance of GrpcNotificationChannelServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -186,6 +196,20 @@ public static final GrpcNotificationChannelServiceStub create(ClientContext clie protected GrpcNotificationChannelServiceStub( NotificationChannelServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcNotificationChannelServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcNotificationChannelServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcNotificationChannelServiceStub( + NotificationChannelServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings< ListNotificationChannelDescriptorsRequest, ListNotificationChannelDescriptorsResponse> @@ -231,47 +255,47 @@ protected GrpcNotificationChannelServiceStub( .build(); this.listNotificationChannelDescriptorsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listNotificationChannelDescriptorsTransportSettings, settings.listNotificationChannelDescriptorsSettings(), clientContext); this.listNotificationChannelDescriptorsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listNotificationChannelDescriptorsTransportSettings, settings.listNotificationChannelDescriptorsSettings(), clientContext); this.getNotificationChannelDescriptorCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getNotificationChannelDescriptorTransportSettings, settings.getNotificationChannelDescriptorSettings(), clientContext); this.listNotificationChannelsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listNotificationChannelsTransportSettings, settings.listNotificationChannelsSettings(), clientContext); this.listNotificationChannelsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listNotificationChannelsTransportSettings, settings.listNotificationChannelsSettings(), clientContext); this.getNotificationChannelCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getNotificationChannelTransportSettings, settings.getNotificationChannelSettings(), clientContext); this.createNotificationChannelCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createNotificationChannelTransportSettings, settings.createNotificationChannelSettings(), clientContext); this.updateNotificationChannelCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateNotificationChannelTransportSettings, settings.updateNotificationChannelSettings(), clientContext); this.deleteNotificationChannelCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteNotificationChannelTransportSettings, settings.deleteNotificationChannelSettings(), clientContext); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcUptimeCheckServiceCallableFactory.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcUptimeCheckServiceCallableFactory.java new file mode 100644 index 000000000000..2edabadb0a73 --- /dev/null +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcUptimeCheckServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.monitoring.v3.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Monitoring API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcUptimeCheckServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcUptimeCheckServiceStub.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcUptimeCheckServiceStub.java index c4e6d83bbd4c..5f8b881f2ac0 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcUptimeCheckServiceStub.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/GrpcUptimeCheckServiceStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.monitoring.v3.CreateUptimeCheckConfigRequest; @@ -129,6 +129,8 @@ public class GrpcUptimeCheckServiceStub extends UptimeCheckServiceStub { private final UnaryCallable listUptimeCheckIpsPagedCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcUptimeCheckServiceStub create(UptimeCheckServiceStubSettings settings) throws IOException { return new GrpcUptimeCheckServiceStub(settings, ClientContext.create(settings)); @@ -140,6 +142,12 @@ public static final GrpcUptimeCheckServiceStub create(ClientContext clientContex UptimeCheckServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcUptimeCheckServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcUptimeCheckServiceStub( + UptimeCheckServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcUptimeCheckServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -147,6 +155,20 @@ public static final GrpcUptimeCheckServiceStub create(ClientContext clientContex */ protected GrpcUptimeCheckServiceStub( UptimeCheckServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcUptimeCheckServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcUptimeCheckServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcUptimeCheckServiceStub( + UptimeCheckServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings listUptimeCheckConfigsTransportSettings = @@ -181,42 +203,42 @@ protected GrpcUptimeCheckServiceStub( .build(); this.listUptimeCheckConfigsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listUptimeCheckConfigsTransportSettings, settings.listUptimeCheckConfigsSettings(), clientContext); this.listUptimeCheckConfigsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listUptimeCheckConfigsTransportSettings, settings.listUptimeCheckConfigsSettings(), clientContext); this.getUptimeCheckConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getUptimeCheckConfigTransportSettings, settings.getUptimeCheckConfigSettings(), clientContext); this.createUptimeCheckConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createUptimeCheckConfigTransportSettings, settings.createUptimeCheckConfigSettings(), clientContext); this.updateUptimeCheckConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateUptimeCheckConfigTransportSettings, settings.updateUptimeCheckConfigSettings(), clientContext); this.deleteUptimeCheckConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteUptimeCheckConfigTransportSettings, settings.deleteUptimeCheckConfigSettings(), clientContext); this.listUptimeCheckIpsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listUptimeCheckIpsTransportSettings, settings.listUptimeCheckIpsSettings(), clientContext); this.listUptimeCheckIpsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listUptimeCheckIpsTransportSettings, settings.listUptimeCheckIpsSettings(), clientContext); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/MetricServiceStubSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/MetricServiceStubSettings.java index bb72d7eaa467..2ea5277faee3 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/MetricServiceStubSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/MetricServiceStubSettings.java @@ -85,7 +85,7 @@ * * MetricServiceStubSettings.Builder metricServiceSettingsBuilder = * MetricServiceStubSettings.newBuilder(); - * metricServiceSettingsBuilder.getMonitoredResourceDescriptorSettings().getRetrySettingsBuilder() + * metricServiceSettingsBuilder.getMonitoredResourceDescriptorSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * MetricServiceStubSettings metricServiceSettings = metricServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/NotificationChannelServiceStubSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/NotificationChannelServiceStubSettings.java index e1bc8ffb9d53..b2fa1a19ca8e 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/NotificationChannelServiceStubSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/NotificationChannelServiceStubSettings.java @@ -81,7 +81,7 @@ * * NotificationChannelServiceStubSettings.Builder notificationChannelServiceSettingsBuilder = * NotificationChannelServiceStubSettings.newBuilder(); - * notificationChannelServiceSettingsBuilder.getNotificationChannelDescriptorSettings().getRetrySettingsBuilder() + * notificationChannelServiceSettingsBuilder.getNotificationChannelDescriptorSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * NotificationChannelServiceStubSettings notificationChannelServiceSettings = notificationChannelServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/UptimeCheckServiceStubSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/UptimeCheckServiceStubSettings.java index 321e00afb021..135f93dfdb99 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/UptimeCheckServiceStubSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/v3/stub/UptimeCheckServiceStubSettings.java @@ -80,7 +80,7 @@ * * UptimeCheckServiceStubSettings.Builder uptimeCheckServiceSettingsBuilder = * UptimeCheckServiceStubSettings.newBuilder(); - * uptimeCheckServiceSettingsBuilder.getUptimeCheckConfigSettings().getRetrySettingsBuilder() + * uptimeCheckServiceSettingsBuilder.getUptimeCheckConfigSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * UptimeCheckServiceStubSettings uptimeCheckServiceSettings = uptimeCheckServiceSettingsBuilder.build(); * diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/v3/MetricServiceSmokeTest.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/v3/MetricServiceSmokeTest.java new file mode 100644 index 000000000000..749e501751b9 --- /dev/null +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/v3/MetricServiceSmokeTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2018 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.cloud.monitoring.v3; + +import static com.google.cloud.monitoring.v3.MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse; + +import com.google.common.base.Preconditions; +import com.google.monitoring.v3.ProjectName; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class MetricServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (MetricServiceClient client = MetricServiceClient.create()) { + ProjectName name = ProjectName.of(projectId); + + ListMonitoredResourceDescriptorsPagedResponse pagedResponse = + client.listMonitoredResourceDescriptors(name); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-notification/README.md b/google-cloud-notification/README.md index 7622901974e7..900b7460644a 100644 --- a/google-cloud-notification/README.md +++ b/google-cloud-notification/README.md @@ -14,16 +14,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-notification - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-notification:0.38.0-beta' +compile 'com.google.cloud:google-cloud-notification:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-notification" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-notification" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-notification/pom.xml b/google-cloud-notification/pom.xml index 70aaec2b5293..837f46115903 100644 --- a/google-cloud-notification/pom.xml +++ b/google-cloud-notification/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-notification - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Pub/Sub Notifications for Google Cloud Storage https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-notification @@ -15,7 +15,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-notification diff --git a/google-cloud-os-login/README.md b/google-cloud-os-login/README.md index a61faa15762d..242f54886263 100644 --- a/google-cloud-os-login/README.md +++ b/google-cloud-os-login/README.md @@ -24,16 +24,16 @@ Add this to your pom.xml file com.google.cloud google-cloud-os-login - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-os-login:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-os-login:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-os-login" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-os-login" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-os-login/pom.xml b/google-cloud-os-login/pom.xml index 71cbda9add09..7bd003e5f7c4 100644 --- a/google-cloud-os-login/pom.xml +++ b/google-cloud-os-login/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-os-login - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud OS Login https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-os-login @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-os-login diff --git a/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java index 53d7d997598f..ccd0f67db49d 100644 --- a/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java +++ b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java @@ -52,7 +52,7 @@ * * OsLoginServiceSettings.Builder osLoginServiceSettingsBuilder = * OsLoginServiceSettings.newBuilder(); - * osLoginServiceSettingsBuilder.deletePosixAccountSettings().getRetrySettingsBuilder() + * osLoginServiceSettingsBuilder.deletePosixAccountSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * OsLoginServiceSettings osLoginServiceSettings = osLoginServiceSettingsBuilder.build(); * diff --git a/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/GrpcOsLoginServiceCallableFactory.java b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/GrpcOsLoginServiceCallableFactory.java new file mode 100644 index 000000000000..f4000fb054d3 --- /dev/null +++ b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/GrpcOsLoginServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.oslogin.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud OS Login API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcOsLoginServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/GrpcOsLoginServiceStub.java b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/GrpcOsLoginServiceStub.java index d368c4045c05..6c76e516a5dc 100644 --- a/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/GrpcOsLoginServiceStub.java +++ b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/GrpcOsLoginServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.oslogin.common.OsLoginProto.SshPublicKey; @@ -114,6 +114,8 @@ public class GrpcOsLoginServiceStub extends OsLoginServiceStub { importSshPublicKeyCallable; private final UnaryCallable updateSshPublicKeyCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcOsLoginServiceStub create(OsLoginServiceStubSettings settings) throws IOException { return new GrpcOsLoginServiceStub(settings, ClientContext.create(settings)); @@ -125,6 +127,12 @@ public static final GrpcOsLoginServiceStub create(ClientContext clientContext) OsLoginServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcOsLoginServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcOsLoginServiceStub( + OsLoginServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcOsLoginServiceStub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -132,6 +140,20 @@ public static final GrpcOsLoginServiceStub create(ClientContext clientContext) */ protected GrpcOsLoginServiceStub(OsLoginServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcOsLoginServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcOsLoginServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcOsLoginServiceStub( + OsLoginServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings deletePosixAccountTransportSettings = GrpcCallSettings.newBuilder() @@ -160,28 +182,28 @@ protected GrpcOsLoginServiceStub(OsLoginServiceStubSettings settings, ClientCont .build(); this.deletePosixAccountCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deletePosixAccountTransportSettings, settings.deletePosixAccountSettings(), clientContext); this.deleteSshPublicKeyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteSshPublicKeyTransportSettings, settings.deleteSshPublicKeySettings(), clientContext); this.getLoginProfileCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getLoginProfileTransportSettings, settings.getLoginProfileSettings(), clientContext); this.getSshPublicKeyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getSshPublicKeyTransportSettings, settings.getSshPublicKeySettings(), clientContext); this.importSshPublicKeyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( importSshPublicKeyTransportSettings, settings.importSshPublicKeySettings(), clientContext); this.updateSshPublicKeyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateSshPublicKeyTransportSettings, settings.updateSshPublicKeySettings(), clientContext); diff --git a/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java index 1fd31fa9544d..f192da078b1d 100644 --- a/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java +++ b/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java @@ -69,7 +69,7 @@ * * OsLoginServiceStubSettings.Builder osLoginServiceSettingsBuilder = * OsLoginServiceStubSettings.newBuilder(); - * osLoginServiceSettingsBuilder.deletePosixAccountSettings().getRetrySettingsBuilder() + * osLoginServiceSettingsBuilder.deletePosixAccountSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * OsLoginServiceStubSettings osLoginServiceSettings = osLoginServiceSettingsBuilder.build(); * diff --git a/google-cloud-pubsub/README.md b/google-cloud-pubsub/README.md index e3e4ca68d9e5..fa507ba8ea37 100644 --- a/google-cloud-pubsub/README.md +++ b/google-cloud-pubsub/README.md @@ -24,16 +24,16 @@ Add this to your pom.xml file com.google.cloud google-cloud-pubsub - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-pubsub:0.38.0-beta' +compile 'com.google.cloud:google-cloud-pubsub:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) @@ -90,12 +90,12 @@ publishers. Add the following imports at the top of your file: ```java import com.google.cloud.pubsub.v1.TopicAdminClient; -import com.google.pubsub.v1.TopicName; +import com.google.pubsub.v1.ProjectTopicName; ``` Then, to create the topic, use the following code: ```java -TopicName topic = TopicName.create("test-project", "test-topic"); +ProjectTopicName topic = ProjectTopicName.of("test-project", "test-topic"); try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { topicAdminClient.createTopic(topic); } @@ -115,13 +115,13 @@ Then, to publish messages asynchronously, use the following code: ```java Publisher publisher = null; try { - publisher = Publisher.defaultBuilder(topic).build(); + publisher = Publisher.newBuilder(topic).build(); ByteString data = ByteString.copyFromUtf8("my-message"); PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build(); ApiFuture messageIdFuture = publisher.publish(pubsubMessage); } finally { if (publisher != null) { - publisher.shutdown(); + publisher.shutdown(); } } ``` @@ -133,14 +133,14 @@ single, specific topic. Add the following imports at the top of your file: ```java import com.google.cloud.pubsub.v1.SubscriptionAdminClient; import com.google.pubsub.v1.PushConfig; -import com.google.pubsub.v1.SubscriptionName; -import com.google.pubsub.v1.TopicName; +import com.google.pubsub.v1.ProjectSubscriptionName; +import com.google.pubsub.v1.ProjectTopicName; ``` Then, to create the subscription, use the following code: ```java -TopicName topic = TopicName.create("test-project", "test-topic"); -SubscriptionName subscription = SubscriptionName.create("test-project", "test-subscription"); +ProjectTopicName topic = ProjectTopicName.of("test-project", "test-topic"); +ProjectSubscriptionName subscription = ProjectSubscriptionName.of("test-project", "test-subscription"); try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { subscriptionAdminClient.createSubscription(subscription, topic, PushConfig.getDefaultInstance(), 0); @@ -157,32 +157,35 @@ import com.google.cloud.pubsub.v1.MessageReceiver; import com.google.cloud.pubsub.v1.Subscriber; import com.google.common.util.concurrent.MoreExecutors; import com.google.pubsub.v1.PubsubMessage; -import com.google.pubsub.v1.SubscriptionName; -import com.google.pubsub.v1.TopicName; +import com.google.pubsub.v1.ProjectSubscriptionName; +import com.google.pubsub.v1.ProjectTopicName; ``` Then, to pull messages asynchronously, use the following code: ```java +ProjectSubscriptionName subscription = ProjectSubscriptionName.of("test-project", "test-subscription"); + MessageReceiver receiver = - new MessageReceiver() { - @Override - public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { - System.out.println("got message: " + message.getData().toStringUtf8()); - consumer.ack(); - } - }; + new MessageReceiver() { + @Override + public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { + System.out.println("got message: " + message.getData().toStringUtf8()); + consumer.ack(); + } + }; + Subscriber subscriber = null; try { - subscriber = Subscriber.defaultBuilder(subscriptionName, receiver).build(); + subscriber = Subscriber.newBuilder(subscription, receiver).build(); subscriber.addListener( - new Subscriber.Listener() { - @Override - public void failed(Subscriber.State from, Throwable failure) { - // Handle failure. This is called when the Subscriber encountered a fatal error and is shutting down. - System.err.println(failure); - } - }, - MoreExecutors.directExecutor()); + new Subscriber.Listener() { + @Override + public void failed(Subscriber.State from, Throwable failure) { + // Handle failure. This is called when the Subscriber encountered a fatal error and is shutting down. + System.err.println(failure); + } + }, + MoreExecutors.directExecutor()); subscriber.startAsync().awaitRunning(); //... } finally { @@ -193,12 +196,7 @@ try { ``` #### Complete source code -In -[CreateTopicAndPublishMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java) -and -[CreateSubscriptionAndConsumeMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java) -we put together all the code shown above into two programs. The programs assume that you are -running on Compute Engine, App Engine Flexible or from your own desktop. +In [CreateTopicAndPublishMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java) and [CreateSubscriptionAndConsumeMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java) we put together all the code shown above into two programs. The programs assume that you are running on Compute Engine, App Engine Flexible or from your own desktop. Transport --------- diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml index c7ff91a9f69f..6b937016d826 100644 --- a/google-cloud-pubsub/pom.xml +++ b/google-cloud-pubsub/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-pubsub - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Pub/Sub https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-pubsub @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-pubsub diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/PollingSubscriberConnection.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/PollingSubscriberConnection.java deleted file mode 100644 index 53f808ab77bf..000000000000 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/PollingSubscriberConnection.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright 2016 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.pubsub.v1; - -import com.google.api.core.AbstractApiService; -import com.google.api.core.ApiClock; -import com.google.api.gax.batching.FlowController; -import com.google.api.gax.core.Distribution; -import com.google.cloud.pubsub.v1.MessageDispatcher.AckProcessor; -import com.google.cloud.pubsub.v1.MessageDispatcher.PendingModifyAckDeadline; -import com.google.common.collect.Lists; -import com.google.common.primitives.Ints; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.pubsub.v1.AcknowledgeRequest; -import com.google.pubsub.v1.ModifyAckDeadlineRequest; -import com.google.pubsub.v1.PullRequest; -import com.google.pubsub.v1.PullResponse; -import com.google.pubsub.v1.SubscriberGrpc.SubscriberFutureStub; -import com.google.pubsub.v1.Subscription; -import java.util.Deque; -import java.util.List; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.Nullable; -import org.threeten.bp.Duration; - -/** - * Implementation of {@link AckProcessor} based on Cloud Pub/Sub pull and acknowledge operations. - */ -final class PollingSubscriberConnection extends AbstractApiService implements AckProcessor { - static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(60); - - private static final int MAX_PER_REQUEST_CHANGES = 1000; - private static final int DEFAULT_MAX_MESSAGES = 1000; - private static final Duration INITIAL_BACKOFF = Duration.ofMillis(100); // 100ms - private static final Duration MAX_BACKOFF = Duration.ofSeconds(10); // 10s - - private static final Logger logger = - Logger.getLogger(PollingSubscriberConnection.class.getName()); - - private final Subscription subscription; - private final ScheduledExecutorService pollingExecutor; - private final SubscriberFutureStub stub; - private final MessageDispatcher messageDispatcher; - private final int maxDesiredPulledMessages; - - public PollingSubscriberConnection( - Subscription subscription, - MessageReceiver receiver, - Duration ackExpirationPadding, - Duration maxAckExtensionPeriod, - Distribution ackLatencyDistribution, - SubscriberFutureStub stub, - FlowController flowController, - @Nullable Long maxDesiredPulledMessages, - Deque outstandingMessageBatches, - ScheduledExecutorService executor, - ScheduledExecutorService systemExecutor, - ApiClock clock) { - this.subscription = subscription; - this.pollingExecutor = systemExecutor; - this.stub = stub; - messageDispatcher = - new MessageDispatcher( - receiver, - this, - ackExpirationPadding, - maxAckExtensionPeriod, - ackLatencyDistribution, - flowController, - outstandingMessageBatches, - executor, - systemExecutor, - clock); - this.maxDesiredPulledMessages = - maxDesiredPulledMessages != null - ? Ints.saturatedCast(maxDesiredPulledMessages) - : DEFAULT_MAX_MESSAGES; - } - - @Override - protected void doStart() { - logger.config("Starting subscriber."); - messageDispatcher.start(); - pullMessages(INITIAL_BACKOFF); - notifyStarted(); - } - - @Override - protected void doStop() { - messageDispatcher.stop(); - notifyStopped(); - } - - private ListenableFuture pullMessages(final Duration backoff) { - if (!isAlive()) { - return Futures.immediateCancelledFuture(); - } - ListenableFuture pullResult = - stub.pull( - PullRequest.newBuilder() - .setSubscription(subscription.getName()) - .setMaxMessages(maxDesiredPulledMessages) - .setReturnImmediately(false) - .build()); - - Futures.addCallback( - pullResult, - new FutureCallback() { - @Override - public void onSuccess(PullResponse pullResponse) { - if (pullResponse.getReceivedMessagesCount() == 0) { - // No messages in response, possibly caught up in backlog, we backoff to avoid - // slamming the server. - pollingExecutor.schedule( - new Runnable() { - @Override - public void run() { - Duration newBackoff = backoff.multipliedBy(2); - if (newBackoff.compareTo(MAX_BACKOFF) > 0) { - newBackoff = MAX_BACKOFF; - } - pullMessages(newBackoff); - } - }, - backoff.toMillis(), - TimeUnit.MILLISECONDS); - return; - } - messageDispatcher.processReceivedMessages( - pullResponse.getReceivedMessagesList(), - new Runnable() { - @Override - public void run() { - pullMessages(INITIAL_BACKOFF); - } - }); - } - - @Override - public void onFailure(Throwable cause) { - if (!isAlive()) { - // we don't care about subscription failures when we're no longer running. - logger.log(Level.FINE, "pull failure after service no longer running", cause); - return; - } - if (StatusUtil.isRetryable(cause)) { - logger.log(Level.WARNING, "Failed to pull messages (recoverable): ", cause); - pollingExecutor.schedule( - new Runnable() { - @Override - public void run() { - Duration newBackoff = backoff.multipliedBy(2); - if (newBackoff.compareTo(MAX_BACKOFF) > 0) { - newBackoff = MAX_BACKOFF; - } - pullMessages(newBackoff); - } - }, - backoff.toMillis(), - TimeUnit.MILLISECONDS); - } else { - messageDispatcher.stop(); - notifyFailed(cause); - } - } - }, - pollingExecutor); - - return pullResult; - } - - private boolean isAlive() { - // Read state only once. Because of threading, different calls can give different results. - State state = state(); - return state == State.RUNNING || state == State.STARTING; - } - - @Override - public void sendAckOperations( - List acksToSend, List ackDeadlineExtensions) { - // Send the modify ack deadlines in batches as not to exceed the max request - // size. - for (PendingModifyAckDeadline modifyAckDeadline : ackDeadlineExtensions) { - for (List ackIdChunk : - Lists.partition(modifyAckDeadline.ackIds, MAX_PER_REQUEST_CHANGES)) { - stub.withDeadlineAfter(DEFAULT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS) - .modifyAckDeadline( - ModifyAckDeadlineRequest.newBuilder() - .setSubscription(subscription.getName()) - .addAllAckIds(ackIdChunk) - .setAckDeadlineSeconds(modifyAckDeadline.deadlineExtensionSeconds) - .build()); - } - } - - for (List ackChunk : Lists.partition(acksToSend, MAX_PER_REQUEST_CHANGES)) { - stub.withDeadlineAfter(DEFAULT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS) - .acknowledge( - AcknowledgeRequest.newBuilder() - .setSubscription(subscription.getName()) - .addAllAckIds(ackChunk) - .build()); - } - } -} diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java index 4db17723937e..55434aa17775 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java @@ -17,57 +17,50 @@ package com.google.cloud.pubsub.v1; import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutureCallback; +import com.google.api.core.ApiFutures; import com.google.api.core.BetaApi; -import com.google.api.core.InternalApi; import com.google.api.core.SettableApiFuture; import com.google.api.gax.batching.BatchingSettings; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.ExecutorAsBackgroundResource; import com.google.api.gax.core.ExecutorProvider; +import com.google.api.gax.core.FixedExecutorProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.GrpcStatusCode; -import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.ApiExceptionFactory; import com.google.api.gax.rpc.HeaderProvider; import com.google.api.gax.rpc.NoHeaderProvider; +import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.TransportChannelProvider; -import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; +import com.google.cloud.pubsub.v1.stub.GrpcPublisherStub; +import com.google.cloud.pubsub.v1.stub.PublisherStub; +import com.google.cloud.pubsub.v1.stub.PublisherStubSettings; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.pubsub.v1.ProjectTopicName; import com.google.pubsub.v1.PublishRequest; import com.google.pubsub.v1.PublishResponse; -import com.google.pubsub.v1.PublisherGrpc; -import com.google.pubsub.v1.PublisherGrpc.PublisherFutureStub; import com.google.pubsub.v1.PubsubMessage; -import io.grpc.CallCredentials; -import io.grpc.Channel; +import com.google.pubsub.v1.TopicName; +import com.google.pubsub.v1.TopicNames; import io.grpc.Status; -import io.grpc.auth.MoreCallCredentials; -import org.threeten.bp.Duration; - -import javax.annotation.Nullable; import java.io.IOException; -import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; +import org.threeten.bp.Duration; /** * A Cloud Pub/Sub publisher, that is @@ -90,12 +83,9 @@ public class Publisher { private static final Logger logger = Logger.getLogger(Publisher.class.getName()); - private final ProjectTopicName topicName; - private final String cachedTopicNameString; + private final String topicName; private final BatchingSettings batchingSettings; - private final RetrySettings retrySettings; - private final LongRandom longRandom; private final Lock messagesBatchLock; private List messagesBatch; @@ -103,12 +93,11 @@ public class Publisher { private final AtomicBoolean activeAlarm; - private final Channel channel; - @Nullable private final CallCredentials callCredentials; + private final PublisherStub publisherStub; private final ScheduledExecutorService executor; private final AtomicBoolean shutdown; - private final List closeables = new ArrayList<>(); + private final List closeables; private final MessageWaiter messagesWaiter; private ScheduledFuture currentAlarmFuture; @@ -124,50 +113,57 @@ public static long getApiMaxRequestBytes() { private Publisher(Builder builder) throws IOException { topicName = builder.topicName; - cachedTopicNameString = topicName.toString(); this.batchingSettings = builder.batchingSettings; - this.retrySettings = builder.retrySettings; - this.longRandom = builder.longRandom; messagesBatch = new LinkedList<>(); messagesBatchLock = new ReentrantLock(); activeAlarm = new AtomicBoolean(false); executor = builder.executorProvider.getExecutor(); if (builder.executorProvider.shouldAutoClose()) { - closeables.add(new ExecutorAsBackgroundResource(executor)); - } - TransportChannelProvider channelProvider = builder.channelProvider; - if (channelProvider.needsExecutor()) { - channelProvider = channelProvider.withExecutor(executor); + closeables = + Collections.singletonList(new ExecutorAsBackgroundResource(executor)); + } else { + closeables = Collections.emptyList(); } - if (channelProvider.needsHeaders()) { - Map headers = - ImmutableMap.builder() - .putAll(builder.headerProvider.getHeaders()) - .putAll(builder.internalHeaderProvider.getHeaders()) - .build(); - channelProvider = channelProvider.withHeaders(headers); - } - if (channelProvider.needsEndpoint()) { - channelProvider = channelProvider.withEndpoint(TopicAdminSettings.getDefaultEndpoint()); - } - GrpcTransportChannel transportChannel = - (GrpcTransportChannel) channelProvider.getTransportChannel(); - channel = transportChannel.getChannel(); - if (channelProvider.shouldAutoClose()) { - closeables.add(transportChannel); + + // Publisher used to take maxAttempt == 0 to mean infinity, but to GAX it means don't retry. + // We post-process this here to keep backward-compatibility. + RetrySettings retrySettings = builder.retrySettings; + if (retrySettings.getMaxAttempts() == 0) { + retrySettings = retrySettings.toBuilder().setMaxAttempts(Integer.MAX_VALUE).build(); } - Credentials credentials = builder.credentialsProvider.getCredentials(); - callCredentials = credentials == null ? null : MoreCallCredentials.from(credentials); + PublisherStubSettings.Builder stubSettings = + PublisherStubSettings.newBuilder() + .setCredentialsProvider(builder.credentialsProvider) + .setExecutorProvider(FixedExecutorProvider.create(executor)) + .setTransportChannelProvider(builder.channelProvider); + stubSettings + .publishSettings() + .setRetryableCodes( + StatusCode.Code.ABORTED, + StatusCode.Code.CANCELLED, + StatusCode.Code.DEADLINE_EXCEEDED, + StatusCode.Code.INTERNAL, + StatusCode.Code.RESOURCE_EXHAUSTED, + StatusCode.Code.UNKNOWN, + StatusCode.Code.UNAVAILABLE) + .setRetrySettings(retrySettings) + .setBatchingSettings(BatchingSettings.newBuilder().setIsEnabled(false).build()); + this.publisherStub = GrpcPublisherStub.create(stubSettings.build()); shutdown = new AtomicBoolean(false); messagesWaiter = new MessageWaiter(); } /** Topic which the publisher publishes to. */ - public ProjectTopicName getTopicName() { + public TopicName getTopicName() { + return TopicNames.parse(topicName); + } + + /** Topic which the publisher publishes to. */ + public String getTopicNameString() { return topicName; } @@ -294,7 +290,12 @@ public void run() { } } - private void publishAllOutstanding() { + /** + * Publish any outstanding batches if non-empty. This method sends buffered messages, but does + * not wait for the send operations to complete. To wait for messages to send, call {@code get} + * on the futures returned from {@code publish}. + */ + public void publishAllOutstanding() { messagesBatchLock.lock(); OutstandingBatch batchToSend; try { @@ -312,26 +313,14 @@ private void publishAllOutstanding() { private void publishOutstandingBatch(final OutstandingBatch outstandingBatch) { PublishRequest.Builder publishRequest = PublishRequest.newBuilder(); - publishRequest.setTopic(cachedTopicNameString); + publishRequest.setTopic(topicName); for (OutstandingPublish outstandingPublish : outstandingBatch.outstandingPublishes) { publishRequest.addMessages(outstandingPublish.message); } - long rpcTimeoutMs = - Math.round( - retrySettings.getInitialRpcTimeout().toMillis() - * Math.pow(retrySettings.getRpcTimeoutMultiplier(), outstandingBatch.attempt - 1)); - rpcTimeoutMs = Math.min(rpcTimeoutMs, retrySettings.getMaxRpcTimeout().toMillis()); - - PublisherFutureStub stub = - PublisherGrpc.newFutureStub(channel).withDeadlineAfter(rpcTimeoutMs, TimeUnit.MILLISECONDS); - if (callCredentials != null) { - stub = stub.withCallCredentials(callCredentials); - } - - Futures.addCallback( - stub.publish(publishRequest.build()), - new FutureCallback() { + ApiFutures.addCallback( + publisherStub.publishCallable().futureCall(publishRequest.build()), + new ApiFutureCallback() { @Override public void onSuccess(PublishResponse result) { try { @@ -361,37 +350,13 @@ public void onSuccess(PublishResponse result) { @Override public void onFailure(Throwable t) { - long nextBackoffDelay = - computeNextBackoffDelayMs(outstandingBatch, retrySettings, longRandom); - - if (!isRetryable(t) - || retrySettings.getMaxAttempts() > 0 - && outstandingBatch.getAttempt() > retrySettings.getMaxAttempts() - || System.currentTimeMillis() + nextBackoffDelay - > outstandingBatch.creationTime + retrySettings.getTotalTimeout().toMillis()) { - try { - ApiException gaxException = - ApiExceptionFactory.createException( - t, GrpcStatusCode.of(Status.fromThrowable(t).getCode()), false); - for (OutstandingPublish outstandingPublish : - outstandingBatch.outstandingPublishes) { - outstandingPublish.publishResult.setException(gaxException); - } - } finally { - messagesWaiter.incrementPendingMessages(-outstandingBatch.size()); + try { + for (OutstandingPublish outstandingPublish : outstandingBatch.outstandingPublishes) { + outstandingPublish.publishResult.setException(t); } - return; + } finally { + messagesWaiter.incrementPendingMessages(-outstandingBatch.size()); } - - executor.schedule( - new Runnable() { - @Override - public void run() { - publishOutstandingBatch(outstandingBatch); - } - }, - nextBackoffDelay, - TimeUnit.MILLISECONDS); } }); } @@ -456,47 +421,18 @@ public void shutdown() throws Exception { for (AutoCloseable closeable : closeables) { closeable.close(); } + publisherStub.shutdown(); } private boolean hasBatchingBytes() { return getMaxBatchBytes() > 0; } - private static long computeNextBackoffDelayMs( - OutstandingBatch outstandingBatch, RetrySettings retrySettings, LongRandom longRandom) { - long delayMillis = - Math.round( - retrySettings.getInitialRetryDelay().toMillis() - * Math.pow(retrySettings.getRetryDelayMultiplier(), outstandingBatch.attempt - 1)); - delayMillis = Math.min(retrySettings.getMaxRetryDelay().toMillis(), delayMillis); - outstandingBatch.attempt++; - return longRandom.nextLong(0, delayMillis); - } - - private boolean isRetryable(Throwable t) { - Status status = Status.fromThrowable(t); - switch (status.getCode()) { - case ABORTED: - case CANCELLED: - case DEADLINE_EXCEEDED: - case INTERNAL: - case RESOURCE_EXHAUSTED: - case UNKNOWN: - case UNAVAILABLE: - return true; - default: - return false; - } - } - - interface LongRandom { - long nextLong(long least, long bound); - } - /** * Constructs a new {@link Builder} using the given topic. * *

    Example of creating a {@code Publisher}. + * *

    {@code
        * String projectName = "my_project";
        * String topicName = "my_topic";
    @@ -509,9 +445,28 @@ interface LongRandom {
        *   publisher.shutdown();
        * }
        * }
    + */ + public static Builder newBuilder(TopicName topicName) { + return newBuilder(topicName.toString()); + } + + /** + * Constructs a new {@link Builder} using the given topic. + * + *

    Example of creating a {@code Publisher}. * + *

    {@code
    +   * String topic = "projects/my_project/topics/my_topic";
    +   * Publisher publisher = Publisher.newBuilder(topic).build();
    +   * try {
    +   *   // ...
    +   * } finally {
    +   *   // When finished with the publisher, make sure to shutdown to free up resources.
    +   *   publisher.shutdown();
    +   * }
    +   * }
    */ - public static Builder newBuilder(ProjectTopicName topicName) { + public static Builder newBuilder(String topicName) { return new Builder(topicName); } @@ -542,13 +497,6 @@ public static final class Builder { .setRpcTimeoutMultiplier(2) .setMaxRpcTimeout(DEFAULT_RPC_TIMEOUT) .build(); - static final LongRandom DEFAULT_LONG_RANDOM = - new LongRandom() { - @Override - public long nextLong(long least, long bound) { - return ThreadLocalRandom.current().nextLong(least, bound); - } - }; private static final int THREADS_PER_CPU = 5; static final ExecutorProvider DEFAULT_EXECUTOR_PROVIDER = @@ -556,13 +504,12 @@ public long nextLong(long least, long bound) { .setExecutorThreadCount(THREADS_PER_CPU * Runtime.getRuntime().availableProcessors()) .build(); - ProjectTopicName topicName; + String topicName; // Batching options BatchingSettings batchingSettings = DEFAULT_BATCHING_SETTINGS; RetrySettings retrySettings = DEFAULT_RETRY_SETTINGS; - LongRandom longRandom = DEFAULT_LONG_RANDOM; TransportChannelProvider channelProvider = TopicAdminSettings.defaultGrpcTransportProviderBuilder().setChannelsPerCpu(1).build(); @@ -574,7 +521,7 @@ public long nextLong(long least, long bound) { CredentialsProvider credentialsProvider = TopicAdminSettings.defaultCredentialsProviderBuilder().build(); - private Builder(ProjectTopicName topic) { + private Builder(String topic) { this.topicName = Preconditions.checkNotNull(topic); } @@ -650,12 +597,6 @@ public Builder setRetrySettings(RetrySettings retrySettings) { return this; } - @InternalApi - Builder setLongRandom(LongRandom longRandom) { - this.longRandom = Preconditions.checkNotNull(longRandom); - return this; - } - /** Gives the ability to set a custom executor to be used by the library. */ public Builder setExecutorProvider(ExecutorProvider executorProvider) { this.executorProvider = Preconditions.checkNotNull(executorProvider); diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java index d6837422cb8e..b9854fe5f683 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java @@ -30,12 +30,16 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.SettableFuture; +import com.google.protobuf.Empty; +import com.google.pubsub.v1.AcknowledgeRequest; +import com.google.pubsub.v1.ModifyAckDeadlineRequest; import com.google.pubsub.v1.StreamingPullRequest; import com.google.pubsub.v1.StreamingPullResponse; import com.google.pubsub.v1.SubscriberGrpc.SubscriberStub; import io.grpc.Status; import io.grpc.stub.ClientCallStreamObserver; import io.grpc.stub.ClientResponseObserver; +import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.Deque; import java.util.List; @@ -56,9 +60,10 @@ final class StreamingSubscriberConnection extends AbstractApiService implements private static final Duration INITIAL_CHANNEL_RECONNECT_BACKOFF = Duration.ofMillis(100); private static final Duration MAX_CHANNEL_RECONNECT_BACKOFF = Duration.ofSeconds(10); - private static final int MAX_PER_REQUEST_CHANGES = 10000; + private static final int MAX_PER_REQUEST_CHANGES = 1000; + private static final Duration UNARY_TIMEOUT = Duration.ofSeconds(60); - private final SubscriberStub asyncStub; + private final SubscriberStub stub; private final String subscription; private final ScheduledExecutorService systemExecutor; private final MessageDispatcher messageDispatcher; @@ -75,7 +80,7 @@ public StreamingSubscriberConnection( Duration ackExpirationPadding, Duration maxAckExtensionPeriod, Distribution ackLatencyDistribution, - SubscriberStub asyncStub, + SubscriberStub stub, FlowController flowController, Deque outstandingMessageBatches, ScheduledExecutorService executor, @@ -83,7 +88,7 @@ public StreamingSubscriberConnection( ApiClock clock) { this.subscription = subscription; this.systemExecutor = systemExecutor; - this.asyncStub = asyncStub; + this.stub = stub; this.messageDispatcher = new MessageDispatcher( receiver, @@ -185,8 +190,7 @@ private void initialize() { final ClientResponseObserver responseObserver = new StreamingPullResponseObserver(errorFuture); final ClientCallStreamObserver requestObserver = - (ClientCallStreamObserver) - (asyncStub.streamingPull(responseObserver)); + (ClientCallStreamObserver) (stub.streamingPull(responseObserver)); logger.log( Level.FINER, "Initializing stream to subscription {0}",subscription); @@ -260,24 +264,52 @@ public void run() { } private boolean isAlive() { - return state() == State.RUNNING || state() == State.STARTING; + State state = state(); // Read the state only once. + return state == State.RUNNING || state == State.STARTING; } @Override public void sendAckOperations( List acksToSend, List ackDeadlineExtensions) { - List requests = - partitionAckOperations(acksToSend, ackDeadlineExtensions, MAX_PER_REQUEST_CHANGES); - lock.lock(); - try { - for (StreamingPullRequest request : requests) { - requestObserver.onNext(request); + SubscriberStub timeoutStub = + stub.withDeadlineAfter(UNARY_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS); + StreamObserver loggingObserver = new StreamObserver() { + @Override + public void onCompleted() { + // noop } - } catch (Exception e) { - Level level = isAlive() ? Level.WARNING : Level.FINER; - logger.log(level, "failed to send ack operations", e); - } finally { - lock.unlock(); + + @Override + public void onNext(Empty e) { + // noop + } + + @Override + public void onError(Throwable t) { + Level level = isAlive() ? Level.WARNING : Level.FINER; + logger.log(level, "failed to send operations", t); + } + }; + + for (PendingModifyAckDeadline modack : ackDeadlineExtensions) { + for (List idChunk : Lists.partition(modack.ackIds, MAX_PER_REQUEST_CHANGES)) { + timeoutStub.modifyAckDeadline( + ModifyAckDeadlineRequest.newBuilder() + .setSubscription(subscription) + .addAllAckIds(idChunk) + .setAckDeadlineSeconds(modack.deadlineExtensionSeconds) + .build(), + loggingObserver); + } + } + + for (List idChunk : Lists.partition(acksToSend, MAX_PER_REQUEST_CHANGES)) { + timeoutStub.acknowledge( + AcknowledgeRequest.newBuilder() + .setSubscription(subscription) + .addAllAckIds(idChunk) + .build(), + loggingObserver); } } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java index bd1d87c910c2..74fdb6211abe 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java @@ -107,8 +107,7 @@ public class Subscriber extends AbstractApiService { private static final Logger logger = Logger.getLogger(Subscriber.class.getName()); - private final ProjectSubscriptionName subscriptionName; - private final String cachedSubscriptionNameString; + private final String subscriptionName; private final FlowControlSettings flowControlSettings; private final Duration ackExpirationPadding; private final Duration maxAckExtensionPeriod; @@ -123,19 +122,16 @@ public class Subscriber extends AbstractApiService { private final List channels; private final MessageReceiver receiver; private final List streamingSubscriberConnections; - private final List pollingSubscriberConnections; private final Deque outstandingMessageBatches = new LinkedList<>(); private final ApiClock clock; private final List closeables = new ArrayList<>(); - private final boolean useStreaming; private ScheduledFuture ackDeadlineUpdater; private Subscriber(Builder builder) { receiver = builder.receiver; flowControlSettings = builder.flowControlSettings; subscriptionName = builder.subscriptionName; - cachedSubscriptionNameString = subscriptionName.toString(); Preconditions.checkArgument( builder.ackExpirationPadding.compareTo(Duration.ZERO) > 0, "padding must be positive"); @@ -197,26 +193,32 @@ public void close() throws IOException { numChannels = builder.parallelPullCount; channels = new ArrayList<>(numChannels); streamingSubscriberConnections = new ArrayList(numChannels); - pollingSubscriberConnections = new ArrayList(numChannels); - useStreaming = builder.useStreaming; } /** * Constructs a new {@link Builder}. * - *

    Once {@link Builder#build} is called a gRPC stub will be created for use of the {@link - * Subscriber}. - * * @param subscription Cloud Pub/Sub subscription to bind the subscriber to * @param receiver an implementation of {@link MessageReceiver} used to process the received * messages */ public static Builder newBuilder(ProjectSubscriptionName subscription, MessageReceiver receiver) { + return newBuilder(subscription.toString(), receiver); + } + + /** + * Constructs a new {@link Builder}. + * + * @param subscription Cloud Pub/Sub subscription to bind the subscriber to + * @param receiver an implementation of {@link MessageReceiver} used to process the received + * messages + */ + public static Builder newBuilder(String subscription, MessageReceiver receiver) { return new Builder(subscription, receiver); } /** Subscription which the subscriber is subscribed to. */ - public ProjectSubscriptionName getSubscriptionName() { + public String getSubscriptionNameString() { return subscriptionName; } @@ -299,11 +301,7 @@ protected void doStart() { @Override public void run() { try { - if (useStreaming) { startStreamingConnections(); - } else { - startPollingConnections(); - } notifyStarted(); } catch (Throwable t) { notifyFailed(t); @@ -316,7 +314,6 @@ public void run() { @Override protected void doStop() { // stop connection is no-op if connections haven't been started. - stopAllPollingConnections(); stopAllStreamingConnections(); try { for (AutoCloseable closeable : closeables) { @@ -328,66 +325,6 @@ protected void doStop() { } } - private void startPollingConnections() throws IOException { - synchronized (pollingSubscriberConnections) { - Credentials credentials = credentialsProvider.getCredentials(); - CallCredentials callCredentials = - credentials == null ? null : MoreCallCredentials.from(credentials); - - SubscriberGrpc.SubscriberBlockingStub getSubStub = - SubscriberGrpc.newBlockingStub(channels.get(0)) - .withDeadlineAfter( - PollingSubscriberConnection.DEFAULT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS); - if (callCredentials != null) { - getSubStub = getSubStub.withCallCredentials(callCredentials); - } - Subscription subscriptionInfo = - getSubStub.getSubscription( - GetSubscriptionRequest.newBuilder() - .setSubscription(cachedSubscriptionNameString) - .build()); - - for (Channel channel : channels) { - SubscriberFutureStub stub = SubscriberGrpc.newFutureStub(channel); - if (callCredentials != null) { - stub = stub.withCallCredentials(callCredentials); - } - pollingSubscriberConnections.add( - new PollingSubscriberConnection( - subscriptionInfo, - receiver, - ackExpirationPadding, - maxAckExtensionPeriod, - ackLatencyDistribution, - stub, - flowController, - flowControlSettings.getMaxOutstandingElementCount(), - outstandingMessageBatches, - executor, - alarmsExecutor, - clock)); - } - startConnections( - pollingSubscriberConnections, - new Listener() { - @Override - public void failed(State from, Throwable failure) { - // If a connection failed is because of a fatal error, we should fail the - // whole subscriber. - stopAllPollingConnections(); - try { - notifyFailed(failure); - } catch (IllegalStateException e) { - if (isRunning()) { - throw e; - } - // It could happen that we are shutting down while some channels fail. - } - } - }); - } - } - private void startStreamingConnections() throws IOException { synchronized (streamingSubscriberConnections) { Credentials credentials = credentialsProvider.getCredentials(); @@ -401,7 +338,7 @@ private void startStreamingConnections() throws IOException { } streamingSubscriberConnections.add( new StreamingSubscriberConnection( - cachedSubscriptionNameString, + subscriptionName, receiver, ackExpirationPadding, maxAckExtensionPeriod, @@ -434,10 +371,6 @@ public void failed(State from, Throwable failure) { } } - private void stopAllPollingConnections() { - stopConnections(pollingSubscriberConnections); - } - private void stopAllStreamingConnections() { stopConnections(streamingSubscriberConnections); if (ackDeadlineUpdater != null) { @@ -491,7 +424,7 @@ public static final class Builder { * Runtime.getRuntime().availableProcessors()) .build(); - ProjectSubscriptionName subscriptionName; + String subscriptionName; MessageReceiver receiver; Duration ackExpirationPadding = DEFAULT_ACK_EXPIRATION_PADDING; @@ -516,10 +449,9 @@ public static final class Builder { CredentialsProvider credentialsProvider = SubscriptionAdminSettings.defaultCredentialsProviderBuilder().build(); Optional clock = Optional.absent(); - boolean useStreaming = true; int parallelPullCount = Runtime.getRuntime().availableProcessors() * CHANNELS_PER_CORE; - Builder(ProjectSubscriptionName subscriptionName, MessageReceiver receiver) { + Builder(String subscriptionName, MessageReceiver receiver) { this.subscriptionName = subscriptionName; this.receiver = receiver; } @@ -621,7 +553,7 @@ public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) { } /** - * Gives the ability to set a custom executor for polling and managing lease extensions. If none + * Gives the ability to set a custom executor for managing lease extensions. If none * is provided a shared one will be used by all {@link Subscriber} instances. */ public Builder setSystemExecutorProvider(ExecutorProvider executorProvider) { @@ -644,11 +576,6 @@ Builder setClock(ApiClock clock) { return this; } - Builder setUseStreaming(boolean useStreaming) { - this.useStreaming = useStreaming; - return this; - } - public Subscriber build() { return new Subscriber(this); } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/SubscriptionAdminSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/SubscriptionAdminSettings.java index fcb1d2ff7254..cb08ae52f7c2 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/SubscriptionAdminSettings.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/SubscriptionAdminSettings.java @@ -82,7 +82,7 @@ * * SubscriptionAdminSettings.Builder subscriptionAdminSettingsBuilder = * SubscriptionAdminSettings.newBuilder(); - * subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettingsBuilder() + * subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SubscriptionAdminSettings subscriptionAdminSettings = subscriptionAdminSettingsBuilder.build(); * diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminSettings.java index 37449df10e56..a0a766b50360 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminSettings.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminSettings.java @@ -71,7 +71,7 @@ * * TopicAdminSettings.Builder topicAdminSettingsBuilder = * TopicAdminSettings.newBuilder(); - * topicAdminSettingsBuilder.createTopicSettings().getRetrySettingsBuilder() + * topicAdminSettingsBuilder.createTopicSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * TopicAdminSettings topicAdminSettings = topicAdminSettingsBuilder.build(); * diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherCallableFactory.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherCallableFactory.java new file mode 100644 index 000000000000..73d10d95f522 --- /dev/null +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.pubsub.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Pub/Sub API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcPublisherCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java index 2e9425408edf..3b337b6edafb 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.iam.v1.GetIamPolicyRequest; @@ -155,6 +155,8 @@ public class GrpcPublisherStub extends PublisherStub { private final UnaryCallable testIamPermissionsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcPublisherStub create(PublisherStubSettings settings) throws IOException { return new GrpcPublisherStub(settings, ClientContext.create(settings)); } @@ -163,6 +165,12 @@ public static final GrpcPublisherStub create(ClientContext clientContext) throws return new GrpcPublisherStub(PublisherStubSettings.newBuilder().build(), clientContext); } + public static final GrpcPublisherStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcPublisherStub( + PublisherStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcPublisherStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -170,6 +178,20 @@ public static final GrpcPublisherStub create(ClientContext clientContext) throws */ protected GrpcPublisherStub(PublisherStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcPublisherCallableFactory()); + } + + /** + * Constructs an instance of GrpcPublisherStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcPublisherStub( + PublisherStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings createTopicTransportSettings = GrpcCallSettings.newBuilder() @@ -216,44 +238,44 @@ protected GrpcPublisherStub(PublisherStubSettings settings, ClientContext client .build(); this.createTopicCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createTopicTransportSettings, settings.createTopicSettings(), clientContext); this.updateTopicCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateTopicTransportSettings, settings.updateTopicSettings(), clientContext); this.publishCallable = - GrpcCallableFactory.createBatchingCallable( + callableFactory.createBatchingCallable( publishTransportSettings, settings.publishSettings(), clientContext); this.getTopicCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getTopicTransportSettings, settings.getTopicSettings(), clientContext); this.listTopicsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTopicsTransportSettings, settings.listTopicsSettings(), clientContext); this.listTopicsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTopicsTransportSettings, settings.listTopicsSettings(), clientContext); this.listTopicSubscriptionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTopicSubscriptionsTransportSettings, settings.listTopicSubscriptionsSettings(), clientContext); this.listTopicSubscriptionsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTopicSubscriptionsTransportSettings, settings.listTopicSubscriptionsSettings(), clientContext); this.deleteTopicCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteTopicTransportSettings, settings.deleteTopicSettings(), clientContext); this.setIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); this.getIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); this.testIamPermissionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( testIamPermissionsTransportSettings, settings.testIamPermissionsSettings(), clientContext); diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcSubscriberCallableFactory.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcSubscriberCallableFactory.java new file mode 100644 index 000000000000..8142ea2894d5 --- /dev/null +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcSubscriberCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.pubsub.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Pub/Sub API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcSubscriberCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java index b5053db8636b..30db137cc61e 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +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.UnaryCallable; @@ -253,6 +253,8 @@ public class GrpcSubscriberStub extends SubscriberStub { private final UnaryCallable testIamPermissionsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcSubscriberStub create(SubscriberStubSettings settings) throws IOException { return new GrpcSubscriberStub(settings, ClientContext.create(settings)); @@ -262,6 +264,12 @@ public static final GrpcSubscriberStub create(ClientContext clientContext) throw return new GrpcSubscriberStub(SubscriberStubSettings.newBuilder().build(), clientContext); } + public static final GrpcSubscriberStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSubscriberStub( + SubscriberStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcSubscriberStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -269,6 +277,20 @@ public static final GrpcSubscriberStub create(ClientContext clientContext) throw */ protected GrpcSubscriberStub(SubscriberStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcSubscriberCallableFactory()); + } + + /** + * Constructs an instance of GrpcSubscriberStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcSubscriberStub( + SubscriberStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings createSubscriptionTransportSettings = GrpcCallSettings.newBuilder() @@ -346,76 +368,76 @@ protected GrpcSubscriberStub(SubscriberStubSettings settings, ClientContext clie .build(); this.createSubscriptionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createSubscriptionTransportSettings, settings.createSubscriptionSettings(), clientContext); this.getSubscriptionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getSubscriptionTransportSettings, settings.getSubscriptionSettings(), clientContext); this.updateSubscriptionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateSubscriptionTransportSettings, settings.updateSubscriptionSettings(), clientContext); this.listSubscriptionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listSubscriptionsTransportSettings, settings.listSubscriptionsSettings(), clientContext); this.listSubscriptionsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listSubscriptionsTransportSettings, settings.listSubscriptionsSettings(), clientContext); this.deleteSubscriptionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteSubscriptionTransportSettings, settings.deleteSubscriptionSettings(), clientContext); this.modifyAckDeadlineCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( modifyAckDeadlineTransportSettings, settings.modifyAckDeadlineSettings(), clientContext); this.acknowledgeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( acknowledgeTransportSettings, settings.acknowledgeSettings(), clientContext); this.pullCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( pullTransportSettings, settings.pullSettings(), clientContext); this.streamingPullCallable = - GrpcCallableFactory.createBidiStreamingCallable( + callableFactory.createBidiStreamingCallable( streamingPullTransportSettings, settings.streamingPullSettings(), clientContext); this.modifyPushConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( modifyPushConfigTransportSettings, settings.modifyPushConfigSettings(), clientContext); this.listSnapshotsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listSnapshotsTransportSettings, settings.listSnapshotsSettings(), clientContext); this.listSnapshotsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listSnapshotsTransportSettings, settings.listSnapshotsSettings(), clientContext); this.createSnapshotCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createSnapshotTransportSettings, settings.createSnapshotSettings(), clientContext); this.updateSnapshotCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateSnapshotTransportSettings, settings.updateSnapshotSettings(), clientContext); this.deleteSnapshotCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteSnapshotTransportSettings, settings.deleteSnapshotSettings(), clientContext); this.seekCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( seekTransportSettings, settings.seekSettings(), clientContext); this.setIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); this.getIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); this.testIamPermissionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( testIamPermissionsTransportSettings, settings.testIamPermissionsSettings(), clientContext); diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStubSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStubSettings.java index d4d36ebe3a3e..b736d918c6d7 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStubSettings.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStubSettings.java @@ -95,7 +95,7 @@ * * PublisherStubSettings.Builder topicAdminSettingsBuilder = * PublisherStubSettings.newBuilder(); - * topicAdminSettingsBuilder.createTopicSettings().getRetrySettingsBuilder() + * topicAdminSettingsBuilder.createTopicSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * PublisherStubSettings topicAdminSettings = topicAdminSettingsBuilder.build(); * diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/SubscriberStubSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/SubscriberStubSettings.java index 2e8b8a124f1a..aca2c9143111 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/SubscriberStubSettings.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/SubscriberStubSettings.java @@ -97,7 +97,7 @@ * * SubscriberStubSettings.Builder subscriptionAdminSettingsBuilder = * SubscriberStubSettings.newBuilder(); - * subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettingsBuilder() + * subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SubscriberStubSettings subscriptionAdminSettings = subscriptionAdminSettingsBuilder.build(); * diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java index 200e239236ec..f02606db4321 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java @@ -168,7 +168,7 @@ public void failed(Subscriber.State from, Throwable failure) { } private MessageAndConsumer pollQueue(BlockingQueue queue) throws InterruptedException { - Object obj = queue.poll(1, TimeUnit.MINUTES); + Object obj = queue.poll(10, TimeUnit.MINUTES); if (obj == null) { return null; } diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java index 59879712ab53..13704b27d1b0 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java @@ -93,11 +93,11 @@ public void setupScheduleExpectation(Duration delay) { expectedWorkQueue.add(delay); } } - + /** - * Blocks the current thread until all the work - * {@link FakeScheduledExecutorService#setupScheduleExpectation(Duration) expected} has been - * scheduled in the executor. + * Blocks the current thread until all the work {@link + * FakeScheduledExecutorService#setupScheduleExpectation(Duration) expected} has been scheduled in + * the executor. */ public void waitForExpectedWork() { synchronized (expectedWorkQueue) { @@ -224,7 +224,7 @@ ScheduledFuture schedulePendingCallable(PendingCallable callable) { } expectedWorkQueue.notifyAll(); } - + return callable.getScheduledFuture(); } diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java index 1495c5f32071..bea0ec4e9194 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java @@ -16,14 +16,21 @@ package com.google.cloud.pubsub.v1; +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import com.google.api.core.ApiFuture; import com.google.api.gax.batching.BatchingSettings; import com.google.api.gax.core.ExecutorProvider; import com.google.api.gax.core.FixedExecutorProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.core.NoCredentialsProvider; -import com.google.api.gax.grpc.GrpcTransportChannel; -import com.google.api.gax.rpc.TransportChannel; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.rpc.DataLossException; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.cloud.pubsub.v1.Publisher.Builder; import com.google.protobuf.ByteString; @@ -33,8 +40,8 @@ import io.grpc.Server; import io.grpc.Status; import io.grpc.StatusException; -import io.grpc.inprocess.InProcessChannelBuilder; import io.grpc.inprocess.InProcessServerBuilder; +import java.util.concurrent.ExecutionException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -42,17 +49,6 @@ import org.junit.runners.JUnit4; import org.threeten.bp.Duration; -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ScheduledExecutorService; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - @RunWith(JUnit4.class) public class PublisherImplTest { @@ -62,53 +58,7 @@ public class PublisherImplTest { InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1).build(); private static final TransportChannelProvider TEST_CHANNEL_PROVIDER = - new TransportChannelProvider() { - @Override - public boolean shouldAutoClose() { - return true; - } - - @Override - public boolean needsExecutor() { - return false; - } - - @Override - public TransportChannelProvider withExecutor(ScheduledExecutorService executor) { - return null; - } - - @Override - public boolean needsHeaders() { - return false; - } - - @Override - public TransportChannelProvider withHeaders(Map headers) { - return null; - } - - @Override - public boolean needsEndpoint() { - return false; - } - - @Override - public TransportChannelProvider withEndpoint(String endpoint) { - return null; - } - - @Override - public TransportChannel getTransportChannel() throws IOException { - return GrpcTransportChannel.create(InProcessChannelBuilder.forName("test-server").build()); - } - - @Override - public String getTransportName() { - return null; - } - - }; + LocalChannelProvider.create("test-server"); private FakeScheduledExecutorService fakeExecutor; @@ -285,6 +235,27 @@ private ApiFuture sendTestMessage(Publisher publisher, String data) { PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8(data)).build()); } + @Test + public void testErrorPropagation() throws Exception { + Publisher publisher = + getTestPublisherBuilder() + .setExecutorProvider(SINGLE_THREAD_EXECUTOR) + .setBatchingSettings( + Publisher.Builder.DEFAULT_BATCHING_SETTINGS + .toBuilder() + .setElementCountThreshold(1L) + .setDelayThreshold(Duration.ofSeconds(5)) + .build()) + .build(); + testPublisherServiceImpl.addPublishError(Status.DATA_LOSS.asException()); + try { + sendTestMessage(publisher, "A").get(); + fail("should throw exception"); + } catch (ExecutionException e) { + assertThat(e.getCause()).isInstanceOf(DataLossException.class); + } + } + @Test public void testPublishFailureRetries() throws Exception { Publisher publisher = @@ -384,41 +355,6 @@ public void testPublishFailureRetries_maxRetriesSetUnlimited() throws Exception publisher.shutdown(); } - public void testPublishFailureRetries_exceededsRetryDuration() throws Exception { - Publisher publisher = - getTestPublisherBuilder() - .setExecutorProvider(SINGLE_THREAD_EXECUTOR) - .setRetrySettings( - Publisher.Builder.DEFAULT_RETRY_SETTINGS - .toBuilder() - .setTotalTimeout(Duration.ofSeconds(10)) - .build()) - .setBatchingSettings( - Publisher.Builder.DEFAULT_BATCHING_SETTINGS - .toBuilder() - .setElementCountThreshold(1L) - .setDelayThreshold(Duration.ofSeconds(5)) - .build()) - .build(); // To demonstrate that reaching duration will trigger publish - - // With exponential backoff, starting at 5ms we should have no more than 11 retries - for (int i = 0; i < 11; ++i) { - testPublisherServiceImpl.addPublishError(new FakeException()); - } - ApiFuture publishFuture1 = sendTestMessage(publisher, "A"); - - try { - publishFuture1.get(); - } catch (ExecutionException e) { - if (!(e.getCause() instanceof FakeException)) { - throw new IllegalStateException("unexpected exception", e); - } - } finally { - assertTrue(testPublisherServiceImpl.getCapturedRequests().size() >= 10); - publisher.shutdown(); - } - } - @Test(expected = ExecutionException.class) public void testPublishFailureRetries_nonRetryableFailsImmediately() throws Exception { Publisher publisher = @@ -472,7 +408,7 @@ public void testPublisherGetters() throws Exception { @Test public void testBuilderParametersAndDefaults() { Publisher.Builder builder = Publisher.newBuilder(TEST_TOPIC); - assertEquals(TEST_TOPIC, builder.topicName); + assertEquals(TEST_TOPIC.toString(), builder.topicName); assertEquals(Publisher.Builder.DEFAULT_EXECUTOR_PROVIDER, builder.executorProvider); assertEquals( Publisher.Builder.DEFAULT_REQUEST_BYTES_THRESHOLD, @@ -628,13 +564,6 @@ private Builder getTestPublisherBuilder() { return Publisher.newBuilder(TEST_TOPIC) .setExecutorProvider(FixedExecutorProvider.create(fakeExecutor)) .setChannelProvider(TEST_CHANNEL_PROVIDER) - .setCredentialsProvider(NoCredentialsProvider.create()) - .setLongRandom( - new Publisher.LongRandom() { - @Override - public long nextLong(long least, long bound) { - return bound - 1; - } - }); + .setCredentialsProvider(NoCredentialsProvider.create()); } } diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java index 4ee88f27464e..2664a4a4163a 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java @@ -141,7 +141,7 @@ public void testFailedChannel_fatalError_subscriberFails() throws Exception { } private Subscriber startSubscriber(Builder testSubscriberBuilder) throws Exception { - Subscriber subscriber = testSubscriberBuilder.setUseStreaming(true).build(); + Subscriber subscriber = testSubscriberBuilder.build(); subscriber.startAsync().awaitRunning(); return subscriber; } diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminSmokeTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminSmokeTest.java new file mode 100644 index 000000000000..6eb34fa87bee --- /dev/null +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminSmokeTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2018 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.cloud.pubsub.v1; + +import static com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse; + +import com.google.common.base.Preconditions; +import com.google.pubsub.v1.ProjectName; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class TopicAdminSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (TopicAdminClient client = TopicAdminClient.create()) { + ProjectName project = ProjectName.of(projectId); + + ListTopicsPagedResponse pagedResponse = client.listTopics(project); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-resourcemanager/README.md b/google-cloud-resourcemanager/README.md index dbda8c8fdccf..d42e075467da 100644 --- a/google-cloud-resourcemanager/README.md +++ b/google-cloud-resourcemanager/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-resourcemanager - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-resourcemanager:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-resourcemanager:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-resourcemanager" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-resourcemanager" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-resourcemanager/pom.xml b/google-cloud-resourcemanager/pom.xml index a99a81cdcd42..00a29a3a96f4 100644 --- a/google-cloud-resourcemanager/pom.xml +++ b/google-cloud-resourcemanager/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-resourcemanager - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Resource Manager https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-resourcemanager @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-resourcemanager diff --git a/google-cloud-spanner/README.md b/google-cloud-spanner/README.md index 5a57f3621964..74900a2bf027 100644 --- a/google-cloud-spanner/README.md +++ b/google-cloud-spanner/README.md @@ -22,16 +22,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-spanner - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-spanner:0.38.0-beta' +compile 'com.google.cloud:google-cloud-spanner:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index 71e0c913e73e..357bba82f6a4 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -4,7 +4,7 @@ http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 google-cloud-spanner - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Spanner https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-spanner @@ -14,7 +14,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-spanner diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Statement.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Statement.java index 519e43b873db..fd7cfddf01c0 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Statement.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Statement.java @@ -20,8 +20,8 @@ import static com.google.common.base.Preconditions.checkState; import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; - import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -100,6 +100,9 @@ public Statement build() { private class Binder extends ValueBinder { @Override Builder handle(Value value) { + Preconditions.checkArgument( + !value.isCommitTimestamp(), + "Mutation.COMMIT_TIMESTAMP cannot be bound as a query parameter"); checkState(currentBinding != null, "No binding in progress"); parameters.put(currentBinding, value); currentBinding = null; diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java index cc51f2f870dd..4a9f33216d60 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java @@ -52,6 +52,24 @@ */ @Immutable public abstract class Value implements Serializable { + + /** + * Placeholder value to be passed to a mutation to make Cloud Spanner store the commit timestamp + * in that column. The commit timestamp is the timestamp corresponding to when Cloud Spanner + * commits the transaction containing the mutation. + * + *

    Note that this particular timestamp instance has no semantic meaning. In particular the + * value of seconds and nanoseconds in this timestamp are meaningless. This placeholder can only + * be used for columns that have set the option "(allow_commit_timestamp=true)" in the schema. + * + *

    When reading the value stored in such a column, the value returned is an actual timestamp + * corresponding to the commit time of the transaction, which has no relation to this placeholder. + * + * @see + * Transaction Semantics + */ + public static final Timestamp COMMIT_TIMESTAMP = Timestamp.ofTimeMicroseconds(0L); + private static final int MAX_DEBUG_STRING_LENGTH = 32; private static final String ELLIPSIS = "..."; private static final String NULL_STRING = "NULL"; @@ -122,7 +140,7 @@ public static Value bytes(@Nullable ByteArray v) { /** Returns a {@code TIMESTAMP} value. */ public static Value timestamp(@Nullable Timestamp v) { - return new TimestampImpl(v == null, v); + return new TimestampImpl(v == null, v == Value.COMMIT_TIMESTAMP, v); } /** @@ -327,10 +345,14 @@ private Value() {} /** * Returns the value of a {@code TIMESTAMP}-typed instance. * - * @throws IllegalStateException if {@code isNull()} or the value is not of the expected type + * @throws IllegalStateException if {@code isNull()} or the value is not of the expected type or + * {@link #isCommitTimestamp()}. */ public abstract Timestamp getTimestamp(); + /** Returns true if this is a commit timestamp value. */ + public abstract boolean isCommitTimestamp(); + /** * Returns the value of a {@code DATE}-typed instance. * @@ -576,6 +598,11 @@ public final boolean isNull() { return isNull; } + @Override + public boolean isCommitTimestamp() { + return false; + } + @Override public boolean getBool() { throw defaultGetter(Type.bool()); @@ -927,20 +954,63 @@ void valueToString(StringBuilder b) { private static class TimestampImpl extends AbstractObjectValue { - private TimestampImpl(boolean isNull, Timestamp value) { + private static final String COMMIT_TIMESTAMP_STRING = "spanner.commit_timestamp()"; + private final boolean isCommitTimestamp; + + private TimestampImpl(boolean isNull, boolean isCommitTimestamp, Timestamp value) { super(isNull, Type.timestamp(), value); + this.isCommitTimestamp = isCommitTimestamp; } @Override public Timestamp getTimestamp() { checkType(Type.timestamp()); checkNotNull(); + Preconditions.checkState(!isCommitTimestamp, "Commit timestamp value"); return value; } + @Override + public boolean isCommitTimestamp() { + return isCommitTimestamp; + } + + @Override + com.google.protobuf.Value valueToProto() { + if (isCommitTimestamp) { + return com.google.protobuf.Value.newBuilder() + .setStringValue(COMMIT_TIMESTAMP_STRING) + .build(); + } + return super.valueToProto(); + } + @Override void valueToString(StringBuilder b) { - b.append(value); + if (isCommitTimestamp()) { + b.append(COMMIT_TIMESTAMP_STRING); + } else { + b.append(value); + } + } + + @Override + boolean valueEquals(Value v) { + if (isCommitTimestamp) { + return v.isCommitTimestamp(); + } + if (v.isCommitTimestamp()) { + return isCommitTimestamp; + } + return ((TimestampImpl) v).value.equals(value); + } + + @Override + int valueHash() { + if (isCommitTimestamp) { + return Objects.hashCode(isCommitTimestamp); + } + return value.hashCode(); } } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java index 2eccd3e5786c..6e02938b4f24 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java @@ -72,7 +72,7 @@ * * DatabaseAdminSettings.Builder databaseAdminSettingsBuilder = * DatabaseAdminSettings.newBuilder(); - * databaseAdminSettingsBuilder.getDatabaseSettings().getRetrySettingsBuilder() + * databaseAdminSettingsBuilder.getDatabaseSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * DatabaseAdminSettings databaseAdminSettings = databaseAdminSettingsBuilder.build(); * diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java index 2c38f9f90f6c..2b4c420d0085 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java @@ -90,7 +90,7 @@ * * DatabaseAdminStubSettings.Builder databaseAdminSettingsBuilder = * DatabaseAdminStubSettings.newBuilder(); - * databaseAdminSettingsBuilder.getDatabaseSettings().getRetrySettingsBuilder() + * databaseAdminSettingsBuilder.getDatabaseSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * DatabaseAdminStubSettings databaseAdminSettings = databaseAdminSettingsBuilder.build(); * diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminCallableFactory.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminCallableFactory.java new file mode 100644 index 000000000000..7f7130f5f594 --- /dev/null +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.spanner.admin.database.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Spanner Database Admin API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcDatabaseAdminCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java index 38569c414543..a94587837030 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -158,6 +158,8 @@ public class GrpcDatabaseAdminStub extends DatabaseAdminStub { private final UnaryCallable testIamPermissionsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcDatabaseAdminStub create(DatabaseAdminStubSettings settings) throws IOException { return new GrpcDatabaseAdminStub(settings, ClientContext.create(settings)); @@ -167,6 +169,12 @@ public static final GrpcDatabaseAdminStub create(ClientContext clientContext) th return new GrpcDatabaseAdminStub(DatabaseAdminStubSettings.newBuilder().build(), clientContext); } + public static final GrpcDatabaseAdminStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcDatabaseAdminStub( + DatabaseAdminStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcDatabaseAdminStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -174,7 +182,21 @@ public static final GrpcDatabaseAdminStub create(ClientContext clientContext) th */ protected GrpcDatabaseAdminStub(DatabaseAdminStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcDatabaseAdminCallableFactory()); + } + + /** + * Constructs an instance of GrpcDatabaseAdminStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcDatabaseAdminStub( + DatabaseAdminStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings listDatabasesTransportSettings = GrpcCallSettings.newBuilder() @@ -216,48 +238,48 @@ protected GrpcDatabaseAdminStub(DatabaseAdminStubSettings settings, ClientContex .build(); this.listDatabasesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listDatabasesTransportSettings, settings.listDatabasesSettings(), clientContext); this.listDatabasesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listDatabasesTransportSettings, settings.listDatabasesSettings(), clientContext); this.createDatabaseCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createDatabaseTransportSettings, settings.createDatabaseSettings(), clientContext); this.createDatabaseOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( createDatabaseTransportSettings, settings.createDatabaseOperationSettings(), clientContext, this.operationsStub); this.getDatabaseCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getDatabaseTransportSettings, settings.getDatabaseSettings(), clientContext); this.updateDatabaseDdlCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateDatabaseDdlTransportSettings, settings.updateDatabaseDdlSettings(), clientContext); this.updateDatabaseDdlOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( updateDatabaseDdlTransportSettings, settings.updateDatabaseDdlOperationSettings(), clientContext, this.operationsStub); this.dropDatabaseCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( dropDatabaseTransportSettings, settings.dropDatabaseSettings(), clientContext); this.getDatabaseDdlCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getDatabaseDdlTransportSettings, settings.getDatabaseDdlSettings(), clientContext); this.setIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); this.getIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); this.testIamPermissionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( testIamPermissionsTransportSettings, settings.testIamPermissionsSettings(), clientContext); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/InstanceAdminSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/InstanceAdminSettings.java index 00f3976e31e5..d5dccf33f7d6 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/InstanceAdminSettings.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/InstanceAdminSettings.java @@ -75,7 +75,7 @@ * * InstanceAdminSettings.Builder instanceAdminSettingsBuilder = * InstanceAdminSettings.newBuilder(); - * instanceAdminSettingsBuilder.getInstanceConfigSettings().getRetrySettingsBuilder() + * instanceAdminSettingsBuilder.getInstanceConfigSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * InstanceAdminSettings instanceAdminSettings = instanceAdminSettingsBuilder.build(); * diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/GrpcInstanceAdminCallableFactory.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/GrpcInstanceAdminCallableFactory.java new file mode 100644 index 000000000000..fbffa83f67e0 --- /dev/null +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/GrpcInstanceAdminCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.spanner.admin.instance.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Spanner Instance Admin API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcInstanceAdminCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/GrpcInstanceAdminStub.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/GrpcInstanceAdminStub.java index 6b133cf50ed2..4164fe1213d0 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/GrpcInstanceAdminStub.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/GrpcInstanceAdminStub.java @@ -22,7 +22,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -177,6 +177,8 @@ public class GrpcInstanceAdminStub extends InstanceAdminStub { private final UnaryCallable testIamPermissionsCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcInstanceAdminStub create(InstanceAdminStubSettings settings) throws IOException { return new GrpcInstanceAdminStub(settings, ClientContext.create(settings)); @@ -186,6 +188,12 @@ public static final GrpcInstanceAdminStub create(ClientContext clientContext) th return new GrpcInstanceAdminStub(InstanceAdminStubSettings.newBuilder().build(), clientContext); } + public static final GrpcInstanceAdminStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcInstanceAdminStub( + InstanceAdminStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcInstanceAdminStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -193,7 +201,21 @@ public static final GrpcInstanceAdminStub create(ClientContext clientContext) th */ protected GrpcInstanceAdminStub(InstanceAdminStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcInstanceAdminCallableFactory()); + } + + /** + * Constructs an instance of GrpcInstanceAdminStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcInstanceAdminStub( + InstanceAdminStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings listInstanceConfigsTransportSettings = @@ -239,58 +261,58 @@ protected GrpcInstanceAdminStub(InstanceAdminStubSettings settings, ClientContex .build(); this.listInstanceConfigsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listInstanceConfigsTransportSettings, settings.listInstanceConfigsSettings(), clientContext); this.listInstanceConfigsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listInstanceConfigsTransportSettings, settings.listInstanceConfigsSettings(), clientContext); this.getInstanceConfigCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getInstanceConfigTransportSettings, settings.getInstanceConfigSettings(), clientContext); this.listInstancesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); this.listInstancesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); this.getInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); this.createInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createInstanceTransportSettings, settings.createInstanceSettings(), clientContext); this.createInstanceOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( createInstanceTransportSettings, settings.createInstanceOperationSettings(), clientContext, this.operationsStub); this.updateInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( updateInstanceTransportSettings, settings.updateInstanceSettings(), clientContext); this.updateInstanceOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( updateInstanceTransportSettings, settings.updateInstanceOperationSettings(), clientContext, this.operationsStub); this.deleteInstanceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); this.setIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); this.getIamPolicyCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); this.testIamPermissionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( testIamPermissionsTransportSettings, settings.testIamPermissionsSettings(), clientContext); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java index 95e809401ed6..7548f758e58f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java @@ -93,7 +93,7 @@ * * InstanceAdminStubSettings.Builder instanceAdminSettingsBuilder = * InstanceAdminStubSettings.newBuilder(); - * instanceAdminSettingsBuilder.getInstanceConfigSettings().getRetrySettingsBuilder() + * instanceAdminSettingsBuilder.getInstanceConfigSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * InstanceAdminStubSettings instanceAdminSettings = instanceAdminSettingsBuilder.build(); * diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/SpannerSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/SpannerSettings.java index bb610859fd94..c8caa2d9c2f4 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/SpannerSettings.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/SpannerSettings.java @@ -73,7 +73,7 @@ * * SpannerSettings.Builder spannerSettingsBuilder = * SpannerSettings.newBuilder(); - * spannerSettingsBuilder.createSessionSettings().getRetrySettingsBuilder() + * spannerSettingsBuilder.createSessionSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpannerSettings spannerSettings = spannerSettingsBuilder.build(); * diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerCallableFactory.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerCallableFactory.java new file mode 100644 index 000000000000..017f5be97855 --- /dev/null +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.spanner.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Spanner API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcSpannerCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerStub.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerStub.java index cd99647a3802..7b900fddc150 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerStub.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -183,6 +183,8 @@ public class GrpcSpannerStub extends SpannerStub { private final UnaryCallable partitionQueryCallable; private final UnaryCallable partitionReadCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcSpannerStub create(SpannerStubSettings settings) throws IOException { return new GrpcSpannerStub(settings, ClientContext.create(settings)); } @@ -191,12 +193,31 @@ public static final GrpcSpannerStub create(ClientContext clientContext) throws I return new GrpcSpannerStub(SpannerStubSettings.newBuilder().build(), clientContext); } + public static final GrpcSpannerStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSpannerStub( + SpannerStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcSpannerStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcSpannerStub(SpannerStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcSpannerCallableFactory()); + } + + /** + * Constructs an instance of GrpcSpannerStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcSpannerStub( + SpannerStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings createSessionTransportSettings = GrpcCallSettings.newBuilder() @@ -252,48 +273,48 @@ protected GrpcSpannerStub(SpannerStubSettings settings, ClientContext clientCont .build(); this.createSessionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createSessionTransportSettings, settings.createSessionSettings(), clientContext); this.getSessionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getSessionTransportSettings, settings.getSessionSettings(), clientContext); this.listSessionsCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); this.listSessionsPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); this.deleteSessionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( deleteSessionTransportSettings, settings.deleteSessionSettings(), clientContext); this.executeSqlCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( executeSqlTransportSettings, settings.executeSqlSettings(), clientContext); this.executeStreamingSqlCallable = - GrpcCallableFactory.createServerStreamingCallable( + callableFactory.createServerStreamingCallable( executeStreamingSqlTransportSettings, settings.executeStreamingSqlSettings(), clientContext); this.readCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( readTransportSettings, settings.readSettings(), clientContext); this.streamingReadCallable = - GrpcCallableFactory.createServerStreamingCallable( + callableFactory.createServerStreamingCallable( streamingReadTransportSettings, settings.streamingReadSettings(), clientContext); this.beginTransactionCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( beginTransactionTransportSettings, settings.beginTransactionSettings(), clientContext); this.commitCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( commitTransportSettings, settings.commitSettings(), clientContext); this.rollbackCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( rollbackTransportSettings, settings.rollbackSettings(), clientContext); this.partitionQueryCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( partitionQueryTransportSettings, settings.partitionQuerySettings(), clientContext); this.partitionReadCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( partitionReadTransportSettings, settings.partitionReadSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java index d1174b60fb79..e7dcf5acafc9 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java @@ -88,7 +88,7 @@ * * SpannerStubSettings.Builder spannerSettingsBuilder = * SpannerStubSettings.newBuilder(); - * spannerSettingsBuilder.createSessionSettings().getRetrySettingsBuilder() + * spannerSettingsBuilder.createSessionSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpannerStubSettings spannerSettings = spannerSettingsBuilder.build(); * diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/StatementTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/StatementTest.java index 143899c4276d..d0ecc993b9ac 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/StatementTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/StatementTest.java @@ -115,6 +115,13 @@ public void alreadyBound() { binder.to("xyz"); } + @Test + public void bindCommitTimestampFails() { + ValueBinder binder = Statement.newBuilder("SELECT @v").bind("v"); + expectedException.expect(IllegalArgumentException.class); + binder.to(Value.COMMIT_TIMESTAMP); + } + @Test public void gettersAreSnapshot() { Statement stmt = diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java index 8b93b06a1770..d73cfc8df592 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java @@ -244,6 +244,7 @@ public void timestamp() { Value v = Value.timestamp(t); assertThat(v.getType()).isEqualTo(Type.timestamp()); assertThat(v.isNull()).isFalse(); + assertThat(v.isCommitTimestamp()).isFalse(); assertThat(v.getTimestamp()).isSameAs(t); assertThat(v.toString()).isEqualTo(timestamp); } @@ -254,12 +255,29 @@ public void timestampNull() { assertThat(v.getType()).isEqualTo(Type.timestamp()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); - + assertThat(v.isCommitTimestamp()).isFalse(); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getTimestamp(); } + @Test + public void commitTimestamp() { + Value v = Value.timestamp(Value.COMMIT_TIMESTAMP); + assertThat(v.getType()).isEqualTo(Type.timestamp()); + assertThat(v.isNull()).isFalse(); + assertThat(v.isCommitTimestamp()).isTrue(); + assertThat(v.toString()).isEqualTo("spanner.commit_timestamp()"); + assertThat(v.toProto()) + .isEqualTo( + com.google.protobuf.Value.newBuilder() + .setStringValue("spanner.commit_timestamp()") + .build()); + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Commit timestamp value"); + v.getTimestamp(); + } + @Test public void date() { String date = "2016-09-15"; @@ -661,6 +679,20 @@ public void testEqualsHashCode() { tester.addEqualityGroup(Value.bytes(newByteArray("def"))); tester.addEqualityGroup(Value.bytes(null)); + tester.addEqualityGroup(Value.timestamp(null), Value.timestamp(null)); + tester.addEqualityGroup(Value.timestamp(Value.COMMIT_TIMESTAMP), + Value.timestamp(Value.COMMIT_TIMESTAMP)); + Timestamp now = Timestamp.now(); + tester.addEqualityGroup(Value.timestamp(now), Value.timestamp(now)); + tester.addEqualityGroup(Value.timestamp(Timestamp.ofTimeMicroseconds(0))); + + tester.addEqualityGroup(Value.date(null), Value.date(null)); + tester.addEqualityGroup( + Value.date(Date.fromYearMonthDay(2018, 2, 26)), + Value.date(Date.fromYearMonthDay(2018, 2, 26))); + tester.addEqualityGroup( + Value.date(Date.fromYearMonthDay(2018, 2, 27))); + tester.addEqualityGroup( Value.boolArray(Arrays.asList(false, true)), Value.boolArray(new boolean[] {false, true}), @@ -696,6 +728,18 @@ public void testEqualsHashCode() { tester.addEqualityGroup(Value.bytesArray(Arrays.asList(newByteArray("c")))); tester.addEqualityGroup(Value.bytesArray(null)); + tester.addEqualityGroup(Value.timestampArray(Arrays.asList(null, now)), + Value.timestampArray(Arrays.asList(null, now))); + tester.addEqualityGroup(Value.timestampArray(null)); + + tester.addEqualityGroup( + Value.dateArray( + Arrays.asList(null, Date.fromYearMonthDay(2018, 2, 26))), + Value.dateArray( + Arrays.asList(null, Date.fromYearMonthDay(2018, 2, 26)))); + tester.addEqualityGroup(Value.dateArray(null)); + + tester.testEquals(); } @@ -730,6 +774,16 @@ public void serialization() { reserializeAndAssert(Value.float64Array(BrokenSerializationList.of(.1, .2, .3))); reserializeAndAssert(Value.float64Array((Iterable) null)); + reserializeAndAssert(Value.timestamp(null)); + reserializeAndAssert(Value.timestamp(Value.COMMIT_TIMESTAMP)); + reserializeAndAssert(Value.timestamp(Timestamp.now())); + reserializeAndAssert(Value.timestampArray(Arrays.asList(null, Timestamp.now()))); + + reserializeAndAssert(Value.date(null)); + reserializeAndAssert(Value.date(Date.fromYearMonthDay(2018, 2, 26))); + reserializeAndAssert(Value.dateArray(Arrays.asList(null, + Date.fromYearMonthDay(2018, 2, 26)))); + BrokenSerializationList of = BrokenSerializationList.of("a", "b"); reserializeAndAssert(Value.stringArray(of)); reserializeAndAssert(Value.stringArray(null)); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java index 15c090c8cfff..aff50e7cc059 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java @@ -34,6 +34,7 @@ import com.google.cloud.spanner.SpannerException; import com.google.cloud.spanner.Struct; import com.google.cloud.spanner.TimestampBound; +import com.google.cloud.spanner.Value; import io.grpc.Context; import java.util.Arrays; import java.util.HashMap; @@ -77,7 +78,7 @@ public static void setUpDatabase() { + " Float64Value FLOAT64," + " StringValue STRING(MAX)," + " BytesValue BYTES(MAX)," - + " TimestampValue TIMESTAMP," + + " TimestampValue TIMESTAMP OPTIONS (allow_commit_timestamp = true)," + " DateValue DATE," + " BoolArrayValue ARRAY," + " Int64ArrayValue ARRAY," @@ -97,8 +98,8 @@ private static String uniqueString() { @Rule public ExpectedException expectedException = ExpectedException.none(); private String lastKey; - private void write(Mutation m) { - client.write(Arrays.asList(m)); + private Timestamp write(Mutation m) { + return client.write(Arrays.asList(m)); } private Mutation.WriteBuilder baseInsert() { @@ -294,6 +295,14 @@ public void writeTimestampNull() { assertThat(row.isNull(0)).isTrue(); } + @Test + public void writeCommitTimestamp() { + Timestamp commitTimestamp = + write(baseInsert().set("TimestampValue").to(Value.COMMIT_TIMESTAMP).build()); + Struct row = readLastRow("TimestampValue"); + assertThat(row.getTimestamp(0)).isEqualTo(commitTimestamp); + } + @Test public void writeDate() { Date date = Date.parseDate("2016-09-15"); diff --git a/google-cloud-speech/README.md b/google-cloud-speech/README.md index 3d0ac025e0e6..d5da2fbbccd0 100644 --- a/google-cloud-speech/README.md +++ b/google-cloud-speech/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-speech - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-speech:0.38.0-alpha' +compile 'com.google.cloud:google-cloud-speech:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-speech" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-speech" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-speech/pom.xml b/google-cloud-speech/pom.xml index 52224362bc12..9c7b6687edfb 100644 --- a/google-cloud-speech/pom.xml +++ b/google-cloud-speech/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-speech - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Speech https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-speech @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-speech diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/SpeechSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/SpeechSettings.java index 0db7385c7ccf..527567dec43f 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/SpeechSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/SpeechSettings.java @@ -53,7 +53,7 @@ * * SpeechSettings.Builder speechSettingsBuilder = * SpeechSettings.newBuilder(); - * speechSettingsBuilder.recognizeSettings().getRetrySettingsBuilder() + * speechSettingsBuilder.recognizeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpeechSettings speechSettings = speechSettingsBuilder.build(); * diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/GrpcSpeechCallableFactory.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/GrpcSpeechCallableFactory.java new file mode 100644 index 000000000000..bab4fb4c55a1 --- /dev/null +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/GrpcSpeechCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.speech.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Speech API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcSpeechCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/GrpcSpeechStub.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/GrpcSpeechStub.java index 646cdb9d42c4..ad90ab6d1c70 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/GrpcSpeechStub.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/GrpcSpeechStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +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.OperationCallable; @@ -88,6 +88,8 @@ public class GrpcSpeechStub extends SpeechStub { private final BidiStreamingCallable streamingRecognizeCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcSpeechStub create(SpeechStubSettings settings) throws IOException { return new GrpcSpeechStub(settings, ClientContext.create(settings)); } @@ -96,13 +98,32 @@ public static final GrpcSpeechStub create(ClientContext clientContext) throws IO return new GrpcSpeechStub(SpeechStubSettings.newBuilder().build(), clientContext); } + public static final GrpcSpeechStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSpeechStub( + SpeechStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcSpeechStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcSpeechStub(SpeechStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcSpeechCallableFactory()); + } + + /** + * Constructs an instance of GrpcSpeechStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcSpeechStub( + SpeechStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings recognizeTransportSettings = GrpcCallSettings.newBuilder() @@ -119,21 +140,21 @@ protected GrpcSpeechStub(SpeechStubSettings settings, ClientContext clientContex .build(); this.recognizeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( recognizeTransportSettings, settings.recognizeSettings(), clientContext); this.longRunningRecognizeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( longRunningRecognizeTransportSettings, settings.longRunningRecognizeSettings(), clientContext); this.longRunningRecognizeOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( longRunningRecognizeTransportSettings, settings.longRunningRecognizeOperationSettings(), clientContext, this.operationsStub); this.streamingRecognizeCallable = - GrpcCallableFactory.createBidiStreamingCallable( + callableFactory.createBidiStreamingCallable( streamingRecognizeTransportSettings, settings.streamingRecognizeSettings(), clientContext); diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/SpeechStubSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/SpeechStubSettings.java index 881be28213ef..d1c0d7b97bfd 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/SpeechStubSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1/stub/SpeechStubSettings.java @@ -72,7 +72,7 @@ * * SpeechStubSettings.Builder speechSettingsBuilder = * SpeechStubSettings.newBuilder(); - * speechSettingsBuilder.recognizeSettings().getRetrySettingsBuilder() + * speechSettingsBuilder.recognizeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpeechStubSettings speechSettings = speechSettingsBuilder.build(); * diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/SpeechSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/SpeechSettings.java index aeaf17479eec..456b937eafbc 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/SpeechSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/SpeechSettings.java @@ -53,7 +53,7 @@ * * SpeechSettings.Builder speechSettingsBuilder = * SpeechSettings.newBuilder(); - * speechSettingsBuilder.syncRecognizeSettings().getRetrySettingsBuilder() + * speechSettingsBuilder.syncRecognizeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpeechSettings speechSettings = speechSettingsBuilder.build(); * diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/GrpcSpeechCallableFactory.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/GrpcSpeechCallableFactory.java new file mode 100644 index 000000000000..c3434bd314da --- /dev/null +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/GrpcSpeechCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.speech.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Speech API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcSpeechCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/GrpcSpeechStub.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/GrpcSpeechStub.java index b559f2410267..9c4748c53ee0 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/GrpcSpeechStub.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/GrpcSpeechStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +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.OperationCallable; @@ -90,6 +90,8 @@ public class GrpcSpeechStub extends SpeechStub { private final BidiStreamingCallable streamingRecognizeCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcSpeechStub create(SpeechStubSettings settings) throws IOException { return new GrpcSpeechStub(settings, ClientContext.create(settings)); } @@ -98,13 +100,32 @@ public static final GrpcSpeechStub create(ClientContext clientContext) throws IO return new GrpcSpeechStub(SpeechStubSettings.newBuilder().build(), clientContext); } + public static final GrpcSpeechStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSpeechStub( + SpeechStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcSpeechStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcSpeechStub(SpeechStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcSpeechCallableFactory()); + } + + /** + * Constructs an instance of GrpcSpeechStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcSpeechStub( + SpeechStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings syncRecognizeTransportSettings = GrpcCallSettings.newBuilder() @@ -121,19 +142,19 @@ protected GrpcSpeechStub(SpeechStubSettings settings, ClientContext clientContex .build(); this.syncRecognizeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( syncRecognizeTransportSettings, settings.syncRecognizeSettings(), clientContext); this.asyncRecognizeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( asyncRecognizeTransportSettings, settings.asyncRecognizeSettings(), clientContext); this.asyncRecognizeOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( asyncRecognizeTransportSettings, settings.asyncRecognizeOperationSettings(), clientContext, this.operationsStub); this.streamingRecognizeCallable = - GrpcCallableFactory.createBidiStreamingCallable( + callableFactory.createBidiStreamingCallable( streamingRecognizeTransportSettings, settings.streamingRecognizeSettings(), clientContext); diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/SpeechStubSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/SpeechStubSettings.java index 8bfdfda90112..6f393bb761d7 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/SpeechStubSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1beta1/stub/SpeechStubSettings.java @@ -72,7 +72,7 @@ * * SpeechStubSettings.Builder speechSettingsBuilder = * SpeechStubSettings.newBuilder(); - * speechSettingsBuilder.syncRecognizeSettings().getRetrySettingsBuilder() + * speechSettingsBuilder.syncRecognizeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpeechStubSettings speechSettings = speechSettingsBuilder.build(); * diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/SpeechSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/SpeechSettings.java index 00f80d1b1083..2c374665b091 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/SpeechSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/SpeechSettings.java @@ -53,7 +53,7 @@ * * SpeechSettings.Builder speechSettingsBuilder = * SpeechSettings.newBuilder(); - * speechSettingsBuilder.recognizeSettings().getRetrySettingsBuilder() + * speechSettingsBuilder.recognizeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpeechSettings speechSettings = speechSettingsBuilder.build(); * diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/package-info.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/package-info.java index 356d23560d06..b718f74243ea 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/package-info.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/package-info.java @@ -15,7 +15,7 @@ */ /** - * A client to Google Cloud Speech API. + * A client to Cloud Speech API. * *

    The interfaces provided are listed below, along with usage samples. * diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/GrpcSpeechCallableFactory.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/GrpcSpeechCallableFactory.java new file mode 100644 index 000000000000..b4eb925ace66 --- /dev/null +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/GrpcSpeechCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.speech.v1p1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Speech API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcSpeechCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/GrpcSpeechStub.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/GrpcSpeechStub.java index 9c312518ec7c..29a7398280cc 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/GrpcSpeechStub.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/GrpcSpeechStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +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.OperationCallable; @@ -41,7 +41,7 @@ // AUTO-GENERATED DOCUMENTATION AND CLASS /** - * gRPC stub implementation for Google Cloud Speech API. + * gRPC stub implementation for Cloud Speech API. * *

    This class is for advanced usage and reflects the underlying API directly. */ @@ -88,6 +88,8 @@ public class GrpcSpeechStub extends SpeechStub { private final BidiStreamingCallable streamingRecognizeCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcSpeechStub create(SpeechStubSettings settings) throws IOException { return new GrpcSpeechStub(settings, ClientContext.create(settings)); } @@ -96,13 +98,32 @@ public static final GrpcSpeechStub create(ClientContext clientContext) throws IO return new GrpcSpeechStub(SpeechStubSettings.newBuilder().build(), clientContext); } + public static final GrpcSpeechStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSpeechStub( + SpeechStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcSpeechStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcSpeechStub(SpeechStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcSpeechCallableFactory()); + } + + /** + * Constructs an instance of GrpcSpeechStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcSpeechStub( + SpeechStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings recognizeTransportSettings = GrpcCallSettings.newBuilder() @@ -119,21 +140,21 @@ protected GrpcSpeechStub(SpeechStubSettings settings, ClientContext clientContex .build(); this.recognizeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( recognizeTransportSettings, settings.recognizeSettings(), clientContext); this.longRunningRecognizeCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( longRunningRecognizeTransportSettings, settings.longRunningRecognizeSettings(), clientContext); this.longRunningRecognizeOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( longRunningRecognizeTransportSettings, settings.longRunningRecognizeOperationSettings(), clientContext, this.operationsStub); this.streamingRecognizeCallable = - GrpcCallableFactory.createBidiStreamingCallable( + callableFactory.createBidiStreamingCallable( streamingRecognizeTransportSettings, settings.streamingRecognizeSettings(), clientContext); diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStub.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStub.java index 5a380ef6128d..18fff8160e23 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStub.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStub.java @@ -33,7 +33,7 @@ // AUTO-GENERATED DOCUMENTATION AND CLASS /** - * Base stub class for Google Cloud Speech API. + * Base stub class for Cloud Speech API. * *

    This class is for advanced usage and reflects the underlying API directly. */ diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStubSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStubSettings.java index ca004e3de399..f94301f3bbf0 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStubSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/v1p1beta1/stub/SpeechStubSettings.java @@ -72,7 +72,7 @@ * * SpeechStubSettings.Builder speechSettingsBuilder = * SpeechStubSettings.newBuilder(); - * speechSettingsBuilder.recognizeSettings().getRetrySettingsBuilder() + * speechSettingsBuilder.recognizeSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * SpeechStubSettings speechSettings = speechSettingsBuilder.build(); * diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/v1/SpeechSmokeTest.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/v1/SpeechSmokeTest.java new file mode 100644 index 000000000000..7664f18c41f0 --- /dev/null +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/v1/SpeechSmokeTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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.cloud.speech.v1; + +import com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding; +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class SpeechSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (SpeechClient client = SpeechClient.create()) { + String languageCode = "en-US"; + int sampleRateHertz = 44100; + RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC; + RecognitionConfig config = + RecognitionConfig.newBuilder() + .setLanguageCode(languageCode) + .setSampleRateHertz(sampleRateHertz) + .setEncoding(encoding) + .build(); + String uri = "gs://gapic-toolkit/hello.flac"; + RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build(); + + RecognizeResponse response = client.recognize(config, audio); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/v1beta1/SpeechSmokeTest.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/v1beta1/SpeechSmokeTest.java new file mode 100644 index 000000000000..ea390741159d --- /dev/null +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/v1beta1/SpeechSmokeTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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.cloud.speech.v1beta1; + +import com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding; +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class SpeechSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (SpeechClient client = SpeechClient.create()) { + String languageCode = "en-US"; + int sampleRate = 44100; + RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC; + RecognitionConfig config = + RecognitionConfig.newBuilder() + .setLanguageCode(languageCode) + .setSampleRate(sampleRate) + .setEncoding(encoding) + .build(); + String uri = "gs://gapic-toolkit/hello.flac"; + RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build(); + + SyncRecognizeResponse response = client.syncRecognize(config, audio); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/v1p1beta1/SpeechSmokeTest.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/v1p1beta1/SpeechSmokeTest.java new file mode 100644 index 000000000000..06e4b15f6e44 --- /dev/null +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/v1p1beta1/SpeechSmokeTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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.cloud.speech.v1p1beta1; + +import com.google.cloud.speech.v1p1beta1.RecognitionConfig.AudioEncoding; +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class SpeechSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (SpeechClient client = SpeechClient.create()) { + String languageCode = "en-US"; + int sampleRateHertz = 44100; + RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC; + RecognitionConfig config = + RecognitionConfig.newBuilder() + .setLanguageCode(languageCode) + .setSampleRateHertz(sampleRateHertz) + .setEncoding(encoding) + .build(); + String uri = "gs://gapic-toolkit/hello.flac"; + RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build(); + + RecognizeResponse response = client.recognize(config, audio); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-storage/README.md b/google-cloud-storage/README.md index c816768b4fb0..534d5715df45 100644 --- a/google-cloud-storage/README.md +++ b/google-cloud-storage/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-storage - 1.20.0 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-storage:1.20.0' +compile 'com.google.cloud:google-cloud-storage:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-storage/pom.xml b/google-cloud-storage/pom.xml index 68a5547bb40b..07042b786e88 100644 --- a/google-cloud-storage/pom.xml +++ b/google-cloud-storage/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-storage - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Storage https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-storage @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-storage diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index d5268a1f5fef..b0a71387690a 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -188,6 +188,7 @@ public void submit() { // TODO(hailongwen@): instrument 'google-api-java-client' to further break down the span. // Here we only add a annotation to at least know how much time each batch takes. span.addAnnotation("Execute batch request"); + batch.setBatchUrl(new GenericUrl("https://www.googleapis.com/batch/storage/v1")); batch.execute(); } } catch (IOException ex) { diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java index f0888a05dc93..9f6272b87bf2 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java @@ -408,24 +408,13 @@ public void testListBlobsEmptySelectedFields() throws InterruptedException { } } - @Test(timeout = 5000) + @Test(timeout = 7500) public void testListBlobRequesterPays() throws InterruptedException { - String[] blobNames = {"test-list-blobs-empty-selected-fields-blob1", - "test-list-blobs-empty-selected-fields-blob2"}; - BlobInfo blob1 = BlobInfo.newBuilder(BUCKET, blobNames[0]) - .setContentType(CONTENT_TYPE) - .build(); - BlobInfo blob2 = BlobInfo.newBuilder(BUCKET, blobNames[1]) - .setContentType(CONTENT_TYPE) - .build(); - Blob remoteBlob1 = storage.create(blob1); - Blob remoteBlob2 = storage.create(blob2); - assertNotNull(remoteBlob1); - assertNotNull(remoteBlob2); - - Page page = storage.list(BUCKET, - Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), - Storage.BlobListOption.fields()); + BlobInfo blob1 = + BlobInfo.newBuilder(BUCKET, "test-list-blobs-empty-selected-fields-blob1") + .setContentType(CONTENT_TYPE) + .build(); + assertNotNull(storage.create(blob1)); // Test listing a Requester Pays bucket. Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ID)); @@ -433,9 +422,9 @@ public void testListBlobRequesterPays() throws InterruptedException { remoteBucket = remoteBucket.toBuilder().setRequesterPays(true).build(); Bucket updatedBucket = storage.update(remoteBucket); assertTrue(updatedBucket.requesterPays()); - String projectId = remoteStorageHelper.getOptions().getProjectId(); try { - page = storage.list(BUCKET, + storage.list( + BUCKET, Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), Storage.BlobListOption.fields(), Storage.BlobListOption.userProject("fakeBillingProjectId")); @@ -443,12 +432,23 @@ public void testListBlobRequesterPays() throws InterruptedException { } catch (StorageException e) { assertTrue(e.getMessage().contains("User project specified in the request is invalid")); } - while (Iterators.size(page.iterateAll().iterator()) != 2) { + + String projectId = remoteStorageHelper.getOptions().getProjectId(); + while (true) { + Page page = + storage.list( + BUCKET, + Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), + Storage.BlobListOption.fields(), + Storage.BlobListOption.userProject(projectId)); + List blobs = Lists.newArrayList(page.iterateAll()); + // If the list is empty, maybe the blob isn't visible yet; wait and try again. + // Otherwise, expect one blob, since we only put in one above. + if (!blobs.isEmpty()) { + assertThat(blobs).hasSize(1); + break; + } Thread.sleep(500); - page = storage.list(BUCKET, - Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), - Storage.BlobListOption.fields(), - Storage.BlobListOption.userProject(projectId)); } } diff --git a/google-cloud-testing/google-cloud-appengineflexcompat/pom.xml b/google-cloud-testing/google-cloud-appengineflexcompat/pom.xml index 23934a6ddcf4..20f0bfc754f6 100644 --- a/google-cloud-testing/google-cloud-appengineflexcompat/pom.xml +++ b/google-cloud-testing/google-cloud-appengineflexcompat/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-appengineflexcompat - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT war google-cloud-testing com.google.cloud - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT diff --git a/google-cloud-testing/google-cloud-appengineflexcustom/pom.xml b/google-cloud-testing/google-cloud-appengineflexcustom/pom.xml index 44e9625c3b60..0a185c2cb657 100644 --- a/google-cloud-testing/google-cloud-appengineflexcustom/pom.xml +++ b/google-cloud-testing/google-cloud-appengineflexcustom/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-appengineflexcustom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT war google-cloud-testing com.google.cloud - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT diff --git a/google-cloud-testing/google-cloud-appengineflexjava/pom.xml b/google-cloud-testing/google-cloud-appengineflexjava/pom.xml index a7285144e578..5bdf4e38b9f7 100644 --- a/google-cloud-testing/google-cloud-appengineflexjava/pom.xml +++ b/google-cloud-testing/google-cloud-appengineflexjava/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-appengineflexjava - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT war google-cloud-testing com.google.cloud - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT diff --git a/google-cloud-testing/google-cloud-appenginejava8/pom.xml b/google-cloud-testing/google-cloud-appenginejava8/pom.xml index dafb77de7c18..52fba2e08af5 100644 --- a/google-cloud-testing/google-cloud-appenginejava8/pom.xml +++ b/google-cloud-testing/google-cloud-appenginejava8/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-appenginejava8 - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT war google-cloud-testing com.google.cloud - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT diff --git a/google-cloud-testing/google-cloud-managedtest/pom.xml b/google-cloud-testing/google-cloud-managedtest/pom.xml index 2c3be25e6133..38274f3a1609 100644 --- a/google-cloud-testing/google-cloud-managedtest/pom.xml +++ b/google-cloud-testing/google-cloud-managedtest/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 google-cloud-managedtest - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar google-cloud-testing com.google.cloud - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT diff --git a/google-cloud-testing/pom.xml b/google-cloud-testing/pom.xml index 54cf500192ef..591e13d43004 100644 --- a/google-cloud-testing/pom.xml +++ b/google-cloud-testing/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-testing - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT pom Google Cloud Testing @@ -13,7 +13,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-testing diff --git a/google-cloud-texttospeech/README.md b/google-cloud-texttospeech/README.md new file mode 100644 index 000000000000..9a1b1fe4ce8a --- /dev/null +++ b/google-cloud-texttospeech/README.md @@ -0,0 +1,102 @@ +Google Cloud Java Client for Text-to-Speech +====================================== + +Java idiomatic client for [Text-to-Speech][cloud-texttospeech]. + +[![CircleCI](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master.svg?style=shield)](https://circleci.com/gh/GoogleCloudPlatform/google-cloud-java/tree/master) +[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/google-cloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/google-cloud-java?branch=master) +[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-texttospeech.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-texttospeech.svg) +[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) +[![Dependency Status](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772/badge.svg?style=flat)](https://www.versioneye.com/user/projects/58fe4c8d6ac171426c414772) + +- [Product Documentation][texttospeech-product-docs] +- [Client Library Documentation][texttospeech-client-lib-docs] + +> Note: This client is a work-in-progress, and may occasionally +> make backwards-incompatible changes. + +Quickstart +---------- + +[//]: # ({x-version-update-start:google-cloud-texttospeech:released}) +If you are using Maven, add this to your pom.xml file +```xml + + com.google.cloud + google-cloud-texttospeech + 0.43.0-beta + +``` +If you are using Gradle, add this to your dependencies +```Groovy +compile 'com.google.cloud:google-cloud-texttospeech:0.43.0-beta' +``` +If you are using SBT, add this to your dependencies +```Scala +libraryDependencies += "com.google.cloud" % "google-cloud-texttospeech" % "0.43.0-beta" +``` +[//]: # ({x-version-update-end}) + +Authentication +-------------- + +See the [Authentication](https://github.com/GoogleCloudPlatform/google-cloud-java#authentication) section in the base directory's README. + +About Google Cloud Text-to-Speech +---------------------------- + +Google [Text-to-Speech API][cloud-texttospeech] enables easy integration of Google text recognition technologies into developer applications. Send text and receive synthesized audio output from the Text-to-Speech API service. + +See the [Text-to-Speech client library docs][texttospeech-client-lib-docs] to learn how to use this Text-to-Speech API Client Library. + +Getting Started +--------------- +#### Prerequisites +You will need a [Google Developers Console](https://console.developers.google.com/) project with the Text-to-Speech API enabled. [Follow these instructions](https://cloud.google.com/docs/authentication#preparation) to get your project set up. You will also need to set up the local development environment by [installing the Google Cloud SDK](https://cloud.google.com/sdk/) and running the following commands in command line: `gcloud auth login` and `gcloud config set project [YOUR PROJECT ID]`. + +#### Installation and setup +You'll need to obtain the `google-cloud-texttospeech` library. See the [Quickstart](#quickstart) section to add `google-cloud-texttospeech` as a dependency in your code. + +Troubleshooting +--------------- + +To get help, follow the instructions in the [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting). + +Transport +--------- +Text-to-Speech uses gRPC for the transport layer. + +Java Versions +------------- + +Java 7 or above is required for using this client. + +Versioning +---------- + +This library follows [Semantic Versioning](http://semver.org/). + +It is currently in major version zero (``0.y.z``), which means that anything may change at any time and the public API should not be considered stable. + +Contributing +------------ + +Contributions to this library are always welcome and highly encouraged. + +See `google-cloud`'s [CONTRIBUTING] documentation and the [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started. + +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information. + +License +------- + +Apache 2.0 - See [LICENSE] for more information. + + +[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CONTRIBUTING.md +[code-of-conduct]:https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct +[LICENSE]: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/LICENSE +[cloud-platform]: https://cloud.google.com/ +[cloud-texttospeech]: https://cloud.google.com/texttospeech +[texttospeech-product-docs]: https://cloud.google.com/texttospeech/docs +[texttospeech-client-lib-docs]: https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/texttospeech/v1beta1/package-summary.html diff --git a/google-cloud-texttospeech/pom.xml b/google-cloud-texttospeech/pom.xml new file mode 100644 index 000000000000..d93b574d2d36 --- /dev/null +++ b/google-cloud-texttospeech/pom.xml @@ -0,0 +1,139 @@ + + + 4.0.0 + google-cloud-texttospeech + 0.43.1-beta-SNAPSHOT + jar + Google Cloud Text-to-Speech + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-texttospeech + + Java idiomatic client for Google Cloud Text-to-Speech + + + com.google.cloud + google-cloud-pom + 0.43.1-alpha-SNAPSHOT + + + google-cloud-texttospeech-v1beta1 + + + + ${project.groupId} + google-cloud-core + + + ${project.groupId} + google-cloud-core-grpc + + + com.google.api.grpc + proto-google-cloud-texttospeech-v1beta1 + + + io.grpc + grpc-netty-shaded + + + io.grpc + grpc-stub + + + io.grpc + grpc-auth + + + ${project.groupId} + google-cloud-core + test-jar + test + + + junit + junit + test + + + org.easymock + easymock + test + + + org.objenesis + objenesis + test + + + com.google.api.grpc + grpc-google-cloud-texttospeech-v1beta1 + test + + + com.google.api + gax-grpc + testlib + test + + + + + doclint-java8-disable + + [1.8,) + + + + -Xdoclint:none + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + generate-sources + add-source + + + generated/src/main/java + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + attach-javadocs + + jar + + + ${javadoc.opts} + + + + + + maven-compiler-plugin + + + + 3.1 + + 1.7 + 1.7 + UTF-8 + -Xlint:unchecked + + + + + diff --git a/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechClient.java b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechClient.java new file mode 100644 index 000000000000..70c373ea8502 --- /dev/null +++ b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechClient.java @@ -0,0 +1,329 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.texttospeech.v1beta1.stub.TextToSpeechStub; +import com.google.cloud.texttospeech.v1beta1.stub.TextToSpeechStubSettings; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: Service that implements Google Cloud Text-to-Speech API. + * + *

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

    + * 
    + * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    + *   String languageCode = "";
    + *   ListVoicesResponse response = textToSpeechClient.listVoices(languageCode);
    + * }
    + * 
    + * 
    + * + *

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

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

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

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

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

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

    To customize credentials: + * + *

    + * 
    + * TextToSpeechSettings textToSpeechSettings =
    + *     TextToSpeechSettings.newBuilder()
    + *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
    + *         .build();
    + * TextToSpeechClient textToSpeechClient =
    + *     TextToSpeechClient.create(textToSpeechSettings);
    + * 
    + * 
    + * + * To customize the endpoint: + * + *
    + * 
    + * TextToSpeechSettings textToSpeechSettings =
    + *     TextToSpeechSettings.newBuilder().setEndpoint(myEndpoint).build();
    + * TextToSpeechClient textToSpeechClient =
    + *     TextToSpeechClient.create(textToSpeechSettings);
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class TextToSpeechClient implements BackgroundResource { + private final TextToSpeechSettings settings; + private final TextToSpeechStub stub; + + /** Constructs an instance of TextToSpeechClient with default settings. */ + public static final TextToSpeechClient create() throws IOException { + return create(TextToSpeechSettings.newBuilder().build()); + } + + /** + * Constructs an instance of TextToSpeechClient, using the given settings. The channels are + * created based on the settings passed in, or defaults for any settings that are not set. + */ + public static final TextToSpeechClient create(TextToSpeechSettings settings) throws IOException { + return new TextToSpeechClient(settings); + } + + /** + * Constructs an instance of TextToSpeechClient, using the given stub for making calls. This is + * for advanced usage - prefer to use TextToSpeechSettings}. + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final TextToSpeechClient create(TextToSpeechStub stub) { + return new TextToSpeechClient(stub); + } + + /** + * Constructs an instance of TextToSpeechClient, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected TextToSpeechClient(TextToSpeechSettings settings) throws IOException { + this.settings = settings; + this.stub = ((TextToSpeechStubSettings) settings.getStubSettings()).createStub(); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected TextToSpeechClient(TextToSpeechStub stub) { + this.settings = null; + this.stub = stub; + } + + public final TextToSpeechSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public TextToSpeechStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns a list of [Voice][google.cloud.texttospeech.v1beta1.Voice] supported for synthesis. + * + *

    Sample code: + * + *

    
    +   * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    +   *   String languageCode = "";
    +   *   ListVoicesResponse response = textToSpeechClient.listVoices(languageCode);
    +   * }
    +   * 
    + * + * @param languageCode Optional (but recommended) + * [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag. If specified, the + * ListVoices call will only return voices that can be used to synthesize this language_code. + * E.g. when specifying "en-NZ", you will get supported "en-*" voices; when specifying + * "no", you will get supported "no-*" (Norwegian) and "nb-*" (Norwegian Bokmal) + * voices; specifying "zh" will also get supported "cmn-*" voices; specifying "zh-hk" will + * also get supported "yue-*" voices. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListVoicesResponse listVoices(String languageCode) { + + ListVoicesRequest request = + ListVoicesRequest.newBuilder().setLanguageCode(languageCode).build(); + return listVoices(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns a list of [Voice][google.cloud.texttospeech.v1beta1.Voice] supported for synthesis. + * + *

    Sample code: + * + *

    
    +   * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    +   *   ListVoicesRequest request = ListVoicesRequest.newBuilder().build();
    +   *   ListVoicesResponse response = textToSpeechClient.listVoices(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 ListVoicesResponse listVoices(ListVoicesRequest request) { + return listVoicesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns a list of [Voice][google.cloud.texttospeech.v1beta1.Voice] supported for synthesis. + * + *

    Sample code: + * + *

    
    +   * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    +   *   ListVoicesRequest request = ListVoicesRequest.newBuilder().build();
    +   *   ApiFuture<ListVoicesResponse> future = textToSpeechClient.listVoicesCallable().futureCall(request);
    +   *   // Do something
    +   *   ListVoicesResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable listVoicesCallable() { + return stub.listVoicesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Synthesizes speech synchronously: receive results after all text input has been processed. + * + *

    Sample code: + * + *

    
    +   * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    +   *   SynthesisInput input = SynthesisInput.newBuilder().build();
    +   *   VoiceSelectionParams voice = VoiceSelectionParams.newBuilder().build();
    +   *   AudioConfig audioConfig = AudioConfig.newBuilder().build();
    +   *   SynthesizeSpeechResponse response = textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);
    +   * }
    +   * 
    + * + * @param input Required. The Synthesizer requires either plain text or SSML as input. + * @param voice Required. The desired voice of the synthesized audio. + * @param audioConfig Required. The configuration of the synthesized audio. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final SynthesizeSpeechResponse synthesizeSpeech( + SynthesisInput input, VoiceSelectionParams voice, AudioConfig audioConfig) { + + SynthesizeSpeechRequest request = + SynthesizeSpeechRequest.newBuilder() + .setInput(input) + .setVoice(voice) + .setAudioConfig(audioConfig) + .build(); + return synthesizeSpeech(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Synthesizes speech synchronously: receive results after all text input has been processed. + * + *

    Sample code: + * + *

    
    +   * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    +   *   SynthesisInput input = SynthesisInput.newBuilder().build();
    +   *   VoiceSelectionParams voice = VoiceSelectionParams.newBuilder().build();
    +   *   AudioConfig audioConfig = AudioConfig.newBuilder().build();
    +   *   SynthesizeSpeechRequest request = SynthesizeSpeechRequest.newBuilder()
    +   *     .setInput(input)
    +   *     .setVoice(voice)
    +   *     .setAudioConfig(audioConfig)
    +   *     .build();
    +   *   SynthesizeSpeechResponse response = textToSpeechClient.synthesizeSpeech(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 SynthesizeSpeechResponse synthesizeSpeech(SynthesizeSpeechRequest request) { + return synthesizeSpeechCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Synthesizes speech synchronously: receive results after all text input has been processed. + * + *

    Sample code: + * + *

    
    +   * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    +   *   SynthesisInput input = SynthesisInput.newBuilder().build();
    +   *   VoiceSelectionParams voice = VoiceSelectionParams.newBuilder().build();
    +   *   AudioConfig audioConfig = AudioConfig.newBuilder().build();
    +   *   SynthesizeSpeechRequest request = SynthesizeSpeechRequest.newBuilder()
    +   *     .setInput(input)
    +   *     .setVoice(voice)
    +   *     .setAudioConfig(audioConfig)
    +   *     .build();
    +   *   ApiFuture<SynthesizeSpeechResponse> future = textToSpeechClient.synthesizeSpeechCallable().futureCall(request);
    +   *   // Do something
    +   *   SynthesizeSpeechResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + synthesizeSpeechCallable() { + return stub.synthesizeSpeechCallable(); + } + + @Override + public final void close() throws Exception { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechSettings.java b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechSettings.java new file mode 100644 index 000000000000..0263d198ef33 --- /dev/null +++ b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechSettings.java @@ -0,0 +1,185 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.texttospeech.v1beta1.stub.TextToSpeechStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link TextToSpeechClient}. + * + *

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

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

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

    + * 
    + * TextToSpeechSettings.Builder textToSpeechSettingsBuilder =
    + *     TextToSpeechSettings.newBuilder();
    + * textToSpeechSettingsBuilder.listVoicesSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * TextToSpeechSettings textToSpeechSettings = textToSpeechSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class TextToSpeechSettings extends ClientSettings { + /** Returns the object with the settings used for calls to listVoices. */ + public UnaryCallSettings listVoicesSettings() { + return ((TextToSpeechStubSettings) getStubSettings()).listVoicesSettings(); + } + + /** Returns the object with the settings used for calls to synthesizeSpeech. */ + public UnaryCallSettings + synthesizeSpeechSettings() { + return ((TextToSpeechStubSettings) getStubSettings()).synthesizeSpeechSettings(); + } + + public static final TextToSpeechSettings create(TextToSpeechStubSettings stub) + throws IOException { + return new TextToSpeechSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return TextToSpeechStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return TextToSpeechStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return TextToSpeechStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return TextToSpeechStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return TextToSpeechStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return TextToSpeechStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return TextToSpeechStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected TextToSpeechSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for TextToSpeechSettings. */ + public static class Builder extends ClientSettings.Builder { + protected Builder() throws IOException { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(TextToSpeechStubSettings.newBuilder(clientContext)); + } + + private static Builder createDefault() { + return new Builder(TextToSpeechStubSettings.newBuilder()); + } + + protected Builder(TextToSpeechSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(TextToSpeechStubSettings.Builder stubSettings) { + super(stubSettings); + } + + public TextToSpeechStubSettings.Builder getStubSettingsBuilder() { + return ((TextToSpeechStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to listVoices. */ + public UnaryCallSettings.Builder listVoicesSettings() { + return getStubSettingsBuilder().listVoicesSettings(); + } + + /** Returns the builder for the settings used for calls to synthesizeSpeech. */ + public UnaryCallSettings.Builder + synthesizeSpeechSettings() { + return getStubSettingsBuilder().synthesizeSpeechSettings(); + } + + @Override + public TextToSpeechSettings build() throws IOException { + return new TextToSpeechSettings(this); + } + } +} diff --git a/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/package-info.java b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/package-info.java new file mode 100644 index 000000000000..24ad803ca251 --- /dev/null +++ b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/package-info.java @@ -0,0 +1,37 @@ +/* + * Copyright 2018 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. + */ + +/** + * A client to Cloud Text-to-Speech API. + * + *

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

    ================== TextToSpeechClient ================== + * + *

    Service Description: Service that implements Google Cloud Text-to-Speech API. + * + *

    Sample for TextToSpeechClient: + * + *

    + * 
    + * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
    + *   String languageCode = "";
    + *   ListVoicesResponse response = textToSpeechClient.listVoices(languageCode);
    + * }
    + * 
    + * 
    + */ +package com.google.cloud.texttospeech.v1beta1; diff --git a/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/GrpcTextToSpeechCallableFactory.java b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/GrpcTextToSpeechCallableFactory.java new file mode 100644 index 000000000000..7dec478c4d3b --- /dev/null +++ b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/GrpcTextToSpeechCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Text-to-Speech API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcTextToSpeechCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/GrpcTextToSpeechStub.java b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/GrpcTextToSpeechStub.java new file mode 100644 index 000000000000..5dee1658c92f --- /dev/null +++ b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/GrpcTextToSpeechStub.java @@ -0,0 +1,167 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +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.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.texttospeech.v1beta1.ListVoicesRequest; +import com.google.cloud.texttospeech.v1beta1.ListVoicesResponse; +import com.google.cloud.texttospeech.v1beta1.SynthesizeSpeechRequest; +import com.google.cloud.texttospeech.v1beta1.SynthesizeSpeechResponse; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC stub implementation for Cloud Text-to-Speech API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class GrpcTextToSpeechStub extends TextToSpeechStub { + + private static final MethodDescriptor + listVoicesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.texttospeech.v1beta1.TextToSpeech/ListVoices") + .setRequestMarshaller(ProtoUtils.marshaller(ListVoicesRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListVoicesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + synthesizeSpeechMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.texttospeech.v1beta1.TextToSpeech/SynthesizeSpeech") + .setRequestMarshaller( + ProtoUtils.marshaller(SynthesizeSpeechRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(SynthesizeSpeechResponse.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + + private final UnaryCallable listVoicesCallable; + private final UnaryCallable + synthesizeSpeechCallable; + + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcTextToSpeechStub create(TextToSpeechStubSettings settings) + throws IOException { + return new GrpcTextToSpeechStub(settings, ClientContext.create(settings)); + } + + public static final GrpcTextToSpeechStub create(ClientContext clientContext) throws IOException { + return new GrpcTextToSpeechStub(TextToSpeechStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcTextToSpeechStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcTextToSpeechStub( + TextToSpeechStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcTextToSpeechStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcTextToSpeechStub(TextToSpeechStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcTextToSpeechCallableFactory()); + } + + /** + * Constructs an instance of GrpcTextToSpeechStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcTextToSpeechStub( + TextToSpeechStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + GrpcCallSettings listVoicesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listVoicesMethodDescriptor) + .build(); + GrpcCallSettings + synthesizeSpeechTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(synthesizeSpeechMethodDescriptor) + .build(); + + this.listVoicesCallable = + callableFactory.createUnaryCallable( + listVoicesTransportSettings, settings.listVoicesSettings(), clientContext); + this.synthesizeSpeechCallable = + callableFactory.createUnaryCallable( + synthesizeSpeechTransportSettings, settings.synthesizeSpeechSettings(), clientContext); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public UnaryCallable listVoicesCallable() { + return listVoicesCallable; + } + + public UnaryCallable + synthesizeSpeechCallable() { + return synthesizeSpeechCallable; + } + + @Override + public final void close() throws Exception { + shutdown(); + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/TextToSpeechStub.java b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/TextToSpeechStub.java new file mode 100644 index 000000000000..17107e7b459a --- /dev/null +++ b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/TextToSpeechStub.java @@ -0,0 +1,45 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.texttospeech.v1beta1.ListVoicesRequest; +import com.google.cloud.texttospeech.v1beta1.ListVoicesResponse; +import com.google.cloud.texttospeech.v1beta1.SynthesizeSpeechRequest; +import com.google.cloud.texttospeech.v1beta1.SynthesizeSpeechResponse; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Cloud Text-to-Speech API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public abstract class TextToSpeechStub implements BackgroundResource { + + public UnaryCallable listVoicesCallable() { + throw new UnsupportedOperationException("Not implemented: listVoicesCallable()"); + } + + public UnaryCallable + synthesizeSpeechCallable() { + throw new UnsupportedOperationException("Not implemented: synthesizeSpeechCallable()"); + } +} diff --git a/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/TextToSpeechStubSettings.java b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/TextToSpeechStubSettings.java new file mode 100644 index 000000000000..c4b6ccef6a9f --- /dev/null +++ b/google-cloud-texttospeech/src/main/java/com/google/cloud/texttospeech/v1beta1/stub/TextToSpeechStubSettings.java @@ -0,0 +1,293 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.texttospeech.v1beta1.ListVoicesRequest; +import com.google.cloud.texttospeech.v1beta1.ListVoicesResponse; +import com.google.cloud.texttospeech.v1beta1.SynthesizeSpeechRequest; +import com.google.cloud.texttospeech.v1beta1.SynthesizeSpeechResponse; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link TextToSpeechStub}. + * + *

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

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

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

    + * 
    + * TextToSpeechStubSettings.Builder textToSpeechSettingsBuilder =
    + *     TextToSpeechStubSettings.newBuilder();
    + * textToSpeechSettingsBuilder.listVoicesSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * TextToSpeechStubSettings textToSpeechSettings = textToSpeechSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class TextToSpeechStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + + private final UnaryCallSettings listVoicesSettings; + private final UnaryCallSettings + synthesizeSpeechSettings; + + /** Returns the object with the settings used for calls to listVoices. */ + public UnaryCallSettings listVoicesSettings() { + return listVoicesSettings; + } + + /** Returns the object with the settings used for calls to synthesizeSpeech. */ + public UnaryCallSettings + synthesizeSpeechSettings() { + return synthesizeSpeechSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public TextToSpeechStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcTextToSpeechStub.create(this); + } else { + throw new UnsupportedOperationException( + "Transport not supported: " + getTransportChannelProvider().getTransportName()); + } + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "texttospeech.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(TextToSpeechStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected TextToSpeechStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + listVoicesSettings = settingsBuilder.listVoicesSettings().build(); + synthesizeSpeechSettings = settingsBuilder.synthesizeSpeechSettings().build(); + } + + /** Builder for TextToSpeechStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder + listVoicesSettings; + private final UnaryCallSettings.Builder + synthesizeSpeechSettings; + + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "idempotent", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); + definitions.put("non_idempotent", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(20000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(20000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("default", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + listVoicesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + synthesizeSpeechSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + listVoicesSettings, synthesizeSpeechSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .listVoicesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .synthesizeSpeechSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + return builder; + } + + protected Builder(TextToSpeechStubSettings settings) { + super(settings); + + listVoicesSettings = settings.listVoicesSettings.toBuilder(); + synthesizeSpeechSettings = settings.synthesizeSpeechSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + listVoicesSettings, synthesizeSpeechSettings); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to listVoices. */ + public UnaryCallSettings.Builder listVoicesSettings() { + return listVoicesSettings; + } + + /** Returns the builder for the settings used for calls to synthesizeSpeech. */ + public UnaryCallSettings.Builder + synthesizeSpeechSettings() { + return synthesizeSpeechSettings; + } + + @Override + public TextToSpeechStubSettings build() throws IOException { + return new TextToSpeechStubSettings(this); + } + } +} diff --git a/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/MockTextToSpeech.java b/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/MockTextToSpeech.java new file mode 100644 index 000000000000..1c426479c799 --- /dev/null +++ b/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/MockTextToSpeech.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockTextToSpeech implements MockGrpcService { + private final MockTextToSpeechImpl serviceImpl; + + public MockTextToSpeech() { + serviceImpl = new MockTextToSpeechImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(GeneratedMessageV3 response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/MockTextToSpeechImpl.java b/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/MockTextToSpeechImpl.java new file mode 100644 index 000000000000..f58832d50098 --- /dev/null +++ b/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/MockTextToSpeechImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.cloud.texttospeech.v1beta1.TextToSpeechGrpc.TextToSpeechImplBase; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockTextToSpeechImpl extends TextToSpeechImplBase { + private ArrayList requests; + private Queue responses; + + public MockTextToSpeechImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(GeneratedMessageV3 response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void listVoices( + ListVoicesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListVoicesResponse) { + requests.add(request); + responseObserver.onNext((ListVoicesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void synthesizeSpeech( + SynthesizeSpeechRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof SynthesizeSpeechResponse) { + requests.add(request); + responseObserver.onNext((SynthesizeSpeechResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } +} diff --git a/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechClientTest.java b/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechClientTest.java new file mode 100644 index 000000000000..d60d6366567a --- /dev/null +++ b/google-cloud-texttospeech/src/test/java/com/google/cloud/texttospeech/v1beta1/TextToSpeechClientTest.java @@ -0,0 +1,159 @@ +/* + * Copyright 2018 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.cloud.texttospeech.v1beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +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.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.protobuf.ByteString; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class TextToSpeechClientTest { + private static MockTextToSpeech mockTextToSpeech; + private static MockServiceHelper serviceHelper; + private TextToSpeechClient client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockTextToSpeech = new MockTextToSpeech(); + serviceHelper = + new MockServiceHelper("in-process-1", Arrays.asList(mockTextToSpeech)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + channelProvider = serviceHelper.createChannelProvider(); + TextToSpeechSettings settings = + TextToSpeechSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = TextToSpeechClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void listVoicesTest() { + ListVoicesResponse expectedResponse = ListVoicesResponse.newBuilder().build(); + mockTextToSpeech.addResponse(expectedResponse); + + String languageCode = "languageCode-412800396"; + + ListVoicesResponse actualResponse = client.listVoices(languageCode); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTextToSpeech.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListVoicesRequest actualRequest = (ListVoicesRequest) actualRequests.get(0); + + Assert.assertEquals(languageCode, actualRequest.getLanguageCode()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void listVoicesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockTextToSpeech.addException(exception); + + try { + String languageCode = "languageCode-412800396"; + + client.listVoices(languageCode); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void synthesizeSpeechTest() { + ByteString audioContent = ByteString.copyFromUtf8("16"); + SynthesizeSpeechResponse expectedResponse = + SynthesizeSpeechResponse.newBuilder().setAudioContent(audioContent).build(); + mockTextToSpeech.addResponse(expectedResponse); + + SynthesisInput input = SynthesisInput.newBuilder().build(); + VoiceSelectionParams voice = VoiceSelectionParams.newBuilder().build(); + AudioConfig audioConfig = AudioConfig.newBuilder().build(); + + SynthesizeSpeechResponse actualResponse = client.synthesizeSpeech(input, voice, audioConfig); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTextToSpeech.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SynthesizeSpeechRequest actualRequest = (SynthesizeSpeechRequest) actualRequests.get(0); + + Assert.assertEquals(input, actualRequest.getInput()); + Assert.assertEquals(voice, actualRequest.getVoice()); + Assert.assertEquals(audioConfig, actualRequest.getAudioConfig()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void synthesizeSpeechExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockTextToSpeech.addException(exception); + + try { + SynthesisInput input = SynthesisInput.newBuilder().build(); + VoiceSelectionParams voice = VoiceSelectionParams.newBuilder().build(); + AudioConfig audioConfig = AudioConfig.newBuilder().build(); + + client.synthesizeSpeech(input, voice, audioConfig); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } +} diff --git a/google-cloud-trace/README.md b/google-cloud-trace/README.md index eaabc33cc6a4..95781e7f097e 100644 --- a/google-cloud-trace/README.md +++ b/google-cloud-trace/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-trace - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-trace:0.38.0-beta' +compile 'com.google.cloud:google-cloud-trace:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-trace" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-trace" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-trace/pom.xml b/google-cloud-trace/pom.xml index 0b1989206c3b..efb1a17e4d06 100644 --- a/google-cloud-trace/pom.xml +++ b/google-cloud-trace/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-trace - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Trace https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-trace @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-trace diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/TraceServiceSettings.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/TraceServiceSettings.java index 23b223063e45..c3c5b3e02232 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/TraceServiceSettings.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/TraceServiceSettings.java @@ -59,7 +59,7 @@ * * TraceServiceSettings.Builder traceServiceSettingsBuilder = * TraceServiceSettings.newBuilder(); - * traceServiceSettingsBuilder.patchTracesSettings().getRetrySettingsBuilder() + * traceServiceSettingsBuilder.patchTracesSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * TraceServiceSettings traceServiceSettings = traceServiceSettingsBuilder.build(); * diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/GrpcTraceServiceCallableFactory.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/GrpcTraceServiceCallableFactory.java new file mode 100644 index 000000000000..035b7362461a --- /dev/null +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/GrpcTraceServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.trace.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Trace API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcTraceServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/GrpcTraceServiceStub.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/GrpcTraceServiceStub.java index d61e84d7699c..7e5beb1862bf 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/GrpcTraceServiceStub.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/GrpcTraceServiceStub.java @@ -21,7 +21,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.devtools.cloudtrace.v1.GetTraceRequest; @@ -76,6 +76,8 @@ public class GrpcTraceServiceStub extends TraceServiceStub { private final UnaryCallable listTracesCallable; private final UnaryCallable listTracesPagedCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcTraceServiceStub create(TraceServiceStubSettings settings) throws IOException { return new GrpcTraceServiceStub(settings, ClientContext.create(settings)); @@ -85,6 +87,12 @@ public static final GrpcTraceServiceStub create(ClientContext clientContext) thr return new GrpcTraceServiceStub(TraceServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcTraceServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcTraceServiceStub( + TraceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcTraceServiceStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -92,6 +100,20 @@ public static final GrpcTraceServiceStub create(ClientContext clientContext) thr */ protected GrpcTraceServiceStub(TraceServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcTraceServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcTraceServiceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcTraceServiceStub( + TraceServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings patchTracesTransportSettings = GrpcCallSettings.newBuilder() @@ -107,16 +129,16 @@ protected GrpcTraceServiceStub(TraceServiceStubSettings settings, ClientContext .build(); this.patchTracesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( patchTracesTransportSettings, settings.patchTracesSettings(), clientContext); this.getTraceCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( getTraceTransportSettings, settings.getTraceSettings(), clientContext); this.listTracesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( listTracesTransportSettings, settings.listTracesSettings(), clientContext); this.listTracesPagedCallable = - GrpcCallableFactory.createPagedCallable( + callableFactory.createPagedCallable( listTracesTransportSettings, settings.listTracesSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/TraceServiceStubSettings.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/TraceServiceStubSettings.java index 21e2a70b271f..1e33c8bf3687 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/TraceServiceStubSettings.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/stub/TraceServiceStubSettings.java @@ -74,7 +74,7 @@ * * TraceServiceStubSettings.Builder traceServiceSettingsBuilder = * TraceServiceStubSettings.newBuilder(); - * traceServiceSettingsBuilder.patchTracesSettings().getRetrySettingsBuilder() + * traceServiceSettingsBuilder.patchTracesSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * TraceServiceStubSettings traceServiceSettings = traceServiceSettingsBuilder.build(); * diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/TraceServiceSettings.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/TraceServiceSettings.java index 9be90ca9432c..56f0d660d45b 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/TraceServiceSettings.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/TraceServiceSettings.java @@ -53,7 +53,7 @@ * * TraceServiceSettings.Builder traceServiceSettingsBuilder = * TraceServiceSettings.newBuilder(); - * traceServiceSettingsBuilder.batchWriteSpansSettings().getRetrySettingsBuilder() + * traceServiceSettingsBuilder.batchWriteSpansSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * TraceServiceSettings traceServiceSettings = traceServiceSettingsBuilder.build(); * diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/GrpcTraceServiceCallableFactory.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/GrpcTraceServiceCallableFactory.java new file mode 100644 index 000000000000..0cc4d05502a6 --- /dev/null +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/GrpcTraceServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.trace.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Stackdriver Trace API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcTraceServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/GrpcTraceServiceStub.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/GrpcTraceServiceStub.java index 537ad3ad316e..d746af77c67b 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/GrpcTraceServiceStub.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/GrpcTraceServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest; @@ -63,6 +63,8 @@ public class GrpcTraceServiceStub extends TraceServiceStub { private final UnaryCallable batchWriteSpansCallable; private final UnaryCallable createSpanCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcTraceServiceStub create(TraceServiceStubSettings settings) throws IOException { return new GrpcTraceServiceStub(settings, ClientContext.create(settings)); @@ -72,6 +74,12 @@ public static final GrpcTraceServiceStub create(ClientContext clientContext) thr return new GrpcTraceServiceStub(TraceServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcTraceServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcTraceServiceStub( + TraceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcTraceServiceStub, using the given settings. This is protected so * that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -79,6 +87,20 @@ public static final GrpcTraceServiceStub create(ClientContext clientContext) thr */ protected GrpcTraceServiceStub(TraceServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcTraceServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcTraceServiceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcTraceServiceStub( + TraceServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings batchWriteSpansTransportSettings = GrpcCallSettings.newBuilder() @@ -90,10 +112,10 @@ protected GrpcTraceServiceStub(TraceServiceStubSettings settings, ClientContext .build(); this.batchWriteSpansCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchWriteSpansTransportSettings, settings.batchWriteSpansSettings(), clientContext); this.createSpanCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( createSpanTransportSettings, settings.createSpanSettings(), clientContext); backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/TraceServiceStubSettings.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/TraceServiceStubSettings.java index 96781b9f742e..c58853d9799f 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/TraceServiceStubSettings.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/v2/stub/TraceServiceStubSettings.java @@ -62,7 +62,7 @@ * * TraceServiceStubSettings.Builder traceServiceSettingsBuilder = * TraceServiceStubSettings.newBuilder(); - * traceServiceSettingsBuilder.batchWriteSpansSettings().getRetrySettingsBuilder() + * traceServiceSettingsBuilder.batchWriteSpansSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * TraceServiceStubSettings traceServiceSettings = traceServiceSettingsBuilder.build(); * diff --git a/google-cloud-trace/src/test/java/com/google/cloud/trace/v1/TraceServiceSmokeTest.java b/google-cloud-trace/src/test/java/com/google/cloud/trace/v1/TraceServiceSmokeTest.java new file mode 100644 index 000000000000..89541924fbcf --- /dev/null +++ b/google-cloud-trace/src/test/java/com/google/cloud/trace/v1/TraceServiceSmokeTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2018 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.cloud.trace.v1; + +import static com.google.cloud.trace.v1.TraceServiceClient.ListTracesPagedResponse; + +import com.google.common.base.Preconditions; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class TraceServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (TraceServiceClient client = TraceServiceClient.create()) { + String projectId2 = projectId; + + ListTracesPagedResponse pagedResponse = client.listTraces(projectId2); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-trace/src/test/java/com/google/cloud/trace/v2/TraceServiceSmokeTest.java b/google-cloud-trace/src/test/java/com/google/cloud/trace/v2/TraceServiceSmokeTest.java new file mode 100644 index 000000000000..3c8a15ff5970 --- /dev/null +++ b/google-cloud-trace/src/test/java/com/google/cloud/trace/v2/TraceServiceSmokeTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2018 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.cloud.trace.v2; + +import com.google.common.base.Preconditions; +import com.google.devtools.cloudtrace.v2.ProjectName; +import com.google.devtools.cloudtrace.v2.Span; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class TraceServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(getProjectId()); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch(String projectId) throws Exception { + try (TraceServiceClient client = TraceServiceClient.create()) { + ProjectName name = ProjectName.of(projectId); + List spans = new ArrayList<>(); + + client.batchWriteSpans(name, spans); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-translate/README.md b/google-cloud-translate/README.md index 9b360db9d089..df2e3c4ab37a 100644 --- a/google-cloud-translate/README.md +++ b/google-cloud-translate/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-translate - 1.20.0 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-translate:1.20.0' +compile 'com.google.cloud:google-cloud-translate:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-translate" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-translate" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-translate/pom.xml b/google-cloud-translate/pom.xml index bba2ad1cee41..49def395ccc4 100644 --- a/google-cloud-translate/pom.xml +++ b/google-cloud-translate/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-translate - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Translation https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-translate @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-translate diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/TranslateOptions.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/TranslateOptions.java index 11e8b8cbcb56..a76da3d822b3 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/TranslateOptions.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/TranslateOptions.java @@ -155,30 +155,28 @@ private TranslateOptions(Builder builder) { apiKey = null; if (builder.apiKey != null) { logger.log( - Level.WARNING, "Ignoring API key: using explicit setting for credentials instead."); + Level.WARNING, + "Ignoring API key: using explicit setting for credentials instead."); } else if (getDefaultApiKey() != null) { logger.log( Level.WARNING, - String.format( - "Ignoring API key set in environment variable %s: using explicit setting for credentials instead.", - API_KEY_ENV_NAME)); + "Ignoring API key set in environment variable {0}: using explicit setting for credentials instead.", + API_KEY_ENV_NAME); } } else if (builder.apiKey != null) { credentials = null; apiKey = builder.apiKey; logger.log( Level.WARNING, - String.format( - "Ignoring Application Default Credentials: using explicit setting for API key instead.", - ServiceOptions.CREDENTIAL_ENV_NAME)); + "Ignoring Application Default Credentials {0}: using explicit setting for API key instead.", + ServiceOptions.CREDENTIAL_ENV_NAME); } else if (credentials != null) { // credentials assigned from ADC in superclass constructor apiKey = null; if (getDefaultApiKey() != null) { logger.log( Level.WARNING, - String.format( - "Ignoring API key set in environment variable %s: using Application Default Credentials instead.", - API_KEY_ENV_NAME)); + "Ignoring API key set in environment variable {0}: using Application Default Credentials instead.", + API_KEY_ENV_NAME); } } else { apiKey = getDefaultApiKey(); diff --git a/google-cloud-util/google-cloud-compat-checker/pom.xml b/google-cloud-util/google-cloud-compat-checker/pom.xml index f793e86fb0c8..f038d7343f39 100644 --- a/google-cloud-util/google-cloud-compat-checker/pom.xml +++ b/google-cloud-util/google-cloud-compat-checker/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-compat-checker - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud Java Compatibility Checker https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-util/google-cloud-compat-checker @@ -12,7 +12,7 @@ com.google.cloud google-cloud-util - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-compat-checker diff --git a/google-cloud-util/pom.xml b/google-cloud-util/pom.xml index 16dfae35fd15..faf0447f15ff 100644 --- a/google-cloud-util/pom.xml +++ b/google-cloud-util/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-util - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT pom Google Cloud Util https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-util @@ -13,7 +13,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-compat-checker diff --git a/google-cloud-video-intelligence/README.md b/google-cloud-video-intelligence/README.md index 9b65b5378c94..00c572a6c802 100644 --- a/google-cloud-video-intelligence/README.md +++ b/google-cloud-video-intelligence/README.md @@ -24,16 +24,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-video-intelligence - 0.38.0-beta + 0.43.0-beta ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-video-intelligence:0.38.0-beta' +compile 'com.google.cloud:google-cloud-video-intelligence:0.43.0-beta' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-video-intelligence" % "0.38.0-beta" +libraryDependencies += "com.google.cloud" % "google-cloud-video-intelligence" % "0.43.0-beta" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-video-intelligence/pom.xml b/google-cloud-video-intelligence/pom.xml index df9ab1bfc1f5..5f704c83bdc3 100644 --- a/google-cloud-video-intelligence/pom.xml +++ b/google-cloud-video-intelligence/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-video-intelligence - 0.38.1-beta-SNAPSHOT + 0.43.1-beta-SNAPSHOT jar Google Cloud Video Intelligence https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-video-intelligence @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-video-intelligence @@ -38,6 +38,10 @@ com.google.api.grpc proto-google-cloud-video-intelligence-v1 + + com.google.api.grpc + proto-google-cloud-video-intelligence-v1p1beta1 + io.grpc grpc-netty-shaded @@ -86,6 +90,11 @@ grpc-google-cloud-video-intelligence-v1 test + + com.google.api.grpc + grpc-google-cloud-video-intelligence-v1p1beta1 + test + com.google.api gax-grpc diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSettings.java index 38ca233d2815..ad9008306598 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSettings.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSettings.java @@ -53,7 +53,7 @@ * * VideoIntelligenceServiceSettings.Builder videoIntelligenceServiceSettingsBuilder = * VideoIntelligenceServiceSettings.newBuilder(); - * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettingsBuilder() + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * VideoIntelligenceServiceSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build(); * diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/GrpcVideoIntelligenceServiceCallableFactory.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/GrpcVideoIntelligenceServiceCallableFactory.java new file mode 100644 index 000000000000..77d13baba90f --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/GrpcVideoIntelligenceServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Video Intelligence API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcVideoIntelligenceServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/GrpcVideoIntelligenceServiceStub.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/GrpcVideoIntelligenceServiceStub.java index f2c4bd849371..93a91062b888 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/GrpcVideoIntelligenceServiceStub.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/GrpcVideoIntelligenceServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -63,6 +63,8 @@ public class GrpcVideoIntelligenceServiceStub extends VideoIntelligenceServiceSt AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> annotateVideoOperationCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcVideoIntelligenceServiceStub create( VideoIntelligenceServiceStubSettings settings) throws IOException { return new GrpcVideoIntelligenceServiceStub(settings, ClientContext.create(settings)); @@ -74,6 +76,12 @@ public static final GrpcVideoIntelligenceServiceStub create(ClientContext client VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcVideoIntelligenceServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -82,7 +90,21 @@ public static final GrpcVideoIntelligenceServiceStub create(ClientContext client protected GrpcVideoIntelligenceServiceStub( VideoIntelligenceServiceStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcVideoIntelligenceServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings annotateVideoTransportSettings = GrpcCallSettings.newBuilder() @@ -90,10 +112,10 @@ protected GrpcVideoIntelligenceServiceStub( .build(); this.annotateVideoCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( annotateVideoTransportSettings, settings.annotateVideoSettings(), clientContext); this.annotateVideoOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( annotateVideoTransportSettings, settings.annotateVideoOperationSettings(), clientContext, diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/VideoIntelligenceServiceStubSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/VideoIntelligenceServiceStubSettings.java index 4fcaecdebaf8..88b2f426bf36 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/VideoIntelligenceServiceStubSettings.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/stub/VideoIntelligenceServiceStubSettings.java @@ -68,7 +68,7 @@ * * VideoIntelligenceServiceStubSettings.Builder videoIntelligenceServiceSettingsBuilder = * VideoIntelligenceServiceStubSettings.newBuilder(); - * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettingsBuilder() + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * VideoIntelligenceServiceStubSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build(); * diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/VideoIntelligenceServiceSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/VideoIntelligenceServiceSettings.java index 938eb88273ba..dea9309efe19 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/VideoIntelligenceServiceSettings.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/VideoIntelligenceServiceSettings.java @@ -53,7 +53,7 @@ * * VideoIntelligenceServiceSettings.Builder videoIntelligenceServiceSettingsBuilder = * VideoIntelligenceServiceSettings.newBuilder(); - * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettingsBuilder() + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * VideoIntelligenceServiceSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build(); * diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/GrpcVideoIntelligenceServiceCallableFactory.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/GrpcVideoIntelligenceServiceCallableFactory.java new file mode 100644 index 000000000000..605ac0b1c30f --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/GrpcVideoIntelligenceServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Video Intelligence API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcVideoIntelligenceServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/GrpcVideoIntelligenceServiceStub.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/GrpcVideoIntelligenceServiceStub.java index 1329acdf7efd..b6ab8ec850ad 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/GrpcVideoIntelligenceServiceStub.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/GrpcVideoIntelligenceServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -63,6 +63,8 @@ public class GrpcVideoIntelligenceServiceStub extends VideoIntelligenceServiceSt AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> annotateVideoOperationCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcVideoIntelligenceServiceStub create( VideoIntelligenceServiceStubSettings settings) throws IOException { return new GrpcVideoIntelligenceServiceStub(settings, ClientContext.create(settings)); @@ -74,6 +76,12 @@ public static final GrpcVideoIntelligenceServiceStub create(ClientContext client VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcVideoIntelligenceServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -82,7 +90,21 @@ public static final GrpcVideoIntelligenceServiceStub create(ClientContext client protected GrpcVideoIntelligenceServiceStub( VideoIntelligenceServiceStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcVideoIntelligenceServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings annotateVideoTransportSettings = GrpcCallSettings.newBuilder() @@ -90,10 +112,10 @@ protected GrpcVideoIntelligenceServiceStub( .build(); this.annotateVideoCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( annotateVideoTransportSettings, settings.annotateVideoSettings(), clientContext); this.annotateVideoOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( annotateVideoTransportSettings, settings.annotateVideoOperationSettings(), clientContext, diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/VideoIntelligenceServiceStubSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/VideoIntelligenceServiceStubSettings.java index 6b14acce4df7..4da697fb1e53 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/VideoIntelligenceServiceStubSettings.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta1/stub/VideoIntelligenceServiceStubSettings.java @@ -68,7 +68,7 @@ * * VideoIntelligenceServiceStubSettings.Builder videoIntelligenceServiceSettingsBuilder = * VideoIntelligenceServiceStubSettings.newBuilder(); - * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettingsBuilder() + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * VideoIntelligenceServiceStubSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build(); * diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/VideoIntelligenceServiceSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/VideoIntelligenceServiceSettings.java index 91aa59f4a5e5..3cfb898fd5a2 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/VideoIntelligenceServiceSettings.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/VideoIntelligenceServiceSettings.java @@ -53,7 +53,7 @@ * * VideoIntelligenceServiceSettings.Builder videoIntelligenceServiceSettingsBuilder = * VideoIntelligenceServiceSettings.newBuilder(); - * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettingsBuilder() + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * VideoIntelligenceServiceSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build(); * diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/GrpcVideoIntelligenceServiceCallableFactory.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/GrpcVideoIntelligenceServiceCallableFactory.java new file mode 100644 index 000000000000..fecd81b0ac69 --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/GrpcVideoIntelligenceServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1beta2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Video Intelligence API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcVideoIntelligenceServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/GrpcVideoIntelligenceServiceStub.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/GrpcVideoIntelligenceServiceStub.java index ba2685392268..7fea64e1f0bd 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/GrpcVideoIntelligenceServiceStub.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/GrpcVideoIntelligenceServiceStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -63,6 +63,8 @@ public class GrpcVideoIntelligenceServiceStub extends VideoIntelligenceServiceSt AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> annotateVideoOperationCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcVideoIntelligenceServiceStub create( VideoIntelligenceServiceStubSettings settings) throws IOException { return new GrpcVideoIntelligenceServiceStub(settings, ClientContext.create(settings)); @@ -74,6 +76,12 @@ public static final GrpcVideoIntelligenceServiceStub create(ClientContext client VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext); } + public static final GrpcVideoIntelligenceServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is * protected so that it is easy to make a subclass, but otherwise, the static factory methods @@ -82,7 +90,21 @@ public static final GrpcVideoIntelligenceServiceStub create(ClientContext client protected GrpcVideoIntelligenceServiceStub( VideoIntelligenceServiceStubSettings settings, ClientContext clientContext) throws IOException { - this.operationsStub = GrpcOperationsStub.create(clientContext); + this(settings, clientContext, new GrpcVideoIntelligenceServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings annotateVideoTransportSettings = GrpcCallSettings.newBuilder() @@ -90,10 +112,10 @@ protected GrpcVideoIntelligenceServiceStub( .build(); this.annotateVideoCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( annotateVideoTransportSettings, settings.annotateVideoSettings(), clientContext); this.annotateVideoOperationCallable = - GrpcCallableFactory.createOperationCallable( + callableFactory.createOperationCallable( annotateVideoTransportSettings, settings.annotateVideoOperationSettings(), clientContext, diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/VideoIntelligenceServiceStubSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/VideoIntelligenceServiceStubSettings.java index 19d47c4c654c..2e37558e95a2 100644 --- a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/VideoIntelligenceServiceStubSettings.java +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1beta2/stub/VideoIntelligenceServiceStubSettings.java @@ -68,7 +68,7 @@ * * VideoIntelligenceServiceStubSettings.Builder videoIntelligenceServiceSettingsBuilder = * VideoIntelligenceServiceStubSettings.newBuilder(); - * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettingsBuilder() + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * VideoIntelligenceServiceStubSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build(); * diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceClient.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceClient.java new file mode 100644 index 000000000000..4ed72db6307d --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceClient.java @@ -0,0 +1,321 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.longrunning.OperationFuture; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.videointelligence.v1p1beta1.stub.VideoIntelligenceServiceStub; +import com.google.cloud.videointelligence.v1p1beta1.stub.VideoIntelligenceServiceStubSettings; +import com.google.longrunning.Operation; +import com.google.longrunning.OperationsClient; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: Service that implements Google Cloud Video Intelligence API. + * + *

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

    + * 
    + * try (VideoIntelligenceServiceClient videoIntelligenceServiceClient = VideoIntelligenceServiceClient.create()) {
    + *   String inputUri = "gs://demomaker/cat.mp4";
    + *   Feature featuresElement = Feature.LABEL_DETECTION;
    + *   List<Feature> features = Arrays.asList(featuresElement);
    + *   AnnotateVideoResponse response = videoIntelligenceServiceClient.annotateVideoAsync(inputUri, features).get();
    + * }
    + * 
    + * 
    + * + *

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

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

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

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

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

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

    To customize credentials: + * + *

    + * 
    + * VideoIntelligenceServiceSettings videoIntelligenceServiceSettings =
    + *     VideoIntelligenceServiceSettings.newBuilder()
    + *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
    + *         .build();
    + * VideoIntelligenceServiceClient videoIntelligenceServiceClient =
    + *     VideoIntelligenceServiceClient.create(videoIntelligenceServiceSettings);
    + * 
    + * 
    + * + * To customize the endpoint: + * + *
    + * 
    + * VideoIntelligenceServiceSettings videoIntelligenceServiceSettings =
    + *     VideoIntelligenceServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
    + * VideoIntelligenceServiceClient videoIntelligenceServiceClient =
    + *     VideoIntelligenceServiceClient.create(videoIntelligenceServiceSettings);
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class VideoIntelligenceServiceClient implements BackgroundResource { + private final VideoIntelligenceServiceSettings settings; + private final VideoIntelligenceServiceStub stub; + private final OperationsClient operationsClient; + + /** Constructs an instance of VideoIntelligenceServiceClient with default settings. */ + public static final VideoIntelligenceServiceClient create() throws IOException { + return create(VideoIntelligenceServiceSettings.newBuilder().build()); + } + + /** + * Constructs an instance of VideoIntelligenceServiceClient, using the given settings. The + * channels are created based on the settings passed in, or defaults for any settings that are not + * set. + */ + public static final VideoIntelligenceServiceClient create( + VideoIntelligenceServiceSettings settings) throws IOException { + return new VideoIntelligenceServiceClient(settings); + } + + /** + * Constructs an instance of VideoIntelligenceServiceClient, using the given stub for making + * calls. This is for advanced usage - prefer to use VideoIntelligenceServiceSettings}. + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final VideoIntelligenceServiceClient create(VideoIntelligenceServiceStub stub) { + return new VideoIntelligenceServiceClient(stub); + } + + /** + * Constructs an instance of VideoIntelligenceServiceClient, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected VideoIntelligenceServiceClient(VideoIntelligenceServiceSettings settings) + throws IOException { + this.settings = settings; + this.stub = ((VideoIntelligenceServiceStubSettings) settings.getStubSettings()).createStub(); + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected VideoIntelligenceServiceClient(VideoIntelligenceServiceStub stub) { + this.settings = null; + this.stub = stub; + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + public final VideoIntelligenceServiceSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public VideoIntelligenceServiceStub getStub() { + return stub; + } + + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getOperationsClient() { + return operationsClient; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Performs asynchronous video annotation. Progress and results can be retrieved through the + * `google.longrunning.Operations` interface. `Operation.metadata` contains + * `AnnotateVideoProgress` (progress). `Operation.response` contains `AnnotateVideoResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (VideoIntelligenceServiceClient videoIntelligenceServiceClient = VideoIntelligenceServiceClient.create()) {
    +   *   String inputUri = "gs://demomaker/cat.mp4";
    +   *   Feature featuresElement = Feature.LABEL_DETECTION;
    +   *   List<Feature> features = Arrays.asList(featuresElement);
    +   *   AnnotateVideoResponse response = videoIntelligenceServiceClient.annotateVideoAsync(inputUri, features).get();
    +   * }
    +   * 
    + * + * @param inputUri Input video location. Currently, only [Google Cloud + * Storage](https://cloud.google.com/storage/) URIs are supported, which must be specified in + * the following format: `gs://bucket-id/object-id` (other URI formats return + * [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more + * information, see [Request URIs](/storage/docs/reference-uris). A video URI may include + * wildcards in `object-id`, and thus identify multiple videos. Supported wildcards: '*' + * to match 0 or more characters; '?' to match 1 character. If unset, the input video should + * be embedded in the request as `input_content`. If set, `input_content` should be unset. + * @param features Requested video annotation features. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture annotateVideoAsync( + String inputUri, List features) { + + AnnotateVideoRequest request = + AnnotateVideoRequest.newBuilder().setInputUri(inputUri).addAllFeatures(features).build(); + return annotateVideoAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Performs asynchronous video annotation. Progress and results can be retrieved through the + * `google.longrunning.Operations` interface. `Operation.metadata` contains + * `AnnotateVideoProgress` (progress). `Operation.response` contains `AnnotateVideoResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (VideoIntelligenceServiceClient videoIntelligenceServiceClient = VideoIntelligenceServiceClient.create()) {
    +   *   String inputUri = "gs://demomaker/cat.mp4";
    +   *   Feature featuresElement = Feature.LABEL_DETECTION;
    +   *   List<Feature> features = Arrays.asList(featuresElement);
    +   *   AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
    +   *     .setInputUri(inputUri)
    +   *     .addAllFeatures(features)
    +   *     .build();
    +   *   AnnotateVideoResponse response = videoIntelligenceServiceClient.annotateVideoAsync(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 annotateVideoAsync( + AnnotateVideoRequest request) { + return annotateVideoOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Performs asynchronous video annotation. Progress and results can be retrieved through the + * `google.longrunning.Operations` interface. `Operation.metadata` contains + * `AnnotateVideoProgress` (progress). `Operation.response` contains `AnnotateVideoResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (VideoIntelligenceServiceClient videoIntelligenceServiceClient = VideoIntelligenceServiceClient.create()) {
    +   *   String inputUri = "gs://demomaker/cat.mp4";
    +   *   Feature featuresElement = Feature.LABEL_DETECTION;
    +   *   List<Feature> features = Arrays.asList(featuresElement);
    +   *   AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
    +   *     .setInputUri(inputUri)
    +   *     .addAllFeatures(features)
    +   *     .build();
    +   *   OperationFuture<Operation> future = videoIntelligenceServiceClient.annotateVideoOperationCallable().futureCall(request);
    +   *   // Do something
    +   *   AnnotateVideoResponse response = future.get();
    +   * }
    +   * 
    + */ + public final OperationCallable + annotateVideoOperationCallable() { + return stub.annotateVideoOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Performs asynchronous video annotation. Progress and results can be retrieved through the + * `google.longrunning.Operations` interface. `Operation.metadata` contains + * `AnnotateVideoProgress` (progress). `Operation.response` contains `AnnotateVideoResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (VideoIntelligenceServiceClient videoIntelligenceServiceClient = VideoIntelligenceServiceClient.create()) {
    +   *   String inputUri = "gs://demomaker/cat.mp4";
    +   *   Feature featuresElement = Feature.LABEL_DETECTION;
    +   *   List<Feature> features = Arrays.asList(featuresElement);
    +   *   AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
    +   *     .setInputUri(inputUri)
    +   *     .addAllFeatures(features)
    +   *     .build();
    +   *   ApiFuture<Operation> future = videoIntelligenceServiceClient.annotateVideoCallable().futureCall(request);
    +   *   // Do something
    +   *   Operation response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable annotateVideoCallable() { + return stub.annotateVideoCallable(); + } + + @Override + public final void close() throws Exception { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceSettings.java new file mode 100644 index 000000000000..525ad55d8814 --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceSettings.java @@ -0,0 +1,192 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.videointelligence.v1p1beta1.stub.VideoIntelligenceServiceStubSettings; +import com.google.longrunning.Operation; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link VideoIntelligenceServiceClient}. + * + *

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

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

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

    + * 
    + * VideoIntelligenceServiceSettings.Builder videoIntelligenceServiceSettingsBuilder =
    + *     VideoIntelligenceServiceSettings.newBuilder();
    + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * VideoIntelligenceServiceSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class VideoIntelligenceServiceSettings + extends ClientSettings { + /** Returns the object with the settings used for calls to annotateVideo. */ + public UnaryCallSettings annotateVideoSettings() { + return ((VideoIntelligenceServiceStubSettings) getStubSettings()).annotateVideoSettings(); + } + + /** Returns the object with the settings used for calls to annotateVideo. */ + public OperationCallSettings + annotateVideoOperationSettings() { + return ((VideoIntelligenceServiceStubSettings) getStubSettings()) + .annotateVideoOperationSettings(); + } + + public static final VideoIntelligenceServiceSettings create( + VideoIntelligenceServiceStubSettings stub) throws IOException { + return new VideoIntelligenceServiceSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return VideoIntelligenceServiceStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return VideoIntelligenceServiceStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return VideoIntelligenceServiceStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return VideoIntelligenceServiceStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return VideoIntelligenceServiceStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return VideoIntelligenceServiceStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return VideoIntelligenceServiceStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected VideoIntelligenceServiceSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for VideoIntelligenceServiceSettings. */ + public static class Builder + extends ClientSettings.Builder { + protected Builder() throws IOException { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(VideoIntelligenceServiceStubSettings.newBuilder(clientContext)); + } + + private static Builder createDefault() { + return new Builder(VideoIntelligenceServiceStubSettings.newBuilder()); + } + + protected Builder(VideoIntelligenceServiceSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(VideoIntelligenceServiceStubSettings.Builder stubSettings) { + super(stubSettings); + } + + public VideoIntelligenceServiceStubSettings.Builder getStubSettingsBuilder() { + return ((VideoIntelligenceServiceStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to annotateVideo. */ + public UnaryCallSettings.Builder annotateVideoSettings() { + return getStubSettingsBuilder().annotateVideoSettings(); + } + + /** Returns the builder for the settings used for calls to annotateVideo. */ + public OperationCallSettings.Builder< + AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> + annotateVideoOperationSettings() { + return getStubSettingsBuilder().annotateVideoOperationSettings(); + } + + @Override + public VideoIntelligenceServiceSettings build() throws IOException { + return new VideoIntelligenceServiceSettings(this); + } + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/package-info.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/package-info.java new file mode 100644 index 000000000000..c0778efbf06a --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/package-info.java @@ -0,0 +1,39 @@ +/* + * Copyright 2018 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. + */ + +/** + * A client to Cloud Video Intelligence API. + * + *

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

    ============================== VideoIntelligenceServiceClient ============================== + * + *

    Service Description: Service that implements Google Cloud Video Intelligence API. + * + *

    Sample for VideoIntelligenceServiceClient: + * + *

    + * 
    + * try (VideoIntelligenceServiceClient videoIntelligenceServiceClient = VideoIntelligenceServiceClient.create()) {
    + *   String inputUri = "gs://demomaker/cat.mp4";
    + *   Feature featuresElement = Feature.LABEL_DETECTION;
    + *   List<Feature> features = Arrays.asList(featuresElement);
    + *   AnnotateVideoResponse response = videoIntelligenceServiceClient.annotateVideoAsync(inputUri, features);
    + * }
    + * 
    + * 
    + */ +package com.google.cloud.videointelligence.v1p1beta1; diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/GrpcVideoIntelligenceServiceCallableFactory.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/GrpcVideoIntelligenceServiceCallableFactory.java new file mode 100644 index 000000000000..7ab8dfd3c0d7 --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/GrpcVideoIntelligenceServiceCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Cloud Video Intelligence API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcVideoIntelligenceServiceCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/GrpcVideoIntelligenceServiceStub.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/GrpcVideoIntelligenceServiceStub.java new file mode 100644 index 000000000000..941b56af8e79 --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/GrpcVideoIntelligenceServiceStub.java @@ -0,0 +1,169 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +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.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoProgress; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoRequest; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoResponse; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.GrpcOperationsStub; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC stub implementation for Cloud Video Intelligence API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class GrpcVideoIntelligenceServiceStub extends VideoIntelligenceServiceStub { + + private static final MethodDescriptor + annotateVideoMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + "google.cloud.videointelligence.v1p1beta1.VideoIntelligenceService/AnnotateVideo") + .setRequestMarshaller( + ProtoUtils.marshaller(AnnotateVideoRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + + private final UnaryCallable annotateVideoCallable; + private final OperationCallable< + AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> + annotateVideoOperationCallable; + + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcVideoIntelligenceServiceStub create( + VideoIntelligenceServiceStubSettings settings) throws IOException { + return new GrpcVideoIntelligenceServiceStub(settings, ClientContext.create(settings)); + } + + public static final GrpcVideoIntelligenceServiceStub create(ClientContext clientContext) + throws IOException { + return new GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcVideoIntelligenceServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcVideoIntelligenceServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcVideoIntelligenceServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected GrpcVideoIntelligenceServiceStub( + VideoIntelligenceServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings annotateVideoTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(annotateVideoMethodDescriptor) + .build(); + + this.annotateVideoCallable = + callableFactory.createUnaryCallable( + annotateVideoTransportSettings, settings.annotateVideoSettings(), clientContext); + this.annotateVideoOperationCallable = + callableFactory.createOperationCallable( + annotateVideoTransportSettings, + settings.annotateVideoOperationSettings(), + clientContext, + this.operationsStub); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + public OperationCallable + annotateVideoOperationCallable() { + return annotateVideoOperationCallable; + } + + public UnaryCallable annotateVideoCallable() { + return annotateVideoCallable; + } + + @Override + public final void close() throws Exception { + shutdown(); + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/VideoIntelligenceServiceStub.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/VideoIntelligenceServiceStub.java new file mode 100644 index 000000000000..0e86413ad8f4 --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/VideoIntelligenceServiceStub.java @@ -0,0 +1,51 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1.stub; + +import com.google.api.core.BetaApi; +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.videointelligence.v1p1beta1.AnnotateVideoProgress; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoRequest; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoResponse; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Cloud Video Intelligence API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public abstract class VideoIntelligenceServiceStub implements BackgroundResource { + + public OperationsStub getOperationsStub() { + throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + } + + public OperationCallable + annotateVideoOperationCallable() { + throw new UnsupportedOperationException("Not implemented: annotateVideoOperationCallable()"); + } + + public UnaryCallable annotateVideoCallable() { + throw new UnsupportedOperationException("Not implemented: annotateVideoCallable()"); + } +} diff --git a/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/VideoIntelligenceServiceStubSettings.java b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/VideoIntelligenceServiceStubSettings.java new file mode 100644 index 000000000000..fc1f951a9aec --- /dev/null +++ b/google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1p1beta1/stub/VideoIntelligenceServiceStubSettings.java @@ -0,0 +1,318 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoProgress; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoRequest; +import com.google.cloud.videointelligence.v1p1beta1.AnnotateVideoResponse; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link VideoIntelligenceServiceStub}. + * + *

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

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

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

    + * 
    + * VideoIntelligenceServiceStubSettings.Builder videoIntelligenceServiceSettingsBuilder =
    + *     VideoIntelligenceServiceStubSettings.newBuilder();
    + * videoIntelligenceServiceSettingsBuilder.annotateVideoSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * VideoIntelligenceServiceStubSettings videoIntelligenceServiceSettings = videoIntelligenceServiceSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class VideoIntelligenceServiceStubSettings + extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + + private final UnaryCallSettings annotateVideoSettings; + private final OperationCallSettings< + AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> + annotateVideoOperationSettings; + + /** Returns the object with the settings used for calls to annotateVideo. */ + public UnaryCallSettings annotateVideoSettings() { + return annotateVideoSettings; + } + + /** Returns the object with the settings used for calls to annotateVideo. */ + public OperationCallSettings + annotateVideoOperationSettings() { + return annotateVideoOperationSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public VideoIntelligenceServiceStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcVideoIntelligenceServiceStub.create(this); + } else { + throw new UnsupportedOperationException( + "Transport not supported: " + getTransportChannelProvider().getTransportName()); + } + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "videointelligence.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(VideoIntelligenceServiceStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected VideoIntelligenceServiceStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + annotateVideoSettings = settingsBuilder.annotateVideoSettings().build(); + annotateVideoOperationSettings = settingsBuilder.annotateVideoOperationSettings().build(); + } + + /** Builder for VideoIntelligenceServiceStubSettings. */ + public static class Builder + extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder annotateVideoSettings; + private final OperationCallSettings.Builder< + AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> + annotateVideoOperationSettings; + + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "idempotent", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); + definitions.put("non_idempotent", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(1000L)) + .setRetryDelayMultiplier(2.5) + .setMaxRetryDelay(Duration.ofMillis(120000L)) + .setInitialRpcTimeout(Duration.ofMillis(120000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(120000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("default", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + annotateVideoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + annotateVideoOperationSettings = OperationCallSettings.newBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of(annotateVideoSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .annotateVideoSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + builder + .annotateVideoOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(AnnotateVideoResponse.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(AnnotateVideoProgress.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(20000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(86400000L)) + .build())); + + return builder; + } + + protected Builder(VideoIntelligenceServiceStubSettings settings) { + super(settings); + + annotateVideoSettings = settings.annotateVideoSettings.toBuilder(); + annotateVideoOperationSettings = settings.annotateVideoOperationSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of(annotateVideoSettings); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to annotateVideo. */ + public UnaryCallSettings.Builder annotateVideoSettings() { + return annotateVideoSettings; + } + + /** Returns the builder for the settings used for calls to annotateVideo. */ + public OperationCallSettings.Builder< + AnnotateVideoRequest, AnnotateVideoResponse, AnnotateVideoProgress> + annotateVideoOperationSettings() { + return annotateVideoOperationSettings; + } + + @Override + public VideoIntelligenceServiceStubSettings build() throws IOException { + return new VideoIntelligenceServiceStubSettings(this); + } + } +} diff --git a/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSmokeTest.java b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSmokeTest.java new file mode 100644 index 000000000000..ac52723a15c1 --- /dev/null +++ b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSmokeTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class VideoIntelligenceServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) { + String inputUri = "gs://demomaker/cat.mp4"; + Feature featuresElement = Feature.LABEL_DETECTION; + List features = Arrays.asList(featuresElement); + + AnnotateVideoResponse response = client.annotateVideoAsync(inputUri, features).get(); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/MockVideoIntelligenceService.java b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/MockVideoIntelligenceService.java new file mode 100644 index 000000000000..ad7eb61ca408 --- /dev/null +++ b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/MockVideoIntelligenceService.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockVideoIntelligenceService implements MockGrpcService { + private final MockVideoIntelligenceServiceImpl serviceImpl; + + public MockVideoIntelligenceService() { + serviceImpl = new MockVideoIntelligenceServiceImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(GeneratedMessageV3 response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/MockVideoIntelligenceServiceImpl.java b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/MockVideoIntelligenceServiceImpl.java new file mode 100644 index 000000000000..25f2f6c3cdac --- /dev/null +++ b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/MockVideoIntelligenceServiceImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1; + +import com.google.api.core.BetaApi; +import com.google.cloud.videointelligence.v1p1beta1.VideoIntelligenceServiceGrpc.VideoIntelligenceServiceImplBase; +import com.google.longrunning.Operation; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockVideoIntelligenceServiceImpl extends VideoIntelligenceServiceImplBase { + private ArrayList requests; + private Queue responses; + + public MockVideoIntelligenceServiceImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(GeneratedMessageV3 response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void annotateVideo( + AnnotateVideoRequest 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("Unrecognized response type")); + } + } +} diff --git a/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceClientTest.java b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceClientTest.java new file mode 100644 index 000000000000..e0e7381b8def --- /dev/null +++ b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceClientTest.java @@ -0,0 +1,130 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +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.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class VideoIntelligenceServiceClientTest { + private static MockVideoIntelligenceService mockVideoIntelligenceService; + private static MockServiceHelper serviceHelper; + private VideoIntelligenceServiceClient client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockVideoIntelligenceService = new MockVideoIntelligenceService(); + serviceHelper = + new MockServiceHelper( + "in-process-1", Arrays.asList(mockVideoIntelligenceService)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + channelProvider = serviceHelper.createChannelProvider(); + VideoIntelligenceServiceSettings settings = + VideoIntelligenceServiceSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = VideoIntelligenceServiceClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void annotateVideoTest() throws Exception { + AnnotateVideoResponse expectedResponse = AnnotateVideoResponse.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("annotateVideoTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockVideoIntelligenceService.addResponse(resultOperation); + + String inputUri = "gs://demomaker/cat.mp4"; + Feature featuresElement = Feature.LABEL_DETECTION; + List features = Arrays.asList(featuresElement); + + AnnotateVideoResponse actualResponse = client.annotateVideoAsync(inputUri, features).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockVideoIntelligenceService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnnotateVideoRequest actualRequest = (AnnotateVideoRequest) actualRequests.get(0); + + Assert.assertEquals(inputUri, actualRequest.getInputUri()); + Assert.assertEquals(features, actualRequest.getFeaturesList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void annotateVideoExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockVideoIntelligenceService.addException(exception); + + try { + String inputUri = "gs://demomaker/cat.mp4"; + Feature featuresElement = Feature.LABEL_DETECTION; + List features = Arrays.asList(featuresElement); + + client.annotateVideoAsync(inputUri, features).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/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceSmokeTest.java b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceSmokeTest.java new file mode 100644 index 000000000000..888223d885ba --- /dev/null +++ b/google-cloud-video-intelligence/src/test/java/com/google/cloud/videointelligence/v1p1beta1/VideoIntelligenceServiceSmokeTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2018 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.cloud.videointelligence.v1p1beta1; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class VideoIntelligenceServiceSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) { + String inputUri = "gs://demomaker/cat.mp4"; + Feature featuresElement = Feature.LABEL_DETECTION; + List features = Arrays.asList(featuresElement); + + AnnotateVideoResponse response = client.annotateVideoAsync(inputUri, features).get(); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-vision/README.md b/google-cloud-vision/README.md index ac6b871e70df..27fead38f0f7 100644 --- a/google-cloud-vision/README.md +++ b/google-cloud-vision/README.md @@ -21,16 +21,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-vision - 1.20.0 + 1.25.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-vision:1.20.0' +compile 'com.google.cloud:google-cloud-vision:1.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-vision" % "1.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-vision" % "1.25.0" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud-vision/pom.xml b/google-cloud-vision/pom.xml index 9f5372b3d1e3..2826f422e366 100644 --- a/google-cloud-vision/pom.xml +++ b/google-cloud-vision/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-vision - 1.20.1-SNAPSHOT + 1.25.1-SNAPSHOT jar Google Cloud Vision https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-vision @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT google-cloud-vision @@ -34,6 +34,10 @@ com.google.api.grpc proto-google-cloud-vision-v1p1beta1 + + com.google.api.grpc + proto-google-cloud-vision-v1p2beta1 + io.grpc grpc-netty-shaded @@ -77,6 +81,11 @@ grpc-google-cloud-vision-v1p1beta1 test + + com.google.api.grpc + grpc-google-cloud-vision-v1p2beta1 + test + com.google.api gax-grpc diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/ImageAnnotatorSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/ImageAnnotatorSettings.java index cb0778b9ef83..40f8fd501a3a 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/ImageAnnotatorSettings.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/ImageAnnotatorSettings.java @@ -50,7 +50,7 @@ * * ImageAnnotatorSettings.Builder imageAnnotatorSettingsBuilder = * ImageAnnotatorSettings.newBuilder(); - * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettingsBuilder() + * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ImageAnnotatorSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build(); * diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/GrpcImageAnnotatorCallableFactory.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/GrpcImageAnnotatorCallableFactory.java new file mode 100644 index 000000000000..e29b73f3b552 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/GrpcImageAnnotatorCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.vision.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Vision API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcImageAnnotatorCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/GrpcImageAnnotatorStub.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/GrpcImageAnnotatorStub.java index aab1133c2c69..9e464d77f9cd 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/GrpcImageAnnotatorStub.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/GrpcImageAnnotatorStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.vision.v1.BatchAnnotateImagesRequest; @@ -56,6 +56,8 @@ public class GrpcImageAnnotatorStub extends ImageAnnotatorStub { private final UnaryCallable batchAnnotateImagesCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcImageAnnotatorStub create(ImageAnnotatorStubSettings settings) throws IOException { return new GrpcImageAnnotatorStub(settings, ClientContext.create(settings)); @@ -67,6 +69,12 @@ public static final GrpcImageAnnotatorStub create(ClientContext clientContext) ImageAnnotatorStubSettings.newBuilder().build(), clientContext); } + public static final GrpcImageAnnotatorStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -74,6 +82,20 @@ public static final GrpcImageAnnotatorStub create(ClientContext clientContext) */ protected GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcImageAnnotatorCallableFactory()); + } + + /** + * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings batchAnnotateImagesTransportSettings = @@ -82,7 +104,7 @@ protected GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientCont .build(); this.batchAnnotateImagesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchAnnotateImagesTransportSettings, settings.batchAnnotateImagesSettings(), clientContext); diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/ImageAnnotatorStubSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/ImageAnnotatorStubSettings.java index 514bff4839a1..56cb49c63867 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/ImageAnnotatorStubSettings.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/stub/ImageAnnotatorStubSettings.java @@ -61,7 +61,7 @@ * * ImageAnnotatorStubSettings.Builder imageAnnotatorSettingsBuilder = * ImageAnnotatorStubSettings.newBuilder(); - * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettingsBuilder() + * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ImageAnnotatorStubSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build(); * diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/ImageAnnotatorSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/ImageAnnotatorSettings.java index 4be1c226bbdf..cf57682cb3b1 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/ImageAnnotatorSettings.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/ImageAnnotatorSettings.java @@ -50,7 +50,7 @@ * * ImageAnnotatorSettings.Builder imageAnnotatorSettingsBuilder = * ImageAnnotatorSettings.newBuilder(); - * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettingsBuilder() + * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ImageAnnotatorSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build(); * diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/GrpcImageAnnotatorCallableFactory.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/GrpcImageAnnotatorCallableFactory.java new file mode 100644 index 000000000000..a84550f745e2 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/GrpcImageAnnotatorCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.vision.v1p1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Vision API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcImageAnnotatorCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/GrpcImageAnnotatorStub.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/GrpcImageAnnotatorStub.java index fabfaf2e507b..7951d9f1b995 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/GrpcImageAnnotatorStub.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/GrpcImageAnnotatorStub.java @@ -19,7 +19,7 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; -import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.vision.v1p1beta1.BatchAnnotateImagesRequest; @@ -56,6 +56,8 @@ public class GrpcImageAnnotatorStub extends ImageAnnotatorStub { private final UnaryCallable batchAnnotateImagesCallable; + private final GrpcStubCallableFactory callableFactory; + public static final GrpcImageAnnotatorStub create(ImageAnnotatorStubSettings settings) throws IOException { return new GrpcImageAnnotatorStub(settings, ClientContext.create(settings)); @@ -67,6 +69,12 @@ public static final GrpcImageAnnotatorStub create(ClientContext clientContext) ImageAnnotatorStubSettings.newBuilder().build(), clientContext); } + public static final GrpcImageAnnotatorStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings.newBuilder().build(), clientContext, callableFactory); + } + /** * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected * so that it is easy to make a subclass, but otherwise, the static factory methods should be @@ -74,6 +82,20 @@ public static final GrpcImageAnnotatorStub create(ClientContext clientContext) */ protected GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcImageAnnotatorCallableFactory()); + } + + /** + * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; GrpcCallSettings batchAnnotateImagesTransportSettings = @@ -82,7 +104,7 @@ protected GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientCont .build(); this.batchAnnotateImagesCallable = - GrpcCallableFactory.createUnaryCallable( + callableFactory.createUnaryCallable( batchAnnotateImagesTransportSettings, settings.batchAnnotateImagesSettings(), clientContext); diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/ImageAnnotatorStubSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/ImageAnnotatorStubSettings.java index 1dc83f58cb15..2c8db1bd7476 100644 --- a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/ImageAnnotatorStubSettings.java +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p1beta1/stub/ImageAnnotatorStubSettings.java @@ -61,7 +61,7 @@ * * ImageAnnotatorStubSettings.Builder imageAnnotatorSettingsBuilder = * ImageAnnotatorStubSettings.newBuilder(); - * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettingsBuilder() + * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettings().toBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * ImageAnnotatorStubSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build(); * diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClient.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClient.java new file mode 100644 index 000000000000..0ccf242c109f --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClient.java @@ -0,0 +1,375 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.longrunning.OperationFuture; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.vision.v1p2beta1.stub.ImageAnnotatorStub; +import com.google.cloud.vision.v1p2beta1.stub.ImageAnnotatorStubSettings; +import com.google.longrunning.Operation; +import com.google.longrunning.OperationsClient; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: Service that performs Google Cloud Vision API detection tasks over client + * images, such as face, landmark, logo, label, and text detection. The ImageAnnotator service + * returns detected entities from the images. + * + *

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

    + * 
    + * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    + *   List<AnnotateImageRequest> requests = new ArrayList<>();
    + *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
    + * }
    + * 
    + * 
    + * + *

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

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

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

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

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

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

    To customize credentials: + * + *

    + * 
    + * ImageAnnotatorSettings imageAnnotatorSettings =
    + *     ImageAnnotatorSettings.newBuilder()
    + *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
    + *         .build();
    + * ImageAnnotatorClient imageAnnotatorClient =
    + *     ImageAnnotatorClient.create(imageAnnotatorSettings);
    + * 
    + * 
    + * + * To customize the endpoint: + * + *
    + * 
    + * ImageAnnotatorSettings imageAnnotatorSettings =
    + *     ImageAnnotatorSettings.newBuilder().setEndpoint(myEndpoint).build();
    + * ImageAnnotatorClient imageAnnotatorClient =
    + *     ImageAnnotatorClient.create(imageAnnotatorSettings);
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +public class ImageAnnotatorClient implements BackgroundResource { + private final ImageAnnotatorSettings settings; + private final ImageAnnotatorStub stub; + private final OperationsClient operationsClient; + + /** Constructs an instance of ImageAnnotatorClient with default settings. */ + public static final ImageAnnotatorClient create() throws IOException { + return create(ImageAnnotatorSettings.newBuilder().build()); + } + + /** + * Constructs an instance of ImageAnnotatorClient, using the given settings. The channels are + * created based on the settings passed in, or defaults for any settings that are not set. + */ + public static final ImageAnnotatorClient create(ImageAnnotatorSettings settings) + throws IOException { + return new ImageAnnotatorClient(settings); + } + + /** + * Constructs an instance of ImageAnnotatorClient, using the given stub for making calls. This is + * for advanced usage - prefer to use ImageAnnotatorSettings}. + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final ImageAnnotatorClient create(ImageAnnotatorStub stub) { + return new ImageAnnotatorClient(stub); + } + + /** + * Constructs an instance of ImageAnnotatorClient, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected ImageAnnotatorClient(ImageAnnotatorSettings settings) throws IOException { + this.settings = settings; + this.stub = ((ImageAnnotatorStubSettings) settings.getStubSettings()).createStub(); + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected ImageAnnotatorClient(ImageAnnotatorStub stub) { + this.settings = null; + this.stub = stub; + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + public final ImageAnnotatorSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public ImageAnnotatorStub getStub() { + return stub; + } + + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getOperationsClient() { + return operationsClient; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run image detection and annotation for a batch of images. + * + *

    Sample code: + * + *

    
    +   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    +   *   List<AnnotateImageRequest> requests = new ArrayList<>();
    +   *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
    +   * }
    +   * 
    + * + * @param requests Individual image annotation requests for this batch. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BatchAnnotateImagesResponse batchAnnotateImages( + List requests) { + + BatchAnnotateImagesRequest request = + BatchAnnotateImagesRequest.newBuilder().addAllRequests(requests).build(); + return batchAnnotateImages(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run image detection and annotation for a batch of images. + * + *

    Sample code: + * + *

    
    +   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    +   *   List<AnnotateImageRequest> requests = new ArrayList<>();
    +   *   BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder()
    +   *     .addAllRequests(requests)
    +   *     .build();
    +   *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(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 + */ + private final BatchAnnotateImagesResponse batchAnnotateImages( + BatchAnnotateImagesRequest request) { + return batchAnnotateImagesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run image detection and annotation for a batch of images. + * + *

    Sample code: + * + *

    
    +   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    +   *   List<AnnotateImageRequest> requests = new ArrayList<>();
    +   *   BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder()
    +   *     .addAllRequests(requests)
    +   *     .build();
    +   *   ApiFuture<BatchAnnotateImagesResponse> future = imageAnnotatorClient.batchAnnotateImagesCallable().futureCall(request);
    +   *   // Do something
    +   *   BatchAnnotateImagesResponse response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + batchAnnotateImagesCallable() { + return stub.batchAnnotateImagesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    +   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
    +   *   AsyncBatchAnnotateFilesResponse response = imageAnnotatorClient.asyncBatchAnnotateFilesAsync(requests).get();
    +   * }
    +   * 
    + * + * @param requests Individual async file annotation requests for this batch. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture + asyncBatchAnnotateFilesAsync(List requests) { + + AsyncBatchAnnotateFilesRequest request = + AsyncBatchAnnotateFilesRequest.newBuilder().addAllRequests(requests).build(); + return asyncBatchAnnotateFilesAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    +   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
    +   *   AsyncBatchAnnotateFilesRequest request = AsyncBatchAnnotateFilesRequest.newBuilder()
    +   *     .addAllRequests(requests)
    +   *     .build();
    +   *   AsyncBatchAnnotateFilesResponse response = imageAnnotatorClient.asyncBatchAnnotateFilesAsync(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 + */ + private final OperationFuture + asyncBatchAnnotateFilesAsync(AsyncBatchAnnotateFilesRequest request) { + return asyncBatchAnnotateFilesOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    +   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
    +   *   AsyncBatchAnnotateFilesRequest request = AsyncBatchAnnotateFilesRequest.newBuilder()
    +   *     .addAllRequests(requests)
    +   *     .build();
    +   *   OperationFuture<Operation> future = imageAnnotatorClient.asyncBatchAnnotateFilesOperationCallable().futureCall(request);
    +   *   // Do something
    +   *   AsyncBatchAnnotateFilesResponse response = future.get();
    +   * }
    +   * 
    + */ + public final OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable() { + return stub.asyncBatchAnnotateFilesOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

    Sample code: + * + *

    
    +   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    +   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
    +   *   AsyncBatchAnnotateFilesRequest request = AsyncBatchAnnotateFilesRequest.newBuilder()
    +   *     .addAllRequests(requests)
    +   *     .build();
    +   *   ApiFuture<Operation> future = imageAnnotatorClient.asyncBatchAnnotateFilesCallable().futureCall(request);
    +   *   // Do something
    +   *   Operation response = future.get();
    +   * }
    +   * 
    + */ + public final UnaryCallable + asyncBatchAnnotateFilesCallable() { + return stub.asyncBatchAnnotateFilesCallable(); + } + + @Override + public final void close() throws Exception { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSettings.java new file mode 100644 index 000000000000..3e5b601c6147 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSettings.java @@ -0,0 +1,203 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.vision.v1p2beta1.stub.ImageAnnotatorStubSettings; +import com.google.longrunning.Operation; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link ImageAnnotatorClient}. + * + *

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

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

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

    + * 
    + * ImageAnnotatorSettings.Builder imageAnnotatorSettingsBuilder =
    + *     ImageAnnotatorSettings.newBuilder();
    + * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * ImageAnnotatorSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +public class ImageAnnotatorSettings extends ClientSettings { + /** Returns the object with the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings + batchAnnotateImagesSettings() { + return ((ImageAnnotatorStubSettings) getStubSettings()).batchAnnotateImagesSettings(); + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings + asyncBatchAnnotateFilesSettings() { + return ((ImageAnnotatorStubSettings) getStubSettings()).asyncBatchAnnotateFilesSettings(); + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return ((ImageAnnotatorStubSettings) getStubSettings()) + .asyncBatchAnnotateFilesOperationSettings(); + } + + public static final ImageAnnotatorSettings create(ImageAnnotatorStubSettings stub) + throws IOException { + return new ImageAnnotatorSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return ImageAnnotatorStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return ImageAnnotatorStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return ImageAnnotatorStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return ImageAnnotatorStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return ImageAnnotatorStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return ImageAnnotatorStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ImageAnnotatorStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected ImageAnnotatorSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for ImageAnnotatorSettings. */ + public static class Builder extends ClientSettings.Builder { + protected Builder() throws IOException { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(ImageAnnotatorStubSettings.newBuilder(clientContext)); + } + + private static Builder createDefault() { + return new Builder(ImageAnnotatorStubSettings.newBuilder()); + } + + protected Builder(ImageAnnotatorSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(ImageAnnotatorStubSettings.Builder stubSettings) { + super(stubSettings); + } + + public ImageAnnotatorStubSettings.Builder getStubSettingsBuilder() { + return ((ImageAnnotatorStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings.Builder + batchAnnotateImagesSettings() { + return getStubSettingsBuilder().batchAnnotateImagesSettings(); + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings.Builder + asyncBatchAnnotateFilesSettings() { + return getStubSettingsBuilder().asyncBatchAnnotateFilesSettings(); + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings.Builder< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return getStubSettingsBuilder().asyncBatchAnnotateFilesOperationSettings(); + } + + @Override + public ImageAnnotatorSettings build() throws IOException { + return new ImageAnnotatorSettings(this); + } + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/package-info.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/package-info.java new file mode 100644 index 000000000000..bcd23873e09b --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/package-info.java @@ -0,0 +1,39 @@ +/* + * Copyright 2018 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. + */ + +/** + * A client to Google Cloud Vision API. + * + *

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

    ==================== ImageAnnotatorClient ==================== + * + *

    Service Description: Service that performs Google Cloud Vision API detection tasks over client + * images, such as face, landmark, logo, label, and text detection. The ImageAnnotator service + * returns detected entities from the images. + * + *

    Sample for ImageAnnotatorClient: + * + *

    + * 
    + * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
    + *   List<AnnotateImageRequest> requests = new ArrayList<>();
    + *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
    + * }
    + * 
    + * 
    + */ +package com.google.cloud.vision.v1p2beta1; diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorCallableFactory.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorCallableFactory.java new file mode 100644 index 000000000000..4a42f250e1a3 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorCallableFactory.java @@ -0,0 +1,114 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Vision API. + * + *

    This class is for advanced usage. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcImageAnnotatorCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorStub.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorStub.java new file mode 100644 index 000000000000..c9fbd3278b4b --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorStub.java @@ -0,0 +1,203 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +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.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse; +import com.google.cloud.vision.v1p2beta1.OperationMetadata; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.GrpcOperationsStub; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC stub implementation for Google Cloud Vision API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class GrpcImageAnnotatorStub extends ImageAnnotatorStub { + + private static final MethodDescriptor + batchAnnotateImagesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.vision.v1p2beta1.ImageAnnotator/BatchAnnotateImages") + .setRequestMarshaller( + ProtoUtils.marshaller(BatchAnnotateImagesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(BatchAnnotateImagesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + asyncBatchAnnotateFilesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + "google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles") + .setRequestMarshaller( + ProtoUtils.marshaller(AsyncBatchAnnotateFilesRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + + private final UnaryCallable + batchAnnotateImagesCallable; + private final UnaryCallable + asyncBatchAnnotateFilesCallable; + private final OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable; + + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcImageAnnotatorStub create(ImageAnnotatorStubSettings settings) + throws IOException { + return new GrpcImageAnnotatorStub(settings, ClientContext.create(settings)); + } + + public static final GrpcImageAnnotatorStub create(ClientContext clientContext) + throws IOException { + return new GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcImageAnnotatorStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcImageAnnotatorCallableFactory()); + } + + /** + * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings + batchAnnotateImagesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(batchAnnotateImagesMethodDescriptor) + .build(); + GrpcCallSettings + asyncBatchAnnotateFilesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(asyncBatchAnnotateFilesMethodDescriptor) + .build(); + + this.batchAnnotateImagesCallable = + callableFactory.createUnaryCallable( + batchAnnotateImagesTransportSettings, + settings.batchAnnotateImagesSettings(), + clientContext); + this.asyncBatchAnnotateFilesCallable = + callableFactory.createUnaryCallable( + asyncBatchAnnotateFilesTransportSettings, + settings.asyncBatchAnnotateFilesSettings(), + clientContext); + this.asyncBatchAnnotateFilesOperationCallable = + callableFactory.createOperationCallable( + asyncBatchAnnotateFilesTransportSettings, + settings.asyncBatchAnnotateFilesOperationSettings(), + clientContext, + this.operationsStub); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + public UnaryCallable + batchAnnotateImagesCallable() { + return batchAnnotateImagesCallable; + } + + public OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable() { + return asyncBatchAnnotateFilesOperationCallable; + } + + public UnaryCallable + asyncBatchAnnotateFilesCallable() { + return asyncBatchAnnotateFilesCallable; + } + + @Override + public final void close() throws Exception { + shutdown(); + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStub.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStub.java new file mode 100644 index 000000000000..c7d036f4a91e --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStub.java @@ -0,0 +1,61 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1.stub; + +import com.google.api.core.BetaApi; +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.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse; +import com.google.cloud.vision.v1p2beta1.OperationMetadata; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Google Cloud Vision API. + * + *

    This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public abstract class ImageAnnotatorStub implements BackgroundResource { + + public OperationsStub getOperationsStub() { + throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + } + + public UnaryCallable + batchAnnotateImagesCallable() { + throw new UnsupportedOperationException("Not implemented: batchAnnotateImagesCallable()"); + } + + public OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable() { + throw new UnsupportedOperationException( + "Not implemented: asyncBatchAnnotateFilesOperationCallable()"); + } + + public UnaryCallable + asyncBatchAnnotateFilesCallable() { + throw new UnsupportedOperationException("Not implemented: asyncBatchAnnotateFilesCallable()"); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStubSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStubSettings.java new file mode 100644 index 000000000000..3fd3039e79b5 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStubSettings.java @@ -0,0 +1,354 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse; +import com.google.cloud.vision.v1p2beta1.OperationMetadata; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link ImageAnnotatorStub}. + * + *

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

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

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

    + * 
    + * ImageAnnotatorStubSettings.Builder imageAnnotatorSettingsBuilder =
    + *     ImageAnnotatorStubSettings.newBuilder();
    + * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettings().toBuilder()
    + *     .setTotalTimeout(Duration.ofSeconds(30));
    + * ImageAnnotatorStubSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build();
    + * 
    + * 
    + */ +@Generated("by GAPIC v0.0.5") +public class ImageAnnotatorStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/cloud-platform") + .add("https://www.googleapis.com/auth/cloud-vision") + .build(); + + private final UnaryCallSettings + batchAnnotateImagesSettings; + private final UnaryCallSettings + asyncBatchAnnotateFilesSettings; + private final OperationCallSettings< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings; + + /** Returns the object with the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings + batchAnnotateImagesSettings() { + return batchAnnotateImagesSettings; + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings + asyncBatchAnnotateFilesSettings() { + return asyncBatchAnnotateFilesSettings; + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return asyncBatchAnnotateFilesOperationSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public ImageAnnotatorStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcImageAnnotatorStub.create(this); + } else { + throw new UnsupportedOperationException( + "Transport not supported: " + getTransportChannelProvider().getTransportName()); + } + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "vision.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(ImageAnnotatorStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected ImageAnnotatorStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + batchAnnotateImagesSettings = settingsBuilder.batchAnnotateImagesSettings().build(); + asyncBatchAnnotateFilesSettings = settingsBuilder.asyncBatchAnnotateFilesSettings().build(); + asyncBatchAnnotateFilesOperationSettings = + settingsBuilder.asyncBatchAnnotateFilesOperationSettings().build(); + } + + /** Builder for ImageAnnotatorStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder + batchAnnotateImagesSettings; + private final UnaryCallSettings.Builder + asyncBatchAnnotateFilesSettings; + private final OperationCallSettings.Builder< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings; + + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "idempotent", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); + definitions.put("non_idempotent", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(60000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(60000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("default", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + batchAnnotateImagesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + asyncBatchAnnotateFilesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + asyncBatchAnnotateFilesOperationSettings = OperationCallSettings.newBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + batchAnnotateImagesSettings, asyncBatchAnnotateFilesSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .batchAnnotateImagesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .asyncBatchAnnotateFilesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + builder + .asyncBatchAnnotateFilesOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create( + AsyncBatchAnnotateFilesResponse.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(20000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(86400000L)) + .build())); + + return builder; + } + + protected Builder(ImageAnnotatorStubSettings settings) { + super(settings); + + batchAnnotateImagesSettings = settings.batchAnnotateImagesSettings.toBuilder(); + asyncBatchAnnotateFilesSettings = settings.asyncBatchAnnotateFilesSettings.toBuilder(); + asyncBatchAnnotateFilesOperationSettings = + settings.asyncBatchAnnotateFilesOperationSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + batchAnnotateImagesSettings, asyncBatchAnnotateFilesSettings); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

    Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings.Builder + batchAnnotateImagesSettings() { + return batchAnnotateImagesSettings; + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings.Builder + asyncBatchAnnotateFilesSettings() { + return asyncBatchAnnotateFilesSettings; + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings.Builder< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return asyncBatchAnnotateFilesOperationSettings; + } + + @Override + public ImageAnnotatorStubSettings build() throws IOException { + return new ImageAnnotatorStubSettings(this); + } + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1/ImageAnnotatorSmokeTest.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1/ImageAnnotatorSmokeTest.java new file mode 100644 index 000000000000..d83a26e55ee4 --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1/ImageAnnotatorSmokeTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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.cloud.vision.v1; + +import com.google.cloud.vision.v1.Feature.Type; +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ImageAnnotatorSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { + String gcsImageUri = "gs://gapic-toolkit/President_Barack_Obama.jpg"; + ImageSource source = ImageSource.newBuilder().setGcsImageUri(gcsImageUri).build(); + Image image = Image.newBuilder().setSource(source).build(); + Feature.Type type = Feature.Type.FACE_DETECTION; + Feature featuresElement = Feature.newBuilder().setType(type).build(); + List features = Arrays.asList(featuresElement); + AnnotateImageRequest requestsElement = + AnnotateImageRequest.newBuilder().setImage(image).addAllFeatures(features).build(); + List requests = Arrays.asList(requestsElement); + + BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p1beta1/ImageAnnotatorSmokeTest.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p1beta1/ImageAnnotatorSmokeTest.java new file mode 100644 index 000000000000..5ffd68ec0a34 --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p1beta1/ImageAnnotatorSmokeTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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.cloud.vision.v1p1beta1; + +import com.google.cloud.vision.v1p1beta1.Feature.Type; +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ImageAnnotatorSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { + String gcsImageUri = "gs://gapic-toolkit/President_Barack_Obama.jpg"; + ImageSource source = ImageSource.newBuilder().setGcsImageUri(gcsImageUri).build(); + Image image = Image.newBuilder().setSource(source).build(); + Feature.Type type = Feature.Type.FACE_DETECTION; + Feature featuresElement = Feature.newBuilder().setType(type).build(); + List features = Arrays.asList(featuresElement); + AnnotateImageRequest requestsElement = + AnnotateImageRequest.newBuilder().setImage(image).addAllFeatures(features).build(); + List requests = Arrays.asList(requestsElement); + + BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClientTest.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClientTest.java new file mode 100644 index 000000000000..85c6c962d928 --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClientTest.java @@ -0,0 +1,166 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +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.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ImageAnnotatorClientTest { + private static MockImageAnnotator mockImageAnnotator; + private static MockServiceHelper serviceHelper; + private ImageAnnotatorClient client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockImageAnnotator = new MockImageAnnotator(); + serviceHelper = + new MockServiceHelper("in-process-1", Arrays.asList(mockImageAnnotator)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + channelProvider = serviceHelper.createChannelProvider(); + ImageAnnotatorSettings settings = + ImageAnnotatorSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ImageAnnotatorClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void batchAnnotateImagesTest() { + BatchAnnotateImagesResponse expectedResponse = BatchAnnotateImagesResponse.newBuilder().build(); + mockImageAnnotator.addResponse(expectedResponse); + + List requests = new ArrayList<>(); + + BatchAnnotateImagesResponse actualResponse = client.batchAnnotateImages(requests); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockImageAnnotator.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + BatchAnnotateImagesRequest actualRequest = (BatchAnnotateImagesRequest) actualRequests.get(0); + + Assert.assertEquals(requests, actualRequest.getRequestsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void batchAnnotateImagesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockImageAnnotator.addException(exception); + + try { + List requests = new ArrayList<>(); + + client.batchAnnotateImages(requests); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void asyncBatchAnnotateFilesTest() throws Exception { + AsyncBatchAnnotateFilesResponse expectedResponse = + AsyncBatchAnnotateFilesResponse.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("asyncBatchAnnotateFilesTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockImageAnnotator.addResponse(resultOperation); + + List requests = new ArrayList<>(); + + AsyncBatchAnnotateFilesResponse actualResponse = + client.asyncBatchAnnotateFilesAsync(requests).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockImageAnnotator.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AsyncBatchAnnotateFilesRequest actualRequest = + (AsyncBatchAnnotateFilesRequest) actualRequests.get(0); + + Assert.assertEquals(requests, actualRequest.getRequestsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void asyncBatchAnnotateFilesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockImageAnnotator.addException(exception); + + try { + List requests = new ArrayList<>(); + + client.asyncBatchAnnotateFilesAsync(requests).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/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSmokeTest.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSmokeTest.java new file mode 100644 index 000000000000..3be2c0923f1f --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSmokeTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1; + +import com.google.cloud.vision.v1p2beta1.Feature.Type; +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ImageAnnotatorSmokeTest { + private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; + private static final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; + + @Test + public void run() { + main(null); + } + + public static void main(String args[]) { + Logger.getLogger("").setLevel(Level.WARNING); + try { + executeNoCatch(); + System.out.println("OK"); + } catch (Exception e) { + System.err.println("Failed with exception:"); + e.printStackTrace(System.err); + System.exit(1); + } + } + + public static void executeNoCatch() throws Exception { + try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { + String gcsImageUri = "gs://gapic-toolkit/President_Barack_Obama.jpg"; + ImageSource source = ImageSource.newBuilder().setGcsImageUri(gcsImageUri).build(); + Image image = Image.newBuilder().setSource(source).build(); + Feature.Type type = Feature.Type.FACE_DETECTION; + Feature featuresElement = Feature.newBuilder().setType(type).build(); + List features = Arrays.asList(featuresElement); + AnnotateImageRequest requestsElement = + AnnotateImageRequest.newBuilder().setImage(image).addAllFeatures(features).build(); + List requests = Arrays.asList(requestsElement); + + BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); + } + } + + private static String getProjectId() { + String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); + if (projectId == null) { + projectId = + System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); + } + Preconditions.checkArgument(projectId != null, "A project ID is required."); + return projectId; + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotator.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotator.java new file mode 100644 index 000000000000..59867209f4ea --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotator.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockImageAnnotator implements MockGrpcService { + private final MockImageAnnotatorImpl serviceImpl; + + public MockImageAnnotator() { + serviceImpl = new MockImageAnnotatorImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(GeneratedMessageV3 response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotatorImpl.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotatorImpl.java new file mode 100644 index 000000000000..ce9916cc8cc5 --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotatorImpl.java @@ -0,0 +1,90 @@ +/* + * Copyright 2018 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.cloud.vision.v1p2beta1; + +import com.google.api.core.BetaApi; +import com.google.cloud.vision.v1p2beta1.ImageAnnotatorGrpc.ImageAnnotatorImplBase; +import com.google.longrunning.Operation; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockImageAnnotatorImpl extends ImageAnnotatorImplBase { + private ArrayList requests; + private Queue responses; + + public MockImageAnnotatorImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(GeneratedMessageV3 response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void batchAnnotateImages( + BatchAnnotateImagesRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof BatchAnnotateImagesResponse) { + requests.add(request); + responseObserver.onNext((BatchAnnotateImagesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void asyncBatchAnnotateFiles( + AsyncBatchAnnotateFilesRequest 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("Unrecognized response type")); + } + } +} diff --git a/google-cloud/README.md b/google-cloud/README.md index c1bd433aab08..a71e900b66db 100644 --- a/google-cloud/README.md +++ b/google-cloud/README.md @@ -25,16 +25,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud - 0.38.0-alpha + 0.43.0-alpha ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud:0.38.0-alpha' +compile 'com.google.cloud:google-cloud:0.43.0-alpha' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud" % "0.38.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud" % "0.43.0-alpha" ``` [//]: # ({x-version-update-end}) diff --git a/google-cloud/pom.xml b/google-cloud/pom.xml index c7e72837571f..3a5a8391ce79 100644 --- a/google-cloud/pom.xml +++ b/google-cloud/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT jar Google Cloud https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud @@ -12,7 +12,7 @@ com.google.cloud google-cloud-pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT diff --git a/pom.xml b/pom.xml index 2e0471b30aa9..232a4d6af40b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-pom pom - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT Google Cloud https://github.com/GoogleCloudPlatform/google-cloud-java @@ -136,11 +136,11 @@ UTF-8 github google-cloud - 0.38.1-alpha-SNAPSHOT + 0.43.1-alpha-SNAPSHOT 1.23.0 - 1.19.0 + 1.23.0 0.9.0 - 1.9.0 + 1.10.1 2.0.7.Final 20.0 1.23.0 @@ -163,7 +163,7 @@ com.google.apis google-api-services-bigquery - v2-rev372-1.23.0 + v2-rev377-1.23.0 com.google.apis @@ -186,7 +186,7 @@ commons-fileupload 1.3.2 - + com.google.apis google-api-services-cloudresourcemanager @@ -271,7 +271,7 @@ com.google.guava guava ${guava.version} - + com.google.auto.value auto-value @@ -422,6 +422,7 @@ google-cloud-spanner google-cloud-speech google-cloud-storage + google-cloud-texttospeech google-cloud-trace google-cloud-translate google-cloud-vision @@ -474,16 +475,18 @@ maven-surefire-plugin 2.19.1 - + + **/*SmokeTest.java **/IT*.java + **/*SmokeTest.java org.apache.maven.plugins maven-enforcer-plugin - 1.4.1 + 3.0.0-M1 enforce @@ -751,7 +754,7 @@ Stub packages - com.google.cloud.bigquerydatatransfer.v1.stub:com.google.cloud.container.v1.stub:com.google.cloud.dlp.v2beta1.stub:com.google.cloud.dialogflow.v2beta1.stub:com.google.cloud.errorreporting.v1beta1.stub:com.google.cloud.firestore.v1beta1.stub:com.google.cloud.language.v1beta2.stub:com.google.cloud.language.v1.stub:com.google.cloud.logging.v2.stub:com.google.cloud.monitoring.v3.stub:com.google.cloud.pubsub.v1.stub:com.google.cloud.speech.v1beta1.stub:com.google.cloud.speech.v1.stub:com.google.cloud.trace.v1.stub:com.google.cloud.trace.v2.stub:com.google.cloud.videointelligence.v1beta1.stub:com.google.cloud.videointelligence.v1beta2.stub:com.google.cloud.videointelligence.v1.stub:com.google.cloud.vision.v1.stub:com.google.cloud.vision.v1p1beta1.stub + com.google.cloud.bigquerydatatransfer.v1.stub:com.google.cloud.container.v1.stub:com.google.cloud.dlp.v2beta1.stub:com.google.cloud.dlp.v2.stub:com.google.cloud.dialogflow.v2beta1.stub:com.google.cloud.errorreporting.v1beta1.stub:com.google.cloud.firestore.v1beta1.stub:com.google.cloud.language.v1beta2.stub:com.google.cloud.language.v1.stub:com.google.cloud.logging.v2.stub:com.google.cloud.monitoring.v3.stub:com.google.cloud.pubsub.v1.stub:com.google.cloud.speech.v1beta1.stub:com.google.cloud.speech.v1.stub:com.google.cloud.texttospeech.v1beta1.stub:com.google.cloud.trace.v1.stub:com.google.cloud.trace.v2.stub:com.google.cloud.videointelligence.v1beta1.stub:com.google.cloud.videointelligence.v1beta2.stub:com.google.cloud.videointelligence.v1.stub:com.google.cloud.videointelligence.v1p1beta1.stub:com.google.cloud.vision.v1.stub:com.google.cloud.vision.v1p1beta1.stub:com.google.cloud.vision.v1p2beta1.stub Deprecated packages @@ -865,5 +868,39 @@ + + + smoke-test + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.19.1 + + + + integration-test + verify + + + + + + **/*SmokeTest.java + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + true + + + + + diff --git a/utilities/verify_single_it.sh b/utilities/verify_single_it.sh index 8437edf60b46..83a9e3f746c9 100755 --- a/utilities/verify_single_it.sh +++ b/utilities/verify_single_it.sh @@ -5,6 +5,7 @@ set -e MODULE=$1 +ARGS=${@:2:99} if [ -z $MODULE ]; then echo "First arg (module) not provided, so we're exiting." @@ -26,4 +27,4 @@ echo "----- building and installing shared modules -----" mvn -B -pl google-cloud-core,google-cloud-core-http,google-cloud-core-grpc,google-cloud-storage,google-cloud-pubsub install -DskipTests echo "----- running integration tests -----" -mvn -B -pl $MODULE -DtrimStackTrace=false -fae verify +mvn -B -pl $MODULE -DtrimStackTrace=false -fae verify ${ARGS} diff --git a/versions.txt b/versions.txt index 2b9168d1ddf6..f1e80f38525b 100644 --- a/versions.txt +++ b/versions.txt @@ -1,47 +1,48 @@ # Format: # module:released-version:current-version -google-cloud-appengineflexcompat:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-appengineflexcustom:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-appengineflexjava:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-appenginejava8:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-bigquery:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-bigquerydatatransfer:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-bigtable:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-bom:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-compat-checker:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-compute:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-container:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-contrib:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-core:1.20.0:1.20.1-SNAPSHOT -google-cloud-core-grpc:1.20.0:1.20.1-SNAPSHOT -google-cloud-core-http:1.20.0:1.20.1-SNAPSHOT -google-cloud-dataproc:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-datastore:1.20.0:1.20.1-SNAPSHOT -google-cloud-dialogflow:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-dlp:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-dns:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-errorreporting:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-examples:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-firestore:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-language:1.20.0:1.20.1-SNAPSHOT -google-cloud-logging:1.20.0:1.20.1-SNAPSHOT -google-cloud-logging-logback:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-managedtest:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-monitoring:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-nio:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-nio-examples:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-notification:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-os-login:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-pom:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-pubsub:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-resourcemanager:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-spanner:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-speech:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-storage:1.20.0:1.20.1-SNAPSHOT -google-cloud-testing:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-trace:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-translate:1.20.0:1.20.1-SNAPSHOT -google-cloud-util:0.38.0-alpha:0.38.1-alpha-SNAPSHOT -google-cloud-video-intelligence:0.38.0-beta:0.38.1-beta-SNAPSHOT -google-cloud-vision:1.20.0:1.20.1-SNAPSHOT +google-cloud-appengineflexcompat:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-appengineflexcustom:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-appengineflexjava:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-appenginejava8:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-bigquery:1.25.0:1.25.1-SNAPSHOT +google-cloud-bigquerydatatransfer:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-bigtable:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-bom:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-compat-checker:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-compute:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-container:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-contrib:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-core:1.25.0:1.25.1-SNAPSHOT +google-cloud-core-grpc:1.25.0:1.25.1-SNAPSHOT +google-cloud-core-http:1.25.0:1.25.1-SNAPSHOT +google-cloud-dataproc:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-datastore:1.25.0:1.25.1-SNAPSHOT +google-cloud-dialogflow:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-dlp:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-dns:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-errorreporting:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-examples:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-firestore:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-language:1.25.0:1.25.1-SNAPSHOT +google-cloud-logging:1.25.0:1.25.1-SNAPSHOT +google-cloud-logging-logback:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-managedtest:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-monitoring:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-nio:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-nio-examples:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-notification:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-os-login:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-pom:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-pubsub:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-resourcemanager:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-spanner:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-speech:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-storage:1.25.0:1.25.1-SNAPSHOT +google-cloud-texttospeech:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-testing:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-trace:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-translate:1.25.0:1.25.1-SNAPSHOT +google-cloud-util:0.43.0-alpha:0.43.1-alpha-SNAPSHOT +google-cloud-video-intelligence:0.43.0-beta:0.43.1-beta-SNAPSHOT +google-cloud-vision:1.25.0:1.25.1-SNAPSHOT