diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml new file mode 100644 index 000000000000..332cc1a30b5d --- /dev/null +++ b/google-cloud-bigtable/pom.xml @@ -0,0 +1,183 @@ + + + 4.0.0 + google-cloud-bigtable + 0.26.1-beta-SNAPSHOT + jar + Google Cloud Bigtable + https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigtable + + Java idiomatic client for Google Cloud Bigtable. + + + com.google.cloud + google-cloud-pom + 0.26.1-alpha-SNAPSHOT + + + google-cloud-bigtable + ${project.version} + + + + io.netty + netty-tcnative-boringssl-static + + + ${project.groupId} + google-cloud-core + + + ${project.groupId} + google-cloud-core-grpc + + + com.google.api.grpc + proto-google-cloud-bigtable-v2 + + + com.google.api.grpc + grpc-google-cloud-bigtable-v2 + test + + + com.google.api.grpc + proto-google-cloud-bigtable-admin-v2 + + + com.google.api.grpc + grpc-google-cloud-bigtable-admin-v2 + test + + + io.grpc + grpc-netty + + + 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.truth + truth + test + + + com.google.api + gax-grpc + testlib + test + + + + + doclint-java8-disable + + [1.8,) + + + + -Xdoclint:none + + + + + + + ./.. + true + + project.properties + + + + + + maven-antrun-plugin + 1.4 + + + process-resources + + + + + + + run + + + + + + 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.5.1 + + 1.7 + 1.7 + UTF-8 + -Xlint:unchecked + + + + + diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClient.java new file mode 100644 index 000000000000..25f2d074d21c --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClient.java @@ -0,0 +1,1089 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +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.bigtable.admin.v2.Cluster; +import com.google.bigtable.admin.v2.ClusterName; +import com.google.bigtable.admin.v2.CreateClusterMetadata; +import com.google.bigtable.admin.v2.CreateClusterRequest; +import com.google.bigtable.admin.v2.CreateInstanceMetadata; +import com.google.bigtable.admin.v2.CreateInstanceRequest; +import com.google.bigtable.admin.v2.DeleteClusterRequest; +import com.google.bigtable.admin.v2.DeleteInstanceRequest; +import com.google.bigtable.admin.v2.GetClusterRequest; +import com.google.bigtable.admin.v2.GetInstanceRequest; +import com.google.bigtable.admin.v2.Instance; +import com.google.bigtable.admin.v2.Instance.Type; +import com.google.bigtable.admin.v2.InstanceName; +import com.google.bigtable.admin.v2.ListClustersRequest; +import com.google.bigtable.admin.v2.ListClustersResponse; +import com.google.bigtable.admin.v2.ListInstancesRequest; +import com.google.bigtable.admin.v2.ListInstancesResponse; +import com.google.bigtable.admin.v2.LocationName; +import com.google.bigtable.admin.v2.ProjectName; +import com.google.bigtable.admin.v2.StorageType; +import com.google.bigtable.admin.v2.UpdateClusterMetadata; +import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStub; +import com.google.longrunning.Operation; +import com.google.longrunning.OperationsClient; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: Service for creating, configuring, and deleting Cloud Bigtable Instances and + * Clusters. Provides access to the Instance and Cluster schemas only, not the tables' metadata or + * data stored in those tables. + * + *

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 (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+ *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+ *   Instance response = bigtableInstanceAdminClient.getInstance(name);
+ * }
+ * 
+ * 
+ * + *

Note: close() needs to be called on the bigtableInstanceAdminClient 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 BigtableInstanceAdminSettings + * to create(). For example: + * + *

To customize credentials: + * + *

+ * 
+ * BigtableInstanceAdminSettings bigtableInstanceAdminSettings =
+ *     BigtableInstanceAdminSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * BigtableInstanceAdminClient bigtableInstanceAdminClient =
+ *     BigtableInstanceAdminClient.create(bigtableInstanceAdminSettings);
+ * 
+ * 
+ * + * To customize the endpoint: + * + *
+ * 
+ * BigtableInstanceAdminSettings bigtableInstanceAdminSettings =
+ *     BigtableInstanceAdminSettings.newBuilder()
+ *         .setTransportChannelProvider(BigtableInstanceAdminSettings.defaultGrpcTransportProviderBuilder()
+ *             .setEndpoint(myEndpoint)
+ *             .build())
+ *         .build();
+ * BigtableInstanceAdminClient bigtableInstanceAdminClient =
+ *     BigtableInstanceAdminClient.create(bigtableInstanceAdminSettings);
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class BigtableInstanceAdminClient implements BackgroundResource { + private final BigtableInstanceAdminSettings settings; + private final BigtableInstanceAdminStub stub; + private final OperationsClient operationsClient; + + /** Constructs an instance of BigtableInstanceAdminClient with default settings. */ + public static final BigtableInstanceAdminClient create() throws IOException { + return create(BigtableInstanceAdminSettings.newBuilder().build()); + } + + /** + * Constructs an instance of BigtableInstanceAdminClient, 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 BigtableInstanceAdminClient create(BigtableInstanceAdminSettings settings) + throws IOException { + return new BigtableInstanceAdminClient(settings); + } + + /** + * Constructs an instance of BigtableInstanceAdminClient, using the given stub for making calls. + * This is for advanced usage - prefer to use BigtableInstanceAdminSettings}. + */ + @BetaApi + public static final BigtableInstanceAdminClient create(BigtableInstanceAdminStub stub) { + return new BigtableInstanceAdminClient(stub); + } + + /** + * Constructs an instance of BigtableInstanceAdminClient, 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 BigtableInstanceAdminClient(BigtableInstanceAdminSettings settings) throws IOException { + this.settings = settings; + this.stub = settings.createStub(); + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + protected BigtableInstanceAdminClient(BigtableInstanceAdminStub stub) { + this.settings = null; + this.stub = stub; + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + public final BigtableInstanceAdminSettings getSettings() { + return settings; + } + + @BetaApi + public BigtableInstanceAdminStub 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 + /** + * Create an instance within a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   String instanceId = "";
+   *   Instance instance = Instance.newBuilder().build();
+   *   Map<String, Cluster> clusters = new HashMap<>();
+   *   Instance response = bigtableInstanceAdminClient.createInstanceAsync(parent, instanceId, instance, clusters).get();
+   * }
+   * 
+ * + * @param parent The unique name of the project in which to create the new instance. Values are of + * the form `projects/<project>`. + * @param instanceId The ID to be used when referring to the new instance within its project, + * e.g., just `myinstance` rather than `projects/myproject/instances/myinstance`. + * @param instance The instance to create. Fields marked `OutputOnly` must be left blank. + * @param clusters The clusters to be created within the instance, mapped by desired cluster ID, + * e.g., just `mycluster` rather than + * `projects/myproject/instances/myinstance/clusters/mycluster`. Fields marked `OutputOnly` + * must be left blank. Currently exactly one cluster must be specified. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture createInstanceAsync( + ProjectName parent, String instanceId, Instance instance, Map clusters) { + + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParentWithProjectName(parent) + .setInstanceId(instanceId) + .setInstance(instance) + .putAllClusters(clusters) + .build(); + return createInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Create an instance within a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   String instanceId = "";
+   *   Instance instance = Instance.newBuilder().build();
+   *   Map<String, Cluster> clusters = new HashMap<>();
+   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
+   *     .setParentWithProjectName(parent)
+   *     .setInstanceId(instanceId)
+   *     .setInstance(instance)
+   *     .putAllClusters(clusters)
+   *     .build();
+   *   Instance response = bigtableInstanceAdminClient.createInstanceAsync(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 createInstanceAsync( + CreateInstanceRequest request) { + return createInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Create an instance within a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   String instanceId = "";
+   *   Instance instance = Instance.newBuilder().build();
+   *   Map<String, Cluster> clusters = new HashMap<>();
+   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
+   *     .setParentWithProjectName(parent)
+   *     .setInstanceId(instanceId)
+   *     .setInstance(instance)
+   *     .putAllClusters(clusters)
+   *     .build();
+   *   OperationFuture<Operation> future = bigtableInstanceAdminClient.createInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + public final OperationCallable + createInstanceOperationCallable() { + return stub.createInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Create an instance within a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   String instanceId = "";
+   *   Instance instance = Instance.newBuilder().build();
+   *   Map<String, Cluster> clusters = new HashMap<>();
+   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
+   *     .setParentWithProjectName(parent)
+   *     .setInstanceId(instanceId)
+   *     .setInstance(instance)
+   *     .putAllClusters(clusters)
+   *     .build();
+   *   ApiFuture<Operation> future = bigtableInstanceAdminClient.createInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable createInstanceCallable() { + return stub.createInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets information about an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   Instance response = bigtableInstanceAdminClient.getInstance(name);
+   * }
+   * 
+ * + * @param name The unique name of the requested instance. Values are of the form + * `projects/<project>/instances/<instance>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance getInstance(InstanceName name) { + + GetInstanceRequest request = + GetInstanceRequest.newBuilder().setNameWithInstanceName(name).build(); + return getInstance(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets information about an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   GetInstanceRequest request = GetInstanceRequest.newBuilder()
+   *     .setNameWithInstanceName(name)
+   *     .build();
+   *   Instance response = bigtableInstanceAdminClient.getInstance(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 Instance getInstance(GetInstanceRequest request) { + return getInstanceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets information about an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   GetInstanceRequest request = GetInstanceRequest.newBuilder()
+   *     .setNameWithInstanceName(name)
+   *     .build();
+   *   ApiFuture<Instance> future = bigtableInstanceAdminClient.getInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable getInstanceCallable() { + return stub.getInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists information about instances in a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   ListInstancesResponse response = bigtableInstanceAdminClient.listInstances(parent);
+   * }
+   * 
+ * + * @param parent The unique name of the project for which a list of instances is requested. Values + * are of the form `projects/<project>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListInstancesResponse listInstances(ProjectName parent) { + + ListInstancesRequest request = + ListInstancesRequest.newBuilder().setParentWithProjectName(parent).build(); + return listInstances(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists information about instances in a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
+   *     .setParentWithProjectName(parent)
+   *     .build();
+   *   ListInstancesResponse response = bigtableInstanceAdminClient.listInstances(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 ListInstancesResponse listInstances(ListInstancesRequest request) { + return listInstancesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists information about instances in a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
+   *     .setParentWithProjectName(parent)
+   *     .build();
+   *   ApiFuture<ListInstancesResponse> future = bigtableInstanceAdminClient.listInstancesCallable().futureCall(request);
+   *   // Do something
+   *   ListInstancesResponse response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable listInstancesCallable() { + return stub.listInstancesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates an instance within a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String displayName = "";
+   *   Instance.Type type = Instance.Type.TYPE_UNSPECIFIED;
+   *   Instance response = bigtableInstanceAdminClient.updateInstance(name, displayName, type);
+   * }
+   * 
+ * + * @param name (`OutputOnly`) The unique name of the instance. Values are of the form + * `projects/<project>/instances/[a-z][a-z0-9\\-]+[a-z0-9]`. + * @param displayName The descriptive name for this instance as it appears in UIs. Can be changed + * at any time, but should be kept globally unique to avoid confusion. + * @param type The type of the instance. Defaults to `PRODUCTION`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance updateInstance(InstanceName name, String displayName, Instance.Type type) { + + Instance request = + Instance.newBuilder() + .setNameWithInstanceName(name) + .setDisplayName(displayName) + .setType(type) + .build(); + return updateInstance(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates an instance within a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String displayName = "";
+   *   Instance.Type type = Instance.Type.TYPE_UNSPECIFIED;
+   *   Instance request = Instance.newBuilder()
+   *     .setNameWithInstanceName(name)
+   *     .setDisplayName(displayName)
+   *     .setType(type)
+   *     .build();
+   *   Instance response = bigtableInstanceAdminClient.updateInstance(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 Instance updateInstance(Instance request) { + return updateInstanceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates an instance within a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String displayName = "";
+   *   Instance.Type type = Instance.Type.TYPE_UNSPECIFIED;
+   *   Instance request = Instance.newBuilder()
+   *     .setNameWithInstanceName(name)
+   *     .setDisplayName(displayName)
+   *     .setType(type)
+   *     .build();
+   *   ApiFuture<Instance> future = bigtableInstanceAdminClient.updateInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable updateInstanceCallable() { + return stub.updateInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Delete an instance from a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   bigtableInstanceAdminClient.deleteInstance(name);
+   * }
+   * 
+ * + * @param name The unique name of the instance to be deleted. Values are of the form + * `projects/<project>/instances/<instance>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteInstance(InstanceName name) { + + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder().setNameWithInstanceName(name).build(); + deleteInstance(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Delete an instance from a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
+   *     .setNameWithInstanceName(name)
+   *     .build();
+   *   bigtableInstanceAdminClient.deleteInstance(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 void deleteInstance(DeleteInstanceRequest request) { + deleteInstanceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Delete an instance from a project. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
+   *     .setNameWithInstanceName(name)
+   *     .build();
+   *   ApiFuture<Void> future = bigtableInstanceAdminClient.deleteInstanceCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ */ + public final UnaryCallable deleteInstanceCallable() { + return stub.deleteInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String clusterId = "";
+   *   Cluster cluster = Cluster.newBuilder().build();
+   *   Cluster response = bigtableInstanceAdminClient.createClusterAsync(parent, clusterId, cluster).get();
+   * }
+   * 
+ * + * @param parent The unique name of the instance in which to create the new cluster. Values are of + * the form `projects/<project>/instances/<instance>`. + * @param clusterId The ID to be used when referring to the new cluster within its instance, e.g., + * just `mycluster` rather than `projects/myproject/instances/myinstance/clusters/mycluster`. + * @param cluster The cluster to be created. Fields marked `OutputOnly` must be left blank. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture createClusterAsync( + InstanceName parent, String clusterId, Cluster cluster) { + + CreateClusterRequest request = + CreateClusterRequest.newBuilder() + .setParentWithInstanceName(parent) + .setClusterId(clusterId) + .setCluster(cluster) + .build(); + return createClusterAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String clusterId = "";
+   *   Cluster cluster = Cluster.newBuilder().build();
+   *   CreateClusterRequest request = CreateClusterRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .setClusterId(clusterId)
+   *     .setCluster(cluster)
+   *     .build();
+   *   Cluster response = bigtableInstanceAdminClient.createClusterAsync(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 createClusterAsync( + CreateClusterRequest request) { + return createClusterOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String clusterId = "";
+   *   Cluster cluster = Cluster.newBuilder().build();
+   *   CreateClusterRequest request = CreateClusterRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .setClusterId(clusterId)
+   *     .setCluster(cluster)
+   *     .build();
+   *   OperationFuture<Operation> future = bigtableInstanceAdminClient.createClusterOperationCallable().futureCall(request);
+   *   // Do something
+   *   Cluster response = future.get();
+   * }
+   * 
+ */ + public final OperationCallable + createClusterOperationCallable() { + return stub.createClusterOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String clusterId = "";
+   *   Cluster cluster = Cluster.newBuilder().build();
+   *   CreateClusterRequest request = CreateClusterRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .setClusterId(clusterId)
+   *     .setCluster(cluster)
+   *     .build();
+   *   ApiFuture<Operation> future = bigtableInstanceAdminClient.createClusterCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable createClusterCallable() { + return stub.createClusterCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets information about a cluster. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   Cluster response = bigtableInstanceAdminClient.getCluster(name);
+   * }
+   * 
+ * + * @param name The unique name of the requested cluster. Values are of the form + * `projects/<project>/instances/<instance>/clusters/<cluster>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Cluster getCluster(ClusterName name) { + + GetClusterRequest request = GetClusterRequest.newBuilder().setNameWithClusterName(name).build(); + return getCluster(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets information about a cluster. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   GetClusterRequest request = GetClusterRequest.newBuilder()
+   *     .setNameWithClusterName(name)
+   *     .build();
+   *   Cluster response = bigtableInstanceAdminClient.getCluster(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 Cluster getCluster(GetClusterRequest request) { + return getClusterCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets information about a cluster. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   GetClusterRequest request = GetClusterRequest.newBuilder()
+   *     .setNameWithClusterName(name)
+   *     .build();
+   *   ApiFuture<Cluster> future = bigtableInstanceAdminClient.getClusterCallable().futureCall(request);
+   *   // Do something
+   *   Cluster response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable getClusterCallable() { + return stub.getClusterCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists information about clusters in an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   ListClustersResponse response = bigtableInstanceAdminClient.listClusters(parent);
+   * }
+   * 
+ * + * @param parent The unique name of the instance for which a list of clusters is requested. Values + * are of the form `projects/<project>/instances/<instance>`. Use + * `<instance> = '-'` to list Clusters for all Instances in a project, e.g., + * `projects/myproject/instances/-`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListClustersResponse listClusters(InstanceName parent) { + + ListClustersRequest request = + ListClustersRequest.newBuilder().setParentWithInstanceName(parent).build(); + return listClusters(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists information about clusters in an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   ListClustersRequest request = ListClustersRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .build();
+   *   ListClustersResponse response = bigtableInstanceAdminClient.listClusters(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 ListClustersResponse listClusters(ListClustersRequest request) { + return listClustersCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists information about clusters in an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   ListClustersRequest request = ListClustersRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .build();
+   *   ApiFuture<ListClustersResponse> future = bigtableInstanceAdminClient.listClustersCallable().futureCall(request);
+   *   // Do something
+   *   ListClustersResponse response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable listClustersCallable() { + return stub.listClustersCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   LocationName location = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   int serveNodes = 0;
+   *   StorageType defaultStorageType = StorageType.STORAGE_TYPE_UNSPECIFIED;
+   *   Cluster response = bigtableInstanceAdminClient.updateClusterAsync(name, location, serveNodes, defaultStorageType).get();
+   * }
+   * 
+ * + * @param name (`OutputOnly`) The unique name of the cluster. Values are of the form + * `projects/<project>/instances/<instance>/clusters/[a-z][-a-z0-9]*`. + * @param location (`CreationOnly`) The location where this cluster's nodes and storage reside. + * For best performance, clients should be located as close as possible to this cluster. + * Currently only zones are supported, so values should be of the form + * `projects/<project>/locations/<zone>`. + * @param serveNodes The number of nodes allocated to this cluster. More nodes enable higher + * throughput and more consistent performance. + * @param defaultStorageType (`CreationOnly`) The type of storage used by this cluster to serve + * its parent instance's tables, unless explicitly overridden. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture updateClusterAsync( + ClusterName name, LocationName location, int serveNodes, StorageType defaultStorageType) { + + Cluster request = + Cluster.newBuilder() + .setNameWithClusterName(name) + .setLocationWithLocationName(location) + .setServeNodes(serveNodes) + .setDefaultStorageType(defaultStorageType) + .build(); + return updateClusterAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   LocationName location = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   int serveNodes = 0;
+   *   StorageType defaultStorageType = StorageType.STORAGE_TYPE_UNSPECIFIED;
+   *   Cluster request = Cluster.newBuilder()
+   *     .setNameWithClusterName(name)
+   *     .setLocationWithLocationName(location)
+   *     .setServeNodes(serveNodes)
+   *     .setDefaultStorageType(defaultStorageType)
+   *     .build();
+   *   Cluster response = bigtableInstanceAdminClient.updateClusterAsync(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 updateClusterAsync(Cluster request) { + return updateClusterOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   LocationName location = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   int serveNodes = 0;
+   *   StorageType defaultStorageType = StorageType.STORAGE_TYPE_UNSPECIFIED;
+   *   Cluster request = Cluster.newBuilder()
+   *     .setNameWithClusterName(name)
+   *     .setLocationWithLocationName(location)
+   *     .setServeNodes(serveNodes)
+   *     .setDefaultStorageType(defaultStorageType)
+   *     .build();
+   *   OperationFuture<Operation> future = bigtableInstanceAdminClient.updateClusterOperationCallable().futureCall(request);
+   *   // Do something
+   *   Cluster response = future.get();
+   * }
+   * 
+ */ + public final OperationCallable + updateClusterOperationCallable() { + return stub.updateClusterOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates a cluster within an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   LocationName location = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   int serveNodes = 0;
+   *   StorageType defaultStorageType = StorageType.STORAGE_TYPE_UNSPECIFIED;
+   *   Cluster request = Cluster.newBuilder()
+   *     .setNameWithClusterName(name)
+   *     .setLocationWithLocationName(location)
+   *     .setServeNodes(serveNodes)
+   *     .setDefaultStorageType(defaultStorageType)
+   *     .build();
+   *   ApiFuture<Operation> future = bigtableInstanceAdminClient.updateClusterCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable updateClusterCallable() { + return stub.updateClusterCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a cluster from an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   bigtableInstanceAdminClient.deleteCluster(name);
+   * }
+   * 
+ * + * @param name The unique name of the cluster to be deleted. Values are of the form + * `projects/<project>/instances/<instance>/clusters/<cluster>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteCluster(ClusterName name) { + + DeleteClusterRequest request = + DeleteClusterRequest.newBuilder().setNameWithClusterName(name).build(); + deleteCluster(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a cluster from an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   DeleteClusterRequest request = DeleteClusterRequest.newBuilder()
+   *     .setNameWithClusterName(name)
+   *     .build();
+   *   bigtableInstanceAdminClient.deleteCluster(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 void deleteCluster(DeleteClusterRequest request) { + deleteClusterCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a cluster from an instance. + * + *

Sample code: + * + *


+   * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+   *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
+   *   DeleteClusterRequest request = DeleteClusterRequest.newBuilder()
+   *     .setNameWithClusterName(name)
+   *     .build();
+   *   ApiFuture<Void> future = bigtableInstanceAdminClient.deleteClusterCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ */ + public final UnaryCallable deleteClusterCallable() { + return stub.deleteClusterCallable(); + } + + @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-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 new file mode 100644 index 000000000000..b0ee16a3c64e --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java @@ -0,0 +1,699 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.ExecutorProvider; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.core.PropertiesProvider; +import com.google.api.gax.grpc.GrpcExtraHeaderData; +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.ClientSettings; +import com.google.api.gax.rpc.HeaderProvider; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.bigtable.admin.v2.Cluster; +import com.google.bigtable.admin.v2.CreateClusterMetadata; +import com.google.bigtable.admin.v2.CreateClusterRequest; +import com.google.bigtable.admin.v2.CreateInstanceMetadata; +import com.google.bigtable.admin.v2.CreateInstanceRequest; +import com.google.bigtable.admin.v2.DeleteClusterRequest; +import com.google.bigtable.admin.v2.DeleteInstanceRequest; +import com.google.bigtable.admin.v2.GetClusterRequest; +import com.google.bigtable.admin.v2.GetInstanceRequest; +import com.google.bigtable.admin.v2.Instance; +import com.google.bigtable.admin.v2.ListClustersRequest; +import com.google.bigtable.admin.v2.ListClustersResponse; +import com.google.bigtable.admin.v2.ListInstancesRequest; +import com.google.bigtable.admin.v2.ListInstancesResponse; +import com.google.bigtable.admin.v2.UpdateClusterMetadata; +import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStub; +import com.google.cloud.bigtable.admin.v2.stub.GrpcBigtableInstanceAdminStub; +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 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 BigtableInstanceAdminClient}. + * + *

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

    + *
  • The default service address (bigtableadmin.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 getInstance to 30 seconds: + * + *

+ * 
+ * BigtableInstanceAdminSettings.Builder bigtableInstanceAdminSettingsBuilder =
+ *     BigtableInstanceAdminSettings.newBuilder();
+ * bigtableInstanceAdminSettingsBuilder.getInstanceSettings().getRetrySettingsBuilder()
+ *     .setTotalTimeout(Duration.ofSeconds(30));
+ * BigtableInstanceAdminSettings bigtableInstanceAdminSettings = bigtableInstanceAdminSettingsBuilder.build();
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class BigtableInstanceAdminSettings extends ClientSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/bigtable.admin") + .add("https://www.googleapis.com/auth/bigtable.admin.cluster") + .add("https://www.googleapis.com/auth/bigtable.admin.instance") + .add("https://www.googleapis.com/auth/bigtable.admin.table") + .add("https://www.googleapis.com/auth/cloud-bigtable.admin") + .add("https://www.googleapis.com/auth/cloud-bigtable.admin.cluster") + .add("https://www.googleapis.com/auth/cloud-bigtable.admin.table") + .add("https://www.googleapis.com/auth/cloud-platform") + .add("https://www.googleapis.com/auth/cloud-platform.read-only") + .build(); + + private static final String DEFAULT_GAPIC_NAME = "gapic"; + private static final String DEFAULT_GAPIC_VERSION = ""; + + private static final String PROPERTIES_FILE = + "/com/google/cloud/bigtable/admin/project.properties"; + private static final String META_VERSION_KEY = "artifact.version"; + + private static String gapicVersion; + + private final UnaryCallSettings createInstanceSettings; + private final OperationCallSettings + createInstanceOperationSettings; + private final UnaryCallSettings getInstanceSettings; + private final UnaryCallSettings + listInstancesSettings; + private final UnaryCallSettings updateInstanceSettings; + private final UnaryCallSettings deleteInstanceSettings; + private final UnaryCallSettings createClusterSettings; + private final OperationCallSettings + createClusterOperationSettings; + private final UnaryCallSettings getClusterSettings; + private final UnaryCallSettings listClustersSettings; + private final UnaryCallSettings updateClusterSettings; + private final OperationCallSettings + updateClusterOperationSettings; + private final UnaryCallSettings deleteClusterSettings; + + /** Returns the object with the settings used for calls to createInstance. */ + public UnaryCallSettings createInstanceSettings() { + return createInstanceSettings; + } + + /** Returns the object with the settings used for calls to createInstance. */ + public OperationCallSettings + createInstanceOperationSettings() { + return createInstanceOperationSettings; + } + + /** Returns the object with the settings used for calls to getInstance. */ + public UnaryCallSettings getInstanceSettings() { + return getInstanceSettings; + } + + /** Returns the object with the settings used for calls to listInstances. */ + public UnaryCallSettings listInstancesSettings() { + return listInstancesSettings; + } + + /** Returns the object with the settings used for calls to updateInstance. */ + public UnaryCallSettings updateInstanceSettings() { + return updateInstanceSettings; + } + + /** Returns the object with the settings used for calls to deleteInstance. */ + public UnaryCallSettings deleteInstanceSettings() { + return deleteInstanceSettings; + } + + /** Returns the object with the settings used for calls to createCluster. */ + public UnaryCallSettings createClusterSettings() { + return createClusterSettings; + } + + /** Returns the object with the settings used for calls to createCluster. */ + public OperationCallSettings + createClusterOperationSettings() { + return createClusterOperationSettings; + } + + /** Returns the object with the settings used for calls to getCluster. */ + public UnaryCallSettings getClusterSettings() { + return getClusterSettings; + } + + /** Returns the object with the settings used for calls to listClusters. */ + public UnaryCallSettings listClustersSettings() { + return listClustersSettings; + } + + /** Returns the object with the settings used for calls to updateCluster. */ + public UnaryCallSettings updateClusterSettings() { + return updateClusterSettings; + } + + /** Returns the object with the settings used for calls to updateCluster. */ + public OperationCallSettings + updateClusterOperationSettings() { + return updateClusterOperationSettings; + } + + /** Returns the object with the settings used for calls to deleteCluster. */ + public UnaryCallSettings deleteClusterSettings() { + return deleteClusterSettings; + } + + public BigtableInstanceAdminStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcBigtableInstanceAdminStub.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 "bigtableadmin.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().setEndpoint(getDefaultEndpoint()); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratorHeader(DEFAULT_GAPIC_NAME, getGapicVersion()) + .setApiClientHeaderLineKey("x-goog-api-client") + .addApiClientHeaderLineData(GrpcExtraHeaderData.getXGoogApiClientData()); + } + + private static String getGapicVersion() { + if (gapicVersion == null) { + gapicVersion = + PropertiesProvider.loadProperty( + BigtableInstanceAdminSettings.class, PROPERTIES_FILE, META_VERSION_KEY); + gapicVersion = gapicVersion == null ? DEFAULT_GAPIC_VERSION : gapicVersion; + } + return gapicVersion; + } + + /** Returns a builder for this class with recommended defaults. */ + @Deprecated + public static Builder defaultBuilder() { + return Builder.createDefault(); + } + + /** + * Returns a builder for this class with recommended defaults for API methods, and the given + * ClientContext used for executor/transport/credentials. + */ + @Deprecated + public static Builder defaultBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** 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); + } + + private BigtableInstanceAdminSettings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getExecutorProvider(), + settingsBuilder.getTransportChannelProvider(), + settingsBuilder.getCredentialsProvider(), + settingsBuilder.getHeaderProvider(), + settingsBuilder.getClock()); + + createInstanceSettings = settingsBuilder.createInstanceSettings().build(); + createInstanceOperationSettings = settingsBuilder.createInstanceOperationSettings().build(); + getInstanceSettings = settingsBuilder.getInstanceSettings().build(); + listInstancesSettings = settingsBuilder.listInstancesSettings().build(); + updateInstanceSettings = settingsBuilder.updateInstanceSettings().build(); + deleteInstanceSettings = settingsBuilder.deleteInstanceSettings().build(); + createClusterSettings = settingsBuilder.createClusterSettings().build(); + createClusterOperationSettings = settingsBuilder.createClusterOperationSettings().build(); + getClusterSettings = settingsBuilder.getClusterSettings().build(); + listClustersSettings = settingsBuilder.listClustersSettings().build(); + updateClusterSettings = settingsBuilder.updateClusterSettings().build(); + updateClusterOperationSettings = settingsBuilder.updateClusterOperationSettings().build(); + deleteClusterSettings = settingsBuilder.deleteClusterSettings().build(); + } + + /** Builder for BigtableInstanceAdminSettings. */ + public static class Builder extends ClientSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder + createInstanceSettings; + private final OperationCallSettings.Builder< + CreateInstanceRequest, Instance, CreateInstanceMetadata> + createInstanceOperationSettings; + private final UnaryCallSettings.Builder getInstanceSettings; + private final UnaryCallSettings.Builder + listInstancesSettings; + private final UnaryCallSettings.Builder updateInstanceSettings; + private final UnaryCallSettings.Builder deleteInstanceSettings; + private final UnaryCallSettings.Builder createClusterSettings; + private final OperationCallSettings.Builder< + CreateClusterRequest, Cluster, CreateClusterMetadata> + createClusterOperationSettings; + private final UnaryCallSettings.Builder getClusterSettings; + private final UnaryCallSettings.Builder + listClustersSettings; + private final UnaryCallSettings.Builder updateClusterSettings; + private final OperationCallSettings.Builder + updateClusterOperationSettings; + private final UnaryCallSettings.Builder deleteClusterSettings; + + 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(StatusCode.Code.UNAVAILABLE))); + 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(5L)) + .setRetryDelayMultiplier(2.0) + .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(); + } + + private Builder() { + this((ClientContext) null); + } + + private Builder(ClientContext clientContext) { + super(clientContext); + + createInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createInstanceOperationSettings = OperationCallSettings.newBuilder(); + + getInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listInstancesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + updateInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + deleteInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createClusterSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createClusterOperationSettings = OperationCallSettings.newBuilder(); + + getClusterSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listClustersSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + updateClusterSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + updateClusterOperationSettings = OperationCallSettings.newBuilder(); + + deleteClusterSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createInstanceSettings, + getInstanceSettings, + listInstancesSettings, + updateInstanceSettings, + deleteInstanceSettings, + createClusterSettings, + getClusterSettings, + listClustersSettings, + updateClusterSettings, + deleteClusterSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .createInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listInstancesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .updateInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deleteInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .createClusterSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getClusterSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listClustersSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .updateClusterSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deleteClusterSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + builder + .createInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(CreateInstanceMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + builder + .createClusterOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Cluster.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(CreateClusterMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + builder + .updateClusterOperationSettings() + .setInitialCallSettings( + UnaryCallSettings.newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Cluster.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(UpdateClusterMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + return builder; + } + + private Builder(BigtableInstanceAdminSettings settings) { + super(settings); + + createInstanceSettings = settings.createInstanceSettings.toBuilder(); + createInstanceOperationSettings = settings.createInstanceOperationSettings.toBuilder(); + getInstanceSettings = settings.getInstanceSettings.toBuilder(); + listInstancesSettings = settings.listInstancesSettings.toBuilder(); + updateInstanceSettings = settings.updateInstanceSettings.toBuilder(); + deleteInstanceSettings = settings.deleteInstanceSettings.toBuilder(); + createClusterSettings = settings.createClusterSettings.toBuilder(); + createClusterOperationSettings = settings.createClusterOperationSettings.toBuilder(); + getClusterSettings = settings.getClusterSettings.toBuilder(); + listClustersSettings = settings.listClustersSettings.toBuilder(); + updateClusterSettings = settings.updateClusterSettings.toBuilder(); + updateClusterOperationSettings = settings.updateClusterOperationSettings.toBuilder(); + deleteClusterSettings = settings.deleteClusterSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createInstanceSettings, + getInstanceSettings, + listInstancesSettings, + updateInstanceSettings, + deleteInstanceSettings, + createClusterSettings, + getClusterSettings, + listClustersSettings, + updateClusterSettings, + deleteClusterSettings); + } + + @Override + public Builder setExecutorProvider(ExecutorProvider executorProvider) { + super.setExecutorProvider(executorProvider); + return this; + } + + @Override + public Builder setTransportChannelProvider(TransportChannelProvider transportProvider) { + super.setTransportChannelProvider(transportProvider); + return this; + } + + @Override + public Builder setHeaderProvider(HeaderProvider headerProvider) { + super.setHeaderProvider(headerProvider); + return this; + } + + @Override + public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) { + super.setCredentialsProvider(credentialsProvider); + return this; + } + + /** + * 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; + } + + /** Returns the builder for the settings used for calls to createInstance. */ + public UnaryCallSettings.Builder createInstanceSettings() { + return createInstanceSettings; + } + + /** Returns the builder for the settings used for calls to createInstance. */ + public OperationCallSettings.Builder + createInstanceOperationSettings() { + return createInstanceOperationSettings; + } + + /** Returns the builder for the settings used for calls to getInstance. */ + public UnaryCallSettings.Builder getInstanceSettings() { + return getInstanceSettings; + } + + /** Returns the builder for the settings used for calls to listInstances. */ + public UnaryCallSettings.Builder + listInstancesSettings() { + return listInstancesSettings; + } + + /** Returns the builder for the settings used for calls to updateInstance. */ + public UnaryCallSettings.Builder updateInstanceSettings() { + return updateInstanceSettings; + } + + /** Returns the builder for the settings used for calls to deleteInstance. */ + public UnaryCallSettings.Builder deleteInstanceSettings() { + return deleteInstanceSettings; + } + + /** Returns the builder for the settings used for calls to createCluster. */ + public UnaryCallSettings.Builder createClusterSettings() { + return createClusterSettings; + } + + /** Returns the builder for the settings used for calls to createCluster. */ + public OperationCallSettings.Builder + createClusterOperationSettings() { + return createClusterOperationSettings; + } + + /** Returns the builder for the settings used for calls to getCluster. */ + public UnaryCallSettings.Builder getClusterSettings() { + return getClusterSettings; + } + + /** Returns the builder for the settings used for calls to listClusters. */ + public UnaryCallSettings.Builder + listClustersSettings() { + return listClustersSettings; + } + + /** Returns the builder for the settings used for calls to updateCluster. */ + public UnaryCallSettings.Builder updateClusterSettings() { + return updateClusterSettings; + } + + /** Returns the builder for the settings used for calls to updateCluster. */ + public OperationCallSettings.Builder + updateClusterOperationSettings() { + return updateClusterOperationSettings; + } + + /** Returns the builder for the settings used for calls to deleteCluster. */ + public UnaryCallSettings.Builder deleteClusterSettings() { + return deleteClusterSettings; + } + + @Override + public BigtableInstanceAdminSettings build() throws IOException { + return new BigtableInstanceAdminSettings(this); + } + } +} 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 new file mode 100644 index 000000000000..b1e6e988da79 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -0,0 +1,691 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +import static com.google.cloud.bigtable.admin.v2.PagedResponseWrappers.ListTablesPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.CreateTableRequest; +import com.google.bigtable.admin.v2.DeleteTableRequest; +import com.google.bigtable.admin.v2.DropRowRangeRequest; +import com.google.bigtable.admin.v2.GetTableRequest; +import com.google.bigtable.admin.v2.InstanceName; +import com.google.bigtable.admin.v2.ListTablesRequest; +import com.google.bigtable.admin.v2.ListTablesResponse; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification; +import com.google.bigtable.admin.v2.Table; +import com.google.bigtable.admin.v2.TableName; +import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub; +import com.google.protobuf.ByteString; +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: Service for creating, configuring, and deleting Cloud Bigtable tables. + * + *

Provides access to the table schemas only, not the data stored within the tables. + * + *

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 (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+ *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+ *   String tableId = "";
+ *   Table table = Table.newBuilder().build();
+ *   Table response = bigtableTableAdminClient.createTable(parent, tableId, table);
+ * }
+ * 
+ * 
+ * + *

Note: close() needs to be called on the bigtableTableAdminClient 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 BigtableTableAdminSettings to + * create(). For example: + * + *

To customize credentials: + * + *

+ * 
+ * BigtableTableAdminSettings bigtableTableAdminSettings =
+ *     BigtableTableAdminSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * BigtableTableAdminClient bigtableTableAdminClient =
+ *     BigtableTableAdminClient.create(bigtableTableAdminSettings);
+ * 
+ * 
+ * + * To customize the endpoint: + * + *
+ * 
+ * BigtableTableAdminSettings bigtableTableAdminSettings =
+ *     BigtableTableAdminSettings.newBuilder()
+ *         .setTransportChannelProvider(BigtableTableAdminSettings.defaultGrpcTransportProviderBuilder()
+ *             .setEndpoint(myEndpoint)
+ *             .build())
+ *         .build();
+ * BigtableTableAdminClient bigtableTableAdminClient =
+ *     BigtableTableAdminClient.create(bigtableTableAdminSettings);
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class BigtableTableAdminClient implements BackgroundResource { + private final BigtableTableAdminSettings settings; + private final BigtableTableAdminStub stub; + + /** Constructs an instance of BigtableTableAdminClient with default settings. */ + public static final BigtableTableAdminClient create() throws IOException { + return create(BigtableTableAdminSettings.newBuilder().build()); + } + + /** + * Constructs an instance of BigtableTableAdminClient, 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 BigtableTableAdminClient create(BigtableTableAdminSettings settings) + throws IOException { + return new BigtableTableAdminClient(settings); + } + + /** + * Constructs an instance of BigtableTableAdminClient, using the given stub for making calls. This + * is for advanced usage - prefer to use BigtableTableAdminSettings}. + */ + @BetaApi + public static final BigtableTableAdminClient create(BigtableTableAdminStub stub) { + return new BigtableTableAdminClient(stub); + } + + /** + * Constructs an instance of BigtableTableAdminClient, 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 BigtableTableAdminClient(BigtableTableAdminSettings settings) throws IOException { + this.settings = settings; + this.stub = settings.createStub(); + } + + protected BigtableTableAdminClient(BigtableTableAdminStub stub) { + this.settings = null; + this.stub = stub; + } + + public final BigtableTableAdminSettings getSettings() { + return settings; + } + + @BetaApi + public BigtableTableAdminStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a new table in the specified instance. The table can be created with a full set of + * initial column families, specified in the request. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String tableId = "";
+   *   Table table = Table.newBuilder().build();
+   *   Table response = bigtableTableAdminClient.createTable(parent, tableId, table);
+   * }
+   * 
+ * + * @param parent The unique name of the instance in which to create the table. Values are of the + * form `projects/<project>/instances/<instance>`. + * @param tableId The name by which the new table should be referred to within the parent + * instance, e.g., `foobar` rather than `<parent>/tables/foobar`. + * @param table The Table to create. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Table createTable(InstanceName parent, String tableId, Table table) { + + CreateTableRequest request = + CreateTableRequest.newBuilder() + .setParentWithInstanceName(parent) + .setTableId(tableId) + .setTable(table) + .build(); + return createTable(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a new table in the specified instance. The table can be created with a full set of + * initial column families, specified in the request. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String tableId = "";
+   *   Table table = Table.newBuilder().build();
+   *   CreateTableRequest request = CreateTableRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .setTableId(tableId)
+   *     .setTable(table)
+   *     .build();
+   *   Table response = bigtableTableAdminClient.createTable(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 Table createTable(CreateTableRequest request) { + return createTableCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a new table in the specified instance. The table can be created with a full set of + * initial column families, specified in the request. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   String tableId = "";
+   *   Table table = Table.newBuilder().build();
+   *   CreateTableRequest request = CreateTableRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .setTableId(tableId)
+   *     .setTable(table)
+   *     .build();
+   *   ApiFuture<Table> future = bigtableTableAdminClient.createTableCallable().futureCall(request);
+   *   // Do something
+   *   Table response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable createTableCallable() { + return stub.createTableCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all tables served from a specified instance. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   for (Table element : bigtableTableAdminClient.listTables(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @param parent The unique name of the instance for which tables should be listed. Values are of + * the form `projects/<project>/instances/<instance>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListTablesPagedResponse listTables(InstanceName parent) { + ListTablesRequest request = + ListTablesRequest.newBuilder().setParentWithInstanceName(parent).build(); + return listTables(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all tables served from a specified instance. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   ListTablesRequest request = ListTablesRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .build();
+   *   for (Table element : bigtableTableAdminClient.listTables(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 + */ + private final ListTablesPagedResponse listTables(ListTablesRequest request) { + return listTablesPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all tables served from a specified instance. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   ListTablesRequest request = ListTablesRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .build();
+   *   ApiFuture<ListTablesPagedResponse> future = bigtableTableAdminClient.listTablesPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (Table element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ */ + public final UnaryCallable listTablesPagedCallable() { + return stub.listTablesPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all tables served from a specified instance. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   *   ListTablesRequest request = ListTablesRequest.newBuilder()
+   *     .setParentWithInstanceName(parent)
+   *     .build();
+   *   while (true) {
+   *     ListTablesResponse response = bigtableTableAdminClient.listTablesCallable().call(request);
+   *     for (Table element : response.getTablesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ */ + public final UnaryCallable listTablesCallable() { + return stub.listTablesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets metadata information about the specified table. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   Table response = bigtableTableAdminClient.getTable(name);
+   * }
+   * 
+ * + * @param name The unique name of the requested table. Values are of the form + * `projects/<project>/instances/<instance>/tables/<table>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Table getTable(TableName name) { + + GetTableRequest request = GetTableRequest.newBuilder().setNameWithTableName(name).build(); + return getTable(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets metadata information about the specified table. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   GetTableRequest request = GetTableRequest.newBuilder()
+   *     .setNameWithTableName(name)
+   *     .build();
+   *   Table response = bigtableTableAdminClient.getTable(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 Table getTable(GetTableRequest request) { + return getTableCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets metadata information about the specified table. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   GetTableRequest request = GetTableRequest.newBuilder()
+   *     .setNameWithTableName(name)
+   *     .build();
+   *   ApiFuture<Table> future = bigtableTableAdminClient.getTableCallable().futureCall(request);
+   *   // Do something
+   *   Table response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable getTableCallable() { + return stub.getTableCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Permanently deletes a specified table and all of its data. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   bigtableTableAdminClient.deleteTable(name);
+   * }
+   * 
+ * + * @param name The unique name of the table to be deleted. Values are of the form + * `projects/<project>/instances/<instance>/tables/<table>`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteTable(TableName name) { + + DeleteTableRequest request = DeleteTableRequest.newBuilder().setNameWithTableName(name).build(); + deleteTable(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Permanently deletes a specified table and all of its data. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   DeleteTableRequest request = DeleteTableRequest.newBuilder()
+   *     .setNameWithTableName(name)
+   *     .build();
+   *   bigtableTableAdminClient.deleteTable(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 void deleteTable(DeleteTableRequest request) { + deleteTableCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Permanently deletes a specified table and all of its data. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   DeleteTableRequest request = DeleteTableRequest.newBuilder()
+   *     .setNameWithTableName(name)
+   *     .build();
+   *   ApiFuture<Void> future = bigtableTableAdminClient.deleteTableCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ */ + public final UnaryCallable deleteTableCallable() { + return stub.deleteTableCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Performs a series of column family modifications on the specified table. Either all or none of + * the modifications will occur before this method returns, but data requests received prior to + * that point may see a table where only some modifications have taken effect. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>();
+   *   Table response = bigtableTableAdminClient.modifyColumnFamilies(name, modifications);
+   * }
+   * 
+ * + * @param name The unique name of the table whose families should be modified. Values are of the + * form `projects/<project>/instances/<instance>/tables/<table>`. + * @param modifications Modifications to be atomically applied to the specified table's families. + * Entries are applied in order, meaning that earlier modifications can be masked by later + * ones (in the case of repeated updates to the same family, for example). + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Table modifyColumnFamilies( + TableName name, List modifications) { + + ModifyColumnFamiliesRequest request = + ModifyColumnFamiliesRequest.newBuilder() + .setNameWithTableName(name) + .addAllModifications(modifications) + .build(); + return modifyColumnFamilies(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Performs a series of column family modifications on the specified table. Either all or none of + * the modifications will occur before this method returns, but data requests received prior to + * that point may see a table where only some modifications have taken effect. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>();
+   *   ModifyColumnFamiliesRequest request = ModifyColumnFamiliesRequest.newBuilder()
+   *     .setNameWithTableName(name)
+   *     .addAllModifications(modifications)
+   *     .build();
+   *   Table response = bigtableTableAdminClient.modifyColumnFamilies(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 Table modifyColumnFamilies(ModifyColumnFamiliesRequest request) { + return modifyColumnFamiliesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Performs a series of column family modifications on the specified table. Either all or none of + * the modifications will occur before this method returns, but data requests received prior to + * that point may see a table where only some modifications have taken effect. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>();
+   *   ModifyColumnFamiliesRequest request = ModifyColumnFamiliesRequest.newBuilder()
+   *     .setNameWithTableName(name)
+   *     .addAllModifications(modifications)
+   *     .build();
+   *   ApiFuture<Table> future = bigtableTableAdminClient.modifyColumnFamiliesCallable().futureCall(request);
+   *   // Do something
+   *   Table response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable modifyColumnFamiliesCallable() { + return stub.modifyColumnFamiliesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Permanently drop/delete a row range from a specified table. The request can specify whether to + * delete all rows in a table, or only those that match a particular prefix. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   String formattedName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString();
+   *   ByteString rowKeyPrefix = ByteString.copyFromUtf8("");
+   *   bigtableTableAdminClient.dropRowRange(formattedName, rowKeyPrefix);
+   * }
+   * 
+ * + * @param name The unique name of the table on which to drop a range of rows. Values are of the + * form `projects/<project>/instances/<instance>/tables/<table>`. + * @param rowKeyPrefix Delete all rows that start with this row key prefix. Prefix cannot be zero + * length. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void dropRowRange(String name, ByteString rowKeyPrefix) { + + DropRowRangeRequest request = + DropRowRangeRequest.newBuilder().setName(name).setRowKeyPrefix(rowKeyPrefix).build(); + dropRowRange(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Permanently drop/delete a row range from a specified table. The request can specify whether to + * delete all rows in a table, or only those that match a particular prefix. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   String formattedName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString();
+   *   DropRowRangeRequest request = DropRowRangeRequest.newBuilder()
+   *     .setName(formattedName)
+   *     .build();
+   *   bigtableTableAdminClient.dropRowRange(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 dropRowRange(DropRowRangeRequest request) { + dropRowRangeCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Permanently drop/delete a row range from a specified table. The request can specify whether to + * delete all rows in a table, or only those that match a particular prefix. + * + *

Sample code: + * + *


+   * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+   *   String formattedName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString();
+   *   DropRowRangeRequest request = DropRowRangeRequest.newBuilder()
+   *     .setName(formattedName)
+   *     .build();
+   *   ApiFuture<Void> future = bigtableTableAdminClient.dropRowRangeCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ */ + public final UnaryCallable dropRowRangeCallable() { + return stub.dropRowRangeCallable(); + } + + @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-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 new file mode 100644 index 000000000000..939c1a6f111a --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java @@ -0,0 +1,526 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +import static com.google.cloud.bigtable.admin.v2.PagedResponseWrappers.ListTablesPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.ExecutorProvider; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.core.PropertiesProvider; +import com.google.api.gax.grpc.GrpcExtraHeaderData; +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.ClientSettings; +import com.google.api.gax.rpc.HeaderProvider; +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.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.CreateTableRequest; +import com.google.bigtable.admin.v2.DeleteTableRequest; +import com.google.bigtable.admin.v2.DropRowRangeRequest; +import com.google.bigtable.admin.v2.GetTableRequest; +import com.google.bigtable.admin.v2.ListTablesRequest; +import com.google.bigtable.admin.v2.ListTablesResponse; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; +import com.google.bigtable.admin.v2.Table; +import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub; +import com.google.cloud.bigtable.admin.v2.stub.GrpcBigtableTableAdminStub; +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.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 BigtableTableAdminClient}. + * + *

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

    + *
  • The default service address (bigtableadmin.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 createTable to 30 seconds: + * + *

+ * 
+ * BigtableTableAdminSettings.Builder bigtableTableAdminSettingsBuilder =
+ *     BigtableTableAdminSettings.newBuilder();
+ * bigtableTableAdminSettingsBuilder.createTableSettings().getRetrySettingsBuilder()
+ *     .setTotalTimeout(Duration.ofSeconds(30));
+ * BigtableTableAdminSettings bigtableTableAdminSettings = bigtableTableAdminSettingsBuilder.build();
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class BigtableTableAdminSettings extends ClientSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/bigtable.admin") + .add("https://www.googleapis.com/auth/bigtable.admin.cluster") + .add("https://www.googleapis.com/auth/bigtable.admin.instance") + .add("https://www.googleapis.com/auth/bigtable.admin.table") + .add("https://www.googleapis.com/auth/cloud-bigtable.admin") + .add("https://www.googleapis.com/auth/cloud-bigtable.admin.cluster") + .add("https://www.googleapis.com/auth/cloud-bigtable.admin.table") + .add("https://www.googleapis.com/auth/cloud-platform") + .add("https://www.googleapis.com/auth/cloud-platform.read-only") + .build(); + + private static final String DEFAULT_GAPIC_NAME = "gapic"; + private static final String DEFAULT_GAPIC_VERSION = ""; + + private static final String PROPERTIES_FILE = + "/com/google/cloud/bigtable/admin/project.properties"; + private static final String META_VERSION_KEY = "artifact.version"; + + private static String gapicVersion; + + private final UnaryCallSettings createTableSettings; + private final PagedCallSettings + listTablesSettings; + private final UnaryCallSettings getTableSettings; + private final UnaryCallSettings deleteTableSettings; + private final UnaryCallSettings modifyColumnFamiliesSettings; + private final UnaryCallSettings dropRowRangeSettings; + + /** Returns the object with the settings used for calls to createTable. */ + public UnaryCallSettings createTableSettings() { + return createTableSettings; + } + + /** Returns the object with the settings used for calls to listTables. */ + public PagedCallSettings + listTablesSettings() { + return listTablesSettings; + } + + /** Returns the object with the settings used for calls to getTable. */ + public UnaryCallSettings getTableSettings() { + return getTableSettings; + } + + /** Returns the object with the settings used for calls to deleteTable. */ + public UnaryCallSettings deleteTableSettings() { + return deleteTableSettings; + } + + /** Returns the object with the settings used for calls to modifyColumnFamilies. */ + public UnaryCallSettings modifyColumnFamiliesSettings() { + return modifyColumnFamiliesSettings; + } + + /** Returns the object with the settings used for calls to dropRowRange. */ + public UnaryCallSettings dropRowRangeSettings() { + return dropRowRangeSettings; + } + + public BigtableTableAdminStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcBigtableTableAdminStub.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 "bigtableadmin.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().setEndpoint(getDefaultEndpoint()); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratorHeader(DEFAULT_GAPIC_NAME, getGapicVersion()) + .setApiClientHeaderLineKey("x-goog-api-client") + .addApiClientHeaderLineData(GrpcExtraHeaderData.getXGoogApiClientData()); + } + + private static String getGapicVersion() { + if (gapicVersion == null) { + gapicVersion = + PropertiesProvider.loadProperty( + BigtableTableAdminSettings.class, PROPERTIES_FILE, META_VERSION_KEY); + gapicVersion = gapicVersion == null ? DEFAULT_GAPIC_VERSION : gapicVersion; + } + return gapicVersion; + } + + /** Returns a builder for this class with recommended defaults. */ + @Deprecated + public static Builder defaultBuilder() { + return Builder.createDefault(); + } + + /** + * Returns a builder for this class with recommended defaults for API methods, and the given + * ClientContext used for executor/transport/credentials. + */ + @Deprecated + public static Builder defaultBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** 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); + } + + private BigtableTableAdminSettings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getExecutorProvider(), + settingsBuilder.getTransportChannelProvider(), + settingsBuilder.getCredentialsProvider(), + settingsBuilder.getHeaderProvider(), + settingsBuilder.getClock()); + + createTableSettings = settingsBuilder.createTableSettings().build(); + listTablesSettings = settingsBuilder.listTablesSettings().build(); + getTableSettings = settingsBuilder.getTableSettings().build(); + deleteTableSettings = settingsBuilder.deleteTableSettings().build(); + modifyColumnFamiliesSettings = settingsBuilder.modifyColumnFamiliesSettings().build(); + dropRowRangeSettings = settingsBuilder.dropRowRangeSettings().build(); + } + + private static final PagedListDescriptor + LIST_TABLES_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListTablesRequest injectToken(ListTablesRequest payload, String token) { + return ListTablesRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListTablesRequest injectPageSize(ListTablesRequest payload, int pageSize) { + throw new UnsupportedOperationException( + "page size is not supported by this API method"); + } + + @Override + public Integer extractPageSize(ListTablesRequest payload) { + throw new UnsupportedOperationException( + "page size is not supported by this API method"); + } + + @Override + public String extractNextToken(ListTablesResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListTablesResponse payload) { + return payload.getTablesList(); + } + }; + + private static final PagedListResponseFactory< + ListTablesRequest, ListTablesResponse, ListTablesPagedResponse> + LIST_TABLES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListTablesRequest, ListTablesResponse, ListTablesPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListTablesRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_TABLES_PAGE_STR_DESC, request, context); + return ListTablesPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Builder for BigtableTableAdminSettings. */ + public static class Builder extends ClientSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder createTableSettings; + private final PagedCallSettings.Builder< + ListTablesRequest, ListTablesResponse, ListTablesPagedResponse> + listTablesSettings; + private final UnaryCallSettings.Builder getTableSettings; + private final UnaryCallSettings.Builder deleteTableSettings; + private final UnaryCallSettings.Builder + modifyColumnFamiliesSettings; + private final UnaryCallSettings.Builder dropRowRangeSettings; + + 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(); + } + + private Builder() { + this((ClientContext) null); + } + + private Builder(ClientContext clientContext) { + super(clientContext); + + createTableSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + listTablesSettings = PagedCallSettings.newBuilder(LIST_TABLES_PAGE_STR_FACT); + + getTableSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + deleteTableSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + modifyColumnFamiliesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + dropRowRangeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createTableSettings, + listTablesSettings, + getTableSettings, + deleteTableSettings, + modifyColumnFamiliesSettings, + dropRowRangeSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .createTableSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .listTablesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getTableSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .deleteTableSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .modifyColumnFamiliesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .dropRowRangeSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + return builder; + } + + private Builder(BigtableTableAdminSettings settings) { + super(settings); + + createTableSettings = settings.createTableSettings.toBuilder(); + listTablesSettings = settings.listTablesSettings.toBuilder(); + getTableSettings = settings.getTableSettings.toBuilder(); + deleteTableSettings = settings.deleteTableSettings.toBuilder(); + modifyColumnFamiliesSettings = settings.modifyColumnFamiliesSettings.toBuilder(); + dropRowRangeSettings = settings.dropRowRangeSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createTableSettings, + listTablesSettings, + getTableSettings, + deleteTableSettings, + modifyColumnFamiliesSettings, + dropRowRangeSettings); + } + + @Override + public Builder setExecutorProvider(ExecutorProvider executorProvider) { + super.setExecutorProvider(executorProvider); + return this; + } + + @Override + public Builder setTransportChannelProvider(TransportChannelProvider transportProvider) { + super.setTransportChannelProvider(transportProvider); + return this; + } + + @Override + public Builder setHeaderProvider(HeaderProvider headerProvider) { + super.setHeaderProvider(headerProvider); + return this; + } + + @Override + public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) { + super.setCredentialsProvider(credentialsProvider); + return this; + } + + /** + * 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; + } + + /** Returns the builder for the settings used for calls to createTable. */ + public UnaryCallSettings.Builder createTableSettings() { + return createTableSettings; + } + + /** Returns the builder for the settings used for calls to listTables. */ + public PagedCallSettings.Builder + listTablesSettings() { + return listTablesSettings; + } + + /** Returns the builder for the settings used for calls to getTable. */ + public UnaryCallSettings.Builder getTableSettings() { + return getTableSettings; + } + + /** Returns the builder for the settings used for calls to deleteTable. */ + public UnaryCallSettings.Builder deleteTableSettings() { + return deleteTableSettings; + } + + /** Returns the builder for the settings used for calls to modifyColumnFamilies. */ + public UnaryCallSettings.Builder + modifyColumnFamiliesSettings() { + return modifyColumnFamiliesSettings; + } + + /** Returns the builder for the settings used for calls to dropRowRange. */ + public UnaryCallSettings.Builder dropRowRangeSettings() { + return dropRowRangeSettings; + } + + @Override + public BigtableTableAdminSettings build() throws IOException { + return new BigtableTableAdminSettings(this); + } + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/PagedResponseWrappers.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/PagedResponseWrappers.java new file mode 100644 index 000000000000..de395857e7fb --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/PagedResponseWrappers.java @@ -0,0 +1,114 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.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.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.bigtable.admin.v2.ListTablesRequest; +import com.google.bigtable.admin.v2.ListTablesResponse; +import com.google.bigtable.admin.v2.Table; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Wrapper class to contain paged response types for page streaming methods. Each static class + * inside this wrapper class is used as the return type of one of an API method that implements the + * page streaming pattern. + */ +@Generated("by GAPIC") +@BetaApi +public class PagedResponseWrappers { + + public static class ListTablesPagedResponse + extends AbstractPagedListResponse< + ListTablesRequest, ListTablesResponse, Table, ListTablesPage, + ListTablesFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListTablesPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListTablesPagedResponse apply(ListTablesPage input) { + return new ListTablesPagedResponse(input); + } + }); + } + + private ListTablesPagedResponse(ListTablesPage page) { + super(page, ListTablesFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListTablesPage + extends AbstractPage { + + private ListTablesPage( + PageContext context, + ListTablesResponse response) { + super(context, response); + } + + private static ListTablesPage createEmptyPage() { + return new ListTablesPage(null, null); + } + + @Override + protected ListTablesPage createPage( + PageContext context, + ListTablesResponse response) { + return new ListTablesPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListTablesFixedSizeCollection + extends AbstractFixedSizeCollection< + ListTablesRequest, ListTablesResponse, Table, ListTablesPage, + ListTablesFixedSizeCollection> { + + private ListTablesFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListTablesFixedSizeCollection createEmptyCollection() { + return new ListTablesFixedSizeCollection(null, 0); + } + + @Override + protected ListTablesFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListTablesFixedSizeCollection(pages, collectionSize); + } + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/package-info.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/package-info.java new file mode 100644 index 000000000000..5e1fa640826b --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/package-info.java @@ -0,0 +1,58 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A client to Cloud Bigtable Admin API. + * + *

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

=========================== BigtableInstanceAdminClient =========================== + * + *

Service Description: Service for creating, configuring, and deleting Cloud Bigtable Instances + * and Clusters. Provides access to the Instance and Cluster schemas only, not the tables' metadata + * or data stored in those tables. + * + *

Sample for BigtableInstanceAdminClient: + * + *

+ * 
+ * try (BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.create()) {
+ *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
+ *   Instance response = bigtableInstanceAdminClient.getInstance(name);
+ * }
+ * 
+ * 
+ * + * ======================== BigtableTableAdminClient ======================== + * + *

Service Description: Service for creating, configuring, and deleting Cloud Bigtable tables. + * + *

Provides access to the table schemas only, not the data stored within the tables. + * + *

Sample for BigtableTableAdminClient: + * + *

+ * 
+ * try (BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.create()) {
+ *   InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
+ *   String tableId = "";
+ *   Table table = Table.newBuilder().build();
+ *   Table response = bigtableTableAdminClient.createTable(parent, tableId, table);
+ * }
+ * 
+ * 
+ */ +package com.google.cloud.bigtable.admin.v2; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStub.java new file mode 100644 index 000000000000..fefdfa29388f --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStub.java @@ -0,0 +1,110 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2.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.bigtable.admin.v2.Cluster; +import com.google.bigtable.admin.v2.CreateClusterMetadata; +import com.google.bigtable.admin.v2.CreateClusterRequest; +import com.google.bigtable.admin.v2.CreateInstanceMetadata; +import com.google.bigtable.admin.v2.CreateInstanceRequest; +import com.google.bigtable.admin.v2.DeleteClusterRequest; +import com.google.bigtable.admin.v2.DeleteInstanceRequest; +import com.google.bigtable.admin.v2.GetClusterRequest; +import com.google.bigtable.admin.v2.GetInstanceRequest; +import com.google.bigtable.admin.v2.Instance; +import com.google.bigtable.admin.v2.ListClustersRequest; +import com.google.bigtable.admin.v2.ListClustersResponse; +import com.google.bigtable.admin.v2.ListInstancesRequest; +import com.google.bigtable.admin.v2.ListInstancesResponse; +import com.google.bigtable.admin.v2.UpdateClusterMetadata; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import com.google.protobuf.Empty; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Cloud Bigtable Admin API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public abstract class BigtableInstanceAdminStub implements BackgroundResource { + + public OperationsStub getOperationsStub() { + throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + } + + public OperationCallable + createInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: createInstanceOperationCallable()"); + } + + public UnaryCallable createInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: createInstanceCallable()"); + } + + public UnaryCallable getInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: getInstanceCallable()"); + } + + public UnaryCallable listInstancesCallable() { + throw new UnsupportedOperationException("Not implemented: listInstancesCallable()"); + } + + public UnaryCallable updateInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: updateInstanceCallable()"); + } + + public UnaryCallable deleteInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: deleteInstanceCallable()"); + } + + public OperationCallable + createClusterOperationCallable() { + throw new UnsupportedOperationException("Not implemented: createClusterOperationCallable()"); + } + + public UnaryCallable createClusterCallable() { + throw new UnsupportedOperationException("Not implemented: createClusterCallable()"); + } + + public UnaryCallable getClusterCallable() { + throw new UnsupportedOperationException("Not implemented: getClusterCallable()"); + } + + public UnaryCallable listClustersCallable() { + throw new UnsupportedOperationException("Not implemented: listClustersCallable()"); + } + + public OperationCallable + updateClusterOperationCallable() { + throw new UnsupportedOperationException("Not implemented: updateClusterOperationCallable()"); + } + + public UnaryCallable updateClusterCallable() { + throw new UnsupportedOperationException("Not implemented: updateClusterCallable()"); + } + + public UnaryCallable deleteClusterCallable() { + throw new UnsupportedOperationException("Not implemented: deleteClusterCallable()"); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStub.java new file mode 100644 index 000000000000..1607126767d4 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStub.java @@ -0,0 +1,71 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2.stub; + +import static com.google.cloud.bigtable.admin.v2.PagedResponseWrappers.ListTablesPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.CreateTableRequest; +import com.google.bigtable.admin.v2.DeleteTableRequest; +import com.google.bigtable.admin.v2.DropRowRangeRequest; +import com.google.bigtable.admin.v2.GetTableRequest; +import com.google.bigtable.admin.v2.ListTablesRequest; +import com.google.bigtable.admin.v2.ListTablesResponse; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; +import com.google.bigtable.admin.v2.Table; +import com.google.protobuf.Empty; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Cloud Bigtable Admin API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public abstract class BigtableTableAdminStub implements BackgroundResource { + + public UnaryCallable createTableCallable() { + throw new UnsupportedOperationException("Not implemented: createTableCallable()"); + } + + public UnaryCallable listTablesPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listTablesPagedCallable()"); + } + + public UnaryCallable listTablesCallable() { + throw new UnsupportedOperationException("Not implemented: listTablesCallable()"); + } + + public UnaryCallable getTableCallable() { + throw new UnsupportedOperationException("Not implemented: getTableCallable()"); + } + + public UnaryCallable deleteTableCallable() { + throw new UnsupportedOperationException("Not implemented: deleteTableCallable()"); + } + + public UnaryCallable modifyColumnFamiliesCallable() { + throw new UnsupportedOperationException("Not implemented: modifyColumnFamiliesCallable()"); + } + + public UnaryCallable dropRowRangeCallable() { + throw new UnsupportedOperationException("Not implemented: dropRowRangeCallable()"); + } +} 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 new file mode 100644 index 000000000000..a93cb24cede1 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java @@ -0,0 +1,364 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2.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.GrpcCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.Cluster; +import com.google.bigtable.admin.v2.CreateClusterMetadata; +import com.google.bigtable.admin.v2.CreateClusterRequest; +import com.google.bigtable.admin.v2.CreateInstanceMetadata; +import com.google.bigtable.admin.v2.CreateInstanceRequest; +import com.google.bigtable.admin.v2.DeleteClusterRequest; +import com.google.bigtable.admin.v2.DeleteInstanceRequest; +import com.google.bigtable.admin.v2.GetClusterRequest; +import com.google.bigtable.admin.v2.GetInstanceRequest; +import com.google.bigtable.admin.v2.Instance; +import com.google.bigtable.admin.v2.ListClustersRequest; +import com.google.bigtable.admin.v2.ListClustersResponse; +import com.google.bigtable.admin.v2.ListInstancesRequest; +import com.google.bigtable.admin.v2.ListInstancesResponse; +import com.google.bigtable.admin.v2.UpdateClusterMetadata; +import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings; +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.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC stub implementation for Cloud Bigtable Admin API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class GrpcBigtableInstanceAdminStub extends BigtableInstanceAdminStub { + + private static final MethodDescriptor + createInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/CreateInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor getInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/GetInstance") + .setRequestMarshaller(ProtoUtils.marshaller(GetInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Instance.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listInstancesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/ListInstances") + .setRequestMarshaller( + ProtoUtils.marshaller(ListInstancesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListInstancesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor updateInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/UpdateInstance") + .setRequestMarshaller(ProtoUtils.marshaller(Instance.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Instance.getDefaultInstance())) + .build(); + private static final MethodDescriptor + deleteInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/DeleteInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(DeleteInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor + createClusterMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/CreateCluster") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateClusterRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor getClusterMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/GetCluster") + .setRequestMarshaller(ProtoUtils.marshaller(GetClusterRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Cluster.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listClustersMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/ListClusters") + .setRequestMarshaller(ProtoUtils.marshaller(ListClustersRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListClustersResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor updateClusterMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/UpdateCluster") + .setRequestMarshaller(ProtoUtils.marshaller(Cluster.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor deleteClusterMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableInstanceAdmin/DeleteCluster") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteClusterRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + + private final UnaryCallable createInstanceCallable; + private final OperationCallable + createInstanceOperationCallable; + private final UnaryCallable getInstanceCallable; + private final UnaryCallable listInstancesCallable; + private final UnaryCallable updateInstanceCallable; + private final UnaryCallable deleteInstanceCallable; + private final UnaryCallable createClusterCallable; + private final OperationCallable + createClusterOperationCallable; + private final UnaryCallable getClusterCallable; + private final UnaryCallable listClustersCallable; + private final UnaryCallable updateClusterCallable; + private final OperationCallable + updateClusterOperationCallable; + private final UnaryCallable deleteClusterCallable; + + public static final GrpcBigtableInstanceAdminStub create(BigtableInstanceAdminSettings settings) + throws IOException { + return new GrpcBigtableInstanceAdminStub(settings, ClientContext.create(settings)); + } + + public static final GrpcBigtableInstanceAdminStub create(ClientContext clientContext) + throws IOException { + return new GrpcBigtableInstanceAdminStub( + BigtableInstanceAdminSettings.newBuilder().build(), clientContext); + } + + /** + * 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( + BigtableInstanceAdminSettings settings, ClientContext clientContext) throws IOException { + this.operationsStub = GrpcOperationsStub.create(clientContext); + + GrpcCallSettings createInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createInstanceMethodDescriptor) + .build(); + GrpcCallSettings getInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getInstanceMethodDescriptor) + .build(); + GrpcCallSettings listInstancesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listInstancesMethodDescriptor) + .build(); + GrpcCallSettings updateInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateInstanceMethodDescriptor) + .build(); + GrpcCallSettings deleteInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteInstanceMethodDescriptor) + .build(); + GrpcCallSettings createClusterTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createClusterMethodDescriptor) + .build(); + GrpcCallSettings getClusterTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getClusterMethodDescriptor) + .build(); + GrpcCallSettings listClustersTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listClustersMethodDescriptor) + .build(); + GrpcCallSettings updateClusterTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateClusterMethodDescriptor) + .build(); + GrpcCallSettings deleteClusterTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteClusterMethodDescriptor) + .build(); + + this.createInstanceCallable = + GrpcCallableFactory.createUnaryCallable( + createInstanceTransportSettings, settings.createInstanceSettings(), clientContext); + this.createInstanceOperationCallable = + GrpcCallableFactory.createOperationCallable( + createInstanceTransportSettings, + settings.createInstanceOperationSettings(), + clientContext, + this.operationsStub); + this.getInstanceCallable = + GrpcCallableFactory.createUnaryCallable( + getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); + this.listInstancesCallable = + GrpcCallableFactory.createUnaryCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.updateInstanceCallable = + GrpcCallableFactory.createUnaryCallable( + updateInstanceTransportSettings, settings.updateInstanceSettings(), clientContext); + this.deleteInstanceCallable = + GrpcCallableFactory.createUnaryCallable( + deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); + this.createClusterCallable = + GrpcCallableFactory.createUnaryCallable( + createClusterTransportSettings, settings.createClusterSettings(), clientContext); + this.createClusterOperationCallable = + GrpcCallableFactory.createOperationCallable( + createClusterTransportSettings, + settings.createClusterOperationSettings(), + clientContext, + this.operationsStub); + this.getClusterCallable = + GrpcCallableFactory.createUnaryCallable( + getClusterTransportSettings, settings.getClusterSettings(), clientContext); + this.listClustersCallable = + GrpcCallableFactory.createUnaryCallable( + listClustersTransportSettings, settings.listClustersSettings(), clientContext); + this.updateClusterCallable = + GrpcCallableFactory.createUnaryCallable( + updateClusterTransportSettings, settings.updateClusterSettings(), clientContext); + this.updateClusterOperationCallable = + GrpcCallableFactory.createOperationCallable( + updateClusterTransportSettings, + settings.updateClusterOperationSettings(), + clientContext, + this.operationsStub); + this.deleteClusterCallable = + GrpcCallableFactory.createUnaryCallable( + deleteClusterTransportSettings, settings.deleteClusterSettings(), clientContext); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + public OperationCallable + createInstanceOperationCallable() { + return createInstanceOperationCallable; + } + + public UnaryCallable createInstanceCallable() { + return createInstanceCallable; + } + + public UnaryCallable getInstanceCallable() { + return getInstanceCallable; + } + + public UnaryCallable listInstancesCallable() { + return listInstancesCallable; + } + + public UnaryCallable updateInstanceCallable() { + return updateInstanceCallable; + } + + public UnaryCallable deleteInstanceCallable() { + return deleteInstanceCallable; + } + + public OperationCallable + createClusterOperationCallable() { + return createClusterOperationCallable; + } + + public UnaryCallable createClusterCallable() { + return createClusterCallable; + } + + public UnaryCallable getClusterCallable() { + return getClusterCallable; + } + + public UnaryCallable listClustersCallable() { + return listClustersCallable; + } + + public OperationCallable + updateClusterOperationCallable() { + return updateClusterOperationCallable; + } + + public UnaryCallable updateClusterCallable() { + return updateClusterCallable; + } + + public UnaryCallable deleteClusterCallable() { + return deleteClusterCallable; + } + + @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-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 new file mode 100644 index 000000000000..bdf2f1d52389 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java @@ -0,0 +1,237 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2.stub; + +import static com.google.cloud.bigtable.admin.v2.PagedResponseWrappers.ListTablesPagedResponse; + +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.GrpcCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.admin.v2.CreateTableRequest; +import com.google.bigtable.admin.v2.DeleteTableRequest; +import com.google.bigtable.admin.v2.DropRowRangeRequest; +import com.google.bigtable.admin.v2.GetTableRequest; +import com.google.bigtable.admin.v2.ListTablesRequest; +import com.google.bigtable.admin.v2.ListTablesResponse; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; +import com.google.bigtable.admin.v2.Table; +import com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings; +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 Bigtable Admin API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class GrpcBigtableTableAdminStub extends BigtableTableAdminStub { + + private static final MethodDescriptor createTableMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableTableAdmin/CreateTable") + .setRequestMarshaller(ProtoUtils.marshaller(CreateTableRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Table.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listTablesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableTableAdmin/ListTables") + .setRequestMarshaller(ProtoUtils.marshaller(ListTablesRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListTablesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor getTableMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableTableAdmin/GetTable") + .setRequestMarshaller(ProtoUtils.marshaller(GetTableRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Table.getDefaultInstance())) + .build(); + private static final MethodDescriptor deleteTableMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableTableAdmin/DeleteTable") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteTableRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private static final MethodDescriptor + modifyColumnFamiliesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableTableAdmin/ModifyColumnFamilies") + .setRequestMarshaller( + ProtoUtils.marshaller(ModifyColumnFamiliesRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Table.getDefaultInstance())) + .build(); + private static final MethodDescriptor dropRowRangeMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.admin.v2.BigtableTableAdmin/DropRowRange") + .setRequestMarshaller(ProtoUtils.marshaller(DropRowRangeRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + + private final UnaryCallable createTableCallable; + private final UnaryCallable listTablesCallable; + private final UnaryCallable listTablesPagedCallable; + private final UnaryCallable getTableCallable; + private final UnaryCallable deleteTableCallable; + private final UnaryCallable modifyColumnFamiliesCallable; + private final UnaryCallable dropRowRangeCallable; + + public static final GrpcBigtableTableAdminStub create(BigtableTableAdminSettings settings) + throws IOException { + return new GrpcBigtableTableAdminStub(settings, ClientContext.create(settings)); + } + + public static final GrpcBigtableTableAdminStub create(ClientContext clientContext) + throws IOException { + return new GrpcBigtableTableAdminStub( + BigtableTableAdminSettings.newBuilder().build(), clientContext); + } + + /** + * 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( + BigtableTableAdminSettings settings, ClientContext clientContext) throws IOException { + + GrpcCallSettings createTableTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createTableMethodDescriptor) + .build(); + GrpcCallSettings listTablesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listTablesMethodDescriptor) + .build(); + GrpcCallSettings getTableTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getTableMethodDescriptor) + .build(); + GrpcCallSettings deleteTableTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteTableMethodDescriptor) + .build(); + GrpcCallSettings modifyColumnFamiliesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(modifyColumnFamiliesMethodDescriptor) + .build(); + GrpcCallSettings dropRowRangeTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(dropRowRangeMethodDescriptor) + .build(); + + this.createTableCallable = + GrpcCallableFactory.createUnaryCallable( + createTableTransportSettings, settings.createTableSettings(), clientContext); + this.listTablesCallable = + GrpcCallableFactory.createUnaryCallable( + listTablesTransportSettings, settings.listTablesSettings(), clientContext); + this.listTablesPagedCallable = + GrpcCallableFactory.createPagedCallable( + listTablesTransportSettings, settings.listTablesSettings(), clientContext); + this.getTableCallable = + GrpcCallableFactory.createUnaryCallable( + getTableTransportSettings, settings.getTableSettings(), clientContext); + this.deleteTableCallable = + GrpcCallableFactory.createUnaryCallable( + deleteTableTransportSettings, settings.deleteTableSettings(), clientContext); + this.modifyColumnFamiliesCallable = + GrpcCallableFactory.createUnaryCallable( + modifyColumnFamiliesTransportSettings, + settings.modifyColumnFamiliesSettings(), + clientContext); + this.dropRowRangeCallable = + GrpcCallableFactory.createUnaryCallable( + dropRowRangeTransportSettings, settings.dropRowRangeSettings(), clientContext); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public UnaryCallable createTableCallable() { + return createTableCallable; + } + + public UnaryCallable listTablesPagedCallable() { + return listTablesPagedCallable; + } + + public UnaryCallable listTablesCallable() { + return listTablesCallable; + } + + public UnaryCallable getTableCallable() { + return getTableCallable; + } + + public UnaryCallable deleteTableCallable() { + return deleteTableCallable; + } + + public UnaryCallable modifyColumnFamiliesCallable() { + return modifyColumnFamiliesCallable; + } + + public UnaryCallable dropRowRangeCallable() { + return dropRowRangeCallable; + } + + @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-bigtable/src/main/java/com/google/cloud/bigtable/v2/BigtableClient.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/BigtableClient.java new file mode 100644 index 000000000000..f609784a9782 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/BigtableClient.java @@ -0,0 +1,615 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.v2; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.CheckAndMutateRowRequest; +import com.google.bigtable.v2.CheckAndMutateRowResponse; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.bigtable.v2.MutateRowResponse; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.bigtable.v2.Mutation; +import com.google.bigtable.v2.ReadModifyWriteRowRequest; +import com.google.bigtable.v2.ReadModifyWriteRowResponse; +import com.google.bigtable.v2.ReadModifyWriteRule; +import com.google.bigtable.v2.ReadRowsRequest; +import com.google.bigtable.v2.ReadRowsResponse; +import com.google.bigtable.v2.RowFilter; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.bigtable.v2.TableName; +import com.google.cloud.bigtable.v2.stub.BigtableStub; +import com.google.protobuf.ByteString; +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 for reading from and writing to existing Bigtable tables. + * + *

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 (BigtableClient bigtableClient = BigtableClient.create()) {
+ *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+ *   ByteString rowKey = ByteString.copyFromUtf8("");
+ *   List<Mutation> mutations = new ArrayList<>();
+ *   MutateRowResponse response = bigtableClient.mutateRow(tableName, rowKey, mutations);
+ * }
+ * 
+ * 
+ * + *

Note: close() needs to be called on the bigtableClient 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 BigtableSettings to create(). + * For example: + * + *

To customize credentials: + * + *

+ * 
+ * BigtableSettings bigtableSettings =
+ *     BigtableSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * BigtableClient bigtableClient =
+ *     BigtableClient.create(bigtableSettings);
+ * 
+ * 
+ * + * To customize the endpoint: + * + *
+ * 
+ * BigtableSettings bigtableSettings =
+ *     BigtableSettings.newBuilder()
+ *         .setTransportChannelProvider(BigtableSettings.defaultGrpcTransportProviderBuilder()
+ *             .setEndpoint(myEndpoint)
+ *             .build())
+ *         .build();
+ * BigtableClient bigtableClient =
+ *     BigtableClient.create(bigtableSettings);
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class BigtableClient implements BackgroundResource { + private final BigtableSettings settings; + private final BigtableStub stub; + + /** Constructs an instance of BigtableClient with default settings. */ + public static final BigtableClient create() throws IOException { + return create(BigtableSettings.newBuilder().build()); + } + + /** + * Constructs an instance of BigtableClient, 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 BigtableClient create(BigtableSettings settings) throws IOException { + return new BigtableClient(settings); + } + + /** + * Constructs an instance of BigtableClient, using the given stub for making calls. This is for + * advanced usage - prefer to use BigtableSettings}. + */ + @BetaApi + public static final BigtableClient create(BigtableStub stub) { + return new BigtableClient(stub); + } + + /** + * Constructs an instance of BigtableClient, 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 BigtableClient(BigtableSettings settings) throws IOException { + this.settings = settings; + this.stub = settings.createStub(); + } + + protected BigtableClient(BigtableStub stub) { + this.settings = null; + this.stub = stub; + } + + public final BigtableSettings getSettings() { + return settings; + } + + @BetaApi + public BigtableStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Streams back the contents of all requested rows in key order, optionally applying the same + * Reader filter to each. Depending on their size, rows and cells may be broken up across multiple + * responses, but atomicity of each row will still be preserved. See the ReadRowsResponse + * documentation for details. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   ApiStreamObserver<ReadRowsResponse> responseObserver =
+   *       new ApiStreamObserver<ReadRowsResponse>() {
+   *         {@literal @}Override
+   *         public void onNext(ReadRowsResponse response) {
+   *           // Do something when receive a response
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onError(Throwable t) {
+   *           // Add error-handling
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onCompleted() {
+   *           // Do something when complete.
+   *         }
+   *       };
+   *
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ReadRowsRequest request = ReadRowsRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .build();
+   *
+   *   bigtableClient.readRowsCallable().serverStreamingCall(request, responseObserver));
+   * }
+   * 
+ */ + public final ServerStreamingCallable readRowsCallable() { + return stub.readRowsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns a sample of row keys in the table. The returned row keys will delimit contiguous + * sections of the table of approximately equal size, which can be used to break up the data for + * distributed tasks like mapreduces. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   ApiStreamObserver<SampleRowKeysResponse> responseObserver =
+   *       new ApiStreamObserver<SampleRowKeysResponse>() {
+   *         {@literal @}Override
+   *         public void onNext(SampleRowKeysResponse response) {
+   *           // Do something when receive a response
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onError(Throwable t) {
+   *           // Add error-handling
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onCompleted() {
+   *           // Do something when complete.
+   *         }
+   *       };
+   *
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   SampleRowKeysRequest request = SampleRowKeysRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .build();
+   *
+   *   bigtableClient.sampleRowKeysCallable().serverStreamingCall(request, responseObserver));
+   * }
+   * 
+ */ + public final ServerStreamingCallable + sampleRowKeysCallable() { + return stub.sampleRowKeysCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Mutates a row atomically. Cells already present in the row are left unchanged unless explicitly + * changed by `mutation`. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   List<Mutation> mutations = new ArrayList<>();
+   *   MutateRowResponse response = bigtableClient.mutateRow(tableName, rowKey, mutations);
+   * }
+   * 
+ * + * @param tableName The unique name of the table to which the mutation should be applied. Values + * are of the form `projects/<project>/instances/<instance>/tables/<table>`. + * @param rowKey The key of the row to which the mutation should be applied. + * @param mutations Changes to be atomically applied to the specified row. Entries are applied in + * order, meaning that earlier mutations can be masked by later ones. Must contain at least + * one entry and at most 100000. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final MutateRowResponse mutateRow( + TableName tableName, ByteString rowKey, List mutations) { + + MutateRowRequest request = + MutateRowRequest.newBuilder() + .setTableNameWithTableName(tableName) + .setRowKey(rowKey) + .addAllMutations(mutations) + .build(); + return mutateRow(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Mutates a row atomically. Cells already present in the row are left unchanged unless explicitly + * changed by `mutation`. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   List<Mutation> mutations = new ArrayList<>();
+   *   MutateRowRequest request = MutateRowRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .setRowKey(rowKey)
+   *     .addAllMutations(mutations)
+   *     .build();
+   *   MutateRowResponse response = bigtableClient.mutateRow(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 MutateRowResponse mutateRow(MutateRowRequest request) { + return mutateRowCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Mutates a row atomically. Cells already present in the row are left unchanged unless explicitly + * changed by `mutation`. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   List<Mutation> mutations = new ArrayList<>();
+   *   MutateRowRequest request = MutateRowRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .setRowKey(rowKey)
+   *     .addAllMutations(mutations)
+   *     .build();
+   *   ApiFuture<MutateRowResponse> future = bigtableClient.mutateRowCallable().futureCall(request);
+   *   // Do something
+   *   MutateRowResponse response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable mutateRowCallable() { + return stub.mutateRowCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Mutates multiple rows in a batch. Each individual row is mutated atomically as in MutateRow, + * but the entire batch is not executed atomically. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   ApiStreamObserver<MutateRowsResponse> responseObserver =
+   *       new ApiStreamObserver<MutateRowsResponse>() {
+   *         {@literal @}Override
+   *         public void onNext(MutateRowsResponse response) {
+   *           // Do something when receive a response
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onError(Throwable t) {
+   *           // Add error-handling
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onCompleted() {
+   *           // Do something when complete.
+   *         }
+   *       };
+   *
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   List<MutateRowsRequest.Entry> entries = new ArrayList<>();
+   *   MutateRowsRequest request = MutateRowsRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .addAllEntries(entries)
+   *     .build();
+   *
+   *   bigtableClient.mutateRowsCallable().serverStreamingCall(request, responseObserver));
+   * }
+   * 
+ */ + public final ServerStreamingCallable mutateRowsCallable() { + return stub.mutateRowsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Mutates a row atomically based on the output of a predicate Reader filter. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   RowFilter predicateFilter = RowFilter.newBuilder().build();
+   *   List<Mutation> trueMutations = new ArrayList<>();
+   *   List<Mutation> falseMutations = new ArrayList<>();
+   *   CheckAndMutateRowResponse response = bigtableClient.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations);
+   * }
+   * 
+ * + * @param tableName The unique name of the table to which the conditional mutation should be + * applied. Values are of the form + * `projects/<project>/instances/<instance>/tables/<table>`. + * @param rowKey The key of the row to which the conditional mutation should be applied. + * @param predicateFilter The filter to be applied to the contents of the specified row. Depending + * on whether or not any results are yielded, either `true_mutations` or `false_mutations` + * will be executed. If unset, checks that the row contains any values at all. + * @param trueMutations Changes to be atomically applied to the specified row if + * `predicate_filter` yields at least one cell when applied to `row_key`. Entries are applied + * in order, meaning that earlier mutations can be masked by later ones. Must contain at least + * one entry if `false_mutations` is empty, and at most 100000. + * @param falseMutations Changes to be atomically applied to the specified row if + * `predicate_filter` does not yield any cells when applied to `row_key`. Entries are applied + * in order, meaning that earlier mutations can be masked by later ones. Must contain at least + * one entry if `true_mutations` is empty, and at most 100000. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final CheckAndMutateRowResponse checkAndMutateRow( + TableName tableName, + ByteString rowKey, + RowFilter predicateFilter, + List trueMutations, + List falseMutations) { + + CheckAndMutateRowRequest request = + CheckAndMutateRowRequest.newBuilder() + .setTableNameWithTableName(tableName) + .setRowKey(rowKey) + .setPredicateFilter(predicateFilter) + .addAllTrueMutations(trueMutations) + .addAllFalseMutations(falseMutations) + .build(); + return checkAndMutateRow(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Mutates a row atomically based on the output of a predicate Reader filter. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   CheckAndMutateRowRequest request = CheckAndMutateRowRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .setRowKey(rowKey)
+   *     .build();
+   *   CheckAndMutateRowResponse response = bigtableClient.checkAndMutateRow(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 CheckAndMutateRowResponse checkAndMutateRow(CheckAndMutateRowRequest request) { + return checkAndMutateRowCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Mutates a row atomically based on the output of a predicate Reader filter. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   CheckAndMutateRowRequest request = CheckAndMutateRowRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .setRowKey(rowKey)
+   *     .build();
+   *   ApiFuture<CheckAndMutateRowResponse> future = bigtableClient.checkAndMutateRowCallable().futureCall(request);
+   *   // Do something
+   *   CheckAndMutateRowResponse response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable + checkAndMutateRowCallable() { + return stub.checkAndMutateRowCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Modifies a row atomically. The method reads the latest existing timestamp and value from the + * specified columns and writes a new entry based on pre-defined read/modify/write rules. The new + * value for the timestamp is the greater of the existing timestamp or the current server time. + * The method returns the new contents of all modified cells. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   List<ReadModifyWriteRule> rules = new ArrayList<>();
+   *   ReadModifyWriteRowResponse response = bigtableClient.readModifyWriteRow(tableName, rowKey, rules);
+   * }
+   * 
+ * + * @param tableName The unique name of the table to which the read/modify/write rules should be + * applied. Values are of the form + * `projects/<project>/instances/<instance>/tables/<table>`. + * @param rowKey The key of the row to which the read/modify/write rules should be applied. + * @param rules Rules specifying how the specified row's contents are to be transformed into + * writes. Entries are applied in order, meaning that earlier rules will affect the results of + * later ones. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ReadModifyWriteRowResponse readModifyWriteRow( + TableName tableName, ByteString rowKey, List rules) { + + ReadModifyWriteRowRequest request = + ReadModifyWriteRowRequest.newBuilder() + .setTableNameWithTableName(tableName) + .setRowKey(rowKey) + .addAllRules(rules) + .build(); + return readModifyWriteRow(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Modifies a row atomically. The method reads the latest existing timestamp and value from the + * specified columns and writes a new entry based on pre-defined read/modify/write rules. The new + * value for the timestamp is the greater of the existing timestamp or the current server time. + * The method returns the new contents of all modified cells. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   List<ReadModifyWriteRule> rules = new ArrayList<>();
+   *   ReadModifyWriteRowRequest request = ReadModifyWriteRowRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .setRowKey(rowKey)
+   *     .addAllRules(rules)
+   *     .build();
+   *   ReadModifyWriteRowResponse response = bigtableClient.readModifyWriteRow(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 ReadModifyWriteRowResponse readModifyWriteRow(ReadModifyWriteRowRequest request) { + return readModifyWriteRowCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Modifies a row atomically. The method reads the latest existing timestamp and value from the + * specified columns and writes a new entry based on pre-defined read/modify/write rules. The new + * value for the timestamp is the greater of the existing timestamp or the current server time. + * The method returns the new contents of all modified cells. + * + *

Sample code: + * + *


+   * try (BigtableClient bigtableClient = BigtableClient.create()) {
+   *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+   *   ByteString rowKey = ByteString.copyFromUtf8("");
+   *   List<ReadModifyWriteRule> rules = new ArrayList<>();
+   *   ReadModifyWriteRowRequest request = ReadModifyWriteRowRequest.newBuilder()
+   *     .setTableNameWithTableName(tableName)
+   *     .setRowKey(rowKey)
+   *     .addAllRules(rules)
+   *     .build();
+   *   ApiFuture<ReadModifyWriteRowResponse> future = bigtableClient.readModifyWriteRowCallable().futureCall(request);
+   *   // Do something
+   *   ReadModifyWriteRowResponse response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable + readModifyWriteRowCallable() { + return stub.readModifyWriteRowCallable(); + } + + @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-bigtable/src/main/java/com/google/cloud/bigtable/v2/BigtableSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/BigtableSettings.java new file mode 100644 index 000000000000..94d3e0e4e5de --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/BigtableSettings.java @@ -0,0 +1,446 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.v2; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.ExecutorProvider; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.core.PropertiesProvider; +import com.google.api.gax.grpc.GrpcExtraHeaderData; +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.ClientSettings; +import com.google.api.gax.rpc.HeaderProvider; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.bigtable.v2.CheckAndMutateRowRequest; +import com.google.bigtable.v2.CheckAndMutateRowResponse; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.bigtable.v2.MutateRowResponse; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.bigtable.v2.ReadModifyWriteRowRequest; +import com.google.bigtable.v2.ReadModifyWriteRowResponse; +import com.google.bigtable.v2.ReadRowsRequest; +import com.google.bigtable.v2.ReadRowsResponse; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.cloud.bigtable.v2.stub.BigtableStub; +import com.google.cloud.bigtable.v2.stub.GrpcBigtableStub; +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 BigtableClient}. + * + *

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

    + *
  • The default service address (bigtable.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 mutateRow to 30 seconds: + * + *

+ * 
+ * BigtableSettings.Builder bigtableSettingsBuilder =
+ *     BigtableSettings.newBuilder();
+ * bigtableSettingsBuilder.mutateRowSettings().getRetrySettingsBuilder()
+ *     .setTotalTimeout(Duration.ofSeconds(30));
+ * BigtableSettings bigtableSettings = bigtableSettingsBuilder.build();
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class BigtableSettings extends ClientSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/bigtable.data") + .add("https://www.googleapis.com/auth/bigtable.data.readonly") + .add("https://www.googleapis.com/auth/cloud-bigtable.data") + .add("https://www.googleapis.com/auth/cloud-bigtable.data.readonly") + .add("https://www.googleapis.com/auth/cloud-platform") + .add("https://www.googleapis.com/auth/cloud-platform.read-only") + .build(); + + private static final String DEFAULT_GAPIC_NAME = "gapic"; + private static final String DEFAULT_GAPIC_VERSION = ""; + + private static final String PROPERTIES_FILE = "/com/google/cloud/bigtable/project.properties"; + private static final String META_VERSION_KEY = "artifact.version"; + + private static String gapicVersion; + + private final StreamingCallSettings readRowsSettings; + private final StreamingCallSettings + sampleRowKeysSettings; + private final UnaryCallSettings mutateRowSettings; + private final StreamingCallSettings mutateRowsSettings; + private final UnaryCallSettings + checkAndMutateRowSettings; + private final UnaryCallSettings + readModifyWriteRowSettings; + + /** Returns the object with the settings used for calls to readRows. */ + public StreamingCallSettings readRowsSettings() { + return readRowsSettings; + } + + /** Returns the object with the settings used for calls to sampleRowKeys. */ + public StreamingCallSettings + sampleRowKeysSettings() { + return sampleRowKeysSettings; + } + + /** Returns the object with the settings used for calls to mutateRow. */ + public UnaryCallSettings mutateRowSettings() { + return mutateRowSettings; + } + + /** Returns the object with the settings used for calls to mutateRows. */ + public StreamingCallSettings mutateRowsSettings() { + return mutateRowsSettings; + } + + /** Returns the object with the settings used for calls to checkAndMutateRow. */ + public UnaryCallSettings + checkAndMutateRowSettings() { + return checkAndMutateRowSettings; + } + + /** Returns the object with the settings used for calls to readModifyWriteRow. */ + public UnaryCallSettings + readModifyWriteRowSettings() { + return readModifyWriteRowSettings; + } + + public BigtableStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcBigtableStub.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 "bigtable.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().setEndpoint(getDefaultEndpoint()); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratorHeader(DEFAULT_GAPIC_NAME, getGapicVersion()) + .setApiClientHeaderLineKey("x-goog-api-client") + .addApiClientHeaderLineData(GrpcExtraHeaderData.getXGoogApiClientData()); + } + + private static String getGapicVersion() { + if (gapicVersion == null) { + gapicVersion = + PropertiesProvider.loadProperty( + BigtableSettings.class, PROPERTIES_FILE, META_VERSION_KEY); + gapicVersion = gapicVersion == null ? DEFAULT_GAPIC_VERSION : gapicVersion; + } + return gapicVersion; + } + + /** Returns a builder for this class with recommended defaults. */ + @Deprecated + public static Builder defaultBuilder() { + return Builder.createDefault(); + } + + /** + * Returns a builder for this class with recommended defaults for API methods, and the given + * ClientContext used for executor/transport/credentials. + */ + @Deprecated + public static Builder defaultBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** 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); + } + + private BigtableSettings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getExecutorProvider(), + settingsBuilder.getTransportChannelProvider(), + settingsBuilder.getCredentialsProvider(), + settingsBuilder.getHeaderProvider(), + settingsBuilder.getClock()); + + readRowsSettings = settingsBuilder.readRowsSettings().build(); + sampleRowKeysSettings = settingsBuilder.sampleRowKeysSettings().build(); + mutateRowSettings = settingsBuilder.mutateRowSettings().build(); + mutateRowsSettings = settingsBuilder.mutateRowsSettings().build(); + checkAndMutateRowSettings = settingsBuilder.checkAndMutateRowSettings().build(); + readModifyWriteRowSettings = settingsBuilder.readModifyWriteRowSettings().build(); + } + + /** Builder for BigtableSettings. */ + public static class Builder extends ClientSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final StreamingCallSettings.Builder readRowsSettings; + private final StreamingCallSettings.Builder + sampleRowKeysSettings; + private final UnaryCallSettings.Builder mutateRowSettings; + private final StreamingCallSettings.Builder + mutateRowsSettings; + private final UnaryCallSettings.Builder + checkAndMutateRowSettings; + private final UnaryCallSettings.Builder + readModifyWriteRowSettings; + + 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(); + } + + private Builder() { + this((ClientContext) null); + } + + private Builder(ClientContext clientContext) { + super(clientContext); + + readRowsSettings = StreamingCallSettings.newBuilder(); + + sampleRowKeysSettings = StreamingCallSettings.newBuilder(); + + mutateRowSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + mutateRowsSettings = StreamingCallSettings.newBuilder(); + + checkAndMutateRowSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + readModifyWriteRowSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + mutateRowSettings, checkAndMutateRowSettings, readModifyWriteRowSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .mutateRowSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .checkAndMutateRowSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .readModifyWriteRowSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + return builder; + } + + private Builder(BigtableSettings settings) { + super(settings); + + readRowsSettings = settings.readRowsSettings.toBuilder(); + sampleRowKeysSettings = settings.sampleRowKeysSettings.toBuilder(); + mutateRowSettings = settings.mutateRowSettings.toBuilder(); + mutateRowsSettings = settings.mutateRowsSettings.toBuilder(); + checkAndMutateRowSettings = settings.checkAndMutateRowSettings.toBuilder(); + readModifyWriteRowSettings = settings.readModifyWriteRowSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + mutateRowSettings, checkAndMutateRowSettings, readModifyWriteRowSettings); + } + + @Override + public Builder setExecutorProvider(ExecutorProvider executorProvider) { + super.setExecutorProvider(executorProvider); + return this; + } + + @Override + public Builder setTransportChannelProvider(TransportChannelProvider transportProvider) { + super.setTransportChannelProvider(transportProvider); + return this; + } + + @Override + public Builder setHeaderProvider(HeaderProvider headerProvider) { + super.setHeaderProvider(headerProvider); + return this; + } + + @Override + public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) { + super.setCredentialsProvider(credentialsProvider); + return this; + } + + /** + * 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; + } + + /** Returns the builder for the settings used for calls to readRows. */ + public StreamingCallSettings.Builder readRowsSettings() { + return readRowsSettings; + } + + /** Returns the builder for the settings used for calls to sampleRowKeys. */ + public StreamingCallSettings.Builder + sampleRowKeysSettings() { + return sampleRowKeysSettings; + } + + /** Returns the builder for the settings used for calls to mutateRow. */ + public UnaryCallSettings.Builder mutateRowSettings() { + return mutateRowSettings; + } + + /** Returns the builder for the settings used for calls to mutateRows. */ + public StreamingCallSettings.Builder + mutateRowsSettings() { + return mutateRowsSettings; + } + + /** Returns the builder for the settings used for calls to checkAndMutateRow. */ + public UnaryCallSettings.Builder + checkAndMutateRowSettings() { + return checkAndMutateRowSettings; + } + + /** Returns the builder for the settings used for calls to readModifyWriteRow. */ + public UnaryCallSettings.Builder + readModifyWriteRowSettings() { + return readModifyWriteRowSettings; + } + + @Override + public BigtableSettings build() throws IOException { + return new BigtableSettings(this); + } + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/package-info.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/package-info.java new file mode 100644 index 000000000000..3a8c613038dc --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/package-info.java @@ -0,0 +1,39 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A client to Google Cloud Bigtable API. + * + *

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

============== BigtableClient ============== + * + *

Service Description: Service for reading from and writing to existing Bigtable tables. + * + *

Sample for BigtableClient: + * + *

+ * 
+ * try (BigtableClient bigtableClient = BigtableClient.create()) {
+ *   TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
+ *   ByteString rowKey = ByteString.copyFromUtf8("");
+ *   List<Mutation> mutations = new ArrayList<>();
+ *   MutateRowResponse response = bigtableClient.mutateRow(tableName, rowKey, mutations);
+ * }
+ * 
+ * 
+ */ +package com.google.cloud.bigtable.v2; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/stub/BigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/stub/BigtableStub.java new file mode 100644 index 000000000000..a8b339d8ec54 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/stub/BigtableStub.java @@ -0,0 +1,72 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.v2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.CheckAndMutateRowRequest; +import com.google.bigtable.v2.CheckAndMutateRowResponse; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.bigtable.v2.MutateRowResponse; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.bigtable.v2.ReadModifyWriteRowRequest; +import com.google.bigtable.v2.ReadModifyWriteRowResponse; +import com.google.bigtable.v2.ReadRowsRequest; +import com.google.bigtable.v2.ReadRowsResponse; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Google Cloud Bigtable API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public abstract class BigtableStub implements BackgroundResource { + + public ServerStreamingCallable readRowsCallable() { + throw new UnsupportedOperationException("Not implemented: readRowsCallable()"); + } + + public ServerStreamingCallable + sampleRowKeysCallable() { + throw new UnsupportedOperationException("Not implemented: sampleRowKeysCallable()"); + } + + public UnaryCallable mutateRowCallable() { + throw new UnsupportedOperationException("Not implemented: mutateRowCallable()"); + } + + public ServerStreamingCallable mutateRowsCallable() { + throw new UnsupportedOperationException("Not implemented: mutateRowsCallable()"); + } + + public UnaryCallable + checkAndMutateRowCallable() { + throw new UnsupportedOperationException("Not implemented: checkAndMutateRowCallable()"); + } + + public UnaryCallable + readModifyWriteRowCallable() { + throw new UnsupportedOperationException("Not implemented: readModifyWriteRowCallable()"); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/stub/GrpcBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/stub/GrpcBigtableStub.java new file mode 100644 index 000000000000..72e3fbe684a5 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/v2/stub/GrpcBigtableStub.java @@ -0,0 +1,246 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.v2.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.GrpcCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.bigtable.v2.CheckAndMutateRowRequest; +import com.google.bigtable.v2.CheckAndMutateRowResponse; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.bigtable.v2.MutateRowResponse; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.bigtable.v2.ReadModifyWriteRowRequest; +import com.google.bigtable.v2.ReadModifyWriteRowResponse; +import com.google.bigtable.v2.ReadRowsRequest; +import com.google.bigtable.v2.ReadRowsResponse; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.cloud.bigtable.v2.BigtableSettings; +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 Bigtable API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi +public class GrpcBigtableStub extends BigtableStub { + + private static final MethodDescriptor + readRowsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName("google.bigtable.v2.Bigtable/ReadRows") + .setRequestMarshaller(ProtoUtils.marshaller(ReadRowsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ReadRowsResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + sampleRowKeysMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName("google.bigtable.v2.Bigtable/SampleRowKeys") + .setRequestMarshaller( + ProtoUtils.marshaller(SampleRowKeysRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(SampleRowKeysResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + mutateRowMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.v2.Bigtable/MutateRow") + .setRequestMarshaller(ProtoUtils.marshaller(MutateRowRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(MutateRowResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + mutateRowsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName("google.bigtable.v2.Bigtable/MutateRows") + .setRequestMarshaller(ProtoUtils.marshaller(MutateRowsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(MutateRowsResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + checkAndMutateRowMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.v2.Bigtable/CheckAndMutateRow") + .setRequestMarshaller( + ProtoUtils.marshaller(CheckAndMutateRowRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(CheckAndMutateRowResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + readModifyWriteRowMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.bigtable.v2.Bigtable/ReadModifyWriteRow") + .setRequestMarshaller( + ProtoUtils.marshaller(ReadModifyWriteRowRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ReadModifyWriteRowResponse.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + + private final ServerStreamingCallable readRowsCallable; + private final ServerStreamingCallable + sampleRowKeysCallable; + private final UnaryCallable mutateRowCallable; + private final ServerStreamingCallable mutateRowsCallable; + private final UnaryCallable + checkAndMutateRowCallable; + private final UnaryCallable + readModifyWriteRowCallable; + + public static final GrpcBigtableStub create(BigtableSettings settings) throws IOException { + return new GrpcBigtableStub(settings, ClientContext.create(settings)); + } + + public static final GrpcBigtableStub create(ClientContext clientContext) throws IOException { + return new GrpcBigtableStub(BigtableSettings.newBuilder().build(), clientContext); + } + + /** + * 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(BigtableSettings settings, ClientContext clientContext) + throws IOException { + + GrpcCallSettings readRowsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(readRowsMethodDescriptor) + .build(); + GrpcCallSettings sampleRowKeysTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(sampleRowKeysMethodDescriptor) + .build(); + GrpcCallSettings mutateRowTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(mutateRowMethodDescriptor) + .build(); + GrpcCallSettings mutateRowsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(mutateRowsMethodDescriptor) + .build(); + GrpcCallSettings + checkAndMutateRowTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(checkAndMutateRowMethodDescriptor) + .build(); + GrpcCallSettings + readModifyWriteRowTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(readModifyWriteRowMethodDescriptor) + .build(); + + this.readRowsCallable = + GrpcCallableFactory.createServerStreamingCallable( + readRowsTransportSettings, settings.readRowsSettings(), clientContext); + this.sampleRowKeysCallable = + GrpcCallableFactory.createServerStreamingCallable( + sampleRowKeysTransportSettings, settings.sampleRowKeysSettings(), clientContext); + this.mutateRowCallable = + GrpcCallableFactory.createUnaryCallable( + mutateRowTransportSettings, settings.mutateRowSettings(), clientContext); + this.mutateRowsCallable = + GrpcCallableFactory.createServerStreamingCallable( + mutateRowsTransportSettings, settings.mutateRowsSettings(), clientContext); + this.checkAndMutateRowCallable = + GrpcCallableFactory.createUnaryCallable( + checkAndMutateRowTransportSettings, + settings.checkAndMutateRowSettings(), + clientContext); + this.readModifyWriteRowCallable = + GrpcCallableFactory.createUnaryCallable( + readModifyWriteRowTransportSettings, + settings.readModifyWriteRowSettings(), + clientContext); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public ServerStreamingCallable readRowsCallable() { + return readRowsCallable; + } + + public ServerStreamingCallable + sampleRowKeysCallable() { + return sampleRowKeysCallable; + } + + public UnaryCallable mutateRowCallable() { + return mutateRowCallable; + } + + public ServerStreamingCallable mutateRowsCallable() { + return mutateRowsCallable; + } + + public UnaryCallable + checkAndMutateRowCallable() { + return checkAndMutateRowCallable; + } + + public UnaryCallable + readModifyWriteRowCallable() { + return readModifyWriteRowCallable; + } + + @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-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java new file mode 100644 index 000000000000..ec4967a64dd6 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java @@ -0,0 +1,529 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.bigtable.admin.v2.Cluster; +import com.google.bigtable.admin.v2.ClusterName; +import com.google.bigtable.admin.v2.CreateClusterRequest; +import com.google.bigtable.admin.v2.CreateInstanceRequest; +import com.google.bigtable.admin.v2.DeleteClusterRequest; +import com.google.bigtable.admin.v2.DeleteInstanceRequest; +import com.google.bigtable.admin.v2.GetClusterRequest; +import com.google.bigtable.admin.v2.GetInstanceRequest; +import com.google.bigtable.admin.v2.Instance; +import com.google.bigtable.admin.v2.Instance.Type; +import com.google.bigtable.admin.v2.InstanceName; +import com.google.bigtable.admin.v2.ListClustersRequest; +import com.google.bigtable.admin.v2.ListClustersResponse; +import com.google.bigtable.admin.v2.ListInstancesRequest; +import com.google.bigtable.admin.v2.ListInstancesResponse; +import com.google.bigtable.admin.v2.LocationName; +import com.google.bigtable.admin.v2.ProjectName; +import com.google.bigtable.admin.v2.StorageType; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +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 BigtableInstanceAdminClientTest { + private static MockBigtableInstanceAdmin mockBigtableInstanceAdmin; + private static MockBigtableTableAdmin mockBigtableTableAdmin; + private static MockServiceHelper serviceHelper; + private BigtableInstanceAdminClient client; + + @BeforeClass + public static void startStaticServer() { + mockBigtableInstanceAdmin = new MockBigtableInstanceAdmin(); + mockBigtableTableAdmin = new MockBigtableTableAdmin(); + serviceHelper = + new MockServiceHelper( + "in-process-1", + Arrays.asList(mockBigtableInstanceAdmin, mockBigtableTableAdmin)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + BigtableInstanceAdminSettings settings = + BigtableInstanceAdminSettings.newBuilder() + .setTransportChannelProvider(serviceHelper.createChannelProvider()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = BigtableInstanceAdminClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void createInstanceTest() throws Exception { + InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + Instance expectedResponse = + Instance.newBuilder().setNameWithInstanceName(name).setDisplayName(displayName).build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockBigtableInstanceAdmin.addResponse(resultOperation); + + ProjectName parent = ProjectName.of("[PROJECT]"); + String instanceId = "instanceId-2101995259"; + Instance instance = Instance.newBuilder().build(); + Map clusters = new HashMap<>(); + + Instance actualResponse = + client.createInstanceAsync(parent, instanceId, instance, clusters).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateInstanceRequest actualRequest = (CreateInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(parent, actualRequest.getParentAsProjectName()); + Assert.assertEquals(instanceId, actualRequest.getInstanceId()); + Assert.assertEquals(instance, actualRequest.getInstance()); + Assert.assertEquals(clusters, actualRequest.getClustersMap()); + } + + @Test + @SuppressWarnings("all") + public void createInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + String instanceId = "instanceId-2101995259"; + Instance instance = Instance.newBuilder().build(); + Map clusters = new HashMap<>(); + + client.createInstanceAsync(parent, instanceId, instance, clusters).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 getInstanceTest() { + InstanceName name2 = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + Instance expectedResponse = + Instance.newBuilder().setNameWithInstanceName(name2).setDisplayName(displayName).build(); + mockBigtableInstanceAdmin.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + Instance actualResponse = client.getInstance(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetInstanceRequest actualRequest = (GetInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsInstanceName()); + } + + @Test + @SuppressWarnings("all") + public void getInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void listInstancesTest() { + String nextPageToken = "nextPageToken-1530815211"; + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder().setNextPageToken(nextPageToken).build(); + mockBigtableInstanceAdmin.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListInstancesResponse actualResponse = client.listInstances(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListInstancesRequest actualRequest = (ListInstancesRequest) actualRequests.get(0); + + Assert.assertEquals(parent, actualRequest.getParentAsProjectName()); + } + + @Test + @SuppressWarnings("all") + public void listInstancesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + + client.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void updateInstanceTest() { + InstanceName name2 = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String displayName2 = "displayName21615000987"; + Instance expectedResponse = + Instance.newBuilder().setNameWithInstanceName(name2).setDisplayName(displayName2).build(); + mockBigtableInstanceAdmin.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + Instance.Type type = Instance.Type.TYPE_UNSPECIFIED; + + Instance actualResponse = client.updateInstance(name, displayName, type); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + Instance actualRequest = (Instance) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsInstanceName()); + Assert.assertEquals(displayName, actualRequest.getDisplayName()); + Assert.assertEquals(type, actualRequest.getType()); + } + + @Test + @SuppressWarnings("all") + public void updateInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + Instance.Type type = Instance.Type.TYPE_UNSPECIFIED; + + client.updateInstance(name, displayName, type); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void deleteInstanceTest() { + Empty expectedResponse = Empty.newBuilder().build(); + mockBigtableInstanceAdmin.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + client.deleteInstance(name); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteInstanceRequest actualRequest = (DeleteInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsInstanceName()); + } + + @Test + @SuppressWarnings("all") + public void deleteInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + client.deleteInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void createClusterTest() throws Exception { + ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + LocationName location = LocationName.of("[PROJECT]", "[LOCATION]"); + int serveNodes = -1288838783; + Cluster expectedResponse = + Cluster.newBuilder() + .setNameWithClusterName(name) + .setLocationWithLocationName(location) + .setServeNodes(serveNodes) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockBigtableInstanceAdmin.addResponse(resultOperation); + + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String clusterId = "clusterId240280960"; + Cluster cluster = Cluster.newBuilder().build(); + + Cluster actualResponse = client.createClusterAsync(parent, clusterId, cluster).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateClusterRequest actualRequest = (CreateClusterRequest) actualRequests.get(0); + + Assert.assertEquals(parent, actualRequest.getParentAsInstanceName()); + Assert.assertEquals(clusterId, actualRequest.getClusterId()); + Assert.assertEquals(cluster, actualRequest.getCluster()); + } + + @Test + @SuppressWarnings("all") + public void createClusterExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String clusterId = "clusterId240280960"; + Cluster cluster = Cluster.newBuilder().build(); + + client.createClusterAsync(parent, clusterId, cluster).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 getClusterTest() { + ClusterName name2 = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + LocationName location = LocationName.of("[PROJECT]", "[LOCATION]"); + int serveNodes = -1288838783; + Cluster expectedResponse = + Cluster.newBuilder() + .setNameWithClusterName(name2) + .setLocationWithLocationName(location) + .setServeNodes(serveNodes) + .build(); + mockBigtableInstanceAdmin.addResponse(expectedResponse); + + ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + + Cluster actualResponse = client.getCluster(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetClusterRequest actualRequest = (GetClusterRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsClusterName()); + } + + @Test + @SuppressWarnings("all") + public void getClusterExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + + client.getCluster(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void listClustersTest() { + String nextPageToken = "nextPageToken-1530815211"; + ListClustersResponse expectedResponse = + ListClustersResponse.newBuilder().setNextPageToken(nextPageToken).build(); + mockBigtableInstanceAdmin.addResponse(expectedResponse); + + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + ListClustersResponse actualResponse = client.listClusters(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListClustersRequest actualRequest = (ListClustersRequest) actualRequests.get(0); + + Assert.assertEquals(parent, actualRequest.getParentAsInstanceName()); + } + + @Test + @SuppressWarnings("all") + public void listClustersExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + client.listClusters(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void updateClusterTest() throws Exception { + ClusterName name2 = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + LocationName location2 = LocationName.of("[PROJECT]", "[LOCATION]"); + int serveNodes2 = -1623486220; + Cluster expectedResponse = + Cluster.newBuilder() + .setNameWithClusterName(name2) + .setLocationWithLocationName(location2) + .setServeNodes(serveNodes2) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockBigtableInstanceAdmin.addResponse(resultOperation); + + ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + LocationName location = LocationName.of("[PROJECT]", "[LOCATION]"); + int serveNodes = -1288838783; + StorageType defaultStorageType = StorageType.STORAGE_TYPE_UNSPECIFIED; + + Cluster actualResponse = + client.updateClusterAsync(name, location, serveNodes, defaultStorageType).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + Cluster actualRequest = (Cluster) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsClusterName()); + Assert.assertEquals(location, actualRequest.getLocationAsLocationName()); + Assert.assertEquals(serveNodes, actualRequest.getServeNodes()); + Assert.assertEquals(defaultStorageType, actualRequest.getDefaultStorageType()); + } + + @Test + @SuppressWarnings("all") + public void updateClusterExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + LocationName location = LocationName.of("[PROJECT]", "[LOCATION]"); + int serveNodes = -1288838783; + StorageType defaultStorageType = StorageType.STORAGE_TYPE_UNSPECIFIED; + + client.updateClusterAsync(name, location, serveNodes, defaultStorageType).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 deleteClusterTest() { + Empty expectedResponse = Empty.newBuilder().build(); + mockBigtableInstanceAdmin.addResponse(expectedResponse); + + ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + + client.deleteCluster(name); + + List actualRequests = mockBigtableInstanceAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteClusterRequest actualRequest = (DeleteClusterRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsClusterName()); + } + + @Test + @SuppressWarnings("all") + public void deleteClusterExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableInstanceAdmin.addException(exception); + + try { + ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); + + client.deleteCluster(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } +} 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 new file mode 100644 index 000000000000..e896ee89eaf6 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java @@ -0,0 +1,317 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +import static com.google.cloud.bigtable.admin.v2.PagedResponseWrappers.ListTablesPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.bigtable.admin.v2.CreateTableRequest; +import com.google.bigtable.admin.v2.DeleteTableRequest; +import com.google.bigtable.admin.v2.DropRowRangeRequest; +import com.google.bigtable.admin.v2.GetTableRequest; +import com.google.bigtable.admin.v2.InstanceName; +import com.google.bigtable.admin.v2.ListTablesRequest; +import com.google.bigtable.admin.v2.ListTablesResponse; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification; +import com.google.bigtable.admin.v2.Table; +import com.google.bigtable.admin.v2.TableName; +import com.google.common.collect.Lists; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +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 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 BigtableTableAdminClientTest { + private static MockBigtableInstanceAdmin mockBigtableInstanceAdmin; + private static MockBigtableTableAdmin mockBigtableTableAdmin; + private static MockServiceHelper serviceHelper; + private BigtableTableAdminClient client; + + @BeforeClass + public static void startStaticServer() { + mockBigtableInstanceAdmin = new MockBigtableInstanceAdmin(); + mockBigtableTableAdmin = new MockBigtableTableAdmin(); + serviceHelper = + new MockServiceHelper( + "in-process-1", + Arrays.asList(mockBigtableInstanceAdmin, mockBigtableTableAdmin)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + BigtableTableAdminSettings settings = + BigtableTableAdminSettings.newBuilder() + .setTransportChannelProvider(serviceHelper.createChannelProvider()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = BigtableTableAdminClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void createTableTest() { + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + Table expectedResponse = Table.newBuilder().setNameWithTableName(name).build(); + mockBigtableTableAdmin.addResponse(expectedResponse); + + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String tableId = "tableId-895419604"; + Table table = Table.newBuilder().build(); + + Table actualResponse = client.createTable(parent, tableId, table); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableTableAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateTableRequest actualRequest = (CreateTableRequest) actualRequests.get(0); + + Assert.assertEquals(parent, actualRequest.getParentAsInstanceName()); + Assert.assertEquals(tableId, actualRequest.getTableId()); + Assert.assertEquals(table, actualRequest.getTable()); + } + + @Test + @SuppressWarnings("all") + public void createTableExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableTableAdmin.addException(exception); + + try { + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + String tableId = "tableId-895419604"; + Table table = Table.newBuilder().build(); + + client.createTable(parent, tableId, table); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void listTablesTest() { + String nextPageToken = ""; + Table tablesElement = Table.newBuilder().build(); + List

tables = Arrays.asList(tablesElement); + ListTablesResponse expectedResponse = + ListTablesResponse.newBuilder() + .setNextPageToken(nextPageToken) + .addAllTables(tables) + .build(); + mockBigtableTableAdmin.addResponse(expectedResponse); + + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + ListTablesPagedResponse pagedListResponse = client.listTables(parent); + + List
resources = Lists.newArrayList(pagedListResponse.iterateAll()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTablesList().get(0), resources.get(0)); + + List actualRequests = mockBigtableTableAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListTablesRequest actualRequest = (ListTablesRequest) actualRequests.get(0); + + Assert.assertEquals(parent, actualRequest.getParentAsInstanceName()); + } + + @Test + @SuppressWarnings("all") + public void listTablesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableTableAdmin.addException(exception); + + try { + InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); + + client.listTables(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void getTableTest() { + TableName name2 = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + Table expectedResponse = Table.newBuilder().setNameWithTableName(name2).build(); + mockBigtableTableAdmin.addResponse(expectedResponse); + + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + + Table actualResponse = client.getTable(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableTableAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetTableRequest actualRequest = (GetTableRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsTableName()); + } + + @Test + @SuppressWarnings("all") + public void getTableExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableTableAdmin.addException(exception); + + try { + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + + client.getTable(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void deleteTableTest() { + Empty expectedResponse = Empty.newBuilder().build(); + mockBigtableTableAdmin.addResponse(expectedResponse); + + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + + client.deleteTable(name); + + List actualRequests = mockBigtableTableAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteTableRequest actualRequest = (DeleteTableRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsTableName()); + } + + @Test + @SuppressWarnings("all") + public void deleteTableExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableTableAdmin.addException(exception); + + try { + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + + client.deleteTable(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void modifyColumnFamiliesTest() { + TableName name2 = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + Table expectedResponse = Table.newBuilder().setNameWithTableName(name2).build(); + mockBigtableTableAdmin.addResponse(expectedResponse); + + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + List modifications = new ArrayList<>(); + + Table actualResponse = client.modifyColumnFamilies(name, modifications); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtableTableAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ModifyColumnFamiliesRequest actualRequest = (ModifyColumnFamiliesRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getNameAsTableName()); + Assert.assertEquals(modifications, actualRequest.getModificationsList()); + } + + @Test + @SuppressWarnings("all") + public void modifyColumnFamiliesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableTableAdmin.addException(exception); + + try { + TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + List modifications = new ArrayList<>(); + + client.modifyColumnFamilies(name, modifications); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void dropRowRangeTest() { + Empty expectedResponse = Empty.newBuilder().build(); + mockBigtableTableAdmin.addResponse(expectedResponse); + + String formattedName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString(); + ByteString rowKeyPrefix = ByteString.copyFromUtf8("-9"); + + client.dropRowRange(formattedName, rowKeyPrefix); + + List actualRequests = mockBigtableTableAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DropRowRangeRequest actualRequest = (DropRowRangeRequest) actualRequests.get(0); + + Assert.assertEquals(formattedName, actualRequest.getName()); + Assert.assertEquals(rowKeyPrefix, actualRequest.getRowKeyPrefix()); + } + + @Test + @SuppressWarnings("all") + public void dropRowRangeExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtableTableAdmin.addException(exception); + + try { + String formattedName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString(); + ByteString rowKeyPrefix = ByteString.copyFromUtf8("-9"); + + client.dropRowRange(formattedName, rowKeyPrefix); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdmin.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdmin.java new file mode 100644 index 000000000000..7a482aef79d1 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdmin.java @@ -0,0 +1,55 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +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") +public class MockBigtableInstanceAdmin implements MockGrpcService { + private final MockBigtableInstanceAdminImpl serviceImpl; + + public MockBigtableInstanceAdmin() { + serviceImpl = new MockBigtableInstanceAdminImpl(); + } + + @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-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdminImpl.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdminImpl.java new file mode 100644 index 000000000000..a07c82509504 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdminImpl.java @@ -0,0 +1,215 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +import com.google.bigtable.admin.v2.BigtableInstanceAdminGrpc.BigtableInstanceAdminImplBase; +import com.google.bigtable.admin.v2.Cluster; +import com.google.bigtable.admin.v2.CreateClusterRequest; +import com.google.bigtable.admin.v2.CreateInstanceRequest; +import com.google.bigtable.admin.v2.DeleteClusterRequest; +import com.google.bigtable.admin.v2.DeleteInstanceRequest; +import com.google.bigtable.admin.v2.GetClusterRequest; +import com.google.bigtable.admin.v2.GetInstanceRequest; +import com.google.bigtable.admin.v2.Instance; +import com.google.bigtable.admin.v2.ListClustersRequest; +import com.google.bigtable.admin.v2.ListClustersResponse; +import com.google.bigtable.admin.v2.ListInstancesRequest; +import com.google.bigtable.admin.v2.ListInstancesResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +public class MockBigtableInstanceAdminImpl extends BigtableInstanceAdminImplBase { + private ArrayList requests; + private Queue responses; + + public MockBigtableInstanceAdminImpl() { + 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 createInstance( + CreateInstanceRequest 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")); + } + } + + @Override + public void getInstance(GetInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Instance) { + requests.add(request); + responseObserver.onNext((Instance) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listInstances( + ListInstancesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListInstancesResponse) { + requests.add(request); + responseObserver.onNext((ListInstancesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateInstance(Instance request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Instance) { + requests.add(request); + responseObserver.onNext((Instance) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteInstance( + DeleteInstanceRequest 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 createCluster( + CreateClusterRequest 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")); + } + } + + @Override + public void getCluster(GetClusterRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Cluster) { + requests.add(request); + responseObserver.onNext((Cluster) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listClusters( + ListClustersRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListClustersResponse) { + requests.add(request); + responseObserver.onNext((ListClustersResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateCluster(Cluster 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")); + } + } + + @Override + public void deleteCluster(DeleteClusterRequest 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-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdmin.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdmin.java new file mode 100644 index 000000000000..d7fd027dfe9b --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdmin.java @@ -0,0 +1,55 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +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") +public class MockBigtableTableAdmin implements MockGrpcService { + private final MockBigtableTableAdminImpl serviceImpl; + + public MockBigtableTableAdmin() { + serviceImpl = new MockBigtableTableAdminImpl(); + } + + @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-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdminImpl.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdminImpl.java new file mode 100644 index 000000000000..ce73522316c7 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdminImpl.java @@ -0,0 +1,151 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2; + +import com.google.bigtable.admin.v2.BigtableTableAdminGrpc.BigtableTableAdminImplBase; +import com.google.bigtable.admin.v2.CreateTableRequest; +import com.google.bigtable.admin.v2.DeleteTableRequest; +import com.google.bigtable.admin.v2.DropRowRangeRequest; +import com.google.bigtable.admin.v2.GetTableRequest; +import com.google.bigtable.admin.v2.ListTablesRequest; +import com.google.bigtable.admin.v2.ListTablesResponse; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; +import com.google.bigtable.admin.v2.Table; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +public class MockBigtableTableAdminImpl extends BigtableTableAdminImplBase { + private ArrayList requests; + private Queue responses; + + public MockBigtableTableAdminImpl() { + 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 createTable(CreateTableRequest request, StreamObserver
responseObserver) { + Object response = responses.remove(); + if (response instanceof Table) { + requests.add(request); + responseObserver.onNext((Table) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listTables( + ListTablesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListTablesResponse) { + requests.add(request); + responseObserver.onNext((ListTablesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getTable(GetTableRequest request, StreamObserver
responseObserver) { + Object response = responses.remove(); + if (response instanceof Table) { + requests.add(request); + responseObserver.onNext((Table) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteTable(DeleteTableRequest 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 modifyColumnFamilies( + ModifyColumnFamiliesRequest request, StreamObserver
responseObserver) { + Object response = responses.remove(); + if (response instanceof Table) { + requests.add(request); + responseObserver.onNext((Table) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void dropRowRange(DropRowRangeRequest 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-bigtable/src/test/java/com/google/cloud/bigtable/v2/BigtableClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/v2/BigtableClientTest.java new file mode 100644 index 000000000000..498e7eafec52 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/v2/BigtableClientTest.java @@ -0,0 +1,366 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.v2; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.grpc.testing.MockStreamObserver; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.bigtable.v2.CheckAndMutateRowRequest; +import com.google.bigtable.v2.CheckAndMutateRowResponse; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.bigtable.v2.MutateRowResponse; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsRequest.Entry; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.bigtable.v2.Mutation; +import com.google.bigtable.v2.ReadModifyWriteRowRequest; +import com.google.bigtable.v2.ReadModifyWriteRowResponse; +import com.google.bigtable.v2.ReadModifyWriteRule; +import com.google.bigtable.v2.ReadRowsRequest; +import com.google.bigtable.v2.ReadRowsResponse; +import com.google.bigtable.v2.RowFilter; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.bigtable.v2.TableName; +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.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 BigtableClientTest { + private static MockBigtable mockBigtable; + private static MockServiceHelper serviceHelper; + private BigtableClient client; + + @BeforeClass + public static void startStaticServer() { + mockBigtable = new MockBigtable(); + serviceHelper = + new MockServiceHelper("in-process-1", Arrays.asList(mockBigtable)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + BigtableSettings settings = + BigtableSettings.newBuilder() + .setTransportChannelProvider(serviceHelper.createChannelProvider()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = BigtableClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void readRowsTest() throws Exception { + ByteString lastScannedRowKey = ByteString.copyFromUtf8("-126"); + ReadRowsResponse expectedResponse = + ReadRowsResponse.newBuilder().setLastScannedRowKey(lastScannedRowKey).build(); + mockBigtable.addResponse(expectedResponse); + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ReadRowsRequest request = + ReadRowsRequest.newBuilder().setTableNameWithTableName(tableName).build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = client.readRowsCallable(); + callable.serverStreamingCall(request, responseObserver); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + @SuppressWarnings("all") + public void readRowsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtable.addException(exception); + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ReadRowsRequest request = + ReadRowsRequest.newBuilder().setTableNameWithTableName(tableName).build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = client.readRowsCallable(); + callable.serverStreamingCall(request, responseObserver); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof StatusRuntimeException); + StatusRuntimeException statusException = (StatusRuntimeException) e.getCause(); + Assert.assertEquals(Status.INVALID_ARGUMENT, statusException.getStatus()); + } + } + + @Test + @SuppressWarnings("all") + public void sampleRowKeysTest() throws Exception { + ByteString rowKey = ByteString.copyFromUtf8("122"); + long offsetBytes = 889884095L; + SampleRowKeysResponse expectedResponse = + SampleRowKeysResponse.newBuilder().setRowKey(rowKey).setOffsetBytes(offsetBytes).build(); + mockBigtable.addResponse(expectedResponse); + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + SampleRowKeysRequest request = + SampleRowKeysRequest.newBuilder().setTableNameWithTableName(tableName).build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.sampleRowKeysCallable(); + callable.serverStreamingCall(request, responseObserver); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + @SuppressWarnings("all") + public void sampleRowKeysExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtable.addException(exception); + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + SampleRowKeysRequest request = + SampleRowKeysRequest.newBuilder().setTableNameWithTableName(tableName).build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.sampleRowKeysCallable(); + callable.serverStreamingCall(request, responseObserver); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof StatusRuntimeException); + StatusRuntimeException statusException = (StatusRuntimeException) e.getCause(); + Assert.assertEquals(Status.INVALID_ARGUMENT, statusException.getStatus()); + } + } + + @Test + @SuppressWarnings("all") + public void mutateRowTest() { + MutateRowResponse expectedResponse = MutateRowResponse.newBuilder().build(); + mockBigtable.addResponse(expectedResponse); + + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ByteString rowKey = ByteString.copyFromUtf8("122"); + List mutations = new ArrayList<>(); + + MutateRowResponse actualResponse = client.mutateRow(tableName, rowKey, mutations); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtable.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + MutateRowRequest actualRequest = (MutateRowRequest) actualRequests.get(0); + + Assert.assertEquals(tableName, actualRequest.getTableNameAsTableName()); + Assert.assertEquals(rowKey, actualRequest.getRowKey()); + Assert.assertEquals(mutations, actualRequest.getMutationsList()); + } + + @Test + @SuppressWarnings("all") + public void mutateRowExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtable.addException(exception); + + try { + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ByteString rowKey = ByteString.copyFromUtf8("122"); + List mutations = new ArrayList<>(); + + client.mutateRow(tableName, rowKey, mutations); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void mutateRowsTest() throws Exception { + MutateRowsResponse expectedResponse = MutateRowsResponse.newBuilder().build(); + mockBigtable.addResponse(expectedResponse); + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + List entries = new ArrayList<>(); + MutateRowsRequest request = + MutateRowsRequest.newBuilder() + .setTableNameWithTableName(tableName) + .addAllEntries(entries) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.mutateRowsCallable(); + callable.serverStreamingCall(request, responseObserver); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + @SuppressWarnings("all") + public void mutateRowsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtable.addException(exception); + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + List entries = new ArrayList<>(); + MutateRowsRequest request = + MutateRowsRequest.newBuilder() + .setTableNameWithTableName(tableName) + .addAllEntries(entries) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.mutateRowsCallable(); + callable.serverStreamingCall(request, responseObserver); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof StatusRuntimeException); + StatusRuntimeException statusException = (StatusRuntimeException) e.getCause(); + Assert.assertEquals(Status.INVALID_ARGUMENT, statusException.getStatus()); + } + } + + @Test + @SuppressWarnings("all") + public void checkAndMutateRowTest() { + boolean predicateMatched = true; + CheckAndMutateRowResponse expectedResponse = + CheckAndMutateRowResponse.newBuilder().setPredicateMatched(predicateMatched).build(); + mockBigtable.addResponse(expectedResponse); + + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ByteString rowKey = ByteString.copyFromUtf8("122"); + RowFilter predicateFilter = RowFilter.newBuilder().build(); + List trueMutations = new ArrayList<>(); + List falseMutations = new ArrayList<>(); + + CheckAndMutateRowResponse actualResponse = + client.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtable.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CheckAndMutateRowRequest actualRequest = (CheckAndMutateRowRequest) actualRequests.get(0); + + Assert.assertEquals(tableName, actualRequest.getTableNameAsTableName()); + Assert.assertEquals(rowKey, actualRequest.getRowKey()); + Assert.assertEquals(predicateFilter, actualRequest.getPredicateFilter()); + Assert.assertEquals(trueMutations, actualRequest.getTrueMutationsList()); + Assert.assertEquals(falseMutations, actualRequest.getFalseMutationsList()); + } + + @Test + @SuppressWarnings("all") + public void checkAndMutateRowExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtable.addException(exception); + + try { + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ByteString rowKey = ByteString.copyFromUtf8("122"); + RowFilter predicateFilter = RowFilter.newBuilder().build(); + List trueMutations = new ArrayList<>(); + List falseMutations = new ArrayList<>(); + + client.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void readModifyWriteRowTest() { + ReadModifyWriteRowResponse expectedResponse = ReadModifyWriteRowResponse.newBuilder().build(); + mockBigtable.addResponse(expectedResponse); + + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ByteString rowKey = ByteString.copyFromUtf8("122"); + List rules = new ArrayList<>(); + + ReadModifyWriteRowResponse actualResponse = client.readModifyWriteRow(tableName, rowKey, rules); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockBigtable.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ReadModifyWriteRowRequest actualRequest = (ReadModifyWriteRowRequest) actualRequests.get(0); + + Assert.assertEquals(tableName, actualRequest.getTableNameAsTableName()); + Assert.assertEquals(rowKey, actualRequest.getRowKey()); + Assert.assertEquals(rules, actualRequest.getRulesList()); + } + + @Test + @SuppressWarnings("all") + public void readModifyWriteRowExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockBigtable.addException(exception); + + try { + TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); + ByteString rowKey = ByteString.copyFromUtf8("122"); + List rules = new ArrayList<>(); + + client.readModifyWriteRow(tableName, rowKey, rules); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } +} diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/v2/MockBigtable.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/v2/MockBigtable.java new file mode 100644 index 000000000000..0e39397acdb5 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/v2/MockBigtable.java @@ -0,0 +1,55 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.v2; + +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") +public class MockBigtable implements MockGrpcService { + private final MockBigtableImpl serviceImpl; + + public MockBigtable() { + serviceImpl = new MockBigtableImpl(); + } + + @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-bigtable/src/test/java/com/google/cloud/bigtable/v2/MockBigtableImpl.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/v2/MockBigtableImpl.java new file mode 100644 index 000000000000..895555e09de0 --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/v2/MockBigtableImpl.java @@ -0,0 +1,159 @@ +/* + * Copyright 2017 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.v2; + +import com.google.bigtable.v2.BigtableGrpc.BigtableImplBase; +import com.google.bigtable.v2.CheckAndMutateRowRequest; +import com.google.bigtable.v2.CheckAndMutateRowResponse; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.bigtable.v2.MutateRowResponse; +import com.google.bigtable.v2.MutateRowsRequest; +import com.google.bigtable.v2.MutateRowsResponse; +import com.google.bigtable.v2.ReadModifyWriteRowRequest; +import com.google.bigtable.v2.ReadModifyWriteRowResponse; +import com.google.bigtable.v2.ReadRowsRequest; +import com.google.bigtable.v2.ReadRowsResponse; +import com.google.bigtable.v2.SampleRowKeysRequest; +import com.google.bigtable.v2.SampleRowKeysResponse; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +public class MockBigtableImpl extends BigtableImplBase { + private ArrayList requests; + private Queue responses; + + public MockBigtableImpl() { + 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 readRows(ReadRowsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ReadRowsResponse) { + requests.add(request); + responseObserver.onNext((ReadRowsResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void sampleRowKeys( + SampleRowKeysRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof SampleRowKeysResponse) { + requests.add(request); + responseObserver.onNext((SampleRowKeysResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void mutateRow( + MutateRowRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof MutateRowResponse) { + requests.add(request); + responseObserver.onNext((MutateRowResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void mutateRows( + MutateRowsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof MutateRowsResponse) { + requests.add(request); + responseObserver.onNext((MutateRowsResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void checkAndMutateRow( + CheckAndMutateRowRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof CheckAndMutateRowResponse) { + requests.add(request); + responseObserver.onNext((CheckAndMutateRowResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void readModifyWriteRow( + ReadModifyWriteRowRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ReadModifyWriteRowResponse) { + requests.add(request); + responseObserver.onNext((ReadModifyWriteRowResponse) 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/pom.xml b/google-cloud/pom.xml index a6bb16c0f778..0d67620446e8 100644 --- a/google-cloud/pom.xml +++ b/google-cloud/pom.xml @@ -15,6 +15,10 @@ 0.26.1-alpha-SNAPSHOT + + ${project.groupId} + google-cloud-bigtable + ${project.groupId} google-cloud-bigquery diff --git a/pom.xml b/pom.xml index 6a61c328453e..18f6ce2092e9 100644 --- a/pom.xml +++ b/pom.xml @@ -154,6 +154,7 @@ 2.6 0.26.1-alpha-SNAPSHOT + 0.26.1-beta-SNAPSHOT 0.26.1-beta-SNAPSHOT 0.26.1-alpha-SNAPSHOT 0.26.1-alpha-SNAPSHOT @@ -194,6 +195,38 @@ test-jar + + com.google.cloud + google-cloud-bigtable + ${bigtable.version} + + + com.google.cloud + google-cloud-bigtable + ${bigtable.version} + test-jar + + + com.google.api.grpc + proto-google-cloud-bigtable-v2 + ${generatedProto.version} + + + com.google.api.grpc + grpc-google-cloud-bigtable-v2 + ${generatedProto.version} + + + com.google.api.grpc + proto-google-cloud-bigtable-admin-v2 + ${generatedProto.version} + + + com.google.api.grpc + grpc-google-cloud-bigtable-admin-v2 + ${generatedProto.version} + + com.google.cloud google-cloud-bigquery @@ -857,6 +890,7 @@ google-cloud + google-cloud-bigtable google-cloud-bigquery google-cloud-compute google-cloud-contrib @@ -1207,7 +1241,7 @@ Stub packages - com.google.cloud.dlp.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.videointelligence.v1beta1.stub:com.google.cloud.videointelligence.v1beta2.stub:com.google.cloud.vision.v1.stub + com.google.cloud.bigtable.v2.stub:com.google.cloud.bigtable.admin.v2.stub:com.google.cloud.dlp.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.videointelligence.v1beta1.stub:com.google.cloud.videointelligence.v1beta2.stub:com.google.cloud.vision.v1.stub @@ -1215,6 +1249,8 @@ http://google.github.io/google-auth-library-java/releases/${google.auth.version}/apidocs/ http://googleapis.github.io/gax-java/${gax.version}/apidocs/ http://googleapis.github.io/googleapis/java/proto-google-iam-v1/${generatedProto.version}/apidocs/ + http://googleapis.github.io/googleapis/java/proto-google-cloud-bigtable-v2/${generatedProto.version}/apidocs/ + http://googleapis.github.io/googleapis/java/proto-google-cloud-bigtable-admin-v2/${generatedProto.version}/apidocs/ http://googleapis.github.io/googleapis/java/proto-google-cloud-error-reporting-v1beta1/${generatedProto.version}/apidocs/ http://googleapis.github.io/googleapis/java/proto-google-cloud-language-v1/${generatedProto.version}/apidocs/ http://googleapis.github.io/googleapis/java/proto-google-cloud-language-v1beta2/${generatedProto.version}/apidocs/