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()));
}
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());
}
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);
}
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());
}
Aggregations