hunyadi-dev commented on a change in pull request #901:
URL: https://github.com/apache/nifi-minifi-cpp/pull/901#discussion_r540823293
##########
File path: libminifi/src/core/yaml/YamlConfiguration.cpp
##########
@@ -762,106 +762,109 @@ void YamlConfiguration::parsePortYaml(YAML::Node
*portNode, core::ProcessGroup *
}
}
-void YamlConfiguration::parsePropertiesNodeYaml(YAML::Node *propertiesNode,
std::shared_ptr<core::ConfigurableComponent> processor, const std::string
&component_name,
- const std::string
&yaml_section) {
- // Treat generically as a YAML node so we can perform inspection on entries
to ensure they are populated
- logger_->log_trace("Entered %s", component_name);
- for (YAML::const_iterator propsIter = propertiesNode->begin(); propsIter !=
propertiesNode->end(); ++propsIter) {
- std::string propertyName = propsIter->first.as<std::string>();
- YAML::Node propertyValueNode = propsIter->second;
- logger_->log_trace("Encountered %s", propertyName);
- if (!propertyValueNode.IsNull() && propertyValueNode.IsDefined()) {
- if (propertyValueNode.IsSequence()) {
- for (auto iter : propertyValueNode) {
- if (iter.IsDefined()) {
- YAML::Node nodeVal = iter.as<YAML::Node>();
- YAML::Node propertiesNode = nodeVal["value"];
- // must insert the sequence in differently.
- std::string rawValueString = propertiesNode.as<std::string>();
- logger_->log_debug("Found %s=%s", propertyName, rawValueString);
- if (!processor->updateProperty(propertyName, rawValueString)) {
- std::shared_ptr<core::Connectable> proc =
std::dynamic_pointer_cast<core::Connectable>(processor);
- if (proc != 0) {
- logger_->log_warn("Received property %s with value %s but is
not one of the properties for %s. "
- "Attempting to add as dynamic property.",
- propertyName, rawValueString,
proc->getName());
- if (!processor->setDynamicProperty(propertyName,
rawValueString)) {
- logger_->log_warn("Unable to set the dynamic property %s
with value %s", propertyName.c_str(), rawValueString.c_str());
- } else {
- logger_->log_warn("Dynamic property %s with value %s set",
propertyName.c_str(), rawValueString.c_str());
- }
- }
- }
- }
- }
- } else {
- core::Property myProp(propertyName, "", "");
- processor->getProperty(propertyName, myProp);
- PropertyValue defaultValue;
- defaultValue = myProp.getDefaultValue();
- auto defaultType = defaultValue.getTypeInfo();
- PropertyValue coercedValue = defaultValue;
-
- // coerce the types. upon failure we will either exit or use the
default value.
- // we do this here ( in addition to the PropertyValue class ) to get
the earliest
- // possible YAML failure.
- try {
- if (defaultType == typeid(std::string)) {
- auto typedValue = propertyValueNode.as<std::string>();
- coercedValue = typedValue;
- } else if (defaultType == typeid(int64_t)) {
- auto typedValue = propertyValueNode.as<int64_t>();
- coercedValue = typedValue;
- } else if (defaultType == typeid(uint64_t)) {
- try {
- auto typedValue = propertyValueNode.as<uint64_t>();
- coercedValue = typedValue;
- } catch (...) {
- auto typedValue = propertyValueNode.as<std::string>();
- coercedValue = typedValue;
- }
- } else if (defaultType == typeid(int)) {
- auto typedValue = propertyValueNode.as<int>();
- coercedValue = typedValue;
- } else if (defaultType == typeid(bool)) {
- auto typedValue = propertyValueNode.as<bool>();
- coercedValue = typedValue;
+void YamlConfiguration::parsePropertyValueSequence(const std::string&
propertyName, const YAML::Node& propertyValueNode,
std::shared_ptr<core::ConfigurableComponent> processor,
+ const std::string &yaml_section) {
+ for (auto iter : propertyValueNode) {
+ if (iter.IsDefined()) {
+ YAML::Node nodeVal = iter.as<YAML::Node>();
+ YAML::Node propertiesNode = nodeVal["value"];
+ // must insert the sequence in differently.
+ std::string rawValueString = propertiesNode.as<std::string>();
+ logger_->log_debug("Found %s=%s", propertyName, rawValueString);
+ if (!processor->updateProperty(propertyName, rawValueString)) {
+ std::shared_ptr<core::Connectable> proc =
std::dynamic_pointer_cast<core::Connectable>(processor);
+ if (proc != 0) {
+ logger_->log_warn("Received property %s with value %s but is not one
of the properties for %s. Attempting to add as dynamic property.",
propertyName, rawValueString, proc->getName());
+ if (!processor->setDynamicProperty(propertyName, rawValueString)) {
+ logger_->log_warn("Unable to set the dynamic property %s with
value %s", propertyName.c_str(), rawValueString.c_str());
} else {
- auto typedValue = propertyValueNode.as<std::string>();
- coercedValue = typedValue;
- }
- } catch (...) {
- std::string eof;
- bool exit_on_failure = false;
- if
(configuration_->get(Configure::nifi_flow_configuration_file_exit_failure,
eof)) {
- utils::StringUtils::StringToBool(eof, exit_on_failure);
- }
- logger_->log_error("Invalid conversion for field %s. Value %s",
myProp.getName(), propertyValueNode.as<std::string>());
- if (exit_on_failure) {
- std::cerr << "Invalid conversion for " << myProp.getName() << " to
" << defaultType.name() << std::endl;
- } else {
- coercedValue = defaultValue;
+ logger_->log_warn("Dynamic property %s with value %s set",
propertyName.c_str(), rawValueString.c_str());
}
}
- std::string rawValueString = propertyValueNode.as<std::string>();
- if (!processor->setProperty(myProp, coercedValue)) {
- std::shared_ptr<core::Connectable> proc =
std::dynamic_pointer_cast<core::Connectable>(processor);
- if (proc != 0) {
- logger_->log_warn("Received property %s with value %s but is not
one of the properties for %s. "
- "Attempting to add as dynamic property.",
- propertyName, rawValueString, proc->getName());
- if (!processor->setDynamicProperty(propertyName, rawValueString)) {
- logger_->log_warn("Unable to set the dynamic property %s with
value %s", propertyName.c_str(), rawValueString.c_str());
- } else {
- logger_->log_warn("Dynamic property %s with value %s set",
propertyName.c_str(), rawValueString.c_str());
- }
- }
- } else {
- logger_->log_debug("Property %s with value %s set",
propertyName.c_str(), rawValueString.c_str());
- }
}
}
}
+}
+
+PropertyValue
YamlConfiguration::getValidatedProcessorPropertyForDefaultTypeInfo(const
core::Property& propertyFromProcessor, const YAML::Node& propertyValueNode) {
+ PropertyValue defaultValue;
+ defaultValue = propertyFromProcessor.getDefaultValue();
+ auto defaultType = defaultValue.getTypeInfo();
+ try {
+ PropertyValue coercedValue = defaultValue;
+ if (defaultType == typeid(int64_t)) {
+ coercedValue = propertyValueNode.as<int64_t>();
Review comment:
Honestly, I do not quite remember why we do not need `uint64_t` anymore
:S
It probably has something to do with the uint64 nodes being parsed as string
even though their value type matches here:
```c++
class DataSizeValue : public TransformableValue, public
state::response::UInt64Value {
```
There has been a discussion about it where @szaszm replied that he agreed on
the removal, but gah this is old. This should be though thoroughly tested as
there are many integration tests that directly rely on yamlparsing and even
some yamlconfiguration tests 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.
For queries about this service, please contact Infrastructure at:
[email protected]