This is an automated email from the ASF dual-hosted git repository. joewitt pushed a commit to branch support/nifi-1.11.x in repository https://gitbox.apache.org/repos/asf/nifi.git
commit ca27a6c5490e6f4473f8421cdfd16a024adc15fe Author: Mark Bean <[email protected]> AuthorDate: Fri Mar 6 17:18:09 2020 +0000 NIFI-7231: move controller service validation out of synchronized block for enabling This closes #4118. Signed-off-by: Mark Payne <[email protected]> --- .../nifi/components/validation/ValidationState.java | 4 ++++ .../nifi/controller/service/ServiceStateTransition.java | 16 ---------------- .../service/StandardControllerServiceNode.java | 9 ++++++++- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/components/validation/ValidationState.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/components/validation/ValidationState.java index 17b3ff2..0f8f57f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/components/validation/ValidationState.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/components/validation/ValidationState.java @@ -37,4 +37,8 @@ public class ValidationState { public Collection<ValidationResult> getValidationErrors() { return validationErrors; } + + public String toString() { + return status.toString(); + } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java index 28f77b1..a2cd537 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java @@ -17,8 +17,6 @@ package org.apache.nifi.controller.service; -import org.apache.nifi.controller.ComponentNode; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -31,15 +29,10 @@ public class ServiceStateTransition { private final List<CompletableFuture<?>> enabledFutures = new ArrayList<>(); private final List<CompletableFuture<?>> disabledFutures = new ArrayList<>(); - private final ControllerServiceNode serviceNode; private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); private final Lock writeLock = rwLock.writeLock(); private final Lock readLock = rwLock.readLock(); - public ServiceStateTransition(final ControllerServiceNode serviceNode) { - this.serviceNode = serviceNode; - } - public boolean transitionToEnabling(final ControllerServiceState expectedState, final CompletableFuture<?> enabledFuture) { writeLock.lock(); try { @@ -64,8 +57,6 @@ public class ServiceStateTransition { state = ControllerServiceState.ENABLED; - validateReferences(serviceNode); - enabledFutures.forEach(future -> future.complete(null)); return true; } finally { @@ -73,13 +64,6 @@ public class ServiceStateTransition { } } - private void validateReferences(final ControllerServiceNode service) { - final List<ComponentNode> referencingComponents = service.getReferences().findRecursiveReferences(ComponentNode.class); - for (final ComponentNode component : referencingComponents) { - component.performValidation(); - } - } - public boolean transitionToDisabling(final ControllerServiceState expectedState, final CompletableFuture<?> disabledFuture) { writeLock.lock(); try { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java index da08c8c..e75fb3c 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java @@ -111,7 +111,7 @@ public class StandardControllerServiceNode extends AbstractComponentNode impleme this.serviceProvider = serviceProvider; this.active = new AtomicBoolean(); setControllerServiceAndProxy(implementation, proxiedControllerService, invocationHandler); - stateTransition = new ServiceStateTransition(this); + stateTransition = new ServiceStateTransition(); } @Override @@ -436,6 +436,7 @@ public class StandardControllerServiceNode extends AbstractComponentNode impleme synchronized (active) { shouldEnable = active.get() && stateTransition.enable(); // Transitioning the state to ENABLED will complete our future. } + validateReferences(); if (!shouldEnable) { LOG.info("Disabling service {} after it has been enabled due to disable action being initiated.", service); @@ -474,6 +475,12 @@ public class StandardControllerServiceNode extends AbstractComponentNode impleme return future; } + private void validateReferences() { + final List<ComponentNode> referencingComponents = getReferences().findRecursiveReferences(ComponentNode.class); + for (final ComponentNode component : referencingComponents) { + component.performValidation(); + } + } /** * Will atomically disable this service by invoking its @OnDisabled operation.
