Search in sources :

Example 1 with Instance

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

the class CreateBackupTestIT method setUp.

@BeforeClass
public static void setUp() throws IOException {
    projectId = requireEnv(PROJECT_ENV);
    try (BigtableInstanceAdminClient instanceAdmin = BigtableInstanceAdminClient.create(projectId)) {
        CreateInstanceRequest request = CreateInstanceRequest.of(INSTANCE_ID).addCluster(CLUSTER_ID, ZONE_ID, 1, StorageType.SSD);
        Instance instance = instanceAdmin.createInstance(request);
    } catch (IOException e) {
        System.out.println("Error during BeforeClass while creating instance: \n" + e.toString());
        throw (e);
    }
    try (BigtableTableAdminClient tableAdmin = BigtableTableAdminClient.create(projectId, INSTANCE_ID)) {
        // Create a table.
        tableAdmin.createTable(CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME));
    } catch (IOException e) {
        System.out.println("Error during BeforeClass while creating table: \n" + e.toString());
        throw (e);
    }
    // Get the sample's base directory (the one containing a pom.xml file)
    String baseDir = System.getProperty("basedir");
    // Emulate the function locally by running the Functions Framework Maven plugin
    emulatorProcess = new ProcessBuilder().command("mvn", "function:run").directory(new File(baseDir)).start();
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) BigtableInstanceAdminClient(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient) IOException(java.io.IOException) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) CreateInstanceRequest(com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 2 with Instance

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

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

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

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

the class TableAdminExample method addFamilyWithUnionRule.

/**
 * Demonstrates how to create a new instance of the UnionRule.
 */
public void addFamilyWithUnionRule() {
    System.out.printf("%nCreating column family %s with union GC rule%n", COLUMN_FAMILY_3);
    // [START bigtable_create_family_gc_union]
    // Creates a column family with GC policy to drop data that matches at least one condition.
    // Defines a list of GC rules to drop cells older than 5 days OR not the most recent
    // version.
    UnionRule unionRule = GCRULES.union().rule(GCRULES.maxAge(5, TimeUnit.DAYS)).rule(GCRULES.maxVersions(1));
    // Creates column family with given GC rule.
    try {
        // ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is
        // being used to add a family
        ModifyColumnFamiliesRequest columnFamiliesRequest = ModifyColumnFamiliesRequest.of(tableId).addFamily(COLUMN_FAMILY_3, unionRule);
        adminClient.modifyFamilies(columnFamiliesRequest);
        System.out.println("Created column family: " + COLUMN_FAMILY_3);
    } catch (AlreadyExistsException e) {
        System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
    }
// [END bigtable_create_family_gc_union]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) UnionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Aggregations

Test (org.junit.Test)18 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)14 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)9 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 List (java.util.List)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 CreateClusterRequest (com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest)3 CreateInstanceRequest (com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 ClusterName (com.google.bigtable.admin.v2.ClusterName)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2 ListAppProfilesRequest (com.google.bigtable.admin.v2.ListAppProfilesRequest)2 ListTablesRequest (com.google.bigtable.admin.v2.ListTablesRequest)2 ListAppProfilesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse)2