Skip to content

Commit 8b45ff7

Browse files
Lev Dragunovdanpat
authored andcommitted
Store metadata about original OSM data, and return it in the API response, if available.
1 parent 4c665b2 commit 8b45ff7

File tree

17 files changed

+104
-5
lines changed

17 files changed

+104
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- ADDED: optionally build Node `lts` and `latest` bindings [#5347](https://github.com/Project-OSRM/osrm-backend/pull/5347)
55
- Features:
66
- ADDED: new waypoints parameter to the `route` plugin, enabling silent waypoints [#5345](https://github.com/Project-OSRM/osrm-backend/pull/5345)
7+
- ADDED: data timestamp information in the response (saved in new file `.osrm.timestamp`). [#5115](https://github.com/Project-OSRM/osrm-backend/issues/5115)
78

89
# 5.21.0
910
- Changes from 5.20.0

docs/http.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ curl 'http://router.project-osrm.org/route/v1/driving/polyline(ofp_Ik_vpAilAyu@t
7070

7171
### Responses
7272

73+
#### Code
74+
7375
Every response object has a `code` property containing one of the strings below or a service dependent code:
7476

7577
| Type | Description |
@@ -87,12 +89,17 @@ Every response object has a `code` property containing one of the strings below
8789
- `message` is a **optional** human-readable error message. All other status types are service dependent.
8890
- In case of an error the HTTP status code will be `400`. Otherwise the HTTP status code will be `200` and `code` will be `Ok`.
8991

92+
#### Data version
93+
94+
Every response object has a `data_version` propetry containing timestamp from the original OpenStreetMap file. This field is optional. It can be ommited if data_version parametr was not set on osrm-extract stage or OSM file has not `osmosis_replication_timestamp` section.
95+
9096
#### Example response
9197

9298
```json
9399
{
94100
"code": "Ok",
95-
"message": "Everything worked"
101+
"message": "Everything worked",
102+
"data_version": "2017-11-17T21:43:02Z"
96103
}
97104
```
98105

features/support/shared_steps.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ module.exports = function () {
7575
got.message = json.message || '';
7676
}
7777

78+
if (headers.has('data_version')) {
79+
got.data_version = json.data_version || '';
80+
}
81+
7882
if (headers.has('#')) {
7983
// comment column
8084
got['#'] = row['#'];

features/testbot/basic.feature

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,26 @@ Feature: Basic Routing
1717
| ab |
1818

1919
When I route I should get
20-
| from | to | route |
21-
| a | b | ab,ab |
22-
| b | a | ab,ab |
20+
| from | to | route | data_version |
21+
| a | b | ab,ab | |
22+
| b | a | ab,ab | |
23+
24+
Scenario: Data_version test
25+
Given the node map
26+
"""
27+
a b
28+
"""
29+
30+
And the extract extra arguments "--data_version cucumber_data_version"
31+
32+
And the ways
33+
| nodes |
34+
| ab |
35+
36+
When I route I should get
37+
| from | to | route | data_version |
38+
| a | b | ab,ab | cucumber_data_version |
39+
| b | a | ab,ab | cucumber_data_version |
2340

2441
Scenario: Routing in between two nodes of way
2542
Given the node map

include/engine/api/route_api.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class RouteAPI : public BaseAPI
6868
response.values["waypoints"] = BaseAPI::MakeWaypoints(all_start_end_points);
6969
response.values["routes"] = std::move(jsRoutes);
7070
response.values["code"] = "Ok";
71+
auto data_timestamp = facade.GetTimestamp();
72+
if (!data_timestamp.empty())
73+
{
74+
response.values["data_version"] = data_timestamp;
75+
}
7176
}
7277

7378
protected:

include/engine/datafacade/contiguous_internalmem_datafacade.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
137137
extractor::Datasources *m_datasources;
138138

139139
std::uint32_t m_check_sum;
140+
StringView m_data_timestamp;
140141
util::vector_view<util::Coordinate> m_coordinate_list;
141142
extractor::PackedOSMIDsView m_osmnodeid_list;
142143
util::vector_view<std::uint32_t> m_lane_description_offsets;
@@ -183,6 +184,8 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
183184

184185
m_check_sum = *index.GetBlockPtr<std::uint32_t>("/common/connectivity_checksum");
185186

187+
m_data_timestamp = make_timestamp_view(index, "/common/timestamp");
188+
186189
std::tie(m_coordinate_list, m_osmnodeid_list) =
187190
make_nbn_data_view(index, "/common/nbn_data");
188191

@@ -432,6 +435,11 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
432435

433436
std::uint32_t GetCheckSum() const override final { return m_check_sum; }
434437

438+
std::string GetTimestamp() const override final
439+
{
440+
return std::string(m_data_timestamp.begin(), m_data_timestamp.end());
441+
}
442+
435443
GeometryID GetGeometryIndex(const NodeID id) const override final
436444
{
437445
return edge_based_node_data.GetGeometryID(id);

include/engine/datafacade/datafacade_base.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class BaseDataFacade
7474

7575
virtual std::uint32_t GetCheckSum() const = 0;
7676

77+
virtual std::string GetTimestamp() const = 0;
78+
7779
// node and edge information access
7880
virtual util::Coordinate GetCoordinateOfNode(const NodeID id) const = 0;
7981

include/extractor/extractor_config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct ExtractorConfig final : storage::IOConfig
5555
".osrm.geometry",
5656
".osrm.nbg_nodes",
5757
".osrm.ebg_nodes",
58+
".osrm.timestamp",
5859
".osrm.edges",
5960
".osrm.ebg",
6061
".osrm.ramIndex",
@@ -82,6 +83,7 @@ struct ExtractorConfig final : storage::IOConfig
8283
boost::filesystem::path input_path;
8384
boost::filesystem::path profile_path;
8485
std::vector<boost::filesystem::path> location_dependent_data_paths;
86+
std::string data_version;
8587

8688
unsigned requested_num_threads;
8789
unsigned small_component_size;

include/extractor/files.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ inline void writeTurnLaneData(const boost::filesystem::path &path,
308308
storage::serialization::write(writer, "/common/turn_lanes/data", turn_lane_data);
309309
}
310310

311+
// reads .osrm.timestamp
312+
template <typename TimestampDataT>
313+
inline void readTimestamp(const boost::filesystem::path &path, TimestampDataT &timestamp)
314+
{
315+
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
316+
storage::tar::FileReader reader{path, fingerprint};
317+
318+
storage::serialization::read(reader, "/common/timestamp", timestamp);
319+
}
320+
321+
// writes .osrm.timestamp
322+
template <typename TimestampDataT>
323+
inline void writeTimestamp(const boost::filesystem::path &path, const TimestampDataT &timestamp)
324+
{
325+
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
326+
storage::tar::FileWriter writer{path, fingerprint};
327+
328+
storage::serialization::write(writer, "/common/timestamp", timestamp);
329+
}
330+
311331
// reads .osrm.maneuver_overrides
312332
template <typename StorageManeuverOverrideT, typename NodeSequencesT>
313333
inline void readManeuverOverrides(const boost::filesystem::path &path,

include/storage/storage_config.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct StorageConfig final : IOConfig
5858
".osrm.turn_duration_penalties",
5959
".osrm.datasource_names",
6060
".osrm.names",
61+
".osrm.timestamp",
6162
".osrm.properties",
6263
".osrm.icd",
6364
".osrm.maneuver_overrides"},

0 commit comments

Comments
 (0)