Skip to content

Commit

Permalink
removing samples
Browse files Browse the repository at this point in the history
  • Loading branch information
asthamohta committed Mar 25, 2022
1 parent 430f772 commit 10d2134
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 198 deletions.
20 changes: 1 addition & 19 deletions samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@
<module>snippets</module>
</modules>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.19.1-SNAPSHOT</version>
</dependency>
<!-- [END spanner_install_with_bom] -->
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.19.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.19.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand All @@ -71,4 +53,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
11 changes: 0 additions & 11 deletions samples/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,8 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.19.1-SNAPSHOT</version>
</dependency>
<!-- [END spanner_install_with_bom] -->
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.19.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.19.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>io.opencensus</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Operation> 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<Operation> operations = instance.listBackupOperations(Options.filter(filter));
for (Operation op : operations.iterateAll()) {
try {
CreateBackupMetadata metadata = op.getMetadata().unpack(CreateBackupMetadata.class);
System.out.println(
Expand All @@ -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<Operation> 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]

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 10d2134

Please sign in to comment.