Search in sources :

Example 11 with AppProfile

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

the class BigtableInstanceAdminClientIT method appProfileTest.

@Test
public void appProfileTest() {
    String testAppProfile = prefixGenerator.newPrefix();
    AppProfile newlyCreatedAppProfile = client.createAppProfile(CreateAppProfileRequest.of(instanceId, testAppProfile).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.of()).setDescription("This is to test app profile"));
    AppProfile updated = client.updateAppProfile(UpdateAppProfileRequest.of(newlyCreatedAppProfile).setDescription("This is to app profile operation"));
    AppProfile freshAppProfile = client.getAppProfile(instanceId, testAppProfile);
    assertThat(freshAppProfile.getDescription()).isEqualTo(updated.getDescription());
    assertThat(client.listAppProfiles(instanceId)).contains(freshAppProfile);
    Exception actualEx = null;
    try {
        client.deleteAppProfile(instanceId, testAppProfile, true);
    } catch (Exception ex) {
        actualEx = ex;
    }
    assertThat(actualEx).isNull();
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Example 12 with AppProfile

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

Example 13 with AppProfile

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

the class BigtableInstanceAdminClient method getAppProfileAsync.

/**
 * Asynchronously gets the app profile by ID.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * ApiFuture<AppProfile> appProfileFuture = client.getAppProfileAsync("my-instance", "my-app-profile");
 *
 * AppProfile appProfile = appProfileFuture.get();
 * }</pre>
 *
 * @see AppProfile
 */
@SuppressWarnings("WeakerAccess")
public ApiFuture<AppProfile> getAppProfileAsync(String instanceId, String appProfileId) {
    String name = NameUtil.formatAppProfileName(projectId, instanceId, appProfileId);
    GetAppProfileRequest request = GetAppProfileRequest.newBuilder().setName(name).build();
    return ApiFutures.transform(stub.getAppProfileCallable().futureCall(request), new ApiFunction<com.google.bigtable.admin.v2.AppProfile, AppProfile>() {

        @Override
        public AppProfile apply(com.google.bigtable.admin.v2.AppProfile proto) {
            return AppProfile.fromProto(proto);
        }
    }, MoreExecutors.directExecutor());
}
Also used : GetAppProfileRequest(com.google.bigtable.admin.v2.GetAppProfileRequest) AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile)

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