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
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": {
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)
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,
}
msg = {
'alarm_create_request': alarm_create_request,
- 'vim_uuid': vim_uuid
}
return msg
##
import json
import logging
+from typing import Dict, List
+
+import peewee
import yaml
from kafka import KafkaConsumer
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
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:
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
# 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,
"vdu_monitoring_param": {
"type": "object",
"properties": {
- "vim_uuid": {
+ "vnf_member_index": {
"type": "string"
},
- "resource_id": {
+ "vdu_name": {
"type": "string"
},
"name": {
"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"
}
}