Search in sources :

Example 6 with Cluster

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

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

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

the class BigtableInstanceAdminClientTest method testCreateAppProfileAddMultipleClusterIds.

@Test
public void testCreateAppProfileAddMultipleClusterIds() {
    // Setup
    Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
    com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).setAppProfileId(APP_PROFILE_ID).setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1").addClusterIds("cluster-id-2"))).build();
    com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1").addClusterIds("cluster-id-2")).build();
    Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    // Execute
    AppProfile actualResult = adminClient.createAppProfile(CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("my description").setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1", "cluster-id-2")));
    // Verify
    assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Example 9 with Cluster

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

the class BigtableInstanceAdminClientTest method testCreateAppProfileAddSingleClusterId.

@Test
public void testCreateAppProfileAddSingleClusterId() {
    // Setup
    Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
    com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).setAppProfileId(APP_PROFILE_ID).setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1"))).build();
    com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1")).build();
    Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    // Execute
    AppProfile actualResult = adminClient.createAppProfile(CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("my description").setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1")));
    // Verify
    assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Example 10 with Cluster

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

the class BigtableInstanceAdminClientTest method testGetCluster.

@Test
public void testGetCluster() {
    // Setup
    Mockito.when(mockStub.getClusterCallable()).thenReturn(mockGetClusterCallable);
    com.google.bigtable.admin.v2.GetClusterRequest expectedRequest = com.google.bigtable.admin.v2.GetClusterRequest.newBuilder().setName(CLUSTER_NAME).build();
    com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).build();
    Mockito.when(mockGetClusterCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    // Execute
    Cluster actualResult = adminClient.getCluster(INSTANCE_ID, CLUSTER_ID);
    // Verify
    assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
Also used : 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