summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler
diff options
context:
space:
mode:
Diffstat (limited to 'components/pm-subscription-handler')
-rwxr-xr-xcomponents/pm-subscription-handler/Changelog.md4
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/exit_handler.py27
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/pmsh_service_main.py22
-rw-r--r--components/pm-subscription-handler/pom.xml4
-rw-r--r--components/pm-subscription-handler/setup.py4
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_exit_handler.py22
-rw-r--r--components/pm-subscription-handler/version.properties2
7 files changed, 36 insertions, 49 deletions
diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md
index d2630aea..dedca67b 100755
--- a/components/pm-subscription-handler/Changelog.md
+++ b/components/pm-subscription-handler/Changelog.md
@@ -5,6 +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]
+### Changed
+* Exit Handler Update (DCAEGEN2-3084)
+
## [2.0.0]
### Changed
* Updated PMSH app configuration, simplified existing config (DCAEGEN2-2814)
diff --git a/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py b/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py
index 1ea83e59..16223790 100755
--- a/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py
@@ -1,5 +1,5 @@
# ============LICENSE_START===================================================
-# Copyright (C) 2020-2021 Nordix Foundation.
+# Copyright (C) 2020-2022 Nordix Foundation.
# ============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
# ============LICENSE_END=====================================================
from mod import logger, db
+from mod.api.services import subscription_service, measurement_group_service
from mod.subscription import AdministrativeState
@@ -25,29 +26,25 @@ class ExitHandler:
Args:
periodic_tasks (List[PeriodicTask]): PeriodicTasks that needs to be cancelled.
- app_conf (AppConfig): The PMSH Application Configuration.
- subscription_handler (SubscriptionHandler): The subscription handler instance.
"""
shutdown_signal_received = False
- def __init__(self, *, periodic_tasks, app_conf, subscription_handler):
+ def __init__(self, *, periodic_tasks):
self.periodic_tasks = periodic_tasks
- self.app_conf = app_conf
- self.subscription_handler = subscription_handler
def __call__(self, sig_num, frame):
logger.info('Graceful shutdown of PMSH initiated.')
logger.debug(f'ExitHandler was called with signal number: {sig_num}.')
- self.subscription_handler.stop_aai_event_thread()
- current_sub = self.app_conf.subscription
- if current_sub.administrativeState == AdministrativeState.UNLOCKED.value:
- try:
- nfs = self.app_conf.subscription.get_network_functions()
- current_sub.delete_subscription_from_nfs(nfs, self.subscription_handler.mr_pub,
- self.app_conf)
- except Exception as e:
- logger.error(f'Failed to shut down PMSH application: {e}', exc_info=True)
+ try:
+ subscriptions_all = subscription_service.query_all_subscriptions()
+ for subscription in subscriptions_all:
+ for mg in subscription.measurement_groups:
+ if mg.administrative_state == AdministrativeState.UNLOCKED.value:
+ measurement_group_service.\
+ update_admin_status(mg, AdministrativeState.LOCKED.value)
+ except Exception as e:
+ logger.error(f'Failed to shut down PMSH application: {e}', exc_info=True)
for thread in self.periodic_tasks:
logger.info(f'Cancelling thread {thread.name}')
thread.cancel()
diff --git a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py
index 1af01cf1..1d8b0b34 100755
--- a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py
+++ b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py
@@ -1,5 +1,5 @@
# ============LICENSE_START===================================================
-# Copyright (C) 2019-2021 Nordix Foundation.
+# Copyright (C) 2019-2022 Nordix Foundation.
# ============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -20,10 +20,9 @@ from signal import signal, SIGTERM
from mod.aai_event_handler import AAIEventHandler
from mod import db, create_app, launch_api_server, logger
from mod.exit_handler import ExitHandler
-from mod.pmsh_config import AppConfig as NewAppConfig
-from mod.pmsh_utils import AppConfig, PeriodicTask
+from mod.pmsh_config import AppConfig
+from mod.pmsh_utils import PeriodicTask
from mod.policy_response_handler import PolicyResponseHandler
-from mod.subscription_handler import SubscriptionHandler
def main():
@@ -32,10 +31,7 @@ def main():
app = create_app()
app.app_context().push()
db.create_all(app=app)
- app_conf = AppConfig()
- pmsh_app_conf = NewAppConfig()
- policy_mr_pub = app_conf.get_mr_pub('policy_pm_publisher')
- aai_event_mr_sub = app_conf.get_mr_sub('aai_subscriber')
+ pmsh_app_conf = AppConfig()
except Exception as e:
logger.error(f'Failed to get config and create application: {e}', exc_info=True)
sys.exit(e)
@@ -46,20 +42,14 @@ def main():
logger.info('Start polling PMSH_CL_INPUT topic on DMaaP MR.')
policy_response_handler_thread.start()
- subscription_handler = SubscriptionHandler(policy_mr_pub, aai_event_mr_sub, app, app_conf)
- subscription_handler_thread = PeriodicTask(20, subscription_handler.execute)
- subscription_handler_thread.name = 'sub_handler_thread'
- subscription_handler_thread.start()
-
aai_event_handler = AAIEventHandler(app)
aai_event_handler_thread = PeriodicTask(20, aai_event_handler.execute)
aai_event_handler_thread.name = 'aai_event_thread'
aai_event_handler_thread.start()
- periodic_tasks = [subscription_handler_thread, policy_response_handler_thread,
+ periodic_tasks = [policy_response_handler_thread,
aai_event_handler_thread]
- signal(SIGTERM, ExitHandler(periodic_tasks=periodic_tasks,
- app_conf=app_conf, subscription_handler=subscription_handler))
+ signal(SIGTERM, ExitHandler(periodic_tasks=periodic_tasks))
launch_api_server(pmsh_app_conf)
except Exception as e:
diff --git a/components/pm-subscription-handler/pom.xml b/components/pm-subscription-handler/pom.xml
index 89baa288..d5f93cb8 100644
--- a/components/pm-subscription-handler/pom.xml
+++ b/components/pm-subscription-handler/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
# ============LICENSE_START=======================================================
-# Copyright (C) 2019 Nordix Foundation.
+# Copyright (C) 2019-2022 Nordix Foundation.
# Copyright 2020 Deutsche Telekom. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,7 +32,7 @@
<groupId>org.onap.dcaegen2.services</groupId>
<artifactId>pmsh</artifactId>
<name>dcaegen2-services-pm-subscription-handler</name>
- <version>2.0.0-SNAPSHOT</version>
+ <version>3.0.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 d5d60401..d803d6ba 100644
--- a/components/pm-subscription-handler/setup.py
+++ b/components/pm-subscription-handler/setup.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2019-2021 Nordix Foundation.
+# Copyright (C) 2019-2022 Nordix Foundation.
# Copyright (C) 2021 AT&T Property. All rights reserved.
# Copyright 2020 Deutsche Telekom. All rights reserved.
# ================================================================================
@@ -22,7 +22,7 @@ from setuptools import setup, find_packages
setup(
name="pm_subscription_handler",
- version="2.0.0",
+ version="3.0.0",
packages=find_packages(),
author="lego@est.tech",
author_email="lego@est.tech",
diff --git a/components/pm-subscription-handler/tests/test_exit_handler.py b/components/pm-subscription-handler/tests/test_exit_handler.py
index c3cc0241..c98be634 100755
--- a/components/pm-subscription-handler/tests/test_exit_handler.py
+++ b/components/pm-subscription-handler/tests/test_exit_handler.py
@@ -1,5 +1,5 @@
# ============LICENSE_START===================================================
-# Copyright (C) 2020 Nordix Foundation.
+# Copyright (C) 2020-2022 Nordix Foundation.
# ============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,10 +17,9 @@
# ============LICENSE_END=====================================================
import os
from signal import SIGTERM, signal
-from unittest.mock import patch, Mock
+from unittest.mock import patch
from mod.exit_handler import ExitHandler
-from mod.subscription import Subscription
from tests.base_setup import BaseClassSetup
@@ -31,10 +30,11 @@ class ExitHandlerTests(BaseClassSetup):
super().setUpClass()
@patch('mod.pmsh_utils.PeriodicTask')
- def setUp(self, mock_periodic_task):
+ @patch('mod.pmsh_utils.PeriodicTask')
+ def setUp(self, mock_periodic_task_aai, mock_periodic_task_policy):
super().setUp()
- self.mock_aai_event_thread = mock_periodic_task
- self.sub = self.app_conf.subscription
+ self.mock_aai_event_thread = mock_periodic_task_aai
+ self.mock_policy_resp_handler_thread = mock_periodic_task_policy
def tearDown(self):
super().tearDown()
@@ -43,13 +43,9 @@ class ExitHandlerTests(BaseClassSetup):
def tearDownClass(cls):
super().tearDownClass()
- @patch.object(Subscription, 'update_sub_nf_status')
- @patch.object(Subscription, 'update_subscription_status')
- def test_terminate_signal_successful(self, mock_upd_sub_status,
- mock_upd_subnf_status):
- handler = ExitHandler(periodic_tasks=[self.mock_aai_event_thread],
- app_conf=self.app_conf,
- subscription_handler=Mock())
+ def test_terminate_signal_successful(self):
+ handler = ExitHandler(periodic_tasks=[self.mock_aai_event_thread,
+ self.mock_policy_resp_handler_thread])
signal(SIGTERM, handler)
os.kill(os.getpid(), SIGTERM)
self.assertTrue(ExitHandler.shutdown_signal_received)
diff --git a/components/pm-subscription-handler/version.properties b/components/pm-subscription-handler/version.properties
index 358e99ce..081a54a9 100644
--- a/components/pm-subscription-handler/version.properties
+++ b/components/pm-subscription-handler/version.properties
@@ -1,4 +1,4 @@
-major=2
+major=3
minor=0
patch=0
base_version=${major}.${minor}.${patch}