You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2015/01/26 15:20:08 UTC

[44/48] incubator-nifi git commit: NIFI-4: Fixed issue with lifecycle of Controller Services

NIFI-4: Fixed issue with lifecycle of Controller Services


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

Branch: refs/heads/NIFI-250
Commit: a4e4af7cba686ee3929d4515df77ea26b408c3d9
Parents: 413a0b2
Author: Mark Payne <ma...@hotmail.com>
Authored: Fri Jan 23 10:35:41 2015 -0500
Committer: Mark Payne <ma...@hotmail.com>
Committed: Fri Jan 23 10:35:41 2015 -0500

----------------------------------------------------------------------
 .../cluster/manager/impl/WebClusterManager.java | 12 ++++++++
 .../service/ControllerServiceProvider.java      | 13 ++++++++
 .../apache/nifi/controller/FlowController.java  |  8 ++---
 .../scheduling/StandardProcessScheduler.java    | 31 --------------------
 .../service/ControllerServiceLoader.java        |  9 ++----
 .../service/StandardControllerServiceNode.java  |  1 +
 .../StandardControllerServiceProvider.java      | 27 +++++++++++++++++
 .../nifi/web/controller/ControllerFacade.java   | 10 +++++++
 8 files changed, 70 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
index cec9b74..656759a 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
@@ -1320,6 +1320,18 @@ public class WebClusterManager implements HttpClusterManager, ProtocolHandler, C
         controllerServiceProvider.removeControllerService(serviceNode);
     }
     
+
+    @Override
+    public void enableControllerService(final ControllerServiceNode serviceNode) {
+        controllerServiceProvider.enableControllerService(serviceNode);
+    }
+    
+    @Override
+    public void disableControllerService(final ControllerServiceNode serviceNode) {
+        controllerServiceProvider.disableControllerService(serviceNode);
+    }
+    
+    
     /**
      * Handle a bulletins message.
      *

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java
index 03ed779..5f2fc2e 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java
@@ -53,4 +53,17 @@ public interface ControllerServiceProvider extends ControllerServiceLookup {
      * @throws IllegalStateException if the controller service is not disabled or is not a part of this flow
      */
     void removeControllerService(ControllerServiceNode serviceNode);
+    
+    /**
+     * Enables the given controller service that it can be used by other components
+     * @param serviceNode
+     */
+    void enableControllerService(ControllerServiceNode serviceNode);
+    
+    /**
+     * Disables the given controller service so that it cannot be used by other components. This allows
+     * configuration to be updated or allows service to be removed.
+     * @param serviceNode
+     */
+    void disableControllerService(ControllerServiceNode serviceNode);
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
index 1b7a3c0..7cb2874 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
@@ -2569,16 +2569,16 @@ public class FlowController implements EventAccess, ControllerServiceProvider, H
         processScheduler.disableReportingTask(reportingTaskNode);
     }
     
+    @Override
     public void enableControllerService(final ControllerServiceNode serviceNode) {
         serviceNode.verifyCanEnable();
-        
-        processScheduler.enableControllerService(serviceNode);
+        controllerServiceProvider.enableControllerService(serviceNode);
     }
     
+    @Override
     public void disableControllerService(final ControllerServiceNode serviceNode) {
         serviceNode.verifyCanDisable();
-        
-        processScheduler.disableControllerService(serviceNode);
+        controllerServiceProvider.disableControllerService(serviceNode);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
index 0653b03..1627994 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
@@ -581,37 +581,6 @@ public final class StandardProcessScheduler implements ProcessScheduler {
         }
     }
 
-    public synchronized void enableControllerService(final ControllerServiceNode serviceNode) {
-        if ( !serviceNode.isDisabled() ) {
-            throw new IllegalStateException("Controller Service cannot be enabled because it is not disabled");
-        }
-
-        // we set the service to enabled before invoking the @OnEnabled methods. We do this because it must be
-        // done in this order for disabling (serviceNode.setDisabled(true) will throw Exceptions if the service
-        // is currently known to be in use) and we want to be consistent with the ordering of calling setDisabled
-        // before annotated methods.
-        serviceNode.setDisabled(false);
-        
-        try (final NarCloseable x = NarCloseable.withNarLoader()) {
-            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnEnabled.class, serviceNode.getControllerServiceImplementation());
-        }
-    }
-    
-    public synchronized void disableControllerService(final ControllerServiceNode serviceNode) {
-        if ( serviceNode.isDisabled() ) {
-            throw new IllegalStateException("Controller Service cannot be disabled because it is already disabled");
-        }
-
-        // We must set the service to disabled before we invoke the OnDisabled methods because the service node
-        // can throw Exceptions if we attempt to disable the service while it's known to be in use.
-        serviceNode.setDisabled(true);
-        
-        try (final NarCloseable x = NarCloseable.withNarLoader()) {
-            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnDisabled.class, serviceNode.getControllerServiceImplementation());
-        }
-    }
-    
-    
     @Override
     public boolean isScheduled(final Object scheduled) {
         final ScheduleState scheduleState = scheduleStates.get(scheduled);

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ControllerServiceLoader.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ControllerServiceLoader.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ControllerServiceLoader.java
index 9fec307..db44b5f 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ControllerServiceLoader.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ControllerServiceLoader.java
@@ -25,9 +25,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
@@ -36,11 +34,10 @@ import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 
-import org.apache.nifi.util.file.FileUtils;
-import org.apache.nifi.util.DomUtils;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.nifi.util.DomUtils;
+import org.apache.nifi.util.file.FileUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -139,7 +136,7 @@ public class ControllerServiceLoader {
                     }
 
                     services.add(serviceNode);
-                    serviceNode.setDisabled(false);
+                    provider.enableControllerService(serviceNode);
                 }
             }
         } catch (SAXException | ParserConfigurationException sxe) {

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/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/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
index 4681293..741caec 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
@@ -154,6 +154,7 @@ public class StandardControllerServiceNode extends AbstractConfiguredComponent i
         return removed;
     }
     
+    @SuppressWarnings("deprecation")
     private void onConfigured() {
         try (final NarCloseable x = NarCloseable.withNarLoader()) {
             final ConfigurationContext configContext = new StandardConfigurationContext(this, serviceProvider);

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/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/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
index cc7a18a..a40e43e 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java
@@ -31,6 +31,8 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.nifi.annotation.lifecycle.OnAdded;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
 import org.apache.nifi.annotation.lifecycle.OnRemoved;
 import org.apache.nifi.controller.ConfigurationContext;
 import org.apache.nifi.controller.ControllerService;
@@ -165,6 +167,31 @@ public class StandardControllerServiceProvider implements ControllerServiceProvi
             }
         }
     }
+    
+    @Override
+    public void enableControllerService(final ControllerServiceNode serviceNode) {
+        serviceNode.verifyCanEnable();
+        
+        try (final NarCloseable x = NarCloseable.withNarLoader()) {
+            final ConfigurationContext configContext = new StandardConfigurationContext(serviceNode, this);
+            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnEnabled.class, serviceNode.getControllerServiceImplementation(), configContext);
+        }
+        
+        serviceNode.setDisabled(false);
+    }
+    
+    @Override
+    public void disableControllerService(final ControllerServiceNode serviceNode) {
+        serviceNode.verifyCanDisable();
+
+        // We must set the service to disabled before we invoke the OnDisabled methods because the service node
+        // can throw Exceptions if we attempt to disable the service while it's known to be in use.
+        serviceNode.setDisabled(true);
+        
+        try (final NarCloseable x = NarCloseable.withNarLoader()) {
+            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnDisabled.class, serviceNode.getControllerServiceImplementation());
+        }
+    }
 
     @Override
     public ControllerService getControllerService(final String serviceIdentifier) {

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a4e4af7c/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java
index c97d38c..efdfbb1 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java
@@ -412,6 +412,16 @@ public class ControllerFacade implements ControllerServiceProvider {
         return flowController.isControllerServiceEnabled(serviceIdentifier);
     }
 
+    @Override
+    public void enableControllerService(final ControllerServiceNode serviceNode) {
+        flowController.enableControllerService(serviceNode);
+    }
+    
+    @Override
+    public void disableControllerService(ControllerServiceNode serviceNode) {
+        flowController.disableControllerService(serviceNode);
+    }
+    
     /**
      * Gets the status of this controller.
      *