lordgamez commented on code in PR #2047:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2047#discussion_r2435811815
##########
libminifi/src/core/ProcessContextImpl.cpp:
##########
@@ -74,28 +75,72 @@ bool
ProcessContextImpl::hasNonEmptyProperty(std::string_view name) const {
std::vector<std::string> ProcessContextImpl::getDynamicPropertyKeys() const {
return processor_.getDynamicPropertyKeys(); }
-std::map<std::string, std::string>
ProcessContextImpl::getDynamicProperties(const FlowFile*) const { return
processor_.getDynamicProperties(); }
+std::map<std::string, std::string>
ProcessContextImpl::getDynamicProperties(const FlowFile* flow_file) const {
+ std::lock_guard<std::mutex> lock(mutex_);
+ auto dynamic_props = processor_.getDynamicProperties();
+ const expression::Parameters params{this, flow_file};
+ for (auto& [dynamic_property_name, dynamic_property_value]: dynamic_props) {
+ auto cached_dyn_expr_it =
cached_dynamic_expressions_.find(dynamic_property_name);
+ if (cached_dyn_expr_it == cached_dynamic_expressions_.end()) {
+ auto expression = expression::compile(dynamic_property_value);
+ const auto [it, success] =
cached_dynamic_expressions_.emplace(dynamic_property_name, expression);
+ gsl_Assert(success && "getDynamicProperties: no element with the key
existed, yet insertion failed");
+ cached_dyn_expr_it = it;
+ }
+ auto& expression = cached_dyn_expr_it->second;
+ dynamic_property_value = expression(params).asString();
+ }
+ return dynamic_props;
+}
bool ProcessContextImpl::isAutoTerminated(Relationship relationship) const {
return processor_.isAutoTerminated(relationship); }
uint8_t ProcessContextImpl::getMaxConcurrentTasks() const { return
processor_.getMaxConcurrentTasks(); }
void ProcessContextImpl::yield() { processor_.yield(); }
-nonstd::expected<std::string, std::error_code>
ProcessContextImpl::getProperty(const std::string_view name, const FlowFile*
const) const {
- return getProcessor().getProperty(name);
+nonstd::expected<std::string, std::error_code>
ProcessContextImpl::getProperty(const std::string_view name, const FlowFile*
flow_file) const {
+ std::lock_guard<std::mutex> lock(mutex_);
+ const auto property = getProcessorInfo().getSupportedProperty(name);
+ if (!property) {
+ return nonstd::make_unexpected(PropertyErrorCode::NotSupportedProperty);
+ }
+
+ if (!property->supportsExpressionLanguage()) {
+ return getProcessor().getProperty(name);
+ }
+ if (!cached_expressions_.contains(name)) {
+ auto expression_str = getProcessor().getProperty(name);
+ if (!expression_str) { return expression_str; }
+ cached_expressions_.emplace(std::string{name},
expression::compile(*expression_str));
+ }
+ expression::Parameters p(this, flow_file);
+ auto result = cached_expressions_[std::string{name}](p).asString();
+ if (!property->getValidator().validate(result)) {
+ return nonstd::make_unexpected(PropertyErrorCode::ValidationFailed);
+ }
+ return result;
}
nonstd::expected<void, std::error_code> ProcessContextImpl::setProperty(const
std::string_view name, std::string value) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ cached_expressions_.erase(std::string{name});
return getProcessor().setProperty(name, std::move(value));
}
nonstd::expected<void, std::error_code>
ProcessContextImpl::clearProperty(const std::string_view name) {
Review Comment:
Updated in
https://github.com/apache/nifi-minifi-cpp/pull/2047/commits/6e5ea6606a09fef36f498e5db3c48d0e7bbac705
##########
libminifi/src/core/ProcessContextImpl.cpp:
##########
@@ -15,8 +15,9 @@
* limitations under the License.
*/
-#include "core/ProcessContext.h"
+#include "core/ProcessContextImpl.h"
#include "core/Processor.h"
+#include "utils/PropertyErrors.h"
Review Comment:
Updated in
https://github.com/apache/nifi-minifi-cpp/pull/2047/commits/6e5ea6606a09fef36f498e5db3c48d0e7bbac705
##########
extensions/standard-processors/tests/unit/ExpressionLanguageInDynamicPropertiesTests.cpp:
##########
@@ -0,0 +1,95 @@
+/**
+ *
+ * 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 <ExtractText.h>
+#include <GetFile.h>
+#include <PutFile.h>
+#include <UpdateAttribute.h>
+#include <LogAttribute.h>
+#include "unit/TestBase.h"
+#include "unit/Catch.h"
+#include "unit/ProvenanceTestHelper.h"
+
+namespace org::apache::nifi::minifi::test {
+
+TEST_CASE("GetFile PutFile dynamic attribute",
"[expressionLanguageTestGetFilePutFileDynamicAttribute]") {
+ TestController testController;
+
+ LogTestController::getInstance().setTrace<TestPlan>();
+ LogTestController::getInstance().setTrace<minifi::processors::PutFile>();
+ LogTestController::getInstance().setTrace<minifi::processors::ExtractText>();
+ LogTestController::getInstance().setTrace<minifi::processors::GetFile>();
+ LogTestController::getInstance().setTrace<minifi::processors::PutFile>();
+
LogTestController::getInstance().setTrace<minifi::processors::LogAttribute>();
+
LogTestController::getInstance().setTrace<minifi::processors::UpdateAttribute>();
+
+ auto conf = std::make_shared<minifi::ConfigureImpl>();
+
+ conf->set("nifi.my.own.property", "custom_value");
+
+ auto plan = testController.createPlan(conf);
+ auto repo = std::make_shared<TestRepository>();
Review Comment:
Updated in
https://github.com/apache/nifi-minifi-cpp/pull/2047/commits/6e5ea6606a09fef36f498e5db3c48d0e7bbac705
##########
libminifi/CMakeLists.txt:
##########
@@ -32,15 +32,10 @@ set_cpp_version()
include_directories(include)
-if(WIN32)
- include_directories(opsys/win)
- set(SOCKET_SOURCES "src/io/win/*.cpp")
-else()
- include_directories(opsys/posix)
- set(SOCKET_SOURCES "src/io/posix/*.cpp")
-endif()
+include(ExpressionLanguage)
set(TLS_SOURCES "src/utils/tls/*.cpp" "src/io/tls/*.cpp")
+set(EL_GENERATED_SOURCES "${EL_GENERATED_INCLUDE_DIR}/*.cpp")
Review Comment:
Updated in
https://github.com/apache/nifi-minifi-cpp/pull/2047/commits/6e5ea6606a09fef36f498e5db3c48d0e7bbac705
--
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]