These are the inbuilt interfaces provided by HBase so that clients can communicate using RESTful and Thrift calls.
Now, let's discuss the RESTful service and Thrift that HBase provides in order to contact HBase besides Java coding. Stargate is the server that provides RESTful service interface through Java package, org.apache.hadoop.hbase.rest
. It internally runs an embedded Jetty servlet container to handle the request.
We can start it as follows:
hbase rest start -p <port to use>
The preceding command starts REStful services in the foreground. Alternatively, you can start it and send it to the background:
bin/hbase-daemon.sh start rest -p <port to use>
REStful services can be stopped with the following command:
bin/hbase-daemon.sh stop rest
HBase can handle all REST requests through curl
or any computer languages that support web service such as PHP. The following is the curl
request example:
curl -H "Accept: text/xml" http://localhost:8000/version
The preceding command will return the HBase version.
To delete a table, we can give a command as follows:
curl -v -X DELETE 'http://localhost:8080/test/schema' -H "Accept: application/json"
The result can be fetched in XML or JSON and be parsed further.
The Thrift framework is provided by a Thrift server, which provides a way for scalable flexibility and interoperability across computer languages and services development. It builds an engine with the help of code generation, which works efficiently between HBase and C++, Java, Python, PHP, Ruby, Perl, and so on.
This service is provided by HBase using the gthrough
package:
org.apache.hadoop.hbase.thrift
The Thrift service can be started like this:
bin/hbase-daemon.sh start thrift
And can be stopped like this:
bin/hbase-daemon.sh stop thrift
The following is the example for creating a table using Thrift in Python:
from thrift.transport import TSocket from thrift.protocol import TBinaryProtocol from thrift.transport import TTransport from hbase import Hbase # Connects to HBase Thrift server transport = TTransport.TBufferedTransport(TSocket.TSocket(hostname, thriftport)) protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport) # Create and open the client connection client = Hbase.Client(protocol) transport.open() client.createTable(tablename, [Hbase.ColumnDescriptor(name=cfname)]) transport.close()
The client can be built in Python or PHP or any language that supports Thrift.
Complete details of the Thrift service and updated APIs can be found at the following links:
18.226.187.233