use of com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest in project java-bigtable by googleapis.
the class BigtableTableAdminClientTest method testRestoreTable.
@Test
public void testRestoreTable() throws ExecutionException, InterruptedException {
// Setup
Mockito.when(mockStub.restoreTableOperationCallable()).thenReturn(mockRestoreTableOperationCallable);
Timestamp startTime = Timestamp.newBuilder().setSeconds(1234).build();
Timestamp endTime = Timestamp.newBuilder().setSeconds(5678).build();
String operationName = "my-operation";
RestoreTableRequest req = RestoreTableRequest.of(CLUSTER_ID, BACKUP_ID).setTableId(TABLE_ID);
mockOperationResult(mockRestoreTableOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build(), RestoreTableMetadata.newBuilder().setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setOptimizeTableOperationName(operationName).setSourceType(RestoreSourceType.BACKUP).setBackupInfo(BackupInfo.newBuilder().setBackup(BACKUP_ID).setSourceTable(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setStartTime(startTime).setEndTime(endTime).build()).build());
// Execute
RestoredTableResult actualResult = adminClient.restoreTable(req);
// Verify
assertThat(actualResult.getTable().getId()).isEqualTo(TABLE_ID);
}
use of com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest in project java-bigtable by googleapis.
the class BigtableBackupIT method crossInstanceRestoreTest.
@Test
public void crossInstanceRestoreTest() throws InterruptedException, IOException, ExecutionException, TimeoutException {
String backupId = prefixGenerator.newPrefix();
String restoredTableId = prefixGenerator.newPrefix();
// Create the backup
tableAdmin.createBackup(CreateBackupRequest.of(targetCluster, backupId).setSourceTableId(testTable.getId()).setExpireTime(Instant.now().plus(Duration.ofHours(6))));
Stopwatch stopwatch = Stopwatch.createStarted();
// Set up a new instance to test cross-instance restore. The backup will be restored here
String targetInstance = prefixGenerator.newPrefix();
instanceAdmin.createInstance(CreateInstanceRequest.of(targetInstance).addCluster(targetInstance, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD).setDisplayName("backups-dest-test-instance").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
try (BigtableTableAdminClient destTableAdmin = testEnvRule.env().getTableAdminClientForInstance(targetInstance)) {
// Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
// table operation.
Thread.sleep(Duration.ofMinutes(2).minus(Duration.ofMillis(stopwatch.elapsed(TimeUnit.MILLISECONDS))).toMillis());
try {
RestoreTableRequest req = RestoreTableRequest.of(testEnvRule.env().getInstanceId(), targetCluster, backupId).setTableId(restoredTableId);
RestoredTableResult result = destTableAdmin.restoreTable(req);
assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
assertWithMessage("Incorrect instance id").that(result.getTable().getInstanceId()).isEqualTo(targetInstance);
// The assertion might be missing if the test is running against a HDD cluster or an
// optimization is not necessary.
assertWithMessage("Empty OptimizeRestoredTable token").that(result.getOptimizeRestoredTableOperationToken()).isNotNull();
destTableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
destTableAdmin.getTable(restoredTableId);
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
instanceAdmin.deleteInstance(targetInstance);
}
}
}
use of com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest in project java-bigtable-hbase by googleapis.
the class AbstractBigtableAdmin method cloneSnapshot.
/**
* @param snapshotId a {@link String} object.
* @param tableName a {@link TableName} object.
* @throws IOException if any.
*/
@Override
public void cloneSnapshot(String snapshotId, TableName tableName) throws IOException, TableExistsException, RestoreSnapshotException {
RestoreTableRequest request = RestoreTableRequest.of(getBackupClusterId(), snapshotId).setTableId(tableName.getNameAsString());
FutureUtil.unwrap(adminClientWrapper.restoreTableAsync(request));
}
use of com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest in project java-bigtable by googleapis.
the class BigtableBackupIT method restoreTableTest.
@Test
public void restoreTableTest() throws InterruptedException, ExecutionException {
String backupId = prefixGenerator.newPrefix();
String restoredTableId = prefixGenerator.newPrefix();
tableAdmin.createBackup(createBackupRequest(backupId));
// Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
// table operation.
Thread.sleep(120 * 1000);
try {
RestoreTableRequest req = RestoreTableRequest.of(targetCluster, backupId).setTableId(restoredTableId);
RestoredTableResult result = tableAdmin.restoreTable(req);
assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
if (result.getOptimizeRestoredTableOperationToken() != null) {
// The assertion might be missing if the test is running against a HDD cluster or an
// optimization is not necessary.
tableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
Table restoredTable = tableAdmin.getTable(restoredTableId);
assertWithMessage("Incorrect restored table id").that(restoredTable.getId()).isEqualTo(restoredTableId);
}
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
tableAdmin.deleteTable(restoredTableId);
}
}
Aggregations