Parametrize table_prefix_separator in hbase
table_prefix_separator is hardcoded to be an underscore (happybase default). This fix adds the possibility to parametrize this value using a parameter in ceilometer database configuration. An example is: hbase://localhost:9090/?table_prefix=ceilo&table_prefix_separator=. Change-Id: I8c3c2a0b35001991844e679282ffd0ee4ae76abc Closes-Bug: #1331374
This commit is contained in:
parent
aa84943c97
commit
3ae2e054ac
@ -60,9 +60,10 @@ class Connection(object):
|
||||
"""
|
||||
LOG.debug('connecting to HBase on %(host)s:%(port)s',
|
||||
{'host': conf['host'], 'port': conf['port']})
|
||||
return happybase.ConnectionPool(size=100, host=conf['host'],
|
||||
port=conf['port'],
|
||||
table_prefix=conf['table_prefix'])
|
||||
return happybase.ConnectionPool(
|
||||
size=100, host=conf['host'], port=conf['port'],
|
||||
table_prefix=conf['table_prefix'],
|
||||
table_prefix_separator=conf['table_prefix_separator'])
|
||||
|
||||
@staticmethod
|
||||
def _parse_connection_url(url):
|
||||
@ -77,6 +78,8 @@ class Connection(object):
|
||||
result = netutils.urlsplit(url)
|
||||
opts['table_prefix'] = urlparse.parse_qs(
|
||||
result.query).get('table_prefix', [None])[0]
|
||||
opts['table_prefix_separator'] = urlparse.parse_qs(
|
||||
result.query).get('table_prefix_separator', ['_'])[0]
|
||||
opts['dbtype'] = result.scheme
|
||||
if ':' in result.netloc:
|
||||
opts['host'], port = result.netloc.split(':')
|
||||
|
@ -161,9 +161,10 @@ class HBaseManager(fixtures.Fixture):
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return '%s?table_prefix=%s' % (
|
||||
return '%s?table_prefix=%s&table_prefix_separator=%s' % (
|
||||
self._url,
|
||||
os.getenv("CEILOMETER_TEST_HBASE_TABLE_PREFIX", "test")
|
||||
os.getenv("CEILOMETER_TEST_HBASE_TABLE_PREFIX", "test"),
|
||||
os.getenv("CEILOMETER_TEST_HBASE_TABLE_PREFIX_SEPARATOR", "_")
|
||||
)
|
||||
|
||||
|
||||
|
@ -25,8 +25,10 @@ class MockHBaseTable(happybase.Table):
|
||||
# We create happybase Table with prefix from
|
||||
# CEILOMETER_TEST_HBASE_TABLE_PREFIX
|
||||
prefix = os.getenv("CEILOMETER_TEST_HBASE_TABLE_PREFIX", 'test')
|
||||
separator = os.getenv(
|
||||
"CEILOMETER_TEST_HBASE_TABLE_PREFIX_SEPARATOR", '_')
|
||||
super(MockHBaseTable, self).__init__(
|
||||
"%s_%s" % (prefix, name),
|
||||
"%s%s%s" % (prefix, separator, name),
|
||||
connection)
|
||||
|
||||
def put(self, row, *args, **kwargs):
|
||||
|
@ -85,7 +85,10 @@ HBase
|
||||
|
||||
import happybase
|
||||
|
||||
conn = happybase.Connection(host=$hbase-thrift-server, port=9090, table_prefix=None)
|
||||
conn = happybase.Connection(host=$hbase-thrift-server,
|
||||
port=9090,
|
||||
table_prefix=None,
|
||||
table_prefix_separator='_')
|
||||
print conn.tables() # this returns a list of HBase tables in your HBase server
|
||||
|
||||
.. note::
|
||||
@ -103,6 +106,16 @@ HBase
|
||||
[database]
|
||||
connection = hbase://hbase-thrift-host:9090
|
||||
|
||||
It is possible to customize happybase's `table_prefix` and `table_prefix_separator`
|
||||
via query string. By default `table_prefix` is not set and `table_prefix_separator`
|
||||
is '_'. When `table_prefix` is not specified `table_prefix_separator` is not taken
|
||||
into account. E.g. the resource table in the default case will be 'resource' while
|
||||
with `table_prefix` set to 'ceilo' and `table_prefix_separator` to '.' the resulting
|
||||
table will be 'ceilo.resource'. For this second case this is the database connection
|
||||
configuration::
|
||||
|
||||
[database]
|
||||
connection = hbase://hbase-thrift-host:9090?table_prefix=ceilo&table_prefix_separator=.
|
||||
|
||||
.. _HappyBase: http://happybase.readthedocs.org/en/latest/index.html#
|
||||
.. _MongoDB: http://www.mongodb.org/
|
||||
|
Loading…
x
Reference in New Issue
Block a user