Search in sources :

Example 46 with Instance

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

the class BigtableInstanceAdminClientTest method testCreateInstanceAutoscaling.

@Test
public void testCreateInstanceAutoscaling() {
    Mockito.when(mockStub.createInstanceOperationCallable()).thenReturn(mockCreateInstanceCallable);
    // Setup
    AutoscalingLimits autoscalingLimits = AutoscalingLimits.newBuilder().setMaxServeNodes(5).setMinServeNodes(1).build();
    AutoscalingTargets autoscalingTargets = AutoscalingTargets.newBuilder().setCpuUtilizationPercent(49).build();
    com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig clusterAutoscalingConfig = com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig.newBuilder().setAutoscalingLimits(autoscalingLimits).setAutoscalingTargets(autoscalingTargets).build();
    com.google.bigtable.admin.v2.CreateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.CreateInstanceRequest.newBuilder().setParent(PROJECT_NAME).setInstanceId(INSTANCE_ID).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT).setDisplayName(INSTANCE_ID)).putClusters("cluster1", com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().setClusterAutoscalingConfig(clusterAutoscalingConfig).build()).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD).build()).build();
    com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
    mockOperationResult(mockCreateInstanceCallable, expectedRequest, expectedResponse);
    // Execute
    ClusterAutoscalingConfig autoscalingConfig = ClusterAutoscalingConfig.of(INSTANCE_ID, "cluster1").setCpuUtilizationTargetPercent(49).setMaxNodes(5).setMinNodes(1);
    Instance actualResult = adminClient.createInstance(CreateInstanceRequest.of(INSTANCE_ID).setType(Instance.Type.DEVELOPMENT).addCluster("cluster1", "us-east1-c", autoscalingConfig, StorageType.SSD));
    // Verify
    assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Also used : AutoscalingTargets(com.google.bigtable.admin.v2.AutoscalingTargets) AutoscalingLimits(com.google.bigtable.admin.v2.AutoscalingLimits) Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) ClusterAutoscalingConfig(com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig) Test(org.junit.Test)

Example 47 with Instance

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

Example 48 with Instance

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

the class QueryExternalBigtableTempIT method tearDown.

@After
public void tearDown() throws IOException {
    // Clean up
    try (BigtableTableAdminClient client = BigtableTableAdminClient.create(PROJECT, INSTANCE)) {
        client.deleteTable(TABLE_ID);
    }
    // restores print statements in the original method
    System.out.flush();
    System.setOut(originalPrintStream);
    log.log(Level.INFO, bout.toString());
}
Also used : BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) After(org.junit.After)

Example 49 with Instance

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

the class QueryExternalBigtableTempIT method setUp.

@Before
public void setUp() throws IOException {
    bout = new ByteArrayOutputStream();
    out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    // create a temporary bigtable table.
    try (BigtableTableAdminClient client = BigtableTableAdminClient.create(PROJECT, INSTANCE)) {
        CreateTableRequest createTableRequest = CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME);
        client.createTable(createTableRequest);
    }
    // inserting temporary rows.
    try (BigtableDataClient client = BigtableDataClient.create(PROJECT, INSTANCE)) {
        BulkMutation bulkMutation = BulkMutation.create(TABLE_ID).add("phone#4c410523#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_CELL.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_WIFI.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190405.003")).add("phone#4c410523#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_CELL.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_WIFI.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190405.004")).add("phone#4c410523#20190505", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_CELL.getBytes()), TIMESTAMP, 0).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_WIFI.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190406.000")).add("phone#5c10102#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_CELL.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_WIFI.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190401.002")).add("phone#5c10102#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_CELL.getBytes()), TIMESTAMP, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(CONNECTED_WIFI.getBytes()), TIMESTAMP, 0).setCell(COLUMN_FAMILY_NAME, OS_BUILD, TIMESTAMP, "PQ2A.190406.000"));
        client.bulkMutateRows(bulkMutation);
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)24 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)19 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)10 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)7 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ClusterName (com.google.bigtable.admin.v2.ClusterName)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 ClusterAutoscalingConfig (com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)3 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)2 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)2 GetInstanceRequest (com.google.bigtable.admin.v2.GetInstanceRequest)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2