Skip to content

Commit

Permalink
MINIFICPP-2493 Fix C2 flow update with parameter contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
lordgamez authored and szaszm committed Nov 21, 2024
1 parent 96dd2a6 commit 5953140
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docker/test/integration/features/minifi_c2_server.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ Feature: MiNiFi can communicate with Apache NiFi MiNiFi C2 server
When all instances start up
Then the MiNiFi C2 SSL server logs contain the following message: "acknowledged with a state of FULLY_APPLIED(DONE)" in less than 60 seconds
And a flowfile with the content "test" is placed in the monitored directory in less than 10 seconds

Scenario: MiNiFi flow config is updated from MiNiFi C2 server with overriden parameter context
Given a GetFile processor with the name "GetFile1" and the "Input Directory" property set to "${INPUT_DIR}"
And parameter context name is set to 'my-context'
And a non-sensitive parameter in the flow config called 'INPUT_DIR' with the value '/tmp/non-existent' in the parameter context 'my-context'
And C2 is enabled in MiNiFi
And a file with the content "test" is present in "/tmp/input"
And a MiNiFi C2 server is set up
When all instances start up
Then the MiNiFi C2 server logs contain the following message: "acknowledged with a state of FULLY_APPLIED(DONE)" in less than 30 seconds
And a flowfile with the content "test" is placed in the monitored directory in less than 10 seconds
And the Minifi logs do not contain the following message: "Failed to parse json response: The document is empty. at 0" after 0 seconds
12 changes: 11 additions & 1 deletion docker/test/integration/resources/minifi-c2-server/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
MiNiFi Config Version: 3
Flow Controller:
name: MiNiFi Flow
Parameter Contexts:
- id: 721e10b7-8e00-3188-9a27-476cca376978
name: my-context
description: my parameter context
Parameters:
- name: INPUT_DIR
description: ''
sensitive: false
value: /tmp/input
Processors:
- name: Get files from /tmp/input
id: 2f2a3b47-f5ba-49f6-82b5-bc1c86b96e27
class: org.apache.nifi.minifi.processors.GetFile
scheduling strategy: TIMER_DRIVEN
scheduling period: 1000 ms
Properties:
Input Directory: /tmp/input
Input Directory: "#{INPUT_DIR}"
- name: Put files to /tmp/output
id: e143601d-de4f-44ba-a6ec-d1f97d77ec94
class: org.apache.nifi.minifi.processors.PutFile
Expand All @@ -27,5 +36,6 @@ Connections:
source relationship names:
- success
destination id: e143601d-de4f-44ba-a6ec-d1f97d77ec94
Parameter Context Name: my-context
Controller Services: []
Remote Process Groups: []
2 changes: 2 additions & 0 deletions libminifi/src/core/FlowConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ std::unique_ptr<core::reporting::SiteToSiteProvenanceReportingTask> FlowConfigur

std::unique_ptr<core::ProcessGroup> FlowConfiguration::updateFromPayload(const std::string& url, const std::string& yamlConfigPayload, const std::optional<std::string>& flow_id) {
auto old_provider = service_provider_;
auto old_parameter_contexts = std::move(parameter_contexts_);
service_provider_ = std::make_shared<core::controller::StandardControllerServiceProvider>(std::make_unique<core::controller::ControllerServiceNodeMap>(), configuration_);
auto payload = getRootFromPayload(yamlConfigPayload);
if (!url.empty() && payload != nullptr) {
Expand All @@ -110,6 +111,7 @@ std::unique_ptr<core::ProcessGroup> FlowConfiguration::updateFromPayload(const s
flow_version_->setFlowVersion(url, bucket_id, flow_id ? *flow_id : payload_flow_id);
} else {
service_provider_ = old_provider;
parameter_contexts_ = std::move(old_parameter_contexts);
}
return payload;
}
Expand Down

0 comments on commit 5953140

Please sign in to comment.