Ejemplo n.º 1
0
def _pre_populate_workers(scheduler):
    """Loops through enabled drivers triggering each drivers pre_populate_hook
    which is a static method for each driver.

    """
    for driver in drivers.enabled_drivers():
        resources = driver.pre_populate_hook()

        if not resources:
            # just skip to the next one the drivers pre_populate_hook already
            # handled the exception or error and outputs to logs
            LOG.debug('No %s resources found to pre-populate', driver)
            continue

        LOG.debug('Start pre-populating %d workers for the %s driver',
                  len(resources),
                  driver.RESOURCE_NAME)

        for resource in resources:
            message = event.Event(
                resource=resource,
                crud=event.POLL,
                body={}
            )
            scheduler.handle_message(resource.tenant_id, message)
Ejemplo n.º 2
0
def _pre_populate_workers(scheduler):
    """Loops through enabled drivers triggering each drivers pre_populate_hook
    which is a static method for each driver.

    """
    for driver in drivers.enabled_drivers():
        resources = driver.pre_populate_hook()

        if not resources:
            # just skip to the next one the drivers pre_populate_hook already
            # handled the exception or error and outputs to logs
            LOG.debug('No %s resources found to pre-populate', driver)
            continue

        LOG.debug('Start pre-populating %d workers for the %s driver',
                  len(resources), driver.RESOURCE_NAME)

        for resource in resources:
            message = event.Event(resource=resource, crud=event.POLL, body={})
            scheduler.handle_message(resource.tenant_id, message)
Ejemplo n.º 3
0
    def info(self, ctxt, publisher_id, event_type, payload, metadata):
        tenant_id = _get_tenant_id_for_message(ctxt, payload)
        crud = event.UPDATE
        e = None
        events = []
        if event_type.startswith('akanda.rug.command'):
            LOG.debug('received a command: %r', payload)
            crud = event.COMMAND
            if payload.get('command') == commands.POLL:
                e = event.Event(
                    resource='*',
                    crud=event.POLL,
                    body={})
                self.notification_queue.put(('*', e))
                return
            else:
                # If the message does not specify a tenant, send it to everyone
                tenant_id = payload.get('tenant_id', '*')
                router_id = payload.get('router_id')
                resource = event.Resource(
                    driver='*',
                    id=router_id,
                    tenant_id=tenant_id)
                events.append(event.Event(resource, crud, payload))
        else:
            for driver in drivers.enabled_drivers():
                driver_event = driver.process_notification(
                    tenant_id, event_type, payload)
                if driver_event:
                    events.append(driver_event)

        if not events:
            LOG.debug('Could not construct any events from %s /w payload: %s',
                      event_type, payload)
            return

        LOG.debug('Generated %s events from %s /w payload: %s',
                  len(events), event_type, payload)

        for e in events:
            self.notification_queue.put((e.resource.tenant_id, e))
Ejemplo n.º 4
0
    def info(self, ctxt, publisher_id, event_type, payload, metadata):
        tenant_id = _get_tenant_id_for_message(ctxt, payload)
        crud = event.UPDATE
        e = None
        events = []
        if event_type.startswith('akanda.rug.command'):
            LOG.debug('received a command: %r', payload)
            crud = event.COMMAND
            if payload.get('command') == commands.POLL:
                e = event.Event(resource='*', crud=event.POLL, body={})
                self.notification_queue.put(('*', e))
                return
            else:
                # If the message does not specify a tenant, send it to everyone
                tenant_id = payload.get('tenant_id', '*')
                router_id = payload.get('router_id')
                resource = event.Resource(driver='*',
                                          id=router_id,
                                          tenant_id=tenant_id)
                events.append(event.Event(resource, crud, payload))
        else:
            for driver in drivers.enabled_drivers():
                driver_event = driver.process_notification(
                    tenant_id, event_type, payload)
                if driver_event:
                    events.append(driver_event)

        if not events:
            LOG.debug('Could not construct any events from %s /w payload: %s',
                      event_type, payload)
            return

        LOG.debug('Generated %s events from %s /w payload: %s', len(events),
                  event_type, payload)

        for e in events:
            self.notification_queue.put((e.resource.tenant_id, e))
Ejemplo n.º 5
0
 def test_enabled_drivers_nonexistent_left_out(self):
     all_driver_cfg = drivers.AVAILABLE_DRIVERS.keys() + ['foodriver']
     all_driver_obj = drivers.AVAILABLE_DRIVERS.values()
     self.config(enabled_drivers=all_driver_cfg)
     enabled_drivers = [d for d in drivers.enabled_drivers()]
     self.assertEqual(set(all_driver_obj), set(enabled_drivers))
Ejemplo n.º 6
0
 def test_enabled_drivers(self):
     all_driver_cfg = drivers.AVAILABLE_DRIVERS.keys()
     all_driver_obj = drivers.AVAILABLE_DRIVERS.values()
     self.config(enabled_drivers=all_driver_cfg)
     enabled_drivers = [d for d in drivers.enabled_drivers()]
     self.assertEqual(set(all_driver_obj), set(enabled_drivers))