Repository: nifi
Updated Branches:
  refs/heads/master 0ff851806 -> 1e75f8c78


NIFI-5394: Ensure that we wait for service to be fully enabled when enabling a 
group, before moving on to the next in the list

Signed-off-by: Matthew Burgess <[email protected]>

This closes #2867


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/1e75f8c7
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/1e75f8c7
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/1e75f8c7

Branch: refs/heads/master
Commit: 1e75f8c78908546fe287e8f8d3c03524f5e58e8f
Parents: 0ff8518
Author: Mark Payne <[email protected]>
Authored: Mon Jul 9 10:01:37 2018 -0400
Committer: Matthew Burgess <[email protected]>
Committed: Mon Jul 9 12:15:23 2018 -0400

----------------------------------------------------------------------
 .../service/StandardControllerServiceNode.java          |  2 +-
 .../service/StandardControllerServiceProvider.java      | 12 +++++++++++-
 .../service/StandardControllerServiceProviderIT.java    |  7 ++++---
 3 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/1e75f8c7/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
----------------------------------------------------------------------
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 df17a8d..2323f02 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
@@ -336,7 +336,7 @@ public class StandardControllerServiceNode extends 
AbstractComponentNode impleme
 
         final Collection<ValidationResult> validationErrors = 
getValidationErrors(ignoredReferences);
         if (ignoredReferences != null && !validationErrors.isEmpty()) {
-            throw new IllegalStateException("Controller Service with ID " + 
getIdentifier() + " cannot be enabled because it is not currently valid");
+            throw new IllegalStateException("Controller Service with ID " + 
getIdentifier() + " cannot be enabled because it is not currently valid: " + 
validationErrors);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/nifi/blob/1e75f8c7/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
index b8b3e74..3e212c0 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
@@ -33,6 +33,7 @@ import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
@@ -747,7 +748,16 @@ public class StandardControllerServiceProvider implements 
ControllerServiceProvi
         for (final ControllerServiceNode nodeToEnable : recursiveReferences) {
             if (!nodeToEnable.isActive()) {
                 logger.debug("Enabling {} because it references {}", 
nodeToEnable, serviceNode);
-                enableControllerService(nodeToEnable);
+                final Future<?> enableFuture = 
enableControllerService(nodeToEnable);
+                try {
+                    enableFuture.get();
+                } catch (final ExecutionException ee) {
+                    throw new IllegalStateException("Failed to enable 
Controller Service " + nodeToEnable, ee.getCause());
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                    throw new IllegalStateException("Interrupted while 
enabling Controller Service");
+                }
+
                 updated.add(nodeToEnable);
             }
         }

http://git-wip-us.apache.org/repos/asf/nifi/blob/1e75f8c7/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
index d2784ca..e956944 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ExecutionException;
 
 import org.apache.nifi.bundle.Bundle;
 import org.apache.nifi.components.state.StateManager;
@@ -90,14 +91,14 @@ public class StandardControllerServiceProviderIT {
      * https://issues.apache.org/jira/browse/NIFI-1143
      */
     @Test(timeout = 120000)
-    public void testConcurrencyWithEnablingReferencingServicesGraph() throws 
InterruptedException {
+    public void testConcurrencyWithEnablingReferencingServicesGraph() throws 
InterruptedException, ExecutionException {
         final StandardProcessScheduler scheduler = new 
StandardProcessScheduler(new FlowEngine(1, "Unit Test", true), null, null, 
stateManagerProvider, niFiProperties);
         for (int i = 0; i < 5000; i++) {
             testEnableReferencingServicesGraph(scheduler);
         }
     }
 
-    public void testEnableReferencingServicesGraph(final 
StandardProcessScheduler scheduler) {
+    public void testEnableReferencingServicesGraph(final 
StandardProcessScheduler scheduler) throws InterruptedException, 
ExecutionException {
         final FlowController controller = Mockito.mock(FlowController.class);
         final ProcessGroup procGroup = new MockProcessGroup(controller);
         
Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
@@ -136,7 +137,7 @@ public class StandardControllerServiceProviderIT {
         setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "2");
         setProperty(serviceNode3, ServiceA.OTHER_SERVICE_2.getName(), "4");
 
-        provider.enableControllerService(serviceNode4);
+        provider.enableControllerService(serviceNode4).get();
         provider.enableReferencingServices(serviceNode4);
 
         // Verify that the services are either ENABLING or ENABLED, and wait 
for all of them to become ENABLED.

Reply via email to