You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/12/21 15:15:18 UTC

[GitHub] [nifi-minifi-cpp] martinzink opened a new pull request #1228: MINIFICPP-1703 ExecuteScript Lua documentation, tests and fixes

martinzink opened a new pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228


   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 MINIFICPP-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 main)?
   
   - [ ] 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](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] 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 GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] martinzink commented on a change in pull request #1228: MINIFICPP-1703 ExecuteScript error handling fix, more docs and tests

Posted by GitBox <gi...@apache.org>.
martinzink commented on a change in pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228#discussion_r773805246



##########
File path: extensions/script/ExecuteScript.cpp
##########
@@ -79,80 +79,72 @@ void ExecuteScript::onSchedule(core::ProcessContext *context, core::ProcessSessi
   context->getProperty(ScriptBody.getName(), script_body_);
   context->getProperty(ModuleDirectory.getName(), module_directory_);
 
-  if (script_file_.empty() && script_engine_.empty()) {
+  if (script_file_.empty() && script_body_.empty()) {
     logger_->log_error("Either Script Body or Script File must be defined");
     return;
   }
 }
 
 void ExecuteScript::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
                               const std::shared_ptr<core::ProcessSession> &session) {
-  try {
-    std::shared_ptr<script::ScriptEngine> engine;
+  std::shared_ptr<script::ScriptEngine> engine;
 
-    // Use an existing engine, if one is available
-    if (script_engine_q_.try_dequeue(engine)) {
-      logger_->log_debug("Using available %s script engine instance", script_engine_);
-    } else {
-      logger_->log_info("Creating new %s script instance", script_engine_);
-      logger_->log_info("Approximately %d %s script instances created for this processor",
-                        script_engine_q_.size_approx(),
-                        script_engine_);
+  // Use an existing engine, if one is available
+  if (script_engine_q_.try_dequeue(engine)) {
+    logger_->log_debug("Using available %s script engine instance", script_engine_);
+  } else {
+    logger_->log_info("Creating new %s script instance", script_engine_);
+    logger_->log_info("Approximately %d %s script instances created for this processor",
+                      script_engine_q_.size_approx(),
+                      script_engine_);
 
-      if (script_engine_ == "python") {
+    if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT
-        engine = createEngine<python::PythonScriptEngine>();
+      engine = createEngine<python::PythonScriptEngine>();
 #else
-        throw std::runtime_error("Python support is disabled in this build.");
+      throw std::runtime_error("Python support is disabled in this build.");
 #endif  // PYTHON_SUPPORT
-      } else if (script_engine_ == "lua") {
+    } else if (script_engine_ == "lua") {
 #ifdef LUA_SUPPORT
-        engine = createEngine<lua::LuaScriptEngine>();
+      engine = createEngine<lua::LuaScriptEngine>();
 #else
-        throw std::runtime_error("Lua support is disabled in this build.");
+      throw std::runtime_error("Lua support is disabled in this build.");
 #endif  // LUA_SUPPORT
-      }
-
-      if (engine == nullptr) {
-        throw std::runtime_error("No script engine available");
-      }
-
-      if (!script_body_.empty()) {
-        engine->eval(script_body_);
-      } else if (!script_file_.empty()) {
-        engine->evalFile(script_file_);
-      } else {
-        throw std::runtime_error("Neither Script Body nor Script File is available to execute");
-      }
     }
 
-    if (script_engine_ == "python") {
+    if (engine == nullptr) {
+      throw std::runtime_error("No script engine available");
+    }
+
+    if (!script_body_.empty()) {
+      engine->eval(script_body_);
+    } else if (!script_file_.empty()) {
+      engine->evalFile(script_file_);
+    } else {
+      throw std::runtime_error("Neither Script Body nor Script File is available to execute");
+    }
+  }
+
+  if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT

Review comment:
       I agree 👍
   This is quite old code, and I think it could really use some refactor
   (we could replace these template functions and ifdefs with some good old polymorphism, add allowable values for the ScriptEngine Property etc..)
   
   Originally I didnt wanna inflate this PR with these refactors, how about a separete PR aiming at refactoring and modernizing the ExecuteScript?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1228: MINIFICPP-1703 ExecuteScript error handling fix, more docs and tests

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228#discussion_r773279257



##########
File path: extensions/script/python/PythonScriptEngine.h
##########
@@ -57,7 +57,7 @@ struct Interpreter {
 
 Interpreter *getInterpreter();
 
-class PythonScriptEngine : public script::ScriptEngine {
+class __attribute__((visibility("default"))) PythonScriptEngine : public script::ScriptEngine {

Review comment:
       This may not compile on msvc, try doing it with a platform-specific macro.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #1228: MINIFICPP-1703 ExecuteScript error handling fix, more docs and tests

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228#discussion_r773700888



##########
File path: extensions/script/ExecuteScript.cpp
##########
@@ -79,80 +79,72 @@ void ExecuteScript::onSchedule(core::ProcessContext *context, core::ProcessSessi
   context->getProperty(ScriptBody.getName(), script_body_);
   context->getProperty(ModuleDirectory.getName(), module_directory_);
 
-  if (script_file_.empty() && script_engine_.empty()) {
+  if (script_file_.empty() && script_body_.empty()) {
     logger_->log_error("Either Script Body or Script File must be defined");
     return;
   }
 }
 
 void ExecuteScript::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
                               const std::shared_ptr<core::ProcessSession> &session) {
-  try {
-    std::shared_ptr<script::ScriptEngine> engine;
+  std::shared_ptr<script::ScriptEngine> engine;
 
-    // Use an existing engine, if one is available
-    if (script_engine_q_.try_dequeue(engine)) {
-      logger_->log_debug("Using available %s script engine instance", script_engine_);
-    } else {
-      logger_->log_info("Creating new %s script instance", script_engine_);
-      logger_->log_info("Approximately %d %s script instances created for this processor",
-                        script_engine_q_.size_approx(),
-                        script_engine_);
+  // Use an existing engine, if one is available
+  if (script_engine_q_.try_dequeue(engine)) {
+    logger_->log_debug("Using available %s script engine instance", script_engine_);
+  } else {
+    logger_->log_info("Creating new %s script instance", script_engine_);
+    logger_->log_info("Approximately %d %s script instances created for this processor",
+                      script_engine_q_.size_approx(),
+                      script_engine_);
 
-      if (script_engine_ == "python") {
+    if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT
-        engine = createEngine<python::PythonScriptEngine>();
+      engine = createEngine<python::PythonScriptEngine>();
 #else
-        throw std::runtime_error("Python support is disabled in this build.");
+      throw std::runtime_error("Python support is disabled in this build.");
 #endif  // PYTHON_SUPPORT
-      } else if (script_engine_ == "lua") {
+    } else if (script_engine_ == "lua") {
 #ifdef LUA_SUPPORT
-        engine = createEngine<lua::LuaScriptEngine>();
+      engine = createEngine<lua::LuaScriptEngine>();
 #else
-        throw std::runtime_error("Lua support is disabled in this build.");
+      throw std::runtime_error("Lua support is disabled in this build.");
 #endif  // LUA_SUPPORT
-      }
-
-      if (engine == nullptr) {
-        throw std::runtime_error("No script engine available");
-      }
-
-      if (!script_body_.empty()) {
-        engine->eval(script_body_);
-      } else if (!script_file_.empty()) {
-        engine->evalFile(script_file_);
-      } else {
-        throw std::runtime_error("Neither Script Body nor Script File is available to execute");
-      }
     }
 
-    if (script_engine_ == "python") {
+    if (engine == nullptr) {
+      throw std::runtime_error("No script engine available");
+    }
+
+    if (!script_body_.empty()) {
+      engine->eval(script_body_);
+    } else if (!script_file_.empty()) {
+      engine->evalFile(script_file_);
+    } else {
+      throw std::runtime_error("Neither Script Body nor Script File is available to execute");
+    }
+  }
+
+  if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT

Review comment:
       Wouldn't it be easier to check if engine is valid (not nullptr) here?
   In case python support is disabled, I think the error above at engine init is already thrown. 

##########
File path: extensions/script/ExecuteScript.cpp
##########
@@ -79,80 +79,72 @@ void ExecuteScript::onSchedule(core::ProcessContext *context, core::ProcessSessi
   context->getProperty(ScriptBody.getName(), script_body_);
   context->getProperty(ModuleDirectory.getName(), module_directory_);
 
-  if (script_file_.empty() && script_engine_.empty()) {
+  if (script_file_.empty() && script_body_.empty()) {
     logger_->log_error("Either Script Body or Script File must be defined");
     return;
   }
 }
 
 void ExecuteScript::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
                               const std::shared_ptr<core::ProcessSession> &session) {
-  try {
-    std::shared_ptr<script::ScriptEngine> engine;
+  std::shared_ptr<script::ScriptEngine> engine;
 
-    // Use an existing engine, if one is available
-    if (script_engine_q_.try_dequeue(engine)) {
-      logger_->log_debug("Using available %s script engine instance", script_engine_);
-    } else {
-      logger_->log_info("Creating new %s script instance", script_engine_);
-      logger_->log_info("Approximately %d %s script instances created for this processor",
-                        script_engine_q_.size_approx(),
-                        script_engine_);
+  // Use an existing engine, if one is available
+  if (script_engine_q_.try_dequeue(engine)) {
+    logger_->log_debug("Using available %s script engine instance", script_engine_);
+  } else {
+    logger_->log_info("Creating new %s script instance", script_engine_);
+    logger_->log_info("Approximately %d %s script instances created for this processor",
+                      script_engine_q_.size_approx(),
+                      script_engine_);
 
-      if (script_engine_ == "python") {
+    if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT

Review comment:
       I know it's old code, but I feel like these ifdefs are unnecessary here. 
   Python being enabled in the build could also be checked in OnSchedule. In case it's not, the processor can simply thrown an exception there, preventing ontrigger to be called ever. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1228: MINIFICPP-1703 ExecuteScript error handling fix, more docs and tests

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228#discussion_r773852660



##########
File path: extensions/script/python/PythonScriptEngine.h
##########
@@ -57,7 +57,7 @@ struct Interpreter {
 
 Interpreter *getInterpreter();
 
-class PythonScriptEngine : public script::ScriptEngine {
+class __attribute__((visibility("default"))) PythonScriptEngine : public script::ScriptEngine {

Review comment:
       It looks like we are not testing this extension on msvc. I'm fine with ignoring the error until we actually want to support this on windows.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #1228: MINIFICPP-1703 ExecuteScript error handling fix, more docs and tests

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228#discussion_r773833965



##########
File path: extensions/script/ExecuteScript.cpp
##########
@@ -79,80 +79,72 @@ void ExecuteScript::onSchedule(core::ProcessContext *context, core::ProcessSessi
   context->getProperty(ScriptBody.getName(), script_body_);
   context->getProperty(ModuleDirectory.getName(), module_directory_);
 
-  if (script_file_.empty() && script_engine_.empty()) {
+  if (script_file_.empty() && script_body_.empty()) {
     logger_->log_error("Either Script Body or Script File must be defined");
     return;
   }
 }
 
 void ExecuteScript::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
                               const std::shared_ptr<core::ProcessSession> &session) {
-  try {
-    std::shared_ptr<script::ScriptEngine> engine;
+  std::shared_ptr<script::ScriptEngine> engine;
 
-    // Use an existing engine, if one is available
-    if (script_engine_q_.try_dequeue(engine)) {
-      logger_->log_debug("Using available %s script engine instance", script_engine_);
-    } else {
-      logger_->log_info("Creating new %s script instance", script_engine_);
-      logger_->log_info("Approximately %d %s script instances created for this processor",
-                        script_engine_q_.size_approx(),
-                        script_engine_);
+  // Use an existing engine, if one is available
+  if (script_engine_q_.try_dequeue(engine)) {
+    logger_->log_debug("Using available %s script engine instance", script_engine_);
+  } else {
+    logger_->log_info("Creating new %s script instance", script_engine_);
+    logger_->log_info("Approximately %d %s script instances created for this processor",
+                      script_engine_q_.size_approx(),
+                      script_engine_);
 
-      if (script_engine_ == "python") {
+    if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT
-        engine = createEngine<python::PythonScriptEngine>();
+      engine = createEngine<python::PythonScriptEngine>();
 #else
-        throw std::runtime_error("Python support is disabled in this build.");
+      throw std::runtime_error("Python support is disabled in this build.");
 #endif  // PYTHON_SUPPORT
-      } else if (script_engine_ == "lua") {
+    } else if (script_engine_ == "lua") {
 #ifdef LUA_SUPPORT
-        engine = createEngine<lua::LuaScriptEngine>();
+      engine = createEngine<lua::LuaScriptEngine>();
 #else
-        throw std::runtime_error("Lua support is disabled in this build.");
+      throw std::runtime_error("Lua support is disabled in this build.");
 #endif  // LUA_SUPPORT
-      }
-
-      if (engine == nullptr) {
-        throw std::runtime_error("No script engine available");
-      }
-
-      if (!script_body_.empty()) {
-        engine->eval(script_body_);
-      } else if (!script_file_.empty()) {
-        engine->evalFile(script_file_);
-      } else {
-        throw std::runtime_error("Neither Script Body nor Script File is available to execute");
-      }
     }
 
-    if (script_engine_ == "python") {
+    if (engine == nullptr) {
+      throw std::runtime_error("No script engine available");
+    }
+
+    if (!script_body_.empty()) {
+      engine->eval(script_body_);
+    } else if (!script_file_.empty()) {
+      engine->evalFile(script_file_);
+    } else {
+      throw std::runtime_error("Neither Script Body nor Script File is available to execute");
+    }
+  }
+
+  if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT

Review comment:
       Makes sense to me :) 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] adamdebreceni closed pull request #1228: MINIFICPP-1703 ExecuteScript error handling fix, more docs and tests

Posted by GitBox <gi...@apache.org>.
adamdebreceni closed pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org