Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master 678aab1ea -> 21ca80b4c (forced update)


MINIFICPP-499 Incorporate property required validation metadata into agent 
manifest

This closes #332.

Signed-off-by: Marc Parisi <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/21ca80b4
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/21ca80b4
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/21ca80b4

Branch: refs/heads/master
Commit: 21ca80b4c4936a79aa35e9933c7849189aefb352
Parents: 8777ab5
Author: Andrew I. Christianson <[email protected]>
Authored: Fri May 18 14:07:16 2018 -0400
Committer: Marc Parisi <[email protected]>
Committed: Mon May 21 09:20:05 2018 -0400

----------------------------------------------------------------------
 libminifi/include/agent/build_description.h     |  6 +--
 libminifi/include/core/ConfigurableComponent.h  |  4 +-
 libminifi/include/core/Property.h               | 28 +++++++-----
 .../include/core/state/nodes/AgentInformation.h | 11 +++--
 libminifi/src/core/ConfigurableComponent.cpp    | 10 ++---
 libminifi/src/core/Property.cpp                 |  8 +++-
 .../unit/PropertyValidationAgentInfoTests.cpp   | 45 ++++++++++++++++++++
 7 files changed, 86 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/21ca80b4/libminifi/include/agent/build_description.h
----------------------------------------------------------------------
diff --git a/libminifi/include/agent/build_description.h 
b/libminifi/include/agent/build_description.h
index 314282c..b653b93 100644
--- a/libminifi/include/agent/build_description.h
+++ b/libminifi/include/agent/build_description.h
@@ -26,21 +26,19 @@ namespace apache {
 namespace nifi {
 namespace minifi {
 
-
-
 struct ClassDescription {
   explicit ClassDescription(std::string name)
       : class_name_(name),
         support_dynamic_(false) {
   }
-  explicit ClassDescription(std::string name, std::map<std::string, 
std::string> props, bool dyn)
+  explicit ClassDescription(std::string name, std::map<std::string, 
core::Property> props, bool dyn)
       : class_name_(name),
         class_properties_(props),
         support_dynamic_(dyn) {
 
   }
   std::string class_name_;
-  std::map<std::string, std::string> class_properties_;
+  std::map<std::string, core::Property> class_properties_;
   bool support_dynamic_;
 };
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/21ca80b4/libminifi/include/core/ConfigurableComponent.h
----------------------------------------------------------------------
diff --git a/libminifi/include/core/ConfigurableComponent.h 
b/libminifi/include/core/ConfigurableComponent.h
index e83e30e..d69e1c7 100644
--- a/libminifi/include/core/ConfigurableComponent.h
+++ b/libminifi/include/core/ConfigurableComponent.h
@@ -148,9 +148,9 @@ class __attribute__((visibility("default"))) 
ConfigurableComponent {
   /**
    * Returns a vector all properties
    *
-   * @return map of property keys to their descriptions.
+   * @return map of property keys to Property instances.
    */
-  std::map<std::string, std::string> getProperties();
+  std::map<std::string, Property> getProperties();
 
   virtual ~ConfigurableComponent();
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/21ca80b4/libminifi/include/core/Property.h
----------------------------------------------------------------------
diff --git a/libminifi/include/core/Property.h 
b/libminifi/include/core/Property.h
index ec228ec..9aa19e5 100644
--- a/libminifi/include/core/Property.h
+++ b/libminifi/include/core/Property.h
@@ -56,35 +56,45 @@ class Property {
   /*!
    * Create a new property
    */
+  Property(const std::string name, const std::string description, const 
std::string value, bool is_required)
+      : name_(name),
+        description_(description),
+        is_required_(is_required),
+        is_collection_(false) {
+    values_.push_back(std::string(value.c_str()));
+  }
+
   Property(const std::string name, const std::string description, const 
std::string value)
       : name_(name),
         description_(description),
-        isCollection(false) {
+        is_required_(false),
+        is_collection_(false) {
     values_.push_back(std::string(value.c_str()));
   }
 
   Property(const std::string name, const std::string description)
       : name_(name),
         description_(description),
-        isCollection(true) {
+        is_required_(false),
+        is_collection_(true) {
   }
 
   Property()
       : name_(""),
         description_(""),
-        isCollection(false) {
+        is_required_(false),
+        is_collection_(false) {
 
   }
 
   // Destructor
   virtual ~Property() {
   }
-  // Get Name for the property
+
   std::string getName() const;
-  // Get Description for the property
   std::string getDescription() const;
-  // Get value for the property
   std::string getValue() const;
+  bool getRequired() const;
   std::vector<std::string> &getValues();
 
   // Set value for the property
@@ -359,12 +369,10 @@ class Property {
   }
 
  protected:
-  // Name
   std::string name_;
-  // Description
   std::string description_;
-  bool isCollection;
-  // Value
+  bool is_required_;
+  bool is_collection_;
   std::vector<std::string> values_;
 
  private:

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/21ca80b4/libminifi/include/core/state/nodes/AgentInformation.h
----------------------------------------------------------------------
diff --git a/libminifi/include/core/state/nodes/AgentInformation.h 
b/libminifi/include/core/state/nodes/AgentInformation.h
index bc3f496..c406610 100644
--- a/libminifi/include/core/state/nodes/AgentInformation.h
+++ b/libminifi/include/core/state/nodes/AgentInformation.h
@@ -291,10 +291,15 @@ class ComponentManifest : public DeviceInformation {
 
             SerializedResponseNode descriptorDescription;
             descriptorDescription.name = "description";
-            descriptorDescription.value = prop.second;
+            descriptorDescription.value = prop.second.getDescription();
+
+            SerializedResponseNode descriptorRequired;
+            descriptorRequired.name = "required";
+            descriptorRequired.value = prop.second.getRequired();
 
             child.children.push_back(descriptorName);
             child.children.push_back(descriptorDescription);
+            child.children.push_back(descriptorRequired);
 
             props.children.push_back(child);
           }
@@ -515,7 +520,7 @@ class AgentInformation : public DeviceInformation, public 
AgentMonitor, public A
           for (auto && prop : group.class_properties_) {
             SerializedResponseNode child;
             child.name = prop.first;
-            child.value = prop.second;
+            child.value = prop.second.getDescription();
             props.children.push_back(child);
           }
 
@@ -550,7 +555,7 @@ class AgentInformation : public DeviceInformation, public 
AgentMonitor, public A
           for (auto && prop : group.class_properties_) {
             SerializedResponseNode child;
             child.name = prop.first;
-            child.value = prop.second;
+            child.value = prop.second.getDescription();
             props.children.push_back(child);
           }
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/21ca80b4/libminifi/src/core/ConfigurableComponent.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/core/ConfigurableComponent.cpp 
b/libminifi/src/core/ConfigurableComponent.cpp
index fc8a8fd..b81c20d 100644
--- a/libminifi/src/core/ConfigurableComponent.cpp
+++ b/libminifi/src/core/ConfigurableComponent.cpp
@@ -190,7 +190,7 @@ bool ConfigurableComponent::createDynamicProperty(const 
std::string &name, const
     return false;
   }
 
-  Property new_property(name, DEFAULT_DYNAMIC_PROPERTY_DESC, value);
+  Property new_property(name, DEFAULT_DYNAMIC_PROPERTY_DESC, value, false);
   logger_->log_info("Processor %s dynamic property '%s' value '%s'", 
name.c_str(), new_property.getName().c_str(), value.c_str());
   dynamic_properties_[new_property.getName()] = new_property;
   onDynamicPropertyModified({}, new_property);
@@ -243,17 +243,17 @@ std::vector<std::string> 
ConfigurableComponent::getDynamicPropertyKeys() {
   return result;
 }
 
-std::map<std::string, std::string> ConfigurableComponent::getProperties() {
+std::map<std::string, Property> ConfigurableComponent::getProperties() {
   std::lock_guard<std::mutex> lock(configuration_mutex_);
 
-  std::map<std::string, std::string> result;
+  std::map<std::string, Property> result;
 
   for (const auto &pair : properties_) {
-    result.insert(std::pair<std::string, std::string>(pair.first, 
pair.second.getDescription()));
+    result.insert({pair.first, pair.second});
   }
 
   for (const auto &pair : dynamic_properties_) {
-    result.insert(std::pair<std::string, std::string>(pair.first, 
pair.second.getDescription()));
+    result.insert({pair.first, pair.second});
   }
 
   return result;

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/21ca80b4/libminifi/src/core/Property.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/core/Property.cpp b/libminifi/src/core/Property.cpp
index 8733b59..ebfcf0c 100644
--- a/libminifi/src/core/Property.cpp
+++ b/libminifi/src/core/Property.cpp
@@ -41,12 +41,16 @@ std::string Property::getValue() const {
     return "";
 }
 
+bool Property::getRequired() const {
+  return is_required_;
+}
+
 std::vector<std::string> &Property::getValues() {
   return values_;
 }
 // Set value for the property
 void Property::setValue(std::string value) {
-  if (!isCollection) {
+  if (!is_collection_) {
     values_.clear();
     values_.push_back(std::string(value.c_str()));
   } else {
@@ -66,7 +70,7 @@ const Property &Property::operator=(const Property &other) {
   name_ = other.name_;
   values_ = other.values_;
   description_ = other.description_;
-  isCollection = other.isCollection;
+  is_collection_ = other.is_collection_;
   return *this;
 }
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/21ca80b4/libminifi/test/unit/PropertyValidationAgentInfoTests.cpp
----------------------------------------------------------------------
diff --git a/libminifi/test/unit/PropertyValidationAgentInfoTests.cpp 
b/libminifi/test/unit/PropertyValidationAgentInfoTests.cpp
new file mode 100644
index 0000000..149e4e9
--- /dev/null
+++ b/libminifi/test/unit/PropertyValidationAgentInfoTests.cpp
@@ -0,0 +1,45 @@
+/**
+ *
+ * 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 <memory>
+
+#include "../../include/core/Processor.h"
+#include "../../include/core/state/nodes/AgentInformation.h"
+#include "../TestBase.h"
+#include "io/ClientSocket.h"
+#include "core/Processor.h"
+#include "core/ClassLoader.h"
+
+TEST_CASE("TestRequired", "[required]") {
+  minifi::state::response::ComponentManifest manifest("PutFile");
+  auto serialized = manifest.serialize();
+  REQUIRE(serialized.size() > 0);
+  const auto &resp = serialized[0];
+  REQUIRE(resp.children.size() > 0);
+  const auto &processors = resp.children[0];
+  REQUIRE(processors.children.size() > 0);
+  const auto &proc_0 = processors.children[0];
+  REQUIRE(proc_0.children.size() > 0);
+  const auto &prop_descriptors = proc_0.children[0];
+  REQUIRE(prop_descriptors.children.size() > 0);
+  const auto &prop_0 = prop_descriptors.children[0];
+  REQUIRE(prop_0.children.size() >= 3);
+  const auto &prop_0_required = prop_0.children[2];
+  REQUIRE("required" == prop_0_required.name);
+  
REQUIRE(!std::dynamic_pointer_cast<minifi::state::response::BoolValue>(prop_0_required.value.getValue())->getValue());
+}

Reply via email to