/** * @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); } } }
/** * @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); } } }