From 1e75f8c78908546fe287e8f8d3c03524f5e58e8f Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Mon, 9 Jul 2018 10:01:37 -0400 Subject: [PATCH] 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 This closes #2867 --- .../service/StandardControllerServiceNode.java | 2 +- .../service/StandardControllerServiceProvider.java | 12 +++++++++++- .../service/StandardControllerServiceProviderIT.java | 7 ++++--- 3 files changed, 16 insertions(+), 5 deletions(-) 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 df17a8d1fa..2323f0268e 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 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); } } 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 b8b3e74554..3e212c0071 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); } } 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 d2784ca5f8..e95694426f 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.