valhalla_client/status.rs
1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashSet;
4
5#[serde_with::skip_serializing_none]
6#[derive(Serialize, Default, Debug)]
7/// Request to get the current status of the Valhalla server
8pub struct Manifest {
9 verbose: Option<bool>,
10}
11impl Manifest {
12 /// Creates a new [`Manifest`] request
13 pub fn builder() -> Self {
14 Default::default()
15 }
16
17 /// If set to `true` will add [`VerboseStatus`] to the output.
18 ///
19 /// **Note:**
20 /// Gathering this additional information can be computationally expensive.
21 /// Hence, the verbose flag can be disallowed in the configuration JSON.
22 /// See `service_limits.status.allow_verbose`, with default `false`.
23 ///
24 /// Default: `false`
25 pub fn verbose_output(mut self, verbose: bool) -> Self {
26 self.verbose = Some(verbose);
27 self
28 }
29}
30
31#[derive(Deserialize, Debug, Clone)]
32/// Response to a [`Manifest`] request
33pub struct Response {
34 /// Current Valhalla version
35 ///
36 /// Example: `3.1.4`
37 pub version: semver::Version,
38 /// Time the tile_extract or tile_dir were last modified
39 #[serde(with = "chrono::serde::ts_seconds")]
40 pub tileset_last_modified: chrono::DateTime<chrono::Utc>,
41 /// Actions which are available to a consumer.
42 ///
43 /// Can be used in applications to enable/disable parts of the UI such as an elevation map.
44 /// Example: `["expansion","height","status","trace_attributes","trace_route","optimized_route","sources_to_targets","isochrone","route","locate"]`
45 pub available_actions: HashSet<String>,
46 /// Verbose information about the deployment
47 ///
48 /// Only included if
49 /// - requested via [`Manifest::verbose_output`] (default: `false`) and
50 /// - allowed via the configuration option `service_limits.status.allow_verbose` (default: `false`)
51 #[serde(flatten)]
52 pub verbose: Option<VerboseStatus>,
53}
54#[derive(Deserialize, Debug, Clone)]
55/// Verbose information about the deployment
56pub struct VerboseStatus {
57 /// Whether a valid tileset is currently loaded
58 pub has_tiles: bool,
59 /// Whether the current tileset was built using the admin database
60 pub has_admins: bool,
61 /// Whether the current tileset was built using the timezone database
62 pub has_timezones: bool,
63 /// Whether live traffic tiles are currently available
64 pub has_live_traffic: bool,
65 /// GeoJSON of the tileset extent
66 ///
67 /// This is likely humongous, be cautions
68 pub bbox: Value,
69 /// May contain warning objects informing about
70 /// - deprecated request parameters,
71 /// - clamped values
72 /// - etc.
73 #[serde(default = "Vec::new")]
74 pub warnings: Vec<Value>,
75}
76
77#[cfg(all(test, feature = "blocking"))]
78mod tests {
79 use super::*;
80 use crate::blocking::Valhalla;
81 #[test]
82 fn test_status_verbose() {
83 let request = Manifest::builder().verbose_output(true);
84 let response = Valhalla::default().status(request).unwrap();
85 assert!(response.version >= semver::Version::parse("3.1.4").unwrap());
86 assert!(response.tileset_last_modified.timestamp() > 0);
87 let verbose = response.verbose.unwrap();
88 assert!(verbose.bbox.is_object());
89 assert!(verbose.warnings.is_empty());
90 }
91}