You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ph...@apache.org on 2018/11/29 14:37:28 UTC

nifi-minifi-cpp git commit: MINIFICPP-681 - Minor fixes and improvements of HashContent proc. and related docs

Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master b53f497f3 -> 298b5dcce


MINIFICPP-681 - Minor fixes and improvements of HashContent proc. and related docs

This closes #452.

Signed-off-by: Marc Parisi <ph...@apache.org>


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/298b5dcc
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/298b5dcc
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/298b5dcc

Branch: refs/heads/master
Commit: 298b5dcce0d1f04175b96eb9eec69eafbc634f1f
Parents: b53f497
Author: Arpad Boda <ab...@hortonworks.com>
Authored: Thu Nov 29 13:13:26 2018 +0100
Committer: Marc Parisi <ph...@apache.org>
Committed: Thu Nov 29 08:52:11 2018 -0500

----------------------------------------------------------------------
 PROCESSORS.md                              |  5 +++--
 libminifi/include/processors/HashContent.h |  9 ++++++---
 libminifi/src/processors/HashContent.cpp   | 18 ++++++++++++++++--
 3 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/298b5dcc/PROCESSORS.md
----------------------------------------------------------------------
diff --git a/PROCESSORS.md b/PROCESSORS.md
index f07a74a..9b77a61 100644
--- a/PROCESSORS.md
+++ b/PROCESSORS.md
@@ -148,13 +148,14 @@ default values, and whether a property supports the NiFi Expression Language.
 | - | - | - | - |
 | Hash Attribute | Checksum | | Name of the attribute the processor will use to add the checksum |
 | Hash Algorithm | MD5 | MD5, SHA1, SHA256 | Name of the algorithm used to calculate the checksum |
+| Fail on empty | false | false, true | Route flow files with empty content to failure relationship |
 
 ### Relationships
 
 | Name | Description |
 | - | - |
-| success | All FlowFiles are routed to this relationship. |
-
+| success | By default all flow files are routed to this relationship. |
+| failure | In case "Fail on empty" property is set to true, flow files with empty content are routed to this relationship. |
 
 ## ConvertHeartBeat
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/298b5dcc/libminifi/include/processors/HashContent.h
----------------------------------------------------------------------
diff --git a/libminifi/include/processors/HashContent.h b/libminifi/include/processors/HashContent.h
index acafd0f..28b865a 100644
--- a/libminifi/include/processors/HashContent.h
+++ b/libminifi/include/processors/HashContent.h
@@ -153,15 +153,17 @@ class HashContent : public core::Processor {
   //! Supported Properties
   static core::Property HashAttribute;
   static core::Property HashAlgorithm;
+  static core::Property FailOnEmpty;
   //! Supported Relationships
   static core::Relationship Success;
+  static core::Relationship Failure;
 
-  void onSchedule(core::ProcessContext *context, core::ProcessSessionFactory *sessionFactory) override;
+  void onSchedule(core::ProcessContext *context, core::ProcessSessionFactory *sessionFactory);  // override
 
   //! OnTrigger method, implemented by NiFi HashContent
-  void onTrigger(core::ProcessContext *context, core::ProcessSession *session) override;
+  void onTrigger(core::ProcessContext *context, core::ProcessSession *session);  // override
   //! Initialize, over write by NiFi HashContent
-  void initialize(void) override;
+  void initialize(void);  // override
 
   class ReadCallback : public InputStreamCallback {
    public:
@@ -181,6 +183,7 @@ class HashContent : public core::Processor {
   std::shared_ptr<logging::Logger> logger_;
   std::string algoName_;
   std::string attrKey_;
+  bool failOnEmpty_;
 };
 
 REGISTER_RESOURCE(HashContent);

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/298b5dcc/libminifi/src/processors/HashContent.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/processors/HashContent.cpp b/libminifi/src/processors/HashContent.cpp
index e76a368..962e70c 100644
--- a/libminifi/src/processors/HashContent.cpp
+++ b/libminifi/src/processors/HashContent.cpp
@@ -36,8 +36,10 @@ namespace minifi {
 namespace processors {
 
 core::Property HashContent::HashAttribute("Hash Attribute", "Attribute to store checksum to", "Checksum");
-core::Property HashContent::HashAlgorithm("Hash Algorithm", "Name of the algorithm used to generate checksum", "MD5");
+core::Property HashContent::HashAlgorithm("Hash Algorithm", "Name of the algorithm used to generate checksum", "SHA256");
+core::Property HashContent::FailOnEmpty("Fail on empty", "Route to failure relationship in case of empty content", "false");
 core::Relationship HashContent::Success("success", "success operational on the flow record");
+core::Relationship HashContent::Failure("failure", "failure operational on the flow record");
 
 void HashContent::initialize() {
   //! Set the supported properties
@@ -48,6 +50,7 @@ void HashContent::initialize() {
   //! Set the supported relationships
   std::set<core::Relationship> relationships;
   relationships.insert(Success);
+  relationships.insert(Failure);
   setSupportedRelationships(relationships);
 }
 
@@ -55,7 +58,14 @@ void HashContent::onSchedule(core::ProcessContext *context, core::ProcessSession
   std::string value;
 
   attrKey_ = (context->getProperty(HashAttribute.getName(), value)) ? value : "Checksum";
-  algoName_ = (context->getProperty(HashAlgorithm.getName(), value)) ? value : "MD5";
+  algoName_ = (context->getProperty(HashAlgorithm.getName(), value)) ? value : "SHA256";
+
+  if (context->getProperty(HashAlgorithm.getName(), value)) {
+    bool bool_value;
+    failOnEmpty_ = utils::StringUtils::StringToBool(value, bool_value) && bool_value;  // Only true in case of valid true string
+  } else {
+    failOnEmpty_ = false;
+  }
 
   std::transform(algoName_.begin(), algoName_.end(), algoName_.begin(), ::toupper);
 
@@ -70,6 +80,10 @@ void HashContent::onTrigger(core::ProcessContext *, core::ProcessSession *sessio
     return;
   }
 
+  if (failOnEmpty_ && flowFile->getSize() == 0) {
+    session->transfer(flowFile, Failure);
+  }
+
   ReadCallback cb(flowFile, *this);
   session->read(flowFile, &cb);
   session->transfer(flowFile, Success);