diff options
author | emartin <ephraim.martin@est.tech> | 2020-02-24 14:13:03 +0000 |
---|---|---|
committer | emartin <ephraim.martin@est.tech> | 2020-02-26 15:25:50 +0000 |
commit | e7f6914ca5397987eddc6788a6e378c51b12ce52 (patch) | |
tree | 1c4a1015afa1030ee3e75fdf78c282a2ce994433 /components/pm-subscription-handler/pmsh_service/pmsh_service_main.py | |
parent | de549f5f1bb3e0a6f94e9755ae0800b469114113 (diff) |
Handle AAI Update and Delete events for PMSH
Change-Id: I7f84e4429011bbaea4de23077ce23629b897fd7d
Issue-ID: DCAEGEN2-1846
Signed-off-by: emartin <ephraim.martin@est.tech>
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/pmsh_service_main.py')
-rwxr-xr-x | components/pm-subscription-handler/pmsh_service/pmsh_service_main.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py index 5c81250f..31d1d079 100755 --- a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py +++ b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py @@ -21,12 +21,14 @@ import threading import mod.aai_client as aai import mod.pmsh_logging as logger from mod import db, create_app, launch_api_server +from mod.aai_event_handler import process_aai_events from mod.config_handler import ConfigHandler -from mod.pmsh_utils import AppConfig +from mod.pmsh_utils import AppConfig, PeriodicTask from mod.subscription import Subscription, AdministrativeState -def subscription_processor(config_handler, administrative_state, mr_pub, app): +def subscription_processor(config_handler, administrative_state, mr_pub, app, + mr_aai_event_subscriber): """ Checks for changes of administrative state in config and proceeds to process the Subscription if a change has occurred @@ -36,10 +38,10 @@ def subscription_processor(config_handler, administrative_state, mr_pub, app): administrative_state (str): The administrative state mr_pub (_MrPub): MR publisher app (db): DB application + mr_aai_event_subscriber (_MrSub): AAI events MR subscriber """ app.app_context().push() config = config_handler.get_config() - sub, nfs = aai.get_pmsh_subscription_data(config) new_administrative_state = config['policy']['subscription']['administrativeState'] polling_period = 30.0 @@ -47,17 +49,29 @@ def subscription_processor(config_handler, administrative_state, mr_pub, app): if administrative_state == new_administrative_state: logger.debug('Administrative State did not change in the Config') else: + logger.debug(f'Administrative State changed from "{administrative_state}" "to ' + f'"{new_administrative_state}".') + sub, nfs = aai.get_pmsh_subscription_data(config) sub.process_subscription(nfs, mr_pub) + aai_event_thread = PeriodicTask(10, process_aai_events, args=(mr_aai_event_subscriber, + sub, mr_pub, app)) + + if new_administrative_state == AdministrativeState.UNLOCKED.value: + logger.debug('Listening to AAI-EVENT topic in MR.') + aai_event_thread.start() + else: + logger.debug('Stopping to listen to AAI-EVENT topic in MR.') + aai_event_thread.cancel() except Exception as err: logger.debug(f'Error occurred during the activation/deactivation process {err}') threading.Timer(polling_period, subscription_processor, - [config_handler, new_administrative_state, mr_pub, app]).start() + [config_handler, new_administrative_state, mr_pub, app, + mr_aai_event_subscriber]).start() def main(): - try: config_handler = ConfigHandler() config = config_handler.get_config() @@ -68,6 +82,7 @@ def main(): sub, nfs = aai.get_pmsh_subscription_data(config) mr_pub = app_conf.get_mr_pub('policy_pm_publisher') mr_sub = app_conf.get_mr_sub('policy_pm_subscriber') + mr_aai_event_subscriber = app_conf.get_mr_sub('aai_subscriber') initial_start_delay = 5.0 administrative_state = AdministrativeState.LOCKED.value @@ -76,7 +91,8 @@ def main(): administrative_state = subscription_in_db.status threading.Timer(initial_start_delay, subscription_processor, - [config_handler, administrative_state, mr_pub, app]).start() + [config_handler, administrative_state, mr_pub, + app, mr_aai_event_subscriber]).start() threading.Timer(20.0, mr_sub.poll_policy_topic, [sub.subscriptionName, app]).start() |