lordgamez commented on code in PR #2057:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2057#discussion_r2489615392


##########
libminifi/test/libtest/integration/HTTPHandlers.cpp:
##########
@@ -453,18 +453,33 @@ void HeartbeatHandler::verifySupportedOperations(const 
rapidjson::Document& root
   REQUIRE(operations == 
std::set<std::string>(magic_enum::enum_names<minifi::c2::Operation>().begin(), 
magic_enum::enum_names<minifi::c2::Operation>().end()));
 }
 
-bool StoppingHeartbeatHandler::handlePost(CivetServer *, struct mg_connection 
*conn) {
-  verify(conn);
-  sendStopOperation(conn);
-  return true;
-}
-void StoppingHeartbeatHandler::sendStopOperation(struct mg_connection *conn) {
-  std::string resp = "{\"operation\" : \"heartbeat\", \"requested_operations\" 
: [{ \"operationid\" : 41, \"operation\" : \"stop\", \"operand\" : 
\"2438e3c8-015a-1000-79ca-83af40ec1991\"  }, "
-      "{ \"operationid\" : 42, \"operation\" : \"stop\", \"operand\" : 
\"FlowController\"  } ]}";
+void StoppingHeartbeatHandler::sendStartStopOperation(struct mg_connection 
*conn) {
+  std::lock_guard<std::mutex> lock(post_count_mutex_);
+  std::string requested_operation;
+  if (post_count_ == 0) {
+    requested_operation = R"({ "operationid" : 41, "operation" : "stop", 
"operand" : "2438e3c8-015a-1000-79ca-83af40ec1991" })";
+  } else if (post_count_ == 1) {
+    requested_operation = R"({ "operationid" : 42, "operation" : "stop", 
"operand" : "FlowController"  })";
+  } else if (post_count_ == 2) {
+    requested_operation = R"({ "operationid" : 43, "operation" : "start", 
"operand" : "2438e3c8-015a-1000-79ca-83af40ec1991" })";

Review Comment:
   I think I just started testing them separately, and added them one by one, 
but I think the flow and component start or stop operations can be merged to 
make the test run faster, I updated in 
https://github.com/apache/nifi-minifi-cpp/pull/2057/commits/4ce50e373a42eba19a68e33a6716bcc17468a60d



##########
libminifi/test/libtest/integration/HTTPHandlers.cpp:
##########


Review Comment:
   Added negative tests in 
https://github.com/apache/nifi-minifi-cpp/pull/2057/commits/258d0e8f1a7d90a4221f75b4461f7f795b415399
   
   Currently all the integration test civet server handlers are defined here, 
but you are right that these should be refactored and we can discuss how these 
should be modularized, but I think it should be addressed in a separate PR. I 
created a jira ticket for this issue 
https://issues.apache.org/jira/browse/MINIFICPP-2663



##########
libminifi/src/c2/C2Agent.cpp:
##########
@@ -871,6 +852,46 @@ void C2Agent::handle_sync(const 
org::apache::nifi::minifi::c2::C2ContentResponse
   enqueue_c2_response(std::move(response));
 }
 
+void C2Agent::handle_start_stop(const C2ContentResponse& resp) {
+  const auto lowered_response_name = utils::string::toLower(resp.name);
+  if (lowered_response_name == "c2") {
+    std::ignore = raise(SIGTERM);
+  }
+
+  auto executeStartStopOnComponent = [this, &resp](const std::string& 
component_name) {
+    update_sink_->executeOnComponent(component_name, [this, &resp, 
&component_name] (state::StateController& component) {
+      const std::string component_message = component_name == "FlowController" 
? "all processors" : "processor " + component_name;
+      if (resp.op == Operation::stop) {
+        logger_->log_debug("Stopping {}", component_message);
+        component.stop();
+      } else {
+        logger_->log_debug("Starting {}", component_message);
+        component.start();
+      }
+    });
+  };
+
+  if (lowered_response_name == "flow" || lowered_response_name == "processor") 
{
+    if (lowered_response_name == "flow") {
+      executeStartStopOnComponent("FlowController");
+    } else {
+      auto processor_id = resp.getStringArgument("processorId");
+      if (processor_id) {
+        executeStartStopOnComponent(processor_id.value());
+      } else {
+        logger_->log_warn("Processor start/stop request missing 'processorId' 
argument");
+      }
+    }
+  } else {
+    executeStartStopOnComponent(resp.name);
+  }

Review Comment:
   Updated in 
https://github.com/apache/nifi-minifi-cpp/pull/2057/commits/4ce50e373a42eba19a68e33a6716bcc17468a60d



-- 
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]

Reply via email to