Search in sources :

Example 1 with Cluster

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;
}
Also used : HashMap(java.util.HashMap) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster)

Example 2 with Cluster

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]
    }
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) CreateInstanceRequest(com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest) NotFoundException(com.google.api.gax.rpc.NotFoundException) IOException(java.io.IOException) AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) PartialListInstancesException(com.google.cloud.bigtable.admin.v2.models.PartialListInstancesException)

Example 3 with Cluster

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);
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 4 with 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);
    }
}
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 5 with Cluster

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);
    }
}
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

Test (org.junit.Test)21 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)17 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)4 PartialUpdateClusterRequest (com.google.bigtable.admin.v2.PartialUpdateClusterRequest)3 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)3 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)3 CreateClusterRequest (com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest)3 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)3 ByteString (com.google.protobuf.ByteString)3 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 ClusterName (com.google.bigtable.admin.v2.ClusterName)2 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)2 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 RestoreTableRequest (com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest)2 RestoredTableResult (com.google.cloud.bigtable.admin.v2.models.RestoredTableResult)2 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)2 ImmutableList (com.google.common.collect.ImmutableList)2 AbstractMessage (com.google.protobuf.AbstractMessage)2