Skip to content

Commit 1066013

Browse files
Change the VersionedLayerClient code (#1537)
Change the clint to perform query requests with default additional fields. Fix the boost configuration error on Windows. Fix various clang-tidy warnings. Relates-To: OCMAM-179 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent a46dc3a commit 1066013

18 files changed

+299
-300
lines changed

external/boost/CMakeLists.txt.boost.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ExternalProject_Add(boost-download
6060
BUILD_IN_SOURCE 1
6161
UPDATE_COMMAND ""
6262
CONFIGURE_COMMAND @BOOTSTRAP_CMD@
63-
BUILD_COMMAND @B2_CMD@ headers
63+
BUILD_COMMAND "@B2_CMD@" headers
6464
INSTALL_COMMAND ""
6565
TEST_COMMAND ""
6666
)

olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp

Lines changed: 63 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ client::CancellationToken VersionedLayerClientImpl::StreamLayerPartitions(
118118
auto async_stream = std::make_shared<repository::AsyncJsonStream>();
119119

120120
auto request_task =
121-
[=](client::CancellationContext context) -> client::ApiNoResponse {
121+
[=](const client::CancellationContext& context) -> client::ApiNoResponse {
122122
auto version_response =
123123
GetVersion(boost::none, FetchOptions::OnlineIfNotFound, context);
124124
if (!version_response.IsSuccessful()) {
@@ -145,8 +145,8 @@ client::CancellationToken VersionedLayerClientImpl::StreamLayerPartitions(
145145
repository::PartitionsRepository repository(catalog_, layer_id_, settings_,
146146
lookup_client_, mutex_storage_);
147147

148-
return repository.ParsePartitionsStream(async_stream,
149-
partition_stream_callback, context);
148+
return repository.ParsePartitionsStream(
149+
async_stream, partition_stream_callback, std::move(context));
150150
};
151151

152152
auto parse_task_token =
@@ -166,14 +166,13 @@ VersionedLayerClientImpl::GetPartitions(PartitionsRequest partitions_request) {
166166
[promise](PartitionsResponse response) {
167167
promise->set_value(std::move(response));
168168
});
169-
return client::CancellableFuture<PartitionsResponse>(std::move(cancel_token),
170-
std::move(promise));
169+
return {cancel_token, std::move(promise)};
171170
}
172171

173172
client::CancellationToken VersionedLayerClientImpl::GetData(
174173
DataRequest request, DataResponseCallback callback) {
175174
auto data_task =
176-
[=](client::CancellationContext context) mutable -> DataResponse {
175+
[=](const client::CancellationContext& context) mutable -> DataResponse {
177176
if (request.GetFetchOption() == CacheWithUpdate) {
178177
return client::ApiError::InvalidArgument(
179178
"CacheWithUpdate option can not be used for versioned layer");
@@ -201,8 +200,8 @@ client::CancellationToken VersionedLayerClientImpl::GetData(
201200

202201
client::CancellationToken VersionedLayerClientImpl::QuadTreeIndex(
203202
TileRequest tile_request, PartitionsResponseCallback callback) {
204-
auto data_task =
205-
[=](client::CancellationContext context) mutable -> PartitionsResponse {
203+
auto data_task = [=](const client::CancellationContext& context) mutable
204+
-> PartitionsResponse {
206205
if (!tile_request.GetTileKey().IsValid()) {
207206
return client::ApiError::InvalidArgument("Tile key is invalid");
208207
}
@@ -224,20 +223,19 @@ client::CancellationToken VersionedLayerClientImpl::QuadTreeIndex(
224223
repository::PartitionsRepository repository(catalog_, layer_id_, settings_,
225224
lookup_client_, mutex_storage_);
226225

227-
std::vector<std::string> additional_fields = {PartitionsRequest::kChecksum,
228-
PartitionsRequest::kCrc,
229-
PartitionsRequest::kDataSize};
230-
auto partition_response = repository.GetTile(tile_request, version, context,
231-
std::move(additional_fields));
226+
static const std::vector<std::string> additional_fields = {
227+
PartitionsRequest::kChecksum, PartitionsRequest::kCrc,
228+
PartitionsRequest::kDataSize};
229+
230+
auto partition_response =
231+
repository.GetTile(tile_request, version, context, additional_fields);
232232
if (!partition_response) {
233-
return PartitionsResponse(partition_response.GetError(),
234-
partition_response.GetPayload());
233+
return {partition_response.GetError(), partition_response.GetPayload()};
235234
}
236235

237236
model::Partitions result;
238237
result.GetMutablePartitions().emplace_back(partition_response.MoveResult());
239-
return PartitionsResponse(std::move(result),
240-
partition_response.GetPayload());
238+
return {std::move(result), partition_response.GetPayload()};
241239
};
242240

243241
return task_sink_.AddTask(std::move(data_task), std::move(callback),
@@ -251,8 +249,7 @@ client::CancellableFuture<DataResponse> VersionedLayerClientImpl::GetData(
251249
GetData(std::move(data_request), [promise](DataResponse response) {
252250
promise->set_value(std::move(response));
253251
});
254-
return client::CancellableFuture<DataResponse>(std::move(cancel_token),
255-
std::move(promise));
252+
return {cancel_token, std::move(promise)};
256253
}
257254

258255
client::CancellationToken VersionedLayerClientImpl::PrefetchPartitions(
@@ -291,7 +288,7 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchPartitions(
291288
return;
292289
}
293290

294-
auto billing_tag = request.GetBillingTag();
291+
const auto& billing_tag = request.GetBillingTag();
295292

296293
auto response = GetVersion(billing_tag, OnlineIfNotFound, context);
297294

@@ -366,7 +363,8 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchPartitions(
366363
version, std::move(inner_context), true);
367364
};
368365

369-
auto append_result = [](ExtendedDataResponse response, std::string item,
366+
auto append_result = [](const ExtendedDataResponse& response,
367+
std::string item,
370368
PrefetchPartitionsResult& prefetch_result) {
371369
if (response.IsSuccessful()) {
372370
prefetch_result.AddPartition(std::move(item));
@@ -406,8 +404,7 @@ VersionedLayerClientImpl::PrefetchPartitions(
406404
promise->set_value(std::move(response));
407405
},
408406
std::move(status_callback));
409-
return client::CancellableFuture<PrefetchPartitionsResponse>(cancel_token,
410-
promise);
407+
return {cancel_token, promise};
411408
}
412409

413410
client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
@@ -420,7 +417,7 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
420417

421418
execution_context.ExecuteOrCancelled([&]() -> client::CancellationToken {
422419
return task_sink_.AddTask(
423-
[=](client::CancellationContext context) mutable -> void {
420+
[=](const client::CancellationContext& context) mutable {
424421
if (context.IsCancelled()) {
425422
callback(ApiError::Cancelled());
426423
return;
@@ -507,27 +504,28 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
507504
}
508505
};
509506

510-
auto query = [=](geo::TileKey root,
511-
client::CancellationContext inner_context) mutable {
512-
auto response = repository.GetVersionedSubQuads(
513-
root, kQuadTreeDepth, version, inner_context);
514-
515-
if (response.IsSuccessful() && aggregation_enabled) {
516-
const auto& tiles = response.GetResult();
517-
auto network_stats = repository.LoadAggregatedSubQuads(
518-
root,
519-
request_only_input_tiles
520-
? repository.FilterTileKeysByList(request, tiles)
521-
: repository.FilterTileKeysByLevel(request, tiles),
522-
version, inner_context);
523-
524-
// append network statistics
525-
network_stats += GetNetworkStatistics(response);
526-
response = {response.MoveResult(), network_stats};
527-
}
507+
auto query =
508+
[=](geo::TileKey root,
509+
const client::CancellationContext& inner_context) mutable {
510+
auto response = repository.GetVersionedSubQuads(
511+
root, kQuadTreeDepth, version, inner_context);
512+
513+
if (response.IsSuccessful() && aggregation_enabled) {
514+
const auto& tiles = response.GetResult();
515+
auto network_stats = repository.LoadAggregatedSubQuads(
516+
root,
517+
request_only_input_tiles
518+
? repository.FilterTileKeysByList(request, tiles)
519+
: repository.FilterTileKeysByLevel(request, tiles),
520+
version, inner_context);
521+
522+
// append network statistics
523+
network_stats += GetNetworkStatistics(response);
524+
response = {response.MoveResult(), network_stats};
525+
}
528526

529-
return response;
530-
};
527+
return response;
528+
};
531529

532530
auto& billing_tag = request.GetBillingTag();
533531

@@ -569,10 +567,10 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
569567
return root.first;
570568
});
571569

572-
auto append_result = [](ExtendedDataResponse response,
570+
auto append_result = [](const ExtendedDataResponse& response,
573571
geo::TileKey item,
574572
PrefetchTilesResult& prefetch_result) {
575-
if (response.IsSuccessful()) {
573+
if (response) {
576574
prefetch_result.emplace_back(std::make_shared<PrefetchTileResult>(
577575
item, PrefetchTileNoError()));
578576
} else {
@@ -587,7 +585,7 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
587585
std::move(callback), std::move(status_callback));
588586

589587
return PrefetchTilesHelper::Prefetch(
590-
std::move(download_job), std::move(roots), std::move(query),
588+
std::move(download_job), roots, std::move(query),
591589
std::move(filter), task_sink_, request.GetPriority(),
592590
execution_context);
593591
},
@@ -607,8 +605,7 @@ VersionedLayerClientImpl::PrefetchTiles(
607605
promise->set_value(std::move(response));
608606
},
609607
std::move(status_callback));
610-
return client::CancellableFuture<PrefetchTilesResponse>(cancel_token,
611-
promise);
608+
return {cancel_token, promise};
612609
}
613610

614611
CatalogVersionResponse VersionedLayerClientImpl::GetVersion(
@@ -678,8 +675,7 @@ client::CancellableFuture<DataResponse> VersionedLayerClientImpl::GetData(
678675
GetData(std::move(request), [promise](DataResponse response) {
679676
promise->set_value(std::move(response));
680677
});
681-
return client::CancellableFuture<DataResponse>(std::move(cancel_token),
682-
std::move(promise));
678+
return {cancel_token, std::move(promise)};
683679
}
684680

685681
bool VersionedLayerClientImpl::RemoveFromCache(
@@ -812,10 +808,10 @@ bool VersionedLayerClientImpl::IsCached(const geo::TileKey& tile,
812808

813809
client::CancellationToken VersionedLayerClientImpl::GetAggregatedData(
814810
TileRequest request, AggregatedDataResponseCallback callback) {
815-
auto data_task =
816-
[=](client::CancellationContext context) -> AggregatedDataResponse {
811+
auto data_task = [=](const client::CancellationContext& context)
812+
-> AggregatedDataResponse {
817813
const auto fetch_option = request.GetFetchOption();
818-
const auto billing_tag = request.GetBillingTag();
814+
const auto& billing_tag = request.GetBillingTag();
819815

820816
if (fetch_option == CacheWithUpdate) {
821817
return client::ApiError::InvalidArgument(
@@ -832,28 +828,20 @@ client::CancellationToken VersionedLayerClientImpl::GetAggregatedData(
832828
}
833829

834830
auto version = version_response.GetResult().GetVersion();
835-
repository::PartitionsRepository repository(catalog_, layer_id_, settings_,
836-
lookup_client_, mutex_storage_);
837-
auto partition_response =
838-
repository.GetAggregatedTile(request, version, context);
831+
repository::PartitionsRepository partition_repository(
832+
catalog_, layer_id_, settings_, lookup_client_, mutex_storage_);
833+
const auto& partition_response =
834+
partition_repository.GetAggregatedTile(request, version, context);
839835
if (!partition_response.IsSuccessful()) {
840-
return AggregatedDataResponse(partition_response.GetError(),
841-
partition_response.GetPayload());
836+
return {partition_response.GetError(), partition_response.GetPayload()};
842837
}
843838

844-
const auto& fetch_partition = partition_response.GetResult();
845-
const auto fetch_tile_key =
846-
geo::TileKey::FromHereTile(fetch_partition.GetPartition());
847-
848-
auto data_request = DataRequest()
849-
.WithDataHandle(fetch_partition.GetDataHandle())
850-
.WithFetchOption(fetch_option)
851-
.WithBillingTag(billing_tag);
839+
const auto& partition = partition_response.GetResult();
852840

853841
repository::DataRepository data_repository(catalog_, settings_,
854842
lookup_client_, mutex_storage_);
855-
auto data_response = data_repository.GetVersionedData(
856-
layer_id_, data_request, version, context,
843+
auto data_response = data_repository.GetBlobData(
844+
layer_id_, "blob", partition, fetch_option, billing_tag, context,
857845
settings_.propagate_all_cache_errors);
858846

859847
const auto aggregated_network_statistics =
@@ -863,18 +851,15 @@ client::CancellationToken VersionedLayerClientImpl::GetAggregatedData(
863851
OLP_SDK_LOG_WARNING_F(
864852
kLogTag,
865853
"GetAggregatedData: failed to load data, key=%s, data_handle=%s",
866-
fetch_tile_key.ToHereTile().c_str(),
867-
fetch_partition.GetDataHandle().c_str());
868-
return AggregatedDataResponse(data_response.GetError(),
869-
aggregated_network_statistics);
854+
partition.GetPartition().c_str(), partition.GetDataHandle().c_str());
855+
return {data_response.GetError(), aggregated_network_statistics};
870856
}
871857

872858
AggregatedDataResult result;
873-
result.SetTile(fetch_tile_key);
859+
result.SetTile(geo::TileKey::FromHereTile(partition.GetPartition()));
874860
result.SetData(data_response.MoveResult());
875861

876-
return AggregatedDataResponse(std::move(result),
877-
aggregated_network_statistics);
862+
return {result, aggregated_network_statistics};
878863
};
879864

880865
return task_sink_.AddTask(std::move(data_task), std::move(callback),
@@ -888,8 +873,7 @@ VersionedLayerClientImpl::GetAggregatedData(TileRequest request) {
888873
std::move(request), [promise](AggregatedDataResponse response) {
889874
promise->set_value(std::move(response));
890875
});
891-
return client::CancellableFuture<AggregatedDataResponse>(
892-
std::move(cancel_token), std::move(promise));
876+
return {cancel_token, std::move(promise)};
893877
}
894878

895879
bool VersionedLayerClientImpl::Protect(const TileKeys& tiles) {

olp-cpp-sdk-dataservice-read/src/generated/api/QueryApi.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2022 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,38 +94,38 @@ QueryApi::PartitionsExtendedResponse QueryApi::GetPartitionsbyId(
9494
layer_id.c_str(), http_response.status);
9595

9696
if (http_response.status != olp::http::HttpStatusCode::OK) {
97-
return PartitionsExtendedResponse(
97+
return {
9898
client::ApiError(http_response.status, http_response.response.str()),
99-
http_response.GetNetworkStatistics());
99+
http_response.GetNetworkStatistics()};
100100
}
101101
using PartitionsResponse =
102102
client::ApiResponse<model::Partitions, client::ApiError>;
103103

104104
auto partitions_response =
105105
parser::parse_result<PartitionsResponse>(http_response.response);
106106

107-
if (!partitions_response.IsSuccessful()) {
108-
return PartitionsExtendedResponse(partitions_response.GetError(),
109-
http_response.GetNetworkStatistics());
107+
if (!partitions_response) {
108+
return {partitions_response.GetError(),
109+
http_response.GetNetworkStatistics()};
110110
}
111111

112-
return PartitionsExtendedResponse(partitions_response.MoveResult(),
113-
http_response.GetNetworkStatistics());
112+
return {partitions_response.MoveResult(),
113+
http_response.GetNetworkStatistics()};
114114
}
115115

116116
olp::client::HttpResponse QueryApi::QuadTreeIndex(
117117
const client::OlpClient& client, const std::string& layer_id,
118118
const std::string& quad_key, boost::optional<int64_t> version,
119-
int32_t depth, boost::optional<std::vector<std::string>> additional_fields,
119+
int32_t depth, const std::vector<std::string>& additional_fields,
120120
boost::optional<std::string> billing_tag,
121121
client::CancellationContext context) {
122122
std::multimap<std::string, std::string> header_params;
123123
header_params.emplace("Accept", "application/json");
124124

125125
std::multimap<std::string, std::string> query_params;
126-
if (additional_fields) {
126+
if (!additional_fields.empty()) {
127127
query_params.emplace("additionalFields",
128-
ConcatStringArray(*additional_fields, ","));
128+
ConcatStringArray(additional_fields, ","));
129129
}
130130
if (billing_tag) {
131131
query_params.emplace("billingTag", *billing_tag);

olp-cpp-sdk-dataservice-read/src/generated/api/QueryApi.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -112,8 +112,7 @@ class QueryApi {
112112
static olp::client::HttpResponse QuadTreeIndex(
113113
const client::OlpClient& client, const std::string& layer_id,
114114
const std::string& quad_key, boost::optional<int64_t> version,
115-
int32_t depth,
116-
boost::optional<std::vector<std::string>> additional_fields,
115+
int32_t depth, const std::vector<std::string>& additional_fields,
117116
boost::optional<std::string> billing_tag,
118117
client::CancellationContext context);
119118

0 commit comments

Comments
 (0)