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 2022/03/25 12:12:00 UTC

[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1285: MINIFICPP-1779 Verify multiple C2 commands in HB response

lordgamez commented on a change in pull request #1285:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1285#discussion_r835213387



##########
File path: extensions/http-curl/tests/C2MultipleCommandsTest.cpp
##########
@@ -0,0 +1,107 @@
+/**
+ *
+ * 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.
+ */
+
+#undef NDEBUG
+#include <string>
+#include "TestBase.h"
+#include "Catch.h"
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+
+class AckAuditor {
+ public:
+  void addAck(const std::string& ack) {
+    std::lock_guard<std::mutex> guard(mutex_);
+    acknowledged_operations_.insert(ack);
+  }
+
+  bool isAcknowledged(const std::string& operation_id) const {
+    std::lock_guard<std::mutex> guard(mutex_);
+    return acknowledged_operations_.count(operation_id) > 0;
+  }
+
+ private:
+  mutable std::mutex mutex_;
+  std::unordered_set<std::string> acknowledged_operations_;
+};
+
+class MultipleC2CommandHandler: public HeartbeatHandler {
+ public:
+  explicit MultipleC2CommandHandler(AckAuditor& ack_auditor, std::shared_ptr<minifi::Configure> configuration)
+    : HeartbeatHandler(std::move(configuration)),
+      ack_auditor_(ack_auditor) {
+  }
+
+  void handleHeartbeat(const rapidjson::Document&, struct mg_connection * conn) override {
+    std::vector<C2Operation> operations{{"DESCRIBE", "manifest", "889345", {}}, {"DESCRIBE", "corecomponentstate", "889346", {}}};
+    sendHeartbeatResponse(operations, conn);
+  }
+
+  void handleAcknowledge(const rapidjson::Document& root) override {
+    if (is_odd_ack) {
+      verifyJsonHasAgentManifest(root);
+      is_odd_ack = false;
+    } else {
+      assert(root.HasMember("corecomponentstate"));
+      is_odd_ack = true;
+    }
+    if (root.IsObject() && root.HasMember("operationId")) {
+      ack_auditor_.addAck(root["operationId"].GetString());
+    }
+  }
+
+ private:
+  AckAuditor& ack_auditor_;
+  bool is_odd_ack = true;

Review comment:
       We would like to guarantee that the C2 commands are processed in their order in the request, that's why we are checking this way.




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