use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testCreateClusterAutoscaling.
@Test
public void testCreateClusterAutoscaling() {
Mockito.when(mockStub.createClusterOperationCallable()).thenReturn(mockCreateClusterCallable);
// Setup
com.google.bigtable.admin.v2.CreateClusterRequest expectedRequest = com.google.bigtable.admin.v2.CreateClusterRequest.newBuilder().setParent(INSTANCE_NAME).setClusterId(CLUSTER_ID).setCluster(com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setClusterConfig(clusterConfig).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)).build();
com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).build();
mockOperationResult(mockCreateClusterCallable, expectedRequest, expectedResponse);
// Execute
Cluster actualResult = adminClient.createCluster(CreateClusterRequest.of(INSTANCE_ID, CLUSTER_ID).setZone("us-east1-c").setScalingMode(ClusterAutoscalingConfig.of(INSTANCE_ID, CLUSTER_ID).setMinNodes(2).setMaxNodes(10).setCpuUtilizationTargetPercent(22)).setStorageType(StorageType.SSD));
// 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 testCreateAppProfileAddMultipleClusterIdsWithList.
@Test
public void testCreateAppProfileAddMultipleClusterIdsWithList() {
// Setup
Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).setAppProfileId(APP_PROFILE_ID).setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")))).build();
com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2"))).build();
Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
// Execute
AppProfile actualResult = adminClient.createAppProfile(CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("my description").setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1", "cluster-id-2")));
// Verify
assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testResizeCluster.
@Test
public void testResizeCluster() {
// Setup
Mockito.when(mockStub.updateClusterOperationCallable()).thenReturn(mockUpdateClusterCallable);
com.google.bigtable.admin.v2.Cluster expectedRequest = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setServeNodes(30).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(mockUpdateClusterCallable, expectedRequest, expectedResponse);
// Execute
Cluster actualResult = adminClient.resizeCluster(INSTANCE_ID, CLUSTER_ID, 30);
// 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 BaseBigtableTableAdminClientTest method listSnapshotsTest.
@Test
public void listSnapshotsTest() throws Exception {
Snapshot responsesElement = Snapshot.newBuilder().build();
ListSnapshotsResponse expectedResponse = ListSnapshotsResponse.newBuilder().setNextPageToken("").addAllSnapshots(Arrays.asList(responsesElement)).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
ListSnapshotsPagedResponse pagedListResponse = client.listSnapshots(parent);
List<Snapshot> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSnapshotsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSnapshotsRequest actualRequest = ((ListSnapshotsRequest) 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-hbase by googleapis.
the class BigtableAsyncAdmin method getBackupClusterName.
private synchronized BigtableClusterName getBackupClusterName() {
if (this.bigtableSnapshotClusterName == null) {
List<Cluster> clusters = asyncConnection.getBigtableApi().getAdminClient().listClusters(asyncConnection.getBigtableSettings().getInstanceId());
Preconditions.checkState(clusters.size() == 1, String.format("Project '%s' / Instance '%s' has %d clusters. There must be exactly 1 for this operation to work.", asyncConnection.getBigtableSettings().getProjectId(), asyncConnection.getBigtableSettings().getInstanceId(), clusters.size()));
String clusterName = NameUtil.formatClusterName(asyncConnection.getBigtableSettings().getProjectId(), asyncConnection.getBigtableSettings().getInstanceId(), clusters.get(0).getId());
bigtableSnapshotClusterName = new BigtableClusterName(clusterName);
}
return bigtableSnapshotClusterName;
}
Aggregations