use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class AbstractTestEnv method getPrimaryClusterId.
/**
* Try to guess the primary cluster id
*/
public synchronized String getPrimaryClusterId() {
if (primaryClusterId != null) {
return primaryClusterId;
}
List<Cluster> clusters = getInstanceAdminClient().listClusters(getInstanceId());
Map<String, Cluster> byId = new HashMap<>();
for (Cluster cluster : clusters) {
byId.put(cluster.getId(), cluster);
}
Cluster cluster = null;
cluster = byId.get(getInstanceId());
if (cluster == null) {
// gcloud-devel setup
cluster = byId.get(getInstanceId() + "-cluster");
}
if (cluster == null) {
cluster = byId.get(getInstanceId() + "-c0");
}
primaryClusterId = Preconditions.checkNotNull(cluster, "Failed to guess the primary cluster for projects/%s/instances/%s", getProjectId(), getInstanceId()).getId();
return primaryClusterId;
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster 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.Cluster in project java-bigtable by googleapis.
the class InstanceAdminExampleTest method testAddAndDeleteCluster.
@Test(expected = NotFoundException.class)
public void testAddAndDeleteCluster() {
// Adds a cluster.
instanceAdmin.addCluster();
Cluster cluster = adminClient.getCluster(instanceId, CLUSTER);
assertNotNull(cluster);
// Deletes a cluster.
instanceAdmin.deleteCluster();
adminClient.getCluster(instanceId, CLUSTER);
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster 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.Cluster 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);
}
}
Aggregations