You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2025/01/20 16:35:25 UTC

(nifi-minifi-cpp) branch main updated (b194ce55d -> 634016bbe)

This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


    from b194ce55d MINIFICPP-2506 Fix a gcc warning
     new 4054419f3 MINIFICPP-2485 fix: Support Expression Language in InvokeHTTP "Remote URL" property
     new a469556a4 MINIFICPP-2503 Remove C2 metric duplication in heartbeat
     new 634016bbe MINIFICPP-2499 Do not log errors when loading Python helper files

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../prometheus/PrometheusMetricsPublisher.cpp      |   5 +-
 extensions/python/ExecutePythonProcessor.cpp       |   2 +
 extensions/python/PythonCreator.h                  |   4 +-
 extensions/python/PythonScriptEngine.cpp           |   2 +-
 extensions/python/PythonScriptException.h          |   7 +
 .../standard-processors/processors/InvokeHTTP.cpp  |  68 +++++--
 .../standard-processors/processors/InvokeHTTP.h    |  71 ++++++-
 .../tests/unit/HttpClientStoreTests.cpp            | 219 +++++++++++++++++++++
 .../include/core/state/nodes/ResponseNodeLoader.h  |   2 +
 libminifi/src/c2/C2MetricsPublisher.cpp            |  25 ++-
 libminifi/src/core/state/LogMetricsPublisher.cpp   |   5 +-
 .../src/core/state/MetricsPublisherFactory.cpp     |   7 +-
 .../src/core/state/nodes/ResponseNodeLoader.cpp    |   9 +
 libminifi/test/integration/C2MetricsTest.cpp       |  15 +-
 libminifi/test/unit/LogMetricsPublisherTests.cpp   |  16 +-
 15 files changed, 409 insertions(+), 48 deletions(-)
 create mode 100644 extensions/standard-processors/tests/unit/HttpClientStoreTests.cpp


(nifi-minifi-cpp) 02/03: MINIFICPP-2503 Remove C2 metric duplication in heartbeat

Posted by sz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit a469556a45b4f94c5f6f6729baf26ea670387a10
Author: Gabor Gyimesi <ga...@gmail.com>
AuthorDate: Mon Jan 20 16:54:26 2025 +0100

    MINIFICPP-2503 Remove C2 metric duplication in heartbeat
    
    Closes #1908
    
    Signed-off-by: Marton Szasz <sz...@apache.org>
---
 .../prometheus/PrometheusMetricsPublisher.cpp      |  5 +++--
 .../include/core/state/nodes/ResponseNodeLoader.h  |  2 ++
 libminifi/src/c2/C2MetricsPublisher.cpp            | 25 +++++++++++++---------
 libminifi/src/core/state/LogMetricsPublisher.cpp   |  5 +++--
 .../src/core/state/MetricsPublisherFactory.cpp     |  7 +++---
 .../src/core/state/nodes/ResponseNodeLoader.cpp    |  9 ++++++++
 libminifi/test/integration/C2MetricsTest.cpp       | 15 ++++++++++---
 libminifi/test/unit/LogMetricsPublisherTests.cpp   | 16 ++++++++------
 8 files changed, 57 insertions(+), 27 deletions(-)

diff --git a/extensions/prometheus/PrometheusMetricsPublisher.cpp b/extensions/prometheus/PrometheusMetricsPublisher.cpp
index 36f239166..f4a010f08 100644
--- a/extensions/prometheus/PrometheusMetricsPublisher.cpp
+++ b/extensions/prometheus/PrometheusMetricsPublisher.cpp
@@ -85,8 +85,9 @@ std::vector<gsl::not_null<std::shared_ptr<state::PublishedMetricProvider>>> Prom
     metric_classes_str = configuration_->get(minifi::Configuration::nifi_metrics_publisher_metrics);
   }
   if (metric_classes_str && !metric_classes_str->empty()) {
-    auto metric_classes = utils::string::split(*metric_classes_str, ",");
-    for (const std::string& clazz : metric_classes) {
+    auto metric_classes = utils::string::splitAndTrimRemovingEmpty(*metric_classes_str, ",");
+    std::unordered_set<std::string> unique_metric_classes{metric_classes.begin(), metric_classes.end()};
+    for (const std::string& clazz : unique_metric_classes) {
       auto response_nodes = response_node_loader_->loadResponseNodes(clazz);
       if (response_nodes.empty()) {
         logger_->log_warn("Metric class '{}' could not be loaded.", clazz);
diff --git a/libminifi/include/core/state/nodes/ResponseNodeLoader.h b/libminifi/include/core/state/nodes/ResponseNodeLoader.h
index 9eb55f413..31e8ac93f 100644
--- a/libminifi/include/core/state/nodes/ResponseNodeLoader.h
+++ b/libminifi/include/core/state/nodes/ResponseNodeLoader.h
@@ -69,9 +69,11 @@ class ResponseNodeLoader {
   mutable std::mutex root_mutex_;
   mutable std::mutex component_metrics_mutex_;
   mutable std::mutex system_metrics_mutex_;
+  mutable std::mutex initialization_mutex_;
   core::ProcessGroup* root_{};
   std::unordered_map<std::string, std::vector<SharedResponseNode>> component_metrics_;
   std::unordered_map<std::string, SharedResponseNode> system_metrics_;
+  std::unordered_set<std::string> initialized_metrics_;
   std::shared_ptr<Configure> configuration_;
   std::vector<std::shared_ptr<core::RepositoryMetricsSource>> repository_metric_sources_;
   std::shared_ptr<core::FlowConfiguration> flow_configuration_;
diff --git a/libminifi/src/c2/C2MetricsPublisher.cpp b/libminifi/src/c2/C2MetricsPublisher.cpp
index a58b72bf4..3e90d36fd 100644
--- a/libminifi/src/c2/C2MetricsPublisher.cpp
+++ b/libminifi/src/c2/C2MetricsPublisher.cpp
@@ -41,8 +41,9 @@ namespace org::apache::nifi::minifi::c2 {
 
 void C2MetricsPublisher::loadNodeClasses(const std::string& class_definitions, const state::response::SharedResponseNode& new_node) {
   gsl_Expects(response_node_loader_);
-  auto classes = utils::string::split(class_definitions, ",");
-  for (const std::string& clazz : classes) {
+  auto classes = utils::string::splitAndTrimRemovingEmpty(class_definitions, ",");
+  std::unordered_set<std::string> unique_classes{classes.begin(), classes.end()};
+  for (const std::string& clazz : unique_classes) {
     auto response_nodes = response_node_loader_->loadResponseNodes(clazz);
     if (response_nodes.empty()) {
       continue;
@@ -60,9 +61,10 @@ void C2MetricsPublisher::loadC2ResponseConfiguration(const std::string &prefix)
     return;
   }
 
-  std::vector<std::string> classes = utils::string::split(class_definitions, ",");
+  auto classes = utils::string::splitAndTrimRemovingEmpty(class_definitions, ",");
+  std::unordered_set<std::string> unique_classes{classes.begin(), classes.end()};
 
-  for (const std::string& metricsClass : classes) {
+  for (const std::string& metricsClass : unique_classes) {
     try {
       std::string option = utils::string::join_pack(prefix, ".", metricsClass);
       std::string classOption = option + ".classes";
@@ -97,9 +99,10 @@ state::response::SharedResponseNode C2MetricsPublisher::loadC2ResponseConfigurat
   if (!configuration_->get(prefix, class_definitions)) {
     return prev_node;
   }
-  std::vector<std::string> classes = utils::string::split(class_definitions, ",");
+  auto classes = utils::string::splitAndTrimRemovingEmpty(class_definitions, ",");
+  std::unordered_set<std::string> unique_classes{classes.begin(), classes.end()};
 
-  for (const std::string& metricsClass : classes) {
+  for (const std::string& metricsClass : unique_classes) {
     try {
       std::string option = utils::string::join_pack(prefix, ".", metricsClass);
       std::string classOption = option + ".classes";
@@ -111,8 +114,9 @@ state::response::SharedResponseNode C2MetricsPublisher::loadC2ResponseConfigurat
       }
       state::response::SharedResponseNode new_node = gsl::make_not_null(std::make_shared<state::response::ObjectNode>(name));
       if (name.find(',') != std::string::npos) {
-        std::vector<std::string> sub_classes = utils::string::split(name, ",");
-        for (const std::string& subClassStr : classes) {
+        auto sub_classes = utils::string::splitAndTrimRemovingEmpty(name, ",");
+        std::unordered_set<std::string> unique_sub_classes{sub_classes.begin(), sub_classes.end()};
+        for (const std::string& subClassStr : unique_sub_classes) {
           auto node = loadC2ResponseConfiguration(subClassStr, prev_node);
           static_cast<state::response::ObjectNode*>(prev_node.get())->add_node(node);
         }
@@ -198,9 +202,10 @@ void C2MetricsPublisher::loadMetricNodes() {
   std::string class_csv;
   std::lock_guard<std::mutex> guard{metrics_mutex_};
   if (configuration_->get(minifi::Configuration::nifi_c2_root_classes, class_csv)) {
-    std::vector<std::string> classes = utils::string::split(class_csv, ",");
+    auto classes = utils::string::splitAndTrimRemovingEmpty(class_csv, ",");
+    std::unordered_set<std::string> unique_classes{classes.begin(), classes.end()};
 
-    for (const std::string& clazz : classes) {
+    for (const std::string& clazz : unique_classes) {
       auto response_nodes = response_node_loader_->loadResponseNodes(clazz);
       if (response_nodes.empty()) {
         continue;
diff --git a/libminifi/src/core/state/LogMetricsPublisher.cpp b/libminifi/src/core/state/LogMetricsPublisher.cpp
index e31428a5a..bb91a67a5 100644
--- a/libminifi/src/core/state/LogMetricsPublisher.cpp
+++ b/libminifi/src/core/state/LogMetricsPublisher.cpp
@@ -99,9 +99,10 @@ void LogMetricsPublisher::loadMetricNodes() {
     metric_classes_str = configuration_->get(minifi::Configuration::nifi_metrics_publisher_metrics);
   }
   if (metric_classes_str && !metric_classes_str->empty()) {
-    auto metric_classes = utils::string::split(*metric_classes_str, ",");
+    auto metric_classes = utils::string::splitAndTrimRemovingEmpty(*metric_classes_str, ",");
+    std::unordered_set<std::string> unique_metric_classes{metric_classes.begin(), metric_classes.end()};
     std::lock_guard<std::mutex> lock(response_nodes_mutex_);
-    for (const std::string& clazz : metric_classes) {
+    for (const std::string& clazz : unique_metric_classes) {
       auto loaded_response_nodes = response_node_loader_->loadResponseNodes(clazz);
       if (loaded_response_nodes.empty()) {
         logger_->log_warn("Metric class '{}' could not be loaded.", clazz);
diff --git a/libminifi/src/core/state/MetricsPublisherFactory.cpp b/libminifi/src/core/state/MetricsPublisherFactory.cpp
index aba0ddf11..d44d706dc 100644
--- a/libminifi/src/core/state/MetricsPublisherFactory.cpp
+++ b/libminifi/src/core/state/MetricsPublisherFactory.cpp
@@ -41,9 +41,10 @@ std::vector<gsl::not_null<std::unique_ptr<MetricsPublisher>>> createMetricsPubli
     const std::shared_ptr<Configure>& configuration, const std::shared_ptr<state::response::ResponseNodeLoader>& response_node_loader) {
   if (auto metrics_publisher_class_str = configuration->get(minifi::Configure::nifi_metrics_publisher_class)) {
     std::vector<gsl::not_null<std::unique_ptr<MetricsPublisher>>> publishers;
-    auto publisher_classes = minifi::utils::string::split(*metrics_publisher_class_str, ",");
-    publishers.reserve(publisher_classes.size());
-    for (const auto& publisher_class : publisher_classes) {
+    auto publisher_classes = minifi::utils::string::splitAndTrimRemovingEmpty(*metrics_publisher_class_str, ",");
+    std::unordered_set<std::string> unique_publisher_classes{publisher_classes.begin(), publisher_classes.end()};
+    publishers.reserve(unique_publisher_classes.size());
+    for (const auto& publisher_class : unique_publisher_classes) {
       publishers.push_back(createMetricsPublisher(publisher_class, configuration, response_node_loader));
     }
     return publishers;
diff --git a/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp b/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp
index 68b74da48..2d892a60b 100644
--- a/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp
+++ b/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp
@@ -42,6 +42,10 @@ ResponseNodeLoader::ResponseNodeLoader(std::shared_ptr<Configure> configuration,
 }
 
 void ResponseNodeLoader::clearConfigRoot() {
+  {
+    std::lock_guard<std::mutex> guard(initialization_mutex_);
+    initialized_metrics_.clear();
+  }
   {
     std::lock_guard<std::mutex> guard(system_metrics_mutex_);
     system_metrics_.clear();
@@ -237,7 +241,11 @@ std::vector<SharedResponseNode> ResponseNodeLoader::loadResponseNodes(const std:
     return {};
   }
 
+  std::lock_guard<std::mutex> guard(initialization_mutex_);
   for (const auto& response_node : response_nodes) {
+    if (initialized_metrics_.contains(response_node->getName())) {
+      continue;
+    }
     initializeRepositoryMetrics(response_node);
     initializeQueueMetrics(response_node);
     initializeAgentIdentifier(response_node);
@@ -247,6 +255,7 @@ std::vector<SharedResponseNode> ResponseNodeLoader::loadResponseNodes(const std:
     initializeConfigurationChecksums(response_node);
     initializeFlowMonitor(response_node);
     initializeAssetInformation(response_node);
+    initialized_metrics_.insert(response_node->getName());
   }
   return response_nodes;
 }
diff --git a/libminifi/test/integration/C2MetricsTest.cpp b/libminifi/test/integration/C2MetricsTest.cpp
index 39a0a19c7..6065b5ecf 100644
--- a/libminifi/test/integration/C2MetricsTest.cpp
+++ b/libminifi/test/integration/C2MetricsTest.cpp
@@ -128,6 +128,8 @@ class MetricsHandler: public HeartbeatHandler {
 
   static bool verifyRuntimeMetrics(const rapidjson::Value& runtime_metrics) {
     return runtime_metrics.HasMember("deviceInfo") &&
+      runtime_metrics["deviceInfo"]["systemInfo"].HasMember("operatingSystem") &&
+      runtime_metrics["deviceInfo"]["networkInfo"].HasMember("hostname") &&
       runtime_metrics.HasMember("flowInfo") &&
       runtime_metrics["flowInfo"].HasMember("versionedFlowSnapshotURI") &&
       runtime_metrics["flowInfo"].HasMember("queues") &&
@@ -135,11 +137,15 @@ class MetricsHandler: public HeartbeatHandler {
       runtime_metrics["flowInfo"]["queues"].HasMember("2438e3c8-015a-1000-79ca-83af40ec1997") &&
       runtime_metrics["flowInfo"]["components"].HasMember("FlowController") &&
       runtime_metrics["flowInfo"]["components"].HasMember("GetTCP") &&
-      runtime_metrics["flowInfo"]["components"].HasMember("LogAttribute");
+      runtime_metrics["flowInfo"]["components"].HasMember("LogAttribute") &&
+      runtime_metrics.HasMember("agentInfo") &&
+      runtime_metrics["agentInfo"]["status"]["repositories"]["ff"].HasMember("size");
   }
 
   static bool verifyUpdatedRuntimeMetrics(const rapidjson::Value& runtime_metrics) {
     return runtime_metrics.HasMember("deviceInfo") &&
+      runtime_metrics["deviceInfo"]["systemInfo"].HasMember("operatingSystem") &&
+      runtime_metrics["deviceInfo"]["networkInfo"].HasMember("hostname") &&
       runtime_metrics.HasMember("flowInfo") &&
       runtime_metrics["flowInfo"].HasMember("versionedFlowSnapshotURI") &&
       runtime_metrics["flowInfo"].HasMember("queues") &&
@@ -147,7 +153,9 @@ class MetricsHandler: public HeartbeatHandler {
       runtime_metrics["flowInfo"]["queues"].HasMember("8368e3c8-015a-1003-52ca-83af40ec1332") &&
       runtime_metrics["flowInfo"]["components"].HasMember("FlowController") &&
       runtime_metrics["flowInfo"]["components"].HasMember("GenerateFlowFile") &&
-      runtime_metrics["flowInfo"]["components"].HasMember("LogAttribute");
+      runtime_metrics["flowInfo"]["components"].HasMember("LogAttribute") &&
+      runtime_metrics.HasMember("agentInfo") &&
+      runtime_metrics["agentInfo"]["status"]["repositories"]["ff"].HasMember("size");
   }
 
   static bool verifyLoadMetrics(const rapidjson::Value& load_metrics) {
@@ -186,11 +194,12 @@ class MetricsHandler: public HeartbeatHandler {
 TEST_CASE("C2MetricsTest", "[c2test]") {
   std::atomic_bool metrics_updated_successfully{false};
   VerifyC2Metrics harness(metrics_updated_successfully);
+  harness.getConfiguration()->set("nifi.c2.root.classes", "FlowInformation,AgentInformation");
   harness.getConfiguration()->set("nifi.c2.root.class.definitions", "metrics");
   harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.name", "metrics");
   harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.metrics", "runtimemetrics,loadmetrics,processorMetrics");
   harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.metrics.runtimemetrics.name", "RuntimeMetrics");
-  harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.metrics.runtimemetrics.classes", "DeviceInfoNode,FlowInformation");
+  harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.metrics.runtimemetrics.classes", "DeviceInfoNode,FlowInformation,AssetInformation,DeviceInfoNode,AgentInformation");
   harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.metrics.loadmetrics.name", "LoadMetrics");
   harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.metrics.loadmetrics.classes", "QueueMetrics,RepositoryMetrics");
   harness.getConfiguration()->set("nifi.c2.root.class.definitions.metrics.metrics.processorMetrics.name", "ProcessorMetrics");
diff --git a/libminifi/test/unit/LogMetricsPublisherTests.cpp b/libminifi/test/unit/LogMetricsPublisherTests.cpp
index 511113d37..1801bfadf 100644
--- a/libminifi/test/unit/LogMetricsPublisherTests.cpp
+++ b/libminifi/test/unit/LogMetricsPublisherTests.cpp
@@ -96,9 +96,9 @@ TEST_CASE_METHOD(LogPublisherTestFixture, "Verify multiple metric nodes in logs"
   publisher_.initialize(configuration_, response_node_loader_);
   publisher_.loadMetricNodes();
   using org::apache::nifi::minifi::test::utils::verifyLogLinePresenceInPollTime;
-  std::string expected_log = R"([info] {
-    "LogMetrics": {
-        "RepositoryMetrics": {
+  std::string expected_log_1 = R"([info] {
+    "LogMetrics": {)";
+  std::string expected_log_2 = R"("RepositoryMetrics": {
             "provenancerepository": {
                 "running": "false",
                 "full": "false",
@@ -117,10 +117,12 @@ TEST_CASE_METHOD(LogPublisherTestFixture, "Verify multiple metric nodes in logs"
                 "rocksDbTableReadersSize": "0",
                 "rocksDbAllMemoryTablesSize": "2048"
             }
-        },
-        "deviceInfo": {
+        })";
+  std::string expected_log_3 = R"("deviceInfo": {
             "identifier":)";
-  REQUIRE(verifyLogLinePresenceInPollTime(5s, expected_log));
+  REQUIRE(verifyLogLinePresenceInPollTime(5s, expected_log_1));
+  REQUIRE(verifyLogLinePresenceInPollTime(5s, expected_log_2));
+  REQUIRE(verifyLogLinePresenceInPollTime(5s, expected_log_3));
 }
 
 TEST_CASE_METHOD(LogPublisherTestFixture, "Verify reloading different metrics", "[LogMetricsPublisher]") {
@@ -218,7 +220,7 @@ TEST_CASE_METHOD(LogPublisherTestFixture, "Verify changing log level property fo
   publisher_.initialize(configuration_, response_node_loader_);
   publisher_.loadMetricNodes();
   using org::apache::nifi::minifi::test::utils::verifyLogLinePresenceInPollTime;
-  std::string expected_log = R"([debug] {
+  std::string expected_log = R"([info] {
     "LogMetrics": {
         "RepositoryMetrics": {
             "provenancerepository": {


(nifi-minifi-cpp) 01/03: MINIFICPP-2485 fix: Support Expression Language in InvokeHTTP "Remote URL" property

Posted by sz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 4054419f34b26ed552be97bb2d8c7ee6f867ceec
Author: Adam Debreceni <ad...@apache.org>
AuthorDate: Mon Jan 20 16:54:06 2025 +0100

    MINIFICPP-2485 fix: Support Expression Language in InvokeHTTP "Remote URL" property
    
    Closes #1904
    
    Signed-off-by: Marton Szasz <sz...@apache.org>
---
 .../standard-processors/processors/InvokeHTTP.cpp  |  68 +++++--
 .../standard-processors/processors/InvokeHTTP.h    |  71 ++++++-
 .../tests/unit/HttpClientStoreTests.cpp            | 219 +++++++++++++++++++++
 3 files changed, 339 insertions(+), 19 deletions(-)

diff --git a/extensions/standard-processors/processors/InvokeHTTP.cpp b/extensions/standard-processors/processors/InvokeHTTP.cpp
index 7104359a8..19f0f4361 100644
--- a/extensions/standard-processors/processors/InvokeHTTP.cpp
+++ b/extensions/standard-processors/processors/InvokeHTTP.cpp
@@ -35,6 +35,45 @@
 #include "range/v3/algorithm/any_of.hpp"
 
 namespace org::apache::nifi::minifi::processors {
+namespace invoke_http {
+
+HttpClientStore::HttpClientWrapper HttpClientStore::getClient(const std::string& url) {
+  std::unique_lock lock(clients_mutex_);
+  const auto it = std::find_if(std::begin(unused_clients_), std::end(unused_clients_), [&url](const auto& client) {
+    return client->getURL() == url;
+  });
+  if (it != std::end(unused_clients_)) {
+    used_clients_.splice(used_clients_.end(), unused_clients_, it);
+    return {*this, **it};
+  }
+
+  if (used_clients_.size() + unused_clients_.size() < max_size_) {
+    auto client = create_client_function_(url);
+    used_clients_.push_back(std::move(client));
+    return {*this, *used_clients_.back()};
+  } else {
+    cv_.wait(lock, [this] { return !unused_clients_.empty(); });
+    auto client = create_client_function_(url);
+    unused_clients_.front() = std::move(client);
+    used_clients_.splice(used_clients_.end(), unused_clients_, unused_clients_.begin());
+    return {*this, *used_clients_.back()};
+  }
+}
+
+void HttpClientStore::returnClient(http::HTTPClient& client) {
+  std::unique_lock lock(clients_mutex_);
+  const auto it = std::find_if(std::begin(used_clients_), std::end(used_clients_),
+    [&client](const auto& elem) { return &client == elem.get(); });
+  if (it == std::end(used_clients_)) {
+    logger_->log_error("Couldn't find HTTP client in client store to be returned");
+    return;
+  }
+  unused_clients_.splice(unused_clients_.end(), used_clients_, it);
+  lock.unlock();
+  cv_.notify_one();
+}
+
+}  // namespace invoke_http
 
 std::string InvokeHTTP::DefaultContentType = "application/octet-stream";
 
@@ -64,8 +103,9 @@ void setupClientTransferEncoding(http::HTTPClient& client, bool use_chunked_enco
 }  // namespace
 
 void InvokeHTTP::setupMembersFromProperties(const core::ProcessContext& context) {
-  if (!context.getProperty(URL, url_))
-    throw Exception(PROCESS_SCHEDULE_EXCEPTION, "URL property missing or invalid");
+  std::string url;
+  if (!context.getProperty(URL, url) || url.empty())
+    throw Exception(PROCESS_SCHEDULE_EXCEPTION, "URL property missing or empty");
 
   method_ = utils::parseEnumProperty<http::HttpRequestMethod>(context, Method);
 
@@ -121,9 +161,9 @@ void InvokeHTTP::setupMembersFromProperties(const core::ProcessContext& context)
   }
 }
 
-std::unique_ptr<minifi::http::HTTPClient> InvokeHTTP::createHTTPClientFromMembers() const {
-  auto client = std::make_unique<minifi::http::HTTPClient>();
-  client->initialize(method_, url_, ssl_context_service_);
+gsl::not_null<std::unique_ptr<http::HTTPClient>> InvokeHTTP::createHTTPClientFromMembers(const std::string& url) const {
+  auto client = std::make_unique<http::HTTPClient>();
+  client->initialize(method_, url, ssl_context_service_);
   setupClientTimeouts(*client, connect_timeout_, read_timeout_);
   client->setHTTPProxy(proxy_);
   client->setFollowRedirects(follow_redirects_);
@@ -133,18 +173,18 @@ std::unique_ptr<minifi::http::HTTPClient> InvokeHTTP::createHTTPClientFromMember
   client->setMaximumUploadSpeed(maximum_upload_speed_.getValue());
   client->setMaximumDownloadSpeed(maximum_download_speed_.getValue());
 
-  return client;
+  return gsl::make_not_null(std::move(client));
 }
 
 
 void InvokeHTTP::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory&) {
   setupMembersFromProperties(context);
 
-  auto create_client = [this]() -> std::unique_ptr<minifi::http::HTTPClient> {
-    return createHTTPClientFromMembers();
+  auto create_client = [this](const std::string& url) -> gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>> {
+    return createHTTPClientFromMembers(url);
   };
 
-  client_queue_ = utils::ResourceQueue<http::HTTPClient>::create(create_client, getMaxConcurrentTasks(), std::nullopt, logger_);
+  client_queue_ = std::make_unique<invoke_http::HttpClientStore>(getMaxConcurrentTasks() * 2, create_client);
 }
 
 bool InvokeHTTP::shouldEmitFlowFile() const {
@@ -202,9 +242,15 @@ void InvokeHTTP::onTrigger(core::ProcessContext& context, core::ProcessSession&
     logger_->log_debug("InvokeHTTP -- Received flowfile");
   }
 
-  auto client = client_queue_->getResource();
+  auto url = context.getProperty(URL, flow_file.get());
+  if (!url || url->empty()) {
+    logger_->log_error("InvokeHTTP -- URL is empty, transferring to failure");
+    session.transfer(flow_file, RelFailure);
+    return;
+  }
 
-  onTriggerWithClient(context, session, flow_file, *client);
+  auto client = client_queue_->getClient(*url);
+  onTriggerWithClient(context, session, flow_file, client.get());
 }
 
 void InvokeHTTP::onTriggerWithClient(core::ProcessContext& context, core::ProcessSession& session,
diff --git a/extensions/standard-processors/processors/InvokeHTTP.h b/extensions/standard-processors/processors/InvokeHTTP.h
index bb5e9d283..46caabdf6 100644
--- a/extensions/standard-processors/processors/InvokeHTTP.h
+++ b/extensions/standard-processors/processors/InvokeHTTP.h
@@ -23,6 +23,8 @@
 #include <string>
 #include <unordered_map>
 #include <utility>
+#include <optional>
+#include <list>
 
 #include "Core.h"
 #include "FlowFileRecord.h"
@@ -41,9 +43,62 @@
 #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<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, http::HTTPClient& client)
+      :client_(client), client_store_(client_store) { }
+
+    HttpClientWrapper(const HttpClientWrapper&) = delete;
+    HttpClientWrapper& operator=(const HttpClientWrapper&) = delete;
+    HttpClientWrapper(HttpClientWrapper&& src) = delete;
+    HttpClientWrapper& operator=(HttpClientWrapper&& src) = delete;
+    ~HttpClientWrapper() {
+      client_store_.returnClient(client_);
+    }
+
+    [[nodiscard]] http::HTTPClient& get() const {
+      return client_;
+    }
+
+   private:
+    http::HTTPClient& client_;
+    HttpClientStore& client_store_;
+  };
+
+  [[nodiscard]] HttpClientWrapper getClient(const std::string& url);
+
+ private:
+  friend class test::HttpClientStoreTestAccessor;
+  void returnClient(http::HTTPClient& client);
+
+  std::mutex clients_mutex_;
+  std::condition_variable cv_;
+  const size_t max_size_;
+  std::list<gsl::not_null<std::unique_ptr<http::HTTPClient>>> used_clients_;
+  std::list<gsl::not_null<std::unique_ptr<http::HTTPClient>>> unused_clients_;
+  std::function<gsl::not_null<std::unique_ptr<http::HTTPClient>>(const std::string&)> create_client_function_;
+  std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<HttpClientWrapper>::getLogger()};
+};
+
 enum class InvalidHTTPHeaderFieldHandlingOption {
     fail,
     transform,
@@ -64,8 +119,8 @@ class InvokeHTTP : public core::Processor {
   }
 
   EXTENSIONAPI static constexpr const char* Description = "An HTTP client processor which can interact with a configurable HTTP Endpoint. "
-                                                          "The destination URL and HTTP Method are configurable. FlowFile attributes are converted to HTTP headers and the "
-                                                          "FlowFile contents are included as the body of the request (if the HTTP Method is PUT, POST or PATCH).";
+      "The destination URL and HTTP Method are configurable. FlowFile attributes are converted to HTTP headers and the "
+      "FlowFile contents are included as the body of the request (if the HTTP Method is PUT, POST or PATCH).";
 
   EXTENSIONAPI static constexpr auto Method = core::PropertyDefinitionBuilder<magic_enum::enum_count<http::HttpRequestMethod>()>::createProperty("HTTP Method")
       .withDescription("HTTP request method. Methods other than POST, PUT and PATCH will be sent without a message body.")
@@ -106,7 +161,7 @@ class InvokeHTTP : public core::Processor {
   EXTENSIONAPI static constexpr auto SSLContext = core::PropertyDefinitionBuilder<0, 0, 1>::createProperty("SSL Context Service")
       .withDescription("The SSL Context Service used to provide client certificate information for TLS/SSL (https) connections.")
       .isRequired(false)
-      .withAllowedTypes<minifi::controllers::SSLContextService>()
+      .withAllowedTypes<controllers::SSLContextService>()
       .withExclusiveOfProperties({{{"Remote URL", "^http:.*$"}}})
       .build();
   EXTENSIONAPI static constexpr auto ProxyHost = core::PropertyDefinitionBuilder<>::createProperty("Proxy Host")
@@ -268,15 +323,15 @@ class InvokeHTTP : public core::Processor {
 
  private:
   void route(const std::shared_ptr<core::FlowFile>& request, const std::shared_ptr<core::FlowFile>& response, core::ProcessSession& session,
-             core::ProcessContext& context, bool is_success, int64_t status_code);
+      core::ProcessContext& context, bool is_success, int64_t status_code);
   [[nodiscard]] bool shouldEmitFlowFile() const;
   void onTriggerWithClient(core::ProcessContext& context, core::ProcessSession& session,
-                           const std::shared_ptr<core::FlowFile>& flow_file, minifi::http::HTTPClient& client);
+      const std::shared_ptr<core::FlowFile>& flow_file, http::HTTPClient& client);
   [[nodiscard]] bool appendHeaders(const core::FlowFile& flow_file, /*std::invocable<std::string, std::string>*/ auto append_header);
 
 
   void setupMembersFromProperties(const core::ProcessContext& context);
-  std::unique_ptr<minifi::http::HTTPClient> createHTTPClientFromMembers() const;
+  gsl::not_null<std::unique_ptr<http::HTTPClient>> createHTTPClientFromMembers(const std::string& url) const;
 
   http::HttpRequestMethod method_{};
   std::optional<utils::Regex> attributes_to_send_;
@@ -289,7 +344,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 +357,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
diff --git a/extensions/standard-processors/tests/unit/HttpClientStoreTests.cpp b/extensions/standard-processors/tests/unit/HttpClientStoreTests.cpp
new file mode 100644
index 000000000..c3bc7f985
--- /dev/null
+++ b/extensions/standard-processors/tests/unit/HttpClientStoreTests.cpp
@@ -0,0 +1,219 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <thread>
+
+#include "unit/TestBase.h"
+#include "unit/Catch.h"
+#include "InvokeHTTP.h"
+#include "http/BaseHTTPClient.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::test {
+
+class HttpClientStoreTestAccessor {
+ public:
+  static const std::list<gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>>>& getUsedClients(minifi::processors::invoke_http::HttpClientStore& store) {
+    return store.used_clients_;
+  }
+
+  static const std::list<gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>>>& getUnusedClients(minifi::processors::invoke_http::HttpClientStore& store) {
+    return store.unused_clients_;
+  }
+
+  static size_t getMaxSize(minifi::processors::invoke_http::HttpClientStore& store) {
+    return store.max_size_;
+  }
+};
+
+TEST_CASE("HttpClientStore can create new client for a url and is returned after it's not used anymore") {
+  minifi::processors::invoke_http::HttpClientStore store(2, [](const std::string& url) {
+    auto client = std::make_unique<minifi::http::HTTPClient>();
+    client->initialize(minifi::http::HttpRequestMethod::GET, url, nullptr);
+    return gsl::make_not_null(std::move(client));
+  });
+  REQUIRE(HttpClientStoreTestAccessor::getMaxSize(store) == 2);
+  const auto& used_clients = HttpClientStoreTestAccessor::getUsedClients(store);
+  const auto& unused_clients = HttpClientStoreTestAccessor::getUnusedClients(store);
+  REQUIRE(used_clients.empty());
+  REQUIRE(unused_clients.empty());
+  {
+    [[maybe_unused]] auto client = store.getClient("http://localhost:8080");
+    REQUIRE(used_clients.size() == 1);
+    REQUIRE(unused_clients.empty());
+  }
+
+  REQUIRE(used_clients.empty());
+  REQUIRE(unused_clients.size() == 1);
+}
+
+TEST_CASE("A http client can be reused") {
+  minifi::processors::invoke_http::HttpClientStore store(2, [](const std::string& url) {
+    auto client = std::make_unique<minifi::http::HTTPClient>();
+    client->initialize(minifi::http::HttpRequestMethod::GET, url, nullptr);
+    return gsl::make_not_null(std::move(client));
+  });
+  minifi::http::HTTPClient* client_ptr = nullptr;
+  const auto& used_clients = HttpClientStoreTestAccessor::getUsedClients(store);
+  const auto& unused_clients = HttpClientStoreTestAccessor::getUnusedClients(store);
+  {
+    auto client = store.getClient("http://localhost:8080");
+    client_ptr = &client.get();
+  }
+
+  {
+    auto client = store.getClient("http://localhost:8080");
+    REQUIRE(&client.get() == client_ptr);
+    REQUIRE(used_clients.size() == 1);
+    REQUIRE(unused_clients.empty());
+  }
+  REQUIRE(used_clients.empty());
+  REQUIRE(unused_clients.size() == 1);
+}
+
+TEST_CASE("A new url always creates a new client") {
+  minifi::processors::invoke_http::HttpClientStore store(3, [](const std::string& url) {
+    auto client = std::make_unique<minifi::http::HTTPClient>();
+    client->initialize(minifi::http::HttpRequestMethod::GET, url, nullptr);
+    return gsl::make_not_null(std::move(client));
+  });
+  const auto& used_clients = HttpClientStoreTestAccessor::getUsedClients(store);
+  const auto& unused_clients = HttpClientStoreTestAccessor::getUnusedClients(store);
+  {
+    [[maybe_unused]] auto client1 = store.getClient("http://localhost:8080");
+    [[maybe_unused]] auto client2 = store.getClient("http://localhost:8081");
+    [[maybe_unused]] auto client3 = store.getClient("http://localhost:8082");
+    REQUIRE(used_clients.size() == 3);
+    REQUIRE(unused_clients.empty());
+    CHECK(used_clients.front()->getURL() == "http://localhost:8080");
+    CHECK((*std::next(used_clients.begin(), 1))->getURL() == "http://localhost:8081");
+    CHECK((*std::next(used_clients.begin(), 2))->getURL() == "http://localhost:8082");
+  }
+  REQUIRE(used_clients.empty());
+  REQUIRE(unused_clients.size() == 3);
+  CHECK(unused_clients.front()->getURL() == "http://localhost:8082");
+  CHECK((*std::next(unused_clients.begin(), 1))->getURL() == "http://localhost:8081");
+  CHECK((*std::next(unused_clients.begin(), 2))->getURL() == "http://localhost:8080");
+}
+
+TEST_CASE("If a store is full, the first unused client is replaced by the newly requested one") {
+  minifi::processors::invoke_http::HttpClientStore store(3, [](const std::string& url) {
+    auto client = std::make_unique<minifi::http::HTTPClient>();
+    client->initialize(minifi::http::HttpRequestMethod::GET, url, nullptr);
+    return gsl::make_not_null(std::move(client));
+  });
+  const auto& used_clients = HttpClientStoreTestAccessor::getUsedClients(store);
+  const auto& unused_clients = HttpClientStoreTestAccessor::getUnusedClients(store);
+  {
+    [[maybe_unused]] auto client1 = store.getClient("http://localhost:8080");
+    {
+      [[maybe_unused]] auto client2 = store.getClient("http://localhost:8081");
+    }
+    [[maybe_unused]] auto client3 = store.getClient("http://localhost:8082");
+    REQUIRE(used_clients.size() == 2);
+    REQUIRE(unused_clients.size() == 1);
+    CHECK(unused_clients.front()->getURL() == "http://localhost:8081");
+    CHECK(used_clients.front()->getURL() == "http://localhost:8080");
+    CHECK((*std::next(used_clients.begin(), 1))->getURL() == "http://localhost:8082");
+
+    [[maybe_unused]] auto client4 = store.getClient("http://localhost:8083");
+    REQUIRE(used_clients.size() == 3);
+    REQUIRE(unused_clients.empty());
+    CHECK(used_clients.front()->getURL() == "http://localhost:8080");
+    CHECK((*std::next(used_clients.begin(), 1))->getURL() == "http://localhost:8082");
+    CHECK((*std::next(used_clients.begin(), 2))->getURL() == "http://localhost:8083");
+  }
+  REQUIRE(used_clients.empty());
+  REQUIRE(unused_clients.size() == 3);
+  CHECK(unused_clients.front()->getURL() == "http://localhost:8083");
+  CHECK((*std::next(unused_clients.begin(), 1))->getURL() == "http://localhost:8082");
+  CHECK((*std::next(unused_clients.begin(), 2))->getURL() == "http://localhost:8080");
+}
+
+TEST_CASE("Multiple unused clients are present the oldest one is replaced") {
+  minifi::processors::invoke_http::HttpClientStore store(4, [](const std::string& url) {
+    auto client = std::make_unique<minifi::http::HTTPClient>();
+    client->initialize(minifi::http::HttpRequestMethod::GET, url, nullptr);
+    return gsl::make_not_null(std::move(client));
+  });
+  const auto& used_clients = HttpClientStoreTestAccessor::getUsedClients(store);
+  const auto& unused_clients = HttpClientStoreTestAccessor::getUnusedClients(store);
+  {
+    [[maybe_unused]] auto client1 = store.getClient("http://localhost:8080");
+    {
+      [[maybe_unused]] auto client2 = store.getClient("http://localhost:8081");
+      [[maybe_unused]] auto client3 = store.getClient("http://localhost:8082");
+    }
+    [[maybe_unused]] auto client4 = store.getClient("http://localhost:8083");
+    REQUIRE(used_clients.size() == 2);
+    REQUIRE(unused_clients.size() == 2);
+    CHECK(unused_clients.front()->getURL() == "http://localhost:8082");
+    CHECK((*std::next(unused_clients.begin(), 1))->getURL() == "http://localhost:8081");
+    CHECK(used_clients.front()->getURL() == "http://localhost:8080");
+    CHECK((*std::next(used_clients.begin(), 1))->getURL() == "http://localhost:8083");
+
+    [[maybe_unused]] auto client5 = store.getClient("http://localhost:8084");
+    CHECK(unused_clients.front()->getURL() == "http://localhost:8081");
+
+    CHECK(used_clients.front()->getURL() == "http://localhost:8080");
+    CHECK((*std::next(used_clients.begin(), 1))->getURL() == "http://localhost:8083");
+    CHECK((*std::next(used_clients.begin(), 2))->getURL() == "http://localhost:8084");
+  }
+  REQUIRE(used_clients.empty());
+  REQUIRE(unused_clients.size() == 4);
+  CHECK(unused_clients.front()->getURL() == "http://localhost:8081");
+  CHECK((*std::next(unused_clients.begin(), 1))->getURL() == "http://localhost:8084");
+  CHECK((*std::next(unused_clients.begin(), 2))->getURL() == "http://localhost:8083");
+  CHECK((*std::next(unused_clients.begin(), 3))->getURL() == "http://localhost:8080");
+}
+
+TEST_CASE("If all clients are in use, the call will block until a client is returned") {
+  minifi::processors::invoke_http::HttpClientStore store(2, [](const std::string& url) {
+    auto client = std::make_unique<minifi::http::HTTPClient>();
+    client->initialize(minifi::http::HttpRequestMethod::GET, url, nullptr);
+    return gsl::make_not_null(std::move(client));
+  });
+  bool client2_created{false};
+  std::mutex mutex;
+  std::condition_variable client2_created_cv;
+  [[maybe_unused]] auto client1 = store.getClient("http://localhost:8080");
+
+  std::thread thread1([&store, &mutex, &client2_created, &client2_created_cv] {
+    std::unique_lock lock(mutex);
+    [[maybe_unused]] auto client2 = store.getClient("http://localhost:8081");
+    client2_created = true;
+    lock.unlock();
+    client2_created_cv.notify_one();
+    std::this_thread::sleep_for(300ms);
+  });
+
+  std::thread thread2([&store, &mutex, &client2_created, &client2_created_cv] {
+    std::unique_lock lock(mutex);
+    client2_created_cv.wait(lock, [&client2_created] { return client2_created; });
+    [[maybe_unused]] auto client3 = store.getClient("http://localhost:8082");
+    auto& used_clients = HttpClientStoreTestAccessor::getUsedClients(store);
+    REQUIRE(used_clients.size() == 2);
+    CHECK(used_clients.front()->getURL() == "http://localhost:8080");
+    CHECK((*std::next(used_clients.begin(), 1))->getURL() == "http://localhost:8082");
+  });
+
+  thread1.join();
+  thread2.join();
+}
+
+}  // namespace org::apache::nifi::minifi::test


(nifi-minifi-cpp) 03/03: MINIFICPP-2499 Do not log errors when loading Python helper files

Posted by sz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 634016bbe0c934678bd9f09c4a5c10e31fd3d4a8
Author: Ferenc Gerlits <fg...@gmail.com>
AuthorDate: Mon Jan 20 16:54:41 2025 +0100

    MINIFICPP-2499 Do not log errors when loading Python helper files
    
    Closes #1913
    
    Signed-off-by: Marton Szasz <sz...@apache.org>
---
 extensions/python/ExecutePythonProcessor.cpp | 2 ++
 extensions/python/PythonCreator.h            | 4 +++-
 extensions/python/PythonScriptEngine.cpp     | 2 +-
 extensions/python/PythonScriptException.h    | 7 +++++++
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/extensions/python/ExecutePythonProcessor.cpp b/extensions/python/ExecutePythonProcessor.cpp
index 7beca34d4..3cc282514 100644
--- a/extensions/python/ExecutePythonProcessor.cpp
+++ b/extensions/python/ExecutePythonProcessor.cpp
@@ -69,6 +69,8 @@ void ExecutePythonProcessor::initalizeThroughScriptEngine() {
     python_script_engine_->describe(this);
     python_script_engine_->onInitialize(this);
     processor_initialized_ = true;
+  } catch (const PythonScriptWarning&) {
+    throw;
   } catch (const std::exception& e) {
     std::string python_processor_name = python_class_name_ ? *python_class_name_ : script_file_path_;
     logger_->log_error("Failed to initialize python processor '{}' due to error: {}", python_processor_name, e.what());
diff --git a/extensions/python/PythonCreator.h b/extensions/python/PythonCreator.h
index dce65b356..ad2e5164f 100644
--- a/extensions/python/PythonCreator.h
+++ b/extensions/python/PythonCreator.h
@@ -97,8 +97,10 @@ class PythonCreator : public minifi::core::CoreComponent {
       registered_classes_.push_back(class_name);
       try {
         registerScriptDescription(class_name, full_name, path, script_name.string());
+      } catch (const PythonScriptWarning &warning) {
+        logger_->log_info("Could not process {}.py: {} -- if this is a helper file, then this is OK", script_name, warning.what());
       } catch (const std::exception &err) {
-        logger_->log_error("Cannot load {}: {}", script_name, err.what());
+        logger_->log_error("Could not process {}.py: {}", script_name, err.what());
       }
     }
   }
diff --git a/extensions/python/PythonScriptEngine.cpp b/extensions/python/PythonScriptEngine.cpp
index 60e661b05..e68ba022f 100644
--- a/extensions/python/PythonScriptEngine.cpp
+++ b/extensions/python/PythonScriptEngine.cpp
@@ -200,7 +200,7 @@ void PythonScriptEngine::initializeProcessorObject(const std::string& python_cla
       throw PythonScriptException("Could not bind 'REL_ORIGINAL' object to '" + python_class_name + "' python processor object");
     }
   } else {
-    throw PythonScriptException("No python class '" + python_class_name + "' was found!");
+    throw PythonScriptWarning("No Python class '" + python_class_name + "' was found");
   }
 }
 
diff --git a/extensions/python/PythonScriptException.h b/extensions/python/PythonScriptException.h
index 4ba0ebf87..0a0728121 100644
--- a/extensions/python/PythonScriptException.h
+++ b/extensions/python/PythonScriptException.h
@@ -25,8 +25,15 @@
 #include <stdexcept>
 
 namespace org::apache::nifi::minifi::extensions::python {
+
+class PythonScriptWarning : public std::runtime_error {
+ public:
+  explicit PythonScriptWarning(const std::string& error) : std::runtime_error(error) {}
+};
+
 class PythonScriptException : public std::runtime_error {
  public:
   explicit PythonScriptException(const std::string& error) : std::runtime_error(error) {}
 };
+
 }  // namespace org::apache::nifi::minifi::extensions::python