From 6da781734ab55eb8840b20964fcbd65b7bc25a5a Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Tue, 3 Jan 2017 23:12:31 +0300 Subject: [PATCH] Allow to specify data and lock apis with config Change-Id: Ib8aecda22b89218a3106b301ec56baf081b164bf --- glare/common/wsgi.py | 28 ++++++++++++++++++++++++++++ glare/engine.py | 4 ++-- glare/objects/base.py | 16 +++------------- glare/opts.py | 1 + 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/glare/common/wsgi.py b/glare/common/wsgi.py index d56dc19..a706f04 100644 --- a/glare/common/wsgi.py +++ b/glare/common/wsgi.py @@ -104,6 +104,33 @@ eventlet_opts = [ 'wait forever.')), ] +data_api_opts = [ + cfg.StrOpt('data_api', + default='glare.db.artifact_api.ArtifactAPI', + help=(""" +Python class path of data access API. + +Specifies the path to the API to use for accessing the data model. +This option determines how the artifact catalog data will be accessed. + +If this option is set to ``glare.db.artifact_api.ArtifactAPI`` then +the artifact catalog data is stored in and read from the database via the +SQLAlchemy Core and ORM APIs. +""")), + cfg.StrOpt('lock_api', + default='glare.db.artifact_api.ArtifactLockApi', + help=(""" +Python class path of API for setting locks on artifacts. + +Specifies the path to the API to use for locking. +This option determines how the locking will be accessed. + +If this option is set to ``glare.db.artifact_api.ArtifactLockApi`` +then the locks are stored in and read from the database via the +SQLAlchemy Core and ORM APIs. +""")) +] + LOG = logging.getLogger(__name__) @@ -111,6 +138,7 @@ CONF = cfg.CONF CONF.register_opts(bind_opts) CONF.register_opts(socket_opts) CONF.register_opts(eventlet_opts) +CONF.register_opts(data_api_opts) profiler_opts.set_defaults(CONF) ASYNC_EVENTLET_THREAD_POOL_LIST = [] diff --git a/glare/engine.py b/glare/engine.py index 8b29bc8..af3e378 100644 --- a/glare/engine.py +++ b/glare/engine.py @@ -19,12 +19,12 @@ import jsonpatch from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils +from oslo_utils import importutils from glare.common import exception from glare.common import policy from glare.common import store_api from glare.common import utils -from glare.db import artifact_api from glare.i18n import _, _LI from glare import locking from glare.notification import Notifier @@ -52,7 +52,7 @@ class Engine(object): registry = glare_registry.ArtifactRegistry registry.register_all_artifacts() - lock_engine = locking.LockEngine(artifact_api.ArtifactLockApi()) + lock_engine = locking.LockEngine(importutils.import_class(CONF.lock_api)()) @classmethod def _get_schemas(cls, reg): diff --git a/glare/objects/base.py b/glare/objects/base.py index 43c930a..d52fd47 100644 --- a/glare/objects/base.py +++ b/glare/objects/base.py @@ -18,6 +18,7 @@ import uuid from oslo_config import cfg from oslo_log import log as logging +from oslo_utils import importutils from oslo_utils import timeutils from oslo_versionedobjects import base from oslo_versionedobjects import fields @@ -27,7 +28,6 @@ import six.moves.urllib.request as urlrequest from glare.common import exception from glare.common import store_api from glare.common import utils -from glare.db import artifact_api from glare import locking from glare.i18n import _, _LI from glare.objects.meta import attribute @@ -233,24 +233,14 @@ class BaseArtifact(base.VersionedObject): _DB_API = None - @classmethod - def init_db_api(cls): - """Provide initialized db api to interact with artifact database. - - To interact with database each artifact type must provide an api - to execute db operations with artifacts. - :return: subtype of glare.db.api.BaseDBAPI - """ - return artifact_api.ArtifactAPI(cls) - @classproperty def db_api(cls): """Return current database API""" if cls._DB_API is None: - cls._DB_API = cls.init_db_api() + cls._DB_API = importutils.import_class(CONF.data_api)(cls) return cls._DB_API - lock_engine = locking.LockEngine(artifact_api.ArtifactLockApi()) + lock_engine = locking.LockEngine(importutils.import_class(CONF.lock_api)()) @classmethod def _lock_version(cls, context, values): diff --git a/glare/opts.py b/glare/opts.py index 0220f30..065251f 100644 --- a/glare/opts.py +++ b/glare/opts.py @@ -37,6 +37,7 @@ _artifacts_opts = [ glare.api.versions.versions_opts, glare.common.config.common_opts, glare.common.wsgi.bind_opts, + glare.common.wsgi.data_api_opts, glare.common.wsgi.eventlet_opts, glare.common.wsgi.socket_opts, glare.notification.notifier_opts,