1 Introduction
利用restapi来获取hbase的数据
2 Configure
2.1 version
命令:curl http://10.1.200.7:8080/version
2.2 获取集群信息
命令:curl -H “Accept:application/json” http://10.1.200.7:8080/version/cluster
2.3 获取集群中各个实例的状态
命令:curl -H “Accept:application/json” http://10.1.200.7:8080/status/cluster
2.4 获取所有的table信息
命令:curl http://10.1.200.7:8080/
2.5 获取某一个表的建表信息
命令: curl -H “Accept:application/json” http://10.1.200.7:8080/tablename/schema
Postscript:
创建表: put /tablename/schema
更新表: pos /tablename/schema
删除表: DELETE /tablename/schema
2.6 获取表的metadata数据
命令:curl -H “Accept:application/json” http://10.1.200.7:8080/basic-test/regions
3 Rest Method
GET 根据content-type获取指定格式的数据
PUT 根据content-type以及对应格式的数据,替换hbase上已经存在的数据
POST 添加数据到hbase上
DELETE 删除hbase上的数据
4 Get
4.1 Format
path := '/' <table>
'/' <row>
( '/' ( <column> ( ':' <qualifier> )?
( ',' <column> ( ':' <qualifier> )? )+ )?
( '/' ( <start-timestamp> ',' )? <end-timestamp> )? )?
query := ( '?' 'v' '=' <num-versions> )?
4.2 Intro
table # 表格名
row # rowkey键值
column # 列名,可以是正则通配符来进行范围获取
qualifier # 列名对应的修饰符
timestamp # 指示版本信息
4.3 获取多keys上相同的column:qualifier
命令: curl -H “Accept:application/json” http://10.1.200.7:8080/basic-test/devops-dev1:2015092603*/cpu:used|python -m json.tool
4.4 获取某一个小时内33分钟~36分钟的所有所有数据
命令: curl -H “Accept:application/json” http://10.10.116.229:8080/basic/dm-positionrec-python-bja-001:20150930173[3-6]
5 PUT
5.1 Format
path := '/' <table> '/' <row> '/' <column> ( ':' <qualifier> )?
( '/' <timestamp> )?
或者
path := '/' <table> '/' <false-row-key>
5.2 Intro
false-row-key # 一次put多个keys,直接在url后面写入false-row-key即可
5.3 存入列信息到指定的table, rowkeys中
附录:存在就覆盖,不存在添加,其他都不变
命令:
curl -v -X PUT -H "Content-Type: application/json" --data '{"Row":[{"Cell":[{"column":"YWdlOg==","timestamp":1443555518104,"$":"MjQ="},{"column":"Y29sb3I6","timestamp":1443555530473,"$":"cmVk"}],"key":"d2hvOjAx"}]}' http://10.1.200.7:8080/bifeng/who:01
返回:200
5.4 存入多行信息到指定的table中
命令:
curl -v -X PUT -H "Content-Type: application/json" --data '{"Row":[
{"Cell":[
{"column":"YWdlOg==","$":"MjQ="},
{"column":"Y29sb3I6","$":"cmVk"},
{"column":"bmFtZTo=","$":"bXlsb3Zl"}
],
"key":"cGFueGlhb3l1YW46MDE="
},
{"Cell":[
{"column":"YWdlOg==","$":"Mjc="},
{"column":"Y29sb3I6","$":"Ymx1ZQ=="},
{"column":"bmFtZTo=","$":"bG92ZQ=="}
],
"key":"d2hvOjAx"}
]}' http://10.1.200.7:8080/bifeng/false-row-key
返回:200
注意: 在退出数据时,key必须在cell的前头
6 构建http的请求体
必须保证每一个column的格式为ABC:xxx,其中xxx可以不存在, 通过”Content-Type: application/json”或者其他值来指定请求体中的数据编码形式;
curl命令:
curl -v -X PUT -H "Content-Type: application/json" --data '{"Row":[{"Cell":[{"column":"YWdlOg==","timestamp":1443555518104,"$":"MjQ="},{"column":"Y29sb3I6","timestamp":1443555530473,"$":"cmVk"},{"column":"bmFtZTo=","timestamp":1443555541777,"$":"bG92ZQ=="}],"key":"d2hvOjAx"}]}' http://10.1.200.7:8080/bifeng/who:01