Skip to content

Comments

MINIFICPP-269 Implement ApplyTemplate processor#157

Closed
calebj wants to merge 3 commits intoapache:masterfrom
NiFiLocal:ApplyTemplate
Closed

MINIFICPP-269 Implement ApplyTemplate processor#157
calebj wants to merge 3 commits intoapache:masterfrom
NiFiLocal:ApplyTemplate

Conversation

@calebj
Copy link
Contributor

@calebj calebj commented Oct 27, 2017

Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with MINIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file?
  • If applicable, have you updated the NOTICE file?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.

@ai-christianson
Copy link
Contributor

The code looks very clean and straightforward. Great work.

I can definitely see the utility in such a processor for efficiently generating arbitrary textual formats from structured inputs.

I will build and test this and get back to you if I notice any issues.

std::shared_ptr<core::Processor> processor = std::make_shared<org::apache::nifi::minifi::processors::ApplyTemplate>("processorname");
REQUIRE(processor->getName() == "processorname");
uuid_t processoruuid;
REQUIRE(true == processor->getUUID(processoruuid));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: simplify to REQUIRE(processor->getUUID(processoruuid));

std::stringstream output_buf;
output_buf << output_file.rdbuf();
std::string output_contents = output_buf.str();
REQUIRE(output_contents == EXPECT_OUTPUT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, concise test condition.

@ai-christianson
Copy link
Contributor

There are a few clang-tidy issues that come up, which are mostly valid if minor.

Other than that, looks good to me.

@calebj calebj changed the title MINIFI-269 Implement ApplyTemplate processor MINIFICPP-269 Implement ApplyTemplate processor Oct 30, 2017
@calebj calebj force-pushed the ApplyTemplate branch 2 times, most recently from 5600f29 to f1ee73a Compare October 30, 2017 11:31
include_directories(../thirdparty/civetweb-1.9.1/include)
include_directories(../thirdparty/jsoncpp/include)
include_directories(../thirdparty/concurrentqueue/)
include_directories(../thirdparty/bustache/include)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to include this here, but rather in the your extension's CMakeLists

private:
//! Logger
std::shared_ptr<logging::Logger> logger_;
core::ProcessContext *_ctx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private:
//! Logger
std::shared_ptr<logging::Logger> logger_;
core::ProcessContext *_ctx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the use of storing the raw pointer. Functors exist to provide on trigger and onschedule with the shared pointers. Please use those instead.

ApplyTemplate(std::string name, uuid_t uuid = NULL)
: Processor(name, uuid)
{
logger_ = logging::LoggerFactory<ApplyTemplate>::getLogger();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With logger_ we should consider using the initializer list

@calebj calebj force-pushed the ApplyTemplate branch 6 times, most recently from 4989cec to 5f582dd Compare November 2, 2017 11:48
setSupportedRelationships(relationships);
}

void ApplyTemplate::onTrigger(core::ProcessContext *context, core::ProcessSession *session) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared ptr variants of these have for a while, so let's move to that for new processors. While the raw pointers exist I want to ensure new processors used the shared pointer calls.

flowFile_ = flowFile;
}

int64_t ApplyTemplate::WriteCallback::process(std::shared_ptr<io::BaseStream> stream) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ref on this call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't let me declare a different prototype than the virtual one in OutputStreamCallback

[ 85%] Building CXX object extensions/bustache/CMakeFiles/minifi-bustache-extensions.dir/ApplyTemplate.cpp.o
/home/ubuntu/workspace/extensions/bustache/ApplyTemplate.cpp: In member function ‘virtual void org::apache::nifi::minifi::processors::ApplyTemplate::onTrigger(const std::shared_ptr<org::apache::nifi::minifi::core::ProcessContext>&, const std::shared_ptr<org::apache::nifi::minifi::core::ProcessSession>&)’:
/home/ubuntu/workspace/extensions/bustache/ApplyTemplate.cpp:66:19: error: cannot declare variable ‘cb’ to be of abstract type ‘org::apache::nifi::minifi::processors::ApplyTemplate::WriteCallback’
     WriteCallback cb(templateFile, std::shared_ptr<core::FlowFile>(flowFile));
                   ^
In file included from /home/ubuntu/workspace/extensions/bustache/ApplyTemplate.cpp:32:0:
/home/ubuntu/workspace/extensions/bustache/ApplyTemplate.h:61:11: note:   because the following virtual functions are pure within ‘org::apache::nifi::minifi::processors::ApplyTemplate::WriteCallback’:
     class WriteCallback : public OutputStreamCallback {
           ^
In file included from /home/ubuntu/workspace/extensions/bustache/../../libminifi/include/core/ProcessSession.h:31:0,
                 from /home/ubuntu/workspace/extensions/bustache/../../libminifi/include/core/Processor.h:42,
                 from /home/ubuntu/workspace/extensions/bustache/ApplyTemplate.h:25,
                 from /home/ubuntu/workspace/extensions/bustache/ApplyTemplate.cpp:32:
/home/ubuntu/workspace/extensions/bustache/../../libminifi/include/FlowFileRecord.h:97:19: note:        virtual int64_t org::apache::nifi::minifi::OutputStreamCallback::process(std::shared_ptr<org::apache::nifi::minifi::io::BaseStream>)
   virtual int64_t process(std::shared_ptr<io::BaseStream> stream) = 0;
                   ^
make[2]: *** [extensions/bustache/CMakeFiles/minifi-bustache-extensions.dir/ApplyTemplate.cpp.o] Error 1
make[1]: *** [extensions/bustache/CMakeFiles/minifi-bustache-extensions.dir/all] Error 2
make: *** [all] Error 2

class WriteCallback : public OutputStreamCallback {
public:
WriteCallback(const std::string& templateFile, std::shared_ptr<core::FlowFile> flowFile);
int64_t process(std::shared_ptr<io::BaseStream> stream);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ref shared pointers here, please.

}

virtual std::unique_ptr<ObjectFactory> assign(const std::string &class_name) {
std::string name = class_name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like dead code here.

@calebj calebj force-pushed the ApplyTemplate branch 10 times, most recently from 8e10ed3 to f09be82 Compare November 9, 2017 15:07
@calebj calebj force-pushed the ApplyTemplate branch 2 times, most recently from 11cf1e8 to ed79c61 Compare November 13, 2017 17:03
@calebj
Copy link
Contributor Author

calebj commented Nov 13, 2017

Is there an estimate as to when this can be merged?

CMakeLists.txt Outdated

## Bustache/template extensions
option(DISABLE_BUSTACHE "Disables Bustache (ApplyTemplate) support." OFF)
if (NOT DISABLE_BUSTACHE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this ENABLE_BUSTACHE

@calebj calebj force-pushed the ApplyTemplate branch 7 times, most recently from 4cc44a8 to 40f9237 Compare November 20, 2017 12:31
@calebj calebj force-pushed the ApplyTemplate branch 7 times, most recently from 54cbeb6 to b7fcca1 Compare November 27, 2017 19:31
endif()

## Bustache/template extensions
option(ENABLE_BUSTACHE "Enables Bustache (ApplyTemplate) support." OFF)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem to conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What with?

Copy link
Contributor

@phrocker phrocker Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your conditional is DISABLE_BUSTACHE. Your option is ENABLE_BUSTACHE. It seems to only be enabled if you DISABLE_BUSTACHE per the conditional below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my bad. Fixing that uncovered a missing include, but both issues are resolved in the latest push.

Copy link
Contributor

@phrocker phrocker Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll merge shortly

edit: I'll wait for travis. I had a build failure on my mac:

/Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits:4291:23: error: calling 'operator()' with incomplete return type 'bustache::value'
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/__config:392:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
              ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits:4188:23: note: expanded from macro '_LIBCPP_INVOKE_RETURN'
    noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
                      ^~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits:4308:9: note: in instantiation of exception specification for '__invoke<std::__1::function<bustache::value (const std::__1::vector<bustache::ast::content,
      std::__1::allocator<bustache::ast::content> > &)> &, const std::__1::vector<bustache::ast::content, std::__1::allocator<bustache::ast::content> > &>' requested here
        _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
        ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/__config:392:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
              ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/functional:1591:33: note: in instantiation of template class 'std::__1::__invokable_r<void, std::__1::function<bustache::value (const std::__1::vector<bustache::ast::content,
      std::__1::allocator<bustache::ast::content> > &)> &, const std::__1::vector<bustache::ast::content, std::__1::allocator<bustache::ast::content> > &>' requested here
                                __invokable<_Fp&, _ArgTypes...>::value>
                                ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/functional:1616:9: note: in instantiation of default argument for '__callable<std::__1::function<bustache::value (const std::__1::vector<bustache::ast::content,
      std::__1::allocator<bustache::ast::content> > &)> >' required here
        __callable<_Fp>::value && !is_same<_Fp, function>::value
        ^~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/functional:1618:5: note: in instantiation of default argument for 'function<std::__1::function<bustache::value (const std::__1::vector<bustache::ast::content,
      std::__1::allocator<bustache::ast::content> > &)> >' required here
    function(_Fp);
    ^~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/functional:1578:28: note: while substituting deduced template arguments into function template 'function' [with _Fp = std::__1::function<bustache::value (const
      std::__1::vector<bustache::ast::content, std::__1::allocator<bustache::ast::content> > &)>, $1 = (no value)]
class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
                           ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/functional:1670:9: note: 'operator()' declared here
    _Rp operator()(_ArgTypes...) const;
        ^
/Users/mparisi/code/apache/nifi-minifi-cpp/thirdparty/bustache/include/bustache/model.hpp:56:11: note: definition of 'bustache::value' is not complete until the closing '}'
    class value : public variant_base<value>
          ^

@calebj calebj force-pushed the ApplyTemplate branch 2 times, most recently from 6c72d27 to acae2d3 Compare November 28, 2017 20:02
@phrocker
Copy link
Contributor

phrocker commented Nov 28, 2017

@calebj change your root env in travis to be

  • CMAKE_BUILD_OPTIONS="-DENABLE_PCAP=TRUE -DENABLE_BUSTACHE=TRUE"

Unless this is a linux only extension. Is it? If it is you'll have to include the previous CMAKE_BUILD_OPTIONS. As it is now linux is ignoring PCAP because you defined it in linux and overwrote the env option.

@phrocker
Copy link
Contributor

@calebj I saw that your Travis imp run didn't build bustache, so I tried it myself. I added global to the root env https://github.com/phrocker/nifi-minifi-cpp/blob/ApplyTemplate/.travis.yml It seemed to run and build it.

I then noticed Travis passed while my build continues to Fail. Would you be okay adding A "Known Issues" referencing https://bugs.llvm.org/show_bug.cgi?id=34298 in regards to bustache not building on certain versions of os x? @apiri have any thoughts on this?

@calebj
Copy link
Contributor Author

calebj commented Nov 29, 2017

@phrocker Sure, I'll do that when I get a chance to.

@asfgit asfgit closed this in d4f0bcf Dec 13, 2017
@calebj calebj deleted the ApplyTemplate branch December 13, 2017 22:23
nghiaxlee pushed a commit to nghiaxlee/nifi-minifi-cpp that referenced this pull request Jul 8, 2019
Move ENABLE_BUSTACHE to travis root env

This closes apache#157.

Signed-off-by: Marc Parisi <phrocker@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants