diff options
author | 2022-02-14 13:21:34 +0000 | |
---|---|---|
committer | 2022-02-16 16:13:00 +0000 | |
commit | eabbdce7cba8c04a852cad47b0731b88030e1856 (patch) | |
tree | e67bdd896fd221f8f26f7919a62a0bf999c360b3 /components/pm-subscription-handler/pmsh_service/mod/api/controller.py | |
parent | 28b3d8f7ac48cb202b04d599b52112282a38417e (diff) |
[PMSH] Delete Measurement Group API
API to delete MG when admin status allows
Issue-ID: DCAEGEN2-2921
Signed-off-by: egernug <gerard.nugent@est.tech>
Change-Id: I4116d0096baf2f803e965385eaeac11da97ac65e
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 | 38 |
1 files changed, 38 insertions, 0 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 96fb1b79..7f4f28f5 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/api/controller.py +++ b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py @@ -22,6 +22,7 @@ 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.subscription import AdministrativeState def status(): @@ -150,6 +151,43 @@ def get_meas_group_with_nfs(subscription_name, measurement_group_name): f'{exception}'}, HTTPStatus.INTERNAL_SERVER_ERROR.value +def delete_meas_group_by_name(subscription_name, measurement_group_name): + """Deletes the measurement group by name + + Args: + subscription_name (String): Name of the subscription + measurement_group_name (String): Name of measurement group + + Returns: + NoneType, HTTPStatus: None, 204 + dict, HTTPStatus: measurement group not defined, 404 + dict, HTTPStatus: Reason for not deleting measurement group, 409 + dict, HTTPStatus: Exception details of failure, 500 + """ + logger.info(f'API call received to delete measurement group: {measurement_group_name}') + try: + 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_service.query_to_delete_meas_group(subscription_name, measurement_group_name) == 1: + return None, HTTPStatus.NO_CONTENT + else: + logger.error(f'Measurement Group not found with name {measurement_group_name}') + return {'error': f'Measurement Group not found with name {measurement_group_name}'}, \ + HTTPStatus.NOT_FOUND.value + else: + logger.error('Measurement Group was not deleted because the Administrative State ' + f'was {measurement_group_administrative_status}') + return {'error': 'Measurement Group was not deleted because the Administrative State ' + 'was {measurement_group_administrative_status}'}, \ + HTTPStatus.CONFLICT.value + except Exception as e: + logger.error(f'Try again, measurement group {measurement_group_name} was not' + f'deleted due to exception: {e}') + return {'error': f'Try again, measurement group {measurement_group_name} was not ' + f'deleted due to exception: {e}'}, HTTPStatus.INTERNAL_SERVER_ERROR.value + + def delete_subscription_by_name(subscription_name): """ Deletes the subscription by name |