Search in sources :

Example 26 with Instance

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

the class BigtableInstanceAdminClient method getAppProfileAsync.

/**
 * Asynchronously gets the app profile by ID.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<AppProfile> appProfileFuture = client.getAppProfileAsync("my-instance", "my-app-profile");
 *
 * AppProfile appProfile = appProfileFuture.get();
 * }</pre>
 *
 * @see AppProfile
 */
@SuppressWarnings("WeakerAccess")
public ApiFuture<AppProfile> getAppProfileAsync(String instanceId, String appProfileId) {
    String name = NameUtil.formatAppProfileName(projectId, instanceId, appProfileId);
    GetAppProfileRequest request = GetAppProfileRequest.newBuilder().setName(name).build();
    return ApiFutures.transform(stub.getAppProfileCallable().futureCall(request), new ApiFunction<com.google.bigtable.admin.v2.AppProfile, AppProfile>() {

        @Override
        public AppProfile apply(com.google.bigtable.admin.v2.AppProfile proto) {
            return AppProfile.fromProto(proto);
        }
    }, MoreExecutors.directExecutor());
}
Also used : GetAppProfileRequest(com.google.bigtable.admin.v2.GetAppProfileRequest) AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile)

Example 27 with Instance

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

the class BigtableInstanceAdminClient method listInstancesAsync.

/**
 * Asynchronously lists all of the instances in the current project.
 *
 * <p>This method will throw a {@link PartialListInstancesException} when any zone is unavailable.
 * If a partial list is OK, the exception can be caught and inspected.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<Instance> instancesFuture = client.listInstancesAsync();
 *
 * ApiFutures.addCallback(instancesFuture, new ApiFutureCallback<List<Instance>>() {
 *   public void onFailure(Throwable t) {
 *     if (t instanceof PartialListInstancesException) {
 *       PartialListInstancesException partialError = (PartialListInstancesException)t;
 *       System.out.println("The following zones are unavailable: " + partialError.getUnavailableZones());
 *       System.out.println("But the following instances are reachable: " + partialError.getInstances());
 *     } else {
 *       t.printStackTrace();
 *     }
 *   }
 *
 *   public void onSuccess(List<Instance> result) {
 *     System.out.println("Found a complete set of instances: " + result);
 *   }
 * }, MoreExecutors.directExecutor());
 * }</pre>
 */
@SuppressWarnings("WeakerAccess")
public ApiFuture<List<Instance>> listInstancesAsync() {
    com.google.bigtable.admin.v2.ListInstancesRequest request = com.google.bigtable.admin.v2.ListInstancesRequest.newBuilder().setParent(NameUtil.formatProjectName(projectId)).build();
    ApiFuture<com.google.bigtable.admin.v2.ListInstancesResponse> responseFuture = stub.listInstancesCallable().futureCall(request);
    return ApiFutures.transform(responseFuture, new ApiFunction<com.google.bigtable.admin.v2.ListInstancesResponse, List<Instance>>() {

        @Override
        public List<Instance> apply(com.google.bigtable.admin.v2.ListInstancesResponse proto) {
            // NOTE: Pagination is intentionally ignored. The server does not implement it and never
            // will.
            Verify.verify(proto.getNextPageToken().isEmpty(), "Server returned an unexpected paginated response");
            ImmutableList.Builder<Instance> instances = ImmutableList.builder();
            for (com.google.bigtable.admin.v2.Instance protoInstance : proto.getInstancesList()) {
                instances.add(Instance.fromProto(protoInstance));
            }
            ImmutableList.Builder<String> failedZones = ImmutableList.builder();
            for (String locationStr : proto.getFailedLocationsList()) {
                failedZones.add(NameUtil.extractZoneIdFromLocationName(locationStr));
            }
            if (!failedZones.build().isEmpty()) {
                throw new PartialListInstancesException(failedZones.build(), instances.build());
            }
            return instances.build();
        }
    }, MoreExecutors.directExecutor());
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) PartialListInstancesException(com.google.cloud.bigtable.admin.v2.models.PartialListInstancesException) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 28 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 29 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 30 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)

Aggregations

Test (org.junit.Test)24 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)19 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)10 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)7 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 AbstractMessage (com.google.protobuf.AbstractMessage)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 ClusterName (com.google.bigtable.admin.v2.ClusterName)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 ClusterAutoscalingConfig (com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)3 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)2 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)2 GetInstanceRequest (com.google.bigtable.admin.v2.GetInstanceRequest)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2