Search in sources :

Example 16 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster 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)

Example 17 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster 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 18 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class NativeImageBigtableSample method main.

/**
 * Entrypoint to the BigTable sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableInstanceAdminSettings instanceAdminSettings = BigtableInstanceAdminSettings.newBuilder().setProjectId(projectId).build();
    BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminClientSettings);
    BigtableDataClient standardClient = BigtableDataClient.create(clientSettings);
    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"));
    }
    String tableName = TABLE_NAME + UUID.randomUUID().toString().replace("-", "");
    createTable(adminClient, tableName);
    // Add data into table
    ImmutableMap<String, Long> dataWithLong = ImmutableMap.of("connected_cell", 1L, "connected_wifi", 1L);
    ImmutableMap<String, String> dataWithStrings = ImmutableMap.of("os_build", "PQ2A.190405.003");
    long timestamp = System.currentTimeMillis() * 1000;
    insertData(standardClient, tableName, timestamp, dataWithLong, dataWithStrings);
    readData(standardClient, tableName);
    // Clean up
    deleteTable(adminClient, tableName);
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableInstanceAdminClient(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient) ByteString(com.google.protobuf.ByteString) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) BigtableInstanceAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)

Example 19 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class BigtableBackupIT method restoreTableTest.

@Test
public void restoreTableTest() throws InterruptedException, ExecutionException {
    String backupId = prefixGenerator.newPrefix();
    String restoredTableId = prefixGenerator.newPrefix();
    tableAdmin.createBackup(createBackupRequest(backupId));
    // Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
    // table operation.
    Thread.sleep(120 * 1000);
    try {
        RestoreTableRequest req = RestoreTableRequest.of(targetCluster, backupId).setTableId(restoredTableId);
        RestoredTableResult result = tableAdmin.restoreTable(req);
        assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
        if (result.getOptimizeRestoredTableOperationToken() != null) {
            // The assertion might be missing if the test is running against a HDD cluster or an
            // optimization is not necessary.
            tableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
            Table restoredTable = tableAdmin.getTable(restoredTableId);
            assertWithMessage("Incorrect restored table id").that(restoredTable.getId()).isEqualTo(restoredTableId);
        }
    } finally {
        tableAdmin.deleteBackup(targetCluster, backupId);
        tableAdmin.deleteTable(restoredTableId);
    }
}
Also used : RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) Table(com.google.cloud.bigtable.admin.v2.models.Table) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 20 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testPartialUpdateCluster.

@Test
public void testPartialUpdateCluster() {
    Mockito.when(mockStub.partialUpdateClusterOperationCallable()).thenReturn(mockPartialUpdateClusterCallable);
    // Setup
    com.google.bigtable.admin.v2.Cluster cluster = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setClusterConfig(clusterConfig).build();
    PartialUpdateClusterRequest expectedRequest = PartialUpdateClusterRequest.newBuilder().setCluster(cluster).setUpdateMask(FieldMask.newBuilder().addPaths("cluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodes").addPaths("cluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodes").addPaths("cluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percent").build()).build();
    com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setLocation(NameUtil.formatLocationName(PROJECT_ID, "us-east1-c")).setClusterConfig(clusterConfig).build();
    mockOperationResult(mockPartialUpdateClusterCallable, expectedRequest, expectedResponse);
    // Execute
    Cluster actualResult = adminClient.updateClusterAutoscalingConfig(ClusterAutoscalingConfig.of(INSTANCE_ID, CLUSTER_ID).setMaxNodes(10).setMinNodes(2).setCpuUtilizationTargetPercent(22));
    // Verify
    assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
Also used : PartialUpdateClusterRequest(com.google.bigtable.admin.v2.PartialUpdateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)17 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)4 PartialUpdateClusterRequest (com.google.bigtable.admin.v2.PartialUpdateClusterRequest)3 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)3 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)3 CreateClusterRequest (com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest)3 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)3 ByteString (com.google.protobuf.ByteString)3 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 ClusterName (com.google.bigtable.admin.v2.ClusterName)2 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)2 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 RestoreTableRequest (com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest)2 RestoredTableResult (com.google.cloud.bigtable.admin.v2.models.RestoredTableResult)2 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)2 ImmutableList (com.google.common.collect.ImmutableList)2 AbstractMessage (com.google.protobuf.AbstractMessage)2