You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2017/05/25 17:32:18 UTC

[2/2] nifi git commit: NIFI-3972: This closes #1855. When enabling Controller Services on startup, wait until service is enabled (or until 30 seconds elapses, whichever comes first) before returning. This avoids having Service A depend on Service B and t

NIFI-3972: This closes #1855. When enabling Controller Services on startup, wait until service is enabled (or until 30 seconds elapses, whichever comes first) before returning. This avoids having Service A depend on Service B and then attempting to start Service A before Service B is fully enabled

Signed-off-by: joewitt <jo...@apache.org>


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

Branch: refs/heads/master
Commit: 36911957dce87d37e2342bec5d25a934583852d8
Parents: eb25c85
Author: Mark Payne <ma...@hotmail.com>
Authored: Thu May 25 12:36:18 2017 -0400
Committer: joewitt <jo...@apache.org>
Committed: Thu May 25 13:32:02 2017 -0400

----------------------------------------------------------------------
 .../StandardControllerServiceProvider.java      | 30 ++++++++++++++++----
 1 file changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/36911957/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 4c6c3a3..2d006cc 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
@@ -24,12 +24,14 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -339,6 +341,7 @@ public class StandardControllerServiceProvider implements ControllerServiceProvi
             for (ControllerServiceNode requiredService : requiredServices) {
                 if (!requiredService.isActive() && !serviceNodes.contains(requiredService)) {
                     shouldStart = false;
+                    logger.debug("Will not start {} because required service {} is not active and is not part of the collection of things to start", serviceNodes, requiredService);
                 }
             }
         }
@@ -347,7 +350,15 @@ public class StandardControllerServiceProvider implements ControllerServiceProvi
             for (ControllerServiceNode controllerServiceNode : serviceNodes) {
                 try {
                     if (!controllerServiceNode.isActive()) {
-                        this.enableControllerServiceDependenciesFirst(controllerServiceNode);
+                        final Future<Void> future = enableControllerServiceDependenciesFirst(controllerServiceNode);
+
+                        try {
+                            future.get(30, TimeUnit.SECONDS);
+                            logger.debug("Successfully enabled {}; service state = {}", controllerServiceNode, controllerServiceNode.getState());
+                        } catch (final Exception e) {
+                            logger.warn("Failed to enable service {}", controllerServiceNode, e);
+                            // Nothing we can really do. Will attempt to enable this service anyway.
+                        }
                     }
                 } catch (Exception e) {
                     logger.error("Failed to enable " + controllerServiceNode, e);
@@ -361,26 +372,33 @@ public class StandardControllerServiceProvider implements ControllerServiceProvi
     }
 
     private Future<Void> enableControllerServiceDependenciesFirst(ControllerServiceNode serviceNode) {
-        final List<Future<Void>> futures = new ArrayList<>();
+        final Map<ControllerServiceNode, Future<Void>> futures = new HashMap<>();
 
         for (ControllerServiceNode depNode : serviceNode.getRequiredControllerServices()) {
             if (!depNode.isActive()) {
-                futures.add(this.enableControllerServiceDependenciesFirst(depNode));
+                logger.debug("Before enabling {}, will enable dependent Controller Service {}", serviceNode, depNode);
+                futures.put(depNode, this.enableControllerServiceDependenciesFirst(depNode));
             }
         }
 
         if (logger.isDebugEnabled()) {
-            logger.debug("Enabling " + serviceNode);
+            logger.debug("All dependent services for {} have now begun enabling. Will wait for them to complete", serviceNode);
         }
 
-        for (final Future<Void> future : futures) {
+        for (final Map.Entry<ControllerServiceNode, Future<Void>> entry : futures.entrySet()) {
+            final ControllerServiceNode dependentService = entry.getKey();
+            final Future<Void> future = entry.getValue();
+
             try {
-                future.get();
+                future.get(30, TimeUnit.SECONDS);
+                logger.debug("Successfully enabled dependent service {}; service state = {}", dependentService, dependentService.getState());
             } catch (final Exception e) {
+                logger.error("Failed to enable service {}, so may be unable to enable {}", dependentService, serviceNode, e);
                 // Nothing we can really do. Will attempt to enable this service anyway.
             }
         }
 
+        logger.debug("All dependent services have been enabled for {}; will now start service itself", serviceNode);
         return this.enableControllerService(serviceNode);
     }