From d1a5e93b2553373258c8e24d4e63836985139712 Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Wed, 31 Oct 2018 21:07:58 -0700 Subject: [PATCH] Correct errors about freezer-api supporting for V1 and V2 api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At present, the codes as follows: db/elastic/driver.py: Def get_engine (self): If not self._engine: Self._engine = db_session.ElasticSearchEngineV2(self.backend) Return self._engine There is that freezer-api can't support support v1. Actually, there is enable_v1_api ,but it is not used correctly. The documents will be modified in other patches. For example: 1)freezer-api v1: /etc/freezer/freezer-api.conf: [DEFAULT] enable_v1_api = True [storage] driver = elasticsearch backend = elasticsearch [elasticsearch] hosts = http://172.16.1.200:9200 number_of_replicas = 0 index = freezer /etc/freezer/scheduler.conf: [DEFAULT] enable_v1_api = True command: freezer --os-backup-api-version 1 job-list 2)freezer-api v2: /etc/freezer/freezer-api.conf: [DEFAULT] enable_v1_api = False or # enable_v1_api = False [storage] driver = elasticsearch backend = elasticsearch [elasticsearch] hosts = http://172.16.1.200:9200 number_of_replicas = 0 index = freezer /etc/freezer/scheduler.conf: [DEFAULT] enable_v1_api = False or # enable_v1_api = False command: freezer job-list Change-Id: Iccee3a7cde986d0ba2aaf018fafa6bca411c34bf --- etc/freezer/freezer-api.conf.sample | 48 ++++++++++--------------- freezer_api/api/versions.py | 3 +- freezer_api/common/config.py | 50 +++++++++++--------------- freezer_api/db/elasticsearch/driver.py | 11 ++++-- freezer_api/service.py | 13 ++++--- 5 files changed, 58 insertions(+), 67 deletions(-) diff --git a/etc/freezer/freezer-api.conf.sample b/etc/freezer/freezer-api.conf.sample index 0ea5ac19..43330275 100644 --- a/etc/freezer/freezer-api.conf.sample +++ b/etc/freezer/freezer-api.conf.sample @@ -12,36 +12,26 @@ # Maximum value: 65535 #bind_port = 9090 -# Deploy the v1 OpenStack Freezer API. -# When this option is set to ``True``, Freezer-api service will respond to -# requests on registered endpoints conforming to the v1 OpenStack Freezer API. -# NOTES: -# * Multi-tenancy is not supported under this api version. -# * Everything is user based. -# * Freezer api v1 doesn't support Oslo.db. -# * Use elasticsearch db with v1 api version +# Deploy the OpenStack Freezer API. +# Default is the v2 Freezer API. +# When this option is set +# to ``True``, Freezer-api service will respond +# to requests on registered endpoints conforming +# to the v1 OpenStack Freezer api. +# The v1 OpenStack Freezer API: +# * Multi-tenancy is not supported under this +# api version. +# * Everything is user based. +# * Freezer api v1 doesn't support Oslo.db. +# * Use elasticsearch db with v1 api version +# The v2 OpenStack Freezer API: +# * Multi-tenancy is supported under this api version. +# * Freezer api v2 supports Oslo.db. +# * Recommended to use oslo.db with api v2 # Possible values: -# * True -# * False -# Related options: -# * enable_v2_api -# (boolean value) -#enable_v1_api = false - -# Deploy the v2 OpenStack Freezer API. -# When this option is set to ``True``, Freezer-api service will respond to -# requests on registered endpoints conforming to the v2 OpenStack Freezer api. -# NOTES: -# * Multi-tenancy is supported under this api version. -# * Freezer api v2 supports Oslo.db. -# * Recommended to use oslo.db with api v2 -# Possible values: -# * True -# * False -# Related options: -# * enable_v1_api -# (boolean value) -#enable_v2_api = true +# * True +# * False +#enable_v1_api = False # # From oslo.log diff --git a/freezer_api/api/versions.py b/freezer_api/api/versions.py index 8bb839d5..43a1dbcc 100644 --- a/freezer_api/api/versions.py +++ b/freezer_api/api/versions.py @@ -51,7 +51,8 @@ def api_versions(conf=None): class Resource(object): def _build_versions(self, host_url): - allowed_versions = {'v1': CONF.enable_v1_api, 'v2': CONF.enable_v2_api} + allowed_versions = {'v1': CONF.enable_v1_api, + 'v2': False if CONF.enable_v1_api else True} updated_versions = {'versions': []} for version in VERSIONS['versions']: diff --git a/freezer_api/common/config.py b/freezer_api/common/config.py index d32a5182..b2aa6623 100644 --- a/freezer_api/common/config.py +++ b/freezer_api/common/config.py @@ -61,35 +61,27 @@ def api_common_opts(): ), cfg.BoolOpt('enable_v1_api', default=False, - help="""Deploy the v1 OpenStack Freezer API. -When this option is set to ``True``, Freezer-api service will respond to -requests on registered endpoints conforming to the v1 OpenStack Freezer API. -NOTES: - * Multi-tenancy is not supported under this api version. - * Everything is user based. - * Freezer api v1 doesn't support Oslo.db. - * Use elasticsearch db with v1 api version -Possible values: - * True - * False -Related options: - * enable_v2_api - """), - cfg.BoolOpt('enable_v2_api', - default=True, - help="""Deploy the v2 OpenStack Freezer API. -When this option is set to ``True``, Freezer-api service will respond to -requests on registered endpoints conforming to the v2 OpenStack Freezer api. - NOTES: - * Multi-tenancy is supported under this api version. - * Freezer api v2 supports Oslo.db. - * Recommended to use oslo.db with api v2 - Possible values: - * True - * False - Related options: - * enable_v1_api - """) + help="""Default False, That is the v2 Freezer API + will be deployed. When this option is set + to ``True``, Freezer-api service will respond + to requests on registered endpoints conforming + to the v1 OpenStack Freezer api. + The v1 OpenStack Freezer API functions + as follows: + * Multi-tenancy is not supported under this + api version. + * Everything is user based. + * Freezer api v1 doesn't support Oslo.db. + * Use elasticsearch db with v1 api version + The v2 OpenStack Freezer API functions + as follows: + * Multi-tenancy is supported under this api version. + * Freezer api v2 supports Oslo.db. + * Recommended to use oslo.db with api v2 + Possible values: + * True + * False + """) ] return _COMMON diff --git a/freezer_api/db/elasticsearch/driver.py b/freezer_api/db/elasticsearch/driver.py index 80f463f3..d7e2a1e9 100644 --- a/freezer_api/db/elasticsearch/driver.py +++ b/freezer_api/db/elasticsearch/driver.py @@ -19,8 +19,8 @@ from oslo_log import log from freezer_api.common import db_mappings from freezer_api.db import base as db_base from freezer_api.db.elasticsearch import es_manager -from freezer_api.storage import elasticv2 as db_session - +from freezer_api.storage import elastic as db_session_v1 +from freezer_api.storage import elasticv2 as db_session_v2 CONF = cfg.CONF LOG = log.getLogger(__name__) @@ -89,7 +89,12 @@ class ElasticSearchDB(db_base.DBDriver): def get_engine(self): if not self._engine: - self._engine = db_session.ElasticSearchEngineV2(self.backend) + if CONF.enable_v1_api: + self._engine = db_session_v1.\ + ElasticSearchEngine(self.backend) + else: + self._engine = db_session_v2.\ + ElasticSearchEngineV2(self.backend) return self._engine def get_api(self): diff --git a/freezer_api/service.py b/freezer_api/service.py index 95df53de..7664931f 100644 --- a/freezer_api/service.py +++ b/freezer_api/service.py @@ -33,13 +33,16 @@ FALCON_MINVERSION_MIDDLEWARE = pkg_resources.parse_version('0.2.0b1') def root_app_factory(loader, global_conf, **local_conf): - """Allows freezer to launch multiple applications at a time. - It will allow freezer to manage multiple versions. + """Freezer can manage multiple versions, but + only launch one version at a time, Otherwise it is + easy to cause confusion. If there is a demand in the future + for a single freezer-api instance to support both v1 and v2 at a time, + you need to add a new patch to implement it. """ - if not CONF.enable_v1_api and '/v1' in local_conf: - del local_conf['/v1'] - if not CONF.enable_v2_api and '/v2' in local_conf: + if CONF.enable_v1_api and '/v1' in local_conf: del local_conf['/v2'] + else: + del local_conf['/v1'] return urlmap.urlmap_factory(loader, global_conf, **local_conf)