diff options
author | 2022-02-23 13:38:34 +0000 | |
---|---|---|
committer | 2022-03-09 12:25:35 +0000 | |
commit | 36987b3ac6eccb475e9976b95a08683a86682cdc (patch) | |
tree | ff0b5a0296ef94450a04ae1b5b1701e052e27777 /components/pm-subscription-handler/pmsh_service/mod/api/controller.py | |
parent | 6c9c8cc2a1a289ef0b4172d387376d0367549fe3 (diff) |
[PMSH] Create Measurement Group API
Creates Measurement Group for an associated Subscription
POST: /subscription/{subscription_name}/measurementGroups/{measurement_group_name}
Measurement Group structure:
{
"measurementGroup": {
"measurementGroupName": "string",
"fileBasedGP": 0,
"fileLocation": "string",
"administrativeState": "LOCKED",
"measurementTypes": [
{ "measurementType": "string" }
],
"managedObjectDNsBasic": [
{ "DN": "string" }
]
}
}
Returns:
Success: 201
Invalid Data: 400 when measurement_group_name in URI and body do not match
Not Found: 404 when subscription does not exist to associate measurement group to
Duplicate Data: Measurement group with that name already exists
Error raised for any server failure
Issue-ID: DCAEGEN2-2920
Signed-off-by: egernug <gerard.nugent@est.tech>
Change-Id: I812c5a891e9bed5433000f5da24e2667bf9a5d65
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/api/controller.py')
-rwxr-xr-x | components/pm-subscription-handler/pmsh_service/mod/api/controller.py | 56 |
1 files changed, 54 insertions, 2 deletions
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 2e811c28..1aad0519 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/api/controller.py +++ b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py @@ -22,7 +22,6 @@ from mod.api.services import subscription_service, measurement_group_service from connexion import NoContent from mod.api.custom_exception import InvalidDataException, DuplicateDataException, \ DataConflictException -from mod.api.services.measurement_group_service import AdministrativeState def status(): @@ -69,6 +68,58 @@ def post_subscription(body): return response +def post_meas_group(subscription_name, measurement_group_name, body): + """ + Creates a measurement group for a subscription + + Args: + subscription_name (String): Name of the subscription. + measurement_group_name (String): Name of the measurement group + body (dict): measurement group request body to save. + + Returns: + Success : NoContent, 201 + Invalid Data: Invalid message, 400 + Not Found: Subscription no found, 404 + Duplicate Data : Duplicate field detail, 409 + + Raises: + Error: If anything fails in the server. + """ + response = NoContent, HTTPStatus.CREATED.value + try: + subscription = subscription_service.query_subscription_by_name(subscription_name) + if subscription is not None: + try: + measurement_group_service.create_measurement_group(subscription, + measurement_group_name, body) + except DuplicateDataException as e: + logger.error(f'Failed to create measurement group for ' + f'{subscription_name} due to duplicate data: {e}', + exc_info=True) + response = e.args[0], HTTPStatus.CONFLICT.value + except InvalidDataException as e: + logger.error(f'Failed to create measurement group for ' + f'{subscription_name} due to invalid data: {e}', + exc_info=True) + response = e.args[0], HTTPStatus.BAD_REQUEST.value + except Exception as e: + logger.error(f'Failed to create measurement group due to exception {e}') + response = e.args[0], HTTPStatus.INTERNAL_SERVER_ERROR.value + else: + logger.error('queried subscription was un successful with the name: ' + f'{subscription_name}') + return {'error': 'Subscription was not defined with the name : ' + f'{subscription_name}'}, HTTPStatus.NOT_FOUND.value + + except Exception as exception: + logger.error(f'While querying the subscription with name: {subscription_name}, ' + f'it occurred the following exception "{exception}"') + return {'error': 'Request was not processed due to Exception : ' + f'{exception}'}, HTTPStatus.INTERNAL_SERVER_ERROR.value + return response + + def get_subscription_by_name(subscription_name): """ Retrieves subscription based on the name @@ -169,7 +220,8 @@ def delete_meas_group_by_name(subscription_name, measurement_group_name): measurement_group_administrative_status = \ measurement_group_service.query_get_meas_group_admin_status(subscription_name, measurement_group_name) - if measurement_group_administrative_status == AdministrativeState.LOCKED.value: + if measurement_group_administrative_status == \ + measurement_group_service.AdministrativeState.LOCKED.value: if measurement_group_service.query_to_delete_meas_group(subscription_name, measurement_group_name) == 1: return None, HTTPStatus.NO_CONTENT |