Search in sources :

Example 16 with Instance

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

the class BaseBigtableTableAdminClientTest method listSnapshotsTest.

@Test
public void listSnapshotsTest() throws Exception {
    Snapshot responsesElement = Snapshot.newBuilder().build();
    ListSnapshotsResponse expectedResponse = ListSnapshotsResponse.newBuilder().setNextPageToken("").addAllSnapshots(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    ListSnapshotsPagedResponse pagedListResponse = client.listSnapshots(parent);
    List<Snapshot> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSnapshotsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSnapshotsRequest actualRequest = ((ListSnapshotsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Snapshot(com.google.bigtable.admin.v2.Snapshot) ListSnapshotsRequest(com.google.bigtable.admin.v2.ListSnapshotsRequest) ListSnapshotsResponse(com.google.bigtable.admin.v2.ListSnapshotsResponse) ListSnapshotsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListSnapshotsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ClusterName(com.google.bigtable.admin.v2.ClusterName) Test(org.junit.Test)

Example 17 with Instance

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

the class BigtableBackupIT method crossInstanceRestoreTest.

@Test
public void crossInstanceRestoreTest() throws InterruptedException, IOException, ExecutionException, TimeoutException {
    String backupId = prefixGenerator.newPrefix();
    String restoredTableId = prefixGenerator.newPrefix();
    // Create the backup
    tableAdmin.createBackup(CreateBackupRequest.of(targetCluster, backupId).setSourceTableId(testTable.getId()).setExpireTime(Instant.now().plus(Duration.ofHours(6))));
    Stopwatch stopwatch = Stopwatch.createStarted();
    // Set up a new instance to test cross-instance restore. The backup will be restored here
    String targetInstance = prefixGenerator.newPrefix();
    instanceAdmin.createInstance(CreateInstanceRequest.of(targetInstance).addCluster(targetInstance, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD).setDisplayName("backups-dest-test-instance").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
    try (BigtableTableAdminClient destTableAdmin = testEnvRule.env().getTableAdminClientForInstance(targetInstance)) {
        // Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
        // table operation.
        Thread.sleep(Duration.ofMinutes(2).minus(Duration.ofMillis(stopwatch.elapsed(TimeUnit.MILLISECONDS))).toMillis());
        try {
            RestoreTableRequest req = RestoreTableRequest.of(testEnvRule.env().getInstanceId(), targetCluster, backupId).setTableId(restoredTableId);
            RestoredTableResult result = destTableAdmin.restoreTable(req);
            assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
            assertWithMessage("Incorrect instance id").that(result.getTable().getInstanceId()).isEqualTo(targetInstance);
            // The assertion might be missing if the test is running against a HDD cluster or an
            // optimization is not necessary.
            assertWithMessage("Empty OptimizeRestoredTable token").that(result.getOptimizeRestoredTableOperationToken()).isNotNull();
            destTableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
            destTableAdmin.getTable(restoredTableId);
        } finally {
            tableAdmin.deleteBackup(targetCluster, backupId);
            instanceAdmin.deleteInstance(targetInstance);
        }
    }
}
Also used : RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) Stopwatch(com.google.common.base.Stopwatch) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) ByteString(com.google.protobuf.ByteString) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) Test(org.junit.Test)

Example 18 with Instance

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

the class BigtableInstanceAdminClientIT method basicClusterOperationTestHelper.

// To improve test runtime, piggyback off the instance creation/deletion test's fresh instance.
private void basicClusterOperationTestHelper(String targetInstanceId, String targetClusterId) {
    List<Cluster> clusters = client.listClusters(targetInstanceId);
    Cluster targetCluster = null;
    for (Cluster cluster : clusters) {
        if (cluster.getId().equals(targetClusterId)) {
            targetCluster = cluster;
        }
    }
    assertWithMessage("Failed to find target cluster id in listClusters").that(targetCluster).isNotNull();
    assertThat(client.getCluster(targetInstanceId, targetClusterId)).isEqualTo(targetCluster);
    int freshNumOfNodes = targetCluster.getServeNodes() + 1;
    Cluster resizeCluster = client.resizeCluster(targetInstanceId, targetClusterId, freshNumOfNodes);
    assertThat(resizeCluster.getServeNodes()).isEqualTo(freshNumOfNodes);
    ClusterAutoscalingConfig autoscalingConfig = ClusterAutoscalingConfig.of(targetInstanceId, targetClusterId).setMinNodes(1).setMaxNodes(4).setCpuUtilizationTargetPercent(40);
    Cluster cluster = client.updateClusterAutoscalingConfig(autoscalingConfig);
    assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(4);
    assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(1);
    assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(40);
    Cluster updatedCluster = client.disableClusterAutoscaling(targetInstanceId, targetClusterId, 3);
    assertThat(updatedCluster.getServeNodes()).isEqualTo(3);
    assertThat(updatedCluster.getAutoscalingMaxServeNodes()).isEqualTo(0);
    assertThat(updatedCluster.getAutoscalingMinServeNodes()).isEqualTo(0);
    assertThat(updatedCluster.getAutoscalingCpuPercentageTarget()).isEqualTo(0);
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) ClusterAutoscalingConfig(com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)

Example 19 with Instance

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

the class BigtableInstanceAdminClientIT method createClusterWithAutoscalingAndPartialUpdateTest.

@Test
public void createClusterWithAutoscalingAndPartialUpdateTest() {
    String newInstanceId = prefixGenerator.newPrefix();
    String newClusterId = newInstanceId + "-c1";
    try {
        client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD).setDisplayName("Multi-Cluster-Instance-Test").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
        String clusterId = prefixGenerator.newPrefix();
        CreateClusterRequest createClusterRequest = CreateClusterRequest.of(newInstanceId, clusterId).setZone(testEnvRule.env().getSecondaryZone()).setScalingMode(ClusterAutoscalingConfig.of("ignored", clusterId).setMaxNodes(4).setMinNodes(1).setCpuUtilizationTargetPercent(20));
        Cluster cluster = client.createCluster(createClusterRequest);
        assertThat(cluster.getId()).contains(clusterId);
        assertThat(cluster.getServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(1);
        assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(4);
        assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(20);
        Cluster updatedCluster = client.updateClusterAutoscalingConfig(ClusterAutoscalingConfig.of(newInstanceId, clusterId).setMaxNodes(3));
        assertThat(updatedCluster.getAutoscalingMinServeNodes()).isEqualTo(1);
        assertThat(updatedCluster.getAutoscalingMaxServeNodes()).isEqualTo(3);
        assertThat(updatedCluster.getAutoscalingCpuPercentageTarget()).isEqualTo(20);
        updatedCluster = client.updateClusterAutoscalingConfig(ClusterAutoscalingConfig.of(newInstanceId, clusterId).setMinNodes(2));
        assertThat(updatedCluster.getAutoscalingMinServeNodes()).isEqualTo(2);
        assertThat(updatedCluster.getAutoscalingMaxServeNodes()).isEqualTo(3);
        assertThat(updatedCluster.getAutoscalingCpuPercentageTarget()).isEqualTo(20);
        updatedCluster = client.updateClusterAutoscalingConfig(ClusterAutoscalingConfig.of(newInstanceId, clusterId).setCpuUtilizationTargetPercent(40));
        assertThat(updatedCluster.getAutoscalingMinServeNodes()).isEqualTo(2);
        assertThat(updatedCluster.getAutoscalingMaxServeNodes()).isEqualTo(3);
        assertThat(updatedCluster.getAutoscalingCpuPercentageTarget()).isEqualTo(40);
        updatedCluster = client.updateClusterAutoscalingConfig(ClusterAutoscalingConfig.of(newInstanceId, clusterId).setCpuUtilizationTargetPercent(45).setMaxNodes(5));
        assertThat(updatedCluster.getAutoscalingMinServeNodes()).isEqualTo(2);
        assertThat(updatedCluster.getAutoscalingMaxServeNodes()).isEqualTo(5);
        assertThat(updatedCluster.getAutoscalingCpuPercentageTarget()).isEqualTo(45);
    } catch (Exception e) {
        Assert.fail("error in the test: " + e.getMessage());
    } finally {
        client.deleteInstance(newInstanceId);
    }
}
Also used : CreateClusterRequest(com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 20 with Instance

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

the class BigtableInstanceAdminClientIT method createClusterWithAutoscalingTest.

@Test
public void createClusterWithAutoscalingTest() {
    String newInstanceId = prefixGenerator.newPrefix();
    String newClusterId = newInstanceId + "-c1";
    try {
        client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.HDD).setDisplayName("Multi-Cluster-Instance-Test").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
        String clusterId = prefixGenerator.newPrefix();
        CreateClusterRequest createClusterRequest = CreateClusterRequest.of(newInstanceId, clusterId).setZone(testEnvRule.env().getSecondaryZone()).setStorageType(StorageType.HDD).setScalingMode(ClusterAutoscalingConfig.of(newInstanceId, clusterId).setMaxNodes(4).setMinNodes(1).setCpuUtilizationTargetPercent(20));
        Cluster cluster = client.createCluster(createClusterRequest);
        assertThat(cluster.getId()).contains(clusterId);
        assertThat(cluster.getServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(1);
        assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(4);
        assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(20);
    } catch (Exception e) {
        Assert.fail("error in the test" + e.getMessage());
    } finally {
        client.deleteInstance(newInstanceId);
    }
}
Also used : CreateClusterRequest(com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

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