public BigtableClusterName toClusterName(String clusterId) { return new BigtableClusterName(instanceName + "/clusters/" + clusterId); } }
/** * Snapshot operations need various aspects of a {@link BigtableClusterName}. This method gets a * clusterId from either a lookup (projectId and instanceId translate to a single clusterId when * an instance has only one cluster). */ public synchronized BigtableClusterName getClusterName() throws IOException { if (this.clusterName == null) { try (BigtableClusterUtilities util = new BigtableClusterUtilities(options)) { ListClustersResponse clusters = util.getClusters(); Preconditions.checkState(clusters.getClustersCount() == 1, String.format( "Project '%s' / Instance '%s' has %d clusters. There must be exactly 1 for this operation to work.", options.getProjectId(), options.getInstanceId(), clusters.getClustersCount())); clusterName = new BigtableClusterName(clusters.getClusters(0).getName()); } catch (GeneralSecurityException e) { throw new IOException("Could not get cluster Id.", e); } } return clusterName; }
/** * @return The instance id associated with the given project, zone and cluster. We expect instance * and cluster to have one-to-one relationship. * * @throws IllegalStateException if the cluster is not found */ public static String lookupInstanceId(String projectId, String clusterId, String zoneId) throws IOException { BigtableClusterUtilities utils; try { utils = BigtableClusterUtilities.forAllInstances(projectId); } catch (GeneralSecurityException e) { throw new RuntimeException("Could not initialize BigtableClusterUtilities", e); } try { Cluster cluster = utils.getCluster(clusterId, zoneId); return new BigtableClusterName(cluster.getName()).getInstanceId(); } finally { try { utils.close(); } catch (Exception e) { logger.warn("Error closing BigtableClusterUtilities: ", e); } } }
/** * Constructor for the auto-scaler with the minimum required information: project and instance ids. * @param projectId * @param instanceId * @throws GeneralSecurityException * @throws IOException */ public MetricScaler(String projectId, String instanceId) throws GeneralSecurityException, IOException { clusterUtility = BigtableClusterUtilities.forInstance(projectId, instanceId); Cluster cluster = clusterUtility.getSingleCluster(); this.clusterId = new BigtableClusterName(cluster.getName()).getClusterId(); this.zoneId = BigtableClusterUtilities.getZoneId(cluster); // Instantiates a client metricServiceClient = MetricServiceClient.create(); projectName = ProjectName.create(projectId); }