You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by be...@apache.org on 2024/10/04 22:32:08 UTC
(nifi) branch support/nifi-1.x updated: NIFI-13831: Adding inheritance to versioned component synchronizer parameter context synchronization when considering referencing components to restart
This is an automated email from the ASF dual-hosted git repository.
bejancsaba pushed a commit to branch support/nifi-1.x
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/support/nifi-1.x by this push:
new abc5c328f1 NIFI-13831: Adding inheritance to versioned component synchronizer parameter context synchronization when considering referencing components to restart
abc5c328f1 is described below
commit abc5c328f10451cc4d7cb9d06136477f1d5fdce9
Author: Joe Gresock <jg...@gmail.com>
AuthorDate: Wed Oct 2 18:41:22 2024 -0400
NIFI-13831: Adding inheritance to versioned component synchronizer parameter context synchronization when considering referencing components to restart
Signed-off-by: Csaba Bejan <be...@gmail.com>
This closes #9338.
---
.../StandardVersionedComponentSynchronizer.java | 16 +++++++++-
...StandardVersionedComponentSynchronizerTest.java | 34 ++++++++++++++++++----
2 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java
index 12420e3764..a2c702c704 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java
@@ -1656,12 +1656,26 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen
}
}
+ private void collectValueAndReferences(final ParameterContext parameterContext, final Map<String, String> valueAndRef) {
+ parameterContext.getEffectiveParameters()
+ .forEach((pd, param) -> valueAndRef.put(pd.getName(), param.getValue()));
+ }
+
protected Set<String> getUpdatedParameterNames(final ParameterContext parameterContext, final VersionedParameterContext proposed) {
final Map<String, String> originalValues = new HashMap<>();
- parameterContext.getParameters().values().forEach(param -> originalValues.put(param.getDescriptor().getName(), param.getValue()));
+ collectValueAndReferences(parameterContext, originalValues);
final Map<String, String> proposedValues = new HashMap<>();
if (proposed != null) {
+ if (proposed.getInheritedParameterContexts() != null) {
+ for (int i = proposed.getInheritedParameterContexts().size() - 1; i >= 0; i--) {
+ final String name = proposed.getInheritedParameterContexts().get(i);
+ final ParameterContext inheritedContext = getParameterContextByName(name);
+ if (inheritedContext != null) {
+ collectValueAndReferences(inheritedContext, proposedValues);
+ }
+ }
+ }
proposed.getParameters().forEach(versionedParam -> proposedValues.put(versionedParam.getName(), versionedParam.getValue()));
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java
index 0ec1e8df66..64dc2dea8d 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java
@@ -1061,30 +1061,30 @@ public class StandardVersionedComponentSynchronizerTest {
// Test no changes
Map<String, String> parameterMap = new HashMap<>(originalParams);
- VersionedParameterContext proposed = createVersionedParameterContext("Context 2", parameterMap, Collections.singleton("secret"));
+ VersionedParameterContext proposed = createVersionedParameterContext("Context 1", parameterMap, Collections.singleton("secret"));
assertEquals(Collections.emptySet(), synchronizer.getUpdatedParameterNames(existing, proposed));
// Test non-sensitive param change
parameterMap = new HashMap<>(originalParams);
parameterMap.put("abc", "hello");
- proposed = createVersionedParameterContext("Context 2", parameterMap, Collections.singleton("secret"));
+ proposed = createVersionedParameterContext("Context 1", parameterMap, Collections.singleton("secret"));
assertEquals(Collections.singleton("abc"), synchronizer.getUpdatedParameterNames(existing, proposed));
// Test sensitive param change
parameterMap = new HashMap<>(originalParams);
parameterMap.put("secret", "secret");
- proposed = createVersionedParameterContext("Context 2", parameterMap, Collections.singleton("secret"));
+ proposed = createVersionedParameterContext("Context 1", parameterMap, Collections.singleton("secret"));
assertEquals(Collections.singleton("secret"), synchronizer.getUpdatedParameterNames(existing, proposed));
// Test removed parameters
parameterMap.clear();
- proposed = createVersionedParameterContext("Context 2", parameterMap, Collections.singleton("secret"));
+ proposed = createVersionedParameterContext("Context 1", parameterMap, Collections.singleton("secret"));
assertEquals(new HashSet<>(Arrays.asList("abc", "secret")), synchronizer.getUpdatedParameterNames(existing, proposed));
// Test added parameter
parameterMap = new HashMap<>(originalParams);
parameterMap.put("Added", "Added");
- proposed = createVersionedParameterContext("Context 2", parameterMap, Collections.singleton("secret"));
+ proposed = createVersionedParameterContext("Context 1", parameterMap, Collections.singleton("secret"));
assertEquals(Collections.singleton("Added"), synchronizer.getUpdatedParameterNames(existing, proposed));
// Test added, removed, and updated parameters
@@ -1093,8 +1093,30 @@ public class StandardVersionedComponentSynchronizerTest {
parameterMap.put("Added 2", "Added");
parameterMap.remove("secret");
parameterMap.put("abc", "hello");
- proposed = createVersionedParameterContext("Context 2", parameterMap, Collections.singleton("secret"));
+ proposed = createVersionedParameterContext("Context 1", parameterMap, Collections.singleton("secret"));
assertEquals(new HashSet<>(Arrays.asList("abc", "secret", "Added", "Added 2")), synchronizer.getUpdatedParameterNames(existing, proposed));
+
+ // Test change value due to inherited parameter context reordering
+ final Map<String, String> inheritedParameters = new HashMap<>();
+ // Context 1: abc = xyz
+ // Context 3: abc = def
+ inheritedParameters.put("abc", "def");
+ final VersionedParameterContext context3 = createVersionedParameterContext("Context 3", inheritedParameters, Collections.emptySet());
+
+ synchronizer.synchronize(null, context3, synchronizationOptions);
+
+ parameterMap = new HashMap<>();
+ proposed = createVersionedParameterContext("Context 2", parameterMap, Collections.emptySet());
+ synchronizer.synchronize(null, proposed, synchronizationOptions);
+
+ ParameterContext context2 = parameterContextManager.getParameterContextNameMapping().get("Context 2");
+ proposed.setInheritedParameterContexts(List.of("Context 1", "Context 3"));
+ synchronizer.synchronize(context2, proposed, synchronizationOptions);
+
+ proposed.setInheritedParameterContexts(List.of("Context 3", "Context 1"));
+ context2 = parameterContextManager.getParameterContextNameMapping().get("Context 2");
+ // The effective value of abc should change here due to the reordering
+ assertEquals(Collections.singleton("abc"), synchronizer.getUpdatedParameterNames(context2, proposed));
}
@Test