Asgard is the interface between Navitia and Valhalla. It can be used to compute street_network direct_paths and matrix.
To use Asgard with Navitia, you will need to give Jormungandr a configuration file telling Navitia to use Asgard for every street_network_modes you want. This file should be located in the INSTANCE_DIR
which is set in the default_settings.py. Here's a (not so) basic one:
{
"key": "my_instance",
"zmq_socket": "ipc:///tmp/my_instance_kraken",
"street_network": [
{
"modes": [
"car",
"walking",
"bike"
],
"class": "jormungandr.street_network.asgard.Asgard",
"args": {
"service_url": "http://localhost",
"asgard_socket": "tcp://localhost:6000",
"timeout": 2000
}
},
{
"args": {
"street_network": {
"args": {
"service_url": "http://localhost",
"asgard_socket": "tcp://localhost:6000",
"timeout": 2000
},
"class": "jormungandr.street_network.asgard.Asgard",
"modes": []
}
},
"class": "jormungandr.street_network.Taxi",
"modes": [
"taxi"
]
}
]
}
You can then run Asgard via docker or from the sources.
You can clone the repository navitia-docker-compose available here.
Then launch this command at the root directory of the repo 'navitia-docker-compose':
docker-compose -f asgard/docker-compose_asgard.yml up
You will have a running Asgard docker with data from France.
To stop the docker, launch this command at the root directory of the repo 'navitia-docker-compose':
docker-compose -f asgard/docker-compose_asgard.yml down -v
To build Asgard:
git clone https://github.com/CanalTP/asgard.git asgard
cd asgard/scripts
./build_asgard_for_ubuntu.sh -a <path_to_asgard_project>
This will build Valhalla in <path_to_asgard_project>/libvalhalla and install it in <path_to_asgard_project>/valhalla_install.
The executable of Asgard will be located in build/asgard.
Note: Already having a Valhalla library & include directory in respectively /usr/local/lib
& /usr/local/include
may lead to build errors as they currently take priority over the library & include directory specified in build_asgard_for_ubuntu.sh.
To create the data download the pfbs you want here http://download.geofabrik.de/. Then run:
./create_asgard_data.sh -e <path_to_valhalla_executables> -i <path_of_pbf_dir> -o <path_of_output_dir>
By default <path_to_valhalla_executables> will be <path_to_asgard_project>/valhalla_install/bin
To run the unit tests :
cd build/asgard
ctest
You should have now Asgard compiled and a data ready to use.
# Export var env ASGARD_VALHALLA_CONF
export ASGARD_VALHALLA_CONF=/created_data_folder/valhalla.json
# Run Asgard
cd root_project/build/asgard
./asgard
The term ouput looks like that :
~/asgard/build/asgard » ./asgard
2021/02/01 12:41:32.110373 [INFO] Using default log configuration. Logs are going to std_out
2021/02/01 12:41:32.110428 [INFO] Config: ASGARD_SOCKET_PATH=tcp://*:6000
2021/02/01 12:41:32.110432 [INFO] Config: ASGARD_CACHE_SIZE=1000000
2021/02/01 12:41:32.110434 [INFO] Config: ASGARD_NB_THREADS=3
2021/02/01 12:41:32.110436 [INFO] Config: ASGARD_METRICS_BINDING=0.0.0.0:8080
2021/02/01 12:41:32.110440 [INFO] Config: ASGARD_VALHALLA_CONF=/created_data_folder/valhalla.json
2021/02/01 12:41:32.111061 [INFO] metrics available at http://0.0.0.0:8080/metrics
2021/02/01 12:41:32.111648 [INFO] Tile extract successfully loaded with tile count: 40
Clang-format-4.0 is used to format our code. A pre-commit hook can be used to format de code before each commit. Before you can run hooks, you need to have the pre-commit package manager installed. Using pip:
pip install pre-commit
To install the pre-commit hooks just do:
pre-commit install
And if you just want to use one pre-commit hook do:
pre-commit run <hook_id>
The CI will fail if the code is not correctly formated so be careful !
There are 3 differents docker images in the project :
- asgard-build-deps : compiles and installs a specific release of Valhalla and contains all the dependencies to run Asgard.
- asgard-data : creates the configuration file to run asgard and the tiles of a specific pbf. By default it contains the tiles of the whole France.
- asgard-app : compiles and run Asgard with the data of a asgard-data container.
To run Asgard with docker :
# Data of the whole France
docker create --name asgard-data navitia/asgard-data:latest
docker run --volumes-from asgard-data --rm -it -p 6000:6000/tcp navitia/asgard-app:latest
It is possible to create an image from the asgard-data dockerfile with any pbf, tag it and create a container from that tagged image. Let's say you want to create an image from the german pbf and tag it "germany" :
cd docker/asgard-data
# Create the image and tag it "germany"
docker build --build-arg pbf_url=http://download.geofabrik.de/europe/germany-latest.osm.pbf -t navitia/asgard-data:germany .
# Create a container from this image
docker create --name asgard-data navitia/asgard-data:germany