feat(sql/driver): expose ControlDriver, more config
This patch adds two features to our current sqlalchemy driver: - option to configure connection URI for driver - Skeleton of ControlDriver written With the ControlDriver, the expected methods were stubbed out. Small fix: all controller methods not yet implemented now raise NotImplementedError. Change-Id: I1cd4a4d75cbbee7f0ff574c5be4d11660359ab7e Partially-Implements: blueprint: sql-storage-driver
This commit is contained in:
parent
edf9c2b552
commit
957cadc2f3
@ -99,6 +99,9 @@ storage = mongodb
|
||||
uri = mongodb://db1.example.net,db2.example.net:2500/?replicaSet=test&ssl=true&w=majority
|
||||
database = marconi
|
||||
|
||||
[drivers:storage:sqlalchemy]
|
||||
;uri = sqlite:///:memory:
|
||||
|
||||
# Number of databases across which to partition message data,
|
||||
# in order to reduce writer lock %. DO NOT change this setting
|
||||
# after initial deployment. It MUST remain static. Also,
|
||||
|
@ -24,8 +24,8 @@ from marconi.queues.storage.sqlalchemy import tables
|
||||
|
||||
|
||||
_SQLALCHEMY_OPTIONS = [
|
||||
cfg.StrOpt('database', default=':memory:',
|
||||
help='Sqlalchemy database to use.')
|
||||
cfg.StrOpt('uri', default='sqlite:///:memory:',
|
||||
help='An sqlalchemy URL')
|
||||
]
|
||||
|
||||
_SQLALCHEMY_GROUP = 'drivers:storage:sqlalchemy'
|
||||
@ -36,17 +36,19 @@ class DataDriver(storage.DataDriverBase):
|
||||
def __init__(self, conf, cache):
|
||||
super(DataDriver, self).__init__(conf, cache)
|
||||
|
||||
self.conf.register_opts(_SQLALCHEMY_OPTIONS, group=_SQLALCHEMY_GROUP)
|
||||
self.conf.register_opts(_SQLALCHEMY_OPTIONS,
|
||||
group=_SQLALCHEMY_GROUP)
|
||||
self.sqlalchemy_conf = self.conf[_SQLALCHEMY_GROUP]
|
||||
|
||||
self.__path = self.sqlalchemy_conf.database
|
||||
|
||||
@decorators.lazy_property(write=False)
|
||||
def engine(self, *args, **kwargs):
|
||||
engine = sa.create_engine(*args, **kwargs)
|
||||
engine = sa.create_engine(self.sqlalchemy_conf.uri, **kwargs)
|
||||
tables.metadata.create_all(engine, checkfirst=True)
|
||||
return engine
|
||||
|
||||
# TODO(cpp-cabrera): expose connect/close as a context manager
|
||||
# that acquires the connection to the DB for the desired scope and
|
||||
# closes it once the operations are completed
|
||||
@decorators.lazy_property(write=False)
|
||||
def connection(self):
|
||||
return self.engine.connect()
|
||||
@ -56,12 +58,45 @@ class DataDriver(storage.DataDriverBase):
|
||||
|
||||
@decorators.lazy_property(write=False)
|
||||
def queue_controller(self):
|
||||
return None
|
||||
raise NotImplementedError()
|
||||
|
||||
@decorators.lazy_property(write=False)
|
||||
def message_controller(self):
|
||||
return None
|
||||
raise NotImplementedError()
|
||||
|
||||
@decorators.lazy_property(write=False)
|
||||
def claim_controller(self):
|
||||
return None
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class ControlDriver(storage.ControlDriverBase):
|
||||
|
||||
def __init__(self, conf, cache):
|
||||
super(ControlDriver, self).__init__(conf, cache)
|
||||
self.conf.register_opts(_SQLALCHEMY_OPTIONS,
|
||||
group=_SQLALCHEMY_GROUP)
|
||||
self.sqlalchemy_conf = self.conf[_SQLALCHEMY_GROUP]
|
||||
|
||||
@decorators.lazy_property(write=False)
|
||||
def engine(self, *args, **kwargs):
|
||||
engine = sa.create_engine(self.sqlalchemy_conf.uri, **kwargs)
|
||||
tables.metadata.create_all(engine, checkfirst=True)
|
||||
return engine
|
||||
|
||||
# TODO(cpp-cabrera): expose connect/close as a context manager
|
||||
# that acquires the connection to the DB for the desired scope and
|
||||
# closes it once the operations are completed
|
||||
@decorators.lazy_property(write=False)
|
||||
def connection(self):
|
||||
return self.engine.connect()
|
||||
|
||||
def close_connection(self):
|
||||
self.connection.close()
|
||||
|
||||
@property
|
||||
def shards_controller(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def catalogue_controller(self):
|
||||
raise NotImplementedError()
|
||||
|
Loading…
x
Reference in New Issue
Block a user