-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change stream retention to create and update table (#1823)
* feat: add change stream retention to create table Change-Id: I6eec06f3e3178143150490aa5fd97b83b1878cd2 * Remove creating change stream enabled table in IT because we can't delete change stream enabled table Change-Id: Ia2f92ccae3a2582da771b68a26adc1ab5f9d516e * feat: add update table with change stream retention Change-Id: I485507dd224eb0a3a160f7e9b5c569e1ae13ed84 * Disable change stream at end of IT so the table can be deleted Change-Id: I9b64e208ba3bf47f39a7bac3e4a3eb851b2c9468 * Add change stream retention to create table IT Change-Id: I8076da5631aa4dc4f97bba88c8f799303e81a65f * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Tony Tang <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1893be7
commit 05fca58
Showing
8 changed files
with
382 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.bigtable.admin.v2.models; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.bigtable.admin.v2.ChangeStreamConfig; | ||
import com.google.cloud.bigtable.admin.v2.internal.NameUtil; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Objects; | ||
import org.threeten.bp.Duration; | ||
|
||
/** | ||
* Wrapper for {@link com.google.bigtable.admin.v2.UpdateTableRequest} | ||
* | ||
* <p>Allows for updating table: | ||
* | ||
* <ul> | ||
* <li>Change stream retention period. | ||
* </ul> | ||
*/ | ||
public class UpdateTableRequest { | ||
|
||
private final String tableId; | ||
|
||
private final com.google.bigtable.admin.v2.UpdateTableRequest.Builder requestBuilder = | ||
com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder(); | ||
|
||
public static UpdateTableRequest of(String tableId) { | ||
return new UpdateTableRequest(tableId); | ||
} | ||
|
||
private UpdateTableRequest(String tableId) { | ||
this.tableId = tableId; | ||
} | ||
|
||
/** Update change stream retention period between 1 day and 7 days. */ | ||
public UpdateTableRequest addChangeStreamRetention(Duration retention) { | ||
Preconditions.checkNotNull(retention); | ||
if (!retention.isZero()) { | ||
requestBuilder | ||
.getTableBuilder() | ||
.setChangeStreamConfig( | ||
ChangeStreamConfig.newBuilder() | ||
.setRetentionPeriod( | ||
com.google.protobuf.Duration.newBuilder() | ||
.setSeconds(retention.getSeconds()) | ||
.setNanos(retention.getNano()) | ||
.build()) | ||
.build()); | ||
requestBuilder.getUpdateMaskBuilder().addPaths("change_stream_config.retention_period"); | ||
} else { | ||
requestBuilder.getTableBuilder().clearChangeStreamConfig(); | ||
requestBuilder.getUpdateMaskBuilder().addPaths("change_stream_config"); | ||
} | ||
return this; | ||
} | ||
|
||
/** Disable change stream for table */ | ||
public UpdateTableRequest disableChangeStreamRetention() { | ||
return addChangeStreamRetention(Duration.ZERO); | ||
} | ||
|
||
@InternalApi | ||
public com.google.bigtable.admin.v2.UpdateTableRequest toProto( | ||
String projectId, String instanceId) { | ||
requestBuilder | ||
.getTableBuilder() | ||
.setName(NameUtil.formatTableName(projectId, instanceId, tableId)); | ||
return requestBuilder.build(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof UpdateTableRequest)) return false; | ||
UpdateTableRequest that = (UpdateTableRequest) o; | ||
return Objects.equals(requestBuilder, that.requestBuilder); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(requestBuilder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.