Search in sources :

Example 16 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable-hbase by googleapis.

the class TestTableAdapter method testAdaptForTable.

@Test
public void testAdaptForTable() {
    // If no GcRule passed to ColumnFamily, then ColumnDescriptorAdapter#buildGarbageCollectionRule
    // updates maxVersion to Integer.MAX_VALUE
    GCRule gcRule = GCRULES.maxVersions(1);
    ColumnFamily columnFamily = ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build();
    Table table = Table.newBuilder().setName(TABLE_NAME).putColumnFamilies(COLUMN_FAMILY, columnFamily).build();
    HTableDescriptor actualTableDesc = TableAdapter.adapt(com.google.cloud.bigtable.admin.v2.models.Table.fromProto(table));
    HTableDescriptor expected = new HTableDescriptor(TableName.valueOf(TABLE_ID));
    expected.addFamily(new HColumnDescriptor(COLUMN_FAMILY));
    Assert.assertEquals(expected, actualTableDesc);
}
Also used : Table(com.google.bigtable.admin.v2.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 17 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable-hbase by googleapis.

the class TestAdminClientVeneerApi method testCreateTableAsync.

@Test
public void testCreateTableAsync() throws Exception {
    CreateTableRequest req = CreateTableRequest.of(TABLE_ID_1);
    Future<Table> response = adminClientWrapper.createTableAsync(req);
    assertEquals(TABLE_ID_1, response.get().getId());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) Test(org.junit.Test)

Example 18 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable-hbase by googleapis.

the class TestAdminClientVeneerApi method testModifyFamilyAsync.

@Test
public void testModifyFamilyAsync() throws Exception {
    ModifyColumnFamiliesRequest request = ModifyColumnFamiliesRequest.of(TABLE_ID_1).addFamily("first-family").addFamily("another-family");
    Future<Table> response = adminClientWrapper.modifyFamiliesAsync(request);
    assertEquals(TABLE_ID_1, response.get().getId());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Test(org.junit.Test)

Example 19 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable-hbase by googleapis.

the class TestTableAdapter2x method testAdaptWithTable.

@Test
public void testAdaptWithTable() {
    // If no GcRule passed to ColumnFamily, then ColumnDescriptorAdapter#buildGarbageCollectionRule
    // updates maxVersion to Integer.MAX_VALUE
    int maxVersion = 1;
    GCRules.GCRule gcRule = GCRULES.maxVersions(maxVersion);
    ColumnFamily columnFamily = ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build();
    Table table = Table.newBuilder().setName(TABLE_NAME).putColumnFamilies(COLUMN_FAMILY, columnFamily).build();
    TableDescriptor actualTableDesc = TableAdapter2x.adapt(com.google.cloud.bigtable.admin.v2.models.Table.fromProto(table));
    TableDescriptor expected = new HTableDescriptor(TableName.valueOf(TABLE_ID)).addFamily(new HColumnDescriptor(COLUMN_FAMILY));
    Assert.assertEquals(expected, actualTableDesc);
}
Also used : GCRules(com.google.cloud.bigtable.admin.v2.models.GCRules) Table(com.google.bigtable.admin.v2.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 20 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.

the class NativeImageBigtableSample method main.

/**
 * Entrypoint to the BigTable sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableInstanceAdminSettings instanceAdminSettings = BigtableInstanceAdminSettings.newBuilder().setProjectId(projectId).build();
    BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminClientSettings);
    BigtableDataClient standardClient = BigtableDataClient.create(clientSettings);
    BigtableInstanceAdminClient instanceAdminClient = BigtableInstanceAdminClient.create(instanceAdminSettings);
    if (!instanceAdminClient.exists(INSTANCE_NAME)) {
        instanceAdminClient.createInstance(CreateInstanceRequest.of(INSTANCE_NAME).addCluster("cluster", "us-central1-f", 3, StorageType.SSD).setType(Instance.Type.PRODUCTION).addLabel("example", "instance_admin"));
    }
    String tableName = TABLE_NAME + UUID.randomUUID().toString().replace("-", "");
    createTable(adminClient, tableName);
    // Add data into table
    ImmutableMap<String, Long> dataWithLong = ImmutableMap.of("connected_cell", 1L, "connected_wifi", 1L);
    ImmutableMap<String, String> dataWithStrings = ImmutableMap.of("os_build", "PQ2A.190405.003");
    long timestamp = System.currentTimeMillis() * 1000;
    insertData(standardClient, tableName, timestamp, dataWithLong, dataWithStrings);
    readData(standardClient, tableName);
    // Clean up
    deleteTable(adminClient, tableName);
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableInstanceAdminClient(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient) ByteString(com.google.protobuf.ByteString) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) BigtableInstanceAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)

Aggregations

Test (org.junit.Test)17 Table (com.google.cloud.bigtable.admin.v2.models.Table)16 ByteString (com.google.protobuf.ByteString)9 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)5 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)5 ListTablesRequest (com.google.bigtable.admin.v2.ListTablesRequest)4 Table (com.google.bigtable.admin.v2.Table)4 ListTablesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse)4 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)3 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)2 ListTablesResponse (com.google.bigtable.admin.v2.ListTablesResponse)2 ListTablesPage (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)2 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)2 RestoreTableRequest (com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest)2 RestoredTableResult (com.google.cloud.bigtable.admin.v2.models.RestoredTableResult)2 AbstractMessage (com.google.protobuf.AbstractMessage)2