use of com.google.cloud.bigtable.grpc.BigtableClusterName 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;
}
}
use of com.google.cloud.bigtable.grpc.BigtableClusterName in project java-bigtable-hbase by googleapis.
the class BigtableAsyncAdmin method getBackupClusterName.
private synchronized BigtableClusterName getBackupClusterName() {
if (this.bigtableSnapshotClusterName == null) {
List<Cluster> clusters = asyncConnection.getBigtableApi().getAdminClient().listClusters(asyncConnection.getBigtableSettings().getInstanceId());
Preconditions.checkState(clusters.size() == 1, String.format("Project '%s' / Instance '%s' has %d clusters. There must be exactly 1 for this operation to work.", asyncConnection.getBigtableSettings().getProjectId(), asyncConnection.getBigtableSettings().getInstanceId(), clusters.size()));
String clusterName = NameUtil.formatClusterName(asyncConnection.getBigtableSettings().getProjectId(), asyncConnection.getBigtableSettings().getInstanceId(), clusters.get(0).getId());
bigtableSnapshotClusterName = new BigtableClusterName(clusterName);
}
return bigtableSnapshotClusterName;
}
Aggregations