use of com.google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata in project java-spanner by googleapis.
the class DatabaseAdminClientTest method instanceListDatabaseOperationsWithMetadata.
@Test
public void instanceListDatabaseOperationsWithMetadata() throws Exception {
Instance instance = spanner.getInstanceAdminClient().newInstanceBuilder(InstanceId.of(PROJECT_ID, INSTANCE_ID)).build();
String filter = "(metadata.@type:type.googleapis.com/" + "google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata)";
mockDatabaseAdmin.addFilterMatches(filter, restoreDatabaseOperation.getMetadata().get().getOptimizeDatabaseOperationName());
Iterable<Operation> operations = instance.listDatabaseOperations(Options.filter(filter)).iterateAll();
assertThat(operations).hasSize(1);
for (Operation op : operations) {
OptimizeRestoredDatabaseMetadata metadata = op.getMetadata().unpack(OptimizeRestoredDatabaseMetadata.class);
String progress = String.format("Restored database %s is optimized %d%%", metadata.getName(), metadata.getProgress().getProgressPercent());
assertThat(progress.contains("100%"));
}
}
use of com.google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata in project java-spanner by googleapis.
the class SpannerSample method listDatabaseOperations.
// [END spanner_list_backup_operations]
// [START spanner_list_database_operations]
static void listDatabaseOperations(InstanceAdminClient instanceAdminClient, DatabaseAdminClient dbAdminClient, InstanceId instanceId) {
Instance instance = instanceAdminClient.getInstance(instanceId.getInstance());
// Get optimize restored database operations.
Timestamp last24Hours = Timestamp.ofTimeSecondsAndNanos(TimeUnit.SECONDS.convert(TimeUnit.HOURS.convert(Timestamp.now().getSeconds(), TimeUnit.SECONDS) - 24, TimeUnit.HOURS), 0);
String filter = String.format("(metadata.@type:type.googleapis.com/" + "google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata) AND " + "(metadata.progress.start_time > \"%s\")", last24Hours);
for (Operation op : instance.listDatabaseOperations(Options.filter(filter)).iterateAll()) {
try {
OptimizeRestoredDatabaseMetadata metadata = op.getMetadata().unpack(OptimizeRestoredDatabaseMetadata.class);
System.out.println(String.format("Database %s restored from backup is %d%% optimized", metadata.getName(), metadata.getProgress().getProgressPercent()));
} catch (InvalidProtocolBufferException e) {
// The returned operation does not contain OptimizeRestoredDatabaseMetadata.
System.err.println(e.getMessage());
}
}
}
Aggregations