Search in sources :

Example 1 with BigtableClusterUtilities

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;
    }
}
Also used : BigtableClusterName(com.google.cloud.bigtable.grpc.BigtableClusterName) Cluster(com.google.bigtable.admin.v2.Cluster) BigtableClusterUtilities(com.google.cloud.bigtable.grpc.BigtableClusterUtilities)

Aggregations

Cluster (com.google.bigtable.admin.v2.Cluster)1 BigtableClusterName (com.google.cloud.bigtable.grpc.BigtableClusterName)1 BigtableClusterUtilities (com.google.cloud.bigtable.grpc.BigtableClusterUtilities)1