use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class TableAdminExample method addFamilyWithMaxVersionsRule.
/**
* Demonstrates how to create a new instance of the VersionRule.
*/
public void addFamilyWithMaxVersionsRule() {
System.out.printf("%nCreating column family %s with max versions GC rule%n", COLUMN_FAMILY_2);
// [START bigtable_create_family_gc_max_versions]
// Creates a column family with GC policy : most recent N versions
// where 1 = most recent version
// Defines the GC policy to retain only the most recent 2 versions.
VersionRule versionRule = GCRULES.maxVersions(2);
// Creates column family with given GC rule.
try {
// ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is
// being used to add a family
ModifyColumnFamiliesRequest columnFamiliesRequest = ModifyColumnFamiliesRequest.of(tableId).addFamily(COLUMN_FAMILY_2, versionRule);
adminClient.modifyFamilies(columnFamiliesRequest);
System.out.println("Created column family: " + COLUMN_FAMILY_2);
} catch (AlreadyExistsException e) {
System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
}
// [END bigtable_create_family_gc_max_versions]
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class InstanceAdminExample method createProdInstance.
/**
* Demonstrates how to create a Production instance within a provided project.
*/
public void createProdInstance() {
// Checks if instance exists, creates instance if does not exists.
if (!adminClient.exists(instanceId)) {
System.out.println("Instance does not exist, creating a PRODUCTION instance");
// [START bigtable_create_prod_instance]
// Creates a Production Instance with the ID "ssd-instance",
// cluster id "ssd-cluster", 3 nodes and location "us-central1-f".
CreateInstanceRequest createInstanceRequest = CreateInstanceRequest.of(instanceId).addCluster(clusterId, "us-central1-f", 3, StorageType.SSD).setType(Instance.Type.PRODUCTION).addLabel("department", "accounting");
// Creates a production instance with the given request.
try {
Instance instance = adminClient.createInstance(createInstanceRequest);
System.out.printf("PRODUCTION type instance %s created successfully%n", instance.getId());
} catch (Exception e) {
System.err.println("Failed to create instance: " + e.getMessage());
throw e;
}
// [END bigtable_create_prod_instance]
}
}
use of com.google.cloud.bigtable.admin.v2.models.Instance 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);
}
}
use of com.google.cloud.bigtable.admin.v2.models.Instance 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);
}
}
use of com.google.cloud.bigtable.admin.v2.models.Instance 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);
}
Aggregations