Exemple #1
0
    def global_jormun_setup(cls):
        """
        non instance dependent jormungandr setup
        """
        if cls.global_config.get('activate_bragi', False):
            logging.info("rigging the autocomplete for {}".format(
                cls.__name__))
            # if we need a global bragi, we rig jormungandr global_autocomplete
            cls.old_global_autocompletes = deepcopy(
                jormungandr.global_autocomplete)

            # we want to keep the same address for global_autocomplete as others might have references on it
            jormungandr.global_autocomplete.clear()
            jormungandr.global_autocomplete.update({
                'bragi':
                utils.create_object({
                    'class':
                    'jormungandr.autocomplete.geocodejson.GeocodeJson',
                    'args': {
                        "host": "https://host_of_bragi"
                    },
                }),
                'kraken':
                utils.create_object(
                    {'class': 'jormungandr.autocomplete.kraken.Kraken'}),
            })
Exemple #2
0
    def __init__(self, instance, service_url, modes=None, id=None, timeout=10, api_key=None, **kwargs):
        self.instance = instance
        self.modes = modes or []
        self.sn_system_id = id or 'with_parking'
        self.parking_module = utils.create_object(kwargs.get('parking', None))
        config = kwargs.get('street_network', None)
        if 'service_url' not in config['args']:
            config['args'].update({'service_url': None})
        if 'instance' not in config['args']:
            config['args'].update({'instance': instance})

        config['args'].update({'modes': self.modes})
        self.street_network = utils.create_object(config)
Exemple #3
0
    def get_ridesharing_services(instance, ridesharing_configurations):
        logger = logging.getLogger(__name__)
        ridesharing_services = []
        for config in ridesharing_configurations:
            # Set default arguments
            if 'args' not in config:
                config['args'] = {}
            if 'service_url' not in config['args']:
                config['args'].update({'service_url': None})
            if 'instance' not in config['args']:
                config['args'].update({'instance': instance})

            try:
                service = utils.create_object(config)
            except KeyError as e:
                raise KeyError(
                    'impossible to build a ridesharing service for {}, '
                    'missing mandatory field in configuration: {}'.format(instance.name, e.message)
                )

            ridesharing_services.append(service)
            logger.info(
                '** Ridesharing: {} used for instance: {} **'.format(type(service).__name__, instance.name)
            )
        return ridesharing_services
Exemple #4
0
    def init(self, configs):
        import copy

        configs = copy.deepcopy(configs)
        if DEFAULT_PT_PLANNER not in configs:
            configs[DEFAULT_PT_PLANNER] = {
                'class': 'jormungandr.pt_planners.kraken.Kraken',
                'args': {
                    'zmq_socket': self.default_socket_path
                },
            }

        for k in configs:
            conf = configs[k]
            if not conf['args'].get('name'):
                conf['args']['name'] = self.name

            conf['args']['zmq_context'] = self.zmq_context
            conf['args']['zmq_socket_type'] = self.zmq_socket_type

        for k in configs:
            if self.old_configs.get(k) == configs[k]:
                continue

            # config has changed regarding the old one, we must close all
            # zmq sockets before opening new ones
            if k in self.pt_planners and self.pt_planners[k].is_zmq_socket():
                self.pt_planners[k].clean_up_zmq_sockets()

            self.pt_planners[k] = utils.create_object(configs[k])
            self.old_configs[k] = configs[k]
Exemple #5
0
    def get_street_network_services(instance, street_network_configurations):
        log = logging.getLogger(__name__)
        street_network_services = []
        for config in street_network_configurations:
            # Set default arguments
            if 'args' not in config:
                config['args'] = {}
            if 'service_url' not in config['args']:
                config['args'].update({'service_url': None})
            if 'instance' not in config['args']:
                config['args'].update({'instance': instance})
            # for retrocompatibility, since 'modes' was originaly outside 'args'
            if 'modes' not in config['args']:
                config['args']['modes'] = config.get('modes', [])

            try:
                service = utils.create_object(config)
            except KeyError as e:
                raise KeyError(
                    'impossible to build a StreetNetwork, missing mandatory field in configuration: {}'
                    .format(e.message))

            street_network_services.append(service)
            log.info(
                '** StreetNetwork {} used for direct_path with mode: {} **'.
                format(type(service).__name__, service.modes))
        return street_network_services
Exemple #6
0
    def get_street_network_services(instance, street_network_configurations):
        log = logging.getLogger(__name__)
        street_network_services = {}
        for config in street_network_configurations:
            # Set default arguments
            if 'args' not in config:
                config['args'] = {}
            if 'service_url' not in config['args']:
                config['args'].update({'service_url': None})
            if 'instance' not in config['args']:
                config['args'].update({'instance': instance})

            modes = config.get('modes')
            if not modes:
                raise KeyError('impossible to build a StreetNetwork, missing mandatory field in configuration: modes')

            try:
                service = utils.create_object(config)
            except KeyError as e:
                raise KeyError('impossible to build a StreetNetwork, missing mandatory field in configuration: {}'
                               .format(e.message))
            except ConfigException as e:
                raise ConfigException("impossible to build StreetNetwork, wrongly formated class: {}"
                                      .format(e))

            for mode in modes:
                street_network_services[mode] = service
                log.info('** StreetNetwork {} used for direct_path with mode: {} **'
                         .format(type(service).__name__, mode))
        return street_network_services
    def _create_backend_from_db(self, sn_backend, instance):
        # type: (StreetNetworkBackend, Instance) -> AbstractStreetNetworkService
        config = {"class": sn_backend.klass, "args": sn_backend.args}
        config['args'].setdefault('service_url', None)
        config['args'].setdefault('instance', instance)

        return utils.create_object(config)
Exemple #8
0
    def init_external_services(self):
        # Init external services from config file
        for config in self._external_service_configuration:
            # Set default arguments
            if 'args' not in config:
                config['args'] = {}
            if 'service_url' not in config['args']:
                config['args'].update({'service_url': None})
            try:
                service = utils.create_object(config)
            except KeyError as e:
                self.logger.error(
                    'Impossible to create external service with missing key: {}'
                    .format(str(e)))
                raise KeyError(
                    'Impossible to create external service with missing key: {}'
                    .format(str(e)))
            except Exception as e:
                self.logger.error(
                    'Impossible to create external service with wrong class: {}'
                    .format(str(e)))
                raise ConfigException(
                    'Impossible to create external service with wrong class: {}'
                    .format(str(e)))

            self._external_services_legacy.setdefault(
                config['navitia_service'], []).append(service)
Exemple #9
0
 def __init__(self, instance, service_url, modes=None, id=None, timeout=10, api_key=None, **kwargs):
     self.instance = instance
     self.modes = modes or [fm.FallbackModes.ridesharing.name]
     assert list(self.modes) == [fm.FallbackModes.ridesharing.name], (
         'Class: ' + str(self.__class__) + ' can only be used for ridesharing'
     )
     self.sn_system_id = id or 'ridesharing'
     config = kwargs.get('street_network', {})
     if 'service_url' not in config['args']:
         config['args'].update({'service_url': None})
     if 'instance' not in config['args']:
         config['args'].update({'instance': instance})
     config['args'].update({'modes': self.modes})
     self.street_network = utils.create_object(config)
Exemple #10
0
 def init_ridesharing_services(self):
     # Init legacy ridesharing from config file
     for config in self.ridesharing_services_configuration:
         # Set default arguments
         if 'args' not in config:
             config['args'] = {}
         if 'service_url' not in config['args']:
             config['args'].update({'service_url': None})
         try:
             service = utils.create_object(config)
         except KeyError as e:
             raise KeyError(
                 'impossible to build a ridesharing service for {}, '
                 'missing mandatory field in configuration: {}'.format(
                     self.instance.name, e.message))
         self.logger.info(
             '** Ridesharing: {} used for instance: {} **'.format(
                 type(service).__name__, self.instance.name))
         self._ridesharing_services_legacy.append(service)
    def _create_street_network_backends(self, instance,
                                        instance_configuration):
        # type: (Instance, List[Dict[str, Any]]) -> None
        for config in instance_configuration:
            # Set default arguments
            if 'args' not in config:
                config['args'] = {}

            config['args'].setdefault('service_url', None)
            config['args'].setdefault('instance', instance)
            # for retrocompatibility, since 'modes' was originaly outside 'args'
            config['args'].setdefault('modes', config.get('modes', []))

            backend = utils.create_object(config)

            self._streetnetwork_backends_by_instance_legacy[instance].append(
                backend)
            self.logger.info(
                '** StreetNetwork {} used for direct_path with mode: {} **'.
                format(type(backend).__name__, backend.modes))
Exemple #12
0
    app.logger.setLevel('INFO')

app.wsgi_app = ReverseProxied(app.wsgi_app)
got_request_exception.connect(log_exception, app)

#we want the old behavior for reqparse
compat.patch_reqparse()

rest_api = Api(app, catch_all_404s=True, serve_challenge_on_401=True)

from navitiacommon.models import db
db.init_app(app)
cache = Cache(app, config=app.config['CACHE_CONFIGURATION'])

if app.config['AUTOCOMPLETE'] is not None:
    global_autocomplete = utils.create_object(app.config['AUTOCOMPLETE']['class_path'],
                                              **app.config['AUTOCOMPLETE']['kwargs'])
else:
    global_autocomplete = None


from jormungandr.instance_manager import InstanceManager

i_manager = InstanceManager(instances_dir=app.config.get('INSTANCES_DIR', None),
                            start_ping=app.config.get('START_MONITORING_THREAD', True))
i_manager.initialisation()

from jormungandr.stat_manager import StatManager
stat_manager = StatManager()

from jormungandr.parking_space_availability.bss.bss_provider_manager import BssProviderManager
bss_provider_manager = BssProviderManager(app.config['BSS_PROVIDER'])
Exemple #13
0
app.wsgi_app = ReverseProxied(app.wsgi_app)
got_request_exception.connect(log_exception, app)

#we want the old behavior for reqparse
compat.patch_reqparse()

rest_api = Api(app, catch_all_404s=True, serve_challenge_on_401=True)

from navitiacommon.models import db
db.init_app(app)
cache = Cache(app, config=app.config['CACHE_CONFIGURATION'])

if app.config['AUTOCOMPLETE_SYSTEMS'] is not None:
    global_autocomplete = {
        k: utils.create_object(v)
        for k, v in app.config['AUTOCOMPLETE_SYSTEMS'].items()
    }
else:
    from jormungandr.autocomplete.kraken import Kraken
    global_autocomplete = {'kraken': Kraken()}

from jormungandr.instance_manager import InstanceManager

i_manager = InstanceManager(
    instances_dir=app.config.get('INSTANCES_DIR', None),
    start_ping=app.config.get('START_MONITORING_THREAD', True))
i_manager.initialisation()

from jormungandr.stat_manager import StatManager
stat_manager = StatManager()
Exemple #14
0
got_request_exception.connect(log_exception, app)

# we want the old behavior for reqparse
compat.patch_reqparse()

rest_api = Api(app, catch_all_404s=True, serve_challenge_on_401=True)

from navitiacommon.models import db

db.app = app
db.init_app(app)
cache = Cache(app, config=app.config[str('CACHE_CONFIGURATION')])  # type: Cache
memory_cache = Cache(app, config=app.config[str('MEMORY_CACHE_CONFIGURATION')])  # type: Cache

if app.config[str('AUTOCOMPLETE_SYSTEMS')] is not None:
    global_autocomplete = {k: utils.create_object(v) for k, v in app.config[str('AUTOCOMPLETE_SYSTEMS')].items()}
else:
    from jormungandr.autocomplete.kraken import Kraken

    global_autocomplete = {'kraken': Kraken()}


equipment_provider_manager = init.equipments_providers(app)


from jormungandr.instance_manager import InstanceManager

i_manager = InstanceManager(
    instances_dir=app.config.get(str('INSTANCES_DIR'), None),
    instance_filename_pattern=app.config.get(str('INSTANCES_FILENAME_PATTERN'), '*.json'),
    start_ping=app.config.get(str('START_MONITORING_THREAD'), True),