use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class InstanceAdminExampleTest method testGetInstance.
@Test
public void testGetInstance() {
// Gets an instance.
Instance instance = instanceAdmin.getInstance();
assertNotNull(instance);
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class InstanceAdminExampleTest method garbageCollect.
private static void garbageCollect() {
Pattern timestampPattern = Pattern.compile(ID_PREFIX + "-([0-9a-f]+)");
System.out.println();
for (Instance instance : adminClient.listInstances()) {
Matcher matcher = timestampPattern.matcher(instance.getId());
if (!matcher.matches()) {
continue;
}
System.out.println("Garbage collecting orphaned table: " + instance);
adminClient.deleteInstance(instance.getId());
}
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class NativeImageBigtableTest method setUp.
@Before
public void setUp() throws IOException {
// Create instance if not present
BigtableInstanceAdminSettings instanceAdminSettings = BigtableInstanceAdminSettings.newBuilder().setProjectId(PROJECT_ID).build();
BigtableInstanceAdminClient instanceAdminClient = BigtableInstanceAdminClient.create(instanceAdminSettings);
if (!instanceAdminClient.exists(INSTANCE_NAME)) {
instanceAdminClient.createInstance(CreateInstanceRequest.of(INSTANCE_NAME).addCluster("cluster", "us-central1-f", 3, StorageType.SSD).setType(Instance.Type.PRODUCTION).addLabel("example", "instance_admin"));
}
BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(PROJECT_ID).build();
BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(PROJECT_ID).build();
adminClient = BigtableTableAdminClient.create(adminClientSettings);
tableName = TABLE_SUFFIX + UUID.randomUUID().toString().replace("-", "");
NativeImageBigtableSample.createTable(adminClient, tableName);
dataClient = BigtableDataClient.create(clientSettings);
// To test output stream
originalOut = System.out;
bout = new ByteArrayOutputStream();
System.setOut(new PrintStream(bout));
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class InstanceAdminExample method getInstance.
/**
* Demonstrates how to get an instance.
*/
public Instance getInstance() {
System.out.println("\nGet Instance");
// [START bigtable_get_instance]
Instance instance = null;
try {
instance = adminClient.getInstance(instanceId);
System.out.println("Instance ID: " + instance.getId());
System.out.println("Display Name: " + instance.getDisplayName());
System.out.print("Labels: ");
Map<String, String> labels = instance.getLabels();
for (String key : labels.keySet()) {
System.out.printf("%s - %s", key, labels.get(key));
}
System.out.println("\nState: " + instance.getState());
System.out.println("Type: " + instance.getType());
} catch (NotFoundException e) {
System.err.println("Failed to get non-existent instance: " + e.getMessage());
}
// [END bigtable_get_instance]
return instance;
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class TestEnvRule method deleteInstance.
/**
* Delete an instance with all of its resources.
*/
private void deleteInstance(String instanceId) throws IOException, ExecutionException, InterruptedException {
BigtableTableAdminSettings settings = env().getTableAdminSettings().toBuilder().setInstanceId(instanceId).build();
// Delete all child resources (backups & clusters) that wont be automatically deleted
try (BigtableTableAdminClient tableAdmin = BigtableTableAdminClient.create(settings)) {
List<Cluster> clusters = env().getInstanceAdminClient().listClusters(instanceId);
boolean isFirstCluster = true;
for (Cluster cluster : clusters) {
deleteBackups(tableAdmin, cluster.getId());
// without clusters)
if (!isFirstCluster) {
try {
env().getInstanceAdminClient().deleteCluster(instanceId, cluster.getId());
} catch (NotFoundException ignored) {
}
}
isFirstCluster = false;
}
}
// Delete everything else
try {
env().getInstanceAdminClient().deleteInstance(instanceId);
} catch (NotFoundException ignored) {
}
}
Aggregations