This is an automated email from the ASF dual-hosted git repository. martinzink pushed a commit to branch minifi-api-property in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit e8af0c0f984d301c4958afed19e91563722d95e1 Author: Martin Zink <[email protected]> AuthorDate: Tue Mar 18 11:40:10 2025 +0100 replaced ConfigurableComponent::getPropertyReference with getSupportedProperty (copies) --- extensions/expression-language/ProcessContextExpr.cpp | 6 +++--- extensions/python/ExecutePythonProcessor.cpp | 8 ++++---- extensions/python/ExecutePythonProcessor.h | 4 ++-- libminifi/include/core/json/JsonFlowSerializer.h | 2 +- libminifi/include/core/yaml/YamlFlowSerializer.h | 2 +- libminifi/src/core/flow/StructuredConfiguration.cpp | 11 ++++++----- libminifi/src/core/json/JsonFlowSerializer.cpp | 2 +- libminifi/src/core/yaml/YamlFlowSerializer.cpp | 4 +++- .../include/minifi-cpp/core/ConfigurableComponent.h | 5 ++--- utils/include/core/ConfigurableComponentImpl.h | 5 ++--- utils/src/core/ConfigurableComponentImpl.cpp | 17 ++++++++--------- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/extensions/expression-language/ProcessContextExpr.cpp b/extensions/expression-language/ProcessContextExpr.cpp index 8a4665a05..928a2bf1e 100644 --- a/extensions/expression-language/ProcessContextExpr.cpp +++ b/extensions/expression-language/ProcessContextExpr.cpp @@ -26,12 +26,12 @@ namespace org::apache::nifi::minifi::core { nonstd::expected<std::string, std::error_code> ProcessContextExpr::getProperty(const std::string_view name, const FlowFile* flow_file) const { - const auto property = getProcessor().getPropertyReference(name); + const auto property = getProcessor().getSupportedProperty(name); if (!property) { return nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty); } - if (!property->supports_expression_language) { + if (!property->supportsExpressionLanguage()) { return ProcessContextImpl::getProperty(name, flow_file); } if (!cached_expressions_.contains(name)) { @@ -41,7 +41,7 @@ nonstd::expected<std::string, std::error_code> ProcessContextExpr::getProperty(c } expression::Parameters p(this, flow_file); auto result = cached_expressions_[std::string{name}](p).asString(); - if (!property->validator->validate(result)) { + if (!property->getValidator().validate(result)) { return nonstd::make_unexpected(PropertyErrorCode::ValidationFailed); } return result; diff --git a/extensions/python/ExecutePythonProcessor.cpp b/extensions/python/ExecutePythonProcessor.cpp index 118b3a48c..1cde9e4cd 100644 --- a/extensions/python/ExecutePythonProcessor.cpp +++ b/extensions/python/ExecutePythonProcessor.cpp @@ -249,8 +249,8 @@ nonstd::expected<void, std::error_code> ExecutePythonProcessor::setProperty(std: return nonstd::make_unexpected(core::PropertyErrorCode::NotSupportedProperty); } -nonstd::expected<core::PropertyReference, std::error_code> ExecutePythonProcessor::getPropertyReference(std::string_view name) const { - if (const auto non_python_property = ConfigurableComponentImpl::getPropertyReference(name)) { +nonstd::expected<core::Property, std::error_code> ExecutePythonProcessor::getSupportedProperty(std::string_view name) const { + if (const auto non_python_property = ConfigurableComponentImpl::getSupportedProperty(name)) { return *non_python_property; } std::lock_guard<std::mutex> lock(python_properties_mutex_); @@ -258,12 +258,12 @@ nonstd::expected<core::PropertyReference, std::error_code> ExecutePythonProcesso return item.getName() == name; }); if (it != python_properties_.end()) { - return it->getReference(); + return *it; } return nonstd::make_unexpected(core::PropertyErrorCode::NotSupportedProperty); } -std::map<std::string, core::Property> ExecutePythonProcessor::getSupportedProperties() const { +std::map<std::string, core::Property, std::less<>> ExecutePythonProcessor::getSupportedProperties() const { auto result = ConfigurableComponentImpl::getSupportedProperties(); std::lock_guard<std::mutex> lock(python_properties_mutex_); diff --git a/extensions/python/ExecutePythonProcessor.h b/extensions/python/ExecutePythonProcessor.h index 254442e5b..8fb43c048 100644 --- a/extensions/python/ExecutePythonProcessor.h +++ b/extensions/python/ExecutePythonProcessor.h @@ -136,13 +136,13 @@ class ExecutePythonProcessor : public core::ProcessorImpl { qualified_module_name_ = qualified_module_name; } - std::map<std::string, core::Property> getSupportedProperties() const override; + std::map<std::string, core::Property, std::less<>> getSupportedProperties() const override; + nonstd::expected<core::Property, std::error_code> getSupportedProperty(std::string_view name) const override; std::vector<core::Relationship> getPythonRelationships() const; nonstd::expected<std::string, std::error_code> getProperty(std::string_view name) const override; nonstd::expected<void, std::error_code> setProperty(std::string_view name, std::string value) override; - nonstd::expected<core::PropertyReference, std::error_code> getPropertyReference(std::string_view name) const override; private: mutable std::mutex python_properties_mutex_; diff --git a/libminifi/include/core/json/JsonFlowSerializer.h b/libminifi/include/core/json/JsonFlowSerializer.h index d051b38d0..c8929f0c0 100644 --- a/libminifi/include/core/json/JsonFlowSerializer.h +++ b/libminifi/include/core/json/JsonFlowSerializer.h @@ -42,7 +42,7 @@ class JsonFlowSerializer : public core::flow::FlowSerializer { void encryptSensitiveControllerServiceProperties(rapidjson::Value& root_group, rapidjson::Document::AllocatorType& alloc, const core::ProcessGroup& process_group, const core::flow::FlowSchema& schema, const utils::crypto::EncryptionProvider& encryption_provider, const std::unordered_map<utils::Identifier, core::flow::Overrides>& overrides) const; void encryptSensitiveProperties(rapidjson::Value& property_jsons, rapidjson::Document::AllocatorType& alloc, - const std::map<std::string, Property>& properties, const utils::crypto::EncryptionProvider& encryption_provider, + const std::map<std::string, Property, std::less<>>& properties, const utils::crypto::EncryptionProvider& encryption_provider, const core::flow::Overrides& overrides) const; rapidjson::Document flow_definition_json_; diff --git a/libminifi/include/core/yaml/YamlFlowSerializer.h b/libminifi/include/core/yaml/YamlFlowSerializer.h index ebf5b2ff0..dae6cd2aa 100644 --- a/libminifi/include/core/yaml/YamlFlowSerializer.h +++ b/libminifi/include/core/yaml/YamlFlowSerializer.h @@ -38,7 +38,7 @@ class YamlFlowSerializer : public core::flow::FlowSerializer { const utils::crypto::EncryptionProvider& encryption_provider, const std::unordered_map<utils::Identifier, core::flow::Overrides>& overrides) const; void encryptSensitiveControllerServiceProperties(YAML::Node& flow_definition_yaml, const core::ProcessGroup& process_group, const core::flow::FlowSchema& schema, const utils::crypto::EncryptionProvider& encryption_provider, const std::unordered_map<utils::Identifier, core::flow::Overrides>& overrides) const; - void encryptSensitiveProperties(YAML::Node property_yamls, const std::map<std::string, Property>& properties, const utils::crypto::EncryptionProvider& encryption_provider, + void encryptSensitiveProperties(YAML::Node property_yamls, const std::map<std::string, Property, std::less<>>& properties, const utils::crypto::EncryptionProvider& encryption_provider, const core::flow::Overrides& overrides) const; YAML::Node flow_definition_yaml_; diff --git a/libminifi/src/core/flow/StructuredConfiguration.cpp b/libminifi/src/core/flow/StructuredConfiguration.cpp index e6c9bb428..bb572930f 100644 --- a/libminifi/src/core/flow/StructuredConfiguration.cpp +++ b/libminifi/src/core/flow/StructuredConfiguration.cpp @@ -761,8 +761,9 @@ void StructuredConfiguration::parseRPGPort(const Node& port_node, core::ProcessG void StructuredConfiguration::parsePropertyValueSequence(const std::string& property_name, const Node& property_value_node, core::ConfigurableComponent& component, ParameterContext* parameter_context) { - const auto property_reference = component.getPropertyReference(property_name); - const bool is_sensitive = property_reference ? property_reference->is_sensitive : false; + const bool is_sensitive = component.getSupportedProperty(property_name) + | utils::transform([](const auto& prop) -> bool { return prop.isSensitive(); }) + | utils::valueOrElse([]{ return false; }); for (const auto& nodeVal : property_value_node) { if (nodeVal) { @@ -832,9 +833,9 @@ std::optional<std::string> StructuredConfiguration::getReplacedParametersValueOr void StructuredConfiguration::parseSingleProperty(const std::string& property_name, const Node& property_value_node, core::ConfigurableComponent& component, ParameterContext* parameter_context) { - auto my_prop = component.getPropertyReference(property_name); - const bool is_sensitive = my_prop ? my_prop->is_sensitive : false; - const std::optional<std::string_view> default_value = my_prop ? my_prop->default_value : std::nullopt; + auto my_prop = component.getSupportedProperty(property_name); + const bool is_sensitive = my_prop ? my_prop->isSensitive() : false; + const std::optional<std::string_view> default_value = my_prop ? my_prop->getDefaultValue() : std::nullopt; const auto value_to_set = getReplacedParametersValueOrDefault(property_name, is_sensitive, default_value, property_value_node, parameter_context); if (!value_to_set) { diff --git a/libminifi/src/core/json/JsonFlowSerializer.cpp b/libminifi/src/core/json/JsonFlowSerializer.cpp index 470f006d9..1f43ffbb2 100644 --- a/libminifi/src/core/json/JsonFlowSerializer.cpp +++ b/libminifi/src/core/json/JsonFlowSerializer.cpp @@ -90,7 +90,7 @@ void JsonFlowSerializer::addProviderCreatedParameterContexts(rapidjson::Value& f } void JsonFlowSerializer::encryptSensitiveProperties(rapidjson::Value& property_jsons, rapidjson::Document::AllocatorType& alloc, - const std::map<std::string, Property>& properties, const utils::crypto::EncryptionProvider& encryption_provider, + const std::map<std::string, Property, std::less<>>& properties, const utils::crypto::EncryptionProvider& encryption_provider, const core::flow::Overrides& overrides) const { std::unordered_set<std::string> processed_property_names; diff --git a/libminifi/src/core/yaml/YamlFlowSerializer.cpp b/libminifi/src/core/yaml/YamlFlowSerializer.cpp index fe9bee8a2..c4a852716 100644 --- a/libminifi/src/core/yaml/YamlFlowSerializer.cpp +++ b/libminifi/src/core/yaml/YamlFlowSerializer.cpp @@ -76,7 +76,9 @@ void YamlFlowSerializer::addProviderCreatedParameterContexts(YAML::Node flow_def } } -void YamlFlowSerializer::encryptSensitiveProperties(YAML::Node property_yamls, const std::map<std::string, Property>& properties, const utils::crypto::EncryptionProvider& encryption_provider, +void YamlFlowSerializer::encryptSensitiveProperties(YAML::Node property_yamls, + const std::map<std::string, Property, std::less<>>& properties, + const utils::crypto::EncryptionProvider& encryption_provider, const core::flow::Overrides& overrides) const { std::unordered_set<std::string> processed_property_names; diff --git a/minifi-api/include/minifi-cpp/core/ConfigurableComponent.h b/minifi-api/include/minifi-cpp/core/ConfigurableComponent.h index ef161cf4b..9ebf57afd 100644 --- a/minifi-api/include/minifi-cpp/core/ConfigurableComponent.h +++ b/minifi-api/include/minifi-cpp/core/ConfigurableComponent.h @@ -44,15 +44,14 @@ public: virtual nonstd::expected<void, std::error_code> setDynamicProperty(std::string name, std::string value) = 0; virtual nonstd::expected<void, std::error_code> appendDynamicProperty(std::string_view name, std::string value) = 0; - [[nodiscard]] virtual nonstd::expected<PropertyReference, std::error_code> getPropertyReference(std::string_view name) const = 0; - [[nodiscard]] virtual std::vector<std::string> getDynamicPropertyKeys() const = 0; [[nodiscard]] virtual std::map<std::string, std::string> getDynamicProperties() const = 0; [[nodiscard]] virtual bool supportsDynamicProperties() const = 0; [[nodiscard]] virtual bool supportsDynamicRelationships() const = 0; - [[nodiscard]] virtual std::map<std::string, Property> getSupportedProperties() const = 0; + [[nodiscard]] virtual std::map<std::string, Property, std::less<>> getSupportedProperties() const = 0; + [[nodiscard]] virtual nonstd::expected<Property, std::error_code> getSupportedProperty(std::string_view name) const = 0; }; } // namespace org::apache::nifi::minifi::core diff --git a/utils/include/core/ConfigurableComponentImpl.h b/utils/include/core/ConfigurableComponentImpl.h index 355f31853..75386b65e 100644 --- a/utils/include/core/ConfigurableComponentImpl.h +++ b/utils/include/core/ConfigurableComponentImpl.h @@ -38,13 +38,12 @@ class ConfigurableComponentImpl : public virtual ConfigurableComponent { void setSupportedProperties(std::span<const PropertyReference> properties); - [[nodiscard]] std::map<std::string, Property> getSupportedProperties() const override; + [[nodiscard]] std::map<std::string, Property, std::less<>> getSupportedProperties() const override; + [[nodiscard]] nonstd::expected<Property, std::error_code> getSupportedProperty(std::string_view name) const override; [[nodiscard]] std::vector<std::string> getDynamicPropertyKeys() const override; [[nodiscard]] std::map<std::string, std::string> getDynamicProperties() const override; - [[nodiscard]] nonstd::expected<PropertyReference, std::error_code> getPropertyReference(std::string_view name) const override; - // for property sequences nonstd::expected<void, std::error_code> appendProperty(std::string_view name, std::string value) override; diff --git a/utils/src/core/ConfigurableComponentImpl.cpp b/utils/src/core/ConfigurableComponentImpl.cpp index 0ee1eb255..48d18b5cc 100644 --- a/utils/src/core/ConfigurableComponentImpl.cpp +++ b/utils/src/core/ConfigurableComponentImpl.cpp @@ -113,13 +113,6 @@ std::map<std::string, std::string> ConfigurableComponentImpl::getDynamicProperti return result; } -nonstd::expected<PropertyReference, std::error_code> ConfigurableComponentImpl::getPropertyReference(const std::string_view name) const { - const auto it = supported_properties_.find(name); - if (it == supported_properties_.end()) { return nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty); } - const Property& prop = it->second; - return prop.getReference(); -} - [[nodiscard]] nonstd::expected<std::vector<std::string>, std::error_code> ConfigurableComponentImpl::getAllPropertyValues(const std::string_view name) const { std::lock_guard<std::mutex> lock(configuration_mutex_); @@ -138,14 +131,20 @@ nonstd::expected<PropertyReference, std::error_code> ConfigurableComponentImpl:: return prop.getAllValues() | utils::transform([](const auto& values) -> std::vector<std::string> { return std::vector<std::string>{values.begin(), values.end()}; }); } -[[nodiscard]] std::map<std::string, Property> ConfigurableComponentImpl::getSupportedProperties() const { +[[nodiscard]] std::map<std::string, Property, std::less<>> ConfigurableComponentImpl::getSupportedProperties() const { std::lock_guard<std::mutex> lock(configuration_mutex_); - std::map<std::string, Property> supported_properties; + std::map<std::string, Property, std::less<>> supported_properties; for (const auto& [name, prop]: supported_properties_) { supported_properties.emplace(name, prop); } return supported_properties; +} +[[nodiscard]] nonstd::expected<Property, std::error_code> ConfigurableComponentImpl::getSupportedProperty(const std::string_view name) const { + std::lock_guard<std::mutex> lock(configuration_mutex_); + const auto it = supported_properties_.find(name); + if (it == supported_properties_.end()) { return nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty); } + return it->second; } } // namespace org::apache::nifi::minifi::core
