NIFI-6194: Fixed verification logic to determine whether or not a variable's value can be changed. Previously, the logic had a bug that resulted in a failure if any child group contained a running processor that references an overridden variable and the user attempts to change the overridden variable at the higher level. We should not include any components of descendent groups if the descendent group overrides the variable.

This closes #3420.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Mark Payne 2019-04-09 09:44:22 -04:00 committed by Bryan Bende
parent 38db4e97cd
commit bf7e70e4c3
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39

View File

@ -2849,13 +2849,14 @@ public final class StandardProcessGroup implements ProcessGroup {
return;
}
for (final ProcessorNode processor : findAllProcessors()) {
// Determine any Processors that references the variable
for (final ProcessorNode processor : getProcessors()) {
if (!processor.isRunning()) {
continue;
}
for (final String variableName : updatedVariableNames) {
for (final VariableImpact impact : getVariableImpact(processor)) {
for (final VariableImpact impact : getVariableImpact(processor)) {
for (final String variableName : updatedVariableNames) {
if (impact.isImpacted(variableName)) {
throw new IllegalStateException("Cannot update variable '" + variableName + "' because it is referenced by " + processor + ", which is currently running");
}
@ -2863,19 +2864,38 @@ public final class StandardProcessGroup implements ProcessGroup {
}
}
for (final ControllerServiceNode service : findAllControllerServices()) {
// Determine any Controller Service that references the variable.
for (final ControllerServiceNode service : getControllerServices(false)) {
if (!service.isActive()) {
continue;
}
for (final String variableName : updatedVariableNames) {
for (final VariableImpact impact : getVariableImpact(service)) {
for (final VariableImpact impact : getVariableImpact(service)) {
for (final String variableName : updatedVariableNames) {
if (impact.isImpacted(variableName)) {
throw new IllegalStateException("Cannot update variable '" + variableName + "' because it is referenced by " + service + ", which is currently running");
}
}
}
}
// For any child Process Group that does not override the variable, also include its references.
// If a child group has a value for the same variable, though, then that means that the child group
// is overriding the variable and its components are actually referencing a different variable.
for (final ProcessGroup childGroup : getProcessGroups()) {
for (final String variableName : updatedVariableNames) {
final ComponentVariableRegistry childRegistry = childGroup.getVariableRegistry();
final VariableDescriptor descriptor = childRegistry.getVariableKey(variableName);
final boolean overridden = childRegistry.getVariableMap().containsKey(descriptor);
if (!overridden) {
final Set<ComponentNode> affectedComponents = childGroup.getComponentsAffectedByVariable(variableName);
if (!affectedComponents.isEmpty()) {
throw new IllegalStateException("Cannot update variable '" + variableName + "' because it is referenced by " + affectedComponents.size() + " components that are " +
"currently running.");
}
}
}
}
} finally {
readLock.unlock();
}
@ -2987,8 +3007,8 @@ public final class StandardProcessGroup implements ProcessGroup {
}
final Map<VariableDescriptor, String> variableMap = new HashMap<>();
variables.entrySet() // cannot use Collectors.toMap because value may be null
.forEach(entry -> variableMap.put(new VariableDescriptor(entry.getKey()), entry.getValue()));
// cannot use Collectors.toMap because value may be null
variables.forEach((key, value) -> variableMap.put(new VariableDescriptor(key), value));
variableRegistry.setVariables(variableMap);
} finally {