示例#1
0
 def __init__(self,
              module,
              refdes,
              event_url,
              particle_url,
              reader_klass,
              allowed,
              files,
              max_events,
              handler=None):
     version = DriverWrapper.get_version(module)
     headers = {
         'sensor': refdes,
         'deliveryType': 'streamed',
         'version': version,
         'module': module
     }
     self.max_events = max_events
     self.event_publisher = Publisher.from_url(event_url,
                                               handler=handler,
                                               headers=headers)
     self.particle_publisher = Publisher.from_url(particle_url,
                                                  handler=handler,
                                                  headers=headers,
                                                  allowed=allowed,
                                                  max_events=max_events)
     self.protocol = self.construct_protocol(module)
     self.reader = reader_klass(files, self.got_data)
示例#2
0
    def __init__(self, driver_module, driver_class, refdes, event_url,
                 particle_url, init_params):
        """
        @param driver_module The python module containing the driver code.
        @param driver_class The python driver class.
        """
        self.driver_module = driver_module
        self.driver_class = driver_class
        self.refdes = refdes
        self.event_url = event_url
        self.particle_url = particle_url
        self.driver = None
        self.messaging_started = False
        self.int_time = 0
        self.port = None
        self.init_params = init_params

        self.load_balancer = None
        self.status_thread = None
        self.particle_count = 0
        self.version = self.get_version(driver_module)

        headers = {
            'sensor': self.refdes,
            'deliveryType': 'streamed',
            'version': self.version,
            'module': driver_module
        }
        log.info('Publish headers set to: %r', headers)
        self.event_publisher = Publisher.from_url(self.event_url, headers)
        self.particle_publisher = Publisher.from_url(self.particle_url,
                                                     headers)
示例#3
0
    def __init__(self, driver_module, driver_class, refdes, event_url, particle_url, init_params):
        """
        @param driver_module The python module containing the driver code.
        @param driver_class The python driver class.
        """
        self.driver_module = driver_module
        self.driver_class = driver_class
        self.refdes = refdes
        self.event_url = event_url
        self.particle_url = particle_url
        self.driver = None
        self.messaging_started = False
        self.int_time = 0
        self.port = None
        self.init_params = init_params

        self.load_balancer = None
        self.status_thread = None
        self.particle_count = 0
        self.version = self.get_version(driver_module)

        headers = {'sensor': self.refdes, 'deliveryType': 'streamed', 'version': self.version, 'module': driver_module}
        log.info('Publish headers set to: %r', headers)
        self.event_publisher = Publisher.from_url(self.event_url, headers)
        self.particle_publisher = Publisher.from_url(self.particle_url, headers)
示例#4
0
    def __init__(self, module, refdes, event_url, particle_url, reader_klass, allowed, files):
        headers = {'sensor': refdes, 'deliveryType': 'streamed'}
        self.event_publisher = Publisher.from_url(event_url, headers)
        self.particle_publisher = Publisher.from_url(particle_url, headers, allowed)

        self.protocol = self.construct_protocol(module)
        self.reader = reader_klass(files, self.got_data)
示例#5
0
    def send_evt_msg(self):
        """
        Await events on the driver process event queue and publish them
        on a ZMQ PUB socket to the driver process client.
        """
        self.stop_evt_thread = False
        headers = {'sensor': self.refdes, 'deliveryType': 'streamed'}
        event_publisher = Publisher.from_url(self.event_url, headers)
        particle_publisher = Publisher.from_url(self.particle_url, headers)

        events = []
        particles = []

        while not self.stop_evt_thread:
            try:
                # TODO: should events be a deque?
                # TODO: should we fire this with a timer instead of a loop?
                evt = self.events.get_nowait()

                if isinstance(evt[EventKeys.VALUE], Exception):
                    evt[EventKeys.VALUE] = encode_exception(
                        evt[EventKeys.VALUE])

                if evt[EventKeys.TYPE] == DriverAsyncEvent.ERROR:
                    log.error(evt)

                if evt[EventKeys.TYPE] == DriverAsyncEvent.SAMPLE:
                    if evt[EventKeys.VALUE].get('stream_name') == 'raw':
                        # don't publish raw
                        continue
                    particles.append(evt)
                else:
                    events.append(evt)

                if len(particles) >= MAX_NUM_EVENTS:
                    particle_publisher.publish(particles)
                    particles = []

                if len(events) >= MAX_NUM_EVENTS:
                    event_publisher.publish(events)
                    events = []

            except Queue.Empty:
                if particles:
                    particle_publisher.publish(particles)
                    particles = []

                if events:
                    event_publisher.publish(events)
                    events = []

                time.sleep(PUBLISH_INTERVAL)

            except KeyboardInterrupt:
                raise

            # log all other exceptions
            except Exception as e:
                log.exception('Exception in event publishing loop: %r', e)
示例#6
0
 def __init__(self, module, refdes, event_url, particle_url, reader_klass, allowed, files, max_events, handler=None):
     version = DriverWrapper.get_version(module)
     headers = {'sensor': refdes, 'deliveryType': 'streamed', 'version': version, 'module': module}
     self.max_events = max_events
     self.event_publisher = Publisher.from_url(event_url, handler, headers)
     self.particle_publisher = Publisher.from_url(particle_url, handler, headers, allowed, max_events)
     self.protocol = self.construct_protocol(module)
     self.reader = reader_klass(files, self.got_data)
示例#7
0
    def send_evt_msg(self):
        """
        Await events on the driver process event queue and publish them
        on a ZMQ PUB socket to the driver process client.
        """
        self.stop_evt_thread = False
        headers = {'sensor': self.refdes, 'deliveryType': 'streamed'}
        event_publisher = Publisher.from_url(self.event_url, headers)
        particle_publisher = Publisher.from_url(self.particle_url, headers)

        events = []
        particles = []

        while not self.stop_evt_thread:
            try:
                # TODO: should events be a deque?
                # TODO: should we fire this with a timer instead of a loop?
                evt = self.events.get_nowait()

                if isinstance(evt[EventKeys.VALUE], Exception):
                    evt[EventKeys.VALUE] = encode_exception(evt[EventKeys.VALUE])

                if evt[EventKeys.TYPE] == DriverAsyncEvent.ERROR:
                    log.error(evt)

                if evt[EventKeys.TYPE] == DriverAsyncEvent.SAMPLE:
                    if evt[EventKeys.VALUE].get('stream_name') == 'raw':
                        # don't publish raw
                        continue
                    particles.append(evt)
                else:
                    events.append(evt)

                if len(particles) >= MAX_NUM_EVENTS:
                    particle_publisher.publish(particles)
                    particles = []

                if len(events) >= MAX_NUM_EVENTS:
                    event_publisher.publish(events)
                    events = []

            except Queue.Empty:
                if particles:
                    particle_publisher.publish(particles)
                    particles = []

                if events:
                    event_publisher.publish(events)
                    events = []

                time.sleep(PUBLISH_INTERVAL)

            except KeyboardInterrupt:
                raise

            # log all other exceptions
            except Exception as e:
                log.exception('Exception in event publishing loop: %r', e)
示例#8
0
    def __init__(self, module, refdes, event_url, particle_url, reader_klass,
                 allowed, files):
        headers = {'sensor': refdes, 'deliveryType': 'streamed'}
        self.event_publisher = Publisher.from_url(event_url, headers)
        self.particle_publisher = Publisher.from_url(particle_url, headers,
                                                     allowed)
        self.events = []
        self.particles = []

        self.protocol = self.construct_protocol(module)
        self.reader = reader_klass(files, self.got_data)
示例#9
0
 def __init__(self, config):
     self.oms_uri = config.get('oms_uri')
     self.pool_size = config.get('pool_size', DEFAULT_POOL_SIZE)
     self.thread_pool = ThreadPoolExecutor(self.pool_size)
     self.publisher = Publisher.from_url(config.get('publish_uri', 'log://'),
                                         headers=self.headers, max_events=1000, publish_interval=1)
     self.publisher.start()
     self.node_configs = []
     self._get_nodes(config)
     self.times_lock = Lock()
     self._last_times = {}
示例#10
0
def main():
    """
    This main routine will get the configuration file from the command
    line parameter and set the values for required URIs for the OMS, the
    OMS Alert Alarm Server and the qpid Server.  It will then get the qpid
    publisher for publishing the OMS events.  Finally, it will start the web
    service.
    """

    global aa_publisher

    options = docopt(__doc__)
    server_config_file = options['<server_config>']
    try:
        config = yaml.load(open(server_config_file))
    except IOError:
        log.error('Cannot find configuration file: %r', server_config_file)
        return

    try:
        oms_uri = config.get('oms_uri')
        alert_alarm_server_uri = config.get('alert_alarm_server_uri')
        qpid_uri = config.get('qpid_uri')
    except AttributeError:
        log.error('Configuration file is empty: %r', server_config_file)
        return

    if not all((oms_uri, alert_alarm_server_uri, qpid_uri)):
        log.error('Missing mandatory configuration values missing from %r',
                  server_config_file)
    else:
        headers = {'aaServerUri': alert_alarm_server_uri}

        try:
            aa_publisher = Publisher.from_url(qpid_uri, headers=headers)
            start_web_service(oms_uri, alert_alarm_server_uri)

        except Exception as ex:
            log.exception('Error starting OMS Alert and Alarm web service: %r',
                          ex)
            return
def main():
    """
    This main routine will get the configuration file from the command
    line parameter and set the values for required URIs for the OMS, the
    OMS Alert Alarm Server and the qpid Server.  It will then get the qpid
    publisher for publishing the OMS events.  Finally, it will start the web
    service.
    """

    global aa_publisher

    options = docopt(__doc__)
    server_config_file = options['<server_config>']
    try:
        config = yaml.load(open(server_config_file))
    except IOError:
        log.error('Cannot find configuration file: %r', server_config_file)
        return

    try:
        oms_uri = config.get('oms_uri')
        alert_alarm_server_uri = config.get('alert_alarm_server_uri')
        qpid_uri = config.get('qpid_uri')
    except AttributeError:
        log.error('Configuration file is empty: %r', server_config_file)
        return

    if not all((oms_uri, alert_alarm_server_uri, qpid_uri)):
        log.error('Missing mandatory configuration values missing from %r', server_config_file)
    else:
        headers = {'aaServerUri': alert_alarm_server_uri}

        try:
            aa_publisher = Publisher.from_url(qpid_uri, headers=headers)
            start_web_service(oms_uri, alert_alarm_server_uri)

        except Exception as ex:
            log.exception('Error starting OMS Alert and Alarm web service: %r', ex)
            return
示例#12
0
def main():
    """
    This main routine will get the configuration file from the command
    line parameter and set the values for required URIs for the OMS, the
    OMS Alert Alarm Server and the qpid Server.  It will then get the qpid
    publisher for publishing the OMS events.  Finally, it will start the web
    service.
    """

    global aa_publisher

    oms_uri = None
    alert_alarm_server_uri = None
    qpid_uri = None

    options = docopt(__doc__)
    server_config_file = options['<server_config>']
    config = yaml.load(open(server_config_file))

    oms_uri = config.get('oms_uri')
    alert_alarm_server_uri = config.get('alert_alarm_server_uri')
    qpid_uri = config.get('qpid_uri')

    if not all((oms_uri, alert_alarm_server_uri, qpid_uri)):
        log.error('Missing mandatory configuration values missing from ' +
                  server_config_file)
    else:
        headers = {'aaServerUri': alert_alarm_server_uri}

        try:
            aa_publisher = Publisher.from_url(qpid_uri, headers)
            start_web_service(oms_uri, alert_alarm_server_uri)

        except Exception as ex:
            log.exception('Error starting OMS Alert and Alarm web service: %r',
                          ex)

    log.info('Stopping OMS Alert & Alarm Web Service.\n')
def main():
    """
    This main routine will get the configuration file from the command
    line parameter and set the values for required URIs for the OMS, the
    OMS Alert Alarm Server and the qpid Server.  It will then get the qpid
    publisher for publishing the OMS events.  Finally, it will start the web
    service.
    """

    global aa_publisher

    oms_uri = None
    alert_alarm_server_uri = None
    qpid_uri = None

    options = docopt(__doc__)
    server_config_file = options['<server_config>']
    config = yaml.load(open(server_config_file))

    oms_uri = config.get('oms_uri')
    alert_alarm_server_uri = config.get('alert_alarm_server_uri')
    qpid_uri = config.get('qpid_uri')

    if not all((oms_uri, alert_alarm_server_uri, qpid_uri)):
        log.error('Missing mandatory configuration values missing from ' +
                  server_config_file)
    else:
        headers = {'aaServerUri': alert_alarm_server_uri}

        try:
            aa_publisher = Publisher.from_url(qpid_uri, headers)
            start_web_service(oms_uri, alert_alarm_server_uri)

        except Exception as ex:
            log.exception('Error starting OMS Alert and Alarm web service: %r',
                          ex)

    log.info('Stopping OMS Alert & Alarm Web Service.\n')