/** * @return The cluster associated with the given project and instance. We expect instance and * cluster to have one-to-one relationship. * @throws IllegalStateException if the cluster is not found or if there are many clusters in this * instance. */ public static Cluster lookupCluster(String projectId, String instanceId) throws IOException { BigtableClusterUtilities utils; try { utils = BigtableClusterUtilities.forInstance(projectId, instanceId); } catch (GeneralSecurityException e) { throw new RuntimeException("Could not initialize BigtableClusterUtilities", e); } try { return utils.getSingleCluster(); } 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); }