Search in sources :

Example 1 with CreateInstanceRequest

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

Example 2 with CreateInstanceRequest

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]
    }
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) CreateInstanceRequest(com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest) NotFoundException(com.google.api.gax.rpc.NotFoundException) IOException(java.io.IOException) AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) PartialListInstancesException(com.google.cloud.bigtable.admin.v2.models.PartialListInstancesException)

Example 3 with CreateInstanceRequest

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

Example 4 with CreateInstanceRequest

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

Example 5 with CreateInstanceRequest

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

Aggregations

Instance (com.google.cloud.bigtable.admin.v2.models.Instance)5 CreateInstanceRequest (com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest)3 IOException (java.io.IOException)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)1 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)1 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)1 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)1 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)1 ClusterAutoscalingConfig (com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)1 PartialListInstancesException (com.google.cloud.bigtable.admin.v2.models.PartialListInstancesException)1 File (java.io.File)1