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 <bbende@apache.org>
This commit is contained in:
Mark Payne 2018-01-16 12:36:52 -05:00 committed by Bryan Bende
parent 7e29103995
commit 28e1bcc9d0
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
3 changed files with 19 additions and 7 deletions

View File

@ -151,7 +151,7 @@ public abstract class AbstractConfiguredComponent implements ConfigurableCompone
}
@Override
public void setProperties(Map<String, String> properties) {
public void setProperties(final Map<String, String> 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;
}

View File

@ -50,7 +50,11 @@ public interface ConfiguredComponent extends ComponentAuthorizable {
public void setAnnotationData(String data);
public void setProperties(Map<String, String> properties);
public default void setProperties(Map<String, String> properties) {
setProperties(properties, false);
}
public void setProperties(Map<String, String> properties, boolean allowRemovalOfRequiredProperties);
public Map<PropertyDescriptor, String> getProperties();

View File

@ -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<String, String> 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<String, String> 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()));