mirror of
https://github.com/apache/nifi.git
synced 2025-02-14 05:55:07 +00:00
NIFI-13831: Adding inheritance to versioned component synchronizer parameter context synchronization when considering referencing components to restart
Signed-off-by: Csaba Bejan <bejan.csaba@gmail.com> This closes #9338.
This commit is contained in:
parent
8cdc83ee85
commit
abc5c328f1
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user