use of com.google.cloud.bigtable.grpc.BigtableClusterUtilities in project java-docs-samples by GoogleCloudPlatform.
the class BulkWrite method getClusterNodeCount.
// Get the number of nodes for the Bigtable instance. This only works for single cluster instances
// so it will treat multi-cluster instances as single node clusters.
private static int getClusterNodeCount(String projectId, String instanceId) throws IOException, GeneralSecurityException {
try {
BigtableClusterUtilities clusterUtility = BigtableClusterUtilities.forInstance(projectId, instanceId);
Cluster cluster = clusterUtility.getSingleCluster();
String clusterId = new BigtableClusterName(cluster.getName()).getClusterId();
String zoneId = BigtableClusterUtilities.getZoneId(cluster);
int clusterNodeCount = clusterUtility.getClusterNodeCount(clusterId, zoneId);
System.out.println("Cluster size " + clusterNodeCount);
return clusterNodeCount;
} catch (IllegalStateException e) {
System.out.println("Unable to get cluster size. Treating as single-node cluster.");
return 1;
}
}
Aggregations