Skip to content

Commit 66f1d8a

Browse files
committed
Add a new endpoint in BlobApi to support objectstore.
Handle /layers/{layer_id}/keys/{key} path. Add tests Relates-To: DATASDK-103 Signed-off-by: Alexander Sopov <ext-alexander.sopov@here.com>
1 parent 403d2bd commit 66f1d8a

5 files changed

Lines changed: 427 additions & 6 deletions

File tree

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 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.
@@ -22,10 +22,9 @@
2222
#include <cstring>
2323
#include <map>
2424
#include <memory>
25-
#include <mutex>
26-
#include <unordered_map>
2725

2826
#include <olp/core/client/OlpClient.h>
27+
#include <olp/core/utils/Url.h>
2928

3029
namespace olp {
3130
namespace dataservice {
@@ -55,7 +54,7 @@ BlobApi::DataResponse BlobApi::GetBlob(
5554

5655
// In case we know the size in advance, we should pre-allocated a buffer.
5756
const auto expected_size = partition.GetDataSize();
58-
const auto kPartitionPreallocateLimit = 10 * 1024 * 1024;
57+
constexpr auto kPartitionPreallocateLimit = 10 * 1024 * 1024;
5958
if (expected_size && *expected_size > 0 &&
6059
*expected_size < kPartitionPreallocateLimit) {
6160
buffer.reserve(*expected_size);
@@ -84,6 +83,51 @@ BlobApi::DataResponse BlobApi::GetBlob(
8483
return {std::make_shared<std::vector<unsigned char>>(std::move(buffer)),
8584
api_response.GetNetworkStatistics()};
8685
}
86+
87+
BlobApi::DataResponse BlobApi::GetBlobByKey(
88+
const client::OlpClient& client, const std::string& layer_id,
89+
const std::string& key, porting::optional<std::string> billing_tag,
90+
porting::optional<std::string> range,
91+
const client::CancellationContext& context) {
92+
std::multimap<std::string, std::string> header_params;
93+
header_params.emplace("Accept", "application/octet-stream");
94+
if (range) {
95+
header_params.emplace("Range", *range);
96+
}
97+
98+
std::multimap<std::string, std::string> query_params;
99+
if (billing_tag) {
100+
query_params.emplace("billingTag", *billing_tag);
101+
}
102+
103+
std::string metadata_uri =
104+
"/layers/" + layer_id + "/keys/" + olp::utils::Url::Encode(key);
105+
106+
std::vector<unsigned char> buffer;
107+
108+
auto data_callback = [&](const std::uint8_t* data, const std::uint64_t offset,
109+
const std::size_t length) {
110+
if (!offset) {
111+
buffer.clear();
112+
}
113+
114+
const auto buffer_size = buffer.size();
115+
buffer.resize(buffer_size + length);
116+
std::memcpy(buffer.data() + buffer_size, data, length);
117+
};
118+
119+
auto api_response =
120+
client.CallApiStream(metadata_uri, "GET", query_params, header_params,
121+
data_callback, nullptr, "", context);
122+
123+
if (api_response.GetStatus() != http::HttpStatusCode::OK) {
124+
return {client::ApiError(api_response.GetStatus()),
125+
api_response.GetNetworkStatistics()};
126+
}
127+
128+
return {std::make_shared<std::vector<unsigned char>>(std::move(buffer)),
129+
api_response.GetNetworkStatistics()};
130+
}
87131
} // namespace read
88132
} // namespace dataservice
89133
} // namespace olp

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 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.
@@ -71,6 +71,32 @@ class BlobApi {
7171
porting::optional<std::string> billing_tag,
7272
porting::optional<std::string> range,
7373
const client::CancellationContext& context);
74+
75+
/**
76+
* @brief Retrieves a plain data blob for the specified layer and key.
77+
* @param client Instance of OlpClient used to make REST request.
78+
* @param layer_id Layer id.
79+
* @param key The key of the blob to be retrieved.
80+
* @param billing_tag An optional free-form tag which is used for grouping
81+
* billing records together. If supplied, it must be between 4 - 16
82+
* characters, contain only alpha/numeric ASCII characters [A-Za-z0-9].
83+
* @param range Use this parameter to resume download of a large response
84+
* when there is a connection issue between the client and server.
85+
* Specify a single byte range offset like this: Range: bytes=10-.
86+
* This parameter is compliant with RFC 7233, but note that this parameter
87+
* only supports a single byte range. The range parameter can also be
88+
* specified as a query parameter, i.e. range=bytes=10-.
89+
* @param context A CancellationContext, which can be used to cancel the
90+
* pending request.
91+
*
92+
* @return Data response.
93+
*/
94+
static DataResponse GetBlobByKey(const client::OlpClient& client,
95+
const std::string& layer_id,
96+
const std::string& key,
97+
porting::optional<std::string> billing_tag,
98+
porting::optional<std::string> range,
99+
const client::CancellationContext& context);
74100
};
75101

76102
} // namespace read

0 commit comments

Comments
 (0)