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

Bigtable Admin: Promote models to top level classes #3513

Merged
merged 6 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
import com.google.bigtable.admin.v2.InstanceName;
import com.google.bigtable.admin.v2.ListTablesRequest;
import com.google.bigtable.admin.v2.ListTablesResponse;
import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest;
import com.google.bigtable.admin.v2.TableName;
import com.google.cloud.bigtable.admin.v2.models.TableAdminRequests.CreateTable;
import com.google.cloud.bigtable.admin.v2.models.TableAdminRequests.ModifyFamilies;
import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses;
import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.ConsistencyToken;
import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.Table;
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.ConsistencyToken;
import com.google.cloud.bigtable.admin.v2.models.Table;
import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
Expand All @@ -56,13 +54,13 @@
*
* <pre>{@code
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) {
* CreateTable createTableReq =
* TableAdminRequests.createTable("tableId")
* CreateTable request =
* CreateTableRequest.of("tableId")
* .addFamily("cf1")
* .addFamily("cf2", GCRULES.maxVersions(10))
* .addSplit(ByteString.copyFromUtf8("b"))
* .addSplit(ByteString.copyFromUtf8("q"));
* client.createTable(createTableReq);
* client.createTable(request);
* }
* }</pre>
*
Expand Down Expand Up @@ -137,21 +135,18 @@ public void close() {
*
* <pre>{@code
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) {
* CreateTable createTableReq =
* TableAdminRequests.createTable("tableId")
* CreateTableRequest request = CreateTableRequest.of("tableId")
* .addFamily("cf2", GCRULES.maxVersions(10))
* client.createTable(createTableReq);
* client.createTable(request);
* }
* }</pre>
*
* @param createTable
* @return the newly created table
* @see CreateTable for createTable configurations
* @see CreateTableRequest for createTable configurations
*/
public Table createTable(CreateTable createTable) {
public Table createTable(CreateTableRequest request) {
com.google.bigtable.admin.v2.Table table =
this.stub.createTableCallable().call(createTable.toProto(instanceName));
return TableAdminResponses.convertTable(table);
this.stub.createTableCallable().call(request.toProto(instanceName));
return Table.fromProto(table);
}

/**
Expand All @@ -161,20 +156,17 @@ public Table createTable(CreateTable createTable) {
*
* <pre>{@code
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) {
* CreateTable createTableReq =
* TableAdminRequests.createTable("tableId")
* CreateTableRequest request = CreateTableRequest.of("tableId")
* .addFamily("cf2", GCRULES.maxVersions(10))
* client.createTableAsync(createTableReq);
* client.createTableAsync(request);
* }
* }</pre>
*
* @param createTable
* @return the newly created table
* @see CreateTable for createTable configurations
* @see CreateTableRequest for createTable configurations
*/
public ApiFuture<Table> createTableAsync(CreateTable createTable) {
public ApiFuture<Table> createTableAsync(CreateTableRequest request) {
return transformToTableResponse(
this.stub.createTableCallable().futureCall(createTable.toProto(instanceName)));
this.stub.createTableCallable().futureCall(request.toProto(instanceName)));
}

/**
Expand All @@ -184,7 +176,7 @@ public ApiFuture<Table> createTableAsync(CreateTable createTable) {
*
* <pre>{@code
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) {
* ModifyFamilies modifyFamiliesReq = TableAdminRequests.modifyFamilies(tableId)
* ModifyFamilies request = ModifyColumnFamiliesRequest.of(tableId)
* .addFamily("mf1")
* .addFamily(
* "mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000)))
Expand All @@ -201,19 +193,16 @@ public ApiFuture<Table> createTableAsync(CreateTable createTable) {
* .rule(GCRULES.maxAge(Duration.ofSeconds(2000)))
* .rule(GCRULES.maxVersions(10)))
* .dropFamily("mf1")
* client.modifyFamilies(modifyFamiliesReq);
* client.modifyFamilies(request);
* }
* }</pre>
*
* @param modifyFamily
* @return the modified table
* @see ModifyFamilies for modifyFamily options
* @see ModifyColumnFamiliesRequest for modifyFamily options
*/
public Table modifyFamilies(ModifyFamilies modifyFamily) {
ModifyColumnFamiliesRequest modReq = modifyFamily.toProto(instanceName);
public Table modifyFamilies(ModifyColumnFamiliesRequest request) {
com.google.bigtable.admin.v2.Table table =
this.stub.modifyColumnFamiliesCallable().call(modReq);
return TableAdminResponses.convertTable(table);
this.stub.modifyColumnFamiliesCallable().call(request.toProto(instanceName));
return Table.fromProto(table);
}

/**
Expand All @@ -223,7 +212,7 @@ public Table modifyFamilies(ModifyFamilies modifyFamily) {
*
* <pre>{@code
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) {
* ModifyFamilies modifyFamiliesReq = TableAdminRequests.modifyFamilies(tableId)
* ModifyFamilies request = ModifyColumnFamiliesRequest.of(tableId)
* .addFamily("mf1")
* .addFamily(
* "mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000)))
Expand All @@ -240,17 +229,15 @@ public Table modifyFamilies(ModifyFamilies modifyFamily) {
* .rule(GCRULES.maxAge(Duration.ofSeconds(2000)))
* .rule(GCRULES.maxVersions(10)))
* .dropFamily("mf1")
* client.modifyFamilies(modifyFamiliesReq);
* client.modifyFamilies(request);
* }
* }</pre>
*
* @param modifyFamily
* @return Modified table
* @see ModifyFamilies for modifyFamily options
* @see ModifyColumnFamiliesRequest for modifyFamily options
*/
public ApiFuture<Table> modifyFamiliesAsync(ModifyFamilies modifyFamily) {
ModifyColumnFamiliesRequest modReq = modifyFamily.toProto(instanceName);
return transformToTableResponse(this.stub.modifyColumnFamiliesCallable().futureCall(modReq));
public ApiFuture<Table> modifyFamiliesAsync(ModifyColumnFamiliesRequest request) {
return transformToTableResponse(
this.stub.modifyColumnFamiliesCallable().futureCall(request.toProto(instanceName)));
}

/**
Expand All @@ -263,8 +250,6 @@ public ApiFuture<Table> modifyFamiliesAsync(ModifyFamilies modifyFamily) {
* client.deleteTable("tableId");
* }
* }</pre>
*
* @param tableId
*/
public void deleteTable(String tableId) {
this.stub.deleteTableCallable().call(composeDeleteTableRequest(tableId));
Expand All @@ -280,8 +265,6 @@ public void deleteTable(String tableId) {
* client.deleteTableAsync("tableId");
* }
* }</pre>
*
* @param tableId
*/
public ApiFuture<Void> deleteTableAsync(String tableId) {
return transformToVoid(
Expand All @@ -298,13 +281,11 @@ public ApiFuture<Void> deleteTableAsync(String tableId) {
* client.getTable("tableId");
* }
* }</pre>
*
* @param tableId
*/
public Table getTable(String tableId) {
com.google.bigtable.admin.v2.Table table =
this.stub.getTableCallable().call(composeGetTableRequest(tableId));
return TableAdminResponses.convertTable(table);
return Table.fromProto(table);
}

/**
Expand All @@ -317,8 +298,6 @@ public Table getTable(String tableId) {
* client.getTableAsync("tableId");
* }
* }</pre>
*
* @param tableId
*/
public ApiFuture<Table> getTableAsync(String tableId) {
return transformToTableResponse(
Expand Down Expand Up @@ -376,9 +355,6 @@ public List<TableName> apply(ListTablesResponse input) {
* client.dropRowRange("tableId");
* }
* }</pre>
*
* @param tableId
* @param rowKeyPrefix
*/
public void dropRowRange(String tableId, String rowKeyPrefix) {
dropRowRange(tableId, ByteString.copyFromUtf8(rowKeyPrefix));
Expand All @@ -394,9 +370,6 @@ public void dropRowRange(String tableId, String rowKeyPrefix) {
* client.dropRowRangeAsync("tableId");
* }
* }</pre>
*
* @param tableId
* @param rowKeyPrefix
*/
public ApiFuture<Void> dropRowRangeAsync(String tableId, String rowKeyPrefix) {
return dropRowRangeAsync(tableId, ByteString.copyFromUtf8(rowKeyPrefix));
Expand All @@ -412,9 +385,6 @@ public ApiFuture<Void> dropRowRangeAsync(String tableId, String rowKeyPrefix) {
* client.dropRowRange("tableId");
* }
* }</pre>
*
* @param tableId
* @param rowKeyPrefix
*/
public void dropRowRange(String tableId, ByteString rowKeyPrefix) {
this.stub.dropRowRangeCallable().call(composeDropRowRangeRequest(tableId, rowKeyPrefix, false));
Expand All @@ -430,9 +400,6 @@ public void dropRowRange(String tableId, ByteString rowKeyPrefix) {
* client.dropRowRangeAsync("tableId");
* }
* }</pre>
*
* @param tableId
* @param rowKeyPrefix
*/
public ApiFuture<Void> dropRowRangeAsync(String tableId, ByteString rowKeyPrefix) {
return transformToVoid(
Expand All @@ -451,8 +418,6 @@ public ApiFuture<Void> dropRowRangeAsync(String tableId, ByteString rowKeyPrefix
* client.dropAllRows("tableId");
* }
* }</pre>
*
* @param tableId
*/
public void dropAllRows(String tableId) {
this.stub.dropRowRangeCallable().call(composeDropRowRangeRequest(tableId, null, true));
Expand All @@ -468,8 +433,6 @@ public void dropAllRows(String tableId) {
* client.dropAllRowsAsync("tableId");
* }
* }</pre>
*
* @param tableId
*/
public ApiFuture<Void> dropAllRowsAsync(String tableId) {
return transformToVoid(
Expand All @@ -489,11 +452,9 @@ public ApiFuture<Void> dropAllRowsAsync(String tableId) {
* ConsistencyToken consistencyToken = client.generateConsistencyToken("tableId");
* }
* }</pre>
*
* @param tableId
*/
public ConsistencyToken generateConsistencyToken(String tableId) {
return TableAdminResponses.convertTokenResponse(
return ConsistencyToken.fromProto(
this.stub
.generateConsistencyTokenCallable()
.call(composeGenerateConsistencyTokenRequest(tableId)));
Expand All @@ -510,8 +471,6 @@ public ConsistencyToken generateConsistencyToken(String tableId) {
* ConsistencyToken consistencyToken = client.generateConsistencyToken("tableId");
* }
* }</pre>
*
* @param tableId
*/
public ApiFuture<ConsistencyToken> generateConsistencyTokenAsync(String tableId) {
ApiFuture<GenerateConsistencyTokenResponse> tokenResp =
Expand All @@ -524,7 +483,7 @@ public ApiFuture<ConsistencyToken> generateConsistencyTokenAsync(String tableId)
new ApiFunction<GenerateConsistencyTokenResponse, ConsistencyToken>() {
@Override
public ConsistencyToken apply(GenerateConsistencyTokenResponse input) {
return TableAdminResponses.convertTokenResponse(input);
return ConsistencyToken.fromProto(input);
}
});
}
Expand All @@ -539,9 +498,6 @@ public ConsistencyToken apply(GenerateConsistencyTokenResponse input) {
* boolean consistent = client.isConsistent("tableId", token);
* }
* }</pre>
*
* @param tableId
* @param token
*/
public boolean isConsistent(String tableId, ConsistencyToken token) {
return stub.checkConsistencyCallable()
Expand All @@ -559,9 +515,6 @@ public boolean isConsistent(String tableId, ConsistencyToken token) {
* boolean consistent = client.isConsistentAsync("tableId", token);
* }
* }</pre>
*
* @param tableId
* @param token
*/
public ApiFuture<Boolean> isConsistentAsync(String tableId, ConsistencyToken token) {
ApiFuture<CheckConsistencyResponse> checkConsResp =
Expand All @@ -580,9 +533,6 @@ public Boolean apply(CheckConsistencyResponse input) {
/**
* Helper method to construct the table name in format:
* projects/{project}/instances/{instance}/tables/{tableId}
*
* @param tableId
* @return unique table name
*/
@VisibleForTesting
String getTableName(String tableId) {
Expand All @@ -599,8 +549,6 @@ ListTablesRequest composeListTableRequest() {

/**
* Helper method to build an instance of GetTableRequest
*
* @param tableId
*/
@VisibleForTesting
GetTableRequest composeGetTableRequest(String tableId) {
Expand All @@ -609,8 +557,6 @@ GetTableRequest composeGetTableRequest(String tableId) {

/**
* Helper method to build an instance of DeleteTableRequest
*
* @param tableId
*/
@VisibleForTesting
DeleteTableRequest composeDeleteTableRequest(String tableId) {
Expand All @@ -619,10 +565,6 @@ DeleteTableRequest composeDeleteTableRequest(String tableId) {

/**
* Helper method to build an instance of DropRowRangeRequest
*
* @param tableId
* @param rowKeyPrefix
* @param boolean dropAll
*/
@VisibleForTesting
DropRowRangeRequest composeDropRowRangeRequest(
Expand All @@ -639,8 +581,6 @@ DropRowRangeRequest composeDropRowRangeRequest(

/**
* Helper method to build an instance of GenerateConsistencyTokenRequest
*
* @param tableId
*/
@VisibleForTesting
GenerateConsistencyTokenRequest composeGenerateConsistencyTokenRequest(String tableId) {
Expand All @@ -649,8 +589,6 @@ GenerateConsistencyTokenRequest composeGenerateConsistencyTokenRequest(String ta

/**
* Helper method to convert ListTablesResponse to List<TableName>
*
* @param listTablesResponse
*/
@VisibleForTesting
static List<TableName> convertToTableNames(ListTablesResponse listTablesResponse) {
Expand All @@ -662,10 +600,9 @@ static List<TableName> convertToTableNames(ListTablesResponse listTablesResponse
return tableNames;
}

// TODO(igorbernstein): rename methods to make clear that they deal with futures.
/**
* Helper method to transform ApiFuture<com.google.bigtable.admin.v2.Table> to ApiFuture<Table>
*
* @param future
*/
@VisibleForTesting
static ApiFuture<Table> transformToTableResponse(
Expand All @@ -675,15 +612,13 @@ static ApiFuture<Table> transformToTableResponse(
new ApiFunction<com.google.bigtable.admin.v2.Table, Table>() {
@Override
public Table apply(com.google.bigtable.admin.v2.Table table) {
return TableAdminResponses.convertTable(table);
return Table.fromProto(table);
}
});
}

/**
* Helper method to transform ApiFuture<Empty> to ApiFuture<Void>
*
* @param future
*/
@VisibleForTesting
static ApiFuture<Void> transformToVoid(ApiFuture<Empty> future) {
Expand Down
Loading