X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_policy_module%2Fcore%2Fagent.py;h=9867c0ccf147edb472e3f72a9c4caa5043bf56a9;hb=refs%2Ftags%2Fv12.0.0rc1;hp=95cc83073cb8d63ee582f92cc9d1b3251c847fc4;hpb=4584f8e86a492d67d120bfea1195eff1475c0a65;p=osm%2FPOL.git diff --git a/osm_policy_module/core/agent.py b/osm_policy_module/core/agent.py index 95cc830..9867c0c 100644 --- a/osm_policy_module/core/agent.py +++ b/osm_policy_module/core/agent.py @@ -30,13 +30,14 @@ import peewee from osm_policy_module.alarming.service import AlarmingService from osm_policy_module.autoscaling.service import AutoscalingService +from osm_policy_module.healing.service import HealingService from osm_policy_module.common.common_db_client import CommonDbClient from osm_policy_module.common.message_bus_client import MessageBusClient from osm_policy_module.core.config import Config log = logging.getLogger(__name__) -ALLOWED_KAFKA_KEYS = ["instantiated", "scaled", "terminated", "notify_alarm"] +ALLOWED_KAFKA_KEYS = ["instantiated", "scaled", "terminated", "notify_alarm", "policy_updated", "vnf_terminated"] class PolicyModuleAgent: @@ -49,6 +50,7 @@ class PolicyModuleAgent: self.db_client = CommonDbClient(config) self.autoscaling_service = AutoscalingService(config, loop) self.alarming_service = AlarmingService(config, loop) + self.healing_service = HealingService(config, loop) def run(self): self.loop.run_until_complete(self.start()) @@ -78,6 +80,12 @@ class PolicyModuleAgent: if key == "notify_alarm": await self._handle_alarm_notification(msg) + + if key == "policy_updated": + await self._handle_policy_update(msg) + + if key == "vnf_terminated": + await self._handle_vnf_terminated(msg) else: log.debug("Key %s is not in ALLOWED_KAFKA_KEYS", key) except peewee.PeeweeException: @@ -92,6 +100,7 @@ class PolicyModuleAgent: status = content["notify_details"]["status"] await self.autoscaling_service.handle_alarm(alarm_uuid, status) await self.alarming_service.handle_alarm(alarm_uuid, status, content) + await self.healing_service.handle_alarm(alarm_uuid, status) async def _handle_instantiated(self, content): log.debug("_handle_instantiated: %s", content) @@ -105,6 +114,7 @@ class PolicyModuleAgent: log.info("Configuring nsr_id: %s", nsr_id) await self.autoscaling_service.configure_scaling_groups(nsr_id) await self.alarming_service.configure_vnf_alarms(nsr_id) + await self.healing_service.configure_healing_alarms(nsr_id) else: log.info( "Network_service is not in COMPLETED or PARTIALLY_COMPLETED state. " @@ -125,6 +135,8 @@ class PolicyModuleAgent: await self.autoscaling_service.configure_scaling_groups(nsr_id) await self.autoscaling_service.delete_orphaned_alarms(nsr_id) await self.alarming_service.configure_vnf_alarms(nsr_id) + await self.healing_service.configure_healing_alarms(nsr_id) + await self.healing_service.delete_orphaned_healing_alarms(nsr_id) else: log.debug( "Network service is not in COMPLETED or PARTIALLY_COMPLETED state. " @@ -145,9 +157,49 @@ class PolicyModuleAgent: ) await self.autoscaling_service.delete_scaling_groups(nsr_id) await self.alarming_service.delete_vnf_alarms(nsr_id) + await self.healing_service.delete_healing_alarms(nsr_id) else: log.info( "Network service is not in COMPLETED or PARTIALLY_COMPLETED state. " "Current state is %s. Skipping...", content["operationState"], ) + + async def _handle_policy_update(self, content): + log.info("_handle_policy_update: %s", content) + nsr_id = content['nsr_id'] + vnf_member_index = content['vnf_member_index'] + if ( + content["operationState"] == "COMPLETED" + or content["operationState"] == "PARTIALLY_COMPLETED" + ): + log.info( + "Updating policies of VNF with nsr_id: %s and vnf-member-index: %s" + % (nsr_id, vnf_member_index)) + await self.autoscaling_service.delete_scaling_groups(nsr_id, vnf_member_index) + await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index) + await self.autoscaling_service.configure_scaling_groups(nsr_id, vnf_member_index) + await self.alarming_service.configure_vnf_alarms(nsr_id, vnf_member_index) + else: + log.info( + "Network service is not in COMPLETED or PARTIALLY_COMPLETED state. " + "Current state is %s. Skipping...", + content['operationState']) + + async def _handle_vnf_terminated(self, content): + nsr_id = content['nsr_id'] + vnf_member_index = content['vnf_member_index'] + if ( + content["operationState"] == "COMPLETED" + or content["operationState"] == "PARTIALLY_COMPLETED" + ): + log.info( + "Deleting policies of VNF with nsr_id: %s and vnf-member-index: %s" + % (nsr_id, vnf_member_index)) + await self.autoscaling_service.delete_scaling_groups(nsr_id, vnf_member_index) + await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index) + else: + log.info( + "Network service is not in COMPLETED or PARTIALLY_COMPLETED state. " + "Current state is %s. Skipping...", + content['operationState'])