def collect(self, config):
        log.debug("Collect for OpenStack AMQP (%s)" % config.id)

        # During the first collect run, we spin up the AMQP listener.  After
        # that, no active collecting is done in the collect() method.
        #
        # Instead, as each message arives over the AMQP listener, it goes through
        # processMessage(), and is placed into a cache where it can be processed
        # by the onSuccess method.

        queue_key = "%s_%s" % (self.queue_name, config.id)

        if queue_key not in amqp_client:
            # Spin up the AMQP queue listener

            zcml.load_config('configure.zcml', zope.component)
            zcml.load_config('configure.zcml',
                             Products.ZenMessaging.queuemessaging)

            self._amqpConnectionInfo = getUtility(IAMQPConnectionInfo)
            self._amqpConnectionInfo_collector = AMQPConfig(
                amqphost='localhost',
                amqpport=55672,
                amqpvhost=self._amqpConnectionInfo.vhost,
                amqpuser=self._amqpConnectionInfo.user,
                amqppassword=self._amqpConnectionInfo.password,
                amqpusessl=self._amqpConnectionInfo.usessl,
                amqpconnectionheartbeat=self._amqpConnectionInfo.
                amqpconnectionheartbeat)

            self._queueSchema = getUtility(IQueueSchema)

            amqp = AMQPFactory(self._amqpConnectionInfo, self._queueSchema)
            amqp_collector = AMQPFactory(self._amqpConnectionInfo_collector,
                                         self._queueSchema)
            queue = self._queueSchema.getQueue(
                self.queue_name, replacements={'device': config.id})
            log.debug(
                "Listening on queue: %s with binding to routing key %s" %
                (queue.name, queue.bindings[self.exchange_name].routing_key))
            yield amqp.listen(queue,
                              callback=partial(self._processMessage, amqp,
                                               config.id))
            yield amqp_collector.listen(queue,
                                        callback=partial(
                                            self._processMessage,
                                            amqp_collector, config.id))
            amqp_client[queue_key] = amqp
            amqp_client[queue_key + "_collector"] = amqp_collector

            # Give time for some of the existing messages to be processed during
            # this initial collection cycle
            yield sleep(10)

        data = self.new_data()
        defer.returnValue(data)
Beispiel #2
0
    def connect_to_amqp(self):
        zcml.load_config('configure.zcml', zope.component)
        zcml.load_config('configure.zcml',
                         Products.ZenMessaging.queuemessaging)

        self._amqpConnectionInfo = getUtility(IAMQPConnectionInfo)
        self._queueSchema = getUtility(IQueueSchema)

        self.amqp = AMQPFactory(self._amqpConnectionInfo, self._queueSchema)
Beispiel #3
0
 def __init__(self, task, dmd, amqpConnectionInfo=None, queueSchema=None):
     self.dmd = dmd
     if not amqpConnectionInfo:
         amqpConnectionInfo = getUtility(IAMQPConnectionInfo)
     if not queueSchema:
         queueSchema = getUtility(IQueueSchema)
     self.consumer = AMQPFactory(amqpConnectionInfo, queueSchema)
     self.onReady = self._ready()
     if not IQueueConsumerTask.providedBy(task):
         raise AssertionError("%s does not implement IQueueConsumerTask" %
                              task)
     self.task = task
     self.task.dmd = self.dmd
     # give a reference to the consumer to the task
     self.task.queueConsumer = self
     self.shuttingDown = False
    def collect(self, config):
        log.debug("Collect for OpenStack AMQP Queue Size (%s)" % config.id)

        results = {}

        self._amqpConnectionInfo = getUtility(IAMQPConnectionInfo)
        self._queueSchema = getUtility(IQueueSchema)

        # reuse existing connectio if there is one.
        if config.id in amqp_client and amqp_client[config.id]:
            amqp = amqp_client[config.id]
        else:
            amqp = AMQPFactory(self._amqpConnectionInfo, self._queueSchema)
            yield amqp._onConnectionMade
            amqp_client[config.id] = amqp

        for queuename in (
                '$OpenStackInboundPerf',
                '$OpenStackInboundEvent',
        ):
            queue = self._queueSchema.getQueue(
                queuename, replacements={'device': config.id})
            try:
                info = yield amqp.channel.queue_declare(queue=queue.name,
                                                        passive=True)
                results[queuename] = info.fields[1]

            except txamqp.client.Closed, e:
                log.info(
                    "Unable to determine queue size for %s (queue does not exist)"
                    % queue.name)
                pass

            except Exception, e:
                log.info("Unable to determine queue size for %s (%s)" %
                         (queue.name, e))
                pass
Beispiel #5
0
 def reconnect(self):
     connectionInfo = getUtility(IAMQPConnectionInfo)
     queueSchema = getUtility(IQueueSchema)
     self._amqpClient = AMQPFactory(connectionInfo, queueSchema)