Skip to content

Commit

Permalink
test: fix clean up of tables with protected views (#2184)
Browse files Browse the repository at this point in the history
Change-Id: I9a4de8ecdaa3a1d096117853cc27805c7544fe04

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Rollback plan is reviewed and LGTMed
- [ ] All new data plane features have a completed end to end testing plan

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the [samples format](
https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
  • Loading branch information
igorbernstein2 committed Mar 28, 2024
1 parent 3ccd8fc commit 864d32c
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.cloud.bigtable.admin.v2.models.AppProfile;
import com.google.cloud.bigtable.admin.v2.models.Cluster;
import com.google.cloud.bigtable.admin.v2.models.Instance;
import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -203,6 +204,7 @@ private void cleanupStaleTables(String stalePrefix) {
continue;
}
if (stalePrefix.compareTo(tableId) > 0) {
prepTableForDelete(tableId);
try {
env().getTableAdminClient().deleteTable(tableId);
} catch (NotFoundException ignored) {
Expand All @@ -212,6 +214,21 @@ private void cleanupStaleTables(String stalePrefix) {
}
}

private void prepTableForDelete(String tableId) {
// Unprotected views
if (!(env() instanceof EmulatorEnv)) {
for (String viewId : env().getTableAdminClient().listAuthorizedViews(tableId)) {
try {
env()
.getTableAdminClient()
.updateAuthorizedView(
UpdateAuthorizedViewRequest.of(tableId, viewId).setDeletionProtection(false));
} catch (NotFoundException ignored) {
}
}
}
}

/**
* Clean up AppProfile that were dynamically created in the default instance that have been
* orphaned.
Expand Down

0 comments on commit 864d32c

Please sign in to comment.