summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rwxr-xr-xcomponents/pm-subscription-handler/Changelog.md3
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/api/controller.py38
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml26
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py32
-rw-r--r--components/pm-subscription-handler/pom.xml2
-rw-r--r--components/pm-subscription-handler/setup.py2
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_controller.py50
-rw-r--r--components/pm-subscription-handler/version.properties4
8 files changed, 148 insertions, 9 deletions
diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md
index dedca67b..28efae05 100755
--- a/components/pm-subscription-handler/Changelog.md
+++ b/components/pm-subscription-handler/Changelog.md
@@ -5,9 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
-## [3.0.0]
+## [2.1.0]
### Changed
* Exit Handler Update (DCAEGEN2-3084)
+* Delete Measurement Group API (DCAEGEN2-2921)
## [2.0.0]
### Changed
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
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml b/components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml
index 1c4c7927..274e0ebb 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml
@@ -160,6 +160,32 @@ paths:
500:
description: Exception occurred while querying database
+ delete:
+ description: Delete a measurement group
+ operationId: mod.api.controller.delete_meas_group
+ tags:
+ - "measurement group"
+ parameters:
+ - name : subscription_name
+ in: path
+ required: true
+ description: Name of the subscription
+ type: string
+ - name: measurement_group_name
+ in: path
+ required: true
+ description: Name of the measurement group name
+ type: string
+ responses:
+ 204:
+ description: Successfully deleted the measurement group and returns NO Content
+ 404:
+ description: Measurement group with the specified name not found
+ 409:
+ description: Measurement group not deleted because state UNLOCKED OR state change to LOCKED was under process
+ 500:
+ description: Exception occurred on the server
+
/subscription/{subscription_name}/measurementGroups/{measurement_group_name}/adminState:
put:
description: Update the admin status of the Measurement Group by using sub name and measurement group name
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 a1c141f8..998c0b19 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
@@ -158,6 +158,38 @@ def query_meas_group_by_name(subscription_name, measurement_group_name):
return meas_group
+def query_to_delete_meas_group(subscription_name, measurement_group_name):
+ """
+ Deletes a measurement group by name
+
+ Args:
+ subscription_name (String): Name of the Subscription
+ measurement_group_name (String): Name of MG
+
+ Returns:
+ int: Returns '1' if subscription exists and deleted successfully else '0'
+ """
+ affected_rows = db.session.query(MeasurementGroupModel) \
+ .filter_by(subscription_name=subscription_name, measurement_group_name=measurement_group_name).delete()
+ db.session.commit()
+ return affected_rows
+
+
+def query_get_meas_group_admin_status(subscription_name, measurement_group_name):
+ """
+ Queries the administrative state by using subscription name and measurement group name
+
+ Args:
+ subscription_name (String): Name of the subscription.
+ measurement_group_name (String): Name of the measurement group
+
+ Returns:
+ administrative_state (String): Admin State (LOCKED, UNLOCKED, LOCKING)
+ """
+ meas_group = query_meas_group_by_name(subscription_name, measurement_group_name)
+ return meas_group.administrative_state
+
+
def lock_nf_to_meas_grp(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
diff --git a/components/pm-subscription-handler/pom.xml b/components/pm-subscription-handler/pom.xml
index d5f93cb8..b75fbf51 100644
--- a/components/pm-subscription-handler/pom.xml
+++ b/components/pm-subscription-handler/pom.xml
@@ -32,7 +32,7 @@
<groupId>org.onap.dcaegen2.services</groupId>
<artifactId>pmsh</artifactId>
<name>dcaegen2-services-pm-subscription-handler</name>
- <version>3.0.0-SNAPSHOT</version>
+ <version>2.1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.sources>.</sonar.sources>
diff --git a/components/pm-subscription-handler/setup.py b/components/pm-subscription-handler/setup.py
index d803d6ba..37af3307 100644
--- a/components/pm-subscription-handler/setup.py
+++ b/components/pm-subscription-handler/setup.py
@@ -22,7 +22,7 @@ from setuptools import setup, find_packages
setup(
name="pm_subscription_handler",
- version="3.0.0",
+ version="2.1.0",
packages=find_packages(),
author="lego@est.tech",
author_email="lego@est.tech",
diff --git a/components/pm-subscription-handler/tests/test_controller.py b/components/pm-subscription-handler/tests/test_controller.py
index 94bfbfd6..9c69d6d6 100755
--- a/components/pm-subscription-handler/tests/test_controller.py
+++ b/components/pm-subscription-handler/tests/test_controller.py
@@ -22,7 +22,9 @@ from http import HTTPStatus
from mod import aai_client, db
from mod.api.controller import status, post_subscription, get_subscription_by_name, \
- get_subscriptions, get_meas_group_with_nfs, delete_subscription_by_name, update_admin_state
+ get_subscriptions, get_meas_group_with_nfs, delete_subscription_by_name, update_admin_state, \
+ delete_meas_group_by_name
+from mod.api.services.measurement_group_service import query_meas_group_by_name
from tests.base_setup import BaseClassSetup
from mod.api.custom_exception import InvalidDataException, DataConflictException
from mod.api.db_models import SubscriptionModel, NfMeasureGroupRelationalModel
@@ -204,7 +206,7 @@ class ControllerTestCase(BaseClassSetup):
error, status_code = get_meas_group_with_nfs('sub1', 'MG1')
self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value)
- def test_delete_when_state_unlocked(self):
+ def test_delete_sub_when_state_unlocked(self):
subscription_unlocked_data = create_subscription_data('MG_unlocked')
subscription_unlocked_data.measurement_groups[0].measurement_group_name = 'unlock'
subscription_unlocked_data.measurement_groups[0].administrative_state = 'UNLOCKED'
@@ -217,7 +219,18 @@ class ControllerTestCase(BaseClassSetup):
self.assertEqual(subscription_service.query_subscription_by_name('MG_unlocked')
.subscription_name, 'MG_unlocked')
- def test_delete_when_state_locked(self):
+ def test_delete_mg_when_state_unlocked(self):
+ subscription_unlocked_data = create_subscription_data('MG_unlocked')
+ db.session.add(subscription_unlocked_data)
+ db.session.commit()
+ db.session.remove()
+ message, status_code = delete_meas_group_by_name('MG_unlocked', 'MG1')
+ self.assertEqual(status_code, HTTPStatus.CONFLICT.value)
+ self.assertEqual(query_meas_group_by_name('MG_unlocked', 'MG1').measurement_group_name,
+ 'MG1')
+
+
+ def test_delete_sub_when_state_locked(self):
subscription_unlocked_data = create_subscription_data('MG_locked')
subscription_unlocked_data.measurement_groups[0].measurement_group_name = 'lock'
subscription_unlocked_data.measurement_groups[0].administrative_state = 'LOCKED'
@@ -230,7 +243,19 @@ class ControllerTestCase(BaseClassSetup):
self.assertEqual(status_code, HTTPStatus.NO_CONTENT.value)
self.assertEqual(subscription_service.query_subscription_by_name('MG_locked'), None)
- def test_delete_when_state_locking(self):
+ def test_delete_mg_when_state_locked(self):
+ subscription_locked_data = create_subscription_data('MG_locked')
+ subscription_locked_data.measurement_groups[0].administrative_state = 'LOCKED'
+ db.session.add(subscription_locked_data)
+ db.session.add(subscription_locked_data.measurement_groups[0])
+ db.session.commit()
+ db.session.remove()
+ non_type, status_code = delete_meas_group_by_name('MG_locked', 'MG1')
+ self.assertEqual(non_type, None)
+ self.assertEqual(status_code, HTTPStatus.NO_CONTENT.value)
+ self.assertEqual(query_meas_group_by_name('MG_locked', 'MG1'), None)
+
+ def test_delete_sub_when_state_locking(self):
subscription_locking_data = create_subscription_data('MG_locking')
subscription_locking_data.measurement_groups[0].measurement_group_name = 'locking'
subscription_locking_data.measurement_groups[0].administrative_state = 'LOCKING'
@@ -243,11 +268,28 @@ class ControllerTestCase(BaseClassSetup):
self.assertEqual(subscription_service.query_subscription_by_name('MG_locking')
.subscription_name, 'MG_locking')
+ def test_delete_mg_when_state_locking(self):
+ subscription_locking_data = create_subscription_data('MG_locking')
+ subscription_locking_data.measurement_groups[0].administrative_state = 'LOCKING'
+ db.session.add(subscription_locking_data)
+ db.session.add(subscription_locking_data.measurement_groups[0])
+ db.session.commit()
+ db.session.remove()
+ message, status_code = delete_meas_group_by_name('MG_locking', 'MG1')
+ self.assertEqual(status_code, HTTPStatus.CONFLICT.value)
+ self.assertEqual(query_meas_group_by_name('MG_locking', 'MG1').measurement_group_name,
+ 'MG1')
+
def test_delete_sub_none(self):
message, status_code = delete_subscription_by_name('None')
self.assertEqual(message['error'], 'Subscription is not defined with name None')
self.assertEqual(status_code, HTTPStatus.NOT_FOUND.value)
+ def test_delete_mg_exception(self):
+ subscription_locking_data = create_subscription_data('MG_locking')
+ message, status_code = delete_meas_group_by_name(subscription_locking_data, 'None')
+ self.assertEqual(status_code, HTTPStatus.INTERNAL_SERVER_ERROR.value)
+
@patch('mod.api.services.subscription_service.query_to_delete_subscription_by_name',
MagicMock(side_effect=Exception('something failed')))
def test_delete_sub_exception(self):
diff --git a/components/pm-subscription-handler/version.properties b/components/pm-subscription-handler/version.properties
index 081a54a9..7a7808c0 100644
--- a/components/pm-subscription-handler/version.properties
+++ b/components/pm-subscription-handler/version.properties
@@ -1,5 +1,5 @@
-major=3
-minor=0
+major=2
+minor=1
patch=0
base_version=${major}.${minor}.${patch}
release_version=${base_version}