NIFI-6382 Fix verifyUpdate for parameter contexts to account for deletions

This closes #3661.

Signed-off-by: Mark Payne <markap14@hotmail.com>
This commit is contained in:
Bryan Bende 2019-08-20 14:12:18 -04:00 committed by Mark Payne
parent 59734dad88
commit b78aeb67a1

View File

@ -150,21 +150,27 @@ public class StandardParameterContextDAO implements ParameterContextDAO {
final ParameterReferenceManager referenceManager = currentContext.getParameterReferenceManager();
for (final ProcessorNode processor : referenceManager.getProcessorsReferencing(currentContext, parameterName)) {
verifyParameterUpdate(parameterName, processor, parameterDto.getSensitive(), currentContext.getName(), verifyComponentStates, processor.isRunning(), "Processor that is running");
verifyParameterUpdate(parameterDto, processor, currentContext.getName(), verifyComponentStates, processor.isRunning(), "Processor that is running");
}
for (final ControllerServiceNode serviceNode : referenceManager.getControllerServicesReferencing(currentContext, parameterName)) {
verifyParameterUpdate(parameterName, serviceNode, parameterDto.getSensitive(), currentContext.getName(), verifyComponentStates,
verifyParameterUpdate(parameterDto, serviceNode, currentContext.getName(), verifyComponentStates,
serviceNode.getState() != ControllerServiceState.DISABLED, "Controller Service that is enabled");
}
}
}
private void verifyParameterUpdate(final String parameterName, final ComponentNode component, final Boolean parameterSensitive, final String contextName,
private void verifyParameterUpdate(final ParameterDTO parameterDto, final ComponentNode component, final String contextName,
final boolean verifyComponentStates, final boolean active, final String activeExplanation) {
final String parameterName = parameterDto.getName();
final Boolean parameterSensitive = parameterDto.getSensitive();
final boolean parameterDeletion = parameterDto.getDescription() == null && parameterDto.getSensitive() == null && parameterDto.getValue() == null;
// For any parameter that is added or modified, we need to ensure that the new configuration will not result in a Sensitive Parameter being referenced by a non-Sensitive Property
// or a Non-Sensitive Parameter being referenced by a Sensitive Property.
// Additionally, if 'verifyComponentStates', we must ensure that any component that references a value that is to be updated is stopped (if a processor) or disabled (if a controller service)
// Additionally, if 'verifyComponentStates' or parameter is being deleted, we must ensure that any component that references a value that is to be updated
// is stopped (if a processor) or disabled (if a controller service).
for (final Map.Entry<PropertyDescriptor, PropertyConfiguration> entry : component.getProperties().entrySet()) {
final PropertyConfiguration configuration = entry.getValue();
if (configuration == null) {
@ -174,17 +180,17 @@ public class StandardParameterContextDAO implements ParameterContextDAO {
for (final ParameterReference reference : configuration.getParameterReferences()) {
final String referencedParameterName = reference.getParameterName();
if (referencedParameterName.equals(parameterName)) {
if (entry.getKey().isSensitive() && !Boolean.TRUE.equals(parameterSensitive)) {
if (entry.getKey().isSensitive() && !parameterDeletion && !Boolean.TRUE.equals(parameterSensitive)) {
throw new IllegalStateException("Cannot update Parameter Context " + contextName + " because the update would add a Non-Sensitive Parameter " +
"named '" + parameterName + "' but this Parameter already is referenced by a Sensitive Property.");
}
if (!entry.getKey().isSensitive() && Boolean.TRUE.equals(parameterSensitive)) {
if (!entry.getKey().isSensitive() && !parameterDeletion && Boolean.TRUE.equals(parameterSensitive)) {
throw new IllegalStateException("Cannot update Parameter Context " + contextName + " because the update would add a Sensitive Parameter named " +
"'" + parameterName + "' but this Parameter already is referenced by a Non-Sensitive Property.");
}
if (verifyComponentStates && active) {
if (active && (verifyComponentStates || parameterDeletion)) {
throw new IllegalStateException("Cannot update Parameter Context " + contextName + " because it has Parameters that are being referenced by a " +
activeExplanation + ".");
}