Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add admin APIs for AuthorizedView #2175

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Add tests and change AuthorizedViewType to InternalExtensionOnly
Change-Id: I2e7f04d0f7815d014928a924d4a4f26adb2b655d
  • Loading branch information
Lixia Chen committed Mar 19, 2024
commit d37860eea1da3d6b33ba719d692e931093f31736
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.bigtable.admin.v2.models;

import com.google.api.core.InternalApi;
import com.google.api.core.InternalExtensionOnly;
import com.google.bigtable.admin.v2.AuthorizedViewName;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -118,6 +119,6 @@ public int hashCode() {
* Represents a subset of a Table. Please check the implementations of this interface for more
* details.
*/
@InternalApi
@InternalExtensionOnly
public interface AuthorizedViewType {}
trollyxia marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.cloud.bigtable.admin.v2.models.AuthorizedView;
import com.google.cloud.bigtable.admin.v2.models.CreateAuthorizedViewRequest;
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
import com.google.cloud.bigtable.admin.v2.models.FamilySubsets;
import com.google.cloud.bigtable.admin.v2.models.SubsetView;
import com.google.cloud.bigtable.admin.v2.models.Table;
import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest;
Expand Down Expand Up @@ -91,7 +92,11 @@ public void createAuthorizedViewAndGetAuthorizedViewTest() {

CreateAuthorizedViewRequest request =
CreateAuthorizedViewRequest.of(testTable.getId(), authorizedViewId)
.setAuthorizedViewType(SubsetView.create().addRowPrefix("row#"))
.setAuthorizedViewType(
SubsetView.create()
.addRowPrefix("row#")
.addFamilySubsets("cf1", FamilySubsets.create().addQualifier("qualifier"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once we update the logic to replace, we probably also need to update this test

.addFamilySubsets("cf1", FamilySubsets.create().addQualifierPrefix("prefix#")))
.setDeletionProtection(false);
try {
AuthorizedView response = tableAdmin.createAuthorizedView(request);
Expand All @@ -104,6 +109,11 @@ public void createAuthorizedViewAndGetAuthorizedViewTest() {
assertWithMessage("Got wrong subset view in CreateAuthorizedView")
.that(((SubsetView) response.getAuthorizedViewType()).getRowPrefixes())
.containsExactly(ByteString.copyFromUtf8("row#"));
assertWithMessage("Got wrong family subsets in CreateAuthorizedView")
.that(((SubsetView) response.getAuthorizedViewType()).getFamilySubsets())
.containsExactly(
"cf1",
FamilySubsets.create().addQualifier("qualifier").addQualifierPrefix("prefix#"));

response = tableAdmin.getAuthorizedView(testTable.getId(), authorizedViewId);
assertWithMessage("Got wrong authorized view Id in getAuthorizedView")
Expand All @@ -115,6 +125,11 @@ public void createAuthorizedViewAndGetAuthorizedViewTest() {
assertWithMessage("Got wrong subset view in getAuthorizedView")
.that(((SubsetView) response.getAuthorizedViewType()).getRowPrefixes())
.containsExactly(ByteString.copyFromUtf8("row#"));
assertWithMessage("Got wrong family subsets in getAuthorizedView")
.that(((SubsetView) response.getAuthorizedViewType()).getFamilySubsets())
.containsExactly(
"cf1",
FamilySubsets.create().addQualifier("qualifier").addQualifierPrefix("prefix#"));
} finally {
tableAdmin.deleteAuthorizedView(testTable.getId(), authorizedViewId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testToProto() {
}

@Test
public void testUpdateExisting() {
public void testUpdateDeletionProtection() {
com.google.bigtable.admin.v2.AuthorizedView existingAuthorizedView =
com.google.bigtable.admin.v2.AuthorizedView.newBuilder()
.setName(
Expand All @@ -83,6 +83,43 @@ public void testUpdateExisting() {
assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
}

@Test
public void testUpdateSubsetView() {
com.google.bigtable.admin.v2.AuthorizedView authorizedViewProto =
com.google.bigtable.admin.v2.AuthorizedView.newBuilder()
.setName(
NameUtil.formatAuthorizedViewName(
PROJECT_ID, INSTANCE_ID, TABLE_ID, AUTHORIZED_VIEW_ID))
.setSubsetView(
com.google.bigtable.admin.v2.AuthorizedView.SubsetView.newBuilder()
.addRowPrefixes(ByteString.copyFromUtf8("row#"))
.putFamilySubsets(
"cf",
com.google.bigtable.admin.v2.AuthorizedView.FamilySubsets.newBuilder()
.addQualifiers(ByteString.copyFromUtf8("qualifier"))
.addQualifierPrefixes(ByteString.copyFromUtf8("prefix#"))
.build()))
.build();

UpdateAuthorizedViewRequest request =
UpdateAuthorizedViewRequest.of(TABLE_ID, AUTHORIZED_VIEW_ID)
.setAuthorizedViewType(
SubsetView.create()
.addRowPrefix("row#")
.addFamilySubsets(
"cf",
FamilySubsets.create()
.addQualifier("qualifier")
.addQualifierPrefix("prefix#")));

com.google.bigtable.admin.v2.UpdateAuthorizedViewRequest requestProto =
com.google.bigtable.admin.v2.UpdateAuthorizedViewRequest.newBuilder()
.setAuthorizedView(authorizedViewProto)
.setUpdateMask(FieldMask.newBuilder().addPaths("subset_view"))
.build();
assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
}

@Test
public void testEquality() {
UpdateAuthorizedViewRequest request =
Expand Down