Search in sources :

Example 1 with ClusterAutoscalingConfig

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

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

the class BigtableInstanceAdminClientTest method testCreateInstanceAutoscaling.

@Test
public void testCreateInstanceAutoscaling() {
    Mockito.when(mockStub.createInstanceOperationCallable()).thenReturn(mockCreateInstanceCallable);
    // Setup
    AutoscalingLimits autoscalingLimits = AutoscalingLimits.newBuilder().setMaxServeNodes(5).setMinServeNodes(1).build();
    AutoscalingTargets autoscalingTargets = AutoscalingTargets.newBuilder().setCpuUtilizationPercent(49).build();
    com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig clusterAutoscalingConfig = com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig.newBuilder().setAutoscalingLimits(autoscalingLimits).setAutoscalingTargets(autoscalingTargets).build();
    com.google.bigtable.admin.v2.CreateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.CreateInstanceRequest.newBuilder().setParent(PROJECT_NAME).setInstanceId(INSTANCE_ID).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT).setDisplayName(INSTANCE_ID)).putClusters("cluster1", com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().setClusterAutoscalingConfig(clusterAutoscalingConfig).build()).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD).build()).build();
    com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
    mockOperationResult(mockCreateInstanceCallable, expectedRequest, expectedResponse);
    // Execute
    ClusterAutoscalingConfig autoscalingConfig = ClusterAutoscalingConfig.of(INSTANCE_ID, "cluster1").setCpuUtilizationTargetPercent(49).setMaxNodes(5).setMinNodes(1);
    Instance actualResult = adminClient.createInstance(CreateInstanceRequest.of(INSTANCE_ID).setType(Instance.Type.DEVELOPMENT).addCluster("cluster1", "us-east1-c", autoscalingConfig, StorageType.SSD));
    // Verify
    assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Also used : AutoscalingTargets(com.google.bigtable.admin.v2.AutoscalingTargets) AutoscalingLimits(com.google.bigtable.admin.v2.AutoscalingLimits) Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) ClusterAutoscalingConfig(com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig) Test(org.junit.Test)

Aggregations

Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)2 ClusterAutoscalingConfig (com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)2 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)1 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)1 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)1 Test (org.junit.Test)1