Search in sources :

Example 31 with Instance

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);
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Test(org.junit.Test)

Example 32 with 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());
    }
}
Also used : Pattern(java.util.regex.Pattern) Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Matcher(java.util.regex.Matcher)

Example 33 with Instance

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));
}
Also used : PrintStream(java.io.PrintStream) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableInstanceAdminClient(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) BigtableInstanceAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings) Before(org.junit.Before)

Example 34 with Instance

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;
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 35 with 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) {
    }
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) NotFoundException(com.google.api.gax.rpc.NotFoundException) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)

Aggregations

Test (org.junit.Test)24 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)19 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)10 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)7 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ClusterName (com.google.bigtable.admin.v2.ClusterName)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 ClusterAutoscalingConfig (com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)3 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)2 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)2 GetInstanceRequest (com.google.bigtable.admin.v2.GetInstanceRequest)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2