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