Skip to content

Commit 3532ef8

Browse files
author
Liubov Didkivska
authored
Add GetPartitions extended response (#1079)
Add MetadataApi and QueryApi metods wich returns extended responce. Add GetPartitionsExtendedResponse to PartitionsRepository, which returns extended response. Add PrefetchPartitionsRequest and PrefetchPartitionsStatus. Relates-To: OLPEDGE-1902 Signed-off-by: Liubov Didkivska <[email protected]>
1 parent ffcd85b commit 3532ef8

File tree

9 files changed

+272
-30
lines changed

9 files changed

+272
-30
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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 <sstream>
23+
#include <string>
24+
#include <utility>
25+
#include <vector>
26+
27+
#include <olp/core/thread/TaskScheduler.h>
28+
#include <olp/dataservice/read/DataServiceReadApi.h>
29+
#include <olp/dataservice/read/FetchOptions.h>
30+
#include <boost/optional.hpp>
31+
32+
namespace olp {
33+
namespace dataservice {
34+
namespace read {
35+
36+
/**
37+
* @brief Encapsulates the fields required to prefetch a list of partitions for
38+
* the given catalog and layer.
39+
*/
40+
class DATASERVICE_READ_API PrefetchPartitionsRequest final {
41+
public:
42+
/// The alias type of the vector of partitions ids
43+
using PartitionIds = std::vector<std::string>;
44+
45+
/**
46+
* @brief Sets the list of partitions.
47+
*
48+
* When the list is empty, the GetPartitions method will download the whole
49+
* layer metadata. Additionally, a single request supports up to 100
50+
* partitions. If partitions list has more than 100, it will be splitted
51+
* internally to multiple requests.
52+
*
53+
* @param partitions The list of partitions to request.
54+
*
55+
* @return A reference to the updated `PrefetchPartitionsRequest` instance.
56+
*/
57+
inline PrefetchPartitionsRequest& WithPartitionIds(
58+
PartitionIds partition_ids) {
59+
partition_ids_ = std::move(partition_ids);
60+
return *this;
61+
}
62+
63+
/**
64+
* @brief Gets the list of the partitions.
65+
*
66+
* @return The vector of strings that represent partitions.
67+
*/
68+
inline const PartitionIds& GetPartitionIds() const { return partition_ids_; }
69+
70+
/**
71+
* @brief Gets the billing tag to group billing records together.
72+
*
73+
* The billing tag is an optional free-form tag that is used for grouping
74+
* billing records together. If supplied, it must be 4–16 characters
75+
* long and contain only alphanumeric ASCII characters [A-Za-z0-9].
76+
*
77+
* @return The `BillingTag` string or `boost::none` if the billing tag is not
78+
* set.
79+
*/
80+
inline const boost::optional<std::string>& GetBillingTag() const {
81+
return billing_tag_;
82+
}
83+
84+
/**
85+
* @brief Sets the billing tag for the request.
86+
*
87+
* @see `GetBillingTag()` for information on usage and format.
88+
*
89+
* @param billingTag The `BillingTag` string or `boost::none`.
90+
*
91+
* @return A reference to the updated `PrefetchTilesRequest` instance.
92+
*/
93+
inline PrefetchPartitionsRequest& WithBillingTag(
94+
boost::optional<std::string> billing_tag) {
95+
billing_tag_ = billing_tag;
96+
return *this;
97+
}
98+
99+
/**
100+
* @brief Sets the billing tag for the request.
101+
*
102+
* @see `GetBillingTag()` for information on usage and format.
103+
*
104+
* @param billingTag The rvalue reference to the `BillingTag` string or
105+
* `boost::none`.
106+
*
107+
* @return A reference to the updated `PrefetchTilesRequest` instance.
108+
*/
109+
inline PrefetchPartitionsRequest& WithBillingTag(std::string&& billing_tag) {
110+
billing_tag_ = std::move(billing_tag);
111+
return *this;
112+
}
113+
114+
/**
115+
* @brief Gets the request priority.
116+
*
117+
* The default priority is `Priority::LOW`.
118+
*
119+
* @return The request priority.
120+
*/
121+
inline uint32_t GetPriority() const { return priority_; }
122+
123+
/**
124+
* @brief Sets the priority of the prefetch request.
125+
*
126+
* @param priority The priority of the request.
127+
*
128+
* @return A reference to the updated `PrefetchPartitionsRequest` instance.
129+
*/
130+
inline PrefetchPartitionsRequest& WithPriority(uint32_t priority) {
131+
priority_ = priority;
132+
return *this;
133+
}
134+
135+
/**
136+
* @brief Creates a readable format for the request.
137+
*
138+
* @param layer_id The ID of the layer that is used for the request.
139+
*
140+
* @return A string representation of the request.
141+
*/
142+
std::string CreateKey(const std::string& layer_id,
143+
boost::optional<int64_t> version = boost::none) const {
144+
std::stringstream out;
145+
out << layer_id;
146+
if (version) {
147+
out << "@" << version.get();
148+
}
149+
out << "^" << partition_ids_.size();
150+
if (partition_ids_.size() > 0) {
151+
out << "[" << partition_ids_.front() << ", ...]";
152+
}
153+
if (GetBillingTag()) {
154+
out << "$" << GetBillingTag().get();
155+
}
156+
out << "*" << priority_;
157+
return out.str();
158+
}
159+
160+
private:
161+
PartitionIds partition_ids_;
162+
boost::optional<std::string> billing_tag_;
163+
uint32_t priority_{thread::LOW};
164+
};
165+
166+
} // namespace read
167+
} // namespace dataservice
168+
} // namespace olp

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ struct PrefetchStatus {
3737
size_t bytes_transferred;
3838
};
3939

40+
/*
41+
* @brief PrefetchPartitionsStatus structure represent the progress of prefetch
42+
* operation for partitions.
43+
*/
44+
struct PrefetchPartitionsStatus {
45+
/// Partitions available (prefetched).
46+
size_t prefetched_partitions;
47+
/// Total number of partitions to prefetch during prefetch operation.
48+
size_t total_partitions_to_prefetch;
49+
/// Total bytes tranferred during API calls.
50+
size_t bytes_transferred;
51+
};
52+
4053
} // namespace read
4154
} // namespace dataservice
4255
} // namespace olp

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ using PrefetchStatusCallback = std::function<void(PrefetchStatus)>;
9696
using PrefetchPartitionsResponse = Response<PrefetchPartitionsResult>;
9797
/// The callback type of the prefetch completion.
9898
using PrefetchPartitionsResponseCallback = Callback<PrefetchPartitionsResult>;
99+
/// The callback type for the prefetch status update.
100+
using PrefetchPartitionsStatusCallback =
101+
std::function<void(PrefetchPartitionsStatus)>;
99102

100103
/// The subscribe ID type of the stream layer client.
101104
using SubscriptionId = std::string;

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ MetadataApi::LayerVersionsResponse MetadataApi::GetLayerVersions(
8080
return parser::parse_result<LayerVersionsResponse>(api_response.response);
8181
}
8282

83-
MetadataApi::PartitionsResponse MetadataApi::GetPartitions(
83+
MetadataApi::PartitionsExtendedResponse MetadataApi::GetPartitions(
8484
const client::OlpClient& client, const std::string& layer_id,
8585
boost::optional<std::int64_t> version,
8686
const std::vector<std::string>& additional_fields,
@@ -107,14 +107,27 @@ MetadataApi::PartitionsResponse MetadataApi::GetPartitions(
107107

108108
std::string metadataUri = "/layers/" + layer_id + "/partitions";
109109

110-
auto api_response = client.CallApi(metadataUri, "GET", query_params,
111-
header_params, {}, nullptr, "", context);
110+
auto http_response = client.CallApi(metadataUri, "GET", query_params,
111+
header_params, {}, nullptr, "", context);
112112

113-
if (api_response.status != http::HttpStatusCode::OK) {
114-
return {{api_response.status, api_response.response.str()}};
113+
if (http_response.status != olp::http::HttpStatusCode::OK) {
114+
return {{http_response.status, http_response.response.str()},
115+
http_response.GetNetworkStatistics()};
116+
}
117+
118+
using PartitionsResponse =
119+
client::ApiResponse<model::Partitions, client::ApiError>;
120+
121+
auto partitions_response =
122+
parser::parse_result<PartitionsResponse>(http_response.response);
123+
124+
if (!partitions_response.IsSuccessful()) {
125+
return {{partitions_response.GetError()},
126+
http_response.GetNetworkStatistics()};
115127
}
116128

117-
return parser::parse_result<PartitionsResponse>(api_response.response);
129+
return {partitions_response.MoveResult(),
130+
http_response.GetNetworkStatistics()};
118131
}
119132

120133
MetadataApi::CatalogVersionResponse MetadataApi::GetLatestCatalogVersion(

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <olp/core/client/ApiError.h>
2626
#include <olp/core/client/ApiResponse.h>
2727
#include <boost/optional.hpp>
28+
#include "ExtendedApiResponse.h"
2829
#include "generated/model/LayerVersions.h"
2930
#include "olp/dataservice/read/model/Partitions.h"
3031
#include "olp/dataservice/read/model/VersionInfos.h"
@@ -45,15 +46,17 @@ class MetadataApi {
4546
public:
4647
using VersionsResponse =
4748
client::ApiResponse<model::VersionInfos, client::ApiError>;
48-
using PartitionsResponse =
49-
client::ApiResponse<model::Partitions, client::ApiError>;
5049

5150
using CatalogVersionResponse =
5251
client::ApiResponse<model::VersionResponse, client::ApiError>;
5352

5453
using LayerVersionsResponse =
5554
client::ApiResponse<model::LayerVersions, client::ApiError>;
5655

56+
using PartitionsExtendedResponse =
57+
ExtendedApiResponse<model::Partitions, client::ApiError,
58+
client::NetworkStatistics>;
59+
5760
/**
5861
* @brief Retrieves the latest metadata version for each layer of a specified
5962
* catalog metadata version.
@@ -91,9 +94,10 @@ class MetadataApi {
9194
* characters, contain only alpha/numeric ASCII characters [A-Za-z0-9].
9295
* @param context A CancellationContext, which can be used to cancel request.
9396
*
94-
* @return The Partitions response.
97+
* @return The result of this operation as an extended client::ApiResponse
98+
* object with \c model::Partitions as a result.
9599
*/
96-
static PartitionsResponse GetPartitions(
100+
static PartitionsExtendedResponse GetPartitions(
97101
const client::OlpClient& client, const std::string& layerId,
98102
boost::optional<int64_t> version,
99103
const std::vector<std::string>& additional_fields,

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace olp {
5959
namespace dataservice {
6060
namespace read {
6161

62-
QueryApi::PartitionsResponse QueryApi::GetPartitionsbyId(
62+
QueryApi::PartitionsExtendedResponse QueryApi::GetPartitionsbyId(
6363
const client::OlpClient& client, const std::string& layer_id,
6464
const std::vector<std::string>& partitions,
6565
boost::optional<int64_t> version,
@@ -86,17 +86,30 @@ QueryApi::PartitionsResponse QueryApi::GetPartitionsbyId(
8686

8787
std::string metadata_uri = "/layers/" + layer_id + "/partitions";
8888

89-
client::HttpResponse response = client.CallApi(
89+
client::HttpResponse http_response = client.CallApi(
9090
metadata_uri, "GET", std::move(query_params), std::move(header_params),
9191
{}, nullptr, std::string{}, std::move(context));
92-
if (response.status != olp::http::HttpStatusCode::OK) {
93-
return client::ApiError(response.status, response.response.str());
92+
93+
OLP_SDK_LOG_TRACE_F(kLogTag, "GetPartitionsbyId, layer_id=%s, status=%d",
94+
layer_id.c_str(), http_response.status);
95+
96+
if (http_response.status != olp::http::HttpStatusCode::OK) {
97+
return {{http_response.status, http_response.response.str()},
98+
http_response.GetNetworkStatistics()};
9499
}
100+
using PartitionsResponse =
101+
client::ApiResponse<model::Partitions, client::ApiError>;
95102

96-
OLP_SDK_LOG_TRACE_F(kLogTag, "GetPartitionsbyId, uri=%s, status=%d",
97-
metadata_uri.c_str(), response.status);
103+
auto partitions_response =
104+
parser::parse_result<PartitionsResponse>(http_response.response);
105+
106+
if (!partitions_response.IsSuccessful()) {
107+
return {{partitions_response.GetError()},
108+
http_response.GetNetworkStatistics()};
109+
}
98110

99-
return parser::parse_result<PartitionsResponse>(response.response);
111+
return {partitions_response.MoveResult(),
112+
http_response.GetNetworkStatistics()};
100113
}
101114

102115
olp::client::HttpResponse QueryApi::QuadTreeIndex(

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <olp/core/client/CancellationContext.h>
2828
#include <olp/core/client/HttpResponse.h>
2929
#include <boost/optional.hpp>
30+
#include "ExtendedApiResponse.h"
3031
#include "generated/model/Index.h"
3132
#include "olp/dataservice/read/model/Partitions.h"
3233

@@ -42,11 +43,13 @@ namespace read {
4243
*/
4344
class QueryApi {
4445
public:
45-
using PartitionsResponse =
46-
client::ApiResponse<model::Partitions, client::ApiError>;
4746
using QuadTreeIndexResponse =
4847
client::ApiResponse<model::Index, client::ApiError>;
4948

49+
using PartitionsExtendedResponse =
50+
ExtendedApiResponse<model::Partitions, client::ApiError,
51+
client::NetworkStatistics>;
52+
5053
/**
5154
* @brief Call to synchronously retrieve metadata for specified partitions in
5255
* a specified layer.
@@ -66,10 +69,10 @@ class QueryApi {
6669
* response.
6770
* @param context A CancellationContext instance which can be used to cancel
6871
* call of this method.
69-
* @param The result of this operation as a client::ApiResponse object with \c
70-
* model::Partitions as a result.
72+
* @return The result of this operation as an extended client::ApiResponse
73+
* object with \c model::Partitions as a result.
7174
*/
72-
static PartitionsResponse GetPartitionsbyId(
75+
static PartitionsExtendedResponse GetPartitionsbyId(
7376
const client::OlpClient& client, const std::string& layer_id,
7477
const std::vector<std::string>& partitions,
7578
boost::optional<int64_t> version,
@@ -104,8 +107,7 @@ class QueryApi {
104107
* release.
105108
* @param context A CancellationContext instance which can be used to cancel
106109
* call of this method.
107-
* @param The result of this operation as a client::ApiResponse object with \c
108-
* model::Index as a result
110+
* @return HttpResponse of this operation.
109111
**/
110112
static olp::client::HttpResponse QuadTreeIndex(
111113
const client::OlpClient& client, const std::string& layer_id,

0 commit comments

Comments
 (0)