Esempio n. 1
0
def publish_event(queue, routing_key, event):
    exchange_name = 'cloudify-monitoring'
    exchange_type = 'topic'
    connection = utils.create_pika_connection()
    channel = connection.channel()
    try:
        channel.exchange_declare(exchange=exchange_name,
                                 exchange_type=exchange_type,
                                 durable=False,
                                 auto_delete=True,
                                 internal=False)
        channel.queue_declare(
                queue=queue,
                auto_delete=True,
                durable=False,
                exclusive=False)
        channel.queue_bind(exchange=exchange_name,
                           queue=queue,
                           routing_key=routing_key)
        channel.basic_publish(exchange=exchange_name,
                              routing_key=routing_key,
                              body=json.dumps(event))
    finally:
        channel.close()
        connection.close()
Esempio n. 2
0
def publish_event(queue, routing_key, event):
    exchange_name = 'cloudify-monitoring'
    exchange_type = 'topic'
    connection = utils.create_pika_connection()
    channel = connection.channel()
    try:
        channel.exchange_declare(exchange=exchange_name,
                                 exchange_type=exchange_type,
                                 durable=False,
                                 auto_delete=True,
                                 internal=False)
        channel.queue_declare(
                queue=queue,
                auto_delete=True,
                durable=False,
                exclusive=False)
        channel.queue_bind(exchange=exchange_name,
                           queue=queue,
                           routing_key=routing_key)
        channel.basic_publish(exchange=exchange_name,
                              routing_key=routing_key,
                              body=json.dumps(event))
    finally:
        channel.close()
        connection.close()
    def run(self):
        """
        This function will consume logs and events directly from the
        cloudify-logs and cloudify-events exchanges. (As opposed to the usual
        means of fetching events using the REST api).

        Note: This method is only used for events/logs printing.
        Tests that need to assert on event should use the REST client events
        module.
        """
        connection = utils.create_pika_connection()
        channel = connection.channel()
        queues = []

        # Binding the logs queue
        self._bind_queue_to_exchange(channel,
                                     LOGS_EXCHANGE_NAME,
                                     'fanout',
                                     queues)

        # Binding the events queue
        self._bind_queue_to_exchange(channel,
                                     EVENTS_EXCHANGE_NAME,
                                     'topic',
                                     queues,
                                     routing_key='events.#')

        if not os.environ.get('CI'):
            cloudify.logs.EVENT_CLASS = ColorfulEvent
        cloudify.logs.EVENT_VERBOSITY_LEVEL = cloudify.event.MEDIUM_VERBOSE

        def callback(ch, method, properties, body):
            try:
                ev = json.loads(body)
                output = cloudify.logs.create_event_message_prefix(ev)
                if output:
                    sys.stdout.write('{0}\n'.format(output))
            except Exception:
                logger.error('event/log format error - output: {0}'
                             .format(body), exc_info=True)

        channel.basic_consume(callback, queue=queues[0], no_ack=True)
        channel.basic_consume(callback, queue=queues[1], no_ack=True)
        try:
            channel.start_consuming()
        except ConnectionClosed:
            pass
    def run(self):
        """
        This function will consume logs and events directly from the
        cloudify-logs and cloudify-events-topic exchanges. (As opposed to the
        usual means of fetching events using the REST api).

        Note: This method is only used for events/logs printing.
        Tests that need to assert on event should use the REST client events
        module.
        """
        connection = utils.create_pika_connection()
        channel = connection.channel()
        queues = []

        # Binding the logs queue
        self._bind_queue_to_exchange(channel,
                                     LOGS_EXCHANGE_NAME,
                                     'fanout',
                                     queues)

        # Binding the events queue
        self._bind_queue_to_exchange(channel,
                                     EVENTS_EXCHANGE_NAME,
                                     'topic',
                                     queues,
                                     routing_key='events.#')

        if not os.environ.get('CI'):
            cloudify.logs.EVENT_CLASS = ColorfulEvent
        cloudify.logs.EVENT_VERBOSITY_LEVEL = cloudify.event.MEDIUM_VERBOSE

        def callback(ch, method, properties, body):
            try:
                ev = json.loads(body)
                output = cloudify.logs.create_event_message_prefix(ev)
                if output:
                    sys.stdout.write('{0}\n'.format(output))
            except Exception:
                logger.error('event/log format error - output: {0}'
                             .format(body), exc_info=True)

        channel.basic_consume(callback, queue=queues[0], no_ack=True)
        channel.basic_consume(callback, queue=queues[1], no_ack=True)
        try:
            channel.start_consuming()
        except ConnectionClosed:
            pass
Esempio n. 5
0
def print_events(container_id):
    """Print logs and events from rabbitmq.

    This consumes directly cloudify-logs and cloudify-events-topic exchanges.
    (As opposed to the usual means of fetching events using the REST api).

    Note: This method is only used for events/logs printing.
    Tests that need to assert on event should use the REST client events
    module.
    """
    while True:
        try:
            connection = utils.create_pika_connection(container_id)
            _consume_events(connection)
        except (ConnectionClosed, StreamLostError) as e:
            logger.debug('print_events got: %s', e)
            time.sleep(3)
Esempio n. 6
0
    def run(self):
        """
        This function will consume logs and events directly from the
        cloudify-logs and cloudify-events exchanges. (As opposed to the usual
        means of fetching events using the REST api).

        Note: This method is only used for events/logs printing.
        Tests that need to assert on event should use the REST client events
        module.
        """
        connection = utils.create_pika_connection()
        channel = connection.channel()
        exchanges = ['cloudify-events', 'cloudify-logs']
        queues = []
        for exchange in exchanges:
            channel.exchange_declare(exchange=exchange,
                                     type='fanout',
                                     auto_delete=False,
                                     durable=True)
            result = channel.queue_declare(exclusive=True)
            queue_name = result.method.queue
            queues.append(queue_name)
            channel.queue_bind(exchange=exchange, queue=queue_name)

        if not os.environ.get('CI'):
            cloudify.logs.EVENT_CLASS = ColorfulEvent
        cloudify.logs.EVENT_VERBOSITY_LEVEL = cloudify.event.MEDIUM_VERBOSE

        def callback(ch, method, properties, body):
            try:
                ev = json.loads(body)
                output = cloudify.logs.create_event_message_prefix(ev)
                if output:
                    sys.stdout.write('{0}\n'.format(output))
            except Exception:
                logger.error(
                    'event/log format error - output: {0}'.format(body),
                    exc_info=True)

        channel.basic_consume(callback, queue=queues[0], no_ack=True)
        channel.basic_consume(callback, queue=queues[1], no_ack=True)
        try:
            channel.start_consuming()
        except ConnectionClosed:
            pass