szaszm commented on a change in pull request #1132:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1132#discussion_r675435124



##########
File path: libminifi/src/core/yaml/YamlConfiguration.cpp
##########
@@ -805,6 +807,38 @@ void YamlConfiguration::parsePropertiesNodeYaml(const 
YAML::Node& propertiesNode
   validateComponentProperties(processor, component_name, yaml_section);
 }
 
+void YamlConfiguration::parseFunnelsYaml(const YAML::Node& node, 
core::ProcessGroup* parent) {
+  if (!parent) {
+    logger_->log_error("parseFunnelsYaml: no parent group was provided");
+    return;
+  }
+  if (!node || !node.IsSequence()) {
+    return;
+  }
+
+  for (const auto& element : node) {
+  // for (YAML::const_iterator iter = node.begin(); iter != node.end(); 
++iter) {

Review comment:
       Did you mean to leave the old version here?

##########
File path: libminifi/src/core/yaml/YamlConnectionParser.cpp
##########
@@ -29,24 +29,45 @@ namespace yaml {
 // This is no longer needed in c++17
 constexpr const char* YamlConnectionParser::CONFIG_YAML_CONNECTIONS_KEY;
 
+void YamlConnectionParser::addNewRelationshipToConnection(const std::string& 
relationship_name, const std::shared_ptr<minifi::Connection>& connection) const 
{
+  core::Relationship relationship(relationship_name, "");
+  logger_->log_debug("parseConnection: relationship => [%s]", 
relationship_name);
+  connection->addRelationship(std::move(relationship));
+}
+
+void YamlConnectionParser::addFunnelRelationshipToConnection(const 
std::shared_ptr<minifi::Connection>& connection) const {
+  utils::Identifier srcUUID;
+  try {
+    srcUUID = getSourceUUIDFromYaml();
+  } catch(const std::exception&) {
+    return;
+  }
+  auto processor = parent_->findProcessorById(srcUUID);
+  if (!processor) {
+    return;
+  }
+  if (std::dynamic_pointer_cast<minifi::core::Funnel>(processor)) {

Review comment:
       If `Funnel` can be `final`, then this could be done more efficiently 
with `typeid` comparison, because it doesn't have to travel the inheritance 
graph.

##########
File path: libminifi/include/core/Funnel.h
##########
@@ -0,0 +1,55 @@
+/**
+ *
+ * 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 <string>
+#include <memory>
+
+#include "Processor.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+
+class Funnel : public Processor {

Review comment:
       Could this be `final`? Is this class designed for further subclassing?
   `final` gives optimizers the opportunity to devirtualize calls, because when 
the static type is `final`, then the dynamic type is proven to be the same.

##########
File path: libminifi/src/core/yaml/YamlConfiguration.cpp
##########
@@ -805,6 +807,38 @@ void YamlConfiguration::parsePropertiesNodeYaml(const 
YAML::Node& propertiesNode
   validateComponentProperties(processor, component_name, yaml_section);
 }
 
+void YamlConfiguration::parseFunnelsYaml(const YAML::Node& node, 
core::ProcessGroup* parent) {
+  if (!parent) {
+    logger_->log_error("parseFunnelsYaml: no parent group was provided");
+    return;
+  }
+  if (!node || !node.IsSequence()) {
+    return;
+  }
+
+  for (const auto& element : node) {
+  // for (YAML::const_iterator iter = node.begin(); iter != node.end(); 
++iter) {
+    YAML::Node funnel_node = element.as<YAML::Node>();
+
+    std::string id = getOrGenerateId(funnel_node);
+
+    // Default name to be same as ID
+    std::string name = funnel_node["name"].as<std::string>(id);
+
+    const utils::optional<utils::Identifier> uuid = 
utils::Identifier::parse(id);
+    if (!uuid) {
+      logger_->log_debug("Incorrect connection UUID format.");
+      throw Exception(ExceptionType::GENERAL_EXCEPTION, "Incorrect connection 
UUID format.");
+    }

Review comment:
       You might be interested in `utils::orElse` from OptionalUtils.h 
(inspired by TartanLlama/optional and the associated proposal) if you prefer 
longer expressions over more statements. 
   ```suggestion
       const utils::optional<utils::Identifier> uuid = 
utils::Identifier::parse(id) | utils::orElse([this] {
         logger_->log_debug("Incorrect connection UUID format.");
         throw Exception(ExceptionType::GENERAL_EXCEPTION, "Incorrect 
connection UUID format.");
       });
   ```
   

##########
File path: libminifi/src/core/yaml/YamlConnectionParser.cpp
##########
@@ -29,24 +29,45 @@ namespace yaml {
 // This is no longer needed in c++17
 constexpr const char* YamlConnectionParser::CONFIG_YAML_CONNECTIONS_KEY;
 
+void YamlConnectionParser::addNewRelationshipToConnection(const std::string& 
relationship_name, const std::shared_ptr<minifi::Connection>& connection) const 
{
+  core::Relationship relationship(relationship_name, "");
+  logger_->log_debug("parseConnection: relationship => [%s]", 
relationship_name);
+  connection->addRelationship(std::move(relationship));
+}
+
+void YamlConnectionParser::addFunnelRelationshipToConnection(const 
std::shared_ptr<minifi::Connection>& connection) const {
+  utils::Identifier srcUUID;
+  try {
+    srcUUID = getSourceUUIDFromYaml();
+  } catch(const std::exception&) {
+    return;
+  }
+  auto processor = parent_->findProcessorById(srcUUID);
+  if (!processor) {
+    return;

Review comment:
       Maybe it would be worth logging if something goes wrong here or a few 
lines above.




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


Reply via email to