lordgamez commented on code in PR #1792:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1792#discussion_r1668693502
##########
extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp:
##########
@@ -1072,3 +1075,581 @@ TEST_CASE("Test serialization", "[YamlConfiguration]") {
const std::string serialized_flow_definition_masked =
std::regex_replace(serialized_flow_definition, std::regex{"enc\\{.*\\}"},
"enc{...}");
CHECK(serialized_flow_definition_masked ==
TEST_FLOW_WITH_SENSITIVE_PROPERTIES_ENCRYPTED);
}
+
+TEST_CASE("Yaml configuration can use parameter contexts",
"[YamlConfiguration]") {
+ ConfigurationTestController test_controller;
+ core::YamlConfiguration yaml_config(test_controller.getContext());
+
+ static const std::string TEST_CONFIG_YAML =
+ R"(
+MiNiFi Config Version: 3
+Flow Controller:
+ name: Simple TailFile
+Parameter Contexts:
+ - id: 721e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: lookup.frequency
+ description: ''
+ value: 12 min
+ - name: batch_size
+ description: ''
+ value: 12
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+ name: TailFile
+ class: org.apache.nifi.processors.standard.TailFile
+ max concurrent tasks: 1
+ scheduling strategy: TIMER_DRIVEN
+ scheduling period: 1 sec
+ auto-terminated relationships list: [success]
+ Properties:
+ Batch Size: "#{batch_size}"
+ File to Tail: ./logs/minifi-app.log
+ Initial Start Position: Beginning of File
+ tail-mode: Single file
+ Lookup frequency: "#{lookup.frequency}"
+Controller Services: []
+Process Groups: []
+Input Ports: []
+Output Ports: []
+Funnels: []
+Connections: []
+Parameter Context Name: my-context
+NiFi Properties Overrides: {}
+ )";
+
+ std::unique_ptr<core::ProcessGroup> flow =
yaml_config.getRootFromPayload(TEST_CONFIG_YAML);
+ REQUIRE(flow);
+ auto* proc = flow->findProcessorByName("TailFile");
+ REQUIRE(proc);
+ REQUIRE(proc->getProperty("Batch Size") == "12");
+ REQUIRE(proc->getProperty("Lookup frequency") == "12 min");
+}
+
+TEST_CASE("Yaml config should not replace parameter from different parameter
context", "[YamlConfiguration]") {
+ ConfigurationTestController test_controller;
+ core::YamlConfiguration yaml_config(test_controller.getContext());
+
+ static const std::string TEST_CONFIG_YAML =
+ R"(
+MiNiFi Config Version: 3
+Flow Controller:
+ name: Simple TailFile
+Parameter Contexts:
+ - id: 721e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: lookup.frequency
+ description: ''
+ value: 12 min
+ - id: 123e10b7-8e00-3188-9a27-476cca376978
+ name: other-context
+ description: my other context
+ Parameters:
+ - name: batch_size
+ description: ''
+ value: 1
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+ name: TailFile
+ class: org.apache.nifi.processors.standard.TailFile
+ max concurrent tasks: 1
+ scheduling strategy: TIMER_DRIVEN
+ scheduling period: 1 sec
+ auto-terminated relationships list: [success]
+ Properties:
+ Batch Size: "#{batch_size}"
+ File to Tail: ./logs/minifi-app.log
+ Initial Start Position: Beginning of File
+ tail-mode: Single file
+ Lookup frequency: "#{lookup.frequency}"
+Controller Services: []
+Process Groups: []
+Input Ports: []
+Output Ports: []
+Funnels: []
+Connections: []
+Parameter Context Name: my-context
+NiFi Properties Overrides: {}
+ )";
+
+ REQUIRE_THROWS_WITH(yaml_config.getRootFromPayload(TEST_CONFIG_YAML),
"Parameter 'batch_size' not found");
+}
+
+TEST_CASE("Cannot use the same parameter context name twice",
"[YamlConfiguration]") {
+ ConfigurationTestController test_controller;
+ core::YamlConfiguration yaml_config(test_controller.getContext());
+
+ static const std::string TEST_CONFIG_YAML =
+ R"(
+MiNiFi Config Version: 3
+Flow Controller:
+ name: Simple TailFile
+Parameter Contexts:
+ - id: 721e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: lookup.frequency
+ description: ''
+ value: 12 min
+ - id: 123e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: batch_size
+ description: ''
+ value: 1
+Processors: []
+Controller Services: []
+Process Groups: []
+Input Ports: []
+Output Ports: []
+Funnels: []
+Connections: []
+Parameter Context Name: my-context
+NiFi Properties Overrides: {}
+ )";
+
+ REQUIRE_THROWS_WITH(yaml_config.getRootFromPayload(TEST_CONFIG_YAML),
"Parameter context name 'my-context' already exists, parameter context names
must be unique!");
+}
+
+TEST_CASE("Cannot use the same parameter name within a parameter context
twice", "[YamlConfiguration]") {
+ ConfigurationTestController test_controller;
+ core::YamlConfiguration yaml_config(test_controller.getContext());
+
+ static const std::string TEST_CONFIG_YAML =
+ R"(
+MiNiFi Config Version: 3
+Flow Controller:
+ name: Simple TailFile
+Parameter Contexts:
+ - id: 721e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: lookup.frequency
+ description: ''
+ value: 12 min
+ - name: lookup.frequency
+ description: ''
+ value: 1 min
+Processors: []
+Controller Services: []
+Process Groups: []
+Input Ports: []
+Output Ports: []
+Funnels: []
+Connections: []
+Parameter Context Name: my-context
+NiFi Properties Overrides: {}
+ )";
+
+ REQUIRE_THROWS_WITH(yaml_config.getRootFromPayload(TEST_CONFIG_YAML),
"Parameter name 'lookup.frequency' already exists, parameter names must be
unique within a parameter context!");
+}
+
+class DummyFlowYamlProcessor : public core::Processor {
+ public:
+ using core::Processor::Processor;
+
+ static constexpr const char* Description = "A processor that does nothing.";
+ static constexpr auto SimpleProperty =
core::PropertyDefinitionBuilder<>::createProperty("Simple Property")
+ .withDescription("Just a simple string property")
+ .build();
+ static constexpr auto SensitiveProperty =
core::PropertyDefinitionBuilder<>::createProperty("Sensitive Property")
+ .withDescription("Sensitive property")
+ .isSensitive(true)
+ .build();
+ static constexpr auto Properties = std::array<core::PropertyReference,
2>{SimpleProperty, SensitiveProperty};
+ static constexpr auto Relationships =
std::array<core::RelationshipDefinition, 0>{};
+ static constexpr bool SupportsDynamicProperties = true;
+ static constexpr bool SupportsDynamicRelationships = true;
+ static constexpr core::annotation::Input InputRequirement =
core::annotation::Input::INPUT_ALLOWED;
+ static constexpr bool IsSingleThreaded = false;
+ ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS
+
+ void initialize() override { setSupportedProperties(Properties); }
+};
+
+REGISTER_RESOURCE(DummyFlowYamlProcessor, Processor);
+
+TEST_CASE("Cannot use non-sensitive parameter in sensitive property",
"[YamlConfiguration]") {
+ ConfigurationTestController test_controller;
+ core::YamlConfiguration yaml_config(test_controller.getContext());
+
+ static const std::string TEST_CONFIG_YAML =
+ R"(
+MiNiFi Config Version: 3
+Flow Controller:
+ name: flowconfig
+Parameter Contexts:
+ - id: 721e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: my_value
+ description: ''
+ value: value1
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+ name: TailFile
+ class: org.apache.nifi.processors.DummyFlowYamlProcessor
+ max concurrent tasks: 1
+ scheduling strategy: TIMER_DRIVEN
+ scheduling period: 1 sec
+ auto-terminated relationships list: [success]
+ Properties:
+ Simple Property: simple
+ Sensitive Property: "#{my_value}"
+Controller Services: []
+Process Groups: []
+Input Ports: []
+Output Ports: []
+Funnels: []
+Connections: []
+Parameter Context Name: my-context
+NiFi Properties Overrides: {}
+ )";
+
+ REQUIRE_THROWS_WITH(yaml_config.getRootFromPayload(TEST_CONFIG_YAML),
"Non-sensitive parameter 'my_value' cannot be referenced in a sensitive
property");
+}
+
+TEST_CASE("Cannot use non-sensitive parameter in sensitive property value
sequence", "[YamlConfiguration]") {
+ ConfigurationTestController test_controller;
+ core::YamlConfiguration yaml_config(test_controller.getContext());
+
+ static const std::string TEST_CONFIG_YAML =
+ R"(
+MiNiFi Config Version: 3
+Flow Controller:
+ name: flowconfig
+Parameter Contexts:
+ - id: 721e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: my_value
+ description: ''
+ value: value1
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+ name: TailFile
+ class: org.apache.nifi.processors.DummyFlowYamlProcessor
+ max concurrent tasks: 1
+ scheduling strategy: TIMER_DRIVEN
+ scheduling period: 1 sec
+ auto-terminated relationships list: [success]
+ Properties:
+ Simple Property: simple
+ Sensitive Property:
+ - value: first value
+ - value: "#{my_value}"
+Controller Services: []
+Process Groups: []
+Input Ports: []
+Output Ports: []
+Funnels: []
+Connections: []
+Parameter Context Name: my-context
+NiFi Properties Overrides: {}
+ )";
+
+ REQUIRE_THROWS_WITH(yaml_config.getRootFromPayload(TEST_CONFIG_YAML),
"Non-sensitive parameter 'my_value' cannot be referenced in a sensitive
property");
+}
+
+TEST_CASE("Parameters can be used in nested process groups",
"[YamlConfiguration]") {
+ ConfigurationTestController test_controller;
+ core::YamlConfiguration yaml_config(test_controller.getContext());
+
+ static const std::string TEST_CONFIG_YAML =
+ R"(
+MiNiFi Config Version: 3
+Flow Controller:
+ name: Simple TailFile
+Parameter Contexts:
+ - id: 721e10b7-8e00-3188-9a27-476cca376978
+ name: my-context
+ description: my parameter context
+ Parameters:
+ - name: lookup.frequency
+ description: ''
+ value: 12 min
+ - id: 123e10b7-8e00-3188-9a27-476cca376456
+ name: sub-context
+ description: my sub context
+ Parameters:
+ - name: batch_size
+ description: ''
+ value: 12
+Processors:
+- id: b0c04f28-0158-1000-0000-000000000000
+ name: TailFile
+ class: org.apache.nifi.processors.standard.TailFile
+ max concurrent tasks: 1
+ scheduling strategy: TIMER_DRIVEN
+ scheduling period: 1 sec
+ auto-terminated relationships list: [success]
+ Properties:
+ Batch Size: 1
+ File to Tail: ./logs/minifi-app.log
+ Initial Start Position: Beginning of File
+ tail-mode: Single file
+ Lookup frequency: "#{lookup.frequency}"
+Controller Services: []
+Input Ports: []
+Output Ports: []
+Funnels: []
+Connections: []
+Parameter Context Name: my-context
+Process Groups:
+ - id: 2a3aaf32-8574-4fa7-b720-84001f8dde43
+ name: Sub process group
+ Processors:
+ - id: 12304f28-0158-1000-0000-000000000000
+ name: SubTailFile
+ class: org.apache.nifi.processors.standard.TailFile
+ max concurrent tasks: 1
+ scheduling strategy: TIMER_DRIVEN
+ scheduling period: 1 sec
+ auto-terminated relationships list: [success]
+ Properties:
+ Batch Size: "#{batch_size}"
+ File to Tail: ./logs/minifi-app.log
+ Initial Start Position: Beginning of File
+ tail-mode: Single file
+ Lookup frequency: 1 sec
+ Parameter Context Name: sub-context
+ )";
+
+ std::unique_ptr<core::ProcessGroup> flow =
yaml_config.getRootFromPayload(TEST_CONFIG_YAML);
+ REQUIRE(flow);
+ auto* proc = flow->findProcessorByName("TailFile");
+ REQUIRE(proc);
+ CHECK(proc->getProperty("Batch Size") == "1");
+ CHECK(proc->getProperty("Lookup frequency") == "12 min");
+ auto* subproc = flow->findProcessorByName("SubTailFile");
+ REQUIRE(subproc);
+ CHECK(subproc->getProperty("Batch Size") == "12");
+ CHECK(subproc->getProperty("Lookup frequency") == "1 sec");
+}
+
+TEST_CASE("Subprocessgroups cannot inherit parameters from parent
processgroup", "[YamlConfiguration]") {
Review Comment:
Yes, this is on purpose. In NiFi parameter contexts are not inherited
between process groups. It has to be explicitly selected which parameter
context should be used for each process group. There is a feature in NiFi which
will be implemented later to use parameter context inheritance. That allows
parameter contexts to be derived from other parameter contexts and using the
derived contexts allows the process group to use the parameters from the base
parameter context.
--
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]