Exemple #1
0
def find_hub_extensions(config):
    """ Return a tuple of hub extensions found in the config file. """

    possible_bases = {
        'amqp_broker': AMQPHubExtension,
        'stomp_broker': StompHubExtension,
        'zmq_enabled': ZMQHubExtension,
    }

    broker_vals = [config.get(k, None) for k in possible_bases.keys()]

    # If we're running outside of middleware and hub, load config
    if not any(broker_vals):
        config_path = get_moksha_config_path()
        if not config_path:
            raise ValueError(NO_CONFIG_MESSAGE)

        cfg = appconfig('config:' + config_path)
        config.update(cfg)
        broker_vals = [config.get(k, None) for k in possible_bases.keys()]

    # If there are no brokers defined.. that's a problem.
    if not any(broker_vals):
        raise ValueError("No messaging methods defined.")

    if len(filter(None, broker_vals)) > 1:
        log.warning("Running with multiple brokers.  "
                    "This mode is experimental and may or may not work")

    extensions = tuple(
        [b for k, b in possible_bases.items() if config.get(k, None)])
    return extensions
Exemple #2
0
def find_hub_extensions(config):
    """ Return a tuple of hub extensions found in the config file. """

    possible_bases = {
        'amqp_broker': AMQPHubExtension,
        'stomp_broker': StompHubExtension,
        'zmq_enabled': ZMQHubExtension,
    }

    broker_vals = [config.get(k, None) for k in possible_bases.keys()]

    # If we're running outside of middleware and hub, load config
    if not any(broker_vals):
        config_path = get_moksha_config_path()
        if not config_path:
            raise ValueError(NO_CONFIG_MESSAGE)

        cfg = appconfig('config:' + config_path)
        config.update(cfg)
        broker_vals = [config.get(k, None) for k in possible_bases.keys()]

    # If there are no brokers defined.. that's a problem.
    if not any(broker_vals):
        raise ValueError("No messaging methods defined.")

    if len(filter(None, broker_vals)) > 1:
        log.warning("Running with multiple brokers.  "
                    "This mode is experimental and may or may not work")

    extensions = tuple([
        b for k, b in possible_bases.items() if config.get(k, None)
    ])
    return extensions
Exemple #3
0
def main(options=None, consumers=None, producers=None, framework=True):
    """ The main MokshaHub method """

    # If we're running as a framework, then we're strictly calling other
    # people's code.  So, as the outermost piece of software in the stack, we're
    # responsible for setting up logging.
    # If we're not running as a framework, but as a library, then someone else
    # is calling us.  Therefore, we'll let them set up the logging themselves.
    if framework:
        setup_logger('-v' in sys.argv or '--verbose' in sys.argv)

    config = {}

    if not options:
        if sys.argv[-1].endswith('.ini'):
            config_path = os.path.abspath(sys.argv[-1])
        else:
            config_path = get_moksha_config_path()

        if not config_path:
            print NO_CONFIG_MESSAGE
            return

        cfg = appconfig('config:' + config_path)
        config.update(cfg)
    else:
        config.update(options)

    hub = CentralMokshaHub(config, consumers=consumers, producers=producers)
    global _hub
    _hub = hub

    def handle_signal(signum, stackframe):
        from moksha.hub.reactor import reactor
        if signum in [signal.SIGHUP, signal.SIGINT]:
            hub.stop()
            try:
                reactor.stop()
            except ReactorNotRunning:
                pass

    signal.signal(signal.SIGHUP, handle_signal)
    signal.signal(signal.SIGINT, handle_signal)

    log.info("Running the MokshaHub reactor")
    from moksha.hub.reactor import reactor
    reactor.run(installSignalHandlers=False)
    log.info("MokshaHub reactor stopped")
Exemple #4
0
    def load_configs(self):
        """ Load the configuration files for all applications.

        Here we iterate over all applications, loading their configuration
        files and merging their [DEFAULT] configuration into ours.  This
        requires that applications do not have conflicting configuration
        variable names.  To mitigate this, applications should use some basic
        variable namespacing, such as `myapp.myvariable = myvalue`.

        We first make sure to load up Moksha's configuration, for the cases
        where it is being run as WSGI middleware in a different environment.

        """
        apps = []
        loaded_configs = []
        conf_d = '/etc/moksha/conf.d/%s/'

        moksha_config_path = get_moksha_config_path()
        if moksha_config_path:
            moksha_config_path = os.path.dirname(moksha_config_path)
            apps = [{'path': moksha_config_path}]

        apps += moksha.common.utils._apps.values()
        for app in apps:
            for configfile in ('production.ini', 'development.ini'):
                for path in (app['path'], conf_d % app.get('project_name')):
                    confpath = os.path.join(path, configfile)
                    if os.path.exists(confpath):
                        conf = appconfig('config:' + confpath)
                        if app.get('name'):
                            moksha.common.utils._apps[
                                app['name']]['config'] = conf
                        if confpath in loaded_configs:
                            continue
                        log.info('Loading configuration: %s' % confpath)
                        # This is leftover from the days of using paste.deploy.appconfig.  Is anything
                        # using this?
                        #                       for entry in conf.global_conf:
                        #                           if entry.startswith('_'):
                        #                               continue
                        #                           if entry in config:
                        #                               log.warning('Conflicting variable: %s' % entry)
                        #                               continue
                        #                           else:
                        #                               config[entry] = conf.global_conf[entry]
                        #                               log.debug('Set `%s` in global config' % entry)
                        loaded_configs.append(confpath)
                        break
Exemple #5
0
    def load_configs(self):
        """ Load the configuration files for all applications.

        Here we iterate over all applications, loading their configuration
        files and merging their [DEFAULT] configuration into ours.  This
        requires that applications do not have conflicting configuration
        variable names.  To mitigate this, applications should use some basic
        variable namespacing, such as `myapp.myvariable = myvalue`.

        We first make sure to load up Moksha's configuration, for the cases
        where it is being run as WSGI middleware in a different environment.

        """
        apps = []
        loaded_configs = []
        conf_d = '/etc/moksha/conf.d/%s/'

        moksha_config_path = get_moksha_config_path()
        if moksha_config_path:
            moksha_config_path = os.path.dirname(moksha_config_path)
            apps = [{'path': moksha_config_path}]

        apps += moksha.common.utils._apps.values()
        for app in apps:
            for configfile in ('production.ini', 'development.ini'):
                for path in (app['path'], conf_d % app.get('project_name')):
                    confpath = os.path.join(path, configfile)
                    if os.path.exists(confpath):
                        conf = appconfig('config:' + confpath)
                        if app.get('name'):
                            moksha.common.utils._apps[app['name']]['config'] = conf
                        if confpath in loaded_configs:
                            continue
                        log.info('Loading configuration: %s' % confpath)
# This is leftover from the days of using paste.deploy.appconfig.  Is anything
# using this?
#                       for entry in conf.global_conf:
#                           if entry.startswith('_'):
#                               continue
#                           if entry in config:
#                               log.warning('Conflicting variable: %s' % entry)
#                               continue
#                           else:
#                               config[entry] = conf.global_conf[entry]
#                               log.debug('Set `%s` in global config' % entry)
                        loaded_configs.append(confpath)
                        break
Exemple #6
0
def main(options=None, consumers=None, producers=None):
    """ The main MokshaHub method """
    setup_logger('-v' in sys.argv or '--verbose' in sys.argv)

    config = {}

    if not options:
        if sys.argv[-1].endswith('.ini'):
            config_path = os.path.abspath(sys.argv[-1])
        else:
            config_path = get_moksha_config_path()

        if not config_path:
            print NO_CONFIG_MESSAGE
            return

        cfg = appconfig('config:' + config_path)
        config.update(cfg)
    else:
        config.update(options)

    hub = CentralMokshaHub(config, consumers=consumers, producers=producers)
    global _hub
    _hub = hub

    def handle_signal(signum, stackframe):
        from moksha.hub.reactor import reactor
        if signum in [signal.SIGHUP, signal.SIGINT]:
            hub.stop()
            try:
                reactor.stop()
            except ReactorNotRunning:
                pass

    signal.signal(signal.SIGHUP, handle_signal)
    signal.signal(signal.SIGINT, handle_signal)

    log.info("Running the MokshaHub reactor")
    from moksha.hub.reactor import reactor
    reactor.run(installSignalHandlers=False)
    log.info("MokshaHub reactor stopped")