diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index c6e2ecc38847..a0d2f911aa7e 100644 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -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; @@ -56,13 +54,13 @@ * *
{@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);
  * }
  * }
* @@ -137,21 +135,18 @@ public void close() { * *
{@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);
    * }
    * }
* - * @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); } /** @@ -161,20 +156,17 @@ public Table createTable(CreateTable createTable) { * *
{@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);
    *  }
    *  }
* - * @param createTable - * @return the newly created table - * @see CreateTable for createTable configurations + * @see CreateTableRequest for createTable configurations */ - public ApiFuture createTableAsync(CreateTable createTable) { + public ApiFuture
createTableAsync(CreateTableRequest request) { return transformToTableResponse( - this.stub.createTableCallable().futureCall(createTable.toProto(instanceName))); + this.stub.createTableCallable().futureCall(request.toProto(instanceName))); } /** @@ -184,7 +176,7 @@ public ApiFuture
createTableAsync(CreateTable createTable) { * *
{@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)))
@@ -201,19 +193,16 @@ public ApiFuture
createTableAsync(CreateTable createTable) { * .rule(GCRULES.maxAge(Duration.ofSeconds(2000))) * .rule(GCRULES.maxVersions(10))) * .dropFamily("mf1") - * client.modifyFamilies(modifyFamiliesReq); + * client.modifyFamilies(request); * } * } * - * @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); } /** @@ -223,7 +212,7 @@ public Table modifyFamilies(ModifyFamilies modifyFamily) { * *
{@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)))
@@ -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);
    * }
    * }
* - * @param modifyFamily - * @return Modified table - * @see ModifyFamilies for modifyFamily options + * @see ModifyColumnFamiliesRequest for modifyFamily options */ - public ApiFuture
modifyFamiliesAsync(ModifyFamilies modifyFamily) { - ModifyColumnFamiliesRequest modReq = modifyFamily.toProto(instanceName); - return transformToTableResponse(this.stub.modifyColumnFamiliesCallable().futureCall(modReq)); + public ApiFuture
modifyFamiliesAsync(ModifyColumnFamiliesRequest request) { + return transformToTableResponse( + this.stub.modifyColumnFamiliesCallable().futureCall(request.toProto(instanceName))); } /** @@ -263,8 +250,6 @@ public ApiFuture
modifyFamiliesAsync(ModifyFamilies modifyFamily) { * client.deleteTable("tableId"); * } * } - * - * @param tableId */ public void deleteTable(String tableId) { this.stub.deleteTableCallable().call(composeDeleteTableRequest(tableId)); @@ -280,8 +265,6 @@ public void deleteTable(String tableId) { * client.deleteTableAsync("tableId"); * } * } - * - * @param tableId */ public ApiFuture deleteTableAsync(String tableId) { return transformToVoid( @@ -298,13 +281,11 @@ public ApiFuture deleteTableAsync(String tableId) { * client.getTable("tableId"); * } * } - * - * @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); } /** @@ -317,8 +298,6 @@ public Table getTable(String tableId) { * client.getTableAsync("tableId"); * } * } - * - * @param tableId */ public ApiFuture
getTableAsync(String tableId) { return transformToTableResponse( @@ -376,9 +355,6 @@ public List apply(ListTablesResponse input) { * client.dropRowRange("tableId"); * } * } - * - * @param tableId - * @param rowKeyPrefix */ public void dropRowRange(String tableId, String rowKeyPrefix) { dropRowRange(tableId, ByteString.copyFromUtf8(rowKeyPrefix)); @@ -394,9 +370,6 @@ public void dropRowRange(String tableId, String rowKeyPrefix) { * client.dropRowRangeAsync("tableId"); * } * } - * - * @param tableId - * @param rowKeyPrefix */ public ApiFuture dropRowRangeAsync(String tableId, String rowKeyPrefix) { return dropRowRangeAsync(tableId, ByteString.copyFromUtf8(rowKeyPrefix)); @@ -412,9 +385,6 @@ public ApiFuture dropRowRangeAsync(String tableId, String rowKeyPrefix) { * client.dropRowRange("tableId"); * } * } - * - * @param tableId - * @param rowKeyPrefix */ public void dropRowRange(String tableId, ByteString rowKeyPrefix) { this.stub.dropRowRangeCallable().call(composeDropRowRangeRequest(tableId, rowKeyPrefix, false)); @@ -430,9 +400,6 @@ public void dropRowRange(String tableId, ByteString rowKeyPrefix) { * client.dropRowRangeAsync("tableId"); * } * } - * - * @param tableId - * @param rowKeyPrefix */ public ApiFuture dropRowRangeAsync(String tableId, ByteString rowKeyPrefix) { return transformToVoid( @@ -451,8 +418,6 @@ public ApiFuture dropRowRangeAsync(String tableId, ByteString rowKeyPrefix * client.dropAllRows("tableId"); * } * } - * - * @param tableId */ public void dropAllRows(String tableId) { this.stub.dropRowRangeCallable().call(composeDropRowRangeRequest(tableId, null, true)); @@ -468,8 +433,6 @@ public void dropAllRows(String tableId) { * client.dropAllRowsAsync("tableId"); * } * } - * - * @param tableId */ public ApiFuture dropAllRowsAsync(String tableId) { return transformToVoid( @@ -489,11 +452,9 @@ public ApiFuture dropAllRowsAsync(String tableId) { * ConsistencyToken consistencyToken = client.generateConsistencyToken("tableId"); * } * } - * - * @param tableId */ public ConsistencyToken generateConsistencyToken(String tableId) { - return TableAdminResponses.convertTokenResponse( + return ConsistencyToken.fromProto( this.stub .generateConsistencyTokenCallable() .call(composeGenerateConsistencyTokenRequest(tableId))); @@ -510,8 +471,6 @@ public ConsistencyToken generateConsistencyToken(String tableId) { * ConsistencyToken consistencyToken = client.generateConsistencyToken("tableId"); * } * } - * - * @param tableId */ public ApiFuture generateConsistencyTokenAsync(String tableId) { ApiFuture tokenResp = @@ -524,7 +483,7 @@ public ApiFuture generateConsistencyTokenAsync(String tableId) new ApiFunction() { @Override public ConsistencyToken apply(GenerateConsistencyTokenResponse input) { - return TableAdminResponses.convertTokenResponse(input); + return ConsistencyToken.fromProto(input); } }); } @@ -539,9 +498,6 @@ public ConsistencyToken apply(GenerateConsistencyTokenResponse input) { * boolean consistent = client.isConsistent("tableId", token); * } * } - * - * @param tableId - * @param token */ public boolean isConsistent(String tableId, ConsistencyToken token) { return stub.checkConsistencyCallable() @@ -559,9 +515,6 @@ public boolean isConsistent(String tableId, ConsistencyToken token) { * boolean consistent = client.isConsistentAsync("tableId", token); * } * } - * - * @param tableId - * @param token */ public ApiFuture isConsistentAsync(String tableId, ConsistencyToken token) { ApiFuture checkConsResp = @@ -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) { @@ -599,8 +549,6 @@ ListTablesRequest composeListTableRequest() { /** * Helper method to build an instance of GetTableRequest - * - * @param tableId */ @VisibleForTesting GetTableRequest composeGetTableRequest(String tableId) { @@ -609,8 +557,6 @@ GetTableRequest composeGetTableRequest(String tableId) { /** * Helper method to build an instance of DeleteTableRequest - * - * @param tableId */ @VisibleForTesting DeleteTableRequest composeDeleteTableRequest(String tableId) { @@ -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( @@ -639,8 +581,6 @@ DropRowRangeRequest composeDropRowRangeRequest( /** * Helper method to build an instance of GenerateConsistencyTokenRequest - * - * @param tableId */ @VisibleForTesting GenerateConsistencyTokenRequest composeGenerateConsistencyTokenRequest(String tableId) { @@ -649,8 +589,6 @@ GenerateConsistencyTokenRequest composeGenerateConsistencyTokenRequest(String ta /** * Helper method to convert ListTablesResponse to List - * - * @param listTablesResponse */ @VisibleForTesting static List convertToTableNames(ListTablesResponse listTablesResponse) { @@ -662,10 +600,9 @@ static List convertToTableNames(ListTablesResponse listTablesResponse return tableNames; } + // TODO(igorbernstein): rename methods to make clear that they deal with futures. /** * Helper method to transform ApiFuture to ApiFuture
- * - * @param future */ @VisibleForTesting static ApiFuture
transformToTableResponse( @@ -675,15 +612,13 @@ static ApiFuture
transformToTableResponse( new ApiFunction() { @Override public Table apply(com.google.bigtable.admin.v2.Table table) { - return TableAdminResponses.convertTable(table); + return Table.fromProto(table); } }); } /** * Helper method to transform ApiFuture to ApiFuture - * - * @param future */ @VisibleForTesting static ApiFuture transformToVoid(ApiFuture future) { diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ClusterState.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ClusterState.java new file mode 100644 index 000000000000..13aa1ac8710e --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ClusterState.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 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.bigtable.admin.v2.Table.ClusterState.ReplicationState; +import com.google.common.base.MoreObjects; + +// TODO(igorbernstein2): remove this class and promote Replication State to Table. +/** Wrapper for {@link ClusterState} protocol buffer object */ +public final class ClusterState { + private final String id; + private final ReplicationState replicationState; + + public static ClusterState fromProto(String clusterId, com.google.bigtable.admin.v2.Table.ClusterState proto) { + return new ClusterState(clusterId, proto.getReplicationState()); + } + + private ClusterState(String id, ReplicationState replicationState) { + this.id = id; + this.replicationState = replicationState; + } + + /** + * Gets the cluster Id + */ + public String getId() { + return id; + } + + /** + * Gets the ReplicationState of this cluster + */ + public ReplicationState getReplicationState() { + return replicationState; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("id", id) + .add("replicationState", replicationState) + .toString(); + } +} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ColumnFamily.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ColumnFamily.java new file mode 100644 index 000000000000..738927beace4 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ColumnFamily.java @@ -0,0 +1,70 @@ +/* + * Copyright 2018 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 static com.google.cloud.bigtable.admin.v2.models.GCRules.GCRULES; + +import com.google.api.core.InternalApi; +import com.google.bigtable.admin.v2.GcRule; +import com.google.bigtable.admin.v2.GcRule.RuleCase; +import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule; +import com.google.common.base.MoreObjects; + +/** Wrapper for {@link ColumnFamily} protocol buffer object */ +public final class ColumnFamily { + // TODO(igorbernstein2): rename this to `name` + private final String id; + private final GCRule rule; + + @InternalApi + public static ColumnFamily fromProto(String id, com.google.bigtable.admin.v2.ColumnFamily proto) { + // TODO(igorbernstein): can getGcRule ever be null? + GcRule ruleProto = MoreObjects.firstNonNull(proto.getGcRule(), GcRule.getDefaultInstance()); + + return new ColumnFamily(id, GCRULES.fromProto(ruleProto)); + } + + private ColumnFamily(String id, GCRule rule) { + this.id = id; + this.rule = rule; + } + + /** + * Gets the columnfamily name + */ + public String getId() { + return id; + } + + /** + * Get's the GCRule configured for the columnfamily + */ + public GCRule getGCRule() { + return rule; + } + + /** + * Returns true if a GCRule has been configured for the family + */ + public boolean hasGCRule() { + return !RuleCase.RULE_NOT_SET.equals(rule.toProto().getRuleCase()); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("id", id).add("GCRule", rule).toString(); + } +} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyToken.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyToken.java new file mode 100644 index 000000000000..9b3d32be5a59 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyToken.java @@ -0,0 +1,60 @@ +/* + * Copyright 2018 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.CheckConsistencyRequest; +import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.MoreObjects; + +/** + * Wrapper for {@link GenerateConsistencyTokenResponse#getConsistencyToken()} + * + *

Cannot be created. They are obtained by invoking {@link + * com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient#generateConsistencyToken(String)} + */ +public final class ConsistencyToken { + private final String token; + + @InternalApi + public static ConsistencyToken fromProto(GenerateConsistencyTokenResponse proto) { + return new ConsistencyToken(proto.getConsistencyToken()); + } + + private ConsistencyToken(String token) { + this.token = token; + } + + // TODO(igorbernstein): tableName should be part of the token and be parameterized + @InternalApi + public CheckConsistencyRequest toProto(String tableName) { + return CheckConsistencyRequest.newBuilder() + .setName(tableName) + .setConsistencyToken(token) + .build(); + } + + @VisibleForTesting + String getToken() { + return token; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("token", token).toString(); + } +} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java new file mode 100644 index 000000000000..f00836957e7f --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java @@ -0,0 +1,101 @@ +/* + * Copyright 2018 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.ColumnFamily; +import com.google.bigtable.admin.v2.InstanceName; +import com.google.bigtable.admin.v2.Table; +import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule; +import com.google.common.base.Preconditions; +import com.google.protobuf.ByteString; + +/** + * Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateTableRequest} + * + *

Allows for creating table with: + * + *

    + *
  • optional columnFamilies, including optional {@link GCRule} + *
  • optional granularity + *
  • and optional split points + *
+ */ +public final class CreateTableRequest { + // TODO(igorbernstein): rename to requestBuilder + private final com.google.bigtable.admin.v2.CreateTableRequest.Builder createTableRequest = com.google.bigtable.admin.v2.CreateTableRequest + .newBuilder(); + // TODO(igorbernstein): use the embedded TableBuilder in createTableRequest + private final Table.Builder tableRequest = Table.newBuilder(); + + public static CreateTableRequest of(String tableId) { + return new CreateTableRequest(tableId); + } + + /** + * Configures table with the specified id + * + * @param tableId + */ + private CreateTableRequest(String tableId) { + createTableRequest.setTableId(tableId); + } + + /** + * Adds a new columnFamily to the configuration + * + * @param familyId + */ + public CreateTableRequest addFamily(String familyId) { + Preconditions.checkNotNull(familyId); + tableRequest.putColumnFamilies(familyId, ColumnFamily.getDefaultInstance()); + return this; + } + + /** + * Adds a new columnFamily with {@link GCRule} to the configuration. Please note that calling this + * method with the same familyId will overwrite the previous family. + * + * @param familyId + * @param gcRule + */ + public CreateTableRequest addFamily(String familyId, GCRule gcRule) { + Preconditions.checkNotNull(familyId); + tableRequest.putColumnFamilies( + familyId, ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build()); + return this; + } + + /** + * Adds split at the specified key to the configuration + * + * @param key + */ + public CreateTableRequest addSplit(ByteString key) { + Preconditions.checkNotNull(key); + createTableRequest.addInitialSplitsBuilder().setKey(key); + return this; + } + + @InternalApi + public com.google.bigtable.admin.v2.CreateTableRequest toProto(InstanceName instanceName) { + Preconditions.checkNotNull(instanceName); + return createTableRequest + .setParent(instanceName.toString()) + .setTable(tableRequest.build()) + .build(); + } +} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java index 1ee6263030fe..71db5281413c 100644 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java @@ -27,6 +27,8 @@ import com.google.bigtable.admin.v2.GcRule.Union; import com.google.common.base.MoreObjects; +// TODO(igorbernstein2): the distinction between GcRule & GCRule is too subtle, use fully qualified +// names for the protos. /** Wraps {@link GcRule} protocol buffer object and exposes a simpler Fluent DSL model */ @BetaApi public final class GCRules { @@ -84,6 +86,39 @@ public DefaultRule defaultRule() { return new DefaultRule(); } + + @InternalApi + public GCRule fromProto(GcRule source) { + switch (source.getRuleCase()) { + case MAX_AGE: + return GCRULES.maxAge( + Duration.ofSeconds(source.getMaxAge().getSeconds(), source.getMaxAge().getNanos())); + + case MAX_NUM_VERSIONS: + return GCRULES.maxVersions(source.getMaxNumVersions()); + + case INTERSECTION: + IntersectionRule intersection = GCRules.GCRULES.intersection(); + for (GcRule rule : source.getIntersection().getRulesList()) { + intersection.rule(fromProto(rule)); + } + return intersection; + + case UNION: + UnionRule union = GCRules.GCRULES.union(); + for (GcRule rule : source.getUnion().getRulesList()) { + union.rule(fromProto(rule)); + } + return union; + + case RULE_NOT_SET: + return defaultRule(); + + default: + throw new IllegalArgumentException("Unknown GcRule case: " + source.getRuleCase()); + } + } + /** * Fluent wrapper for {@link Intersection} rule. Allows far adding an hierarchy of rules with * intersection as the root @@ -100,6 +135,7 @@ private IntersectionRule() { * * @param rule */ + // TODO(igorbernstein2): consider renaming this to addRule public IntersectionRule rule(@Nonnull GCRule rule) { rulesList.add(rule); return this; diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ModifyColumnFamiliesRequest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ModifyColumnFamiliesRequest.java new file mode 100644 index 000000000000..7fab2d8a3b97 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/ModifyColumnFamiliesRequest.java @@ -0,0 +1,117 @@ +/* + * Copyright 2018 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.InstanceName; +import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification; +import com.google.bigtable.admin.v2.TableName; +import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule; +import com.google.common.base.Preconditions; + +/** + * Fluent wrapper for {@link com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest} + * + *

Allows for the following ColumnFamily modifications: + * + *

    + *
  • create family, optionally with {@link GCRule} + *
  • update existing family {@link GCRule} + *
  • drop an existing family + *
+ */ +public final class ModifyColumnFamiliesRequest { + private final com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Builder modFamilyRequest = + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.newBuilder(); + private final String tableId; + + + public static ModifyColumnFamiliesRequest of(String tableId) { + return new ModifyColumnFamiliesRequest(tableId); + } + + /** + * Configures the tableId to execute the modifications + * + * @param tableId + */ + ModifyColumnFamiliesRequest(String tableId) { + Preconditions.checkNotNull(tableId); + this.tableId = tableId; + } + + /** + * Configures the name of the new ColumnFamily to be created + * + * @param familyId + * @return + */ + public ModifyColumnFamiliesRequest addFamily(String familyId) { + return addFamily(familyId, GCRules.GCRULES.defaultRule()); + } + + /** + * Configures the name and GcRule of the new ColumnFamily to be created + * + * @param familyId + * @param gcRule + * @return + */ + public ModifyColumnFamiliesRequest addFamily(String familyId, GCRule gcRule) { + Preconditions.checkNotNull(gcRule); + Modification.Builder modification = Modification.newBuilder().setId(familyId); + modification.getCreateBuilder().setGcRule(gcRule.toProto()); + modFamilyRequest.addModifications(modification.build()); + return this; + } + + /** + * Updates the GCRule of existing ColumnFamily + * + * @param familyId + * @param gcRule + * @return + */ + public ModifyColumnFamiliesRequest updateFamily(String familyId, GCRule gcRule) { + Preconditions.checkNotNull(gcRule); + Modification.Builder modification = Modification.newBuilder().setId(familyId); + modification.getUpdateBuilder().setGcRule(gcRule.toProto()); + modFamilyRequest.addModifications(modification.build()); + return this; + } + + /** + * Drops the specified ColumnFamily + * + * @param familyId + * @return + */ + public ModifyColumnFamiliesRequest dropFamily(String familyId) { + Modification.Builder modification = Modification.newBuilder() + .setId(familyId) + .setDrop(true); + modFamilyRequest.addModifications(modification.build()); + return this; + } + + @InternalApi + public com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest toProto(InstanceName instanceName) { + Preconditions.checkNotNull(instanceName); + String tableName = + TableName.of(instanceName.getProject(), instanceName.getInstance(), tableId).toString(); + return modFamilyRequest.setName(tableName).build(); + } +} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java new file mode 100644 index 000000000000..c070f81fd84d --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java @@ -0,0 +1,108 @@ +/* + * Copyright 2018 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.TableName; +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableMap; +import java.util.Collection; +import java.util.Map; +import java.util.Map.Entry; +import javax.annotation.Nonnull; + +/** Wrapper for {@link Table} protocol buffer object */ +public final class Table { + private final TableName tableName; + // TODO(igorbernstein2): avoid duplication of id as keys and embedded in the models + private final Map clusterStates; + private final Map columnFamilies; + + @InternalApi + public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) { + ImmutableMap.Builder clusterStates = ImmutableMap.builder(); + + for (Entry entry : proto.getClusterStatesMap().entrySet()) { + clusterStates.put(entry.getKey(), ClusterState.fromProto(entry.getKey(), entry.getValue())); + } + + ImmutableMap.Builder columnFamilies = ImmutableMap.builder(); + + for (Entry entry : proto.getColumnFamiliesMap().entrySet()) { + columnFamilies.put(entry.getKey(), ColumnFamily.fromProto(entry.getKey(), entry.getValue())); + } + + return new Table( + TableName.parse(proto.getName()), + clusterStates.build(), + columnFamilies.build()); + } + + private Table(TableName tableName, + Map clusterStates, + Map columnFamilies) { + this.tableName = tableName; + this.clusterStates = clusterStates; + this.columnFamilies = columnFamilies; + } + + /** + * Gets the unique name of the table in the format: + * projects/{project}/instances/{instance}/tables/{tableId} + */ + public TableName getTableName() { + return tableName; + } + + // TODO(igorbernstein2): don't expose the objects as both maps & lists + /** + * Returns state of the table by clusters in the instance as map of clusterId and {@link + * ClusterState} + */ + public Map getClusterStatesMap() { + return clusterStates; + } + + /** + * Returns a map of columfamilies in the table keyed by columnfamily and name + */ + public Map getColumnFamiliesMap() { + return columnFamilies; + } + + /** + * Returns state of the table by clusters in the instance as a Collection + */ + public Collection getClusterStates() { + return clusterStates.values(); + } + + /** + * Returns all columnfamilies in the table as a Collection + */ + public Collection getColumnFamiles() { + return columnFamilies.values(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("tableName", tableName) + .add("clusterStates", getClusterStates()) + .add("columnFamiles", getColumnFamiles()) + .toString(); + } +} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/TableAdminRequests.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/TableAdminRequests.java deleted file mode 100644 index ed4197069099..000000000000 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/TableAdminRequests.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2018 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.BetaApi; -import com.google.api.core.InternalApi; -import com.google.bigtable.admin.v2.ColumnFamily; -import com.google.bigtable.admin.v2.CreateTableRequest; -import com.google.bigtable.admin.v2.CreateTableRequest.Split; -import com.google.bigtable.admin.v2.InstanceName; -import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; -import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification; -import com.google.bigtable.admin.v2.Table; -import com.google.bigtable.admin.v2.TableName; -import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule; -import com.google.common.base.Preconditions; -import com.google.protobuf.ByteString; - -/** Fluent DSL models to build Bigtable Table admin requests */ -@BetaApi -public final class TableAdminRequests { - private TableAdminRequests() {} - - /** - * Factory method to get an instance of CreateTable - * - * @param tableId - the id of the table to create - * @return CreateTable - */ - public static CreateTable createTable(String tableId) { - return new CreateTable(tableId); - } - - /** - * Factory method to get an instance of ModifyFamilies - * - * @param tableId - the id of the table to create - * @return ModifyFamilies - */ - public static ModifyFamilies modifyFamilies(String tableId) { - return new ModifyFamilies(tableId); - } - - /** - * Fluent wrapper for {@link CreateTableRequest} - * - *

Allows for creating table with: - * - *

    - *
  • optional columnFamilies, including optional {@link GCRule} - *
  • optional granularity - *
  • and optional split points - *
- */ - public static final class CreateTable { - private final CreateTableRequest.Builder createTableRequest = CreateTableRequest.newBuilder(); - private final Table.Builder tableRequest = Table.newBuilder(); - - /** - * Configures table with the specified id - * - * @param tableId - */ - private CreateTable(String tableId) { - createTableRequest.setTableId(tableId); - } - - /** - * Adds a new columnFamily to the configuration - * - * @param familyId - */ - public CreateTable addFamily(String familyId) { - Preconditions.checkNotNull(familyId); - tableRequest.putColumnFamilies(familyId, ColumnFamily.newBuilder().build()); - return this; - } - - /** - * Adds a new columnFamily with {@link GCRule} to the configuration - * - * @param familyId - * @param gcRule - */ - public CreateTable addFamily(String familyId, GCRule gcRule) { - Preconditions.checkNotNull(familyId); - tableRequest.putColumnFamilies( - familyId, ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build()); - return this; - } - - /** - * Adds split at the specified key to the configuration - * - * @param key - */ - public CreateTable addSplit(ByteString key) { - Preconditions.checkNotNull(key); - createTableRequest.addInitialSplits(Split.newBuilder().setKey(key).build()); - return this; - } - - @InternalApi - public CreateTableRequest toProto(InstanceName instanceName) { - Preconditions.checkNotNull(instanceName); - return createTableRequest - .setParent(instanceName.toString()) - .setTable(tableRequest.build()) - .build(); - } - } - - /** - * Fluent wrapper for {@link ModifyColumnFamiliesRequest} - * - *

Allows for the following ColumnFamily modifications: - * - *

    - *
  • create family, optionally with {@link GCRule} - *
  • update existing family {@link GCRule} - *
  • drop an existing family - *
- */ - public static final class ModifyFamilies { - private final ModifyColumnFamiliesRequest.Builder modFamilyRequest = - ModifyColumnFamiliesRequest.newBuilder(); - private final String tableId; - - /** - * Configures the tableId to execute the modifications - * - * @param tableId - */ - private ModifyFamilies(String tableId) { - Preconditions.checkNotNull(tableId); - this.tableId = tableId; - } - - /** - * Configures the name of the new ColumnFamily to be created - * - * @param familyId - * @return - */ - public ModifyFamilies addFamily(String familyId) { - return addFamily(familyId, GCRules.GCRULES.defaultRule()); - } - - /** - * Configures the name and GcRule of the new ColumnFamily to be created - * - * @param familyId - * @param gcRule - * @return - */ - public ModifyFamilies addFamily(String familyId, GCRule gcRule) { - Modification.Builder modification = Modification.newBuilder().setId(familyId); - Preconditions.checkNotNull(gcRule); - modification.setCreate(ColumnFamily.newBuilder().setGcRule(gcRule.toProto())); - modFamilyRequest.addModifications(modification.build()); - return this; - } - - /** - * Updates the GCRule of existing ColumnFamily - * - * @param familyId - * @param gcRule - * @return - */ - public ModifyFamilies updateFamily(String familyId, GCRule gcRule) { - Modification.Builder modification = Modification.newBuilder().setId(familyId); - Preconditions.checkNotNull(gcRule); - modification.setUpdate(ColumnFamily.newBuilder().setGcRule(gcRule.toProto())); - modFamilyRequest.addModifications(modification.build()); - return this; - } - - /** - * Drops the specified ColumnFamily - * - * @param familyId - * @return - */ - public ModifyFamilies dropFamily(String familyId) { - Modification.Builder modification = Modification.newBuilder().setId(familyId); - modification.setId(familyId).setDrop(true); - modFamilyRequest.addModifications(modification.build()); - return this; - } - - @InternalApi - public ModifyColumnFamiliesRequest toProto(InstanceName instanceName) { - Preconditions.checkNotNull(instanceName); - String tableName = - TableName.of(instanceName.getProject(), instanceName.getInstance(), tableId).toString(); - return modFamilyRequest.setName(tableName).build(); - } - } -} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/TableAdminResponses.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/TableAdminResponses.java deleted file mode 100644 index 170345a8b6b3..000000000000 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/TableAdminResponses.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Copyright 2018 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 static com.google.cloud.bigtable.admin.v2.models.GCRules.GCRULES; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import org.threeten.bp.Duration; -import com.google.api.core.BetaApi; -import com.google.api.core.InternalApi; -import com.google.bigtable.admin.v2.CheckConsistencyRequest; -import com.google.bigtable.admin.v2.GcRule; -import com.google.bigtable.admin.v2.GcRule.RuleCase; -import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; -import com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState; -import com.google.bigtable.admin.v2.TableName; -import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient; -import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule; -import com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule; -import com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; - -/** Bigtable Table admin response wrappers */ -@BetaApi -public class TableAdminResponses { - private TableAdminResponses() {} - - /** - * Converts the protocol buffer table to a simpler Table model with only the required elements - * - * @param table - Protobuf table - * @return Table response wrapper - */ - @InternalApi - public static Table convertTable(com.google.bigtable.admin.v2.Table table) { - return new Table(table); - } - - /** - * Converts the protocol buffer response to a simpler ConsistencyToken which can be passed back as - * is. - * - * @param tokenResponse - Protobuf ConsistencyTokenResponse - * @return ConsistencyToken response wrapper - */ - @InternalApi - public static ConsistencyToken convertTokenResponse( - GenerateConsistencyTokenResponse tokenResponse) { - return new ConsistencyToken(tokenResponse); - } - - /** - * Converts the protocol buffer response to a simpler ClusterState model with only required - * elements - * - * @param clusterStatesMap - Protobuf clusterStatesMap - */ - @InternalApi - public static Map convertClusterStates( - Map clusterStatesMap) { - Map clusterStates = new HashMap<>(); - - for (Entry entry : - clusterStatesMap.entrySet()) { - clusterStates.put(entry.getKey(), new ClusterState(entry.getKey(), entry.getValue())); - } - return clusterStates; - } - - /** - * Converts the protocol buffer response to a simpler ColumnFamily model with only required - * elements - * - * @param columnFamiliesMap - Protobuf columnFamiliesMap - */ - @InternalApi - public static Map convertColumnFamilies( - Map columnFamiliesMap) { - Map columnFamilies = new HashMap<>(); - - for (Entry entry : - columnFamiliesMap.entrySet()) { - columnFamilies.put(entry.getKey(), new ColumnFamily(entry.getKey(), entry.getValue())); - } - return columnFamilies; - } - - /** Wrapper for {@link Table} protocol buffer object */ - public static final class Table { - private final TableName tableName; - private final Map clusterStates; - private final Map columnFamilies; - - private Table(com.google.bigtable.admin.v2.Table table) { - Preconditions.checkNotNull(table); - this.tableName = TableName.parse(table.getName()); - this.clusterStates = convertClusterStates(table.getClusterStatesMap()); - this.columnFamilies = convertColumnFamilies(table.getColumnFamiliesMap()); - } - - /** - * Gets the unique name of the table in the format: - * projects/{project}/instances/{instance}/tables/{tableId} - */ - public TableName getTableName() { - return tableName; - } - - /** - * Returns state of the table by clusters in the instance as map of clusterId and {@link - * ClusterState} - */ - public Map getClusterStatesMap() { - return clusterStates; - } - - /** - * Returns a map of columfamilies in the table keyed by columnfamily and name - */ - public Map getColumnFamiliesMap() { - return columnFamilies; - } - - /** - * Returns state of the table by clusters in the instance as a Collection - */ - public Collection getClusterStates() { - return clusterStates.values(); - } - - /** - * Returns all columnfamilies in the table as a Collection - */ - public Collection getColumnFamiles() { - return columnFamilies.values(); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("tableName", tableName) - .add("clusterStates", getClusterStates()) - .add("columnFamiles", getColumnFamiles()) - .toString(); - } - } - - /** Wrapper for {@link ClusterState} protocol buffer object */ - public static final class ClusterState { - private final String id; - private final ReplicationState replicationState; - - private ClusterState(String id, com.google.bigtable.admin.v2.Table.ClusterState clusterState) { - this.id = id; - replicationState = clusterState.getReplicationState(); - } - - /** - * Gets the cluster Id - */ - public String getId() { - return id; - } - - /** - * Gets the ReplicationState of the table for this cluster - */ - public ReplicationState getReplicationState() { - return replicationState; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("is", id) - .add("replicationState", replicationState) - .toString(); - } - } - - /** Wrapper for {@link ColumnFamily} protocol buffer object */ - public static final class ColumnFamily { - private final String id; - private GCRule gCRule = GCRULES.defaultRule(); - - private ColumnFamily(String id, com.google.bigtable.admin.v2.ColumnFamily cf) { - Preconditions.checkNotNull(id); - Preconditions.checkNotNull(cf); - this.id = id; - - if (cf.getGcRule() != null) { - this.gCRule = convertGcRule(cf.getGcRule()); - } - } - - /** - * Gets the columnfamily name - */ - public String getId() { - return id; - } - - /** - * Get's the GCRule configured for the columnfamily - */ - public GCRule getGCRule() { - return gCRule; - } - - /** - * Returns true if a GCRule has been configured for the family - */ - public boolean hasGcRule() { - return !RuleCase.RULE_NOT_SET.equals(gCRule.toProto().getRuleCase()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this).add("id", id).add("gCRule", gCRule).toString(); - } - - private GCRule convertGcRule(GcRule source) { - switch (source.getRuleCase()) { - case MAX_AGE: - return GCRULES.maxAge( - Duration.ofSeconds(source.getMaxAge().getSeconds(), source.getMaxAge().getNanos())); - - case MAX_NUM_VERSIONS: - return GCRULES.maxVersions(source.getMaxNumVersions()); - - case INTERSECTION: - IntersectionRule intersection = GCRules.GCRULES.intersection(); - for (GcRule rule : source.getIntersection().getRulesList()) { - intersection.rule(convertGcRule(rule)); - } - return intersection; - - case UNION: - UnionRule union = GCRules.GCRULES.union(); - for (GcRule rule : source.getUnion().getRulesList()) { - union.rule(convertGcRule(rule)); - } - return union; - - default: - return GCRULES.defaultRule(); - } - } - } - - /** - * Wrapper for {@link GenerateConsistencyTokenResponse#getConsistencyToken()} - * - *

Cannot be created. They are obtained by invoking {@link - * BigtableTableAdminClient#generateConsistencyToken(String)} - */ - public static final class ConsistencyToken { - private final String token; - - private ConsistencyToken(GenerateConsistencyTokenResponse resp) { - this.token = resp.getConsistencyToken(); - } - - @InternalApi - public CheckConsistencyRequest toProto(String tableName) { - return CheckConsistencyRequest.newBuilder() - .setName(tableName) - .setConsistencyToken(token) - .build(); - } - - @VisibleForTesting - String getToken() { - return token; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this).add("token", token).toString(); - } - } -} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java index d11b3f6d5695..38d078b115d9 100644 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java @@ -31,7 +31,6 @@ import com.google.api.gax.rpc.UnaryCallable; import com.google.bigtable.admin.v2.CheckConsistencyRequest; import com.google.bigtable.admin.v2.CheckConsistencyResponse; -import com.google.bigtable.admin.v2.CreateTableRequest; import com.google.bigtable.admin.v2.DeleteTableRequest; import com.google.bigtable.admin.v2.DropRowRangeRequest; import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest; @@ -40,13 +39,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.Table; import com.google.bigtable.admin.v2.TableName; -import com.google.cloud.bigtable.admin.v2.models.TableAdminRequests; -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.ConsistencyToken; +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.stub.BigtableTableAdminStub; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; @@ -56,8 +53,8 @@ public class BigtableTableAdminClientTest { private BigtableTableAdminClient adminClient; @Mock private BigtableTableAdminStub mockStub; - @Mock private UnaryCallable mockCreateTableCallable; - @Mock private UnaryCallable mockModifyTableCallable; + @Mock private UnaryCallable mockCreateTableCallable; + @Mock private UnaryCallable mockModifyTableCallable; @Mock private UnaryCallable mockDeleteTableCallable; @Mock private UnaryCallable mockGetTableCallable; @Mock private UnaryCallable mockListTableCallable; @@ -88,12 +85,15 @@ public void setUp() throws Exception { Table table = Table.newBuilder().build(); ApiFuture

futureTable = ApiFutures.immediateFuture(table); - Mockito.when(mockCreateTableCallable.call(any(CreateTableRequest.class))).thenReturn(table); - Mockito.when(mockCreateTableCallable.futureCall(any(CreateTableRequest.class))) + Mockito.when(mockCreateTableCallable.call(any(com.google.bigtable.admin.v2.CreateTableRequest.class))).thenReturn(table); + Mockito.when(mockCreateTableCallable.futureCall(any( + com.google.bigtable.admin.v2.CreateTableRequest.class))) .thenReturn(futureTable); - Mockito.when(mockModifyTableCallable.call(any(ModifyColumnFamiliesRequest.class))) + Mockito.when(mockModifyTableCallable.call(any( + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.class))) .thenReturn(table); - Mockito.when(mockModifyTableCallable.futureCall(any(ModifyColumnFamiliesRequest.class))) + Mockito.when(mockModifyTableCallable.futureCall(any( + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.class))) .thenReturn(futureTable); Mockito.when(mockGetTableCallable.call(any(GetTableRequest.class))).thenReturn(table); Mockito.when(mockGetTableCallable.futureCall(any(GetTableRequest.class))) @@ -101,14 +101,14 @@ public void setUp() throws Exception { } @Test - public void close() throws Exception { + public void close() { adminClient.close(); Mockito.verify(mockStub).close(); } @Test public void createTable() { - CreateTable createTableReq = TableAdminRequests.createTable("tableId"); + CreateTableRequest createTableReq = CreateTableRequest.of("tableId"); adminClient.createTable(createTableReq); Mockito.verify(mockCreateTableCallable) .call(createTableReq.toProto(adminClient.getInstanceName())); @@ -116,7 +116,7 @@ public void createTable() { @Test public void createTableAsync() { - CreateTable createTableReq = TableAdminRequests.createTable("tableId"); + CreateTableRequest createTableReq = CreateTableRequest.of("tableId"); adminClient.createTableAsync(createTableReq); Mockito.verify(mockCreateTableCallable) .futureCall(createTableReq.toProto(adminClient.getInstanceName())); @@ -124,7 +124,7 @@ public void createTableAsync() { @Test public void modifyFamilies() { - ModifyFamilies modifyFamReq = TableAdminRequests.modifyFamilies("tableId"); + ModifyColumnFamiliesRequest modifyFamReq = ModifyColumnFamiliesRequest.of("tableId"); adminClient.modifyFamilies(modifyFamReq); Mockito.verify(mockModifyTableCallable) .call(modifyFamReq.toProto(adminClient.getInstanceName())); @@ -132,7 +132,7 @@ public void modifyFamilies() { @Test public void modifyFamiliesAsync() { - ModifyFamilies modifyFamReq = TableAdminRequests.modifyFamilies("tableId"); + ModifyColumnFamiliesRequest modifyFamReq = ModifyColumnFamiliesRequest.of("tableId"); adminClient.modifyFamiliesAsync(modifyFamReq); Mockito.verify(mockModifyTableCallable) .futureCall(modifyFamReq.toProto(adminClient.getInstanceName())); diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index d4805ed51eb3..19d28b892978 100644 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -28,11 +28,10 @@ import com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule; -import com.google.cloud.bigtable.admin.v2.models.TableAdminRequests; -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.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.protobuf.ByteString; import java.io.IOException; import java.util.List; @@ -79,8 +78,8 @@ public void setup() { @Test public void createTable() { String tableId = "adminCreateTest"; - CreateTable createTableReq = - TableAdminRequests.createTable(tableId) + CreateTableRequest createTableReq = + CreateTableRequest.of(tableId) .addFamily("cf1") .addFamily("cf2", GCRULES.maxVersions(10)) .addSplit(ByteString.copyFromUtf8("b")) @@ -91,8 +90,8 @@ public void createTable() { assertNotNull(tableResponse); assertEquals(tableId, tableResponse.getTableName().getTable()); assertEquals(2, tableResponse.getColumnFamiles().size()); - assertFalse(tableResponse.getColumnFamiliesMap().get("cf1").hasGcRule()); - assertTrue(tableResponse.getColumnFamiliesMap().get("cf2").hasGcRule()); + assertFalse(tableResponse.getColumnFamiliesMap().get("cf1").hasGCRule()); + assertTrue(tableResponse.getColumnFamiliesMap().get("cf2").hasGCRule()); assertEquals( 10, ((VersionRule) tableResponse.getColumnFamiliesMap().get("cf2").getGCRule()) @@ -105,7 +104,7 @@ public void createTable() { @Test public void modifyFamilies() { String tableId = "adminModifyFamTest"; - ModifyFamilies modifyFamiliesReq = TableAdminRequests.modifyFamilies(tableId); + ModifyColumnFamiliesRequest modifyFamiliesReq = ModifyColumnFamiliesRequest.of(tableId); modifyFamiliesReq .addFamily("mf1") @@ -130,7 +129,7 @@ public void modifyFamilies() { .addFamily("mf7"); try { - tableAdmin.createTable(TableAdminRequests.createTable(tableId)); + tableAdmin.createTable(CreateTableRequest.of(tableId)); Table tableResponse = tableAdmin.modifyFamilies(modifyFamiliesReq); assertEquals(5, tableResponse.getColumnFamiles().size()); assertNotNull(tableResponse.getColumnFamiliesMap().get("mf1")); @@ -169,7 +168,7 @@ public void modifyFamilies() { @Test public void deleteTable() { String tableId = "adminDeleteTest"; - tableAdmin.createTable(TableAdminRequests.createTable(tableId)); + tableAdmin.createTable(CreateTableRequest.of(tableId)); tableAdmin.deleteTable(tableId); } @@ -178,7 +177,7 @@ public void getTable() { String tableId = "adminGetTest"; try { - tableAdmin.createTable(TableAdminRequests.createTable(tableId)); + tableAdmin.createTable(CreateTableRequest.of(tableId)); Table tableResponse = tableAdmin.getTable(tableId); assertNotNull(tableResponse); assertEquals(tableId, tableResponse.getTableName().getTable()); @@ -192,7 +191,7 @@ public void listTables() { String tableId = "adminListTest"; try { - tableAdmin.createTable(TableAdminRequests.createTable(tableId)); + tableAdmin.createTable(CreateTableRequest.of(tableId)); List tables = tableAdmin.listTables(); assertNotNull(tables); assertFalse("List tables did not return any tables", tables.isEmpty()); @@ -206,7 +205,7 @@ public void listTablesAsync() throws Exception { String tableId = "adminListTest"; try { - tableAdmin.createTable(TableAdminRequests.createTable(tableId)); + tableAdmin.createTable(CreateTableRequest.of(tableId)); List tables = tableAdmin.listTablesAsync().get(); assertNotNull(tables); assertFalse("List tables did not return any tables", tables.isEmpty()); @@ -220,7 +219,7 @@ public void dropRowRange() { String tableId = "adminDropRowrangeTest"; try { - tableAdmin.createTable(TableAdminRequests.createTable(tableId)); + tableAdmin.createTable(CreateTableRequest.of(tableId)); tableAdmin.dropRowRange(tableId, "rowPrefix"); tableAdmin.dropAllRows(tableId); } finally { @@ -233,7 +232,7 @@ public void checkConsistency() { String tableId = "adminConsistencyTest"; try { - tableAdmin.createTable(TableAdminRequests.createTable(tableId)); + tableAdmin.createTable(CreateTableRequest.of(tableId)); ConsistencyToken consistencyToken = tableAdmin.generateConsistencyToken(tableId); assertNotNull(consistencyToken); boolean consistent = tableAdmin.isConsistent(tableId, consistencyToken); diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyTokenTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyTokenTest.java new file mode 100644 index 000000000000..508bf546c63b --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyTokenTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2018 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 static org.junit.Assert.assertEquals; + +import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ConsistencyTokenTest { + @Test + public void fromJsonTest() { + ConsistencyToken tokenResponse = + ConsistencyToken.fromProto( + GenerateConsistencyTokenResponse.newBuilder() + .setConsistencyToken("87282hgwd8yg") + .build()); + + assertEquals("87282hgwd8yg", tokenResponse.getToken()); + } +} diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableAdminRequestsTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableAdminRequestsTest.java index d33940e18f0a..d0538634a2e6 100644 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableAdminRequestsTest.java +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableAdminRequestsTest.java @@ -16,18 +16,15 @@ package com.google.cloud.bigtable.admin.v2.models; import static com.google.common.truth.Truth.assertThat; + +import com.google.bigtable.admin.v2.CreateTableRequest.Split; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import com.google.bigtable.admin.v2.ColumnFamily; -import com.google.bigtable.admin.v2.CreateTableRequest; import com.google.bigtable.admin.v2.GcRule; import com.google.bigtable.admin.v2.Table; import com.google.bigtable.admin.v2.TableName; -import com.google.bigtable.admin.v2.CreateTableRequest.Split; import com.google.bigtable.admin.v2.InstanceName; -import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest; -import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification; import com.google.protobuf.ByteString; @RunWith(JUnit4.class) @@ -36,24 +33,23 @@ public class TableAdminRequestsTest { @Test public void createTable() { - CreateTableRequest actual = - TableAdminRequests.createTable("tableId") + com.google.bigtable.admin.v2.CreateTableRequest actual = CreateTableRequest.of("tableId") .addFamily("cf1") .addFamily("cf2", GCRules.GCRULES.maxVersions(1)) .addSplit(ByteString.copyFromUtf8("c")) .toProto(instanceName); - CreateTableRequest expected = - CreateTableRequest.newBuilder() + com.google.bigtable.admin.v2.CreateTableRequest expected = + com.google.bigtable.admin.v2.CreateTableRequest.newBuilder() .setTableId("tableId") .setParent(InstanceName.of("project", "instance").toString()) .addInitialSplits(Split.newBuilder().setKey(ByteString.copyFromUtf8("c"))) .setTable( Table.newBuilder() - .putColumnFamilies("cf1", ColumnFamily.newBuilder().build()) + .putColumnFamilies("cf1", com.google.bigtable.admin.v2.ColumnFamily.newBuilder().build()) .putColumnFamilies( "cf2", - ColumnFamily.newBuilder() + com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GCRules.GCRULES.maxVersions(1).toProto()) .build())) .build(); @@ -63,18 +59,18 @@ public void createTable() { @Test(expected = NullPointerException.class) public void createTableRequiredTableId() { - TableAdminRequests.createTable(null).toProto(instanceName); + CreateTableRequest.of(null); } @Test(expected = NullPointerException.class) public void createTableRequiredParent() { - TableAdminRequests.createTable("tableId").toProto(null); + CreateTableRequest.of("tableId").toProto(null); } @Test public void modifyFamilies() { - ModifyColumnFamiliesRequest actual = - TableAdminRequests.modifyFamilies("tableId") + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest actual = + ModifyColumnFamiliesRequest.of("tableId") .addFamily("cf1") .addFamily("cf2", GCRules.GCRULES.maxVersions(1)) .addFamily("cf3") @@ -82,43 +78,43 @@ public void modifyFamilies() { .dropFamily("cf3") .toProto(instanceName); - ModifyColumnFamiliesRequest expected = - ModifyColumnFamiliesRequest.newBuilder() + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest expected = + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.newBuilder() .setName( TableName.of(instanceName.getProject(), instanceName.getInstance(), "tableId") .toString()) .addModifications( - Modification.newBuilder() + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder() .setId("cf1") - .setCreate(ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()))) + .setCreate(com.google.bigtable.admin.v2.ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()))) .addModifications( - Modification.newBuilder() + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder() .setId("cf2") .setCreate( - ColumnFamily.newBuilder() + com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GCRules.GCRULES.maxVersions(1).toProto()))) .addModifications( - Modification.newBuilder() + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder() .setId("cf3") - .setCreate(ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()))) + .setCreate(com.google.bigtable.admin.v2.ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()))) .addModifications( - Modification.newBuilder() + com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder() .setId("cf1") .setUpdate( - ColumnFamily.newBuilder() + com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GCRules.GCRULES.maxVersions(5).toProto()))) - .addModifications(Modification.newBuilder().setId("cf3").setDrop(true)) + .addModifications(com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder().setId("cf3").setDrop(true)) .build(); assertThat(actual).isEqualTo(expected); } @Test(expected = NullPointerException.class) public void modifyFamiliesRequiredTableId() { - TableAdminRequests.modifyFamilies(null).toProto(instanceName); + ModifyColumnFamiliesRequest.of(null).toProto(instanceName); } @Test(expected = NullPointerException.class) public void modifyFamiliesRequiredParent() { - TableAdminRequests.modifyFamilies("tableId").toProto(null); + ModifyColumnFamiliesRequest.of("tableId").toProto(null); } } diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableAdminResponsesTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableTest.java similarity index 90% rename from google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableAdminResponsesTest.java rename to google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableTest.java index 3b759e2f2954..b2f33b073a1c 100644 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableAdminResponsesTest.java +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableTest.java @@ -30,8 +30,6 @@ import com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule; -import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.ConsistencyToken; -import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.Table; import com.google.bigtable.admin.v2.GcRule.Intersection; import com.google.bigtable.admin.v2.GcRule.Union; import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse; @@ -39,7 +37,7 @@ import static com.google.common.truth.Truth.assertThat; @RunWith(JUnit4.class) -public class TableAdminResponsesTest { +public class TableTest { @Test public void convertTable() { @@ -74,7 +72,7 @@ public void convertTable() { .build()) .build(); - Table tableResponse = TableAdminResponses.convertTable(table); + Table tableResponse = Table.fromProto(table); assertNotNull(tableResponse); assertEquals(testName, tableResponse.getTableName()); assertEquals(2, tableResponse.getClusterStates().size()); @@ -86,7 +84,7 @@ public void convertTable() { tableResponse.getClusterStatesMap().get("prod").getReplicationState()); assertEquals(3, tableResponse.getColumnFamiles().size()); assertNotNull("cf1", tableResponse.getColumnFamiliesMap().get("cf1").getId()); - assertFalse(tableResponse.getColumnFamiliesMap().get("cf1").hasGcRule()); + assertFalse(tableResponse.getColumnFamiliesMap().get("cf1").hasGCRule()); assertThat(GCRULES.defaultRule().toProto()) .isEqualTo(tableResponse.getColumnFamiliesMap().get("cf1").getGCRule().toProto()); @@ -136,10 +134,10 @@ public void convertTableUnionOfIntersections() { .putColumnFamilies("cf3", ColumnFamily.newBuilder().setGcRule(expected).build()) .build(); - Table tableResponse = TableAdminResponses.convertTable(table); + Table tableResponse = Table.fromProto(table); assertThat(actual) .isEqualTo(tableResponse.getColumnFamiliesMap().get("cf3").getGCRule().toProto()); - assertTrue(tableResponse.getColumnFamiliesMap().get("cf3").hasGcRule()); + assertTrue(tableResponse.getColumnFamiliesMap().get("cf3").hasGCRule()); UnionRule parentUnion = ((UnionRule) tableResponse.getColumnFamiliesMap().get("cf3").getGCRule()); @@ -200,7 +198,7 @@ public void convertTableIntersectionOfUnions() { .putColumnFamilies("cf3", ColumnFamily.newBuilder().setGcRule(expected).build()) .build(); - Table tableResponse = TableAdminResponses.convertTable(table); + Table tableResponse = Table.fromProto(table); assertThat(actual) .isEqualTo(tableResponse.getColumnFamiliesMap().get("cf3").getGCRule().toProto()); } @@ -208,22 +206,10 @@ public void convertTableIntersectionOfUnions() { @Test public void convertTableEmpty() { Table tableResponse = - TableAdminResponses.convertTable(com.google.bigtable.admin.v2.Table.newBuilder().build()); + Table.fromProto(com.google.bigtable.admin.v2.Table.newBuilder().build()); assertNotNull(tableResponse); assertEquals(0, tableResponse.getClusterStates().size()); assertEquals(0, tableResponse.getColumnFamiles().size()); } - - @Test - public void convertTokenResponse() { - ConsistencyToken tokenResponse = - TableAdminResponses.convertTokenResponse( - GenerateConsistencyTokenResponse.newBuilder() - .setConsistencyToken("87282hgwd8yg") - .build()); - - assertNotNull(tokenResponse); - assertEquals("87282hgwd8yg", tokenResponse.getToken()); - } }