Split up storage into each service
This commit is contained in:
parent
2b605025c1
commit
486a78ef64
@ -45,6 +45,7 @@ class SQLAlchemyEngine(StorageEngine):
|
||||
|
||||
return Connection()
|
||||
|
||||
|
||||
class Connection(Connection, api.HelpersMixin):
|
||||
def __init__(self):
|
||||
self.setup('biller:sqlalchemy')
|
||||
|
@ -2,7 +2,7 @@ import functools
|
||||
from oslo.config import cfg
|
||||
from billingstack.openstack.common import log as logging
|
||||
from billingstack.openstack.common.rpc import service as rpc_service
|
||||
from billingstack import storage
|
||||
from billingstack.central import storage
|
||||
|
||||
|
||||
cfg.CONF.import_opt('central_topic', 'billingstack.central.rpcapi')
|
||||
|
57
billingstack/central/storage/__init__.py
Normal file
57
billingstack/central/storage/__init__.py
Normal file
@ -0,0 +1,57 @@
|
||||
# Copyright 2012 Managed I.T.
|
||||
#
|
||||
# Author: Kiall Mac Innes <kiall@managedit.ie>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# Copied: Moniker
|
||||
from oslo.config import cfg
|
||||
from billingstack.openstack.common import log as logging
|
||||
from billingstack.storage import base
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StorageEngine(base.StorageEngine):
|
||||
__plugin_type__ = 'central'
|
||||
__plugin_ns__ = 'billingstack.central.storage'
|
||||
|
||||
|
||||
class Connection(base.Connection):
|
||||
pass
|
||||
|
||||
|
||||
def get_engine(engine_name):
|
||||
"""
|
||||
Return the engine class from the provided engine name
|
||||
"""
|
||||
return StorageEngine.get_plugin(engine_name, invoke_on_load=True)
|
||||
|
||||
|
||||
def get_connection():
|
||||
engine = get_engine(cfg.CONF['service:central'].storage_driver)
|
||||
return engine.get_connection()
|
||||
|
||||
|
||||
def setup_schema():
|
||||
""" Create the DB - Used for testing purposes """
|
||||
LOG.debug("Setting up Schema")
|
||||
connection = get_connection()
|
||||
connection.setup_schema()
|
||||
|
||||
|
||||
def teardown_schema():
|
||||
""" Reset the DB to default - Used for testing purposes """
|
||||
LOG.debug("Tearing down Schema")
|
||||
connection = get_connection()
|
||||
connection.teardown_schema()
|
@ -19,16 +19,17 @@ from billingstack import utils as common_utils
|
||||
from billingstack.sqlalchemy import utils as db_utils, api
|
||||
from billingstack.sqlalchemy.session import SQLOPTS
|
||||
from billingstack.storage import base
|
||||
from billingstack.storage.impl_sqlalchemy import models
|
||||
from billingstack.central.storage import Connection, StorageEngine
|
||||
from billingstack.central.storage.impl_sqlalchemy import models
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
cfg.CONF.register_group(cfg.OptGroup(
|
||||
name='storage:sqlalchemy', title="Configuration for SQLAlchemy Storage"
|
||||
name='central:sqlalchemy', title="Configuration for SQLAlchemy Storage"
|
||||
))
|
||||
|
||||
cfg.CONF.register_opts(SQLOPTS, group='storage:sqlalchemy')
|
||||
cfg.CONF.register_opts(SQLOPTS, group='central:sqlalchemy')
|
||||
|
||||
|
||||
def filter_merchant_by_join(query, cls, criterion):
|
||||
@ -41,14 +42,14 @@ def filter_merchant_by_join(query, cls, criterion):
|
||||
return query
|
||||
|
||||
|
||||
class SQLAlchemyStorage(base.StorageEngine):
|
||||
class SQLAlchemyEngine(StorageEngine):
|
||||
__plugin_name__ = 'sqlalchemy'
|
||||
|
||||
def get_connection(self):
|
||||
return Connection(self.name)
|
||||
|
||||
|
||||
class Connection(base.Connection, api.HelpersMixin):
|
||||
class Connection(Connection, api.HelpersMixin):
|
||||
"""
|
||||
SQLAlchemy connection
|
||||
"""
|
@ -22,7 +22,7 @@ from logging.config import fileConfig
|
||||
from alembic import context
|
||||
from sqlalchemy import create_engine, pool
|
||||
|
||||
from billingstack.storage.impl_sqlalchemy.models import ModelBase
|
||||
from billingstack.central.storage.impl_sqlalchemy.models import ModelBase
|
||||
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
@ -50,7 +50,7 @@ def run_migrations_offline():
|
||||
script output.
|
||||
|
||||
"""
|
||||
context.configure(url=billingstack_config['storage:sqlalchemy']
|
||||
context.configure(url=billingstack_config['central:sqlalchemy']
|
||||
.database_connection)
|
||||
|
||||
with context.begin_transaction():
|
||||
@ -65,7 +65,7 @@ def run_migrations_online():
|
||||
|
||||
"""
|
||||
engine = create_engine(
|
||||
billingstack_config['storage:sqlalchemy'].database_connection,
|
||||
billingstack_config['central:sqlalchemy'].database_connection,
|
||||
poolclass=pool.NullPool)
|
||||
|
||||
connection = engine.connect()
|
@ -33,7 +33,7 @@ _db_opts = [
|
||||
]
|
||||
|
||||
CONF = cfg.ConfigOpts()
|
||||
CONF.register_opts(_db_opts, 'storage:sqlalchemy')
|
||||
CONF.register_opts(_db_opts, 'central:sqlalchemy')
|
||||
|
||||
|
||||
def do_alembic_command(config, cmd, *args, **kwargs):
|
||||
@ -116,7 +116,7 @@ def main():
|
||||
)
|
||||
config.set_main_option(
|
||||
'script_location',
|
||||
'billingstack.storage.impl_sqlalchemy.migration:alembic_migrations')
|
||||
'billingstack.central.storage.impl_sqlalchemy.migration:alembic_migrations')
|
||||
# attach the Quantum conf to the Alembic conf
|
||||
config.billingstack_config = CONF
|
||||
|
@ -30,7 +30,7 @@ cfg.CONF.import_opt(
|
||||
cfg.CONF.import_opt(
|
||||
'database_connection',
|
||||
'billingstack.storage.impl_sqlalchemy',
|
||||
group='storage:sqlalchemy')
|
||||
group='central:sqlalchemy')
|
||||
|
||||
|
||||
class DatabaseCommand(Command):
|
||||
|
@ -1,47 +0,0 @@
|
||||
# Copyright 2012 Managed I.T.
|
||||
#
|
||||
# Author: Kiall Mac Innes <kiall@managedit.ie>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# Copied: Moniker
|
||||
from oslo.config import cfg
|
||||
from billingstack.openstack.common import log as logging
|
||||
from billingstack.storage.base import StorageEngine
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_engine(engine_name):
|
||||
"""
|
||||
Return the engine class from the provided engine name
|
||||
"""
|
||||
return StorageEngine.get_plugin(engine_name, invoke_on_load=True)
|
||||
|
||||
|
||||
def get_connection():
|
||||
engine = get_engine(cfg.CONF['service:central'].storage_driver)
|
||||
return engine.get_connection()
|
||||
|
||||
|
||||
def setup_schema():
|
||||
""" Create the DB - Used for testing purposes """
|
||||
LOG.debug("Setting up Schema")
|
||||
connection = get_connection()
|
||||
connection.setup_schema()
|
||||
|
||||
|
||||
def teardown_schema():
|
||||
""" Reset the DB to default - Used for testing purposes """
|
||||
LOG.debug("Tearing down Schema")
|
||||
connection = get_connection()
|
||||
connection.teardown_schema()
|
@ -20,8 +20,6 @@ from billingstack.plugin import Plugin
|
||||
|
||||
class StorageEngine(Plugin):
|
||||
""" Base class for storage engines """
|
||||
|
||||
__plugin_ns__ = 'billingstack.storage'
|
||||
__plugin_type__ = 'storage'
|
||||
|
||||
def get_connection(self):
|
||||
|
@ -6,7 +6,7 @@ from oslo.config import cfg
|
||||
# from billingstack.openstack.common import policy
|
||||
from billingstack import exceptions
|
||||
from billingstack import samples
|
||||
from billingstack import storage
|
||||
from billingstack.central import storage
|
||||
from billingstack.api import service as api_service
|
||||
from billingstack.central import service as central_service
|
||||
from billingstack.openstack.common.context import RequestContext, \
|
||||
@ -16,8 +16,8 @@ from billingstack.openstack.common.context import RequestContext, \
|
||||
cfg.CONF.import_opt('storage_driver', 'billingstack.central',
|
||||
group='service:central')
|
||||
cfg.CONF.import_opt('database_connection',
|
||||
'billingstack.storage.impl_sqlalchemy',
|
||||
group='storage:sqlalchemy')
|
||||
'billingstack.central.storage.impl_sqlalchemy',
|
||||
group='central:sqlalchemy')
|
||||
|
||||
|
||||
class AssertMixin(object):
|
||||
@ -107,7 +107,7 @@ class TestCase(BaseTestCase):
|
||||
|
||||
self.config(
|
||||
database_connection='sqlite://',
|
||||
group='storage:sqlalchemy'
|
||||
group='central:sqlalchemy'
|
||||
)
|
||||
|
||||
self.samples = samples.get_samples()
|
||||
|
@ -14,7 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from billingstack.openstack.common import log as logging
|
||||
from billingstack.storage.impl_sqlalchemy import models
|
||||
from billingstack.central.storage.impl_sqlalchemy import models
|
||||
from billingstack.tests.base import TestCase
|
||||
|
||||
|
||||
|
@ -26,5 +26,5 @@ class SqlalchemyStorageTest(StorageDriverTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config(database_connection='sqlite://',
|
||||
group='storage:sqlalchemy')
|
||||
group='central:sqlalchemy')
|
||||
super(SqlalchemyStorageTest, self).setUp()
|
||||
|
@ -36,7 +36,7 @@ allowed_rpc_exception_modules = billingstack.exceptions, billingstack.openstack.
|
||||
#-----------------------
|
||||
# SQLAlchemy Storage
|
||||
#-----------------------
|
||||
[storage:sqlalchemy]
|
||||
[central:sqlalchemy]
|
||||
# Database connection string - to configure options for a given implementation
|
||||
# like sqlalchemy or other see below
|
||||
#database_connection = mysql://billingstack:billingstack@localhost:3306/billingstack
|
||||
|
4
setup.py
4
setup.py
@ -57,8 +57,8 @@ setup(
|
||||
],
|
||||
cmdclass=common_setup.get_cmdclass(),
|
||||
entry_points=textwrap.dedent("""
|
||||
[billingstack.storage]
|
||||
sqlalchemy = billingstack.storage.impl_sqlalchemy:SQLAlchemyStorage
|
||||
[billingstack.central.storage]
|
||||
sqlalchemy = billingstack.central.storage.impl_sqlalchemy:SQLAlchemyEngine
|
||||
|
||||
[billingstack.biller.storage]
|
||||
sqlalchemy = billingstack.biller.storage.impl_sqlalchemy:SQLAlchemyEngine
|
||||
|
@ -18,7 +18,7 @@ cfg.CONF.import_opt('state_path', 'billingstack.paths')
|
||||
cfg.CONF.import_opt(
|
||||
'database_connection',
|
||||
'billingstack.storage.impl_sqlalchemy',
|
||||
group='storage:sqlalchemy')
|
||||
group='central:sqlalchemy')
|
||||
|
||||
|
||||
SAMPLES = get_samples()
|
||||
|
@ -21,8 +21,8 @@ cfg.CONF.import_opt('state_path', 'billingstack.paths')
|
||||
|
||||
|
||||
cfg.CONF.import_opt('database_connection',
|
||||
'billingstack.storage.impl_sqlalchemy',
|
||||
group='storage:sqlalchemy')
|
||||
'billingstack.central.storage.impl_sqlalchemy',
|
||||
group='central:sqlalchemy')
|
||||
|
||||
if __name__ == '__main__':
|
||||
service.prepare_service(sys.argv)
|
||||
|
Loading…
x
Reference in New Issue
Block a user