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