This example shows how to use the HBase REST server with Cloud Bigtable. This involves two steps:
- Installing and configuring an HBase client to serve as the REST gateway.
- Installing and configuring a REST client.
In this example, we use a Python REST client built with the requests library. This client is not an extensive, all-purpose application, but rather a simple demonstration of some common operations.
-
Install the Cloud Bigtable HBase shell on a Compute Engine VM. Be sure to install HBase 1.1.1 or later. Earlier versions are not compatible with this example.
-
Start the REST gateway. Run the following command to start HBase's REST API server in the background, suppressing all log output:
bin/hbase rest start > /dev/null 2>&1 &
If you prefer, you can redirect HBase's log output to a file:
bin/hbase rest start > hbase-log.txt 2>&1 &
-
If you would like to connect to your REST gateway using your external IP, open a firewall port:
gcloud compute firewall-rules create <instance_name> --allow=tcp:8080
Warning: Opening a firewall port creates a security risk. To connect from a different VM instance without opening a firewall port, use the VM instance's private internal IP instead of the external IP. You can find the internal IP in the Developers Console by going to Compute Engine > VM Instances and clicking on your instance.
-
In
put_get.py
andput_get_with_client.py
, changebaseurl
to match the IP address of the REST server. -
Use pip to install the
virtualenv
module which creates a virtual Python environment:sudo pip install virtualenv
-
Create an environment called
rest_env
, and activate the environment:virtualenv rest_env source rest_env/bin/activate
-
Install the REST API client's dependencies in the virtual environment:
pip install -r requirements.txt
-
put_get.py
demonstrates some simple operations directly using requests. -
put_get_with_client.py
usesrest_client.py
to wrap some of the details in methods, as well as creating the tablenew-table5001
if it doesn't exist. The test script does not delete the table after it finishes running. You can use the HBase shell to delete the table. -
Running the test scripts
python put_get.py
orpython put_get_with_client.py
Both commands should print "Done!" if all the operations succeed.
-
Stopping the REST server
Once you're done using the test scripts, run the following command to stop HBase's REST API server:
kill $(pgrep hbase)
If you run into a problem relating a java.net.UnknownHostException
when
using localhost
as the server on OS X, try explicitly setting an entry in the
the /etc/hosts
file as described.