From a28dc357e79bed18d542d4e2aaa4bd3c8015ce3d Mon Sep 17 00:00:00 2001 From: Astha Mohta Date: Fri, 25 Mar 2022 13:20:55 +0530 Subject: [PATCH] removing samples --- samples/pom.xml | 20 +------ samples/snippets/pom.xml | 11 ---- .../com/example/spanner/SpannerSample.java | 59 +++++-------------- 3 files changed, 15 insertions(+), 75 deletions(-) diff --git a/samples/pom.xml b/samples/pom.xml index 53b7c5519d8..8271ea6812d 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -33,24 +33,6 @@ snippets - - - com.google.cloud - google-cloud-spanner - 6.19.1-SNAPSHOT - - - - com.google.api.grpc - grpc-google-cloud-spanner-admin-database-v1 - 6.19.1-SNAPSHOT - - - com.google.api.grpc - proto-google-cloud-spanner-admin-database-v1 - 6.19.1-SNAPSHOT - - @@ -71,4 +53,4 @@ - + diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index a0ce1453146..74aaf074d52 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -44,19 +44,8 @@ com.google.cloud google-cloud-spanner - 6.19.1-SNAPSHOT - - com.google.api.grpc - grpc-google-cloud-spanner-admin-database-v1 - 6.19.1-SNAPSHOT - - - com.google.api.grpc - proto-google-cloud-spanner-admin-database-v1 - 6.19.1-SNAPSHOT - io.opencensus diff --git a/samples/snippets/src/main/java/com/example/spanner/SpannerSample.java b/samples/snippets/src/main/java/com/example/spanner/SpannerSample.java index 29a7c26ab56..d0ccd108145 100644 --- a/samples/snippets/src/main/java/com/example/spanner/SpannerSample.java +++ b/samples/snippets/src/main/java/com/example/spanner/SpannerSample.java @@ -56,14 +56,12 @@ import com.google.common.io.BaseEncoding; import com.google.longrunning.Operation; import com.google.protobuf.InvalidProtocolBufferException; -import com.google.spanner.admin.database.v1.CopyBackupMetadata; import com.google.spanner.admin.database.v1.CreateBackupMetadata; import com.google.spanner.admin.database.v1.CreateDatabaseMetadata; import com.google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata; import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata; import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata; import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions; -import java.lang.Math; import java.math.BigDecimal; import java.time.Instant; import java.util.ArrayList; @@ -1661,18 +1659,21 @@ static void cancelCreateBackup( // [END spanner_cancel_backup_create] // [START spanner_list_backup_operations] - static void listBackupOperations( - InstanceAdminClient instanceAdminClient, DatabaseId databaseId, BackupId backupId) { + static void listBackupOperations(InstanceAdminClient instanceAdminClient, DatabaseId databaseId) { Instance instance = instanceAdminClient.getInstance(databaseId.getInstanceId().getInstance()); // Get create backup operations for the sample database. + 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.CreateBackupMetadata) " - + "AND (metadata.database:%s)", - databaseId.getName()); - Page createBackupOperations = instance.listBackupOperations(Options.filter(filter)); - System.out.println("Create Backup Operations:"); - for (Operation op : createBackupOperations.iterateAll()) { + "(metadata.database:%s) AND " + + "(metadata.@type:type.googleapis.com/" + + "google.spanner.admin.database.v1.CreateBackupMetadata) AND " + + "(metadata.progress.start_time > \"%s\")", + databaseId.getName(), last24Hours); + Page operations = instance.listBackupOperations(Options.filter(filter)); + for (Operation op : operations.iterateAll()) { try { CreateBackupMetadata metadata = op.getMetadata().unpack(CreateBackupMetadata.class); System.out.println( @@ -1686,30 +1687,6 @@ static void listBackupOperations( System.err.println(e.getMessage()); } } - - // Get copy backup operations for the sample database. - filter = - String.format( - "(metadata.@type:type.googleapis.com/" - + "google.spanner.admin.database.v1.CopyBackupMetadata) " - + "AND (metadata.source_backup:%s)", - backupId.getName()); - Page copyBackupOperations = instance.listBackupOperations(Options.filter(filter)); - System.out.println("Copy Backup Operations:"); - for (Operation op : copyBackupOperations.iterateAll()) { - try { - CopyBackupMetadata copyBackupMetadata = op.getMetadata().unpack(CopyBackupMetadata.class); - System.out.println( - String.format( - "Copy Backup %s on backup %s pending: %d%% complete", - copyBackupMetadata.getName(), - copyBackupMetadata.getSourceBackup(), - copyBackupMetadata.getProgress().getProgressPercent())); - } catch (InvalidProtocolBufferException e) { - // The returned operation does not contain CopyBackupMetadata. - System.err.println(e.getMessage()); - } - } } // [END spanner_list_backup_operations] @@ -1863,11 +1840,6 @@ static void updateBackup(DatabaseAdminClient dbAdminClient, BackupId backupId) { TimeUnit.SECONDS.toMicros(backup.getExpireTime().getSeconds()) + TimeUnit.NANOSECONDS.toMicros(backup.getExpireTime().getNanos()) + TimeUnit.DAYS.toMicros(30L)); - // New Expire Time must be less than Max Expire Time - expireTime = expireTime.compareTo(backup.getMaxExpireTime())<0?expireTime:backup.getMaxExpireTime(); - int timeDiff = expireTime.compareTo(backup.getExpireTime()); - Timestamp newExpireTime = (timeDiff < 0) ? expireTime : backup.getExpireTime(); - System.out.println(String.format( "Updating expire time of backup [%s] to %s...", backupId.toString(), @@ -2076,7 +2048,7 @@ static void run( BackupId.of(backup.getInstanceId(), backup.getBackup() + "_cancel")); break; case "listbackupoperations": - listBackupOperations(instanceAdminClient, database, backup); + listBackupOperations(instanceAdminClient, database); break; case "listdatabaseoperations": listDatabaseOperations(instanceAdminClient, dbAdminClient, database.getInstanceId()); @@ -2172,14 +2144,14 @@ static void printUsageAndExit() { System.err.println(" SpannerExample querywithqueryoptions my-instance example-db"); System.err.println(" SpannerExample createbackup my-instance example-db"); System.err.println(" SpannerExample listbackups my-instance example-db"); - System.err.println(" SpannerExample listbackupoperations my-instance example-db backup-id"); + System.err.println(" SpannerExample listbackupoperations my-instance example-db"); System.err.println(" SpannerExample listdatabaseoperations my-instance example-db"); System.err.println(" SpannerExample restorebackup my-instance example-db"); System.exit(1); } public static void main(String[] args) throws Exception { - if (args.length != 3 && args.length != 4) { + if (args.length != 3) { printUsageAndExit(); } // [START init_client] @@ -2203,9 +2175,6 @@ public static void main(String[] args) throws Exception { String.format( "%s_%02d", db.getDatabase(), LocalDate.now().get(ChronoField.ALIGNED_WEEK_OF_YEAR)); - if( args.length == 4) { - backupName = args[3]; - } BackupId backup = BackupId.of(db.getInstanceId(), backupName); // [START init_client]