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));
}
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;
}
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());
}
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);
}
}
Aggregations