Search in sources :

Example 1 with TableName

use of com.google.bigtable.admin.v2.TableName in project beam by apache.

the class BigtableClientWrapper method createTable.

void createTable(String tableName, String familyName) {
    Table.Builder tableBuilder = Table.newBuilder();
    tableBuilder.putColumnFamilies(familyName, ColumnFamily.newBuilder().build());
    String instanceName = bigtableOptions.getInstanceName().toString();
    com.google.bigtable.admin.v2.CreateTableRequest.Builder createTableRequestBuilder = com.google.bigtable.admin.v2.CreateTableRequest.newBuilder().setParent(instanceName).setTableId(tableName).setTable(tableBuilder.build());
    tableAdminClient.createTable(createTableRequestBuilder.build());
}
Also used : Table(com.google.bigtable.admin.v2.Table) RowUtils.byteString(org.apache.beam.sdk.io.gcp.bigtable.RowUtils.byteString)

Example 2 with TableName

use of com.google.bigtable.admin.v2.TableName in project beam by apache.

the class BigtableWriteIT method testE2EBigtableWrite.

@Test
public void testE2EBigtableWrite() throws Exception {
    final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId);
    final String instanceName = bigtableOptions.getInstanceName().toString();
    final int numRows = 1000;
    final List<KV<ByteString, ByteString>> testData = generateTableData(numRows);
    createEmptyTable(instanceName, tableId);
    Pipeline p = Pipeline.create(options);
    p.apply(GenerateSequence.from(0).to(numRows)).apply(ParDo.of(new DoFn<Long, KV<ByteString, Iterable<Mutation>>>() {

        @ProcessElement
        public void processElement(ProcessContext c) {
            int index = c.element().intValue();
            Iterable<Mutation> mutations = ImmutableList.of(Mutation.newBuilder().setSetCell(Mutation.SetCell.newBuilder().setValue(testData.get(index).getValue()).setFamilyName(COLUMN_FAMILY_NAME)).build());
            c.output(KV.of(testData.get(index).getKey(), mutations));
        }
    })).apply(BigtableIO.write().withBigtableOptions(bigtableOptions).withTableId(tableId));
    p.run();
    // Test number of column families and column family name equality
    Table table = getTable(tableName);
    assertThat(table.getColumnFamiliesMap().keySet(), Matchers.hasSize(1));
    assertThat(table.getColumnFamiliesMap(), Matchers.hasKey(COLUMN_FAMILY_NAME));
    // Test table data equality
    List<KV<ByteString, ByteString>> tableData = getTableData(tableName);
    assertThat(tableData, Matchers.containsInAnyOrder(testData.toArray()));
}
Also used : Table(com.google.bigtable.admin.v2.Table) ByteString(com.google.protobuf.ByteString) KV(org.apache.beam.sdk.values.KV) Mutation(com.google.bigtable.v2.Mutation) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 3 with TableName

use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method snapshotTableTest2.

@Test
public void snapshotTableTest2() throws Exception {
    Snapshot expectedResponse = Snapshot.newBuilder().setName(SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]").toString()).setSourceTable(Table.newBuilder().build()).setDataSizeBytes(-2110122398).setCreateTime(Timestamp.newBuilder().build()).setDeleteTime(Timestamp.newBuilder().build()).setDescription("description-1724546052").build();
    Operation resultOperation = Operation.newBuilder().setName("snapshotTableTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    String cluster = "cluster872092154";
    String snapshotId = "snapshotId-1113817601";
    String description = "description-1724546052";
    Snapshot actualResponse = client.snapshotTableAsync(name, cluster, snapshotId, description).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SnapshotTableRequest actualRequest = ((SnapshotTableRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(cluster, actualRequest.getCluster());
    Assert.assertEquals(snapshotId, actualRequest.getSnapshotId());
    Assert.assertEquals(description, actualRequest.getDescription());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SnapshotTableRequest(com.google.bigtable.admin.v2.SnapshotTableRequest) Snapshot(com.google.bigtable.admin.v2.Snapshot) TableName(com.google.bigtable.admin.v2.TableName) AbstractMessage(com.google.protobuf.AbstractMessage) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with TableName

use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.

the class BigtableTableAdminClientTest method testAwaitReplication.

@Test
public void testAwaitReplication() {
    // Setup
    Mockito.when(mockStub.awaitReplicationCallable()).thenReturn(mockAwaitReplicationCallable);
    TableName expectedRequest = TableName.parse(TABLE_NAME);
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    Mockito.when(mockAwaitReplicationCallable.futureCall(expectedRequest)).thenAnswer((Answer<ApiFuture<Void>>) invocationOnMock -> {
        wasCalled.set(true);
        return ApiFutures.immediateFuture(null);
    });
    // Execute
    adminClient.awaitReplication(TABLE_ID);
    // Verify
    assertThat(wasCalled.get()).isTrue();
}
Also used : ArgumentMatchers(org.mockito.ArgumentMatchers) OperationFuture(com.google.api.gax.longrunning.OperationFuture) NotFoundException(com.google.api.gax.rpc.NotFoundException) CreateBackupMetadata(com.google.bigtable.admin.v2.CreateBackupMetadata) ListTablesRequest(com.google.bigtable.admin.v2.ListTablesRequest) Empty(com.google.protobuf.Empty) Table(com.google.cloud.bigtable.admin.v2.models.Table) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Map(java.util.Map) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) Status(io.grpc.Status) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) GcRule(com.google.bigtable.admin.v2.GcRule) Role(com.google.cloud.Role) ListBackupsPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) ApiFutures(com.google.api.core.ApiFutures) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Timestamps(com.google.protobuf.util.Timestamps) ClusterState(com.google.bigtable.admin.v2.Table.ClusterState) State(com.google.bigtable.admin.v2.Backup.State) ListTablesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage) ApiFuture(com.google.api.core.ApiFuture) ByteString(com.google.protobuf.ByteString) EncryptionInfo(com.google.cloud.bigtable.admin.v2.models.EncryptionInfo) List(java.util.List) DeleteTableRequest(com.google.bigtable.admin.v2.DeleteTableRequest) NameUtil(com.google.cloud.bigtable.admin.v2.internal.NameUtil) RestoreTableMetadata(com.google.bigtable.admin.v2.RestoreTableMetadata) DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest) GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) BackupInfo(com.google.bigtable.admin.v2.BackupInfo) Policy(com.google.cloud.Policy) Mock(org.mockito.Mock) OperationFutures(com.google.api.gax.longrunning.OperationFutures) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Operation(com.google.longrunning.Operation) Timestamp(com.google.protobuf.Timestamp) RestoreSourceType(com.google.bigtable.admin.v2.RestoreSourceType) CreateBackupRequest(com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest) Code(io.grpc.Status.Code) Answer(org.mockito.stubbing.Answer) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) Lists(com.google.common.collect.Lists) RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) ImmutableList(com.google.common.collect.ImmutableList) GrpcStatusCode(com.google.api.gax.grpc.GrpcStatusCode) Instant(org.threeten.bp.Instant) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) MockitoJUnit(org.mockito.junit.MockitoJUnit) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Identity(com.google.cloud.Identity) Modification(com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification) Before(org.junit.Before) EnhancedBigtableTableAdminStub(com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub) BaseEncoding(com.google.common.io.BaseEncoding) UpdateBackupRequest(com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest) Test(org.junit.Test) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) View(com.google.bigtable.admin.v2.Table.View) TableName(com.google.bigtable.admin.v2.TableName) ExecutionException(java.util.concurrent.ExecutionException) OperationCallable(com.google.api.gax.rpc.OperationCallable) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) MockitoRule(org.mockito.junit.MockitoRule) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot) GetBackupRequest(com.google.bigtable.admin.v2.GetBackupRequest) TableName(com.google.bigtable.admin.v2.TableName) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApiFuture(com.google.api.core.ApiFuture) Test(org.junit.Test)

Example 5 with TableName

use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method snapshotTableTest.

@Test
public void snapshotTableTest() throws Exception {
    Snapshot expectedResponse = Snapshot.newBuilder().setName(SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]").toString()).setSourceTable(Table.newBuilder().build()).setDataSizeBytes(-2110122398).setCreateTime(Timestamp.newBuilder().build()).setDeleteTime(Timestamp.newBuilder().build()).setDescription("description-1724546052").build();
    Operation resultOperation = Operation.newBuilder().setName("snapshotTableTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    String snapshotId = "snapshotId-1113817601";
    String description = "description-1724546052";
    Snapshot actualResponse = client.snapshotTableAsync(name, cluster, snapshotId, description).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SnapshotTableRequest actualRequest = ((SnapshotTableRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(cluster.toString(), actualRequest.getCluster());
    Assert.assertEquals(snapshotId, actualRequest.getSnapshotId());
    Assert.assertEquals(description, actualRequest.getDescription());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SnapshotTableRequest(com.google.bigtable.admin.v2.SnapshotTableRequest) Snapshot(com.google.bigtable.admin.v2.Snapshot) TableName(com.google.bigtable.admin.v2.TableName) AbstractMessage(com.google.protobuf.AbstractMessage) ClusterName(com.google.bigtable.admin.v2.ClusterName) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 TableName (com.google.bigtable.admin.v2.TableName)16 ByteString (com.google.protobuf.ByteString)12 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 AbstractMessage (com.google.protobuf.AbstractMessage)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)4 DeleteTableRequest (com.google.bigtable.admin.v2.DeleteTableRequest)4 Table (com.google.bigtable.admin.v2.Table)4 DropRowRangeRequest (com.google.bigtable.admin.v2.DropRowRangeRequest)3 Operation (com.google.longrunning.Operation)3 ClusterName (com.google.bigtable.admin.v2.ClusterName)2 GetTableRequest (com.google.bigtable.admin.v2.GetTableRequest)2 Snapshot (com.google.bigtable.admin.v2.Snapshot)2 SnapshotTableRequest (com.google.bigtable.admin.v2.SnapshotTableRequest)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 TableName (org.apache.hadoop.hbase.TableName)2 ApiFuture (com.google.api.core.ApiFuture)1 ApiFutures (com.google.api.core.ApiFutures)1