Search in sources :

Example 71 with Cluster

use of com.google.bigtable.admin.v2.Cluster in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method snapshotTableTest4.

@Test
public void snapshotTableTest4() throws Exception {
    Snapshot expectedResponse = Snapshot.newBuilder().setName(SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]").toString()).setSourceTable(Table.newBuilder().build()).setDataSizeBytes(-2110122398).setCreateTime(Timestamp.newBuilder().build()).setDeleteTime(Timestamp.newBuilder().build()).setDescription("description-1724546052").build();
    Operation resultOperation = Operation.newBuilder().setName("snapshotTableTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    String name = "name3373707";
    String cluster = "cluster872092154";
    String snapshotId = "snapshotId-1113817601";
    String description = "description-1724546052";
    Snapshot actualResponse = client.snapshotTableAsync(name, cluster, snapshotId, description).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SnapshotTableRequest actualRequest = ((SnapshotTableRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(cluster, actualRequest.getCluster());
    Assert.assertEquals(snapshotId, actualRequest.getSnapshotId());
    Assert.assertEquals(description, actualRequest.getDescription());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SnapshotTableRequest(com.google.bigtable.admin.v2.SnapshotTableRequest) Snapshot(com.google.bigtable.admin.v2.Snapshot) AbstractMessage(com.google.protobuf.AbstractMessage) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 72 with Cluster

use of com.google.bigtable.admin.v2.Cluster in project java-bigtable by googleapis.

the class BigtableInstanceAdminClient method disableClusterAutoscalingAsync.

/**
 * Asynchronously disables autoscaling and enables manual scaling by setting a static node count
 * for the cluster. Please note that only clusters that belong to a production instance can be
 * resized.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<Cluster> clusterApiFuture = client.disableClusterAutoscalingAsync("my-instance", "my-cluster", 3);
 * Cluster cluster = clusterApiFuture.get();
 * }</pre>
 */
public ApiFuture<Cluster> disableClusterAutoscalingAsync(String instanceId, String clusterId, int staticSize) {
    String name = NameUtil.formatClusterName(projectId, instanceId, clusterId);
    com.google.bigtable.admin.v2.Cluster request = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(name).setServeNodes(staticSize).setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.getDefaultInstance()).build();
    PartialUpdateClusterRequest partialUpdateClusterRequest = PartialUpdateClusterRequest.newBuilder().setUpdateMask(FieldMaskUtil.fromStringList(com.google.bigtable.admin.v2.Cluster.class, Lists.newArrayList("cluster_config.cluster_autoscaling_config", "serve_nodes"))).setCluster(request).build();
    return ApiFutures.transform(stub.partialUpdateClusterOperationCallable().futureCall(partialUpdateClusterRequest), Cluster::fromProto, MoreExecutors.directExecutor());
}
Also used : PartialUpdateClusterRequest(com.google.bigtable.admin.v2.PartialUpdateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster)

Example 73 with Cluster

use of com.google.bigtable.admin.v2.Cluster in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClient method deleteCluster.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a cluster from an instance.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient =
 *     BaseBigtableInstanceAdminClient.create()) {
 *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
 *   baseBigtableInstanceAdminClient.deleteCluster(name);
 * }
 * }</pre>
 *
 * @param name Required. 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().setName(name == null ? null : name.toString()).build();
    deleteCluster(request);
}
Also used : DeleteClusterRequest(com.google.bigtable.admin.v2.DeleteClusterRequest)

Example 74 with Cluster

use of com.google.bigtable.admin.v2.Cluster in project java-bigtable by googleapis.

the class BigtableTableAdminClient method listBackupsAsync.

/**
 * Lists backups in the specified cluster asynchronously.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<List<String>> listFuture = client.listBackupsAsync(clusterId);
 *
 * ApiFutures.addCallback(
 *   listFuture,
 *   new ApiFutureCallback<List<String>>() {
 *     public void onSuccess(List<String> backupIds) {
 *       System.out.println("Got list of backups:");
 *       for (String backupId : backupIds) {
 *         System.out.println(backupId);
 *       }
 *     }
 *
 *     public void onFailure(Throwable t) {
 *       t.printStackTrace();
 *     }
 *   },
 *   MoreExecutors.directExecutor()
 * );
 * }</pre>
 */
public ApiFuture<List<String>> listBackupsAsync(String clusterId) {
    ListBackupsRequest request = ListBackupsRequest.newBuilder().setParent(NameUtil.formatClusterName(projectId, instanceId, clusterId)).build();
    // TODO(igorbernstein2): try to upstream pagination spooling or figure out a way to expose the
    // paginated responses while maintaining the wrapper facade.
    // Fetches the first page.
    ApiFuture<ListBackupsPage> firstPageFuture = ApiFutures.transform(stub.listBackupsPagedCallable().futureCall(request), new ApiFunction<ListBackupsPagedResponse, ListBackupsPage>() {

        @Override
        public ListBackupsPage apply(ListBackupsPagedResponse response) {
            return response.getPage();
        }
    }, MoreExecutors.directExecutor());
    // Fetches the rest of the pages by chaining the futures.
    ApiFuture<List<com.google.bigtable.admin.v2.Backup>> allProtos = ApiFutures.transformAsync(firstPageFuture, new ApiAsyncFunction<ListBackupsPage, List<com.google.bigtable.admin.v2.Backup>>() {

        List<com.google.bigtable.admin.v2.Backup> responseAccumulator = Lists.newArrayList();

        @Override
        public ApiFuture<List<com.google.bigtable.admin.v2.Backup>> apply(ListBackupsPage page) {
            // Add all entries from the page
            responseAccumulator.addAll(Lists.newArrayList(page.getValues()));
            // If this is the last page, just return the accumulated responses.
            if (!page.hasNextPage()) {
                return ApiFutures.immediateFuture(responseAccumulator);
            }
            // Otherwise fetch the next page.
            return ApiFutures.transformAsync(page.getNextPageAsync(), this, MoreExecutors.directExecutor());
        }
    }, MoreExecutors.directExecutor());
    // Wraps all of the accumulated protos.
    return ApiFutures.transform(allProtos, new ApiFunction<List<com.google.bigtable.admin.v2.Backup>, List<String>>() {

        @Override
        public List<String> apply(List<com.google.bigtable.admin.v2.Backup> protos) {
            List<String> results = Lists.newArrayListWithCapacity(protos.size());
            for (com.google.bigtable.admin.v2.Backup proto : protos) {
                results.add(NameUtil.extractBackupIdFromBackupName(proto.getName()));
            }
            return results;
        }
    }, MoreExecutors.directExecutor());
}
Also used : ListBackupsPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) ApiFuture(com.google.api.core.ApiFuture) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

Test (org.junit.Test)59 AbstractMessage (com.google.protobuf.AbstractMessage)28 ByteString (com.google.protobuf.ByteString)27 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)20 StatusRuntimeException (io.grpc.StatusRuntimeException)20 Cluster (com.google.bigtable.admin.v2.Cluster)16 Operation (com.google.longrunning.Operation)16 ExecutionException (java.util.concurrent.ExecutionException)15 ClusterName (com.google.bigtable.admin.v2.ClusterName)14 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)10 HashMap (java.util.HashMap)10 SnapshotName (com.google.bigtable.admin.v2.SnapshotName)8 Backup (com.google.bigtable.admin.v2.Backup)7 Snapshot (com.google.bigtable.admin.v2.Snapshot)7 WeightedCluster (io.envoyproxy.envoy.config.route.v3.WeightedCluster)7 PartialUpdateClusterRequest (com.google.bigtable.admin.v2.PartialUpdateClusterRequest)5 FieldMask (com.google.protobuf.FieldMask)5 ArrayList (java.util.ArrayList)5 BackupName (com.google.bigtable.admin.v2.BackupName)4 InstanceName (com.google.bigtable.admin.v2.InstanceName)4