Skip to content

Commit af2c5cf

Browse files
committed
add backup policy object to table class and retrieval methods
1 parent c80b434 commit af2c5cf

File tree

2 files changed

+89
-54
lines changed

2 files changed

+89
-54
lines changed

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AuthorizedView.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,26 @@
2424
import javax.annotation.Nonnull;
2525

2626
/**
27-
* A class that wraps the {@link com.google.bigtable.admin.v2.AuthorizedView} protocol buffer
28-
* object.
27+
* A class that wraps the {@link com.google.bigtable.admin.v2.AuthorizedView}
28+
* protocol buffer object.
2929
*
30-
* <p>An AuthorizedView represents subsets of a particular table based on rules. The access to each
31-
* AuthorizedView can be configured separately from the Table.
30+
* <p>
31+
* An AuthorizedView represents subsets of a particular table based on rules.
32+
* The access to each AuthorizedView can be configured separately from the
33+
* Table.
3234
*
33-
* <p>Users can perform read/write operation on an AuthorizedView by providing an authorizedView id
34-
* besides a table id, in which case the semantics remain identical as reading/writing on a Table
35-
* except that visibility is restricted to the subset of the Table that the AuthorizedView
36-
* represents.
35+
* <p>
36+
* Users can perform read/write operation on an AuthorizedView by providing an
37+
* authorizedView id besides a table id, in which case the semantics remain
38+
* identical as reading/writing on a Table except that visibility is restricted
39+
* to the subset of the Table that the AuthorizedView represents.
3740
*/
3841
public final class AuthorizedView {
3942
private final com.google.bigtable.admin.v2.AuthorizedView proto;
4043

4144
/**
42-
* Wraps the protobuf. This method is considered an internal implementation detail and not meant
43-
* to be used by applications.
45+
* Wraps the protobuf. This method is considered an internal implementation
46+
* detail and not meant to be used by applications.
4447
*/
4548
@InternalApi
4649
public static AuthorizedView fromProto(
@@ -61,7 +64,7 @@ public String getId() {
6164
// Constructor ensures that name is not null.
6265
AuthorizedViewName fullName = AuthorizedViewName.parse(proto.getName());
6366

64-
//noinspection ConstantConditions
67+
// noinspection ConstantConditions
6568
return fullName.getAuthorizedView();
6669
}
6770

@@ -70,7 +73,7 @@ public String getTableId() {
7073
// Constructor ensures that name is not null.
7174
AuthorizedViewName fullName = AuthorizedViewName.parse(proto.getName());
7275

73-
//noinspection ConstantConditions
76+
// noinspection ConstantConditions
7477
return fullName.getTable();
7578
}
7679

@@ -79,7 +82,10 @@ public boolean isDeletionProtected() {
7982
return proto.getDeletionProtection();
8083
}
8184

82-
/** Gets the type of this authorized view, which currently can only be a subset view. */
85+
/**
86+
* Gets the type of this authorized view, which currently can only be a subset
87+
* view.
88+
*/
8389
public AuthorizedViewType getAuthorizedViewType() {
8490
if (proto.hasSubsetView()) {
8591
return SubsetView.fromProto(proto.getSubsetView());
@@ -90,8 +96,8 @@ public AuthorizedViewType getAuthorizedViewType() {
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.AuthorizedView toProto() {
@@ -116,9 +122,10 @@ public int hashCode() {
116122
}
117123

118124
/**
119-
* Represents a subset of a Table. Please check the implementations of this interface for more
120-
* details.
125+
* Represents a subset of a Table. Please check the implementations of this
126+
* interface for more details.
121127
*/
122128
@InternalExtensionOnly
123-
public interface AuthorizedViewType {}
129+
public interface AuthorizedViewType {
130+
}
124131
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package com.google.cloud.bigtable.admin.v2.models;
1718

1819
import 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

Comments
 (0)