Return-Path: X-Original-To: apmail-nifi-commits-archive@minotaur.apache.org Delivered-To: apmail-nifi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E26DA179A1 for ; Fri, 23 Jan 2015 15:36:24 +0000 (UTC) Received: (qmail 26391 invoked by uid 500); 23 Jan 2015 15:36:25 -0000 Delivered-To: apmail-nifi-commits-archive@nifi.apache.org Received: (qmail 26344 invoked by uid 500); 23 Jan 2015 15:36:25 -0000 Mailing-List: contact commits-help@nifi.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.incubator.apache.org Delivered-To: mailing list commits@nifi.incubator.apache.org Received: (qmail 26334 invoked by uid 99); 23 Jan 2015 15:36:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Jan 2015 15:36:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 23 Jan 2015 15:36:01 +0000 Received: (qmail 26170 invoked by uid 99); 23 Jan 2015 15:35:58 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Jan 2015 15:35:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C7CBFE0393; Fri, 23 Jan 2015 15:35:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: markap14@apache.org To: commits@nifi.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-nifi git commit: NIFI-4: Fixed issue with lifecycle of Controller Services Date: Fri, 23 Jan 2015 15:35:57 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-nifi Updated Branches: refs/heads/annotations 413a0b22a -> a4e4af7cb 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/annotations Commit: a4e4af7cba686ee3929d4515df77ea26b408c3d9 Parents: 413a0b2 Author: Mark Payne Authored: Fri Jan 23 10:35:41 2015 -0500 Committer: Mark Payne 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. *