Search in sources :

Example 1 with CreateTableRequest

use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-docs-samples by GoogleCloudPlatform.

the class ReadsTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException {
    projectId = requireEnv("GOOGLE_CLOUD_PROJECT");
    instanceId = requireEnv(INSTANCE_ENV);
    try (BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(projectId, instanceId)) {
        CreateTableRequest createTableRequest = CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME);
        adminClient.createTable(createTableRequest);
        try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
            BulkMutation bulkMutation = BulkMutation.create(TABLE_ID).add("phone#4c410523#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, "os_build", TIMESTAMP_NANO, "PQ2A.190405.003")).add("phone#4c410523#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, "os_build", TIMESTAMP_NANO, "PQ2A.190405.004")).add("phone#4c410523#20190505", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 0).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, "os_build", TIMESTAMP_NANO, "PQ2A.190406.000")).add("phone#5c10102#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, "os_build", TIMESTAMP_NANO, "PQ2A.190401.002")).add("phone#5c10102#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 0).setCell(COLUMN_FAMILY_NAME, "os_build", TIMESTAMP_NANO, "PQ2A.190406.000"));
            dataClient.bulkMutateRows(bulkMutation);
        }
    } catch (Exception e) {
        System.out.println("Error during beforeClass: \n" + e.toString());
        throw (e);
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 2 with CreateTableRequest

use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-docs-samples by GoogleCloudPlatform.

the class MemcachedTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    projectId = requireEnv("GOOGLE_CLOUD_PROJECT");
    instanceId = requireEnv(INSTANCE_ENV);
    try (BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(projectId, instanceId)) {
        CreateTableRequest createTableRequest = CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME);
        adminClient.createTable(createTableRequest);
        try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
            String rowkey = "phone#4c410523#20190501";
            RowMutation rowMutation = RowMutation.create(TABLE_ID, rowkey).setCell(COLUMN_FAMILY_NAME, "os_build", "PQ2A.190405.003");
            dataClient.mutateRow(rowMutation);
        }
        String[] dockerCommand = (String.format("docker run --name %s -itd --rm --publish 11211:11211 sameersbn/memcached:latest", MEMCACHED_CONTAINER_NAME)).split(" ");
        Process process = new ProcessBuilder(dockerCommand).start();
        process.waitFor();
    } catch (Exception e) {
        System.out.println("Error during beforeClass: \n" + e.toString());
    }
}
Also used : RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) BeforeClass(org.junit.BeforeClass)

Example 3 with CreateTableRequest

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

the class TableAdapter method adapt.

public static CreateTableRequest adapt(HTableDescriptor desc, byte[][] splitKeys) {
    CreateTableRequest request = CreateTableRequest.of(desc.getTableName().getNameAsString());
    adapt(desc, request);
    addSplitKeys(splitKeys, request);
    return request;
}
Also used : CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)

Example 4 with CreateTableRequest

use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest 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 5 with CreateTableRequest

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

the class TestTableAdapter method testAdaptWithColumnDesc.

@Test
public void testAdaptWithColumnDesc() {
    HColumnDescriptor columnDesc = new HColumnDescriptor(COLUMN_FAMILY);
    HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(TABLE_ID));
    CreateTableRequest request = CreateTableRequest.of(TABLE_ID);
    desc.addFamily(columnDesc);
    TableAdapter.adapt(desc, request);
    GCRule gcRule = ColumnDescriptorAdapter.buildGarbageCollectionRule(columnDesc);
    CreateTableRequest expected = CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY, gcRule);
    Assert.assertEquals(request.toProto(PROJECT_ID, INSTANCE_ID), expected.toProto(PROJECT_ID, INSTANCE_ID));
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Aggregations

CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)14 Test (org.junit.Test)7 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)4 Table (com.google.cloud.bigtable.admin.v2.models.Table)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 GCRule (com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule)3 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)3 IOException (java.io.IOException)3 BeforeClass (org.junit.BeforeClass)3 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)2 ByteString (com.google.protobuf.ByteString)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)1 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)1 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)1 ArrayList (java.util.ArrayList)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1