/** * Creates a {@link BigtableClusterUtilities} for a projectId and an instanceId. * * @param projectId * @param instanceId * * @return a {@link BigtableClusterUtilities} for a specific projectId/instanceId. * @throws GeneralSecurityException if ssl configuration fails * @throws IOException if some aspect of the connection fails. */ public static BigtableClusterUtilities forInstance(String projectId, String instanceId) throws IOException, GeneralSecurityException { return new BigtableClusterUtilities( BigtableOptions.builder().setProjectId(projectId).setInstanceId(instanceId).build()); }
/** * Creates a {@link BigtableClusterUtilities} for all instances in a projectId. * * @param projectId * * @return a {@link BigtableClusterUtilities} for a all instances in a projectId. * @throws GeneralSecurityException if ssl configuration fails * @throws IOException if some aspect of the connection fails. */ public static BigtableClusterUtilities forAllInstances(String projectId) throws IOException, GeneralSecurityException { // '-' means all instanceids. return new BigtableClusterUtilities( BigtableOptions.builder().setProjectId(projectId).setInstanceId("-").build()); }
/** * 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; }