20
20
import com .google .common .base .Objects ;
21
21
import com .google .common .base .Preconditions ;
22
22
import javax .annotation .Nonnull ;
23
+ import javax .annotation .Nullable ;
23
24
24
25
/** Fluent wrapper for {@link com.google.bigtable.admin.v2.RestoreTableRequest} */
25
26
public final class RestoreTableRequest {
26
27
private final com .google .bigtable .admin .v2 .RestoreTableRequest .Builder requestBuilder =
27
28
com .google .bigtable .admin .v2 .RestoreTableRequest .newBuilder ();
28
- private final String backupId ;
29
- private final String clusterId ;
29
+ private final String sourceBackupId ;
30
+ private final String sourceClusterId ;
31
+ private final String sourceInstanceId ;
30
32
31
- public static RestoreTableRequest of (String clusterId , String backupId ) {
32
- RestoreTableRequest request = new RestoreTableRequest (clusterId , backupId );
33
+ /**
34
+ * Create a {@link RestoreTableRequest} object. It assumes the source backup locates in the same
35
+ * instance as the destination table. To restore a table from a backup in another instance, use
36
+ * {@link #of(String, String, String) of} method.
37
+ */
38
+ public static RestoreTableRequest of (String sourceClusterId , String sourceBackupId ) {
39
+ RestoreTableRequest request = new RestoreTableRequest (null , sourceClusterId , sourceBackupId );
33
40
return request ;
34
41
}
35
42
36
- private RestoreTableRequest (String clusterId , String backupId ) {
37
- Preconditions .checkNotNull (clusterId );
38
- Preconditions .checkNotNull (backupId );
39
- this .backupId = backupId ;
40
- this .clusterId = clusterId ;
43
+ /**
44
+ * Create a {@link RestoreTableRequest} object. It assumes the source backup locates in the same
45
+ * instance as the destination table. To restore a table from a backup in another instance, use
46
+ * {@link #of(String, String, String) of} method.
47
+ */
48
+ public static RestoreTableRequest of (
49
+ String sourceInstanceId , String sourceClusterId , String sourceBackupId ) {
50
+ RestoreTableRequest request =
51
+ new RestoreTableRequest (sourceInstanceId , sourceClusterId , sourceBackupId );
52
+ return request ;
53
+ }
54
+
55
+ private RestoreTableRequest (
56
+ @ Nullable String sourceInstanceId ,
57
+ @ Nonnull String sourceClusterId ,
58
+ @ Nonnull String sourceBackupId ) {
59
+ Preconditions .checkNotNull (sourceClusterId );
60
+ Preconditions .checkNotNull (sourceBackupId );
61
+ this .sourceBackupId = sourceBackupId ;
62
+ this .sourceInstanceId = sourceInstanceId ;
63
+ this .sourceClusterId = sourceClusterId ;
41
64
}
42
65
43
66
public RestoreTableRequest setTableId (String tableId ) {
@@ -56,13 +79,15 @@ public boolean equals(Object o) {
56
79
}
57
80
RestoreTableRequest that = (RestoreTableRequest ) o ;
58
81
return Objects .equal (requestBuilder .getTableId (), that .requestBuilder .getTableId ())
59
- && Objects .equal (clusterId , that .clusterId )
60
- && Objects .equal (backupId , that .backupId );
82
+ && Objects .equal (sourceInstanceId , that .sourceInstanceId )
83
+ && Objects .equal (sourceClusterId , that .sourceClusterId )
84
+ && Objects .equal (sourceBackupId , that .sourceBackupId );
61
85
}
62
86
63
87
@ Override
64
88
public int hashCode () {
65
- return Objects .hashCode (requestBuilder .getTableId (), clusterId , backupId );
89
+ return Objects .hashCode (
90
+ requestBuilder .getTableId (), sourceInstanceId , sourceClusterId , sourceBackupId );
66
91
}
67
92
68
93
@ InternalApi
@@ -73,7 +98,12 @@ public com.google.bigtable.admin.v2.RestoreTableRequest toProto(
73
98
74
99
return requestBuilder
75
100
.setParent (NameUtil .formatInstanceName (projectId , instanceId ))
76
- .setBackup (NameUtil .formatBackupName (projectId , instanceId , clusterId , backupId ))
101
+ .setBackup (
102
+ NameUtil .formatBackupName (
103
+ projectId ,
104
+ sourceInstanceId == null ? instanceId : sourceInstanceId ,
105
+ sourceClusterId ,
106
+ sourceBackupId ))
77
107
.build ();
78
108
}
79
109
}
0 commit comments