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);
}
}
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);
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class BigtableBackupIT method crossInstanceRestoreTest.
@Test
public void crossInstanceRestoreTest() throws InterruptedException, IOException, ExecutionException, TimeoutException {
String backupId = prefixGenerator.newPrefix();
String restoredTableId = prefixGenerator.newPrefix();
// Create the backup
tableAdmin.createBackup(CreateBackupRequest.of(targetCluster, backupId).setSourceTableId(testTable.getId()).setExpireTime(Instant.now().plus(Duration.ofHours(6))));
Stopwatch stopwatch = Stopwatch.createStarted();
// Set up a new instance to test cross-instance restore. The backup will be restored here
String targetInstance = prefixGenerator.newPrefix();
instanceAdmin.createInstance(CreateInstanceRequest.of(targetInstance).addCluster(targetInstance, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD).setDisplayName("backups-dest-test-instance").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
try (BigtableTableAdminClient destTableAdmin = testEnvRule.env().getTableAdminClientForInstance(targetInstance)) {
// Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
// table operation.
Thread.sleep(Duration.ofMinutes(2).minus(Duration.ofMillis(stopwatch.elapsed(TimeUnit.MILLISECONDS))).toMillis());
try {
RestoreTableRequest req = RestoreTableRequest.of(testEnvRule.env().getInstanceId(), targetCluster, backupId).setTableId(restoredTableId);
RestoredTableResult result = destTableAdmin.restoreTable(req);
assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
assertWithMessage("Incorrect instance id").that(result.getTable().getInstanceId()).isEqualTo(targetInstance);
// The assertion might be missing if the test is running against a HDD cluster or an
// optimization is not necessary.
assertWithMessage("Empty OptimizeRestoredTable token").that(result.getOptimizeRestoredTableOperationToken()).isNotNull();
destTableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
destTableAdmin.getTable(restoredTableId);
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
instanceAdmin.deleteInstance(targetInstance);
}
}
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class BigtableTableAdminSettingsTest method testToString.
@Test
public void testToString() throws IOException {
BigtableTableAdminSettings defaultSettings = BigtableTableAdminSettings.newBuilder().setProjectId("our-project-85").setInstanceId("our-instance-06").build();
checkToString(defaultSettings);
BigtableTableAdminSettings.Builder builder = defaultSettings.toBuilder();
BigtableTableAdminStubSettings.Builder stubSettings = builder.stubSettings().setEndpoint("example.com:1234");
stubSettings.getBackupSettings().setRetrySettings(RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(812)).build());
BigtableTableAdminSettings settings = builder.build();
checkToString(settings);
assertThat(defaultSettings.toString()).doesNotContain("endpoint=example.com:1234");
assertThat(settings.toString()).contains("endpoint=example.com:1234");
assertThat(defaultSettings.toString()).doesNotContain("totalTimeout=PT13H32M");
assertThat(settings.toString()).contains("totalTimeout=PT13H32M");
int nonStaticFields = 0;
for (Field field : BigtableTableAdminStubSettings.class.getDeclaredFields()) {
if (!Modifier.isStatic(field.getModifiers())) {
nonStaticFields++;
}
}
// failure will signal about adding a new settings property
assertThat(SETTINGS_LIST.length).isEqualTo(nonStaticFields);
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testUpdateCluster.
@Test
public void testUpdateCluster() {
Mockito.when(mockStub.partialUpdateInstanceOperationCallable()).thenReturn(mockUpdateInstanceCallable);
// Setup
com.google.bigtable.admin.v2.PartialUpdateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.PartialUpdateInstanceRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("display_name")).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).setDisplayName("new display name")).build();
com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
mockOperationResult(mockUpdateInstanceCallable, expectedRequest, expectedResponse);
// Execute
Instance actualResult = adminClient.updateInstance(UpdateInstanceRequest.of(INSTANCE_ID).setDisplayName("new display name"));
// Verify
assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Aggregations