24
24
import com .google .bigtable .admin .v2 .DeleteAppProfileRequest ;
25
25
import com .google .bigtable .admin .v2 .GetAppProfileRequest ;
26
26
import com .google .bigtable .admin .v2 .ListAppProfilesRequest ;
27
+ import com .google .bigtable .admin .v2 .PartialUpdateClusterRequest ;
27
28
import com .google .cloud .Policy ;
28
29
import com .google .cloud .Policy .DefaultMarshaller ;
29
30
import com .google .cloud .bigtable .admin .v2 .BaseBigtableInstanceAdminClient .ListAppProfilesPage ;
30
31
import com .google .cloud .bigtable .admin .v2 .BaseBigtableInstanceAdminClient .ListAppProfilesPagedResponse ;
31
32
import com .google .cloud .bigtable .admin .v2 .internal .NameUtil ;
32
33
import com .google .cloud .bigtable .admin .v2 .models .AppProfile ;
33
34
import com .google .cloud .bigtable .admin .v2 .models .Cluster ;
35
+ import com .google .cloud .bigtable .admin .v2 .models .ClusterAutoscalingConfig ;
34
36
import com .google .cloud .bigtable .admin .v2 .models .CreateAppProfileRequest ;
35
37
import com .google .cloud .bigtable .admin .v2 .models .CreateClusterRequest ;
36
38
import com .google .cloud .bigtable .admin .v2 .models .CreateInstanceRequest ;
49
51
import com .google .iam .v1 .TestIamPermissionsRequest ;
50
52
import com .google .iam .v1 .TestIamPermissionsResponse ;
51
53
import com .google .protobuf .Empty ;
54
+ import com .google .protobuf .util .FieldMaskUtil ;
52
55
import java .io .IOException ;
53
56
import java .util .Arrays ;
54
57
import java .util .List ;
@@ -660,8 +663,10 @@ public List<Cluster> apply(com.google.bigtable.admin.v2.ListClustersResponse pro
660
663
}
661
664
662
665
/**
663
- * Modifies the cluster's node count. Please note that only clusters that belong to a production
664
- * instance can be resized.
666
+ * Modifies the cluster's node count for manual scaling. If autoscaling is already enabled, manual
667
+ * scaling will be silently ignored. If you wish to disable autoscaling and enable manual scaling,
668
+ * please use {@link BigtableInstanceAdminClient#disableClusterAutoscaling(String, String, int)}
669
+ * instead. Please note that only clusters that belong to a production instance can be resized.
665
670
*
666
671
* <p>Sample code:
667
672
*
@@ -676,8 +681,11 @@ public Cluster resizeCluster(String instanceId, String clusterId, int numServeNo
676
681
}
677
682
678
683
/**
679
- * Asynchronously modifies the cluster's node count. Please note that only clusters that belong to
680
- * a production instance can be resized.
684
+ * Asynchronously modifies the cluster's node count for manual scaling. If autoscaling is already
685
+ * enabled, manual scaling will be silently ignored. If you wish to disable autoscaling and enable
686
+ * manual scaling, please use {@link BigtableInstanceAdminClient#disableClusterAutoscaling(String,
687
+ * String, int)} instead. Please note that only clusters that belong to a production instance can
688
+ * be resized.
681
689
*
682
690
* <pre>{@code
683
691
* ApiFuture<Cluster> clusterFuture = client.resizeCluster("my-instance", "my-cluster", 30);
@@ -707,6 +715,109 @@ public Cluster apply(com.google.bigtable.admin.v2.Cluster proto) {
707
715
MoreExecutors .directExecutor ());
708
716
}
709
717
718
+ /**
719
+ * Modifies the cluster's autoscaling config. This will enable autoscaling and disable manual
720
+ * scaling if the cluster is manually scaled. Please note that only clusters that belong to a
721
+ * production instance can enable autoscaling.
722
+ *
723
+ * <p>Sample code:
724
+ *
725
+ * <pre>{@code
726
+ * ClusterAutoscalingConfig clusterAutoscalingConfig =
727
+ * ClusterAutoscalingConfig.of("my-instance", "my-cluster")
728
+ * .setMinNodes(1)
729
+ * .setMaxNodes(4)
730
+ * .setCpuUtilizationTargetPercent(40);
731
+ * Cluster cluster = client.updateClusterAutoscalingConfig(clusterAutoscalingConfig);
732
+ * }</pre>
733
+ */
734
+ public Cluster updateClusterAutoscalingConfig (
735
+ @ Nonnull ClusterAutoscalingConfig clusterAutoscalingConfig ) {
736
+ return ApiExceptions .callAndTranslateApiException (
737
+ updateClusterAutoscalingConfigAsync (clusterAutoscalingConfig ));
738
+ }
739
+
740
+ /**
741
+ * Asynchronously modifies the cluster's autoscaling config. This will enable autoscaling and
742
+ * disable manual scaling if the cluster is manually scaled. Please note that only clusters that
743
+ * belong to a production instance can enable autoscaling.
744
+ *
745
+ * <p>Sample code:
746
+ *
747
+ * <pre>{@code
748
+ * ClusterAutoscalingConfig clusterAutoscalingConfig =
749
+ * ClusterAutoscalingConfig.of(targetInstanceId, targetClusterId)
750
+ * .setMinNodes(1)
751
+ * .setMaxNodes(4)
752
+ * .setCpuUtilizationTargetPercent(40);
753
+ *
754
+ * ApiFuture<Cluster> clusterApiFuture = client.updateClusterAutoscalingConfigAsync(clusterAutoscalingConfig);
755
+ * Cluster cluster = clusterApiFuture.get();
756
+ * }</pre>
757
+ */
758
+ public ApiFuture <Cluster > updateClusterAutoscalingConfigAsync (
759
+ @ Nonnull ClusterAutoscalingConfig clusterAutoscalingConfig ) {
760
+ PartialUpdateClusterRequest proto = clusterAutoscalingConfig .toProto (projectId );
761
+
762
+ return ApiFutures .transform (
763
+ stub .partialUpdateClusterOperationCallable ().futureCall (proto ),
764
+ Cluster ::fromProto ,
765
+ MoreExecutors .directExecutor ());
766
+ }
767
+
768
+ /**
769
+ * Disables autoscaling and enables manual scaling by setting a static node count for the cluster.
770
+ * Please note that only clusters that belong to a production instance can be resized.
771
+ *
772
+ * <p>Sample code:
773
+ *
774
+ * <pre>{@code
775
+ * Cluster cluster = client.disableClusterAutoscaling("my-instance", "my-cluster", 3);
776
+ * }</pre>
777
+ */
778
+ public Cluster disableClusterAutoscaling (String instanceId , String clusterId , int staticSize ) {
779
+ return ApiExceptions .callAndTranslateApiException (
780
+ disableClusterAutoscalingAsync (instanceId , clusterId , staticSize ));
781
+ }
782
+
783
+ /**
784
+ * Asynchronously disables autoscaling and enables manual scaling by setting a static node count
785
+ * for the cluster. Please note that only clusters that belong to a production instance can be
786
+ * resized.
787
+ *
788
+ * <p>Sample code:
789
+ *
790
+ * <pre>{@code
791
+ * ApiFuture<Cluster> clusterApiFuture = client.disableClusterAutoscalingAsync("my-instance", "my-cluster", 3);
792
+ * Cluster cluster = clusterApiFuture.get();
793
+ * }</pre>
794
+ */
795
+ public ApiFuture <Cluster > disableClusterAutoscalingAsync (
796
+ String instanceId , String clusterId , int staticSize ) {
797
+ String name = NameUtil .formatClusterName (projectId , instanceId , clusterId );
798
+
799
+ com .google .bigtable .admin .v2 .Cluster request =
800
+ com .google .bigtable .admin .v2 .Cluster .newBuilder ()
801
+ .setName (name )
802
+ .setServeNodes (staticSize )
803
+ .setClusterConfig (
804
+ com .google .bigtable .admin .v2 .Cluster .ClusterConfig .getDefaultInstance ())
805
+ .build ();
806
+
807
+ PartialUpdateClusterRequest partialUpdateClusterRequest =
808
+ PartialUpdateClusterRequest .newBuilder ()
809
+ .setUpdateMask (
810
+ FieldMaskUtil .fromStringList (
811
+ com .google .bigtable .admin .v2 .Cluster .class ,
812
+ Lists .newArrayList ("cluster_config.cluster_autoscaling_config" , "serve_nodes" )))
813
+ .setCluster (request )
814
+ .build ();
815
+ return ApiFutures .transform (
816
+ stub .partialUpdateClusterOperationCallable ().futureCall (partialUpdateClusterRequest ),
817
+ Cluster ::fromProto ,
818
+ MoreExecutors .directExecutor ());
819
+ }
820
+
710
821
/**
711
822
* Deletes the specified cluster. Please note that an instance must have at least 1 cluster. To
712
823
* remove the last cluster, please use {@link BigtableInstanceAdminClient#deleteInstance(String)}.
0 commit comments