Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-25 Thread via GitHub


szaszm closed pull request #1751: MINIFICPP-2314 - Send asset state hash in 
heartbeat, implement c2 asset sync
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751


-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-24 Thread via GitHub


szaszm commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1689974764


##
libminifi/include/core/state/nodes/ResponseNodeLoader.h:
##
@@ -73,6 +75,7 @@ class ResponseNodeLoader {
   std::shared_ptr configuration_;
   std::vector> 
repository_metric_sources_;
   std::shared_ptr flow_configuration_;
+  utils::file::AssetManager* asset_manager_;

Review Comment:
   ```suggestion
 utils::file::AssetManager* asset_manager_{};
   ```



-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-24 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1689382339


##
minifi_main/MiNiFiMain.cpp:
##
@@ -397,11 +398,13 @@ int main(int argc, char **argv) {
   .sensitive_properties_encryptor = 
utils::crypto::EncryptionProvider::createSensitivePropertiesEncryptor(minifiHome)
   }, nifi_configuration_class_name);
 
-std::vector> 
repo_metric_sources{prov_repo, flow_repo, content_repo};
-auto metrics_publisher_store = 
std::make_unique(configure, 
repo_metric_sources, flow_configuration);
+auto asset_manager = 
std::make_shared(*configure);

Review Comment:
   replaced with unique_ptr and passing raw pointers as I want to preserve 
nullability downstream



##
libminifi/src/utils/file/AssetManager.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.
+ */
+
+#include "utils/file/AssetManager.h"
+#include "utils/file/FileUtils.h"
+#include "rapidjson/document.h"
+#include "rapidjson/writer.h"
+#include "core/logging/LoggerFactory.h"
+#include "utils/Hash.h"
+
+#undef GetObject  // windows.h #defines GetObject = GetObjectA or GetObjectW, 
which conflicts with rapidjson
+
+namespace org::apache::nifi::minifi::utils::file {
+
+AssetManager::AssetManager(const Configure& configuration)
+: 
root_(configuration.get(Configure::nifi_asset_directory).value_or((configuration.getHome()
 / "asset").string())),
+  logger_(core::logging::LoggerFactory::getLogger()) {
+  refreshState();
+}
+
+void AssetManager::refreshState() {
+  std::lock_guard lock(mtx_);
+  state_.clear();
+  if (!utils::file::FileUtils::exists(root_)) {
+std::filesystem::create_directories(root_);
+  }
+  if (!utils::file::FileUtils::exists(root_ / ".state")) {
+std::ofstream{root_ / ".state", std::ios::binary} << R"({"digest": "", 
"assets": {}})";
+  }
+  rapidjson::Document doc;
+
+  std::string file_content = utils::file::get_content(root_ / ".state");
+
+  rapidjson::ParseResult res = doc.Parse(file_content.c_str(), 
file_content.size());
+  if (!res) {
+logger_->log_error("Failed to parse asset '.state' file, not a valid json 
file");
+return;
+  }
+  if (!doc.IsObject()) {
+logger_->log_error("Asset '.state' file is malformed");
+return;
+  }
+  if (!doc.HasMember("digest")) {
+logger_->log_error("Asset '.state' file is malformed, missing 'digest'");
+return;
+  }
+  if (!doc["digest"].IsString()) {
+logger_->log_error("Asset '.state' file is malformed, 'digest' is not a 
string");
+return;
+  }
+  if (!doc.HasMember("assets")) {
+logger_->log_error("Asset '.state' file is malformed, missing 'assets'");
+return;
+  }
+  if (!doc["assets"].IsObject()) {
+logger_->log_error("Asset '.state' file is malformed, 'assets' is not an 
object");
+return;
+  }
+
+
+  AssetLayout new_state;
+  new_state.digest = std::string{doc["digest"].GetString(), 
doc["digest"].GetStringLength()};
+
+  for (auto& [id, entry] : doc["assets"].GetObject()) {
+if (!entry.IsObject()) {
+  logger_->log_error("Asset '.state' file is malformed, 'assets.{}' is not 
an object", std::string_view{id.GetString(), id.GetStringLength()});
+  return;
+}
+AssetDescription description;
+description.id = std::string{id.GetString(), id.GetStringLength()};
+if (!entry.HasMember("path") || !entry["path"].IsString()) {
+  logger_->log_error("Asset '.state' file is malformed, 'assets.{}.path' 
does not exist or is not a string", std::string_view{id.GetString(), 
id.GetStringLength()});
+  return;
+}
+description.path = std::string{entry["path"].GetString(), 
entry["path"].GetStringLength()};
+if (!entry.HasMember("url") || !entry["url"].IsString()) {
+  logger_->log_error("Asset '.state' file is malformed, 'assets.{}.url' 
does not exist or is not a string", std::string_view{id.GetString(), 
id.GetStringLength()});
+  return;
+}
+description.url = std::string{entry["url"].GetString(), 
entry["url"].GetStringLength()};
+
+if (utils::file::FileUtils::exists(root_ / description.id)) {
+  new_state.assets.insert(std::move(description));
+} else {
+  logger_->log_error(

Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-23 Thread via GitHub


szaszm commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1682907319


##
libminifi/src/utils/file/AssetManager.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.
+ */
+
+#include "utils/file/AssetManager.h"
+#include "utils/file/FileUtils.h"
+#include "rapidjson/document.h"
+#include "rapidjson/writer.h"
+#include "core/logging/LoggerFactory.h"
+#include "utils/Hash.h"
+
+#undef GetObject  // windows.h #defines GetObject = GetObjectA or GetObjectW, 
which conflicts with rapidjson
+
+namespace org::apache::nifi::minifi::utils::file {
+
+AssetManager::AssetManager(const Configure& configuration)
+: 
root_(configuration.get(Configure::nifi_asset_directory).value_or((configuration.getHome()
 / "asset").string())),
+  logger_(core::logging::LoggerFactory::getLogger()) {
+  refreshState();
+}
+
+void AssetManager::refreshState() {
+  std::lock_guard lock(mtx_);
+  state_.clear();
+  if (!utils::file::FileUtils::exists(root_)) {
+std::filesystem::create_directories(root_);
+  }
+  if (!utils::file::FileUtils::exists(root_ / ".state")) {
+std::ofstream{root_ / ".state", std::ios::binary} << R"({"digest": "", 
"assets": {}})";
+  }
+  rapidjson::Document doc;
+
+  std::string file_content = utils::file::get_content(root_ / ".state");
+
+  rapidjson::ParseResult res = doc.Parse(file_content.c_str(), 
file_content.size());
+  if (!res) {
+logger_->log_error("Failed to parse asset '.state' file, not a valid json 
file");
+return;
+  }
+  if (!doc.IsObject()) {
+logger_->log_error("Asset '.state' file is malformed");
+return;
+  }
+  if (!doc.HasMember("digest")) {
+logger_->log_error("Asset '.state' file is malformed, missing 'digest'");
+return;
+  }
+  if (!doc["digest"].IsString()) {
+logger_->log_error("Asset '.state' file is malformed, 'digest' is not a 
string");
+return;
+  }
+  if (!doc.HasMember("assets")) {
+logger_->log_error("Asset '.state' file is malformed, missing 'assets'");
+return;
+  }
+  if (!doc["assets"].IsObject()) {
+logger_->log_error("Asset '.state' file is malformed, 'assets' is not an 
object");
+return;
+  }
+
+
+  AssetLayout new_state;
+  new_state.digest = std::string{doc["digest"].GetString(), 
doc["digest"].GetStringLength()};
+
+  for (auto& [id, entry] : doc["assets"].GetObject()) {
+if (!entry.IsObject()) {
+  logger_->log_error("Asset '.state' file is malformed, 'assets.{}' is not 
an object", std::string_view{id.GetString(), id.GetStringLength()});
+  return;
+}
+AssetDescription description;
+description.id = std::string{id.GetString(), id.GetStringLength()};
+if (!entry.HasMember("path") || !entry["path"].IsString()) {
+  logger_->log_error("Asset '.state' file is malformed, 'assets.{}.path' 
does not exist or is not a string", std::string_view{id.GetString(), 
id.GetStringLength()});
+  return;
+}
+description.path = std::string{entry["path"].GetString(), 
entry["path"].GetStringLength()};
+if (!entry.HasMember("url") || !entry["url"].IsString()) {
+  logger_->log_error("Asset '.state' file is malformed, 'assets.{}.url' 
does not exist or is not a string", std::string_view{id.GetString(), 
id.GetStringLength()});
+  return;
+}
+description.url = std::string{entry["url"].GetString(), 
entry["url"].GetStringLength()};
+
+if (utils::file::FileUtils::exists(root_ / description.id)) {
+  new_state.assets.insert(std::move(description));
+} else {
+  logger_->log_error("Asset '.state' file contains entry '{}' that does 
not exist on the filesystem at '{}'",
+ std::string_view{id.GetString(), 
id.GetStringLength()}, (root_ / description.id).string());
+}
+  }
+  state_ = std::move(new_state);
+}
+
+std::string AssetManager::hash() const {
+  std::lock_guard lock(mtx_);
+  return state_.digest.empty() ? "null" : state_.digest;
+}
+
+nonstd::expected AssetManager::sync(
+const org::apache::nifi::minifi::utils::file::AssetLayout& layout,
+const std::function, 
std::string>(std::string_view /*url*/)>& fetch) {
+  std::lock_guard lock(mtx_);
+  org::apache::nifi::minifi::u

Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-19 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1683918112


##
libminifi/include/c2/C2Payload.h:
##
@@ -79,21 +85,65 @@ enum Direction {
   RECEIVE
 };
 
-struct AnnotatedValue : state::response::ValueNode {
-  using state::response::ValueNode::ValueNode;
-  using state::response::ValueNode::operator=;
+class C2Value {
+ public:
+  friend std::ostream& operator<<(std::ostream& out, const C2Value& val);
+
+  C2Value() = default;
+  C2Value(const C2Value& other) {
+(*this) = other;
+  }
+  C2Value(C2Value&&) = default;
+  template
+  requires(std::constructible_from)
+  C2Value(T&& value) { value_ = 
state::response::ValueNode{std::forward(value)}; }  // 
NOLINT(runtime/explicit)
+  C2Value(const rapidjson::Value& json_value) {  // NOLINT(runtime/explicit)
+value_.emplace();
+get(value_).CopyFrom(json_value, 
get(value_).GetAllocator());
+  }
+  C2Value(rapidjson::Document&& json_doc) {  // NOLINT(runtime/explicit)

Review Comment:
   done



##
libminifi/include/c2/protocols/RESTProtocol.h:
##
@@ -43,7 +43,7 @@ class RESTProtocol : public HeartbeatJsonSerializer {
  protected:
   void initialize(core::controller::ControllerServiceProvider* controller, 
const std::shared_ptr &configure);
   void serializeNestedPayload(rapidjson::Value& target, const C2Payload& 
payload, rapidjson::Document::AllocatorType& alloc) override;
-  static C2Payload parseJsonResponse(const C2Payload &payload, std::span response);
+  C2Payload parseJsonResponse(const C2Payload &payload, std::span response);

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: issues-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-19 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1683913176


##
C2.md:
##
@@ -80,8 +81,10 @@ be requested via C2 DESCRIBE manifest command.
 nifi.c2.rest.listener.cacert=
 
 # specify the rest URIs if using RESTSender
-
nifi.c2.rest.url=http:c2-protocol/heartbeat
-
nifi.c2.rest.url.ack=http:c2-protocol/acknowledge
+nifi.c2.rest.path.base=https:///
+# specify either absolute url or relative to the nifi.c2.rest.path.base 
url for hearbeat and acknowledge
+nifi.c2.rest.url=/c2-protocol/heartbeat
+nifi.c2.rest.url.ack=/c2-protocol/acknowledge

Review Comment:
   this is how it's done in minifi java



-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-18 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1683903871


##
libminifi/include/core/state/nodes/AssetInformation.h:
##
@@ -0,0 +1,42 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include "core/state/nodes/MetricsBase.h"
+#include "utils/file/AssetManager.h"
+#include "core/logging/Logger.h"
+
+namespace org::apache::nifi::minifi::state::response {
+
+class AssetInformation : public ResponseNode {
+ public:
+  AssetInformation();
+  explicit AssetInformation(std::string_view name, const utils::Identifier& 
uuid = {}) : ResponseNode(name, uuid) {}
+
+  MINIFIAPI static constexpr const char* Description = "Metric node that 
defines hash for all asset identifiers";
+
+  void setAssetManager(std::shared_ptr 
asset_manager);

Review Comment:
   it is instantiated through the classloader, and initialized like other 
ResponseNodes in ResponseNodeLoader.cpp



-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-18 Thread via GitHub


szaszm commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1682880317


##
C2.md:
##
@@ -80,8 +81,10 @@ be requested via C2 DESCRIBE manifest command.
 nifi.c2.rest.listener.cacert=
 
 # specify the rest URIs if using RESTSender
-
nifi.c2.rest.url=http:c2-protocol/heartbeat
-
nifi.c2.rest.url.ack=http:c2-protocol/acknowledge
+nifi.c2.rest.path.base=https:///
+# specify either absolute url or relative to the nifi.c2.rest.path.base 
url for hearbeat and acknowledge
+nifi.c2.rest.url=/c2-protocol/heartbeat
+nifi.c2.rest.url.ack=/c2-protocol/acknowledge

Review Comment:
   I think these shouldn't include a leading slash, because they are relative 
paths. That is unless MiNiFi Java works the same strange way. Wdyt?



##
libminifi/include/c2/C2Payload.h:
##
@@ -79,21 +85,65 @@ enum Direction {
   RECEIVE
 };
 
-struct AnnotatedValue : state::response::ValueNode {
-  using state::response::ValueNode::ValueNode;
-  using state::response::ValueNode::operator=;
+class C2Value {
+ public:
+  friend std::ostream& operator<<(std::ostream& out, const C2Value& val);
+
+  C2Value() = default;
+  C2Value(const C2Value& other) {
+(*this) = other;
+  }
+  C2Value(C2Value&&) = default;
+  template
+  requires(std::constructible_from)
+  C2Value(T&& value) { value_ = 
state::response::ValueNode{std::forward(value)}; }  // 
NOLINT(runtime/explicit)
+  C2Value(const rapidjson::Value& json_value) {  // NOLINT(runtime/explicit)
+value_.emplace();
+get(value_).CopyFrom(json_value, 
get(value_).GetAllocator());
+  }
+  C2Value(rapidjson::Document&& json_doc) {  // NOLINT(runtime/explicit)

Review Comment:
   Why not explicit? A rationale after the NOLINT expression would be helpful 
for readers IMO.



##
libminifi/include/core/state/nodes/AssetInformation.h:
##
@@ -0,0 +1,42 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include "core/state/nodes/MetricsBase.h"
+#include "utils/file/AssetManager.h"
+#include "core/logging/Logger.h"
+
+namespace org::apache::nifi::minifi::state::response {
+
+class AssetInformation : public ResponseNode {
+ public:
+  AssetInformation();
+  explicit AssetInformation(std::string_view name, const utils::Identifier& 
uuid = {}) : ResponseNode(name, uuid) {}
+
+  MINIFIAPI static constexpr const char* Description = "Metric node that 
defines hash for all asset identifiers";
+
+  void setAssetManager(std::shared_ptr 
asset_manager);

Review Comment:
   Could we inject `AssetManager` in the constructor? The fewer possible 
states, the less things that can go wrong.



##
libminifi/include/c2/protocols/RESTProtocol.h:
##
@@ -43,7 +43,7 @@ class RESTProtocol : public HeartbeatJsonSerializer {
  protected:
   void initialize(core::controller::ControllerServiceProvider* controller, 
const std::shared_ptr &configure);
   void serializeNestedPayload(rapidjson::Value& target, const C2Payload& 
payload, rapidjson::Document::AllocatorType& alloc) override;
-  static C2Payload parseJsonResponse(const C2Payload &payload, std::span response);
+  C2Payload parseJsonResponse(const C2Payload &payload, std::span response);

Review Comment:
   Even if it's no longer `static`, it could still be `const`, as it doesn't 
seem to modify any members.



-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-07-09 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1669940985


##
libminifi/test/integration/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,278 @@
+/**
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include "integration/HTTPIntegrationBase.h"
+#include "integration/HTTPHandlers.h"
+#include "utils/file/FileUtils.h"
+#include "utils/file/AssetManager.h"
+#include "unit/TestUtils.h"
+#include "unit/Catch.h"
+
+namespace org::apache::nifi::minifi::test {
+
+class FileProvider : public ServerAwareHandler {
+ public:
+  explicit FileProvider(std::string file_content): 
file_content_(std::move(file_content)) {}
+
+  bool handleGet(CivetServer* /*server*/, struct mg_connection* conn) override 
{
+mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+"text/plain\r\nContent-Length: %lu\r\nConnection: 
close\r\n\r\n",
+  file_content_.length());
+mg_printf(conn, "%s", file_content_.c_str());
+return true;
+  }
+
+ private:
+  std::string file_content_;
+};
+
+class C2HeartbeatHandler : public HeartbeatHandler {
+ public:
+  using HeartbeatHandler::HeartbeatHandler;
+  using AssetDescription = 
org::apache::nifi::minifi::utils::file::AssetDescription;
+
+  void handleHeartbeat(const rapidjson::Document& root, struct mg_connection* 
conn) override {
+std::string hb_str = [&] {
+  rapidjson::StringBuffer buffer;
+  rapidjson::Writer writer(buffer);
+  root.Accept(writer);
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}();
+auto& asset_info_node = root["resourceInfo"];
+auto& asset_hash_node = asset_info_node["hash"];
+std::string asset_hash{asset_hash_node.GetString(), 
asset_hash_node.GetStringLength()};
+
+std::vector operations;
+{
+  std::lock_guard guard(asset_mtx_);
+  agent_asset_hash_ = asset_hash;
+  if (asset_hash != calculateAssetHash()) {
+std::unordered_map args;
+rapidjson::Document global_hash_doc{rapidjson::kObjectType};
+global_hash_doc.AddMember("digest", calculateAssetHash(), 
global_hash_doc.GetAllocator());
+args["globalHash"] = std::move(global_hash_doc);
+rapidjson::Document resource_list_doc{rapidjson::kArrayType};
+
+for (auto& asset : expected_assets_) {
+  rapidjson::Value resource_obj{rapidjson::kObjectType};
+  resource_obj.AddMember("resourceId", asset.id, 
resource_list_doc.GetAllocator());
+  resource_obj.AddMember("resourceName", 
asset.path.filename().string(), resource_list_doc.GetAllocator());
+  resource_obj.AddMember("resourceType", "ASSET", 
resource_list_doc.GetAllocator());
+  resource_obj.AddMember("resourcePath", 
asset.path.parent_path().string(), resource_list_doc.GetAllocator());
+  resource_obj.AddMember("url", asset.url, 
resource_list_doc.GetAllocator());
+  resource_list_doc.PushBack(resource_obj, 
resource_list_doc.GetAllocator());
+}
+args["resourceList"] = std::move(resource_list_doc);
+
+operations.push_back(C2Operation{
+  .operation = "sync",
+  .operand = "resource",
+  .operation_id = std::to_string(next_op_id_++),
+  .args = std::move(args)
+});
+  }
+}
+sendHeartbeatResponse(operations, conn);
+  }
+
+  void addAsset(std::string id, std::string path, std::string url) {
+std::lock_guard guard(asset_mtx_);
+expected_assets_.insert(AssetDescription{
+  .id = std::move(id),
+  .path = std::move(path),
+  .url = std::move(url)
+});
+  }
+
+  void removeAsset(std::string id) {
+std::lock_guard guard{asset_mtx_};
+expected_assets_.erase(AssetDescription{.id = std::move(id), .path = {}, 
.url = {}});
+  }
+
+  std::optional getAgentAssetHash() const {
+std::lock_guard lock(asset_mtx_);
+return agent_asset_hash_;
+  }
+
+  std::string calculateAssetHash() const {
+std::lock_guard guard{asset_mtx_};
+size_t hash_value{0};
+for (auto& asset : expected_assets_) {
+  hash_value = minifi::utils::hash_combine(hash_value, 
std::hash{}(asset.id));
+}
+   

Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-04-25 Thread via GitHub


martinzink commented on PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#issuecomment-2077219378

   @adamdebreceni could you check out the the C2AssetSyncTest failure on 
windows?


-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-04-15 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1565319484


##
minifi_main/MiNiFiMain.cpp:
##
@@ -400,9 +401,10 @@ int main(int argc, char **argv) {
   .sensitive_properties_encryptor = 
utils::crypto::EncryptionProvider::createSensitivePropertiesEncryptor(minifiHome)
   }, nifi_configuration_class_name);
 
-std::vector> 
repo_metric_sources{prov_repo, flow_repo, content_repo};
-auto metrics_publisher_store = 
std::make_unique(configure, 
repo_metric_sources, flow_configuration);
+auto asset_manager = 
std::make_shared(*configure);
 
+std::vector> 
repo_metric_sources{prov_repo, flow_repo, content_repo};
+auto metrics_publisher_store = 
std::make_unique(configure, 
repo_metric_sources, flow_configuration, asset_manager);
 const auto controller = std::make_unique(
 prov_repo, flow_repo, configure, std::move(flow_configuration), 
content_repo, std::move(metrics_publisher_store), filesystem, request_restart);

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: issues-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-04-15 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1565319124


##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,256 @@
+/**
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "utils/file/FileUtils.h"
+#include "utils/file/AssetManager.h"
+
+class FileProvider : public ServerAwareHandler {
+ public:
+  explicit FileProvider(std::string file_content): 
file_content_(std::move(file_content)) {}
+
+  bool handleGet(CivetServer* /*server*/, struct mg_connection* conn) override 
{
+mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+"text/plain\r\nContent-Length: %lu\r\nConnection: 
close\r\n\r\n",
+  file_content_.length());
+mg_printf(conn, "%s", file_content_.c_str());
+return true;
+  }
+
+ private:
+  std::string file_content_;
+};
+
+class C2HeartbeatHandler : public HeartbeatHandler {
+ public:
+  using HeartbeatHandler::HeartbeatHandler;
+  using AssetDescription = 
org::apache::nifi::minifi::utils::file::AssetDescription;
+
+  void handleHeartbeat(const rapidjson::Document& root, struct mg_connection* 
conn) override {
+std::string hb_str;
+{
+  rapidjson::StringBuffer buffer;
+  rapidjson::Writer writer(buffer);
+  root.Accept(writer);
+
+  hb_str = std::string{buffer.GetString(), buffer.GetSize()};
+}
+auto& asset_info_node = root["assetInfo"];
+auto& asset_hash_node = asset_info_node["hash"];
+std::string asset_hash{asset_hash_node.GetString(), 
asset_hash_node.GetStringLength()};
+
+std::vector operations;
+{
+  std::lock_guard guard(asset_mtx_);
+  agent_asset_hash_ = asset_hash;
+  if (asset_hash != assetHash()) {
+std::unordered_map args;
+for (auto& asset : expected_assets_) {
+  args[asset.id + ".path"] = asset.path;
+  args[asset.id + ".url"] = asset.url;
+}
+operations.push_back(C2Operation{
+  .operation = "sync",
+  .operand = "asset",
+  .operation_id = std::to_string(next_op_id_++),
+  .args = std::move(args)
+});
+  }
+}
+sendHeartbeatResponse(operations, conn);
+  }
+
+  void addAsset(std::string id, std::string path, std::string url) {
+std::lock_guard guard(asset_mtx_);
+expected_assets_.insert(AssetDescription{
+  .id = id,
+  .path = path,
+  .url = url
+});
+  }
+
+  void removeAsset(std::string id) {
+std::lock_guard guard{asset_mtx_};
+expected_assets_.erase(AssetDescription{.id = id, .path = {}, .url = {}});
+  }
+
+  std::optional getAgentAssetHash() const {
+std::lock_guard lock(asset_mtx_);
+return agent_asset_hash_;
+  }
+
+  std::string assetHash() const {

Review Comment:
   done



##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##


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: issues-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-04-15 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1565318749


##
conf/minifi.properties:
##
@@ -90,7 +90,7 @@ nifi.content.repository.class.name=DatabaseContentRepository
 #nifi.c2.rest.url=
 #nifi.c2.rest.url.ack=
 #nifi.c2.rest.ssl.context.service=
-nifi.c2.root.classes=DeviceInfoNode,AgentInformation,FlowInformation
+nifi.c2.root.classes=DeviceInfoNode,AgentInformation,FlowInformation,AssetInformation

Review Comment:
   added, also added it to resource files and docker image



##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,256 @@
+/**
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "utils/file/FileUtils.h"
+#include "utils/file/AssetManager.h"
+
+class FileProvider : public ServerAwareHandler {
+ public:
+  explicit FileProvider(std::string file_content): 
file_content_(std::move(file_content)) {}
+
+  bool handleGet(CivetServer* /*server*/, struct mg_connection* conn) override 
{
+mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+"text/plain\r\nContent-Length: %lu\r\nConnection: 
close\r\n\r\n",
+  file_content_.length());
+mg_printf(conn, "%s", file_content_.c_str());
+return true;
+  }
+
+ private:
+  std::string file_content_;
+};
+
+class C2HeartbeatHandler : public HeartbeatHandler {
+ public:
+  using HeartbeatHandler::HeartbeatHandler;
+  using AssetDescription = 
org::apache::nifi::minifi::utils::file::AssetDescription;
+
+  void handleHeartbeat(const rapidjson::Document& root, struct mg_connection* 
conn) override {
+std::string hb_str;
+{
+  rapidjson::StringBuffer buffer;
+  rapidjson::Writer writer(buffer);
+  root.Accept(writer);
+
+  hb_str = std::string{buffer.GetString(), buffer.GetSize()};
+}
+auto& asset_info_node = root["assetInfo"];
+auto& asset_hash_node = asset_info_node["hash"];
+std::string asset_hash{asset_hash_node.GetString(), 
asset_hash_node.GetStringLength()};
+
+std::vector operations;
+{
+  std::lock_guard guard(asset_mtx_);
+  agent_asset_hash_ = asset_hash;
+  if (asset_hash != assetHash()) {
+std::unordered_map args;
+for (auto& asset : expected_assets_) {
+  args[asset.id + ".path"] = asset.path;
+  args[asset.id + ".url"] = asset.url;
+}
+operations.push_back(C2Operation{
+  .operation = "sync",
+  .operand = "asset",
+  .operation_id = std::to_string(next_op_id_++),
+  .args = std::move(args)
+});
+  }
+}
+sendHeartbeatResponse(operations, conn);
+  }
+
+  void addAsset(std::string id, std::string path, std::string url) {
+std::lock_guard guard(asset_mtx_);
+expected_assets_.insert(AssetDescription{
+  .id = id,
+  .path = path,
+  .url = url

Review Comment:
   done



##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,256 @@
+/**
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "utils/file/FileUtils.h"
+#include "utils/file/AssetManager.h"
+

Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-04-11 Thread via GitHub


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


##
conf/minifi.properties:
##
@@ -90,7 +90,7 @@ nifi.content.repository.class.name=DatabaseContentRepository
 #nifi.c2.rest.url=
 #nifi.c2.rest.url.ack=
 #nifi.c2.rest.ssl.context.service=
-nifi.c2.root.classes=DeviceInfoNode,AgentInformation,FlowInformation
+nifi.c2.root.classes=DeviceInfoNode,AgentInformation,FlowInformation,AssetInformation

Review Comment:
   I think this should be added to the C2.md documentation as well under Base 
Options.



##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##


Review Comment:
   This test seems to be missing from the CMakeLists.txt, so it does not run 
with ctest. It needs to be added with add_test 



##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,256 @@
+/**
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "utils/file/FileUtils.h"
+#include "utils/file/AssetManager.h"
+
+class FileProvider : public ServerAwareHandler {
+ public:
+  explicit FileProvider(std::string file_content): 
file_content_(std::move(file_content)) {}
+
+  bool handleGet(CivetServer* /*server*/, struct mg_connection* conn) override 
{
+mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
+"text/plain\r\nContent-Length: %lu\r\nConnection: 
close\r\n\r\n",
+  file_content_.length());
+mg_printf(conn, "%s", file_content_.c_str());
+return true;
+  }
+
+ private:
+  std::string file_content_;
+};
+
+class C2HeartbeatHandler : public HeartbeatHandler {
+ public:
+  using HeartbeatHandler::HeartbeatHandler;
+  using AssetDescription = 
org::apache::nifi::minifi::utils::file::AssetDescription;
+
+  void handleHeartbeat(const rapidjson::Document& root, struct mg_connection* 
conn) override {
+std::string hb_str;
+{
+  rapidjson::StringBuffer buffer;
+  rapidjson::Writer writer(buffer);
+  root.Accept(writer);
+
+  hb_str = std::string{buffer.GetString(), buffer.GetSize()};
+}
+auto& asset_info_node = root["assetInfo"];
+auto& asset_hash_node = asset_info_node["hash"];
+std::string asset_hash{asset_hash_node.GetString(), 
asset_hash_node.GetStringLength()};
+
+std::vector operations;
+{
+  std::lock_guard guard(asset_mtx_);
+  agent_asset_hash_ = asset_hash;
+  if (asset_hash != assetHash()) {
+std::unordered_map args;
+for (auto& asset : expected_assets_) {
+  args[asset.id + ".path"] = asset.path;
+  args[asset.id + ".url"] = asset.url;
+}
+operations.push_back(C2Operation{
+  .operation = "sync",
+  .operand = "asset",
+  .operation_id = std::to_string(next_op_id_++),
+  .args = std::move(args)
+});
+  }
+}
+sendHeartbeatResponse(operations, conn);
+  }
+
+  void addAsset(std::string id, std::string path, std::string url) {
+std::lock_guard guard(asset_mtx_);
+expected_assets_.insert(AssetDescription{
+  .id = id,
+  .path = path,
+  .url = url
+});
+  }
+
+  void removeAsset(std::string id) {
+std::lock_guard guard{asset_mtx_};
+expected_assets_.erase(AssetDescription{.id = id, .path = {}, .url = {}});
+  }
+
+  std::optional getAgentAssetHash() const {
+std::lock_guard lock(asset_mtx_);
+return agent_asset_hash_;
+  }
+
+  std::string assetHash() const {

Review Comment:
   I think this could be renamed to something like `calculateAssetHash` because 
having a `getAgentAssetHash` and an `assetHash` is a bit confusing IMO



##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,256 @@
+/**
+ *
+ * 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 

Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-04-10 Thread via GitHub


adamdebreceni commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1559110636


##
conf/minifi.properties:
##
@@ -90,7 +90,7 @@ nifi.content.repository.class.name=DatabaseContentRepository
 #nifi.c2.rest.url=
 #nifi.c2.rest.url.ack=
 #nifi.c2.rest.ssl.context.service=
-nifi.c2.root.classes=DeviceInfoNode,AgentInformation,FlowInformation
+nifi.c2.root.classes=DeviceInfoNode,AgentInformation,FlowInformation,AssetInformation

Review Comment:
   expanded on the Asset directory entry in CONFIGURE.md



##
libminifi/src/utils/file/AssetManager.cpp:
##
@@ -0,0 +1,153 @@
+/**
+ * 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 "utils/file/AssetManager.h"
+#include "utils/file/FileUtils.h"
+#include "rapidjson/document.h"
+#include "rapidjson/writer.h"
+#include "core/logging/LoggerFactory.h"
+#include "utils/Hash.h"
+
+#undef GetObject
+
+namespace org::apache::nifi::minifi::utils::file {
+
+AssetManager::AssetManager(std::shared_ptr configuration)

Review Comment:
   done



##
libminifi/include/core/state/nodes/AssetInformation.h:
##
@@ -0,0 +1,42 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include "core/state/nodes/MetricsBase.h"
+#include "utils/file/AssetManager.h"
+#include "core/logging/Logger.h"
+
+namespace org::apache::nifi::minifi::state::response {
+
+class AssetInformation : public ResponseNode {
+ public:
+  AssetInformation();
+  explicit AssetInformation(std::string name, const utils::Identifier& uuid = 
{}) : ResponseNode(std::move(name), uuid) {}

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: issues-unsubscr...@nifi.apache.org

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



Re: [PR] MINIFICPP-2314 - Send asset state hash in heartbeat, implement c2 asset sync [nifi-minifi-cpp]

2024-04-05 Thread via GitHub


martinzink commented on code in PR #1751:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1751#discussion_r1553149815


##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,257 @@
+/**
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
+#include "utils/IntegrationTestUtils.h"
+#include "utils/Environment.h"
+#include "utils/file/FileUtils.h"
+#include "utils/file/AssetManager.h"
+
+class FileProvider : public ServerAwareHandler {

Review Comment:
   Just noting for visibility that this will cause some conflict with #1749



##
libminifi/src/core/state/nodes/AssetInformation.cpp:
##
@@ -0,0 +1,47 @@
+/**
+ * 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 "core/state/nodes/AssetInformation.h"
+#include "core/Resource.h"
+#include "core/logging/LoggerFactory.h"
+
+namespace org::apache::nifi::minifi::state::response {
+
+AssetInformation::AssetInformation()
+  : logger_(core::logging::LoggerFactory().getLogger()) {}
+
+void 
AssetInformation::setAssetManager(std::shared_ptr 
asset_manager) {
+  asset_manager_ = asset_manager;
+  if (!asset_manager_) {
+logger_->log_error("No asset manager is provided, asset information will 
not be available");
+  }
+}
+
+std::vector AssetInformation::serialize() {
+  if (!asset_manager_) {
+return {};
+  }
+  SerializedResponseNode node;
+  node.name = "hash";
+  node.value = asset_manager_->hash();
+
+  return std::vector{node};
+}
+
+REGISTER_RESOURCE(AssetInformation, DescriptionOnly);
+
+}  // namespace org::apache::nifi::minifi::state::response

Review Comment:
   ```suggestion
   }  // namespace org::apache::nifi::minifi::state::response
   
   ```



##
libminifi/src/core/state/nodes/AssetInformation.cpp:
##
@@ -0,0 +1,47 @@
+/**
+ * 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 "core/state/nodes/AssetInformation.h"
+#include "core/Resource.h"
+#include "core/logging/LoggerFactory.h"
+
+namespace org::apache::nifi::minifi::state::response {
+
+AssetInformation::AssetInformation()
+  : logger_(core::logging::LoggerFactory().getLogger()) {}
+
+void 
AssetInformation::setAssetManager(std::shared_ptr 
asset_manager) {
+  asset_manager_ = asset_manager;

Review Comment:
   ```suggestion
 asset_manager_ = std::move(asset_manager);
   ```



##
extensions/http-curl/tests/C2AssetSyncTest.cpp:
##
@@ -0,0 +1,257 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additio