1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16+
1617package com .google .cloud .bigtable .admin .v2 .models ;
1718
1819import com .google .api .core .InternalApi ;
@@ -33,44 +34,49 @@ public enum ReplicationState {
3334 /** The replication state of the table is unknown in this cluster. */
3435 NOT_KNOWN (com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState .STATE_NOT_KNOWN ),
3536 /**
36- * The cluster was recently created, and the table must finish copying over pre-existing data
37- * from other clusters before it can begin receiving live replication updates and serving Data
38- * API requests.
37+ * The cluster was recently created, and the table must finish copying over
38+ * pre-existing data from other clusters before it can begin receiving live
39+ * replication updates and serving Data API requests.
3940 */
4041 INITIALIZING (com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState .INITIALIZING ),
4142 /**
42- * The table is temporarily unable to serve Data API requests from this cluster due to planned
43- * internal maintenance.
43+ * The table is temporarily unable to serve Data API requests from this cluster
44+ * due to planned internal maintenance.
4445 */
4546 PLANNED_MAINTENANCE (
4647 com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState .PLANNED_MAINTENANCE ),
4748 /**
48- * The table is temporarily unable to serve Data API requests from this cluster due to unplanned
49- * or emergency maintenance.
49+ * The table is temporarily unable to serve Data API requests from this cluster
50+ * due to unplanned or emergency maintenance.
5051 */
5152 UNPLANNED_MAINTENANCE (
5253 com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState .UNPLANNED_MAINTENANCE ),
5354 /**
54- * The table can serve Data API requests from this cluster. Depending on replication delay,
55- * reads may not immediately reflect the state of the table in other clusters.
55+ * The table can serve Data API requests from this cluster. Depending on
56+ * replication delay, reads may not immediately reflect the state of the
57+ * table in other clusters.
5658 */
5759 READY (com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState .READY ),
5860
5961 /**
60- * The table is fully created and ready for use after a restore, and is being optimized for
61- * performance. When optimizations are complete, the table will transition to `READY` state.
62+ * The table is fully created and ready for use after a restore, and is being
63+ * optimized for performance. When optimizations are complete, the table will
64+ * transition to`READY` state.
6265 */
6366 READY_OPTIMIZING (
6467 com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState .READY_OPTIMIZING ),
6568
66- /** The replication state of table is not known by this client. Please upgrade your client. */
69+ /**
70+ * The replication state of table is not known by this client. Please upgrade
71+ * your client.
72+ */
6773 UNRECOGNIZED (com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState .UNRECOGNIZED );
6874
6975 private final com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState proto ;
7076
7177 /**
72- * Wraps the protobuf. This method is considered an internal implementation detail and not meant
73- * to be used by applications.
78+ * Wraps the protobuf. This method is considered an internal implementation
79+ * detail and not meant to be used by applications.
7480 */
7581 @ InternalApi
7682 public static ReplicationState fromProto (
@@ -90,38 +96,40 @@ public static ReplicationState fromProto(
9096 }
9197
9298 /**
93- * Creates the request protobuf. This method is considered an internal implementation detail and
94- * not meant to be used by applications.
99+ * Creates the request protobuf. This method is considered an internal
100+ * implementation detail and not meant to be used by applications.
95101 */
96102 @ InternalApi
97103 public com .google .bigtable .admin .v2 .Table .ClusterState .ReplicationState toProto () {
98104 return proto ;
99105 }
100106 }
101107
102- public final class AutomatedBackupPolicy {
108+ public final static class AutomatedBackupPolicy {
103109 private final com .google .bigtable .admin .v2 .Table .AutomatedBackupPolicy proto ;
104110
105111 /**
106- * Wraps the protobuf. This method is considered an internal implementation detail and not meant
107- * to be used by applications.
112+ * Wraps the protobuf. This method is considered an internal implementation
113+ * detail and not meant to be used by applications.
108114 */
109115 @ InternalApi
110- public AutomatedBackupPolicy fromProto (
116+ public static AutomatedBackupPolicy fromProto (
111117 @ Nonnull com .google .bigtable .admin .v2 .Table .AutomatedBackupPolicy proto ) {
112118 return new AutomatedBackupPolicy (proto );
113119 }
114120
115- private AutomatedBackupPolicy (@ Nonnull com .google .bigtable .admin .v2 .Table .AutomatedBackupPolicy proto ) {
121+ private AutomatedBackupPolicy (
122+ @ Nonnull com .google .bigtable .admin .v2 .Table .AutomatedBackupPolicy proto ) {
116123 Preconditions .checkNotNull (proto );
117- Preconditions .checkArgument (!proto .getRetentionPeriod ().isInitialized (), "Retention Period must be set" );
124+ Preconditions .checkArgument (
125+ !proto .getRetentionPeriod ().isInitialized (), "Retention Period must be set" );
118126 Preconditions .checkArgument (!proto .getFrequency ().isInitialized (), "Frequency must be set" );
119127 this .proto = proto ;
120128 }
121129
122130 /**
123- * Creates the request protobuf. This method is considered an internal implementation detail and
124- * not meant to be used by applications.
131+ * Creates the request protobuf. This method is considered an internal
132+ * implementation detail and not meant to be used by applications.
125133 */
126134 @ InternalApi
127135 public com .google .bigtable .admin .v2 .Table .AutomatedBackupPolicy toProto () {
@@ -136,52 +144,60 @@ public com.google.bigtable.admin.v2.Table.AutomatedBackupPolicy toProto() {
136144
137145 private final Duration changeStreamRetention ;
138146 private final boolean deletionProtection ;
147+ private static AutomatedBackupPolicy automatedBackupPolicy ;
139148
140149 @ InternalApi
141150 public static Table fromProto (@ Nonnull com .google .bigtable .admin .v2 .Table proto ) {
142151 ImmutableMap .Builder <String , ReplicationState > replicationStates = ImmutableMap .builder ();
143152
144- for (Entry <String , com .google .bigtable .admin .v2 .Table .ClusterState > entry :
145- proto . getClusterStatesMap () .entrySet ()) {
153+ for (Entry <String , com .google .bigtable .admin .v2 .Table .ClusterState > entry : proto . getClusterStatesMap ()
154+ .entrySet ()) {
146155 replicationStates .put (
147156 entry .getKey (), ReplicationState .fromProto (entry .getValue ().getReplicationState ()));
148157 }
149158
150159 ImmutableList .Builder <ColumnFamily > columnFamilies = ImmutableList .builder ();
151160
152- for (Entry <String , com .google .bigtable .admin .v2 .ColumnFamily > entry :
153- proto .getColumnFamiliesMap ().entrySet ()) {
161+ for (Entry <String , com .google .bigtable .admin .v2 .ColumnFamily > entry : proto .getColumnFamiliesMap ().entrySet ()) {
154162 columnFamilies .add (ColumnFamily .fromProto (entry .getKey (), entry .getValue ()));
155163 }
156164
157165 Duration changeStreamConfig = null ;
158166 if (proto .hasChangeStreamConfig ()) {
159- changeStreamConfig =
160- Duration .ofSeconds (
161- proto .getChangeStreamConfig ().getRetentionPeriod ().getSeconds (),
162- proto .getChangeStreamConfig ().getRetentionPeriod ().getNanos ());
167+ changeStreamConfig = Duration .ofSeconds (
168+ proto .getChangeStreamConfig ().getRetentionPeriod ().getSeconds (),
169+ proto .getChangeStreamConfig ().getRetentionPeriod ().getNanos ());
170+ }
171+
172+ if (proto .hasAutomatedBackupPolicy ()) {
173+ automatedBackupPolicy = AutomatedBackupPolicy .fromProto (proto .getAutomatedBackupPolicy ());
174+ } else {
175+ automatedBackupPolicy = null ;
163176 }
164177
165178 return new Table (
166179 TableName .parse (proto .getName ()),
167180 replicationStates .build (),
168181 columnFamilies .build (),
169182 changeStreamConfig ,
170- proto .getDeletionProtection ());
183+ proto .getDeletionProtection (),
184+ automatedBackupPolicy );
171185 }
172186
173187 private Table (
174188 TableName tableName ,
175189 Map <String , ReplicationState > replicationStatesByClusterId ,
176190 List <ColumnFamily > columnFamilies ,
177191 Duration changeStreamRetention ,
178- boolean deletionProtection ) {
192+ boolean deletionProtection ,
193+ AutomatedBackupPolicy automatedBackupPolicy ) {
179194 this .instanceId = tableName .getInstance ();
180195 this .id = tableName .getTable ();
181196 this .replicationStatesByClusterId = replicationStatesByClusterId ;
182197 this .columnFamilies = columnFamilies ;
183198 this .changeStreamRetention = changeStreamRetention ;
184199 this .deletionProtection = deletionProtection ;
200+ Table .automatedBackupPolicy = automatedBackupPolicy ;
185201 }
186202
187203 /** Gets the table's id. */
@@ -211,6 +227,16 @@ public boolean isDeletionProtected() {
211227 return deletionProtection ;
212228 }
213229
230+ /** Returns whether this table has automated backups enabled. */
231+ public boolean isAutomatedBackupEnabled () {
232+ return automatedBackupPolicy == null ? false : true ;
233+ }
234+
235+ /** Returns the automated backup policy. */
236+ public AutomatedBackupPolicy getAutomatedBackupPolicy () {
237+ return automatedBackupPolicy ;
238+ }
239+
214240 @ Override
215241 public boolean equals (Object o ) {
216242 if (this == o ) {
@@ -225,7 +251,8 @@ public boolean equals(Object o) {
225251 && Objects .equal (replicationStatesByClusterId , table .replicationStatesByClusterId )
226252 && Objects .equal (columnFamilies , table .columnFamilies )
227253 && Objects .equal (changeStreamRetention , table .changeStreamRetention )
228- && Objects .equal (deletionProtection , table .deletionProtection );
254+ && Objects .equal (deletionProtection , table .deletionProtection )
255+ && Objects .equal (automatedBackupPolicy , Table .automatedBackupPolicy );
229256 }
230257
231258 @ Override
@@ -236,6 +263,7 @@ public int hashCode() {
236263 replicationStatesByClusterId ,
237264 columnFamilies ,
238265 changeStreamRetention ,
239- deletionProtection );
266+ deletionProtection ,
267+ automatedBackupPolicy );
240268 }
241269}
0 commit comments