Search in sources :

Example 1 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BigtableInstanceAdminClient method listAppProfilesAsync.

/**
 * Asynchronously lists all app profiles of the specified instance.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<List<AppProfile>> appProfilesFuture = client.listAppProfilesAsync("my-instance");
 *
 * List<AppProfile> appProfiles = appProfileFuture.get();
 * }</pre>
 *
 * @see AppProfile
 */
@SuppressWarnings("WeakerAccess")
public ApiFuture<List<AppProfile>> listAppProfilesAsync(String instanceId) {
    String instanceName = NameUtil.formatInstanceName(projectId, instanceId);
    ListAppProfilesRequest request = ListAppProfilesRequest.newBuilder().setParent(instanceName).build();
    // TODO(igorbernstein2): try to upstream pagination spooling or figure out a way to expose the
    // paginated responses while maintaining the wrapper facade.
    // Fetches the first page.
    ApiFuture<ListAppProfilesPage> firstPageFuture = ApiFutures.transform(stub.listAppProfilesPagedCallable().futureCall(request), new ApiFunction<ListAppProfilesPagedResponse, ListAppProfilesPage>() {

        @Override
        public ListAppProfilesPage apply(ListAppProfilesPagedResponse response) {
            return response.getPage();
        }
    }, MoreExecutors.directExecutor());
    // Fetches the rest of the pages by chaining the futures.
    ApiFuture<List<com.google.bigtable.admin.v2.AppProfile>> allProtos = ApiFutures.transformAsync(firstPageFuture, new ApiAsyncFunction<ListAppProfilesPage, List<com.google.bigtable.admin.v2.AppProfile>>() {

        List<com.google.bigtable.admin.v2.AppProfile> responseAccumulator = Lists.newArrayList();

        @Override
        public ApiFuture<List<com.google.bigtable.admin.v2.AppProfile>> apply(ListAppProfilesPage page) {
            // Add all entries from the page
            responseAccumulator.addAll(Lists.newArrayList(page.getValues()));
            // If this is the last page, just return the accumulated responses.
            if (!page.hasNextPage()) {
                return ApiFutures.immediateFuture(responseAccumulator);
            }
            // Otherwise fetch the next page.
            return ApiFutures.transformAsync(page.getNextPageAsync(), this, MoreExecutors.directExecutor());
        }
    }, MoreExecutors.directExecutor());
    // Wraps all of the accumulated protos.
    return ApiFutures.transform(allProtos, new ApiFunction<List<com.google.bigtable.admin.v2.AppProfile>, List<AppProfile>>() {

        @Override
        public List<AppProfile> apply(List<com.google.bigtable.admin.v2.AppProfile> input) {
            List<AppProfile> results = Lists.newArrayListWithCapacity(input.size());
            for (com.google.bigtable.admin.v2.AppProfile appProfile : input) {
                results.add(AppProfile.fromProto(appProfile));
            }
            return results;
        }
    }, MoreExecutors.directExecutor());
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) ListAppProfilesRequest(com.google.bigtable.admin.v2.ListAppProfilesRequest) ApiFuture(com.google.api.core.ApiFuture) ListAppProfilesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPage) ListAppProfilesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testCreateAppProfileAddMultipleClusterIds.

@Test
public void testCreateAppProfileAddMultipleClusterIds() {
    // 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().addClusterIds("cluster-id-1").addClusterIds("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().addClusterIds("cluster-id-1").addClusterIds("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 3 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testCreateAppProfileAddSingleClusterId.

@Test
public void testCreateAppProfileAddSingleClusterId() {
    // 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().addClusterIds("cluster-id-1"))).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().addClusterIds("cluster-id-1")).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")));
    // Verify
    assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Example 4 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testCreateAppProfile.

@Test
public void testCreateAppProfile() {
    // 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.getDefaultInstance())).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.getDefaultInstance()).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()));
    // Verify
    assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Example 5 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile 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)

Aggregations

AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)11 Test (org.junit.Test)11 ListAppProfilesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse)4 ListAppProfilesRequest (com.google.bigtable.admin.v2.ListAppProfilesRequest)3 AppProfile (com.google.bigtable.admin.v2.AppProfile)2 ListAppProfilesResponse (com.google.bigtable.admin.v2.ListAppProfilesResponse)2 ListAppProfilesPage (com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPage)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ApiFuture (com.google.api.core.ApiFuture)1 GetAppProfileRequest (com.google.bigtable.admin.v2.GetAppProfileRequest)1 InstanceName (com.google.bigtable.admin.v2.InstanceName)1 CreateAppProfileRequest (com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 List (java.util.List)1