X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcore%2Fmessage_bus%2Fcommon_consumer.py;h=8f595b02a00f615f255a64e597957dbb2ec91444;hb=695d92c3f4f18d14bb18f8f0d4618c3eb5f2390e;hp=27a4188205e372233cd9fdf449ab00e0e95488e2;hpb=6439eb0e6f03b89629bbb8bad3e092133e56a614;p=osm%2FMON.git diff --git a/osm_mon/core/message_bus/common_consumer.py b/osm_mon/core/message_bus/common_consumer.py index 27a4188..8f595b0 100755 --- a/osm_mon/core/message_bus/common_consumer.py +++ b/osm_mon/core/message_bus/common_consumer.py @@ -24,18 +24,20 @@ import logging import os import sys +import yaml + logging.basicConfig(stream=sys.stdout, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) log = logging.getLogger(__name__) + sys.path.append(os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))) from kafka import KafkaConsumer from osm_mon.plugins.OpenStack.Aodh import alarming -from osm_mon.plugins.OpenStack.common import Common from osm_mon.plugins.OpenStack.Gnocchi import metrics from osm_mon.plugins.CloudWatch.plugin_alarm import plugin_alarms @@ -65,8 +67,6 @@ database_manager = DatabaseManager() database_manager.create_tables() # Create OpenStack alarming and metric instances -auth_token = None -openstack_auth = Common() openstack_metrics = metrics.Metrics() openstack_alarms = alarming.Alarming() @@ -80,12 +80,13 @@ aws_access_credentials = AccessCredentials() vrops_rcvr = plugin_receiver.PluginReceiver() -def get_vim_type(message): +def get_vim_type(vim_uuid): """Get the vim type that is required by the message.""" try: - return json.loads(message.value)["vim_type"].lower() + credentials = database_manager.get_credentials(vim_uuid) + return credentials.type except Exception as exc: - log.warn("vim_type is not configured correctly; %s", exc) + log.exception("Error getting vim_type: ") return None @@ -98,16 +99,18 @@ log.info("Listening for alarm_request and metric_request messages") for message in common_consumer: log.info("Message arrived: %s", message) try: + try: + values = json.loads(message.value) + except ValueError: + values = yaml.safe_load(message.value) # Check the message topic if message.topic == "metric_request": # Check the vim desired by the message - vim_type = get_vim_type(message) + vim_type = get_vim_type(values['vim_uuid']) if vim_type == "openstack": log.info("This message is for the OpenStack plugin.") - openstack_metrics.metric_calls( - message, openstack_auth, auth_token) - + openstack_metrics.metric_calls(message) elif vim_type == "aws": log.info("This message is for the CloudWatch plugin.") aws_conn = aws_connection.setEnvironment() @@ -123,10 +126,10 @@ for message in common_consumer: elif message.topic == "alarm_request": # Check the vim desired by the message - vim_type = get_vim_type(message) + vim_type = get_vim_type(values['vim_uuid']) if vim_type == "openstack": log.info("This message is for the OpenStack plugin.") - openstack_alarms.alarming(message, openstack_auth, auth_token) + openstack_alarms.alarming(message) elif vim_type == "aws": log.info("This message is for the CloudWatch plugin.") @@ -143,19 +146,16 @@ for message in common_consumer: elif message.topic == "vim_account": if message.key == "create" or message.key == "edit": - auth_manager.store_auth_credentials(message) + auth_manager.store_auth_credentials(values) if message.key == "delete": - auth_manager.delete_auth_credentials(message) + auth_manager.delete_auth_credentials(values) - # TODO: Remove in the near future. Modify tests accordingly. + # TODO: Remove in the near future when all plugins support vim_uuid. Modify tests accordingly. elif message.topic == "access_credentials": # Check the vim desired by the message - vim_type = get_vim_type(message) - if vim_type == "openstack": - log.info("This message is for the OpenStack plugin.") - auth_token = openstack_auth._authenticate(message=message) + vim_type = get_vim_type(values['vim_uuid']) - elif vim_type == "aws": + if vim_type == "aws": log.info("This message is for the CloudWatch plugin.") aws_access_credentials.access_credential_calls(message)