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 62ec9a5fd4f7ea013de997f465b9c23533ce72ae
Author: Ferenc Gerlits <[email protected]>
AuthorDate: Sat Mar 4 23:37:04 2023 +0100

    MINIFICPP-2064 Skip extensions which have not been loaded
    
    If the `componentManifest` node of the extension would be empty, then do
    not include the extension in the manifest.
    
    Closes #1521
    Signed-off-by: Marton Szasz <[email protected]>
---
 .../tests/unit/ManifestTests.cpp                   | 70 ++++++++++++++--------
 .../include/core/state/nodes/AgentInformation.h    | 13 ++--
 2 files changed, 53 insertions(+), 30 deletions(-)

diff --git a/extensions/standard-processors/tests/unit/ManifestTests.cpp 
b/extensions/standard-processors/tests/unit/ManifestTests.cpp
index a344ce3c0..002494655 100644
--- a/extensions/standard-processors/tests/unit/ManifestTests.cpp
+++ b/extensions/standard-processors/tests/unit/ManifestTests.cpp
@@ -16,24 +16,22 @@
  * limitations under the License.
  */
 
+#define EXTENSION_LIST "*minifi-system*, *minifi-standard-processors*"
+
 #include <memory>
 #include "core/state/nodes/DeviceInformation.h"
 #include "core/state/nodes/AgentInformation.h"
 #include "TestBase.h"
 #include "Catch.h"
+#include "range/v3/algorithm/contains.hpp"
 #include "range/v3/algorithm/find_if.hpp"
 
-// Include some processor headers to make sure they are part of the manifest
-#include "HashContent.h"
-#include "GetFile.h"
-#include "TailFile.h"
-
 TEST_CASE("Test Required", "[required]") {
   minifi::state::response::ComponentManifest 
manifest("minifi-standard-processors");
   auto serialized = manifest.serialize();
-  REQUIRE(serialized.size() > 0);
+  REQUIRE_FALSE(serialized.empty());
   const auto &resp = serialized[0];
-  REQUIRE(resp.children.size() > 0);
+  REQUIRE_FALSE(resp.children.empty());
   size_t processorIndex = resp.children.size();
   for (size_t i = 0; i < resp.children.size(); ++i) {
     if (resp.children[i].name == "processors") {
@@ -49,7 +47,7 @@ TEST_CASE("Test Required", "[required]") {
   });
   REQUIRE(get_file_it != processors.children.end());
 
-  REQUIRE(get_file_it->children.size() > 0);
+  REQUIRE_FALSE(get_file_it->children.empty());
   const auto& get_file_property_descriptors = get_file_it->children[0];
   const auto batch_size_property_it = 
ranges::find_if(get_file_property_descriptors.children, [](const auto& 
property) {
     return property.name == "Batch Size";
@@ -64,17 +62,17 @@ TEST_CASE("Test Required", "[required]") {
 }
 
 TEST_CASE("Test Valid Regex", "[validRegex]") {
-  minifi::state::response::ComponentManifest 
manifest("minifi-test-processors");
+  minifi::state::response::ComponentManifest 
manifest("minifi-standard-processors");
   auto serialized = manifest.serialize();
-  REQUIRE(serialized.size() > 0);
+  REQUIRE_FALSE(serialized.empty());
   const auto &resp = serialized[0];
-  REQUIRE(resp.children.size() > 0);
+  REQUIRE_FALSE(resp.children.empty());
   const auto &processors = resp.children[0];
-  REQUIRE(processors.children.size() > 0);
+  REQUIRE_FALSE(processors.children.empty());
   const auto &proc_0 = processors.children[0];
-  REQUIRE(proc_0.children.size() > 0);
+  REQUIRE_FALSE(proc_0.children.empty());
   const auto &prop_descriptors = proc_0.children[0];
-  REQUIRE(prop_descriptors.children.size() > 0);
+  REQUIRE_FALSE(prop_descriptors.children.empty());
   const auto &prop_0 = prop_descriptors.children[0];
   REQUIRE(prop_0.children.size() >= 3);
   const auto &df = prop_0.children[3];
@@ -90,11 +88,11 @@ TEST_CASE("Test Valid Regex", "[validRegex]") {
 TEST_CASE("Test Relationships", "[rel1]") {
   minifi::state::response::ComponentManifest 
manifest("minifi-standard-processors");
   auto serialized = manifest.serialize();
-  REQUIRE(serialized.size() > 0);
+  REQUIRE_FALSE(serialized.empty());
   const auto &resp = serialized[0];
-  REQUIRE(resp.children.size() > 0);
+  REQUIRE_FALSE(resp.children.empty());
   const auto &processors = resp.children[0];
-  REQUIRE(processors.children.size() > 0);
+  REQUIRE_FALSE(processors.children.empty());
   minifi::state::response::SerializedResponseNode proc_0;
   for (const auto& node : processors.children) {
     if ("org.apache.nifi.minifi.processors.PutFile" == node.name) {
@@ -112,7 +110,7 @@ TEST_CASE("Test Relationships", "[rel1]") {
   REQUIRE(isSingleThreaded.value.getValue()->getTypeIndex() == 
org::apache::nifi::minifi::state::response::Value::BOOL_TYPE);
   REQUIRE(isSingleThreaded.value.to_string() == "false");
 
-  REQUIRE(proc_0.children.size() > 0);
+  REQUIRE_FALSE(proc_0.children.empty());
   const auto& relationships = proc_0.children[3];
   REQUIRE("supportedRelationships" == relationships.name);
   // this is because they are now nested
@@ -129,11 +127,11 @@ TEST_CASE("Test Relationships", "[rel1]") {
 TEST_CASE("Test Dependent", "[dependent]") {
   minifi::state::response::ComponentManifest 
manifest("minifi-standard-processors");
   auto serialized = manifest.serialize();
-  REQUIRE(serialized.size() > 0);
+  REQUIRE_FALSE(serialized.empty());
   const auto &resp = serialized[0];
-  REQUIRE(resp.children.size() > 0);
+  REQUIRE_FALSE(resp.children.empty());
   const auto &processors = resp.children[0];
-  REQUIRE(processors.children.size() > 0);
+  REQUIRE_FALSE(processors.children.empty());
   minifi::state::response::SerializedResponseNode proc_0;
   for (const auto &node : processors.children) {
     if ("org.apache.nifi.minifi.processors.PutFile" == node.name) {
@@ -141,9 +139,9 @@ TEST_CASE("Test Dependent", "[dependent]") {
     }
   }
 #ifndef WIN32
-  REQUIRE(proc_0.children.size() > 0);
+  REQUIRE_FALSE(proc_0.children.empty());
   const auto &prop_descriptors = proc_0.children[0];
-  REQUIRE(prop_descriptors.children.size() > 0);
+  REQUIRE_FALSE(prop_descriptors.children.empty());
   const auto &prop_0 = prop_descriptors.children[1];
   REQUIRE(prop_0.children.size() >= 3);
   REQUIRE("required" == prop_0.children[3].name);
@@ -157,7 +155,7 @@ TEST_CASE("Test Dependent", "[dependent]") {
 TEST_CASE("Test Scheduling Defaults", "[schedDef]") {
   minifi::state::response::AgentManifest manifest("minifi-system");
   auto serialized = manifest.serialize();
-  REQUIRE(serialized.size() > 0);
+  REQUIRE_FALSE(serialized.empty());
   minifi::state::response::SerializedResponseNode proc_0;
   for (const auto &node : serialized) {
     if ("schedulingDefaults" == node.name) {
@@ -187,7 +185,7 @@ TEST_CASE("Test Scheduling Defaults", "[schedDef]") {
 TEST_CASE("Test operatingSystem Defaults", "[opsys]") {
   minifi::state::response::DeviceInfoNode manifest("minifi-system");
   auto serialized = manifest.serialize();
-  REQUIRE(serialized.size() > 0);
+  REQUIRE_FALSE(serialized.empty());
   minifi::state::response::SerializedResponseNode proc_0;
   for (const auto &node : serialized) {
     if ("systemInfo" == node.name) {
@@ -203,3 +201,25 @@ TEST_CASE("Test operatingSystem Defaults", "[opsys]") {
   std::set<std::string> expected({"Linux", "Windows", "Mac OSX", "Unix"});
   REQUIRE(expected.find(proc_0.value.to_string()) != std::end(expected));
 }
+
+namespace {
+std::vector<std::string> 
listExtensionsInManifest(minifi::state::response::AgentManifest& manifest) {
+  std::vector<std::string> extensions;
+  const auto serialized = manifest.serialize();
+  for (const auto& node : serialized) {
+    if ("bundles" != node.name) { continue; }
+    for (const auto& subnode : node.children) {
+      if ("artifact" != subnode.name) { continue; }
+      extensions.push_back(subnode.value.to_string());
+    }
+  }
+  return extensions;
+}
+}  // namespace
+
+TEST_CASE("Compiled but not loaded extensions are not included in the 
manifest") {
+  minifi::state::response::AgentManifest manifest("minifi-system");
+  const auto extensions = listExtensionsInManifest(manifest);
+  CHECK(ranges::contains(extensions, "minifi-standard-processors"));
+  CHECK_FALSE(ranges::contains(extensions, "minifi-test-processors"));
+}
diff --git a/libminifi/include/core/state/nodes/AgentInformation.h 
b/libminifi/include/core/state/nodes/AgentInformation.h
index 3de8ad837..5e699c6a3 100644
--- a/libminifi/include/core/state/nodes/AgentInformation.h
+++ b/libminifi/include/core/state/nodes/AgentInformation.h
@@ -352,6 +352,14 @@ class Bundles : public DeviceInformation {
       SerializedResponseNode bundle;
       bundle.name = "bundles";
 
+      ComponentManifest component_manifest(group);
+      const auto components = component_manifest.serialize();
+      gsl_Expects(components.size() == 1);
+      if (components[0].children.empty()) {
+        continue;
+      }
+      bundle.children.push_back(components[0]);
+
       SerializedResponseNode bgroup;
       bgroup.name = "group";
       bgroup.value = GROUP_STR;
@@ -366,11 +374,6 @@ class Bundles : public DeviceInformation {
       bundle.children.push_back(artifact);
       bundle.children.push_back(version);
 
-      ComponentManifest compMan(group);
-      // serialize the component information.
-      for (auto component : compMan.serialize()) {
-        bundle.children.push_back(component);
-      }
       serialized.push_back(bundle);
     }
 

Reply via email to