You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

The examples below illustrate the set of basic operations with HBase instance using Stargate REST API.
Use following link to get more more details about HBase/Stargate API: http://wiki.apache.org/hadoop/Hbase/Stargate.

Assumptions

This document assumes a few things about your environment in order to simplify the examples.

  1. The JVM is executable as simply java.
  2. The Apache Knox Gateway is installed and functional.
  3. The example commands are executed within the context of the GATEWAY_HOME current directory. The GATEWAY_HOME directory is the directory within the Apache Knox Gateway installation that contains the README file and the bin, conf and deployments directories.
  4. A few examples optionally require the use of commands from a standard Groovy installation. These examples are optional but to try them you will need Groovy installed.

HBase Stargate Setup

Launch Stargate

The command below launches the Stargate daemon on port 60080

/usr/lib/hbase/bin/hbase-daemon.sh start rest -p 60080

Configure Sandbox port mapping for VirtualBox

  1. Select the VM
  2. Select menu Machine>Settings...
  3. Select tab Network
  4. Select Adapter 1
  5. Press Port Forwarding button
  6. Press Plus button to insert new rule: Name=Stargate, Host Port=60080, Guest Port=60080
  7. Press OK to close the rule window
  8. Press OK to Network window save the changes

Client DSL Examples

TODO

cURL Examples

Get software version

Set Accept Header to "text/plain", "text/xml", "application/json" or "application/x-protobuf"

%  curl -i -k -u bob:bob-password\
 -H "Accept:  application/json"\
 -X GET 'https://localhost:8443/gateway/sample/hbase/api/version'

Get version information regarding the HBase cluster backing the Stargate instance

Set Accept Header to "text/plain", "text/xml", "application/json" or "application/x-protobuf"

%  curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X GET 'https://localhost:8443/gateway/sample/hbase/api/version/cluster'

Get detailed status on the HBase cluster backing the Stargate instance.

Set Accept Header to "text/plain", "text/xml", "application/json" or "application/x-protobuf"

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X GET 'https://localhost:8443/gateway/sample/hbase/api/status/cluster'

Get the list of available tables.

Set Accept Header to "text/plain", "text/xml", "application/json" or "application/x-protobuf"

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X GET 'https://localhost:8443/gateway/sample/hbase/api'

Create table with two column families using xml input

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"   -H "Content-Type: text/xml"\
 -d '<?xml version="1.0" encoding="UTF-8"?><TableSchema name="table1"><ColumnSchema name="family1"/><ColumnSchema name="family2"/></TableSchema>'\
 -X PUT 'https://localhost:8443/gateway/sample/hbase/api/table1/schema'

Create table "table2" with column families "family3" and "family4" using JSON input

% curl -i -k -u bob:bob-password\
 -H "Accept: application/json"  -H "Content-Type: application/json"\
 -d '{"name":"table2","ColumnSchema":[{"name":"family3"},{"name":"family4"}]}'\
 -X PUT 'https://localhost:8443/gateway/sample/hbase/api/table2/schema'

Get table metadata

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X GET 'https://localhost:8443/gateway/sample/hbase/api/table1/regions'

Insert single row table

% curl -i -k -u bob:bob-password\
 -H "Content-Type: text/xml"\
 -H "Accept: text/xml"\
 -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><CellSet><Row key="cm93MQ=="><Cell column="ZmFtaWx5MTpjb2wx" >dGVzdA==</Cell></Row></CellSet>'\
 -X POST 'https://localhost:8443/gateway/sample/hbase/api/table1/row1'

Insert multiple rows into table

% curl -i -k -u bob:bob-password\
 -H "Content-Type: text/xml"\
 -H "Accept: text/xml"\
 -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><CellSet><Row key="cm93MA=="><Cell column=" ZmFtaWx5Mzpjb2x1bW4x" >dGVzdA==</Cell></Row><Row key="cm93MQ=="><Cell column=" ZmFtaWx5NDpjb2x1bW4x" >dGVzdA==</Cell></Row></CellSet>'\
 -X POST 'https://localhost:8443/gateway/sample/hbase/api/table2/false-row-key'

Get all data from table

Set Accept Header to "text/plain", "text/xml", "application/json" or "application/x-protobuf"

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X GET 'https://localhost:8443/gateway/sample/hbase/api/table1/*'

Execute cell or row query

Set Accept Header to "text/plain", "text/xml", "application/json" or "application/x-protobuf"

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X GET 'https://localhost:8443/gateway/sample/hbase/api/table1/row0/family1:col1'

Delete entire row from table

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X DELETE 'https://localhost:8443/gateway/sample/hbase/api/table2/row0'

Delete column family from row

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X DELETE 'https://localhost:8443/gateway/sample/hbase/api/table2/row0/family3'

Delete specific column from row

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X DELETE 'https://localhost:8443/gateway/sample/hbase/api/table2/row0/family3'

Create scanner

Scanner URL will be in Location response header

% curl -i -k -u bob:bob-password\
 -H "Content-Type: text/xml"\
 -d '<Scanner batch="1"/>'\
 -X PUT https://localhost:8443/gateway/sample/hbase/api/table1/scanner

Get the values of the next cells found by the scanner

% curl -i -k -u bob:bob-password\
 -H "Accept: application/json"\
 https://localhost:8443/gateway/sample/hbase/api/usertable/scanner/13705290446328cff5ed

Delete scanner

% curl -i -k -u bob:bob-password\
 -H "Accept: text/xml"\
 -X DELETE https://localhost:8443/gateway/sample/hbase/api/table1/scanner/13705290446328cff5ed
  • No labels