2525import com .google .cloud .bigtable .admin .v2 .models .CreateTableRequest ;
2626import com .google .cloud .bigtable .admin .v2 .models .RestoreTableRequest ;
2727import com .google .cloud .bigtable .admin .v2 .models .Table ;
28- import com .google .cloud .bigtable .grpc .BigtableClusterName ;
29- import com .google .cloud .bigtable .grpc .BigtableInstanceName ;
3028import com .google .cloud .bigtable .hbase .BigtableOptionsFactory ;
3129import com .google .cloud .bigtable .hbase .util .Logger ;
3230import com .google .cloud .bigtable .hbase .util .ModifyTableBuilder ;
@@ -86,7 +84,7 @@ public abstract class BigtableAsyncAdmin implements AsyncAdmin {
8684 private final BigtableHBaseSettings settings ;
8785 private final CommonConnection asyncConnection ;
8886 private final String bigtableInstanceName ;
89- private BigtableClusterName bigtableSnapshotClusterName ;
87+ private String snapshotClusterId ;
9088 private final int ttlSeconds ;
9189
9290 public BigtableAsyncAdmin (CommonConnection asyncConnection ) throws IOException {
@@ -98,15 +96,9 @@ public BigtableAsyncAdmin(CommonConnection asyncConnection) throws IOException {
9896 this .asyncConnection = asyncConnection ;
9997
10098 Configuration configuration = asyncConnection .getConfiguration ();
101- String clusterId =
102- configuration .get (BigtableOptionsFactory .BIGTABLE_SNAPSHOT_CLUSTER_ID_KEY , null );
103- if (clusterId != null ) {
104- BigtableInstanceName bigtableInstanceName =
105- new BigtableInstanceName (
106- asyncConnection .getBigtableSettings ().getProjectId (),
107- asyncConnection .getBigtableSettings ().getInstanceId ());
108- bigtableSnapshotClusterName = bigtableInstanceName .toClusterName (clusterId );
109- }
99+
100+ snapshotClusterId = configuration .get (BigtableOptionsFactory .BIGTABLE_SNAPSHOT_CLUSTER_ID_KEY );
101+
110102 this .ttlSeconds =
111103 configuration .getInt (
112104 BigtableOptionsFactory .BIGTABLE_SNAPSHOT_DEFAULT_TTL_SECS_KEY ,
@@ -335,8 +327,7 @@ public CompletableFuture<TableDescriptor> getDescriptor(TableName tableName) {
335327 @ Override
336328 public CompletableFuture <Void > deleteSnapshot (String snapshotId ) {
337329 return toCompletableFuture (
338- bigtableTableAdminClient .deleteBackupAsync (
339- getBackupClusterName ().getClusterId (), snapshotId ));
330+ bigtableTableAdminClient .deleteBackupAsync (getBackupClusterId (), snapshotId ));
340331 }
341332
342333 @ Override
@@ -464,7 +455,7 @@ public CompletableFuture<Void> snapshot(String snapshotId, TableName tableName)
464455
465456 return toCompletableFuture (
466457 bigtableTableAdminClient .createBackupAsync (
467- CreateBackupRequest .of (getBackupClusterName (). getClusterId (), snapshotId )
458+ CreateBackupRequest .of (getBackupClusterId (), snapshotId )
468459 .setExpireTime (expireTime )
469460 .setSourceTableId (tableName .getNameAsString ())))
470461 .thenAccept (backup -> {});
@@ -474,7 +465,7 @@ public CompletableFuture<Void> snapshot(String snapshotId, TableName tableName)
474465 public CompletableFuture <Void > cloneSnapshot (String snapshotId , TableName tableName ) {
475466 return toCompletableFuture (
476467 bigtableTableAdminClient .restoreTableAsync (
477- RestoreTableRequest .of (getBackupClusterName (). getClusterId (), snapshotId )
468+ RestoreTableRequest .of (getBackupClusterId (), snapshotId )
478469 .setTableId (tableName .getNameAsString ())))
479470 .thenAccept (backup -> {});
480471 }
@@ -487,7 +478,7 @@ public CompletableFuture<Void> cloneSnapshot(
487478
488479 @ Override
489480 public CompletableFuture <List <SnapshotDescription >> listSnapshots () {
490- return CompletableFuture .supplyAsync (() -> getBackupClusterName (). getClusterId () )
481+ return CompletableFuture .supplyAsync (this :: getBackupClusterId )
491482 .thenCompose (
492483 c ->
493484 toCompletableFuture (bigtableTableAdminClient .listBackupsAsync (c ))
@@ -517,8 +508,8 @@ private static <T> List<T> filter(Collection<T> r, Predicate<T> predicate) {
517508 return r .stream ().filter (predicate ).collect (Collectors .toList ());
518509 }
519510
520- private synchronized BigtableClusterName getBackupClusterName () {
521- if (this .bigtableSnapshotClusterName == null ) {
511+ private synchronized String getBackupClusterId () {
512+ if (this .snapshotClusterId == null ) {
522513 List <Cluster > clusters =
523514 asyncConnection
524515 .getBigtableApi ()
@@ -531,14 +522,9 @@ private synchronized BigtableClusterName getBackupClusterName() {
531522 asyncConnection .getBigtableSettings ().getProjectId (),
532523 asyncConnection .getBigtableSettings ().getInstanceId (),
533524 clusters .size ()));
534- String clusterName =
535- NameUtil .formatClusterName (
536- asyncConnection .getBigtableSettings ().getProjectId (),
537- asyncConnection .getBigtableSettings ().getInstanceId (),
538- clusters .get (0 ).getId ());
539- bigtableSnapshotClusterName = new BigtableClusterName (clusterName );
525+ snapshotClusterId = clusters .get (0 ).getId ();
540526 }
541- return bigtableSnapshotClusterName ;
527+ return snapshotClusterId ;
542528 }
543529
544530 @ Override
0 commit comments