adamdebreceni commented on code in PR #1391: URL: https://github.com/apache/nifi-minifi-cpp/pull/1391#discussion_r989813669
########## libminifi/src/core/flow/StructuredConfiguration.cpp: ########## @@ -0,0 +1,896 @@ +/** + * + * 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 <memory> +#include <vector> +#include <set> +#include <cinttypes> + +#include "core/flow/StructuredConfiguration.h" +#include "core/flow/CheckRequiredField.h" +#include "core/flow/StructuredConnectionParser.h" +#include "core/state/Value.h" +#include "Defaults.h" +#include "utils/TimeUtil.h" +#include "utils/RegexUtils.h" + +namespace org::apache::nifi::minifi::core::flow { + +std::shared_ptr<utils::IdGenerator> StructuredConfiguration::id_generator_ = utils::IdGenerator::getIdGenerator(); + +StructuredConfiguration::StructuredConfiguration(ConfigurationContext ctx, std::shared_ptr<logging::Logger> logger) + : FlowConfiguration(std::move(ctx)), + logger_(std::move(logger)) {} + +std::unique_ptr<core::ProcessGroup> StructuredConfiguration::parseRootProcessGroup(const Node& root_flow_node) { + auto flow_controller_node = root_flow_node[CONFIG_FLOW_CONTROLLER_KEY]; + auto root_group = parseProcessGroup(flow_controller_node, root_flow_node, true); + this->name_ = root_group->getName(); + return root_group; +} + +std::unique_ptr<core::ProcessGroup> StructuredConfiguration::createProcessGroup(const Node& node, bool is_root) { + int version = 0; + + checkRequiredField(node, "name", CONFIG_REMOTE_PROCESS_GROUP_KEY); + auto flowName = node["name"].getString().value(); + + utils::Identifier uuid; + // assignment throws on invalid uuid + uuid = getOrGenerateId(node); + + if (node["version"]) { + version = node["version"].getInt().value(); + } + + logger_->log_debug("parseRootProcessGroup: id => [%s], name => [%s]", uuid.to_string(), flowName); + std::unique_ptr<core::ProcessGroup> group; + if (is_root) { + group = FlowConfiguration::createRootProcessGroup(flowName, uuid, version); + } else { + group = FlowConfiguration::createSimpleProcessGroup(flowName, uuid, version); + } + + if (node["onschedule retry interval"]) { + auto onScheduleRetryPeriod = node["onschedule retry interval"].getString().value(); + logger_->log_debug("parseRootProcessGroup: onschedule retry period => [%s]", onScheduleRetryPeriod); + + auto on_schedule_retry_period_value = utils::timeutils::StringToDuration<std::chrono::milliseconds>(onScheduleRetryPeriod); + if (on_schedule_retry_period_value.has_value() && group) { + logger_->log_debug("parseRootProcessGroup: onschedule retry => [%" PRId64 "] ms", on_schedule_retry_period_value->count()); + group->setOnScheduleRetryPeriod(on_schedule_retry_period_value->count()); + } + } + + return group; +} + +std::unique_ptr<core::ProcessGroup> StructuredConfiguration::parseProcessGroup(const Node& headerNode, const Node& yamlNode, bool is_root) { + auto group = createProcessGroup(headerNode, is_root); + Node processorsNode = yamlNode[CONFIG_PROCESSORS_KEY]; + Node connectionsNode = yamlNode[StructuredConnectionParser::CONFIG_CONNECTIONS_KEY]; + Node funnelsNode = yamlNode[CONFIG_FUNNELS_KEY]; + Node remoteProcessingGroupsNode = [&] { + // assignment is not supported on invalid Yaml nodes + Node candidate = yamlNode[CONFIG_REMOTE_PROCESS_GROUP_KEY]; + if (candidate) { + return candidate; + } + return yamlNode[CONFIG_REMOTE_PROCESS_GROUP_KEY_V3]; + }(); + Node childProcessGroupNodeSeq = yamlNode["Process Groups"]; + + parseProcessorNode(processorsNode, group.get()); + parseRemoteProcessGroup(remoteProcessingGroupsNode, group.get()); + parseFunnels(funnelsNode, group.get()); + // parse connections last to give feedback if the source and/or destination + // is not in the same process group + parseConnection(connectionsNode, group.get()); + + if (childProcessGroupNodeSeq && childProcessGroupNodeSeq.isSequence()) { + for (const auto childProcessGroupNode : childProcessGroupNodeSeq) { Review Comment: they are used inconsistently, but since we usually return a wrapper `flow::Node` by value, it makes little difference, changed the loop variables to `const auto&` in this file, for simple variables I would vote for `const auto`, but I could change those as well -- 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]
