summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py
diff options
context:
space:
mode:
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py')
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py44
1 files changed, 27 insertions, 17 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py b/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py
index 74b6ac88..e74a1732 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py
@@ -22,14 +22,12 @@ from mod.subscription import AdministrativeState
class SubscriptionHandler:
- def __init__(self, administrative_state, mr_pub, app, app_conf, aai_event_thread):
- self.current_nfs = None
- self.current_sub = None
- self.administrative_state = administrative_state
+ def __init__(self, mr_pub, app, app_conf, aai_event_thread, policy_event_thread):
self.mr_pub = mr_pub
self.app = app
self.app_conf = app_conf
self.aai_event_thread = aai_event_thread
+ self.policy_event_thread = policy_event_thread
def execute(self):
"""
@@ -37,25 +35,37 @@ class SubscriptionHandler:
the Subscription if a change has occurred
"""
self.app.app_context().push()
+ local_admin_state = self.app_conf.subscription.get_local_sub_admin_state()
new_administrative_state = self.app_conf.subscription.administrativeState
try:
- if self.administrative_state == new_administrative_state:
+ if local_admin_state == new_administrative_state:
logger.info('Administrative State did not change in the Config')
else:
- self.current_nfs = aai.get_pmsh_nfs_from_aai(self.app_conf)
- self.current_sub = self.app_conf.subscription
- logger.info(f'Administrative State has changed from {self.administrative_state} '
- f'to {new_administrative_state}.')
- self.administrative_state = new_administrative_state
- self.current_sub.process_subscription(self.current_nfs, self.mr_pub, self.app_conf)
-
if new_administrative_state == AdministrativeState.UNLOCKED.value:
- logger.info('Listening to AAI-EVENT topic in MR.')
- self.aai_event_thread.start()
+ self._activate(local_admin_state, new_administrative_state)
+ elif local_admin_state == AdministrativeState.PENDING.value:
+ logger.info('Administrative State is PENDING')
else:
- logger.info('Stop listening to AAI-EVENT topic in MR.')
- self.aai_event_thread.cancel()
-
+ self._deactivate(local_admin_state, new_administrative_state)
except Exception as err:
logger.error(f'Error occurred during the activation/deactivation process {err}',
exc_info=True)
+
+ def _activate(self, local_admin_state, new_administrative_state):
+ logger.info(f'Administrative State has changed from {local_admin_state} '
+ f'to {new_administrative_state}.')
+ existing_nfs_in_aai = aai.get_pmsh_nfs_from_aai(self.app_conf)
+ self.app_conf.subscription.activate_subscription(existing_nfs_in_aai, self.mr_pub,
+ self.app_conf)
+ self.app_conf.subscription.update_subscription_status()
+ logger.info('Start listening for new NFs on AAI-EVENT topic in MR.')
+ self.aai_event_thread.start()
+ self.policy_event_thread.start()
+
+ def _deactivate(self, local_admin_state, new_administrative_state):
+ logger.info(f'Administrative State has changed from {local_admin_state} '
+ f'to {new_administrative_state}.')
+ self.aai_event_thread.cancel()
+ logger.info('Stop listening for NFs on AAI-EVENT topic in MR.')
+ self.app_conf.subscription.deactivate_subscription(self.mr_pub, self.app_conf)
+ self.app_conf.subscription.update_subscription_status()