This is a simple application that demonstrates using the native HBase API to connect to and interact with Cloud Bigtable.
See the documentation for this sample for a brief explanation of the code.
Table of Contents
- Downloading the sample
- Costs
- Before you begin
- Provisioning an instance
- Running the application
- Cleaning up
Download the sample app and navigate into the app directory:
-
Clone the Cloud Bigtable examples repository, to your local machine:
git clone https://github.com/GoogleCloudPlatform/cloud-bigtable-examples.git
Alternatively, you can download the sample as a zip file and extract it.
-
Change to the Hello World code sample directory.
cd cloud-bigtable-examples/java/hello-world
This sample uses billable components of Cloud Platform, including:
- Google Cloud Bigtable
Use the Pricing Calculator to generate a cost estimate based on your projected usage. New Cloud Platform users might be eligible for a free trial.
This sample assumes you have Java 8 installed.
These samples use the Apache Maven build system. Before getting started, be sure to download and install it. When you use Maven as described here, it will automatically download the needed client libraries.
If you haven't already created a project, create one now. Projects enable you to manage all Google Cloud Platform resources for your app, including deployment, access control, billing, and services.
- Open the Cloud Platform Console.
- In the drop-down menu at the top, select Create a project.
- Give your project a name.
- Make a note of the project ID, which might be different from the project name. The project ID is used in commands and in configurations.
If you haven't already enabled billing for your project, enable billing now. Enabling billing allows is required to use Cloud Bigtable and to create VM instances.
If you haven't already installed the Google Cloud SDK, install the Google Cloud SDK now. The SDK contains tools and libraries that enable you to create and manage resources on Google Cloud Platform.
Set your Google Application Default Credentials by initializing the Google Cloud SDK with the command:
gcloud init
Generate a credentials file by running the application-default login command:
gcloud auth application-default login
Follow the instructions in the user documentation to create a Google Cloud Platform project and Cloud Bigtable instance if necessary. You'll need to reference your project id and instance id to run the application.
Build and run the sample using Maven.
mvn package
mvn exec:java -Dbigtable.projectID=GCLOUDPROJECT -Dbigtable.instanceID=BIGTABLEINSTANCE
You will see output resembling the following, interspersed with informational logging from the underlying libraries:
HelloWorld: Create table Hello-Bigtable
HelloWorld: Write some greetings to the table
HelloWorld: Scan for all greetings:
Hello World!
Hello Cloud Bigtable!
Hello HBase!
HelloWorld: Delete the table
To avoid incurring extra charges to your Google Cloud Platform account, remove the resources created for this sample.
-
Go to the Cloud Bigtable instance page in the Cloud Console.
-
Click on the instance name.
-
Click Delete instance.
-
Type the instance ID, then click Delete to delete the instance.