diff options
author | 2020-02-27 10:05:37 +0000 | |
---|---|---|
committer | 2020-03-23 14:17:18 +0000 | |
commit | b074a929a43629a5d4ced09f1ebe4106241d776f (patch) | |
tree | ed2477888b4b5091736be7209b332ee2c43ab58b /components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py | |
parent | 06ab83c7455d6474548d63a146754748f830922c (diff) |
[PMSH] Refactor subscription processor and policy response handler
Signed-off-by: ERIMROB <robertas.rimkus@est.tech>
Change-Id: I91964848df8f7455169650b138b46d8dfc326b6f
Issue-ID: DCAEGEN2-1820
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.py | 59 |
1 files changed, 59 insertions, 0 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 new file mode 100644 index 00000000..a615aa77 --- /dev/null +++ b/components/pm-subscription-handler/pmsh_service/mod/subscription_handler.py @@ -0,0 +1,59 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2020 Nordix Foundation. +# ============================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== + +import mod.aai_client as aai +import mod.pmsh_logging as logger +from mod.subscription import AdministrativeState + + +class SubscriptionHandler: + def __init__(self, config_handler, administrative_state, mr_pub, + aai_event_thread, app, app_conf): + self.config_handler = config_handler + self.administrative_state = administrative_state + self.mr_pub = mr_pub + self.aai_event_thread = aai_event_thread + self.app = app + self.app_conf = app_conf + + def execute(self): + """ + Checks for changes of administrative state in config and proceeds to process + the Subscription if a change has occurred + """ + self.app.app_context().push() + config = self.config_handler.get_config() + new_administrative_state = config['policy']['subscription']['administrativeState'] + + try: + if self.administrative_state == new_administrative_state: + logger.debug('Administrative State did not change in the Config') + else: + sub, network_functions = aai.get_pmsh_subscription_data(config) + self.administrative_state = new_administrative_state + sub.process_subscription(network_functions, self.mr_pub, self.app_conf) + + if new_administrative_state == AdministrativeState.UNLOCKED.value: + logger.debug('Listening to AAI-EVENT topic in MR.') + self.aai_event_thread.start() + else: + logger.debug('Stop listening to AAI-EVENT topic in MR.') + self.aai_event_thread.cancel() + + except Exception as err: + logger.debug(f'Error occurred during the activation/deactivation process {err}') |