summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/pmsh_service/mod/api
diff options
context:
space:
mode:
authorSagarS <sagar.shetty@est.tech>2021-11-09 17:36:43 +0000
committerSagarS <sagar.shetty@est.tech>2021-12-02 14:49:11 +0000
commit24454771f523f65fce5e3dce91cfe8cd15fc8be7 (patch)
tree4911a6b473cb0c2e2f566f243b95a6dd44719120 /components/pm-subscription-handler/pmsh_service/mod/api
parent7e3042157d736e1f81618b92afc3bab501755a31 (diff)
[DCAEGEN2] PMSH Response Event Handler Integration
Issue-ID: DCAEGEN2-2915 Change-Id: I95b34a7b5b011760ae30c1485925dc19fde5e6c8 Signed-off-by: SagarS <sagar.shetty@est.tech>
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/api')
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py55
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py7
2 files changed, 56 insertions, 6 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py b/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py
index 733d803e..cc07cc03 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py
@@ -18,8 +18,8 @@
from mod.api.db_models import MeasurementGroupModel, NfMeasureGroupRelationalModel
from mod import db, logger
-from mod.subscription import SubNfState
from mod.api.services import nf_service
+from mod.network_function import NetworkFunction
from mod.pmsh_config import MRTopic, AppConfig
@@ -47,18 +47,19 @@ def save_measurement_group(measurement_group, subscription_name):
return new_measurement_group
-def apply_nf_to_measgroup(nf_name, measurement_group_name):
+def apply_nf_status_to_measurement_group(nf_name, measurement_group_name, status):
"""
Associate and saves the measurement group with Network function
Args:
nf_name (string): Network function name.
measurement_group_name (string): Measurement group name
+ status (string): nf status to apply on measurement group
"""
new_nf_measure_grp_rel = NfMeasureGroupRelationalModel(
measurement_grp_name=measurement_group_name,
nf_name=nf_name,
- nf_measure_grp_status=SubNfState.PENDING_CREATE.value
+ nf_measure_grp_status=status
)
db.session.add(new_nf_measure_grp_rel)
@@ -86,3 +87,51 @@ def publish_measurement_group(sub_model, measurement_group, nf):
}
logger.debug(f'Event Body: {event_body}')
AppConfig.get_instance().publish_to_topic(MRTopic.POLICY_PM_PUBLISHER.value, event_body)
+
+
+def update_measurement_group_nf_status(measurement_group_name, status, nf_name):
+ """ Updates the status of a measurement grp for a particular nf
+
+ Args:
+ measurement_group_name (string): Measurement group name
+ nf_name (string): The network function name
+ status (string): status of the network function for measurement group
+ """
+ try:
+ logger.info(f'Performing update for measurement group name: {measurement_group_name},'
+ f' network function name: {nf_name} on status: {status}')
+ NfMeasureGroupRelationalModel.query.filter(
+ NfMeasureGroupRelationalModel.measurement_grp_name == measurement_group_name,
+ NfMeasureGroupRelationalModel.nf_name == nf_name). \
+ update({NfMeasureGroupRelationalModel.nf_measure_grp_status: status},
+ synchronize_session='evaluate')
+ db.session.commit()
+ except Exception as e:
+ logger.error(f'Failed to update nf: {nf_name} for measurement group: '
+ f'{measurement_group_name} due to: {e}')
+
+
+def delete_nf_to_measurement_group(nf_name, measurement_group_name, status):
+ """ Deletes a particular nf related to a measurement group name and
+ if no more relations of nf exist to measurement group then delete nf from PMSH
+
+ Args:
+ nf_name (string): The network function name
+ measurement_group_name (string): Measurement group name
+ status (string): status of the network function for measurement group
+ """
+ try:
+ logger.info(f'Performing delete for measurement group name: {measurement_group_name},'
+ f' network function name: {nf_name} on status: {status}')
+ nf_measurement_group_rel = NfMeasureGroupRelationalModel.query.filter(
+ NfMeasureGroupRelationalModel.measurement_grp_name == measurement_group_name,
+ NfMeasureGroupRelationalModel.nf_name == nf_name).one_or_none()
+ db.session.delete(nf_measurement_group_rel)
+ db.session.commit()
+ nf_relations = NfMeasureGroupRelationalModel.query.filter(
+ NfMeasureGroupRelationalModel.nf_name == nf_name).all()
+ if not nf_relations:
+ NetworkFunction.delete(nf_name=nf_name)
+ except Exception as e:
+ logger.error(f'Failed to delete nf: {nf_name} for measurement group: '
+ f'{measurement_group_name} due to: {e}')
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py b/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
index 96d50c27..c33c82fb 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
@@ -21,7 +21,7 @@ from mod.api.db_models import SubscriptionModel, NfSubRelationalModel, \
NetworkFunctionFilterModel, NetworkFunctionModel
from mod.api.services import measurement_group_service, nf_service
from mod.api.custom_exception import InvalidDataException, DuplicateDataException
-from mod.subscription import AdministrativeState
+from mod.subscription import AdministrativeState, SubNfState
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import joinedload
@@ -143,8 +143,9 @@ def apply_measurement_grp_to_nfs(filtered_nfs, measurement_groups):
for nf in filtered_nfs:
logger.info(f'Saving measurement group to nf name, measure_grp_name: {nf.nf_name},'
f'{measurement_group.measurement_group_name}')
- measurement_group_service.apply_nf_to_measgroup(
- nf.nf_name, measurement_group.measurement_group_name)
+ measurement_group_service.apply_nf_status_to_measurement_group(
+ nf.nf_name, measurement_group.measurement_group_name,
+ SubNfState.PENDING_CREATE.value)
else:
logger.info(f'No nfs added as measure_grp_name: '
f'{measurement_group.measurement_group_name} is LOCKED')