Search in sources :

Example 31 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method listBackupsTest.

@Test
public void listBackupsTest() throws Exception {
    Backup responsesElement = Backup.newBuilder().build();
    ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
    List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) ClusterName(com.google.bigtable.admin.v2.ClusterName) ListBackupsResponse(com.google.bigtable.admin.v2.ListBackupsResponse) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Example 32 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class BigtableBackupIT method restoreTableTest.

@Test
public void restoreTableTest() throws InterruptedException, ExecutionException {
    String backupId = prefixGenerator.newPrefix();
    String restoredTableId = prefixGenerator.newPrefix();
    tableAdmin.createBackup(createBackupRequest(backupId));
    // Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
    // table operation.
    Thread.sleep(120 * 1000);
    try {
        RestoreTableRequest req = RestoreTableRequest.of(targetCluster, backupId).setTableId(restoredTableId);
        RestoredTableResult result = tableAdmin.restoreTable(req);
        assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
        if (result.getOptimizeRestoredTableOperationToken() != null) {
            // The assertion might be missing if the test is running against a HDD cluster or an
            // optimization is not necessary.
            tableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
            Table restoredTable = tableAdmin.getTable(restoredTableId);
            assertWithMessage("Incorrect restored table id").that(restoredTable.getId()).isEqualTo(restoredTableId);
        }
    } finally {
        tableAdmin.deleteBackup(targetCluster, backupId);
        tableAdmin.deleteTable(restoredTableId);
    }
}
Also used : RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) Table(com.google.cloud.bigtable.admin.v2.models.Table) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 33 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class BigtableCmekIT method instanceAndClusterTest.

@Test
public void instanceAndClusterTest() {
    // Keys are specified per-cluster with each cluster requesting the same key and the cluster's
    // zone must be within the region of the key
    Cluster cluster = instanceAdmin.getCluster(instanceId, clusterId1);
    assertThat(cluster.getKmsKeyName()).isEqualTo(kmsKeyName);
    LOGGER.info("Creating cluster in zone: " + zones.get(1));
    instanceAdmin.createCluster(CreateClusterRequest.of(instanceId, clusterId2).setZone(zones.get(1)).setServeNodes(1).setStorageType(StorageType.SSD).setKmsKeyName(kmsKeyName));
    Cluster secondCluster = instanceAdmin.getCluster(instanceId, clusterId2);
    assertThat(secondCluster.getKmsKeyName()).isEqualTo(kmsKeyName);
    LOGGER.info("Trying to create cluster in zone: " + otherZone);
    try {
        instanceAdmin.createCluster(CreateClusterRequest.of(instanceId, clusterId3).setZone(otherZone).setServeNodes(1).setStorageType(StorageType.SSD).setKmsKeyName(kmsKeyName));
        Assert.fail("should have thrown an error");
    } catch (com.google.api.gax.rpc.FailedPreconditionException e) {
        assertThat(e.getMessage()).contains("FAILED_PRECONDITION: Error in field 'cluster' : " + "Error in field 'encryption_config.kms_key_name' : CMEK key " + kmsKeyName + " cannot be used to protect a cluster in zone " + NameUtil.formatLocationName(testEnvRule.env().getProjectId(), otherZone));
    }
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 34 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientIT method instanceAndClusterCreationDeletionTest.

/**
 * To optimize test run time, instance & cluster creation is tested at the same time
 */
@Test
public void instanceAndClusterCreationDeletionTest() {
    String newInstanceId = prefixGenerator.newPrefix();
    String newClusterId = newInstanceId;
    client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 3, StorageType.SSD).setDisplayName("Fresh-Instance-Name").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
    try {
        assertThat(client.exists(newInstanceId)).isTrue();
        client.updateInstance(UpdateInstanceRequest.of(newInstanceId).setDisplayName("Test-Instance-Name"));
        Instance instance = client.getInstance(newInstanceId);
        assertThat(instance.getDisplayName()).isEqualTo("Test-Instance-Name");
        assertThat(client.listInstances()).contains(instance);
        clusterCreationDeletionTestHelper(newInstanceId);
        basicClusterOperationTestHelper(newInstanceId, newClusterId);
        client.deleteInstance(newInstanceId);
        assertThat(client.exists(newInstanceId)).isFalse();
    } finally {
        if (client.exists(newInstanceId)) {
            client.deleteInstance(newInstanceId);
        }
    }
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Test(org.junit.Test)

Example 35 with Cluster

use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientIT method createClusterWithManualScalingTest.

@Test
public void createClusterWithManualScalingTest() {
    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(StaticClusterSize.of(5));
        Cluster cluster = client.createCluster(createClusterRequest);
        assertThat(cluster.getId()).contains(clusterId);
        assertThat(cluster.getServeNodes()).isEqualTo(5);
        assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(0);
    } 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)31 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)23 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)7 PartialUpdateClusterRequest (com.google.bigtable.admin.v2.PartialUpdateClusterRequest)5 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)4 ClusterName (com.google.bigtable.admin.v2.ClusterName)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)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 AbstractMessage (com.google.protobuf.AbstractMessage)3 ByteString (com.google.protobuf.ByteString)3 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)2 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 CreateInstanceRequest (com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest)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