From 2e3c407d0fcf8c73c5fd6714d6013e37930c92cb Mon Sep 17 00:00:00 2001 From: egernug Date: Wed, 19 Aug 2020 14:57:36 +0100 Subject: [PMSH] Enhance Filtering Mechanism Issue-ID: DCAEGEN2-2151 Signed-off-by: egernug Change-Id: Ib6c207ac08a54dea06346596ff11c980fa4cf5e8 --- .../pmsh_service/mod/aai_client.py | 4 +++- .../pmsh_service/mod/aai_event_handler.py | 4 +++- .../pmsh_service/mod/network_function.py | 20 ++++++++++++++++---- .../pmsh_service/mod/pmsh_utils.py | 3 --- 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'components/pm-subscription-handler/pmsh_service') diff --git a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py index 5a3c543a..c8dea9f7 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py +++ b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py @@ -128,8 +128,10 @@ def _filter_nf_data(nf_data, nf_filter): for nf in nf_data['results']: name_identifier = 'pnf-name' if nf['node-type'] == 'pnf' else 'vnf-name' orchestration_status = nf['properties'].get('orchestration-status') + model_invariant_id = nf['properties'].get('model-invariant-id') + model_version_id = nf['properties'].get('model-version-id') if nf_filter.is_nf_in_filter(nf['properties'].get(name_identifier), - orchestration_status): + model_invariant_id, model_version_id, orchestration_status): nf_set.add(NetworkFunction( nf_name=nf['properties'].get(name_identifier), orchestration_status=orchestration_status)) diff --git a/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py b/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py index 60b69602..92369322 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py +++ b/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py @@ -59,8 +59,10 @@ def process_aai_events(mr_sub, mr_pub, app, app_conf): xnf_name = aai_entity['pnf-name'] if entity_type == XNFType.PNF.value \ else aai_entity['vnf-name'] new_status = aai_entity['orchestration-status'] + model_invariant_id = aai_entity['model-invariant-id'] + model_version_id = aai_entity['model-version-id'] - if app_conf.nf_filter.is_nf_in_filter(xnf_name, new_status): + if app_conf.nf_filter.is_nf_in_filter(xnf_name, model_invariant_id, model_version_id, new_status): _process_event(action, new_status, xnf_name, mr_pub, app_conf) except Exception as e: logger.error(f'Failed to process AAI event: {e}', exc_info=True) diff --git a/components/pm-subscription-handler/pmsh_service/mod/network_function.py b/components/pm-subscription-handler/pmsh_service/mod/network_function.py index 191e9512..62cd546f 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/network_function.py +++ b/components/pm-subscription-handler/pmsh_service/mod/network_function.py @@ -90,21 +90,33 @@ class NetworkFunction: db.session.commit() + class NetworkFunctionFilter: def __init__(self, **kwargs): - self.nf_sw_version = kwargs.get('swVersions') self.nf_names = kwargs.get('nfNames') + self.model_invariant_ids = kwargs.get('modelInvariantUUIDs') + self.model_version_ids = kwargs.get('modelVersionIDs') self.regex_matcher = re.compile('|'.join(raw_regex for raw_regex in self.nf_names)) - def is_nf_in_filter(self, nf_name, orchestration_status): + def is_nf_in_filter(self, nf_name, model_invariant_id, model_version_id, orchestration_status): """Match the nf name against regex values in Subscription.nfFilter.nfNames Args: nf_name (str): the AAI nf name. + invariant_uuid (str): the AAI model-invariant-id + uuid (str): the AAI model-version-id orchestration_status (str): orchestration status of the nf Returns: bool: True if matched, else False. """ - return self.regex_matcher.search(nf_name) and \ - orchestration_status == 'Active' + match = True + if orchestration_status != 'Active': + match = False + if self.nf_names and self.regex_matcher.search(nf_name) is None: + match = False + if self.model_invariant_ids and not model_invariant_id in self.model_invariant_ids: + match = False + if self.model_version_ids and not model_version_id in self.model_version_ids: + match = False + return match diff --git a/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py b/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py index 872843d7..fd24fca9 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py +++ b/components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py @@ -118,9 +118,6 @@ class AppConfig: raise ValueError('Failed to refresh AppConfig: INVALID JSON') self.subscription.administrativeState = app_conf['policy']['subscription'][ 'administrativeState'] - self.nf_filter.nf_names = app_conf['policy']['subscription']['nfFilter']['nfNames'] - self.nf_filter.nf_sw_version = app_conf['policy']['subscription']['nfFilter'][ - 'swVersions'] logger.info("AppConfig data has been refreshed") except ValueError or Exception as e: logger.error(e) -- cgit 1.2.3-korg