com.google.cloud.spanner.InstanceId Java Examples

The following examples show how to use com.google.cloud.spanner.InstanceId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpannerSample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
static void listDatabaseOperations(
    InstanceAdminClient instanceAdminClient,
    DatabaseAdminClient dbAdminClient,
    InstanceId instanceId) {
  Instance instance = instanceAdminClient.getInstance(instanceId.getInstance());
  // Get optimize restored database operations.
  String filter = "(metadata.@type:type.googleapis.com/"
                  + "google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata)";
  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());
    }
  }
}
 
Example #2
Source File: SpannerSampleIT.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateInstanceSample() {
  String instanceId = formatForTest("sample-inst");
  String out =
      runSampleRunnable(
          new Runnable() {
            @Override
            public void run() {
              try {
                CreateInstanceExample.createInstance(
                    dbId.getInstanceId().getProject(), instanceId);
              } finally {
                spanner.getInstanceAdminClient().deleteInstance(instanceId);
              }
            }
          });
  assertThat(out)
      .contains(
          String.format(
              "Instance %s was successfully created",
              InstanceId.of(dbId.getInstanceId().getProject(), instanceId)));
}