Search in sources :

Example 1 with Snapshot

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

the class BaseBigtableTableAdminClient method deleteSnapshot.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Permanently deletes the specified snapshot.
 *
 * <p>Note: This is a private alpha release of Cloud Bigtable snapshots. This feature is not
 * currently available to most Cloud Bigtable customers. This feature might be changed in
 * backward-incompatible ways and is not recommended for production use. It is not subject to any
 * SLA or deprecation policy.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient =
 *     BaseBigtableTableAdminClient.create()) {
 *   SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
 *   baseBigtableTableAdminClient.deleteSnapshot(name);
 * }
 * }</pre>
 *
 * @param name Required. The unique name of the snapshot to be deleted. Values are of the form
 *     `projects/{project}/instances/{instance}/clusters/{cluster}/snapshots/{snapshot}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteSnapshot(SnapshotName name) {
    DeleteSnapshotRequest request = DeleteSnapshotRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteSnapshot(request);
}
Also used : DeleteSnapshotRequest(com.google.bigtable.admin.v2.DeleteSnapshotRequest)

Example 2 with Snapshot

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

the class BaseBigtableTableAdminClient method deleteSnapshot.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Permanently deletes the specified snapshot.
 *
 * <p>Note: This is a private alpha release of Cloud Bigtable snapshots. This feature is not
 * currently available to most Cloud Bigtable customers. This feature might be changed in
 * backward-incompatible ways and is not recommended for production use. It is not subject to any
 * SLA or deprecation policy.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient =
 *     BaseBigtableTableAdminClient.create()) {
 *   String name =
 *       SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]").toString();
 *   baseBigtableTableAdminClient.deleteSnapshot(name);
 * }
 * }</pre>
 *
 * @param name Required. The unique name of the snapshot to be deleted. Values are of the form
 *     `projects/{project}/instances/{instance}/clusters/{cluster}/snapshots/{snapshot}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteSnapshot(String name) {
    DeleteSnapshotRequest request = DeleteSnapshotRequest.newBuilder().setName(name).build();
    deleteSnapshot(request);
}
Also used : DeleteSnapshotRequest(com.google.bigtable.admin.v2.DeleteSnapshotRequest)

Example 3 with Snapshot

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

the class BaseBigtableTableAdminClientTest method snapshotTableTest2.

@Test
public void snapshotTableTest2() 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);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    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.toString(), 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) TableName(com.google.bigtable.admin.v2.TableName) AbstractMessage(com.google.protobuf.AbstractMessage) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with Snapshot

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

the class BaseBigtableTableAdminClientTest method snapshotTableTest.

@Test
public void snapshotTableTest() 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);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    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.toString(), actualRequest.getName());
    Assert.assertEquals(cluster.toString(), 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) TableName(com.google.bigtable.admin.v2.TableName) AbstractMessage(com.google.protobuf.AbstractMessage) ClusterName(com.google.bigtable.admin.v2.ClusterName) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 5 with Snapshot

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

the class BaseBigtableTableAdminClientTest method createTableFromSnapshotExceptionTest3.

@Test
public void createTableFromSnapshotExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        String parent = "parent-995424086";
        String tableId = "tableId-1552905847";
        SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
        client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).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());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) SnapshotName(com.google.bigtable.admin.v2.SnapshotName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 AbstractMessage (com.google.protobuf.AbstractMessage)11 ByteString (com.google.protobuf.ByteString)11 Snapshot (com.google.bigtable.admin.v2.Snapshot)8 SnapshotName (com.google.bigtable.admin.v2.SnapshotName)8 Operation (com.google.longrunning.Operation)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 SnapshotTableRequest (com.google.bigtable.admin.v2.SnapshotTableRequest)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 ClusterName (com.google.bigtable.admin.v2.ClusterName)3 DeleteSnapshotRequest (com.google.bigtable.admin.v2.DeleteSnapshotRequest)3 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)2 CreateTableFromSnapshotRequest (com.google.bigtable.admin.v2.CreateTableFromSnapshotRequest)2 GetSnapshotRequest (com.google.bigtable.admin.v2.GetSnapshotRequest)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2 ListSnapshotsRequest (com.google.bigtable.admin.v2.ListSnapshotsRequest)2 ListSnapshotsResponse (com.google.bigtable.admin.v2.ListSnapshotsResponse)2 Table (com.google.bigtable.admin.v2.Table)2 TableName (com.google.bigtable.admin.v2.TableName)2 ListSnapshotsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListSnapshotsPagedResponse)2