Disable pubsub when getting nb_api in external apps
The pubsub creates different problems, and every external app specifically disables it before getting the nb_api instance. We should hide this behaviour inside the get_instance method. Also, I called the argument is_external_app as in the future we may want to add more behavioural differences between the cases. Change-Id: I25a55737351f8fe14bddafa7c78e60fe096db43e
This commit is contained in:
@@ -179,7 +179,7 @@ def add_object_from_json(json_str, table):
|
|||||||
:param table: table name where object should be added
|
:param table: table name where object should be added
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
nb_api = api_nb.NbApi.get_instance(False)
|
nb_api = api_nb.NbApi.get_instance(False, True)
|
||||||
try:
|
try:
|
||||||
model = model_framework.get_model(table)
|
model = model_framework.get_model(table)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ def main():
|
|||||||
config.init(sys.argv[1:])
|
config.init(sys.argv[1:])
|
||||||
config.setup_logging()
|
config.setup_logging()
|
||||||
environment_setup()
|
environment_setup()
|
||||||
cfg.CONF.set_override('enable_df_pub_sub', False, group='df')
|
nb_api = api_nb.NbApi.get_instance(False, True)
|
||||||
nb_api = api_nb.NbApi.get_instance(False)
|
|
||||||
service_instance = metadata_service.DFMetadataProxyHandler(
|
service_instance = metadata_service.DFMetadataProxyHandler(
|
||||||
cfg.CONF, nb_api)
|
cfg.CONF, nb_api)
|
||||||
df_service.register_service(
|
df_service.register_service(
|
||||||
|
|||||||
@@ -165,10 +165,7 @@ class BGPService(service.Service):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
df_config.init(sys.argv)
|
df_config.init(sys.argv)
|
||||||
# BGP dynamic route is not a service that needs real time response.
|
nb_api = api_nb.NbApi.get_instance(False, True)
|
||||||
# So disable pubsub here and use period task to do BGP job.
|
|
||||||
cfg.CONF.set_override('enable_df_pub_sub', False, group='df')
|
|
||||||
nb_api = api_nb.NbApi.get_instance(False)
|
|
||||||
server = BGPService(nb_api)
|
server = BGPService(nb_api)
|
||||||
df_service.register_service('df-bgp-service', nb_api, server)
|
df_service.register_service('df-bgp-service', nb_api, server)
|
||||||
service.launch(cfg.CONF, server).wait()
|
service.launch(cfg.CONF, server).wait()
|
||||||
|
|||||||
@@ -147,8 +147,7 @@ class PublisherService(object):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
df_config.init(sys.argv)
|
df_config.init(sys.argv)
|
||||||
cfg.CONF.set_override('enable_df_pub_sub', False, group='df')
|
nb_api = api_nb.NbApi.get_instance(False, True)
|
||||||
nb_api = api_nb.NbApi.get_instance(False)
|
|
||||||
service = PublisherService(nb_api)
|
service = PublisherService(nb_api)
|
||||||
df_service.register_service('df-publisher-service', nb_api, service)
|
df_service.register_service('df-publisher-service', nb_api, service)
|
||||||
service.initialize()
|
service.initialize()
|
||||||
|
|||||||
@@ -60,15 +60,20 @@ class NbApi(object):
|
|||||||
self.pub_sub_use_multiproc = cfg.CONF.df.pub_sub_use_multiproc
|
self.pub_sub_use_multiproc = cfg.CONF.df.pub_sub_use_multiproc
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_instance(is_neutron_server):
|
def get_instance(is_neutron_server, is_external_app=False):
|
||||||
global _nb_api
|
global _nb_api
|
||||||
if _nb_api is None:
|
if _nb_api is None:
|
||||||
nb_driver = df_utils.load_driver(
|
nb_driver = df_utils.load_driver(
|
||||||
cfg.CONF.df.nb_db_class,
|
cfg.CONF.df.nb_db_class,
|
||||||
df_utils.DF_NB_DB_DRIVER_NAMESPACE)
|
df_utils.DF_NB_DB_DRIVER_NAMESPACE)
|
||||||
|
# Do not use pubsub for external apps - this causes issues with
|
||||||
|
# threads and other issues.
|
||||||
|
use_pubsub = cfg.CONF.df.enable_df_pub_sub
|
||||||
|
if is_external_app:
|
||||||
|
use_pubsub = False
|
||||||
nb_api = NbApi(
|
nb_api = NbApi(
|
||||||
nb_driver,
|
nb_driver,
|
||||||
use_pubsub=cfg.CONF.df.enable_df_pub_sub,
|
use_pubsub=use_pubsub,
|
||||||
is_neutron_server=is_neutron_server)
|
is_neutron_server=is_neutron_server)
|
||||||
nb_api.initialize(db_ip=cfg.CONF.df.remote_db_ip,
|
nb_api.initialize(db_ip=cfg.CONF.df.remote_db_ip,
|
||||||
db_port=cfg.CONF.df.remote_db_port)
|
db_port=cfg.CONF.df.remote_db_port)
|
||||||
|
|||||||
Reference in New Issue
Block a user