adamdebreceni commented on a change in pull request #1259:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1259#discussion_r802615166



##########
File path: extensions/http-curl/tests/C2PropertiesUpdateTests.cpp
##########
@@ -0,0 +1,189 @@
+/**
+ *
+ * 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 "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/gsl.h"
+#include "utils/IntegrationTestUtils.h"
+#include "EmpyFlow.h"
+#include "spdlog/spdlog.h"
+#include "spdlog/sinks/stdout_sinks.h"
+#include "spdlog/sinks/ostream_sink.h"
+#include "spdlog/sinks/dist_sink.h"
+#include "LogUtils.h"
+#include "properties/PropertiesFile.h"
+
+struct PropertyChange {
+  std::string name;
+  std::string value;
+  bool persist;
+};
+
+class C2HeartbeatHandler : public ServerAwareHandler {
+ public:
+  bool handlePost(CivetServer* /*server*/, struct mg_connection *conn) 
override {
+    if (response_) {
+      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());
+      response_.reset();
+    } else {
+      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;
+  }
+
+  void setProperties(const std::vector<PropertyChange>& changes) {
+    std::vector<std::string> fields;
+    for (const auto& change : changes) {
+      fields.push_back(fmt::format(R"("{}": {{"value": "{}", "persist": 
{}}})", change.name, change.value, change.persist));
+    }
+    response_ =
+        R"({
+        "operation" : "heartbeat",
+        "requested_operations": [{
+          "operation" : "update",
+          "operationid" : "79",
+          "name": "properties",
+          "args": {)" +
+            utils::StringUtils::join(", ", fields)
+          + R"(}
+        }]
+      })";
+  }
+
+ private:
+  std::optional<std::string> response_;
+};
+
+class VerifyPropertyUpdate : public HTTPIntegrationBase {
+ public:
+  explicit VerifyPropertyUpdate(std::function<void()> fn) : fn_(std::move(fn)) 
{}
+
+  void testSetup() {}
+
+  void runAssertions() {
+    fn_();
+  }
+
+  std::function<void()> fn_;
+};
+
+static std::string properties_file =
+    "nifi.property.one=tree\n"
+    "nifi.c2.agent.protocol.class=RESTSender\n"
+    "nifi.c2.enable=true\n"
+    "nifi.c2.agent.class=test\n"
+    "nifi.c2.agent.heartbeat.period=100\n";
+
+static std::string log_properties_file =
+    "logger.root=INFO,ostream\n";

Review comment:
       done

##########
File path: libminifi/include/properties/Configure.h
##########
@@ -42,12 +44,23 @@ class Configure : public Configuration, public 
core::AgentIdentificationProvider
   std::string getAgentIdentifier() const override;
   void setFallbackAgentIdentifier(const std::string& id);
 
+  using Configuration::set;
+  void set(const std::string& key, const std::string& value, 
PropertyChangeLifetime lifetime) override;
+  bool commitChanges() override;
+
+  // WARNING! a test utility
+  void setLoggerProperties(std::shared_ptr<core::logging::LoggerProperties> 
new_properties) {
+    logger_properties_ = new_properties;
+  }

Review comment:
       done

##########
File path: libminifi/include/properties/Properties.h
##########
@@ -29,16 +29,23 @@
 
 #include "core/logging/Logger.h"
 #include "utils/ChecksumCalculator.h"
+#include "utils/StringUtils.h"
 
 namespace org {
 namespace apache {
 namespace nifi {
 namespace minifi {
 
+enum class PropertyChangeLifetime {
+  TRANSIENT,  // the changed value will not be committed to disk
+  PERSISTENT  // the changed value will be written to the source file
+};
+
 class Properties {
   struct PropertyValue {
-    std::string value;
-    bool changed;
+    std::string persisted_value;
+    std::string active_value;
+    bool changed;  // persisted_value should be written to disk if requested

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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to