Skip to content

Commit 0f27430

Browse files
author
Liubov Didkivska
committed
Add versions list implementation
Add interface to get versions list to catalog client. Implement get versions list. Relates-To: OLPEDGE-1606 Signed-off-by: Liubov Didkivska <ext-liubov.didkivska@here.com>
1 parent f54b906 commit 0f27430

11 files changed

+291
-20
lines changed

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogClient.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 HERE Europe B.V.
2+
* Copyright (C) 2019-2020 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.
@@ -31,6 +31,7 @@
3131
#include <olp/dataservice/read/DataServiceReadApi.h>
3232
#include <olp/dataservice/read/PartitionsRequest.h>
3333
#include <olp/dataservice/read/Types.h>
34+
#include <olp/dataservice/read/VersionsRequest.h>
3435

3536
namespace olp {
3637

@@ -137,6 +138,32 @@ class DATASERVICE_READ_API CatalogClient final {
137138
client::CancellableFuture<CatalogVersionResponse> GetLatestVersion(
138139
CatalogVersionRequest request);
139140

141+
/**
142+
* @brief Gets the catalog versions list.
143+
*
144+
* @param request The `VersionsRequest` instance that contains
145+
* a complete set of request parameters.
146+
* @param callback The `VersionsResponseCallback` object that is invoked if
147+
* the list of versions is available or an error is encountered.
148+
*
149+
* @return A token that can be used to cancel this request.
150+
*/
151+
client::CancellationToken ListVersions(VersionsRequest request,
152+
VersionsResponseCallback callback);
153+
154+
/**
155+
* @brief Gets the catalog versions list.
156+
*
157+
* @param request The `VersionsRequest` instance that contains
158+
* a complete set of request parameters.
159+
*
160+
* @return CancellableFuture` that contains the `VersionsResponse`
161+
* instance with the list of versions or an error. You can also
162+
* use `CancellableFuture` to cancel this request.
163+
*/
164+
client::CancellableFuture<VersionsResponse> ListVersions(
165+
VersionsRequest request);
166+
140167
private:
141168
std::unique_ptr<CatalogClientImpl> impl_;
142169
};

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionsRequest.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,11 @@ class DATASERVICE_READ_API VersionsRequest final {
164164
/**
165165
* @brief Creates a readable format for the request.
166166
*
167-
* @param layer_id The ID of the layer that is used for the request.
168-
*
169167
* @return A string representation of the request.
170168
*/
171-
inline std::string CreateKey(const std::string& layer_id) const {
169+
inline std::string CreateKey() const {
172170
std::stringstream out;
173-
out << layer_id << "[";
171+
out << "[";
174172
out << GetStartVersion() << ", " << GetEndVersion();
175173
out << "]";
176174
if (GetBillingTag()) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 HERE Europe B.V.
2+
* Copyright (C) 2019-2020 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.
@@ -61,6 +61,16 @@ client::CancellableFuture<CatalogVersionResponse>
6161
CatalogClient::GetLatestVersion(CatalogVersionRequest request) {
6262
return impl_->GetLatestVersion(std::move(request));
6363
}
64+
65+
client::CancellationToken CatalogClient::ListVersions(
66+
VersionsRequest request, VersionsResponseCallback callback) {
67+
return impl_->ListVersions(std::move(request), std::move(callback));
68+
}
69+
70+
client::CancellableFuture<VersionsResponse> CatalogClient::ListVersions(
71+
VersionsRequest request) {
72+
return impl_->ListVersions(std::move(request));
73+
}
6474
} // namespace read
6575
} // namespace dataservice
6676
} // namespace olp

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

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 HERE Europe B.V.
2+
* Copyright (C) 2019-2020 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.
@@ -19,6 +19,8 @@
1919

2020
#include "CatalogClientImpl.h"
2121

22+
#include <utility>
23+
2224
#include <olp/core/cache/DefaultCache.h>
2325
#include <olp/core/client/OlpClientSettingsFactory.h>
2426
#include <olp/core/client/PendingRequests.h>
@@ -31,14 +33,13 @@
3133
namespace olp {
3234
namespace dataservice {
3335
namespace read {
34-
using namespace repository;
35-
using namespace olp::client;
3636

3737
namespace {
3838
constexpr auto kLogTag = "CatalogClientImpl";
3939
}
4040

41-
CatalogClientImpl::CatalogClientImpl(HRN catalog, OlpClientSettings settings)
41+
CatalogClientImpl::CatalogClientImpl(client::HRN catalog,
42+
client::OlpClientSettings settings)
4243
: catalog_(std::move(catalog)), settings_(std::move(settings)) {
4344
if (!settings_.cache) {
4445
settings_.cache = client::OlpClientSettingsFactory::CreateDefaultCache({});
@@ -60,7 +61,7 @@ bool CatalogClientImpl::CancelPendingRequests() {
6061
return pending_requests_->CancelAll();
6162
}
6263

63-
CancellationToken CatalogClientImpl::GetCatalog(
64+
client::CancellationToken CatalogClientImpl::GetCatalog(
6465
CatalogRequest request, CatalogResponseCallback callback) {
6566
auto schedule_get_catalog = [&](CatalogRequest request,
6667
CatalogResponseCallback callback) {
@@ -81,7 +82,7 @@ CancellationToken CatalogClientImpl::GetCatalog(
8182
std::move(callback));
8283
}
8384

84-
CancellableFuture<CatalogResponse> CatalogClientImpl::GetCatalog(
85+
client::CancellableFuture<CatalogResponse> CatalogClientImpl::GetCatalog(
8586
CatalogRequest request) {
8687
auto promise = std::make_shared<std::promise<CatalogResponse>>();
8788
auto cancel_token =
@@ -92,7 +93,7 @@ CancellableFuture<CatalogResponse> CatalogClientImpl::GetCatalog(
9293
std::move(promise));
9394
}
9495

95-
CancellationToken CatalogClientImpl::GetLatestVersion(
96+
client::CancellationToken CatalogClientImpl::GetLatestVersion(
9697
CatalogVersionRequest request, CatalogVersionCallback callback) {
9798
OLP_SDK_LOG_TRACE_F(kLogTag, "GetCatalog '%s'", request.CreateKey().c_str());
9899
auto schedule_get_latest_version = [&](CatalogVersionRequest request,
@@ -114,8 +115,8 @@ CancellationToken CatalogClientImpl::GetLatestVersion(
114115
std::move(request), std::move(callback));
115116
}
116117

117-
CancellableFuture<CatalogVersionResponse> CatalogClientImpl::GetLatestVersion(
118-
CatalogVersionRequest request) {
118+
client::CancellableFuture<CatalogVersionResponse>
119+
CatalogClientImpl::GetLatestVersion(CatalogVersionRequest request) {
119120
auto promise = std::make_shared<std::promise<CatalogVersionResponse>>();
120121
auto cancel_token = GetLatestVersion(
121122
std::move(request), [promise](CatalogVersionResponse response) {
@@ -124,6 +125,48 @@ CancellableFuture<CatalogVersionResponse> CatalogClientImpl::GetLatestVersion(
124125
return client::CancellableFuture<CatalogVersionResponse>(
125126
std::move(cancel_token), std::move(promise));
126127
}
128+
129+
client::CancellationToken CatalogClientImpl::ListVersions(
130+
VersionsRequest request, VersionsResponseCallback callback) {
131+
if (request.GetFetchOption() == CacheWithUpdate) {
132+
auto task = [](client::CancellationContext) -> VersionsResponse {
133+
return {{client::ErrorCode::InvalidArgument,
134+
"CacheWithUpdate option can not be used for versioned catalog"}};
135+
};
136+
return AddTask(settings_.task_scheduler, pending_requests_, std::move(task),
137+
std::move(callback));
138+
}
139+
140+
auto schedule_get_versions_list = [&](VersionsRequest request,
141+
VersionsResponseCallback callback) {
142+
auto catalog = catalog_;
143+
auto settings = settings_;
144+
auto pending_requests = pending_requests_;
145+
146+
auto versions_list_task =
147+
[=](client::CancellationContext context) -> VersionsResponse {
148+
return repository::CatalogRepository::GetVersionsList(
149+
std::move(catalog), context, std::move(request), std::move(settings));
150+
};
151+
152+
return AddTask(settings.task_scheduler, pending_requests,
153+
std::move(versions_list_task), std::move(callback));
154+
};
155+
156+
return ScheduleFetch(std::move(schedule_get_versions_list),
157+
std::move(request), std::move(callback));
158+
}
159+
160+
client::CancellableFuture<VersionsResponse> CatalogClientImpl::ListVersions(
161+
VersionsRequest request) {
162+
auto promise = std::make_shared<std::promise<VersionsResponse>>();
163+
auto cancel_token =
164+
ListVersions(std::move(request), [promise](VersionsResponse response) {
165+
promise->set_value(std::move(response));
166+
});
167+
return client::CancellableFuture<VersionsResponse>(std::move(cancel_token),
168+
std::move(promise));
169+
}
127170
} // namespace read
128171
} // namespace dataservice
129172
} // namespace olp

olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 HERE Europe B.V.
2+
* Copyright (C) 2019-2020 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.
@@ -28,6 +28,7 @@
2828
#include <olp/dataservice/read/CatalogRequest.h>
2929
#include <olp/dataservice/read/CatalogVersionRequest.h>
3030
#include <olp/dataservice/read/Types.h>
31+
#include <olp/dataservice/read/VersionsRequest.h>
3132

3233
namespace olp {
3334
namespace client {
@@ -61,6 +62,12 @@ class CatalogClientImpl final {
6162
client::CancellableFuture<CatalogVersionResponse> GetLatestVersion(
6263
CatalogVersionRequest request);
6364

65+
client::CancellationToken ListVersions(VersionsRequest request,
66+
VersionsResponseCallback callback);
67+
68+
client::CancellableFuture<VersionsResponse> ListVersions(
69+
VersionsRequest request);
70+
6471
private:
6572
client::HRN catalog_;
6673
client::OlpClientSettings settings_;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2020 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
#include <rapidjson/document.h>
21+
22+
#include "VersionInfosSerializer.h"
23+
24+
#include <olp/core/generated/serializer/SerializerWrapper.h>
25+
26+
namespace olp {
27+
namespace serializer {
28+
29+
void to_json(const dataservice::read::model::VersionDependency& x,
30+
rapidjson::Value& value,
31+
rapidjson::Document::AllocatorType& allocator) {
32+
value.SetObject();
33+
serialize("hrn", x.GetHrn(), value, allocator);
34+
serialize("version", x.GetVersion(), value, allocator);
35+
serialize("direct", x.GetDirect(), value, allocator);
36+
}
37+
38+
void to_json(const dataservice::read::model::VersionInfo& x,
39+
rapidjson::Value& value,
40+
rapidjson::Document::AllocatorType& allocator) {
41+
value.SetObject();
42+
serialize("dependencies", x.GetDependencies(), value, allocator);
43+
serialize("timestamp", x.GetTimestamp(), value, allocator);
44+
serialize("version", x.GetVersion(), value, allocator);
45+
serialize("partitionCounts", x.GetPartitionCounts(), value, allocator);
46+
}
47+
48+
void to_json(const dataservice::read::model::VersionInfos& x,
49+
rapidjson::Value& value,
50+
rapidjson::Document::AllocatorType& allocator) {
51+
value.SetObject();
52+
serialize("versions", x.GetVersions(), value, allocator);
53+
}
54+
} // namespace serializer
55+
} // namespace olp
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2020 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
#pragma once
21+
22+
#include <rapidjson/document.h>
23+
24+
#include "olp/dataservice/read/model/VersionInfos.h"
25+
26+
namespace olp {
27+
namespace serializer {
28+
29+
void to_json(const dataservice::read::model::VersionDependency& x,
30+
rapidjson::Value& value,
31+
rapidjson::Document::AllocatorType& allocator);
32+
33+
void to_json(const dataservice::read::model::VersionInfo& x,
34+
rapidjson::Value& value,
35+
rapidjson::Document::AllocatorType& allocator);
36+
37+
void to_json(const dataservice::read::model::VersionInfos& x,
38+
rapidjson::Value& value,
39+
rapidjson::Document::AllocatorType& allocator);
40+
} // namespace serializer
41+
} // namespace olp

olp-cpp-sdk-dataservice-read/src/repositories/CatalogCacheRepository.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 HERE Europe B.V.
2+
* Copyright (C) 2019-2020 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.
@@ -26,10 +26,12 @@
2626

2727
// clang-format off
2828
#include "generated/parser/CatalogParser.h"
29+
#include "generated/parser/VersionInfosParser.h"
2930
#include "generated/parser/VersionResponseParser.h"
3031
#include <olp/core/generated/parser/JsonParser.h>
3132
#include "generated/serializer/CatalogSerializer.h"
3233
#include "generated/serializer/VersionResponseSerializer.h"
34+
#include "generated/serializer/VersionInfosSerializer.h"
3335
#include "generated/serializer/JsonSerializer.h"
3436
// clang-format on
3537

@@ -46,6 +48,11 @@ std::string CreateKey(const std::string& hrn) { return hrn + "::catalog"; }
4648
std::string VersionKey(const std::string& hrn) {
4749
return hrn + "::latestVersion";
4850
}
51+
std::string VersionInfosKey(const std::string& hrn, std::int16_t start,
52+
std::int16_t end) {
53+
return hrn + "::" + std::to_string(start) + "::" + std::to_string(end) +
54+
"::versionInfos";
55+
}
4956

5057
time_t ConvertTime(std::chrono::seconds time) {
5158
return time == kChronoSecondsMax ? kTimetMax : time.count();
@@ -111,6 +118,31 @@ boost::optional<model::VersionResponse> CatalogCacheRepository::GetVersion() {
111118
return boost::any_cast<model::VersionResponse>(cached_version);
112119
}
113120

121+
void CatalogCacheRepository::PutVersionInfos(
122+
std::int64_t start, std::int64_t end, const model::VersionInfos& versions) {
123+
std::string hrn(hrn_.ToCatalogHRNString());
124+
OLP_SDK_LOG_DEBUG_F(kLogTag, "PutVersionInfos -> '%s'", hrn.c_str());
125+
126+
cache_->Put(VersionInfosKey(hrn, start, end), versions,
127+
[&]() { return olp::serializer::serialize(versions); },
128+
kCatalogVersionExpiryTime);
129+
}
130+
boost::optional<model::VersionInfos> CatalogCacheRepository::GetVersionInfos(
131+
std::int64_t start, std::int64_t end) {
132+
std::string hrn(hrn_.ToCatalogHRNString());
133+
auto key = VersionInfosKey(hrn, start, end);
134+
OLP_SDK_LOG_DEBUG_F(kLogTag, "GetVersionInfos -> '%s'", key.c_str());
135+
136+
auto cached_versions = cache_->Get(key, [](const std::string& value) {
137+
return parser::parse<model::VersionInfos>(value);
138+
});
139+
140+
if (cached_versions.empty()) {
141+
return boost::none;
142+
}
143+
return boost::any_cast<model::VersionInfos>(cached_versions);
144+
}
145+
114146
void CatalogCacheRepository::Clear() {
115147
std::string hrn(hrn_.ToCatalogHRNString());
116148
OLP_SDK_LOG_INFO_F(kLogTag, "Clear -> '%s'", CreateKey(hrn).c_str());

0 commit comments

Comments
 (0)