Example #1
0
import ConfigParser
import os
import Queue
import socket
from threading import Lock 
from time import sleep
from bkr.common.helpers import curry, RepeatTimer
from bkr.common.bexceptions import BeakerException

can_use_qpid = True
try:
    from qpid.messaging import *
    from qpid.log import enable, DEBUG, WARN, ERROR
    from qpid import datatypes
    enable("qpid.messaging", ERROR)
except ImportError, e:
    can_use_qpid = False
    qpid_import_error = e

import logging
log = logging.getLogger(__name__)

_connection = None


class BeakerBus(object):

    # XXX Config file ?
    _reconnect = False
    _fetch_timeout = 60
Example #2
0
    password = config.get("system", "password")
except:
    password = "******"

try:
    broker = config.get("system", "broker")
except:
    broker = "localhost"

try:
    debug = config.get("system", "debug")
except:
    debug = "WARN"

if debug == "DEBUG":
    enable("qpid", DEBUG)
else:
    enable("qpid", WARN)

# This should point to the host where DCERouter/RPC-Plugin is running
connection = Connection(broker,
                        username=username,
                        password=password,
                        reconnect=True)
connection.open()
session = connection.session()
sender = session.sender("agocontrol; {create: always, node: {type: topic}}")

TCP_PORT = 6004
BUFFER_SIZE = 4096
Example #3
0
import ConfigParser
import os
import Queue
import socket
from threading import Lock 
from time import sleep
from bkr.common.helpers import curry, RepeatTimer
from bkr.common.bexceptions import BeakerException

can_use_qpid = True
try:
    from qpid.messaging import exceptions, Connection, MessagingError
    from qpid.log import enable, DEBUG, WARN, ERROR
    from qpid import datatypes
    enable("qpid.messaging", ERROR)
except ImportError, e:
    can_use_qpid = False
    qpid_import_error = e

import logging
log = logging.getLogger(__name__)

_connection = None


class BeakerBus(object):

    # XXX Config file ?
    _reconnect = False
    _fetch_timeout = 60
Example #4
0
	password = config.get("system","password")
except:
	password = "******"

try:
	broker = config.get("system","broker")
except:
	broker = "localhost"

try:
	debug = config.get("system","debug")
except:
	debug = "WARN"

if debug=="DEBUG":
	enable("qpid", DEBUG)
else:
	enable("qpid", WARN)


# This should point to the host where DCERouter/RPC-Plugin is running
connection = Connection(broker, username=username, password=password, reconnect=True)
connection.open() 
session = connection.session()
sender = session.sender("agocontrol; {create: always, node: {type: topic}}")

TCP_PORT=6004
BUFFER_SIZE=4096

class ClientThread ( threading.Thread ):
	def __init__ ( self, conn, addr ):
def main():
    conn = None
    try:
        debug = False
        print '\n Starting...'

        # Read configuration file for settings
        config = Configuration()

        # Display configuration variables
        config.settings()

        # development only
        USING_UFRAME_TEST = False
        if 'uframe-test' in config.qpid_broker:
            print '\nDevelopment - Running against uframe-test\n'
            USING_UFRAME_TEST = True
        else:
            print '\nDevelopment - Running against uframe-dev\n'


        # verify ooi-ui-services are available - if not, abort
        # todo consider security/auth access
        #headers = get_api_headers('admin', 'test')
        base_url = 'http://' + config.host + ':' + str(config.port)
        test_url = "/".join([ base_url, 'alert_alarm_definition'])
        ooi_timeout = config.ooi_timeout
        ooi_timeout_read = config.ooi_timeout_read
        try:
            response = requests.get(test_url, timeout=(ooi_timeout, ooi_timeout_read))
            if response.status_code != 200:
                message = 'Unable to connect to ooi-ui-services, aborting. status code: %s' % str(response.status_code)
                print '\n message: ', message
                raise Exception(message)

            # response_data = json.loads(response.content)
            # if 'alert_alarm_definition' not in response_data:
            #     message = 'Malformed response content from ooi-ui-services.'
            #     raise Exception(message)
            # if not response_data['alert_alarm_definition'] or response_data['alert_alarm_definition'] is None:
            #     message = 'Failed to retrieve any alert_alarm_definition(s) from ooi-ui-services.'
            #     raise Exception(message)

        except Exception as err:
            message = 'Verify configuration and availability of ooi-ui-services, aborting. Error: %s' % str(err.message)
            raise Exception(message)

        # Enable qpid DEBUG or WARN
        if config.qpid_verbose:
            enable("qpid", DEBUG)
        else:
            enable("qpid", WARN)

        timeout = config.qpid_timeout

        # Configure connection string for broker; connect to broker and start session
        conn_string = config.qpid_broker
        if config.qpid_username:
            conn_string = '{0}/{1}@{2}:{3}'.format(config.qpid_username, config.qpid_password,
                                                   config.qpid_broker, config.qpid_broker_port)
        else:
            conn_string = '{0}:{1}'.format(config.qpid_broker, 5672)
        try:
            conn = Connection(conn_string, reconnect=config.qpid_reconnect,
                                           reconnect_interval=config.qpid_reconnect_interval,
                                           reconnect_limit=config.qpid_reconnect_limit,
                                           reconnect_timeout=config.qpid_reconnect_timeout)
        except Exception, err:
            message = 'Failed to connect to qpid broker. Error: %s', err.message
            print '\n message: ', message
            raise Exception(message)


        # Configure connection and session receiver. Process available messages one at a time,
        # sending an acknowledge after each.
        conn.open()
        session = conn.session()
        receiver = session.receiver(config.qpid_address)
        url = "/".join([base_url, "alert_alarm"])
        qpid_fetch_interval = config.qpid_fetch_interval
        if qpid_fetch_interval < 1:         # config?
            qpid_fetch_interval = 3         # default value config?

        loop_on = True
        while loop_on == True:
            try:
                print '\n fetch...'
                msg = receiver.fetch(timeout=config.qpid_timeout)
                if msg is not None:
                    if debug:
                        print config.qpid_format % Formatter(msg)
                        print '\n '
                        display_all_message_contents(msg)

                    bresult = persist_system_event(msg, url, ooi_timeout, ooi_timeout_read, USING_UFRAME_TEST,
                                                   config.services_qpid_user, config.services_qpid_password)
                    if bresult:
                        print '\n Persisted system event...'
                        print ' Performing session.acknowledge()'
                        session.acknowledge()

            except Empty:
                pass
            except Exception as err:
                print "\n Exception: ", err.message

            time.sleep(qpid_fetch_interval)