-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MINIFICPP-2485 fix: Support Expression Language in InvokeHTTP "Remote URL" property #1904
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
#include <string> | ||
#include <unordered_map> | ||
#include <utility> | ||
#include <optional> | ||
#include <list> | ||
|
||
#include "Core.h" | ||
#include "FlowFileRecord.h" | ||
|
@@ -41,9 +43,59 @@ | |
#include "utils/Enum.h" | ||
#include "utils/RegexUtils.h" | ||
|
||
namespace org::apache::nifi::minifi::test { | ||
class HttpClientStoreTestAccessor; | ||
} | ||
|
||
namespace org::apache::nifi::minifi::processors { | ||
|
||
namespace invoke_http { | ||
class HttpClientStore { | ||
public: | ||
HttpClientStore(const size_t size, std::function<gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>>(const std::string&)> create_client_function) | ||
: max_size_(size), | ||
create_client_function_(std::move(create_client_function)) { | ||
} | ||
HttpClientStore(const HttpClientStore&) = delete; | ||
HttpClientStore& operator=(const HttpClientStore&) = delete; | ||
HttpClientStore(HttpClientStore&&) = delete; | ||
HttpClientStore& operator=(HttpClientStore&&) = delete; | ||
~HttpClientStore() = default; | ||
|
||
class HttpClientWrapper { | ||
public: | ||
HttpClientWrapper(HttpClientStore& client_store, minifi::http::HTTPClient& client) : client_(client), client_store_(client_store) { | ||
} | ||
HttpClientWrapper(HttpClientWrapper&& src) = default; | ||
HttpClientWrapper(const HttpClientWrapper&) = delete; | ||
~HttpClientWrapper() { | ||
client_store_.returnClient(client_); | ||
} | ||
|
||
minifi::http::HTTPClient& get() const { | ||
return client_; | ||
} | ||
|
||
private: | ||
minifi::http::HTTPClient& client_; | ||
HttpClientStore& client_store_; | ||
}; | ||
|
||
[[nodiscard]] HttpClientWrapper getClient(const std::string& url); | ||
|
||
private: | ||
friend class ::org::apache::nifi::minifi::test::HttpClientStoreTestAccessor; | ||
void returnClient(minifi::http::HTTPClient& client); | ||
|
||
std::mutex clients_mutex_; | ||
std::condition_variable cv_; | ||
const size_t max_size_; | ||
std::list<gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>>> used_clients_; | ||
std::list<gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>>> unused_clients_; | ||
std::function<gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>>(const std::string&)> create_client_function_; | ||
Comment on lines
+93
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could do without the extra indirection of unique_ptr. List splicing doesn't move the data on the heap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true, unfortunately we would still need to copy or move the HTTPClient on line 56 and line 176 and those constructors are delete from the HTTPClient class. |
||
std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<HttpClientWrapper>::getLogger()}; | ||
}; | ||
|
||
enum class InvalidHTTPHeaderFieldHandlingOption { | ||
fail, | ||
transform, | ||
|
@@ -276,7 +328,7 @@ class InvokeHTTP : public core::Processor { | |
|
||
|
||
void setupMembersFromProperties(const core::ProcessContext& context); | ||
std::unique_ptr<minifi::http::HTTPClient> createHTTPClientFromMembers() const; | ||
gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>> createHTTPClientFromMembers(const std::string& url) const; | ||
|
||
http::HttpRequestMethod method_{}; | ||
std::optional<utils::Regex> attributes_to_send_; | ||
|
@@ -289,7 +341,6 @@ class InvokeHTTP : public core::Processor { | |
core::DataTransferSpeedValue maximum_upload_speed_{0}; | ||
core::DataTransferSpeedValue maximum_download_speed_{0}; | ||
|
||
std::string url_; | ||
std::shared_ptr<minifi::controllers::SSLContextService> ssl_context_service_; | ||
|
||
std::chrono::milliseconds connect_timeout_{std::chrono::seconds(30)}; | ||
|
@@ -303,7 +354,8 @@ class InvokeHTTP : public core::Processor { | |
invoke_http::InvalidHTTPHeaderFieldHandlingOption invalid_http_header_field_handling_strategy_{}; | ||
|
||
std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<InvokeHTTP>::getLogger(uuid_)}; | ||
std::shared_ptr<utils::ResourceQueue<http::HTTPClient>> client_queue_; | ||
|
||
std::unique_ptr<invoke_http::HttpClientStore> client_queue_; | ||
}; | ||
|
||
} // namespace org::apache::nifi::minifi::processors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
used_clients_
list seems unnecessary. I'd just move the used client ownership into the local context (client wrapper?) of the thread while it's used, without also keeping another list of them that needs synchronization. This way only acquiring and releasing clients need to be synchronized across threads.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would we make sure that the client returned to the HttpClientStore was a client managed by this client store in this case? Or should we just accept any clients? I'm not sure if we should manage clients not created by the same client store. Also if the used clients list is removed it should probably still needs to be replaced by at least a counter to see how many clients are created and in use to be compared with the defined max size.