Search in sources :

Example 1 with CreateClusterRequest

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

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

Example 3 with CreateClusterRequest

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

the class BigtableInstanceAdminClientTest method testCreateClusterAutoscaling.

@Test
public void testCreateClusterAutoscaling() {
    Mockito.when(mockStub.createClusterOperationCallable()).thenReturn(mockCreateClusterCallable);
    // Setup
    com.google.bigtable.admin.v2.CreateClusterRequest expectedRequest = com.google.bigtable.admin.v2.CreateClusterRequest.newBuilder().setParent(INSTANCE_NAME).setClusterId(CLUSTER_ID).setCluster(com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setClusterConfig(clusterConfig).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)).build();
    com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).build();
    mockOperationResult(mockCreateClusterCallable, expectedRequest, expectedResponse);
    // Execute
    Cluster actualResult = adminClient.createCluster(CreateClusterRequest.of(INSTANCE_ID, CLUSTER_ID).setZone("us-east1-c").setScalingMode(ClusterAutoscalingConfig.of(INSTANCE_ID, CLUSTER_ID).setMinNodes(2).setMaxNodes(10).setCpuUtilizationTargetPercent(22)).setStorageType(StorageType.SSD));
    // Verify
    assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 4 with CreateClusterRequest

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

the class BigtableInstanceAdminClientTest method testCreateCluster.

@Test
public void testCreateCluster() {
    // Setup
    Mockito.when(mockStub.createClusterOperationCallable()).thenReturn(mockCreateClusterCallable);
    com.google.bigtable.admin.v2.CreateClusterRequest expectedRequest = com.google.bigtable.admin.v2.CreateClusterRequest.newBuilder().setParent(INSTANCE_NAME).setClusterId(CLUSTER_ID).setCluster(com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setServeNodes(3).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)).build();
    com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).build();
    mockOperationResult(mockCreateClusterCallable, expectedRequest, expectedResponse);
    // Execute
    Cluster actualResult = adminClient.createCluster(CreateClusterRequest.of(INSTANCE_ID, CLUSTER_ID).setZone("us-east1-c").setServeNodes(3).setStorageType(StorageType.SSD));
    // Verify
    assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 5 with CreateClusterRequest

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

the class BigtableInstanceAdminClientIT method createClusterWithManualScalingTest.

@Test
public void createClusterWithManualScalingTest() {
    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(StaticClusterSize.of(5));
        Cluster cluster = client.createCluster(createClusterRequest);
        assertThat(cluster.getId()).contains(clusterId);
        assertThat(cluster.getServeNodes()).isEqualTo(5);
        assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(0);
    } 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

Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)5 Test (org.junit.Test)5 CreateClusterRequest (com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest)3