Search in sources :

Example 1 with PartialUpdateClusterRequest

use of com.google.bigtable.admin.v2.PartialUpdateClusterRequest in project java-bigtable by googleapis.

the class ClusterAutoscalingConfigTest method testToProto.

@Test
public void testToProto() {
    ClusterAutoscalingConfig request = ClusterAutoscalingConfig.of(INSTANCE_ID, CLUSTER_ID).setMaxNodes(10).setMinNodes(3).setCpuUtilizationTargetPercent(30);
    PartialUpdateClusterRequest partialUpdateClusterRequestProto = request.toProto(PROJECT_ID);
    AutoscalingTargets autoscalingTargets = AutoscalingTargets.newBuilder().setCpuUtilizationPercent(30).build();
    AutoscalingLimits autoscalingLimits = AutoscalingLimits.newBuilder().setMinServeNodes(3).setMaxServeNodes(10).build();
    Cluster.ClusterAutoscalingConfig clusterAutoscalingConfig = Cluster.ClusterAutoscalingConfig.newBuilder().setAutoscalingTargets(autoscalingTargets).setAutoscalingLimits(autoscalingLimits).build();
    Cluster.ClusterConfig clusterConfig = Cluster.ClusterConfig.newBuilder().setClusterAutoscalingConfig(clusterAutoscalingConfig).build();
    Cluster cluster = Cluster.newBuilder().setName(NameUtil.formatClusterName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID)).setClusterConfig(clusterConfig).build();
    PartialUpdateClusterRequest requestProto = PartialUpdateClusterRequest.newBuilder().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")).setCluster(cluster).build();
    assertThat(partialUpdateClusterRequestProto).isEqualTo(requestProto);
}
Also used : PartialUpdateClusterRequest(com.google.bigtable.admin.v2.PartialUpdateClusterRequest) AutoscalingTargets(com.google.bigtable.admin.v2.AutoscalingTargets) AutoscalingLimits(com.google.bigtable.admin.v2.AutoscalingLimits) Cluster(com.google.bigtable.admin.v2.Cluster) Test(org.junit.Test)

Example 2 with PartialUpdateClusterRequest

use of com.google.bigtable.admin.v2.PartialUpdateClusterRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method partialUpdateClusterTest.

@Test
public void partialUpdateClusterTest() throws Exception {
    Cluster expectedResponse = Cluster.newBuilder().setName(ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]").toString()).setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setServeNodes(-1288838783).setDefaultStorageType(StorageType.forNumber(0)).setEncryptionConfig(Cluster.EncryptionConfig.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("partialUpdateClusterTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableInstanceAdmin.addResponse(resultOperation);
    Cluster cluster = Cluster.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    Cluster actualResponse = client.partialUpdateClusterAsync(cluster, updateMask).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    PartialUpdateClusterRequest actualRequest = ((PartialUpdateClusterRequest) actualRequests.get(0));
    Assert.assertEquals(cluster, actualRequest.getCluster());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : PartialUpdateClusterRequest(com.google.bigtable.admin.v2.PartialUpdateClusterRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Cluster(com.google.bigtable.admin.v2.Cluster) Operation(com.google.longrunning.Operation) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 3 with PartialUpdateClusterRequest

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

Example 4 with PartialUpdateClusterRequest

use of com.google.bigtable.admin.v2.PartialUpdateClusterRequest in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testDisableAutoscaling.

@Test
public void testDisableAutoscaling() {
    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(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().build()).setServeNodes(30).build();
    PartialUpdateClusterRequest expectedRequest = PartialUpdateClusterRequest.newBuilder().setCluster(cluster).setUpdateMask(FieldMask.newBuilder().addPaths("cluster_config.cluster_autoscaling_config").addPaths("serve_nodes").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")).setServeNodes(30).build();
    mockOperationResult(mockPartialUpdateClusterCallable, expectedRequest, expectedResponse);
    // Execute
    Cluster actualResult = adminClient.disableClusterAutoscaling(INSTANCE_ID, CLUSTER_ID, 30);
    // 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)

Example 5 with PartialUpdateClusterRequest

use of com.google.bigtable.admin.v2.PartialUpdateClusterRequest in project java-bigtable by googleapis.

the class BigtableInstanceAdminClient method disableClusterAutoscalingAsync.

/**
 * Asynchronously disables autoscaling and enables manual scaling by setting a static node count
 * for the cluster. Please note that only clusters that belong to a production instance can be
 * resized.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<Cluster> clusterApiFuture = client.disableClusterAutoscalingAsync("my-instance", "my-cluster", 3);
 * Cluster cluster = clusterApiFuture.get();
 * }</pre>
 */
public ApiFuture<Cluster> disableClusterAutoscalingAsync(String instanceId, String clusterId, int staticSize) {
    String name = NameUtil.formatClusterName(projectId, instanceId, clusterId);
    com.google.bigtable.admin.v2.Cluster request = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(name).setServeNodes(staticSize).setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.getDefaultInstance()).build();
    PartialUpdateClusterRequest partialUpdateClusterRequest = PartialUpdateClusterRequest.newBuilder().setUpdateMask(FieldMaskUtil.fromStringList(com.google.bigtable.admin.v2.Cluster.class, Lists.newArrayList("cluster_config.cluster_autoscaling_config", "serve_nodes"))).setCluster(request).build();
    return ApiFutures.transform(stub.partialUpdateClusterOperationCallable().futureCall(partialUpdateClusterRequest), Cluster::fromProto, MoreExecutors.directExecutor());
}
Also used : PartialUpdateClusterRequest(com.google.bigtable.admin.v2.PartialUpdateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster)

Aggregations

PartialUpdateClusterRequest (com.google.bigtable.admin.v2.PartialUpdateClusterRequest)5 Test (org.junit.Test)4 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)3 Cluster (com.google.bigtable.admin.v2.Cluster)2 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)1 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)1 Operation (com.google.longrunning.Operation)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 FieldMask (com.google.protobuf.FieldMask)1