Skip to content

Commit

Permalink
NIFI-10572: Allowing variables to be deleted between versions, and co…
Browse files Browse the repository at this point in the history
…nsidering ancestor variable additions to be environmental

This closes apache#6474

Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
gresockj authored and exceptionfactory committed Oct 3, 2022
1 parent 11ff622 commit 10a5e91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,13 @@ private void updateVariableRegistry(final ProcessGroup group, final VersionedPro
}
}

// If any variables were removed from the proposed flow, add those as null values to remove them from the variable registry.
for (final String existingVariableName : existingVariableMap.keySet()) {
if (!proposed.getVariables().containsKey(existingVariableName)) {
updatedVariableMap.put(existingVariableName, null);
}
}

group.setVariables(updatedVariableMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.nifi.flow.VersionedPort;
import org.apache.nifi.flow.VersionedProcessGroup;
import org.apache.nifi.flow.VersionedProcessor;
import org.apache.nifi.groups.ProcessGroup;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.registry.flow.diff.DifferenceType;
import org.apache.nifi.registry.flow.diff.FlowDifference;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class FlowDifferenceFilters {
public static boolean isEnvironmentalChange(final FlowDifference difference, final VersionedProcessGroup localGroup, final FlowManager flowManager) {
return difference.getDifferenceType() == DifferenceType.BUNDLE_CHANGED
|| isVariableValueChange(difference)
|| isAncestorVariableAdded(difference, flowManager)
|| isRpgUrlChange(difference)
|| isAddedOrRemovedRemotePort(difference)
|| isPublicPortNameChange(difference)
Expand Down Expand Up @@ -322,6 +324,26 @@ public static boolean isVariableValueChange(final FlowDifference flowDifference)
return flowDifference.getDifferenceType() == DifferenceType.VARIABLE_CHANGED;
}

public static boolean isAncestorVariableAdded(final FlowDifference fd, final FlowManager flowManager) {
if (fd.getDifferenceType() == DifferenceType.VARIABLE_ADDED) {
if (fd.getComponentA() instanceof InstantiatedVersionedComponent) {
final InstantiatedVersionedComponent componentA = (InstantiatedVersionedComponent) fd.getComponentA();
final ProcessGroup processGroup = flowManager.getGroup(componentA.getInstanceIdentifier());
if (processGroup.getVariableRegistry().getVariableKey(fd.getFieldName().get()) == null) {
return true;
}
} else if (fd.getComponentB() instanceof InstantiatedVersionedComponent) {
final InstantiatedVersionedComponent componentB = (InstantiatedVersionedComponent) fd.getComponentB();
final ProcessGroup processGroup = flowManager.getGroup(componentB.getInstanceIdentifier());
if (processGroup.getVariableRegistry().getVariableKey(fd.getFieldName().get()) == null) {
return true;
}
}
}

return false;
}

public static boolean isRpgUrlChange(final FlowDifference flowDifference) {
return flowDifference.getDifferenceType() == DifferenceType.RPG_URL_CHANGED;
}
Expand Down

0 comments on commit 10a5e91

Please sign in to comment.