From 28e1bcc9d034261c8045c6b2c76ff21839f7eb95 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Tue, 16 Jan 2018 12:36:52 -0500 Subject: [PATCH] NIFI-4782: Allow the value of a Required Property to be moved when changing version of a flow or reverting a flow This closes #2406. Signed-off-by: Bryan Bende --- .../nifi/controller/AbstractConfiguredComponent.java | 12 ++++++++---- .../apache/nifi/controller/ConfiguredComponent.java | 6 +++++- .../org/apache/nifi/groups/StandardProcessGroup.java | 8 ++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java index ff5a8aff0a..a5f2631bdd 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java @@ -151,7 +151,7 @@ public abstract class AbstractConfiguredComponent implements ConfigurableCompone } @Override - public void setProperties(Map properties) { + public void setProperties(final Map properties, final boolean allowRemovalOfRequiredProperties) { if (properties == null) { return; } @@ -170,7 +170,7 @@ public abstract class AbstractConfiguredComponent implements ConfigurableCompone } if (entry.getKey() != null && entry.getValue() == null) { - removeProperty(entry.getKey()); + removeProperty(entry.getKey(), allowRemovalOfRequiredProperties); } else if (entry.getKey() != null) { setProperty(entry.getKey(), CharacterFilterUtils.filterInvalidXmlCharacters(entry.getValue())); } @@ -231,17 +231,20 @@ public abstract class AbstractConfiguredComponent implements ConfigurableCompone * if was a dynamic property. * * @param name the property to remove + * @param allowRemovalOfRequiredProperties whether or not the property should be removed if it's required * @return true if removed; false otherwise * @throws java.lang.IllegalArgumentException if the name is null */ - private boolean removeProperty(final String name) { + private boolean removeProperty(final String name, final boolean allowRemovalOfRequiredProperties) { if (null == name) { throw new IllegalArgumentException("Name can not be null"); } final PropertyDescriptor descriptor = getComponent().getPropertyDescriptor(name); String value = null; - if (!descriptor.isRequired() && (value = properties.remove(descriptor)) != null) { + + final boolean allowRemoval = allowRemovalOfRequiredProperties || !descriptor.isRequired(); + if (allowRemoval && (value = properties.remove(descriptor)) != null) { if (descriptor.getControllerServiceDefinition() != null) { if (value != null) { @@ -541,6 +544,7 @@ public abstract class AbstractConfiguredComponent implements ConfigurableCompone } } + @Override public ComponentVariableRegistry getVariableRegistry() { return this.variableRegistry; } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java index 940ac21adb..b0f65a7a28 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java @@ -50,7 +50,11 @@ public interface ConfiguredComponent extends ComponentAuthorizable { public void setAnnotationData(String data); - public void setProperties(Map properties); + public default void setProperties(Map properties) { + setProperties(properties, false); + } + + public void setProperties(Map properties, boolean allowRemovalOfRequiredProperties); public Map getProperties(); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java index baf02bc4af..15f2b5fa57 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java @@ -3925,7 +3925,9 @@ public final class StandardProcessGroup implements ProcessGroup { service.setAnnotationData(proposed.getAnnotationData()); service.setComments(proposed.getComments()); service.setName(proposed.getName()); - service.setProperties(populatePropertiesMap(service.getProperties(), proposed.getProperties(), proposed.getPropertyDescriptors(), service.getProcessGroup())); + + final Map properties = populatePropertiesMap(service.getProperties(), proposed.getProperties(), proposed.getPropertyDescriptors(), service.getProcessGroup()); + service.setProperties(properties, true); if (!isEqual(service.getBundleCoordinate(), proposed.getBundle())) { final BundleCoordinate newBundleCoordinate = toCoordinate(proposed.getBundle()); @@ -4045,7 +4047,9 @@ public final class StandardProcessGroup implements ProcessGroup { processor.setExecutionNode(ExecutionNode.valueOf(proposed.getExecutionNode())); processor.setName(proposed.getName()); processor.setPenalizationPeriod(proposed.getPenaltyDuration()); - processor.setProperties(populatePropertiesMap(processor.getProperties(), proposed.getProperties(), proposed.getPropertyDescriptors(), processor.getProcessGroup())); + + final Map properties = populatePropertiesMap(processor.getProperties(), proposed.getProperties(), proposed.getPropertyDescriptors(), processor.getProcessGroup()); + processor.setProperties(properties, true); processor.setRunDuration(proposed.getRunDurationMillis(), TimeUnit.MILLISECONDS); processor.setScheduldingPeriod(proposed.getSchedulingPeriod()); processor.setSchedulingStrategy(SchedulingStrategy.valueOf(proposed.getSchedulingStrategy()));