Search in sources :

Example 36 with Instance

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

the class BigtableInstanceAdminClient method listClustersAsync.

/**
 * Asynchronously lists all clusters in the specified instance.
 *
 * <p>This method will throw a {@link PartialListClustersException} when any zone is unavailable.
 * If a partial list is OK, the exception can be caught and inspected.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<Cluster> clustersFuture = client.listClustersAsync("my-instance");
 *
 * ApiFutures.addCallback(clustersFuture, new ApiFutureCallback<List<Cluster>>() {
 *   public void onFailure(Throwable t) {
 *     if (t instanceof PartialListClustersException) {
 *       PartialListClustersException partialError = (PartialListClustersException)t;
 *       System.out.println("The following zones are unavailable: " + partialError.getUnavailableZones());
 *       System.out.println("But the following clusters are reachable: " + partialError.getClusters());
 *     } else {
 *       t.printStackTrace();
 *     }
 *   }
 *
 *   public void onSuccess(List<Cluster> result) {
 *     System.out.println("Found a complete set of instances: " + result);
 *   }
 * }, MoreExecutors.directExecutor());
 * }</pre>
 */
@SuppressWarnings("WeakerAccess")
public ApiFuture<List<Cluster>> listClustersAsync(String instanceId) {
    String name = NameUtil.formatInstanceName(projectId, instanceId);
    com.google.bigtable.admin.v2.ListClustersRequest request = com.google.bigtable.admin.v2.ListClustersRequest.newBuilder().setParent(name).build();
    return ApiFutures.transform(stub.listClustersCallable().futureCall(request), new ApiFunction<com.google.bigtable.admin.v2.ListClustersResponse, List<Cluster>>() {

        @Override
        public List<Cluster> apply(com.google.bigtable.admin.v2.ListClustersResponse proto) {
            // NOTE: Server-side pagination is not and will not be implemented, so remaining pages
            // are not fetched. However, if that assumption turns out to be wrong, fail fast to
            // avoid returning partial data.
            Verify.verify(proto.getNextPageToken().isEmpty(), "Server returned an unexpected paginated response");
            ImmutableList.Builder<Cluster> clusters = ImmutableList.builder();
            for (com.google.bigtable.admin.v2.Cluster cluster : proto.getClustersList()) {
                clusters.add(Cluster.fromProto(cluster));
            }
            ImmutableList.Builder<String> failedZones = ImmutableList.builder();
            for (String locationStr : proto.getFailedLocationsList()) {
                failedZones.add(NameUtil.extractZoneIdFromLocationName(locationStr));
            }
            if (!failedZones.build().isEmpty()) {
                throw new PartialListClustersException(failedZones.build(), clusters.build());
            }
            return clusters.build();
        }
    }, MoreExecutors.directExecutor());
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) PartialListClustersException(com.google.cloud.bigtable.admin.v2.models.PartialListClustersException) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 37 with Instance

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

the class BigtableInstanceAdminClient method disableClusterAutoscalingAsync.

/**
 * Asynchronously disables autoscaling and enables manual scaling by setting a static node count
 * for the cluster. Please note that only clusters that belong to a production instance can be
 * resized.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<Cluster> clusterApiFuture = client.disableClusterAutoscalingAsync("my-instance", "my-cluster", 3);
 * Cluster cluster = clusterApiFuture.get();
 * }</pre>
 */
public ApiFuture<Cluster> disableClusterAutoscalingAsync(String instanceId, String clusterId, int staticSize) {
    String name = NameUtil.formatClusterName(projectId, instanceId, clusterId);
    com.google.bigtable.admin.v2.Cluster request = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(name).setServeNodes(staticSize).setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.getDefaultInstance()).build();
    PartialUpdateClusterRequest partialUpdateClusterRequest = PartialUpdateClusterRequest.newBuilder().setUpdateMask(FieldMaskUtil.fromStringList(com.google.bigtable.admin.v2.Cluster.class, Lists.newArrayList("cluster_config.cluster_autoscaling_config", "serve_nodes"))).setCluster(request).build();
    return ApiFutures.transform(stub.partialUpdateClusterOperationCallable().futureCall(partialUpdateClusterRequest), Cluster::fromProto, MoreExecutors.directExecutor());
}
Also used : PartialUpdateClusterRequest(com.google.bigtable.admin.v2.PartialUpdateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster)

Example 38 with Instance

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

the class TableAdminExample method addFamilyWithMaxAgeRule.

/**
 * Demonstrates how to create a new instance of the DurationRule.
 */
public void addFamilyWithMaxAgeRule() {
    System.out.printf("%nCreating column family %s with max age GC rule%n", COLUMN_FAMILY_1);
    // [START bigtable_create_family_gc_max_age]
    // Creates a column family with GC policy : maximum age
    // where age = current time minus cell timestamp
    // Defines the GC rule to retain data with max age of 5 days.
    DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
    // 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_1, maxAgeRule);
        adminClient.modifyFamilies(columnFamiliesRequest);
        System.out.println("Created column family: " + COLUMN_FAMILY_1);
    } catch (AlreadyExistsException e) {
        System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
    }
// [END bigtable_create_family_gc_max_age]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 39 with Instance

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

the class TableAdminExample method addFamilyWithIntersectionRule.

/**
 * Demonstrates how to create a new instance of the IntersectionRule.
 */
public void addFamilyWithIntersectionRule() {
    System.out.printf("%nCreating column family %s with intersection GC rule%n", COLUMN_FAMILY_4);
    // [START bigtable_create_family_gc_intersection]
    // Creates a column family with GC policy to drop data that matches all conditions.
    // Defines a GC rule to drop cells older than 5 days AND older than the most recent 2 versions.
    DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
    VersionRule versionRule = GCRULES.maxVersions(2);
    IntersectionRule intersectionRule = GCRULES.intersection().rule(maxAgeRule).rule(versionRule);
    // 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_4, intersectionRule);
        adminClient.modifyFamilies(columnFamiliesRequest);
        System.out.println("Created column family: " + COLUMN_FAMILY_4);
    } catch (AlreadyExistsException e) {
        System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
    }
// [END bigtable_create_family_gc_intersection]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) IntersectionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 40 with Instance

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

the class InstanceAdminExampleTest method testGetInstance.

@Test
public void testGetInstance() {
    // Gets an instance.
    Instance instance = instanceAdmin.getInstance();
    assertNotNull(instance);
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Test(org.junit.Test)

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 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)7 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 List (java.util.List)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 CreateClusterRequest (com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest)3 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)3 AbstractMessage (com.google.protobuf.AbstractMessage)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