Search in sources :

Example 36 with Cluster

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);
        }
    }
}
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 37 with Cluster

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

Example 38 with Cluster

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();
}
Also used : BigtableInstanceAdminClient(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) CreateInstanceRequest(com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) BeforeClass(org.junit.BeforeClass)

Example 39 with Cluster

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

Example 40 with Cluster

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

Aggregations

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