From: diazb Date: Mon, 14 May 2018 22:10:31 +0000 (-0300) Subject: Adds support for vdu_name and vnf_member_index in configure_scaling X-Git-Tag: v4.0.0~3 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=2f1be6ba8722211068fb678bc1048283f275f0af;p=osm%2FMON.git Adds support for vdu_name and vnf_member_index in configure_scaling message Handles case when alarm is not registered in database Adds typing check for methods Signed-off-by: diazb Change-Id: I6a36e4abf936f0634064e3e69d95e8b5e94c7a88 --- diff --git a/policy_module/osm_policy_module/common/alarm_config.py b/policy_module/osm_policy_module/common/alarm_config.py index f22a0e6..b6586ae 100644 --- a/policy_module/osm_policy_module/common/alarm_config.py +++ b/policy_module/osm_policy_module/common/alarm_config.py @@ -24,10 +24,10 @@ class AlarmConfig: - def __init__(self, metric_name, resource_uuid, vim_uuid, threshold, operation, statistic, action): + def __init__(self, metric_name, vdu_name, vnf_member_index, threshold, operation, statistic, action): self.metric_name = metric_name - self.resource_uuid = resource_uuid - self.vim_uuid = vim_uuid + self.vdu_name = vdu_name + self.vnf_member_index = vnf_member_index self.threshold = threshold self.operation = operation self.statistic = statistic diff --git a/policy_module/osm_policy_module/common/lcm_client.py b/policy_module/osm_policy_module/common/lcm_client.py index 75e40c3..be44efe 100644 --- a/policy_module/osm_policy_module/common/lcm_client.py +++ b/policy_module/osm_policy_module/common/lcm_client.py @@ -40,13 +40,13 @@ class LcmClient: key_serializer=str.encode, value_serializer=str.encode) - def scale(self, nsr_id, name, action): + def scale(self, nsr_id: str, name: str, action: str): msg = self._create_scale_action_payload(nsr_id, name, action) log.info("Sending scale action message: %s", json.dumps(msg)) self.producer.send(topic='lcm_pm', key='trigger_scaling', value=json.dumps(msg)) self.producer.flush() - def _create_scale_action_payload(self, nsr_id, name, action): + def _create_scale_action_payload(self, nsr_id: str, name: str, action: str): msg = { "ns_id": nsr_id, "scaling_group_descriptor": { diff --git a/policy_module/osm_policy_module/common/mon_client.py b/policy_module/osm_policy_module/common/mon_client.py index 3e81757..d1336db 100644 --- a/policy_module/osm_policy_module/common/mon_client.py +++ b/policy_module/osm_policy_module/common/mon_client.py @@ -42,9 +42,11 @@ class MonClient: key_serializer=str.encode, value_serializer=str.encode) - def create_alarm(self, metric_name, resource_uuid, vim_uuid, threshold, statistic, operation): + def create_alarm(self, metric_name: str, ns_id: str, vdu_name: str, vnf_member_index: str, threshold: int, + statistic: str, operation: str): cor_id = random.randint(1, 1000000) - msg = self._create_alarm_payload(cor_id, metric_name, resource_uuid, vim_uuid, threshold, statistic, operation) + msg = self._create_alarm_payload(cor_id, metric_name, ns_id, vdu_name, vnf_member_index, threshold, statistic, + operation) log.info("Sending create_alarm_request %s", msg) future = self.producer.send(topic='alarm_request', key='create_alarm_request', value=json.dumps(msg)) future.get(timeout=60) @@ -64,12 +66,15 @@ class MonClient: raise ValueError('Timeout: No alarm creation response from MON. Is MON up?') - def _create_alarm_payload(self, cor_id, metric_name, resource_uuid, vim_uuid, threshold, statistic, operation): + def _create_alarm_payload(self, cor_id: int, metric_name: str, ns_id: str, vdu_name: str, vnf_member_index: str, + threshold: int, statistic: str, operation: str): alarm_create_request = { 'correlation_id': cor_id, 'alarm_name': str(uuid.uuid4()), 'metric_name': metric_name, - 'resource_uuid': resource_uuid, + 'ns_id': ns_id, + 'vdu_name': vdu_name, + 'vnf_member_index': vnf_member_index, 'operation': operation, 'severity': 'critical', 'threshold_value': threshold, @@ -77,7 +82,6 @@ class MonClient: } msg = { 'alarm_create_request': alarm_create_request, - 'vim_uuid': vim_uuid } return msg diff --git a/policy_module/osm_policy_module/core/agent.py b/policy_module/osm_policy_module/core/agent.py index f8f82b5..60da337 100644 --- a/policy_module/osm_policy_module/core/agent.py +++ b/policy_module/osm_policy_module/core/agent.py @@ -23,6 +23,9 @@ ## import json import logging +from typing import Dict, List + +import peewee import yaml from kafka import KafkaConsumer @@ -77,8 +80,9 @@ class PolicyModuleAgent: log.info("Creating alarm record in DB") alarm_uuid = mon_client.create_alarm( metric_name=config.metric_name, - resource_uuid=config.resource_uuid, - vim_uuid=config.vim_uuid, + ns_id=scaling_record.nsr_id, + vdu_name=config.vdu_name, + vnf_member_index=config.vnf_member_index, threshold=config.threshold, operation=config.operation, statistic=config.statistic @@ -91,15 +95,18 @@ class PolicyModuleAgent: if message.key == 'notify_alarm': content = json.loads(message.value) alarm_id = content['notify_details']['alarm_uuid'] - alarm = ScalingAlarm.select().where(ScalingAlarm.alarm_id == alarm_id).get() - if alarm: + log.info("Received alarm notification for alarm %s", alarm_id) + try: + alarm = ScalingAlarm.select().where(ScalingAlarm.alarm_id == alarm_id).get() lcm_client = LcmClient() log.info("Sending scaling action message for ns: %s", alarm_id) lcm_client.scale(alarm.scaling_record.nsr_id, alarm.scaling_record.name, alarm.action) + except ScalingAlarm.DoesNotExist: + log.info("There is no action configured for alarm %.", alarm_id) except Exception: log.exception("Error consuming message: ") - def _get_alarm_configs(self, message_content): + def _get_alarm_configs(self, message_content: Dict) -> List[AlarmConfig]: scaling_criterias = message_content['scaling_group_descriptor']['scaling_policy']['scaling_criteria'] alarm_configs = [] for criteria in scaling_criterias: @@ -109,11 +116,11 @@ class PolicyModuleAgent: scale_out_operation = criteria['scale_out_relational_operation'] scale_in_operation = criteria['scale_in_relational_operation'] statistic = criteria['monitoring_param']['aggregation_type'] - vim_uuid = '' - resource_uuid = '' + vdu_name = '' + vnf_member_index = '' if 'vdu_monitoring_param' in criteria['monitoring_param']: - vim_uuid = criteria['monitoring_param']['vdu_monitoring_param']['vim_uuid'] - resource_uuid = criteria['monitoring_param']['vdu_monitoring_param']['resource_id'] + vdu_name = criteria['monitoring_param']['vdu_monitoring_param']['vdu_name'] + vnf_member_index = criteria['monitoring_param']['vdu_monitoring_param']['vnf_member_index'] metric_name = criteria['monitoring_param']['vdu_monitoring_param']['name'] if 'vnf_metric' in criteria['monitoring_param']: # TODO vnf_metric @@ -122,15 +129,15 @@ class PolicyModuleAgent: # TODO vdu_metric continue scale_out_alarm_config = AlarmConfig(metric_name, - resource_uuid, - vim_uuid, + vdu_name, + vnf_member_index, scale_out_threshold, scale_out_operation, statistic, 'scale_out') scale_in_alarm_config = AlarmConfig(metric_name, - resource_uuid, - vim_uuid, + vdu_name, + vnf_member_index, scale_in_threshold, scale_in_operation, statistic, diff --git a/policy_module/osm_policy_module/models/configure_scaling.json b/policy_module/osm_policy_module/models/configure_scaling.json index 72e7963..0a87491 100644 --- a/policy_module/osm_policy_module/models/configure_scaling.json +++ b/policy_module/osm_policy_module/models/configure_scaling.json @@ -87,10 +87,10 @@ "vdu_monitoring_param": { "type": "object", "properties": { - "vim_uuid": { + "vnf_member_index": { "type": "string" }, - "resource_id": { + "vdu_name": { "type": "string" }, "name": { diff --git a/policy_module/osm_policy_module/tests/examples/configure_scaling_full_example.json b/policy_module/osm_policy_module/tests/examples/configure_scaling_full_example.json index be14fb4..eab1cc7 100644 --- a/policy_module/osm_policy_module/tests/examples/configure_scaling_full_example.json +++ b/policy_module/osm_policy_module/tests/examples/configure_scaling_full_example.json @@ -18,8 +18,8 @@ "name": "test_param", "aggregation_type": "average", "vdu_monitoring_param": { - "vim_uuid": "1", - "resource_id": "2d8d5355-acf7-42be-9f34-a10d02f9df39", + "vnf_member_index": "1", + "vdu_name": "2d8d5355-acf7-42be-9f34-a10d02f9df39", "name": "cpu_utilization" } }