Search in sources :

Example 1 with ColumnFamily

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();
}
Also used : GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily)

Example 2 with ColumnFamily

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());
}
Also used : GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) GCRules(com.google.cloud.bigtable.admin.v2.models.GCRules) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 3 with ColumnFamily

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()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) CreateTableFromSnapshotRequest(com.google.bigtable.admin.v2.CreateTableFromSnapshotRequest) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) SnapshotName(com.google.bigtable.admin.v2.SnapshotName) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 4 with ColumnFamily

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()));
    }
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 5 with ColumnFamily

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()));
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) ModifyColumnFamiliesRequest(com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest) Test(org.junit.Test)

Aggregations

ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)19 Test (org.junit.Test)18 Table (com.google.bigtable.admin.v2.Table)13 AbstractMessage (com.google.protobuf.AbstractMessage)11 ByteString (com.google.protobuf.ByteString)11 HashMap (java.util.HashMap)11 GCRule (com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule)5 Operation (com.google.longrunning.Operation)5 CreateTableFromSnapshotRequest (com.google.bigtable.admin.v2.CreateTableFromSnapshotRequest)4 InstanceName (com.google.bigtable.admin.v2.InstanceName)3 TableName (com.google.bigtable.admin.v2.TableName)3 GCRules (com.google.cloud.bigtable.admin.v2.models.GCRules)3 CreateTableRequest (com.google.bigtable.admin.v2.CreateTableRequest)2 GetTableRequest (com.google.bigtable.admin.v2.GetTableRequest)2 ModifyColumnFamiliesRequest (com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest)2 SnapshotName (com.google.bigtable.admin.v2.SnapshotName)2 ArrayList (java.util.ArrayList)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 RestoreTableRequest (com.google.bigtable.admin.v2.RestoreTableRequest)1