Search in sources :

Example 11 with Cluster

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));
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 12 with Cluster

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));
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Example 13 with Cluster

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));
}
Also used : Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 14 with Cluster

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()));
}
Also used : Snapshot(com.google.bigtable.admin.v2.Snapshot) ListSnapshotsRequest(com.google.bigtable.admin.v2.ListSnapshotsRequest) ListSnapshotsResponse(com.google.bigtable.admin.v2.ListSnapshotsResponse) ListSnapshotsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListSnapshotsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ClusterName(com.google.bigtable.admin.v2.ClusterName) Test(org.junit.Test)

Example 15 with Cluster

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;
}
Also used : BigtableClusterName(com.google.cloud.bigtable.grpc.BigtableClusterName) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster)

Aggregations

Test (org.junit.Test)21 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)17 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)4 PartialUpdateClusterRequest (com.google.bigtable.admin.v2.PartialUpdateClusterRequest)3 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)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 ByteString (com.google.protobuf.ByteString)3 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 ClusterName (com.google.bigtable.admin.v2.ClusterName)2 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)2 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)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 ImmutableList (com.google.common.collect.ImmutableList)2 AbstractMessage (com.google.protobuf.AbstractMessage)2