Web service around the c++ core(s). This is the navitia api front end, based on Flask.
🐍 python module
In the Norse mythology, Jörmungandr is a sea serpent that grew so large that it can surround the earth, hence his name: Midgard Serpent. He will be killed by Thor during Ragnarok.
cd navitia/source/jormungandr
mkvirtualenv -r requirements_dev.txt -p /usr/bin/python2 jormungandrJormungandr uses 2 different levels of config:
jormungandr.json: that describes Kraken's instances and coverages- Jormungandr's core config via :
- Environment variables [the prefered option]
- A custom setting file
custom_settings.py[for advanced usage] - that overwrites default settings
Create a file jormungandr.json in a custom directory like:
{
"key": "some_region",
"zmq_socket": "ipc:///tmp/default_kraken"
}You can copy the one from documentation/examples/config/Jormungandr.json
Make sure key and socket respectively match instance_name and zmq_socket from your Kraken config file (kraken.ini).
As an alternative, you can also give the json through an environment variable like:
JORMUNGANDR_INSTANCE_FR_IDF='{"key": "fr-idf","zmq_socket": "tcp://localhost:3000"}'Environment variables can be set when the service is started. Referer to default_settings.py
example for a development environment:
PYTHONPATH=..:../../navitiacommon/ JORMUNGANDR_INSTANCES_DIR=~/jormung_conf/ JORMUNGANDR_START_MONITORING_THREAD=False JORMUNGANDR_DISABLE_DATABASE=True JORMUNGANDR_IS_PUBLIC=True FLASK_APP=jormungandr:app flask runThis helps you overwrite the default settings from a file. Prevent from mixing both custom file settings and environment variables.
Use JORMUNGANDR_CONFIG_FILE to tell where your file is located like:
PYTHONPATH=..:../../navitiacommon/ JORMUNGANDR_INSTANCES_DIR=~/jormung_conf/ JORMUNGANDR_CONFIG_FILE=~/jormung_conf/jormung_settings.py FLASK_APP=jormungandr:app flask runTo run the web service, you'll need to:
- set
JORMUNGANDR_INSTANCES_DIRto point at the directory that contains yourjormungandr.json. - add
navitia/source/jormungandrandnavitia/navitiacommonto your python path viaPYTHONPATH. - [optionally] set
JORMUNGANDR_CONFIG_FILEto point at yourcustom_settings.py.
From navitia/source/jormungandr/jormungandr run :
PYTHONPATH=..:../../navitiacommon/ JORMUNGANDR_INSTANCES_DIR=~/jormung_conf/ FLASK_APP=jormungandr:app flask runSetup Jormungandr for using either Bragi or Kraken for autocompletion
JORMUNGANDR_AUTOCOMPLETE_SYSTEMS='{"kraken": { "class": "jormungandr.autocomplete.kraken.Kraken" }, "bragi": {"class": "jormungandr.autocomplete.geocodejson.GeocodeJson", "args": {"host": "http://127.0.0.1:4000", "timeout": 2}}}'You can select your autocomplete engine based on the hidden and debug-only _autocomplete parameter when querying Jormungandr:
http://localhost:5000/v1/coverage/default/places?q=rennes&_autocomplete='<kraken|bragi>'It is also possible to set the autocomplete engine for an instance by adding the following line in the config file jormungandr.json:
"default_autocomplete": "<kraken|bragi>"from jormungandr import app
ImportError: No module named jormungandr
Make sure you have navitia/source/jormungandr in your PYTHONPATH
from navitiacommon import response_pb2, type_pb2
ImportError: No module named navitiacommon
Make sure you have navitia/source/navitiacommon in your PYTHONPATH
http://localhost:5000/v1/coverage/
{"message":"No region nor coordinates given","id":"unknown_object"}}
You file jormungandr.json is not found or your key and socket don't match your kraken.ini
from flask import Flask, got_request_exception
ImportError: No module named flask
Make sure you use your jormungandr VirtualEnv with :
$ workon jormungJormungandr is trying to access a "jormungandr" database. You can disable this default behavior with JORMUNGANDR_DISABLE_DATABASE=True.
The profiling of Jormungandr is done thanks to Werkzeug profiler, for more details, one can read this interesting article, more specifically, in the Profiling section.
To enable the profiling of Jormungandr, one must set ACTIVATE_PROFILING to True in the $JORMUNGANDR_CONFIG_FILEdefault_settings.py.
Then set the correct directory(create one if not exists) for the output of profiler profile.
The profiling is triggered on every arrival of a request, so a profile file is generated when a request is processed.
To view the generated file, the following packages are needed:
- graphviz:
sudo apt install graphviz - gprof2dot:
pip install gprof2dot
Run the following command to generate and visualize the graph:
gprof2dot -f pstats <your_profiling.prof> | dot -Tsvg -o callgraph.svg | eog callgraph.svg&
Note that, in order to profile the real performance, you should activate the cpp implementation of protobuf by adding the env vars: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2 PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp.
Have fun!