-
Notifications
You must be signed in to change notification settings - Fork 179
Admin interface as GAX admin client #2040
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1d1bf3f
adding first interface
rahulKQL ca4e092
adding adminClient
rahulKQL 3e6e02e
adding first interface
rahulKQL 358516a
adding adminClient
rahulKQL b7455df
adding bigtableTableClient
rahulKQL f44016e
added todo comments
rahulKQL 9770f5f
updated copyright year & remove whitespace
rahulKQL 429aa3f
worked on feedback
rahulKQL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
...e-client-core/src/main/java/com/google/cloud/bigtable/core/IBigtableTableAdminClient.java
This file contains hidden or 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,128 @@ | ||
| /* | ||
| * Copyright 2019 Google LLC. All Rights Reserved. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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.core; | ||
|
|
||
| import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; | ||
| import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; | ||
| import com.google.cloud.bigtable.admin.v2.models.Table; | ||
| import com.google.common.util.concurrent.ListenableFuture; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Interface to wrap {@link com.google.cloud.bigtable.grpc.BigtableTableAdminClient} with | ||
| * Google-Cloud-java's models. | ||
| */ | ||
| public interface IBigtableTableAdminClient { | ||
|
|
||
| /** | ||
| * Creates a new table. The table can be created with a full set of initial column families, | ||
| * specified in the request. | ||
| * @param request a {@link CreateTableRequest} object. | ||
| */ | ||
| Table createTable(CreateTableRequest request); | ||
|
|
||
| /** | ||
| * Creates a new table asynchronously. The table can be created with a full set of initial column | ||
| * families, specified in the request. | ||
| * | ||
| * @param request a {@link CreateTableRequest} object. | ||
| */ | ||
| //TODO(rahulkql): Once it is adapted to v2.models, change the return type to ApiFuture. | ||
| ListenableFuture<Table> createTableAsync(CreateTableRequest request); | ||
|
|
||
| /** | ||
| * Gets the details of a table. | ||
| * | ||
| * @param tableId a String object. | ||
| * @return a {@link Table} object. | ||
| */ | ||
| Table getTable(String tableId); | ||
|
|
||
| /** | ||
| * Gets the details of a table asynchronously. | ||
| * | ||
| * @return a {@link ListenableFuture} that returns a {@link Table} object. | ||
| */ | ||
| //TODO(rahulkql): Once it is adapted to v2.models, change the return type to ApiFuture. | ||
| ListenableFuture<Table> getTableAsync(String tableId); | ||
|
|
||
| /** | ||
| * Lists the names of all tables in an instance. | ||
| * | ||
| * @return an immutable {@link List} object containing tableId. | ||
| */ | ||
| List<String> listTables(); | ||
|
|
||
| /** | ||
| * Lists the names of all tables in an instance asynchronously. | ||
| * | ||
| * @return a {@link ListenableFuture} of type {@link Void} will be set when request is | ||
| * successful otherwise exception will be thrown. | ||
| */ | ||
| //TODO(rahulkql): Once it is adapted to v2.models, change the return type to ApiFuture. | ||
| ListenableFuture<List<String>> listTablesAsync(); | ||
|
|
||
| /** | ||
| * Permanently deletes a specified table and all of its data. | ||
| * | ||
| */ | ||
| void deleteTable(String tableId); | ||
|
|
||
| /** | ||
| * Permanently deletes a specified table and all of its data. | ||
| * | ||
| * @return a {@link ListenableFuture} of type {@link Void} will be set when request is | ||
| * successful otherwise exception will be thrown. | ||
| */ | ||
| //TODO(rahulkql): Once it is adapted to v2.models, change the return type to ApiFuture. | ||
| ListenableFuture<Void> deleteTableAsync(String tableId); | ||
|
|
||
| /** | ||
| * Creates, modifies or deletes a new column family within a specified table. | ||
| * | ||
| * @param request a {@link ModifyColumnFamiliesRequest} object. | ||
| * @return return {@link Table} object that contains the updated table structure. | ||
| */ | ||
| Table modifyFamilies(ModifyColumnFamiliesRequest request); | ||
|
|
||
| /** | ||
| * Creates, modifies or deletes a new column family within a specified table. | ||
| * | ||
| * @param request a {@link ModifyColumnFamiliesRequest} object. | ||
| * @return a {@link ListenableFuture} that returns {@link Table} object that contains | ||
| * the updated table structure. | ||
| */ | ||
| //TODO(rahulkql): Once it is adapted to v2.models, change the return type to ApiFuture. | ||
| ListenableFuture<Table> modifyFamiliesAsync(ModifyColumnFamiliesRequest request); | ||
|
|
||
| /** | ||
| * Permanently deletes all rows in a range. | ||
| * | ||
| * @param tableId | ||
| * @param rowKeyPrefix | ||
| */ | ||
| void dropRowRange(String tableId, String rowKeyPrefix); | ||
|
|
||
| /** | ||
| * Permanently deletes all rows in a range. | ||
| * | ||
| * @param tableId | ||
| * @param rowKeyPrefix | ||
| * @return a {@link ListenableFuture} that returns {@link Void} object. | ||
| */ | ||
| //TODO(rahulkql): Once it is adapted to v2.models, change the return type to ApiFuture. | ||
| ListenableFuture<Void> dropRowRangeAsync(String tableId, String rowKeyPrefix); | ||
| } | ||
223 changes: 223 additions & 0 deletions
223
...nt-core/src/main/java/com/google/cloud/bigtable/grpc/BigtableTableAdminClientWrapper.java
This file contains hidden or 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,223 @@ | ||
| /* | ||
| * Copyright 2019 Google LLC. All Rights Reserved. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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.grpc; | ||
|
|
||
| import com.google.bigtable.admin.v2.DeleteTableRequest; | ||
| import com.google.bigtable.admin.v2.DropRowRangeRequest; | ||
| import com.google.bigtable.admin.v2.GetTableRequest; | ||
| import com.google.bigtable.admin.v2.ListTablesRequest; | ||
| import com.google.bigtable.admin.v2.ListTablesResponse; | ||
| import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; | ||
| import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; | ||
| import com.google.cloud.bigtable.admin.v2.models.Table; | ||
| import com.google.cloud.bigtable.config.BigtableOptions; | ||
| import com.google.cloud.bigtable.core.IBigtableTableAdminClient; | ||
| import com.google.common.base.Function; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.util.concurrent.Futures; | ||
| import com.google.common.util.concurrent.ListenableFuture; | ||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import com.google.protobuf.ByteString; | ||
| import com.google.protobuf.Empty; | ||
| import java.util.List; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * This class implements the {@link IBigtableTableAdminClient} interface and wraps | ||
| * {@link BigtableTableAdminClient} with Google-cloud-java's models. | ||
| */ | ||
| public class BigtableTableAdminClientWrapper implements IBigtableTableAdminClient { | ||
|
|
||
| private final BigtableTableAdminClient adminClient; | ||
| private final BigtableInstanceName instanceName; | ||
|
|
||
| public BigtableTableAdminClientWrapper(@Nonnull BigtableTableAdminClient adminClient, | ||
| @Nonnull BigtableOptions options){ | ||
| Preconditions.checkNotNull(adminClient); | ||
| Preconditions.checkNotNull(options); | ||
| this.adminClient = adminClient; | ||
rahulKQL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.instanceName = new BigtableInstanceName(options.getProjectId(), | ||
| options.getInstanceId()); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public Table createTable(CreateTableRequest request) { | ||
| com.google.bigtable.admin.v2.CreateTableRequest requestProto = | ||
| request.toProto(instanceName.toAdminInstanceName()); | ||
rahulKQL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| adminClient.createTable(requestProto); | ||
|
|
||
| return getTable(requestProto.getTableId()); | ||
igorbernstein2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ListenableFuture<Table> createTableAsync(CreateTableRequest request) { | ||
| com.google.bigtable.admin.v2.CreateTableRequest requestProto = | ||
| request.toProto(instanceName.toAdminInstanceName()); | ||
|
|
||
| return Futures.transform(adminClient.createTableAsync(requestProto), | ||
| new Function<com.google.bigtable.admin.v2.Table, Table>() { | ||
| @Override | ||
| public Table apply(com.google.bigtable.admin.v2.Table tableProto) { | ||
| return Table.fromProto(tableProto); | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public Table getTable(String tableId) { | ||
| GetTableRequest requestProto = GetTableRequest.newBuilder() | ||
| .setName(instanceName.toTableNameStr(tableId)) | ||
| .build(); | ||
|
|
||
| return Table.fromProto(adminClient.getTable(requestProto)); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ListenableFuture<Table> getTableAsync(String tableId) { | ||
| GetTableRequest requestProto = GetTableRequest.newBuilder() | ||
| .setName(instanceName.toTableNameStr(tableId)) | ||
| .build(); | ||
|
|
||
| return Futures.transform(adminClient.getTableAsync(requestProto), | ||
| new Function<com.google.bigtable.admin.v2.Table, Table>() { | ||
| @Override | ||
| public Table apply(com.google.bigtable.admin.v2.Table tableProto) { | ||
| return Table.fromProto(tableProto); | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public List<String> listTables() { | ||
| ListTablesRequest requestProto = ListTablesRequest.newBuilder() | ||
| .setParent(instanceName.toString()) | ||
| .build(); | ||
|
|
||
| ListTablesResponse response = adminClient.listTables(requestProto); | ||
|
|
||
| ImmutableList.Builder<String> tableIdsBuilder = | ||
| ImmutableList.builderWithExpectedSize(response.getTablesList().size()); | ||
| for(com.google.bigtable.admin.v2.Table tableProto : response.getTablesList()){ | ||
| tableIdsBuilder.add(instanceName.toTableId(tableProto.getName())); | ||
| } | ||
|
|
||
| return tableIdsBuilder.build(); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ListenableFuture<List<String>> listTablesAsync() { | ||
| ListTablesRequest request = ListTablesRequest.newBuilder() | ||
| .setParent(instanceName.toString()) | ||
| .build(); | ||
| ListenableFuture<ListTablesResponse> response = adminClient.listTablesAsync(request); | ||
|
|
||
| return Futures.transform(response, new Function<ListTablesResponse, List<String>>() { | ||
| @Override | ||
| public List<String> apply(ListTablesResponse input) { | ||
| ImmutableList.Builder<String> tableIdsBuilder = | ||
| ImmutableList.builderWithExpectedSize(input.getTablesList().size()); | ||
| for(com.google.bigtable.admin.v2.Table tableProto : input.getTablesList()){ | ||
| tableIdsBuilder.add(instanceName.toTableId(tableProto.getName())); | ||
| } | ||
|
|
||
| return tableIdsBuilder.build(); | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public void deleteTable(String tableId) { | ||
| DeleteTableRequest request = DeleteTableRequest.newBuilder() | ||
| .setName(instanceName.toTableNameStr(tableId)) | ||
| .build(); | ||
|
|
||
| adminClient.deleteTable(request); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ListenableFuture<Void> deleteTableAsync(String tableId) { | ||
| DeleteTableRequest request = DeleteTableRequest.newBuilder() | ||
| .setName(instanceName.toTableNameStr(tableId)) | ||
| .build(); | ||
|
|
||
| return Futures.transform(adminClient.deleteTableAsync(request), new Function<Empty, Void>() { | ||
| @Override | ||
| public Void apply(Empty empty) { | ||
| return null; | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public Table modifyFamilies(ModifyColumnFamiliesRequest request) { | ||
| com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest modifyColumnRequestProto = | ||
| request.toProto(instanceName.toAdminInstanceName()); | ||
|
|
||
| return Table.fromProto(adminClient.modifyColumnFamily(modifyColumnRequestProto)); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ListenableFuture<Table> modifyFamiliesAsync(ModifyColumnFamiliesRequest request) { | ||
| com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest modifyColumnRequestProto = | ||
| request.toProto(instanceName.toAdminInstanceName()); | ||
|
|
||
| return Futures.transform(adminClient.modifyColumnFamilyAsync(modifyColumnRequestProto), | ||
| new Function<com.google.bigtable.admin.v2.Table, Table>() { | ||
| @Override | ||
| public Table apply(com.google.bigtable.admin.v2.Table tableProto) { | ||
| return Table.fromProto(tableProto); | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public void dropRowRange(String tableId, String rowKeyPrefix) { | ||
| DropRowRangeRequest requestProto = DropRowRangeRequest.newBuilder() | ||
| .setName(instanceName.toTableNameStr(tableId)) | ||
| .setRowKeyPrefix(ByteString.copyFromUtf8(rowKeyPrefix)) | ||
| .build(); | ||
|
|
||
| adminClient.dropRowRange(requestProto); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public ListenableFuture<Void> dropRowRangeAsync(String tableId, String rowKeyPrefix) { | ||
| DropRowRangeRequest requestProto = DropRowRangeRequest.newBuilder() | ||
| .setName(instanceName.toTableNameStr(tableId)) | ||
| .setRowKeyPrefix(ByteString.copyFromUtf8(rowKeyPrefix)) | ||
| .build(); | ||
|
|
||
| return Futures.transform(adminClient.dropRowRangeAsync(requestProto), new Function<Empty, Void>() { | ||
| @Override | ||
| public Void apply(Empty empty) { | ||
| return null; | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.