Skip to content

Commit 9f41166

Browse files
Remove dead code
Remove old dead code that is not used: * ApiRepository async methods * DataRepository async methods * PartitionsRepository async methods * PrefetchTilesRepository async methods * PendingRequests old methods that were using keys and tokens * MultiRequestContext Clients now do not use separated task schedulers. Resolves: OLPEDGE-1145 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent ee0f18e commit 9f41166

25 files changed

+108
-2081
lines changed

olp-cpp-sdk-core/include/olp/core/client/PendingRequests.h

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,69 +36,37 @@ namespace client {
3636
*/
3737
class PendingRequests final {
3838
public:
39-
PendingRequests();
40-
~PendingRequests();
41-
4239
/**
4340
* @brief Cancels all pending tasks
4441
* @note This call does not wait for the tasks to finalize, use
4542
* CancelAllAndWait() to also wait for the tasks to finalize..
4643
* @return True on success
4744
*/
4845
bool CancelAll();
49-
46+
5047
/**
5148
* @brief Cancels all pending tasks and waits for all beeing finalized.
5249
* @return True on success
5350
*/
5451
bool CancelAllAndWait();
5552

56-
/**
57-
* @brief Generates a placehoder for request cancellation token and returns a
58-
* key associated with it.
59-
* @return Returns a key associated with a placeholder.
60-
*/
61-
int64_t GenerateRequestPlaceholder();
62-
63-
/**
64-
* @brief Inserts request cancellation token into the placeholder associated
65-
* with a key.
66-
* @param token Cancellation token.
67-
* @param key Key associated with a placeholder.
68-
* @return True on success, false when the placeholder is missing.
69-
*/
70-
bool Insert(const client::CancellationToken& token, int64_t key);
71-
7253
/**
7354
* @brief Inserts task context into the requests container.
7455
* @param task_context Task context.
7556
*/
76-
void Insert(client::TaskContext task_context);
77-
78-
/**
79-
* @brief Removes a pending request and placholder.
80-
* @param key Internal request key to remove
81-
* @return True on success
82-
*/
83-
bool Remove(int64_t key);
57+
void Insert(TaskContext task_context);
8458

8559
/**
8660
* @brief Removes a task context.
8761
* @param task_context Task context.
8862
*/
89-
void Remove(client::TaskContext task_context);
63+
void Remove(TaskContext task_context);
9064

9165
private:
92-
int64_t key_ = 0;
93-
using RequestMap = std::unordered_map<int64_t, client::CancellationToken>;
94-
using ContextMap =
95-
std::unordered_set<client::TaskContext, client::TaskContextHash>;
96-
RequestMap requests_map_;
66+
using ContextMap = std::unordered_set<TaskContext, TaskContextHash>;
9767
ContextMap task_contexts_;
98-
99-
std::mutex requests_lock_;
68+
std::mutex task_contexts_lock_;
10069
};
10170

10271
} // namespace client
10372
} // namespace olp
104-

olp-cpp-sdk-core/src/client/PendingRequests.cpp

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,13 @@ namespace {
2828
constexpr auto kLogTag = "PendingRequests";
2929
}
3030

31-
PendingRequests::PendingRequests(){};
32-
33-
PendingRequests::~PendingRequests(){};
34-
3531
bool PendingRequests::CancelAll() {
36-
RequestMap requests_map;
3732
ContextMap contexts;
3833
{
39-
std::lock_guard<std::mutex> lk(requests_lock_);
40-
requests_map = requests_map_;
34+
std::lock_guard<std::mutex> lock(task_contexts_lock_);
4135
contexts = task_contexts_;
4236
}
4337

44-
for (auto& pair : requests_map) {
45-
pair.second.Cancel();
46-
}
47-
4838
for (auto context : contexts) {
4939
context.CancelToken().Cancel();
5040
}
@@ -57,7 +47,7 @@ bool PendingRequests::CancelAllAndWait() {
5747

5848
ContextMap contexts;
5949
{
60-
std::lock_guard<std::mutex> lk(requests_lock_);
50+
std::lock_guard<std::mutex> lock(task_contexts_lock_);
6151
contexts = std::move(task_contexts_);
6252
}
6353

@@ -70,40 +60,13 @@ bool PendingRequests::CancelAllAndWait() {
7060
return true;
7161
}
7262

73-
int64_t PendingRequests::GenerateRequestPlaceholder() {
74-
std::lock_guard<std::mutex> lk(requests_lock_);
75-
key_++;
76-
requests_map_[key_] = client::CancellationToken();
77-
return key_;
78-
}
79-
80-
bool PendingRequests::Insert(const client::CancellationToken& request,
81-
int64_t key) {
82-
std::lock_guard<std::mutex> lk(requests_lock_);
83-
if (requests_map_.find(key) == requests_map_.end()) {
84-
return false;
85-
}
86-
requests_map_[key] = request;
87-
return true;
88-
}
89-
90-
void PendingRequests::Insert(client::TaskContext task_context) {
91-
std::lock_guard<std::mutex> lk(requests_lock_);
63+
void PendingRequests::Insert(TaskContext task_context) {
64+
std::lock_guard<std::mutex> lock(task_contexts_lock_);
9265
task_contexts_.insert(task_context);
9366
}
9467

95-
bool PendingRequests::Remove(int64_t key) {
96-
std::lock_guard<std::mutex> lk(requests_lock_);
97-
auto request = requests_map_.find(key);
98-
if (request != requests_map_.end()) {
99-
requests_map_.erase(request);
100-
return true;
101-
}
102-
return false;
103-
}
104-
105-
void PendingRequests::Remove(client::TaskContext task_context) {
106-
std::lock_guard<std::mutex> lk(requests_lock_);
68+
void PendingRequests::Remove(TaskContext task_context) {
69+
std::lock_guard<std::mutex> lock(task_contexts_lock_);
10770
task_contexts_.erase(task_context);
10871
}
10972

olp-cpp-sdk-core/tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ set(OLP_CPP_SDK_CORE_TESTS_SOURCES
2222
./client/CancellationContextTest.cpp
2323
./client/ConditionTest.cpp
2424
./client/TaskContextTest.cpp
25-
./client/PendingRequestsTest.cpp
2625

2726
./geo/coordinates/GeoCoordinates3dTest.cpp
2827
./geo/coordinates/GeoCoordinatesTest.cpp

olp-cpp-sdk-core/tests/client/PendingRequestsTest.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -50,85 +50,6 @@ std::string GetDatastoreServerUrl(const std::string& partition) {
5050
}
5151
} // namespace
5252

53-
client::CancellationToken ApiClientLookup::LookupApi(
54-
std::shared_ptr<client::OlpClient> client, const std::string& service,
55-
const std::string& service_version, const client::HRN& hrn,
56-
const ApisCallback& callback) {
57-
OLP_SDK_LOG_TRACE_F(kLogTag, "LookupApi(%s/%s): %s", service.c_str(),
58-
service_version.c_str(), hrn.partition.c_str());
59-
60-
// compare the hrn
61-
auto base_url = GetDatastoreServerUrl(hrn.partition);
62-
if (base_url.empty()) {
63-
OLP_SDK_LOG_INFO_F(kLogTag, "LookupApi(%s/%s): %s Lookup URL not found",
64-
service.c_str(), service_version.c_str(),
65-
hrn.partition.c_str());
66-
callback(
67-
client::ApiError(client::ErrorCode::NotFound, "Invalid or broken HRN"));
68-
return client::CancellationToken();
69-
}
70-
71-
client->SetBaseUrl(base_url);
72-
73-
if (service == "config") {
74-
OLP_SDK_LOG_INFO_F(kLogTag, "LookupApi(%s/%s): %s - config service",
75-
service.c_str(), service_version.c_str(),
76-
hrn.partition.c_str());
77-
78-
// scan apis at platform apis
79-
return PlatformApi::GetApis(
80-
client, service, service_version,
81-
[callback](PlatformApi::ApisResponse response) { callback(response); });
82-
}
83-
84-
OLP_SDK_LOG_INFO_F(kLogTag, "LookupApi(%s/%s): %s - resource service",
85-
service.c_str(), service_version.c_str(),
86-
hrn.partition.c_str());
87-
88-
// scan apis at resource endpoint
89-
return ResourcesApi::GetApis(
90-
client, hrn.ToCatalogHRNString(), service, service_version,
91-
[callback](PlatformApi::ApisResponse response) { callback(response); });
92-
}
93-
94-
client::CancellationToken ApiClientLookup::LookupApiClient(
95-
std::shared_ptr<client::OlpClient> client, const std::string& service,
96-
const std::string& service_version, const client::HRN& hrn,
97-
const ApiClientCallback& callback) {
98-
OLP_SDK_LOG_TRACE_F(kLogTag, "LookupApiClient(%s/%s): %s", service.c_str(),
99-
service_version.c_str(), hrn.partition.c_str());
100-
101-
return ApiClientLookup::LookupApi(
102-
client, service, service_version, hrn, [=](ApisResponse response) {
103-
if (!response.IsSuccessful()) {
104-
OLP_SDK_LOG_INFO_F(
105-
kLogTag, "LookupApiClient(%s/%s): %s - unsuccessful: %s",
106-
service.c_str(), service_version.c_str(), hrn.partition.c_str(),
107-
response.GetError().GetMessage().c_str());
108-
109-
callback(response.GetError());
110-
} else if (response.GetResult().size() < 1) {
111-
OLP_SDK_LOG_INFO_F(
112-
kLogTag, "LookupApiClient(%s/%s): %s - service not available",
113-
service.c_str(), service_version.c_str(), hrn.partition.c_str());
114-
115-
// TODO use defined ErrorCode
116-
callback(
117-
client::ApiError(client::ErrorCode::ServiceUnavailable,
118-
"Service/Version not available for given HRN"));
119-
} else {
120-
const auto& base_url = response.GetResult().at(0).GetBaseUrl();
121-
OLP_SDK_LOG_INFO_F(kLogTag,
122-
"LookupApiClient(%s/%s): %s - OK, base_url=%s",
123-
service.c_str(), service_version.c_str(),
124-
hrn.partition.c_str(), base_url.c_str());
125-
126-
client->SetBaseUrl(base_url);
127-
callback(*client);
128-
}
129-
});
130-
}
131-
13253
ApiClientLookup::ApiClientResponse ApiClientLookup::LookupApi(
13354
const client::HRN& catalog,
13455
client::CancellationContext cancellation_context, std::string service,

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,10 @@ namespace read {
3737
*/
3838
class ApiClientLookup {
3939
public:
40-
using ApisResponse = client::ApiResponse<model::Apis, client::ApiError>;
41-
using ApisCallback = std::function<void(ApisResponse)>;
42-
43-
static client::CancellationToken LookupApi(
44-
std::shared_ptr<client::OlpClient> client, const std::string& service,
45-
const std::string& service_version, const client::HRN& hrn,
46-
const ApisCallback& callback);
47-
4840
using ApiClientResponse =
4941
client::ApiResponse<client::OlpClient, client::ApiError>;
5042
using ApiClientCallback = std::function<void(ApiClientResponse)>;
5143

52-
static client::CancellationToken LookupApiClient(
53-
std::shared_ptr<client::OlpClient> client, const std::string& service,
54-
const std::string& service_version, const client::HRN& hrn,
55-
const ApiClientCallback& callback);
56-
5744
static ApiClientResponse LookupApi(
5845
const client::HRN& catalog,
5946
client::CancellationContext cancellation_context, std::string service,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <olp/core/logging/Log.h>
2626

2727
#include "Common.h"
28-
#include "repositories/ApiRepository.h"
2928
#include "repositories/CatalogRepository.h"
3029
#include "repositories/ExecuteOrSchedule.inl"
3130

0 commit comments

Comments
 (0)