use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientIT method appProfileTestMultiClusterWithIds.
@Test
public void appProfileTestMultiClusterWithIds() {
String newInstanceId = prefixGenerator.newPrefix();
String newClusterId = newInstanceId + "-c1";
String newClusterId2 = newInstanceId + "-c2";
client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD).addCluster(newClusterId2, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD).setDisplayName("Multi-Cluster-Instance-Test").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
try {
assertThat(client.exists(newInstanceId)).isTrue();
String testAppProfile = "test-app-profile";
CreateAppProfileRequest request = CreateAppProfileRequest.of(newInstanceId, testAppProfile).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.of(newClusterId)).setDescription("This is to test app profile");
AppProfile newlyCreatedAppProfile = client.createAppProfile(request);
AppProfile updated = client.updateAppProfile(UpdateAppProfileRequest.of(newlyCreatedAppProfile).setDescription("new description"));
AppProfile freshAppProfile = client.getAppProfile(newInstanceId, testAppProfile);
assertThat(freshAppProfile.getDescription()).isEqualTo(updated.getDescription());
AppProfile.MultiClusterRoutingPolicy freshAppProfilePolicy = (AppProfile.MultiClusterRoutingPolicy) freshAppProfile.getPolicy();
AppProfile.MultiClusterRoutingPolicy updatedAppProfilePolicy = (AppProfile.MultiClusterRoutingPolicy) updated.getPolicy();
assertThat(freshAppProfilePolicy.getClusterIds()).containsExactly(newClusterId);
assertThat(freshAppProfilePolicy.getClusterIds()).isEqualTo(updatedAppProfilePolicy.getClusterIds());
assertThat(freshAppProfilePolicy).isEqualTo(updatedAppProfilePolicy);
assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile);
// update again with routing policy
AppProfile updated2 = client.updateAppProfile(UpdateAppProfileRequest.of(updated).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.of(newClusterId2)));
AppProfile freshAppProfile2 = client.getAppProfile(newInstanceId, testAppProfile);
assertThat(freshAppProfile2.getDescription()).isEqualTo(updated2.getDescription());
AppProfile.MultiClusterRoutingPolicy freshAppProfilePolicy2 = (AppProfile.MultiClusterRoutingPolicy) freshAppProfile2.getPolicy();
AppProfile.MultiClusterRoutingPolicy updatedAppProfilePolicy2 = (AppProfile.MultiClusterRoutingPolicy) updated2.getPolicy();
assertThat(freshAppProfilePolicy2.getClusterIds()).containsExactly(newClusterId2);
assertThat(freshAppProfilePolicy2.getClusterIds()).isEqualTo(updatedAppProfilePolicy2.getClusterIds());
assertThat(freshAppProfilePolicy2).isEqualTo(updatedAppProfilePolicy2);
assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile2);
// update to single routing policy
AppProfile updated3 = client.updateAppProfile(UpdateAppProfileRequest.of(updated).setRoutingPolicy(AppProfile.SingleClusterRoutingPolicy.of(newClusterId)));
AppProfile freshAppProfile3 = client.getAppProfile(newInstanceId, testAppProfile);
assertThat(freshAppProfile3.getDescription()).isEqualTo(updated3.getDescription());
AppProfile.SingleClusterRoutingPolicy freshAppProfilePolicy3 = (AppProfile.SingleClusterRoutingPolicy) freshAppProfile3.getPolicy();
AppProfile.SingleClusterRoutingPolicy updatedAppProfilePolicy3 = (AppProfile.SingleClusterRoutingPolicy) updated3.getPolicy();
assertThat(freshAppProfilePolicy3.getClusterId()).isEqualTo(newClusterId);
assertThat(freshAppProfilePolicy3.getClusterId()).isEqualTo(updatedAppProfilePolicy3.getClusterId());
assertThat(freshAppProfilePolicy3).isEqualTo(updatedAppProfilePolicy3);
assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile3);
} 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 basicInstanceOperationTest.
/* As cluster creation is very expensive operation, so reusing existing clusters to verify rest
of the operation.*/
@Test
public void basicInstanceOperationTest() {
assertThat(client.exists(instanceId)).isTrue();
client.updateInstance(UpdateInstanceRequest.of(instanceId).setDisplayName("Updated-Instance-Name"));
Instance instance = client.getInstance(instanceId);
assertThat(instance.getDisplayName()).isEqualTo("Updated-Instance-Name");
assertThat(client.listInstances()).contains(instance);
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project grpc-gcp-java by GoogleCloudPlatform.
the class BigtableIntegrationTest method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException {
Assume.assumeTrue("Need to provide GCP_PROJECT_ID for BigtableIntegrationTest", GCP_PROJECT_ID != null);
BigtableInstanceAdminClient instanceAdminClient = BigtableInstanceAdminClient.create(GCP_PROJECT_ID);
CreateInstanceRequest createInstanceRequest = CreateInstanceRequest.of(INSTANCE_ID).addCluster("grpc-gcp-test-cluster", "us-central1-c", 3, StorageType.SSD);
instanceAdminClient.createInstance(createInstanceRequest);
BigtableTableAdminClient tableAdminClient = BigtableTableAdminClient.create(GCP_PROJECT_ID, INSTANCE_ID);
CreateTableRequest createTableRequest = CreateTableRequest.of(TABLE_ID).addFamily(FAMILY_NAME);
tableAdminClient.createTable(createTableRequest);
tableAdminClient.close();
instanceAdminClient.close();
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testPartialUpdateCluster.
@Test
public void testPartialUpdateCluster() {
Mockito.when(mockStub.partialUpdateClusterOperationCallable()).thenReturn(mockPartialUpdateClusterCallable);
// Setup
com.google.bigtable.admin.v2.Cluster cluster = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setClusterConfig(clusterConfig).build();
PartialUpdateClusterRequest expectedRequest = PartialUpdateClusterRequest.newBuilder().setCluster(cluster).setUpdateMask(FieldMask.newBuilder().addPaths("cluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodes").addPaths("cluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodes").addPaths("cluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percent").build()).build();
com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setLocation(NameUtil.formatLocationName(PROJECT_ID, "us-east1-c")).setClusterConfig(clusterConfig).build();
mockOperationResult(mockPartialUpdateClusterCallable, expectedRequest, expectedResponse);
// Execute
Cluster actualResult = adminClient.updateClusterAutoscalingConfig(ClusterAutoscalingConfig.of(INSTANCE_ID, CLUSTER_ID).setMaxNodes(10).setMinNodes(2).setCpuUtilizationTargetPercent(22));
// Verify
assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testDisableAutoscaling.
@Test
public void testDisableAutoscaling() {
Mockito.when(mockStub.partialUpdateClusterOperationCallable()).thenReturn(mockPartialUpdateClusterCallable);
// Setup
com.google.bigtable.admin.v2.Cluster cluster = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().build()).setServeNodes(30).build();
PartialUpdateClusterRequest expectedRequest = PartialUpdateClusterRequest.newBuilder().setCluster(cluster).setUpdateMask(FieldMask.newBuilder().addPaths("cluster_config.cluster_autoscaling_config").addPaths("serve_nodes").build()).build();
com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setLocation(NameUtil.formatLocationName(PROJECT_ID, "us-east1-c")).setServeNodes(30).build();
mockOperationResult(mockPartialUpdateClusterCallable, expectedRequest, expectedResponse);
// Execute
Cluster actualResult = adminClient.disableClusterAutoscaling(INSTANCE_ID, CLUSTER_ID, 30);
// Verify
assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
Aggregations