From c77c6d999abd83235798b20d7c76e1005f7135a3 Mon Sep 17 00:00:00 2001 From: "raviteja.karumuri" Date: Thu, 2 Dec 2021 19:13:27 +0000 Subject: [PMSH] Read NFS associated with MG by using MGName and subName Issue-ID: DCAEGEN2-2993 Signed-off-by: Raviteja, Karumuri Change-Id: I651a687ab7480fc0d42bf976c3d1b34f00e73e98 --- .../pmsh_service/mod/api/controller.py | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'components/pm-subscription-handler/pmsh_service/mod/api/controller.py') diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/controller.py b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py index e852324d..aee6df0e 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/api/controller.py +++ b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py @@ -18,7 +18,7 @@ from http import HTTPStatus from mod import logger -from mod.api.services import subscription_service +from mod.api.services import subscription_service, measurement_group_service from connexion import NoContent from mod.api.custom_exception import InvalidDataException, DuplicateDataException @@ -112,3 +112,38 @@ def get_subscriptions(): logger.error(f'The following exception occurred while fetching subscriptions: {exception}') return {'error': 'Request was not processed due to Exception : ' f'{exception}'}, HTTPStatus.INTERNAL_SERVER_ERROR.value + + +def get_meas_group_with_nfs(subscription_name, measurement_group_name): + """ + Retrieves the measurement group and it's associated network functions + + Args: + subscription_name (String): Name of the subscription. + measurement_group_name (String): Name of the measurement group + + Returns: + dict, HTTPStatus: measurement group info with associated nfs, 200 + dict, HTTPStatus: measurement group was not defined, 404 + dict, HTTPStatus: Exception details of failure, 500 + """ + logger.info('API call received to query measurement group and associated network' + f' functions by using sub name: {subscription_name} and measurement ' + f'group name: {measurement_group_name}') + try: + meas_group = measurement_group_service.query_meas_group_by_name(subscription_name, + measurement_group_name) + if meas_group is not None: + return meas_group.meas_group_with_nfs(), HTTPStatus.OK.value + else: + logger.error('measurement group was not defined with the sub name: ' + f'{subscription_name} and meas group name: ' + f'{measurement_group_name}') + return {'error': 'measurement group was not defined with the sub name: ' + f'{subscription_name} and meas group name: ' + f'{measurement_group_name}'}, HTTPStatus.NOT_FOUND.value + except Exception as exception: + logger.error('The following exception occurred while fetching measurement group: ' + f'{exception}') + return {'error': 'Request was not processed due to Exception : ' + f'{exception}'}, HTTPStatus.INTERNAL_SERVER_ERROR.value -- cgit 1.2.3-korg