use of com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest in project java-docs-samples by GoogleCloudPlatform.
the class CreateBackupTestIT method setUp.
@BeforeClass
public static void setUp() throws IOException {
projectId = requireEnv(PROJECT_ENV);
try (BigtableInstanceAdminClient instanceAdmin = BigtableInstanceAdminClient.create(projectId)) {
CreateInstanceRequest request = CreateInstanceRequest.of(INSTANCE_ID).addCluster(CLUSTER_ID, ZONE_ID, 1, StorageType.SSD);
Instance instance = instanceAdmin.createInstance(request);
} catch (IOException e) {
System.out.println("Error during BeforeClass while creating instance: \n" + e.toString());
throw (e);
}
try (BigtableTableAdminClient tableAdmin = BigtableTableAdminClient.create(projectId, INSTANCE_ID)) {
// Create a table.
tableAdmin.createTable(CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME));
} catch (IOException e) {
System.out.println("Error during BeforeClass while creating table: \n" + e.toString());
throw (e);
}
// Get the sample's base directory (the one containing a pom.xml file)
String baseDir = System.getProperty("basedir");
// Emulate the function locally by running the Functions Framework Maven plugin
emulatorProcess = new ProcessBuilder().command("mvn", "function:run").directory(new File(baseDir)).start();
}
use of com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest in project java-bigtable by googleapis.
the class InstanceAdminExample method createProdInstance.
/**
* Demonstrates how to create a Production instance within a provided project.
*/
public void createProdInstance() {
// Checks if instance exists, creates instance if does not exists.
if (!adminClient.exists(instanceId)) {
System.out.println("Instance does not exist, creating a PRODUCTION instance");
// [START bigtable_create_prod_instance]
// Creates a Production Instance with the ID "ssd-instance",
// cluster id "ssd-cluster", 3 nodes and location "us-central1-f".
CreateInstanceRequest createInstanceRequest = CreateInstanceRequest.of(instanceId).addCluster(clusterId, "us-central1-f", 3, StorageType.SSD).setType(Instance.Type.PRODUCTION).addLabel("department", "accounting");
// Creates a production instance with the given request.
try {
Instance instance = adminClient.createInstance(createInstanceRequest);
System.out.printf("PRODUCTION type instance %s created successfully%n", instance.getId());
} catch (Exception e) {
System.err.println("Failed to create instance: " + e.getMessage());
throw e;
}
// [END bigtable_create_prod_instance]
}
}
use of com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testCreateInstance.
@Test
public void testCreateInstance() {
// Setup
Mockito.when(mockStub.createInstanceOperationCallable()).thenReturn(mockCreateInstanceCallable);
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").setServeNodes(1).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
Instance actualResult = adminClient.createInstance(CreateInstanceRequest.of(INSTANCE_ID).setType(Instance.Type.DEVELOPMENT).addCluster("cluster1", "us-east1-c", 1, StorageType.SSD));
// Verify
assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest in project java-docs-samples by GoogleCloudPlatform.
the class BulkWriteTest method beforeClass.
@BeforeClass
public static void beforeClass() {
projectId = requireEnv(PROJECT_ENV);
try (BigtableInstanceAdminClient instanceAdmin = BigtableInstanceAdminClient.create(projectId)) {
CreateInstanceRequest request = CreateInstanceRequest.of(INSTANCE_ID).addCluster(CLUSTER_ID, ZONE_ID, 1, StorageType.SSD);
Instance instance = instanceAdmin.createInstance(request);
} catch (IOException e) {
System.out.println("Error during BeforeClass while creating instance: \n" + e.toString());
Assert.fail();
}
}
use of com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest 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));
}
Aggregations