use of com.google.bigtable.admin.v2.InstanceName 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());
}
use of com.google.bigtable.admin.v2.InstanceName 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()));
}
use of com.google.bigtable.admin.v2.InstanceName in project java-bigtable by googleapis.
the class BigtableInstanceAdminClient method listAppProfilesAsync.
/**
* Asynchronously lists all app profiles of the specified instance.
*
* <p>Sample code:
*
* <pre>{@code
* ApiFuture<List<AppProfile>> appProfilesFuture = client.listAppProfilesAsync("my-instance");
*
* List<AppProfile> appProfiles = appProfileFuture.get();
* }</pre>
*
* @see AppProfile
*/
@SuppressWarnings("WeakerAccess")
public ApiFuture<List<AppProfile>> listAppProfilesAsync(String instanceId) {
String instanceName = NameUtil.formatInstanceName(projectId, instanceId);
ListAppProfilesRequest request = ListAppProfilesRequest.newBuilder().setParent(instanceName).build();
// TODO(igorbernstein2): try to upstream pagination spooling or figure out a way to expose the
// paginated responses while maintaining the wrapper facade.
// Fetches the first page.
ApiFuture<ListAppProfilesPage> firstPageFuture = ApiFutures.transform(stub.listAppProfilesPagedCallable().futureCall(request), new ApiFunction<ListAppProfilesPagedResponse, ListAppProfilesPage>() {
@Override
public ListAppProfilesPage apply(ListAppProfilesPagedResponse response) {
return response.getPage();
}
}, MoreExecutors.directExecutor());
// Fetches the rest of the pages by chaining the futures.
ApiFuture<List<com.google.bigtable.admin.v2.AppProfile>> allProtos = ApiFutures.transformAsync(firstPageFuture, new ApiAsyncFunction<ListAppProfilesPage, List<com.google.bigtable.admin.v2.AppProfile>>() {
List<com.google.bigtable.admin.v2.AppProfile> responseAccumulator = Lists.newArrayList();
@Override
public ApiFuture<List<com.google.bigtable.admin.v2.AppProfile>> apply(ListAppProfilesPage page) {
// Add all entries from the page
responseAccumulator.addAll(Lists.newArrayList(page.getValues()));
// If this is the last page, just return the accumulated responses.
if (!page.hasNextPage()) {
return ApiFutures.immediateFuture(responseAccumulator);
}
// Otherwise fetch the next page.
return ApiFutures.transformAsync(page.getNextPageAsync(), this, MoreExecutors.directExecutor());
}
}, MoreExecutors.directExecutor());
// Wraps all of the accumulated protos.
return ApiFutures.transform(allProtos, new ApiFunction<List<com.google.bigtable.admin.v2.AppProfile>, List<AppProfile>>() {
@Override
public List<AppProfile> apply(List<com.google.bigtable.admin.v2.AppProfile> input) {
List<AppProfile> results = Lists.newArrayListWithCapacity(input.size());
for (com.google.bigtable.admin.v2.AppProfile appProfile : input) {
results.add(AppProfile.fromProto(appProfile));
}
return results;
}
}, MoreExecutors.directExecutor());
}
use of com.google.bigtable.admin.v2.InstanceName in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createTableExceptionTest.
@Test
public void createTableExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableTableAdmin.addException(exception);
try {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String tableId = "tableId-1552905847";
Table table = Table.newBuilder().build();
client.createTable(parent, tableId, table);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.bigtable.admin.v2.InstanceName 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()));
}
Aggregations