diff --git a/ceilometer/storage/hbase/base.py b/ceilometer/storage/hbase/base.py index f9192dd0..5f02c606 100644 --- a/ceilometer/storage/hbase/base.py +++ b/ceilometer/storage/hbase/base.py @@ -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(':') diff --git a/ceilometer/tests/db.py b/ceilometer/tests/db.py index 7e422ce1..7ea448b2 100644 --- a/ceilometer/tests/db.py +++ b/ceilometer/tests/db.py @@ -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", "_") ) diff --git a/ceilometer/tests/mocks.py b/ceilometer/tests/mocks.py index f44682a4..5e33b08f 100644 --- a/ceilometer/tests/mocks.py +++ b/ceilometer/tests/mocks.py @@ -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): diff --git a/doc/source/install/manual.rst b/doc/source/install/manual.rst index c14b91bc..5fe3fc19 100644 --- a/doc/source/install/manual.rst +++ b/doc/source/install/manual.rst @@ -79,7 +79,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:: @@ -97,6 +100,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/