Search in sources :

Example 46 with Instance

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

the class ITSystemTest method testGetInstance.

@Test
public void testGetInstance() {
    Instance response = client.getInstance(INSTANCE_NAME);
    assertEquals(TIER, response.getTier());
    assertEquals(INSTANCE_NAME.toString(), response.getName());
}
Also used : Instance(com.google.cloud.redis.v1.Instance) Test(org.junit.Test)

Example 47 with Instance

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

the class BigtableInstanceAdminClient method deleteAppProfileAsync.

/**
 * Asynchronously deletes the specified app profile with an option to force deletion.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<Void> deleteFuture = client.deleteAppProfileAsync("my-instance", "my-app-profile", true);
 *
 * deleteFuture.get();
 * }</pre>
 */
@SuppressWarnings("WeakerAccess")
public ApiFuture<Void> deleteAppProfileAsync(String instanceId, String appProfileId, boolean forceDelete) {
    String name = NameUtil.formatAppProfileName(projectId, instanceId, appProfileId);
    DeleteAppProfileRequest request = DeleteAppProfileRequest.newBuilder().setName(name).setIgnoreWarnings(forceDelete).build();
    return ApiFutures.transform(stub.deleteAppProfileCallable().futureCall(request), new ApiFunction<Empty, Void>() {

        @Override
        public Void apply(Empty input) {
            return null;
        }
    }, MoreExecutors.directExecutor());
}
Also used : DeleteAppProfileRequest(com.google.bigtable.admin.v2.DeleteAppProfileRequest) Empty(com.google.protobuf.Empty)

Example 48 with Instance

use of com.google.bigtable.admin.v2.Instance 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());
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) ListAppProfilesRequest(com.google.bigtable.admin.v2.ListAppProfilesRequest) ApiFuture(com.google.api.core.ApiFuture) ListAppProfilesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPage) ListAppProfilesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 49 with Instance

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

the class BigtableTableAdminClient method listTablesAsync.

/**
 * Asynchronously lists all table IDs in the instance.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<List<String>> listFuture = client.listTables();
 *
 * ApiFutures.addCallback(
 *   listFuture,
 *   new ApiFutureCallback<List<String>>() {
 *     public void onSuccess(List<String> tableIds) {
 *       System.out.println("Got list of tables:");
 *       for (String tableId : tableIds) {
 *         System.out.println(tableId);
 *       }
 *     }
 *
 *     public void onFailure(Throwable t) {
 *       t.printStackTrace();
 *     }
 *   },
 *   MoreExecutors.directExecutor()
 * );
 * }</pre>
 */
public ApiFuture<List<String>> listTablesAsync() {
    ListTablesRequest request = ListTablesRequest.newBuilder().setParent(NameUtil.formatInstanceName(projectId, instanceId)).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<ListTablesPage> firstPageFuture = ApiFutures.transform(stub.listTablesPagedCallable().futureCall(request), new ApiFunction<ListTablesPagedResponse, ListTablesPage>() {

        @Override
        public ListTablesPage apply(ListTablesPagedResponse response) {
            return response.getPage();
        }
    }, MoreExecutors.directExecutor());
    // Fetches the rest of the pages by chaining the futures.
    ApiFuture<List<com.google.bigtable.admin.v2.Table>> allProtos = ApiFutures.transformAsync(firstPageFuture, new ApiAsyncFunction<ListTablesPage, List<com.google.bigtable.admin.v2.Table>>() {

        List<com.google.bigtable.admin.v2.Table> responseAccumulator = Lists.newArrayList();

        @Override
        public ApiFuture<List<com.google.bigtable.admin.v2.Table>> apply(ListTablesPage 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.Table>, List<String>>() {

        @Override
        public List<String> apply(List<com.google.bigtable.admin.v2.Table> protos) {
            List<String> results = Lists.newArrayListWithCapacity(protos.size());
            for (com.google.bigtable.admin.v2.Table proto : protos) {
                results.add(NameUtil.extractTableIdFromTableName(proto.getName()));
            }
            return results;
        }
    }, MoreExecutors.directExecutor());
}
Also used : ListTablesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage) Table(com.google.cloud.bigtable.admin.v2.models.Table) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) ApiFuture(com.google.api.core.ApiFuture) ListTablesRequest(com.google.bigtable.admin.v2.ListTablesRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 50 with Instance

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

the class EmulatorTest method testTableAdminClient.

@Test
public void testTableAdminClient() {
    Table table = tableAdminStub.createTable(CreateTableRequest.newBuilder().setParent("projects/fake-project/instances/fake-instance").setTableId("fake-table").setTable(Table.newBuilder().putColumnFamilies("cf", ColumnFamily.getDefaultInstance())).build());
    assertThat(table.getName()).isEqualTo("projects/fake-project/instances/fake-instance/tables/fake-table");
}
Also used : Table(com.google.bigtable.admin.v2.Table) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)137 AbstractMessage (com.google.protobuf.AbstractMessage)63 ByteString (com.google.protobuf.ByteString)57 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)41 StatusRuntimeException (io.grpc.StatusRuntimeException)41 Instance (com.google.cloud.redis.v1beta1.Instance)34 CloudRedisClient (com.google.cloud.redis.v1beta1.CloudRedisClient)30 Instance (com.google.cloud.compute.v1.Instance)25 Operation (com.google.longrunning.Operation)22 InstanceName (com.google.bigtable.admin.v2.InstanceName)20 InstancesClient (com.google.cloud.compute.v1.InstancesClient)19 ExecutionException (java.util.concurrent.ExecutionException)17 ClusterName (com.google.bigtable.admin.v2.ClusterName)16 Table (com.google.bigtable.admin.v2.Table)16 HashMap (java.util.HashMap)16 TableName (com.google.bigtable.admin.v2.TableName)15 Cluster (com.google.bigtable.admin.v2.Cluster)13 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)13 Operation (com.google.cloud.compute.v1.Operation)13 ArrayList (java.util.ArrayList)13