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/01/05 11:36:49 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni opened a new pull request #969: MINIFICPP-1439 - Startup without agent class, handle class update

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


   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.

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



[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #969: MINIFICPP-1439 - Startup without agent class, handle class update

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


   


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

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 #969: MINIFICPP-1439 - Startup without agent class, handle class update

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



##########
File path: extensions/http-curl/tests/C2RequestClassTest.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * 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 <vector>
+#include <string>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "CivetStream.h"
+#include "StreamPipe.h"
+#include "OptionalUtils.h"
+
+class C2AcknowledgeHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    if (root.HasMember("operationId")) {
+      std::lock_guard<std::mutex> guard(mtx_);
+      acknowledged_operations_.insert(root["operationId"].GetString());
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    return true;
+  }
+
+  bool isAcknowledged(const std::string& operation_id) {
+    std::lock_guard<std::mutex> guard(mtx_);
+    return acknowledged_operations_.count(operation_id) > 0;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::set<std::string> acknowledged_operations_;
+};
+
+class C2HeartbeatHandler : public ServerAwareHandler {
+ public:
+  explicit C2HeartbeatHandler(std::string response) : response_(std::move(response)) {}
+
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    utils::optional<std::string> agent_class;
+    if (root["agentInfo"].HasMember("agentClass")) {
+      agent_class = root["agentInfo"]["agentClass"].GetString();
+    }
+    {
+      std::lock_guard<std::mutex> lock(mtx_);
+      classes_.push_back(agent_class);
+    }
+
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
+              response_.length());
+    mg_printf(conn, "%s", response_.c_str());
+    return true;
+  }
+
+  bool gotClassesInOrder(const std::vector<utils::optional<std::string>>& class_names) {
+    std::lock_guard<std::mutex> lock(mtx_);
+    auto it = classes_.begin();
+    for (const auto& class_name : class_names) {
+      it = std::find(classes_.begin(), classes_.end(), class_name);
+      if (it == classes_.end()) {
+        return false;
+      }
+      ++it;
+    }
+    return true;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::vector<utils::optional<std::string>> classes_;

Review comment:
       Do we really need optional here?
   Using empty string instead would make the code a bit more simple

##########
File path: libminifi/include/c2/C2Payload.h
##########
@@ -182,6 +197,8 @@ class C2Payload : public state::Update {
   Operation op_;
   bool raw_{ false };
   std::vector<char> raw_data_;
+  // TODO(adebreceni): isResponse is currently unused and incorrectly

Review comment:
       I think this can be addressed in scope of this PR (doesn't seem to have a big impact)

##########
File path: extensions/http-curl/tests/C2RequestClassTest.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * 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 <vector>
+#include <string>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "CivetStream.h"
+#include "StreamPipe.h"
+#include "OptionalUtils.h"
+
+class C2AcknowledgeHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    if (root.HasMember("operationId")) {
+      std::lock_guard<std::mutex> guard(mtx_);
+      acknowledged_operations_.insert(root["operationId"].GetString());
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    return true;
+  }
+
+  bool isAcknowledged(const std::string& operation_id) {

Review comment:
       nitpicking: const (the mutexneeds to be mutable in this case)




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

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



[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #969: MINIFICPP-1439 - Startup without agent class, handle class update

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


   


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

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



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #969: MINIFICPP-1439 - Startup without agent class, handle class update

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



##########
File path: extensions/http-curl/tests/C2RequestClassTest.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * 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 <vector>
+#include <string>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "CivetStream.h"
+#include "StreamPipe.h"
+#include "OptionalUtils.h"
+
+class C2AcknowledgeHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    if (root.HasMember("operationId")) {
+      std::lock_guard<std::mutex> guard(mtx_);
+      acknowledged_operations_.insert(root["operationId"].GetString());
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    return true;
+  }
+
+  bool isAcknowledged(const std::string& operation_id) {
+    std::lock_guard<std::mutex> guard(mtx_);
+    return acknowledged_operations_.count(operation_id) > 0;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::set<std::string> acknowledged_operations_;
+};
+
+class C2HeartbeatHandler : public ServerAwareHandler {
+ public:
+  explicit C2HeartbeatHandler(std::string response) : response_(std::move(response)) {}
+
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    utils::optional<std::string> agent_class;
+    if (root["agentInfo"].HasMember("agentClass")) {
+      agent_class = root["agentInfo"]["agentClass"].GetString();
+    }
+    {
+      std::lock_guard<std::mutex> lock(mtx_);
+      classes_.push_back(agent_class);
+    }
+
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
+              response_.length());
+    mg_printf(conn, "%s", response_.c_str());
+    return true;
+  }
+
+  bool gotClassesInOrder(const std::vector<utils::optional<std::string>>& class_names) {
+    std::lock_guard<std::mutex> lock(mtx_);
+    auto it = classes_.begin();
+    for (const auto& class_name : class_names) {
+      it = std::find(classes_.begin(), classes_.end(), class_name);
+      if (it == classes_.end()) {
+        return false;
+      }
+      ++it;
+    }
+    return true;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::vector<utils::optional<std::string>> classes_;

Review comment:
       I would like to distinguish between a heartbeat sending an empty agent class, and a heartbeat sending no agent class




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

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



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #969: MINIFICPP-1439 - Startup without agent class, handle class update

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



##########
File path: extensions/http-curl/tests/C2RequestClassTest.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * 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 <vector>
+#include <string>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "CivetStream.h"
+#include "StreamPipe.h"
+#include "OptionalUtils.h"
+
+class C2AcknowledgeHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    if (root.HasMember("operationId")) {
+      std::lock_guard<std::mutex> guard(mtx_);
+      acknowledged_operations_.insert(root["operationId"].GetString());
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    return true;
+  }
+
+  bool isAcknowledged(const std::string& operation_id) {
+    std::lock_guard<std::mutex> guard(mtx_);
+    return acknowledged_operations_.count(operation_id) > 0;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::set<std::string> acknowledged_operations_;
+};
+
+class C2HeartbeatHandler : public ServerAwareHandler {
+ public:
+  explicit C2HeartbeatHandler(std::string response) : response_(std::move(response)) {}
+
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    utils::optional<std::string> agent_class;
+    if (root["agentInfo"].HasMember("agentClass")) {
+      agent_class = root["agentInfo"]["agentClass"].GetString();
+    }
+    {
+      std::lock_guard<std::mutex> lock(mtx_);
+      classes_.push_back(agent_class);
+    }
+
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
+              response_.length());
+    mg_printf(conn, "%s", response_.c_str());
+    return true;
+  }
+
+  bool gotClassesInOrder(const std::vector<utils::optional<std::string>>& class_names) {
+    std::lock_guard<std::mutex> lock(mtx_);
+    auto it = classes_.begin();
+    for (const auto& class_name : class_names) {
+      it = std::find(classes_.begin(), classes_.end(), class_name);
+      if (it == classes_.end()) {
+        return false;
+      }
+      ++it;
+    }
+    return true;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::vector<utils::optional<std::string>> classes_;

Review comment:
       but I don't have strong feelings for this version, should I change it?




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

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



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #969: MINIFICPP-1439 - Startup without agent class, handle class update

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



##########
File path: libminifi/include/c2/C2Payload.h
##########
@@ -182,6 +197,8 @@ class C2Payload : public state::Update {
   Operation op_;
   bool raw_{ false };
   std::vector<char> raw_data_;
+  // TODO(adebreceni): isResponse is currently unused and incorrectly

Review comment:
       done in #971 

##########
File path: extensions/http-curl/tests/C2RequestClassTest.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * 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 <vector>
+#include <string>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "CivetStream.h"
+#include "StreamPipe.h"
+#include "OptionalUtils.h"
+
+class C2AcknowledgeHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    if (root.HasMember("operationId")) {
+      std::lock_guard<std::mutex> guard(mtx_);
+      acknowledged_operations_.insert(root["operationId"].GetString());
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    return true;
+  }
+
+  bool isAcknowledged(const std::string& operation_id) {

Review comment:
       done




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

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



[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #969: MINIFICPP-1439 - Startup without agent class, handle class update

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



##########
File path: extensions/http-curl/tests/C2RequestClassTest.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * 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 <vector>
+#include <string>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "CivetStream.h"
+#include "StreamPipe.h"
+#include "OptionalUtils.h"
+
+class C2AcknowledgeHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    if (root.HasMember("operationId")) {
+      std::lock_guard<std::mutex> guard(mtx_);
+      acknowledged_operations_.insert(root["operationId"].GetString());
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    return true;
+  }
+
+  bool isAcknowledged(const std::string& operation_id) {
+    std::lock_guard<std::mutex> guard(mtx_);
+    return acknowledged_operations_.count(operation_id) > 0;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::set<std::string> acknowledged_operations_;
+};
+
+class C2HeartbeatHandler : public ServerAwareHandler {
+ public:
+  explicit C2HeartbeatHandler(std::string response) : response_(std::move(response)) {}
+
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    utils::optional<std::string> agent_class;
+    if (root["agentInfo"].HasMember("agentClass")) {
+      agent_class = root["agentInfo"]["agentClass"].GetString();
+    }
+    {
+      std::lock_guard<std::mutex> lock(mtx_);
+      classes_.push_back(agent_class);
+    }
+
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
+              response_.length());
+    mg_printf(conn, "%s", response_.c_str());
+    return true;
+  }
+
+  bool gotClassesInOrder(const std::vector<utils::optional<std::string>>& class_names) {
+    std::lock_guard<std::mutex> lock(mtx_);
+    auto it = classes_.begin();
+    for (const auto& class_name : class_names) {
+      it = std::find(classes_.begin(), classes_.end(), class_name);
+      if (it == classes_.end()) {
+        return false;
+      }
+      ++it;
+    }
+    return true;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::vector<utils::optional<std::string>> classes_;

Review comment:
       well, I am leaning towards considering a heartbeat with `""` agent class an error (although we do not check for such cases), it all depends on what the constraints of the c2 protocol are, do you think an `""` agent class should have the same semantics as a "missing" agent class, or we could even abandon the "missing" agent class, and use the empty string to denote an agent with non-specified class?




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

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 #969: MINIFICPP-1439 - Startup without agent class, handle class update

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



##########
File path: extensions/http-curl/tests/C2RequestClassTest.cpp
##########
@@ -0,0 +1,139 @@
+/**
+ *
+ * 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 <vector>
+#include <string>
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "CivetStream.h"
+#include "StreamPipe.h"
+#include "OptionalUtils.h"
+
+class C2AcknowledgeHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    if (root.HasMember("operationId")) {
+      std::lock_guard<std::mutex> guard(mtx_);
+      acknowledged_operations_.insert(root["operationId"].GetString());
+    }
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
+    return true;
+  }
+
+  bool isAcknowledged(const std::string& operation_id) {
+    std::lock_guard<std::mutex> guard(mtx_);
+    return acknowledged_operations_.count(operation_id) > 0;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::set<std::string> acknowledged_operations_;
+};
+
+class C2HeartbeatHandler : public ServerAwareHandler {
+ public:
+  explicit C2HeartbeatHandler(std::string response) : response_(std::move(response)) {}
+
+  bool handlePost(CivetServer *server, struct mg_connection *conn) override {
+    std::string req = readPayload(conn);
+    rapidjson::Document root;
+    root.Parse(req.data(), req.size());
+    utils::optional<std::string> agent_class;
+    if (root["agentInfo"].HasMember("agentClass")) {
+      agent_class = root["agentInfo"]["agentClass"].GetString();
+    }
+    {
+      std::lock_guard<std::mutex> lock(mtx_);
+      classes_.push_back(agent_class);
+    }
+
+    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+                    "text/plain\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
+              response_.length());
+    mg_printf(conn, "%s", response_.c_str());
+    return true;
+  }
+
+  bool gotClassesInOrder(const std::vector<utils::optional<std::string>>& class_names) {
+    std::lock_guard<std::mutex> lock(mtx_);
+    auto it = classes_.begin();
+    for (const auto& class_name : class_names) {
+      it = std::find(classes_.begin(), classes_.end(), class_name);
+      if (it == classes_.end()) {
+        return false;
+      }
+      ++it;
+    }
+    return true;
+  }
+
+ private:
+  std::mutex mtx_;
+  std::vector<utils::optional<std::string>> classes_;

Review comment:
       I think that's correct, but usecase-wise I see no difference between the two. 
   Do you think there is any?




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

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