lordgamez commented on code in PR #1414:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1414#discussion_r1011972702
##########
extensions/standard-processors/processors/ExecuteProcess.h:
##########
@@ -89,38 +85,35 @@ class ExecuteProcess : public core::Processor {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false;
- EXTENSIONAPI static constexpr core::annotation::Input InputRequirement =
core::annotation::Input::INPUT_ALLOWED;
- EXTENSIONAPI static constexpr bool IsSingleThreaded = false;
+ EXTENSIONAPI static constexpr core::annotation::Input InputRequirement =
core::annotation::Input::INPUT_FORBIDDEN;
+ EXTENSIONAPI static constexpr bool IsSingleThreaded = true;
ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS
- public:
- // OnTrigger method, implemented by NiFi ExecuteProcess
void onTrigger(core::ProcessContext *context, core::ProcessSession *session)
override;
- // Initialize, over write by NiFi ExecuteProcess
+ void onSchedule(core::ProcessContext *context, core::ProcessSessionFactory
*session_factory) override;
void initialize() override;
private:
- // Logger
+ bool changeWorkdir() const;
+ std::vector<std::string> readArgs() const;
+ void executeProcessForkFailed();
+ void executeChildProcess(const std::vector<char*>& argv);
+ void collectChildProcessOutput(core::ProcessSession& session);
+ void readOutputInBatches(core::ProcessSession& session);
+ void readOutput(core::ProcessSession& session);
+ bool writeToFlowFile(core::ProcessSession& session,
std::shared_ptr<core::FlowFile>& flow_file, gsl::span<const char> buffer) const;
+
std::shared_ptr<core::logging::Logger> logger_ =
core::logging::LoggerFactory<ExecuteProcess>::getLogger();
- // Property
- std::string _command;
- std::string _commandArgument;
- std::string _workingDir;
- std::chrono::milliseconds _batchDuration = std::chrono::milliseconds(0);
- bool _redirectErrorStream;
- // Full command
- std::string _fullCommand;
- // whether the process is running
- bool _processRunning;
- int _pipefd[2];
- pid_t _pid;
+ std::string command_;
+ std::string command_argument_;
+ std::string working_dir_;
+ std::chrono::milliseconds batch_duration_ = std::chrono::milliseconds(0);
+ bool redirect_error_stream_;
+ std::string full_command_;
+ bool process_running_;
+ int pipefd_[2];
Review Comment:
Updated in b8a9a3297a4c6e56c02a1b5767f13596ddf7b853
##########
extensions/standard-processors/tests/unit/ExecuteProcessTests.cpp:
##########
@@ -0,0 +1,167 @@
+/**
+ * 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 <string>
+
+#include "Catch.h"
+#include "processors/ExecuteProcess.h"
+#include "SingleProcessorTestController.h"
+#include "utils/file/FileUtils.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::test {
+#ifndef WIN32
+
+class ExecuteProcessTestsFixture {
+ public:
+ ExecuteProcessTestsFixture()
+ :
execute_process_(std::make_shared<processors::ExecuteProcess>("ExecuteProcess")),
+ controller_(execute_process_) {
+ LogTestController::getInstance().setTrace<processors::ExecuteProcess>();
+ }
+ protected:
+ std::shared_ptr<processors::ExecuteProcess> execute_process_;
+ test::SingleProcessorTestController controller_;
+};
+
+TEST_CASE_METHOD(ExecuteProcessTestsFixture, "ExecuteProcess can run a single
command", "[ExecuteProcess]") {
+ REQUIRE(execute_process_->setProperty(processors::ExecuteProcess::Command,
"echo -n test"));
+
+ controller_.plan->scheduleProcessor(execute_process_);
+ auto result = controller_.trigger("data");
Review Comment:
Updated in b8a9a3297a4c6e56c02a1b5767f13596ddf7b853
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]