use of com.google.bigtable.admin.v2.ColumnFamily in project java-bigtable-hbase by googleapis.
the class ColumnDescriptorAdapter method adapt.
/**
* Adapt a single instance of an HBase {@link org.apache.hadoop.hbase.HColumnDescriptor} to an
* instance of {@link com.google.bigtable.admin.v2.ColumnFamily.Builder}.
*
* <p>NOTE: This method does not set the name of the ColumnFamily.Builder. The assumption is that
* the CreateTableRequest or CreateColumnFamilyRequest takes care of the naming. As of now
* (3/11/2015), the server insists on having a blank name.
*
* @param columnDescriptor a {@link org.apache.hadoop.hbase.HColumnDescriptor} object.
* @return a {@link com.google.bigtable.admin.v2.ColumnFamily.Builder} object.
*/
public ColumnFamily adapt(HColumnDescriptor columnDescriptor) {
throwIfRequestingUnknownFeatures(columnDescriptor);
throwIfRequestingUnsupportedFeatures(columnDescriptor);
ColumnFamily.Builder resultBuilder = ColumnFamily.newBuilder();
GCRule gcRule = buildGarbageCollectionRule(columnDescriptor);
if (gcRule != null) {
resultBuilder.setGcRule(gcRule.toProto());
}
return resultBuilder.build();
}
use of com.google.bigtable.admin.v2.ColumnFamily in project java-bigtable-hbase by googleapis.
the class TestColumnDescriptorAdapter method ttlIsPreservedInGcRule.
@Test
public void ttlIsPreservedInGcRule() {
// TTL of 1 day (in seconds):
int ttl = 86400;
descriptor.setTimeToLive(ttl);
ColumnFamily result = adapter.adapt(descriptor);
GCRules.GCRule expected = GCRULES.union().rule(GCRULES.maxAge(Duration.ofSeconds(ttl))).rule(GCRULES.maxVersions(1));
Assert.assertEquals(expected.toProto(), result.getGcRule());
}
use of com.google.bigtable.admin.v2.ColumnFamily in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createTableFromSnapshotTest.
@Test
public void createTableFromSnapshotTest() throws Exception {
Table expectedResponse = Table.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).putAllClusterStates(new HashMap<String, Table.ClusterState>()).putAllColumnFamilies(new HashMap<String, ColumnFamily>()).setRestoreInfo(RestoreInfo.newBuilder().build()).build();
Operation resultOperation = Operation.newBuilder().setName("createTableFromSnapshotTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableTableAdmin.addResponse(resultOperation);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String tableId = "tableId-1552905847";
SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
Table actualResponse = client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateTableFromSnapshotRequest actualRequest = ((CreateTableFromSnapshotRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(tableId, actualRequest.getTableId());
Assert.assertEquals(sourceSnapshot.toString(), actualRequest.getSourceSnapshot());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.ColumnFamily in project java-bigtable by googleapis.
the class TableTest method testFromProto.
@Test
public void testFromProto() {
TableName testName = TableName.of("my-project", "my-instance", "my-table");
com.google.bigtable.admin.v2.Table proto = com.google.bigtable.admin.v2.Table.newBuilder().setName(testName.toString()).setGranularity(TimestampGranularity.MILLIS).putClusterStates("cluster1", com.google.bigtable.admin.v2.Table.ClusterState.newBuilder().setReplicationState(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.READY).build()).putClusterStates("cluster2", com.google.bigtable.admin.v2.Table.ClusterState.newBuilder().setReplicationState(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.INITIALIZING).build()).putColumnFamilies("cf1", ColumnFamily.newBuilder().build()).putColumnFamilies("cf2", ColumnFamily.newBuilder().setGcRule(GcRule.newBuilder().setMaxNumVersions(1)).build()).putColumnFamilies("cf3", ColumnFamily.newBuilder().setGcRule(GcRule.newBuilder().setMaxAge(com.google.protobuf.Duration.newBuilder().setSeconds(1).setNanos(99))).build()).build();
Table result = Table.fromProto(proto);
assertThat(result.getInstanceId()).isEqualTo("my-instance");
assertThat(result.getId()).isEqualTo("my-table");
assertThat(result.getReplicationStatesByClusterId()).containsExactly("cluster1", Table.ReplicationState.READY, "cluster2", Table.ReplicationState.INITIALIZING);
assertThat(result.getColumnFamilies()).hasSize(3);
for (Entry<String, ColumnFamily> entry : proto.getColumnFamiliesMap().entrySet()) {
assertThat(result.getColumnFamilies()).contains(com.google.cloud.bigtable.admin.v2.models.ColumnFamily.fromProto(entry.getKey(), entry.getValue()));
}
}
use of com.google.bigtable.admin.v2.ColumnFamily in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method modifyColumnFamiliesTest.
@Test
public void modifyColumnFamiliesTest() throws Exception {
Table expectedResponse = Table.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).putAllClusterStates(new HashMap<String, Table.ClusterState>()).putAllColumnFamilies(new HashMap<String, ColumnFamily>()).setRestoreInfo(RestoreInfo.newBuilder().build()).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>();
Table actualResponse = client.modifyColumnFamilies(name, modifications);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ModifyColumnFamiliesRequest actualRequest = ((ModifyColumnFamiliesRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(modifications, actualRequest.getModificationsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations