You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2018/05/30 14:54:05 UTC
nifi-minifi-cpp git commit: MINIFICPP-508 Added EL support to
Template property of ApplyTemplate
Repository: nifi-minifi-cpp
Updated Branches:
refs/heads/master 4c2eef3c6 -> 44d0bcffd
MINIFICPP-508 Added EL support to Template property of ApplyTemplate
This closes #338.
Closes #306.
Signed-off-by: Aldrin Piri <al...@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/44d0bcff
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/44d0bcff
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/44d0bcff
Branch: refs/heads/master
Commit: 44d0bcffd63d18a59a4e84dabb6ed9f0975046fe
Parents: 4c2eef3
Author: Andrew I. Christianson <an...@andyic.org>
Authored: Wed May 23 11:37:22 2018 -0400
Committer: Aldrin Piri <al...@apache.org>
Committed: Wed May 30 10:53:20 2018 -0400
----------------------------------------------------------------------
PROCESSORS.md | 2 +-
extensions/bustache/ApplyTemplate.cpp | 75 ++++++++++++++----------------
extensions/bustache/ApplyTemplate.h | 66 ++++++++++++--------------
3 files changed, 67 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/44d0bcff/PROCESSORS.md
----------------------------------------------------------------------
diff --git a/PROCESSORS.md b/PROCESSORS.md
index 4588236..36c5cec 100644
--- a/PROCESSORS.md
+++ b/PROCESSORS.md
@@ -91,7 +91,7 @@ default values, and whether a property supports the NiFi Expression Language.
| Name | Default Value | Allowable Values | Description |
| - | - | - | - |
-| **Template** | | | Path to the input mustache template file |
+| **Template** | | | Path to the input mustache template file<br>**Supports Expression Language: true** |
### Relationships
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/44d0bcff/extensions/bustache/ApplyTemplate.cpp
----------------------------------------------------------------------
diff --git a/extensions/bustache/ApplyTemplate.cpp b/extensions/bustache/ApplyTemplate.cpp
index 69461fe..a9ca4d0 100644
--- a/extensions/bustache/ApplyTemplate.cpp
+++ b/extensions/bustache/ApplyTemplate.cpp
@@ -17,22 +17,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <string.h>
#include <iostream>
#include <fstream>
#include <memory>
-#include <string>
#include <set>
#include <boost/iostreams/device/mapped_file.hpp>
#include <bustache/model.hpp>
-#include <bustache/format.hpp>
#include "ApplyTemplate.h"
-#include "core/ProcessContext.h"
-#include "core/ProcessSession.h"
-
namespace org {
namespace apache {
@@ -44,53 +38,54 @@ core::Property ApplyTemplate::Template("Template", "Path to the input mustache t
core::Relationship ApplyTemplate::Success("success", "success operational on the flow record");
void ApplyTemplate::initialize() {
- //! Set the supported properties
- std::set<core::Property> properties;
- properties.insert(Template);
- setSupportedProperties(properties);
- //! Set the supported relationships
- std::set<core::Relationship> relationships;
- relationships.insert(Success);
- setSupportedRelationships(relationships);
+ //! Set the supported properties
+ std::set<core::Property> properties;
+ properties.insert(Template);
+ setSupportedProperties(properties);
+ //! Set the supported relationships
+ std::set<core::Relationship> relationships;
+ relationships.insert(Success);
+ setSupportedRelationships(relationships);
}
-void ApplyTemplate::onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) {
- auto flowFile = session->get();
+void ApplyTemplate::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
+ const std::shared_ptr<core::ProcessSession> &session) {
+ auto flow_file = session->get();
- if (!flowFile) {
- return;
- }
+ if (!flow_file) {
+ return;
+ }
- std::string templateFile;
- context->getProperty(Template.getName(), templateFile);
- WriteCallback cb(templateFile, flowFile);
- session->write(flowFile, &cb);
- session->transfer(flowFile, Success);
+ std::string template_file;
+ context->getProperty(Template.getName(), template_file, flow_file);
+ WriteCallback cb(template_file, flow_file);
+ session->write(flow_file, &cb);
+ session->transfer(flow_file, Success);
}
-ApplyTemplate::WriteCallback::WriteCallback(const std::string& path, const std::shared_ptr<core::FlowFile>& flowFile) {
- logger_ = logging::LoggerFactory<ApplyTemplate::WriteCallback>::getLogger();
- templateFile_ = path;
- flowFile_ = flowFile;
+ApplyTemplate::WriteCallback::WriteCallback(const std::string &path, const std::shared_ptr<core::FlowFile> &flow_file) {
+ logger_ = logging::LoggerFactory<ApplyTemplate::WriteCallback>::getLogger();
+ template_file_ = path;
+ flow_file_ = flow_file;
}
int64_t ApplyTemplate::WriteCallback::process(const std::shared_ptr<io::BaseStream> stream) {
- logger_->log_info("ApplyTemplate reading template file from %s", templateFile_);
- boost::iostreams::mapped_file_source file(templateFile_);
+ logger_->log_info("ApplyTemplate reading template file from %s", template_file_);
+ boost::iostreams::mapped_file_source file(template_file_);
- bustache::format format(file);
- bustache::object data;
+ bustache::format format(file);
+ bustache::object data;
- for (const auto &attr : flowFile_->getAttributes()) {
- data[attr.first] = attr.second;
- }
+ for (const auto &attr : flow_file_->getAttributes()) {
+ data[attr.first] = attr.second;
+ }
- // TODO(calebj) write ostream reciever for format() to prevent excessive copying
- std::string ostring = to_string(format(data));
- stream->writeData(reinterpret_cast<uint8_t*>(const_cast<char*>(ostring.c_str())),
- ostring.length());
+ // TODO(calebj) write ostream reciever for format() to prevent excessive copying
+ std::string ostring = to_string(format(data));
+ stream->writeData(reinterpret_cast<uint8_t *>(const_cast<char *>(ostring.c_str())),
+ ostring.length());
- return ostring.length();
+ return ostring.length();
}
} /* namespace processors */
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/44d0bcff/extensions/bustache/ApplyTemplate.h
----------------------------------------------------------------------
diff --git a/extensions/bustache/ApplyTemplate.h b/extensions/bustache/ApplyTemplate.h
index ad76feb..1e890ff 100644
--- a/extensions/bustache/ApplyTemplate.h
+++ b/extensions/bustache/ApplyTemplate.h
@@ -33,48 +33,44 @@ namespace nifi {
namespace minifi {
namespace processors {
-//! ApplyTemplate Class
+/**
+ * Applies a mustache template using incoming attributes as template parameters.
+ */
class ApplyTemplate : public core::Processor {
-public:
- //! Constructor
- /*!
- * Create a new processor
- */
- ApplyTemplate(std::string name, uuid_t uuid = NULL)
- : Processor(name, uuid),
- logger_(logging::LoggerFactory<ApplyTemplate>::getLogger()) {}
- //! Destructor
- ~ApplyTemplate() {}
- //! Processor Name
- static constexpr char const* ProcessorName = "ApplyTemplate";
- //! Supported Properties
- static core::Property Template;
- //! Supported Relationships
- static core::Relationship Success;
+ public:
+ /*!
+ * Create a new processor
+ */
+ ApplyTemplate(std::string name, uuid_t uuid = NULL)
+ : Processor(name, uuid),
+ logger_(logging::LoggerFactory<ApplyTemplate>::getLogger()) {}
+ ~ApplyTemplate() {}
+ static constexpr char const *ProcessorName = "ApplyTemplate";
- //! OnTrigger method, implemented by NiFi ApplyTemplate
- void onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session);
- //! Initialize, over write by NiFi ApplyTemplate
- void initialize(void);
+ //! Supported Properties
+ static core::Property Template;
- //! Write callback for outputting files generated by applying template to input
- class WriteCallback : public OutputStreamCallback {
- public:
- WriteCallback(const std::string& templateFile, const std::shared_ptr<core::FlowFile>& flowFile);
- int64_t process(std::shared_ptr<io::BaseStream> stream);
+ //! Supported Relationships
+ static core::Relationship Success;
- private:
- //! Logger
- std::shared_ptr<logging::Logger> logger_;
- std::string templateFile_;
- std::shared_ptr<core::FlowFile> flowFile_;
- };
+ void onTrigger(const std::shared_ptr<core::ProcessContext> &context,
+ const std::shared_ptr<core::ProcessSession> &session);
+ void initialize(void);
-protected:
+ //! Write callback for outputting files generated by applying template to input
+ class WriteCallback : public OutputStreamCallback {
+ public:
+ WriteCallback(const std::string &templateFile, const std::shared_ptr<core::FlowFile> &flow_file);
+ int64_t process(std::shared_ptr<io::BaseStream> stream);
-private:
- //! Logger
+ private:
std::shared_ptr<logging::Logger> logger_;
+ std::string template_file_;
+ std::shared_ptr<core::FlowFile> flow_file_;
+ };
+
+ private:
+ std::shared_ptr<logging::Logger> logger_;
};
REGISTER_RESOURCE(ApplyTemplate);