Search in sources :

Example 6 with Instance

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]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 7 with Instance

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]
    }
}
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 8 with 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);
    }
}
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 9 with Instance

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);
    }
}
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 10 with Instance

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

Aggregations

Test (org.junit.Test)18 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)14 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)9 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 List (java.util.List)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 CreateClusterRequest (com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest)3 CreateInstanceRequest (com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 ClusterName (com.google.bigtable.admin.v2.ClusterName)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2 ListAppProfilesRequest (com.google.bigtable.admin.v2.ListAppProfilesRequest)2 ListTablesRequest (com.google.bigtable.admin.v2.ListTablesRequest)2 ListAppProfilesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse)2