NIFI-250: Incorporate new logic for controller service state

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

Branch: refs/heads/NIFI-250
Commit: f246565f7e5344db91f731e003c7e35e1d7cbe95
Parents: 852cc60
Author: Mark Payne <[email protected]>
Authored: Thu Feb 19 15:04:13 2015 -0500
Committer: Mark Payne <[email protected]>
Committed: Thu Feb 19 15:04:13 2015 -0500

----------------------------------------------------------------------
 .../apache/nifi/controller/FlowFromDOMFactory.java |  5 ++++-
 .../nifi/controller/StandardFlowSynchronizer.java  | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/f246565f/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowFromDOMFactory.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowFromDOMFactory.java
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowFromDOMFactory.java
index 2a44176..6e17208 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowFromDOMFactory.java
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowFromDOMFactory.java
@@ -26,6 +26,7 @@ import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.nifi.connectable.Size;
+import org.apache.nifi.controller.service.ControllerServiceState;
 import org.apache.nifi.encrypt.StringEncryptor;
 import org.apache.nifi.groups.RemoteProcessGroupPortDescriptor;
 import org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor;
@@ -86,7 +87,9 @@ public class FlowFromDOMFactory {
        dto.setName(getString(element, "name"));
        dto.setComments(getString(element, "comment"));
        dto.setType(getString(element, "class"));
-       dto.setEnabled(getBoolean(element, "enabled"));
+
+       final boolean enabled = getBoolean(element, "enabled");
+       dto.setState(enabled ? ControllerServiceState.ENABLED.name() : 
ControllerServiceState.DISABLED.name());
        
         dto.setProperties(getProperties(element, encryptor));
         dto.setAnnotationData(getString(element, "annotationData"));

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/f246565f/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
index 2508b5b..633d58b 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
@@ -54,6 +54,7 @@ import 
org.apache.nifi.controller.exception.ProcessorInstantiationException;
 import org.apache.nifi.controller.label.Label;
 import 
org.apache.nifi.controller.reporting.ReportingTaskInstantiationException;
 import org.apache.nifi.controller.service.ControllerServiceNode;
+import org.apache.nifi.controller.service.ControllerServiceState;
 import org.apache.nifi.encrypt.StringEncryptor;
 import org.apache.nifi.events.BulletinFactory;
 import org.apache.nifi.fingerprint.FingerprintException;
@@ -361,7 +362,9 @@ public class StandardFlowSynchronizer implements 
FlowSynchronizer {
         }
 
         if ( autoResumeState ) {
-               if ( Boolean.TRUE.equals(dto.getEnabled()) ) {
+            final ControllerServiceState state = 
ControllerServiceState.valueOf(dto.getState());
+            final boolean enable = (state == ControllerServiceState.ENABLED || 
state == ControllerServiceState.ENABLING);
+               if (enable) {
                        try {
                                controller.enableControllerService(node);
                        } catch (final Exception e) {
@@ -380,10 +383,16 @@ public class StandardFlowSynchronizer implements 
FlowSynchronizer {
     private void updateControllerService(final FlowController controller, 
final Element controllerServiceElement, final StringEncryptor encryptor) {
        final ControllerServiceDTO dto = 
FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor);
        
-       final boolean enabled = 
controller.isControllerServiceEnabled(dto.getId());
-       if (dto.getEnabled() && !enabled) {
+       final ControllerServiceState state = 
ControllerServiceState.valueOf(dto.getState());
+        final boolean dtoEnabled = (state == ControllerServiceState.ENABLED || 
state == ControllerServiceState.ENABLING);
+        
+        final ControllerServiceNode serviceNode = 
controller.getControllerServiceNode(dto.getId());
+        final ControllerServiceState serviceState = serviceNode.getState();
+        final boolean serviceEnabled = (serviceState == 
ControllerServiceState.ENABLED || state == ControllerServiceState.ENABLING);
+        
+       if (dtoEnabled && !serviceEnabled) {
                
controller.enableControllerService(controller.getControllerServiceNode(dto.getId()));
-       } else if (dto.getEnabled() == Boolean.FALSE && enabled) {
+       } else if (!dtoEnabled && serviceEnabled) {
                
controller.disableControllerService(controller.getControllerServiceNode(dto.getId()));
        }
     }

Reply via email to