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());
}
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());
}
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());
}
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]
}
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]
}
Aggregations