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 2018/07/10 13:57:40 UTC

[1/2] nifi git commit: NIFI-5377: Addressed issue of infinite recursion when enabling/disabling controller services if there is a recursive loop (i.e., Service A references Service B references Service A). This closes #2847

Repository: nifi
Updated Branches:
  refs/heads/master 3ef8b4ab8 -> 35bfc9390


NIFI-5377: Addressed issue of infinite recursion when enabling/disabling controller services if there is a recursive loop (i.e., Service A references Service B references Service A). This closes #2847

Signed-off-by: Matt Gilman <ma...@gmail.com>


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

Branch: refs/heads/master
Commit: 35bfc939011f5289eb65949c41f61fdea1d1b1fa
Parents: 0d07bc4
Author: Mark Payne <ma...@hotmail.com>
Authored: Mon Jul 9 11:50:06 2018 -0400
Committer: Matt Gilman <ma...@gmail.com>
Committed: Tue Jul 10 09:57:13 2018 -0400

----------------------------------------------------------------------
 .../service/ServiceStateTransition.java         |  8 +--
 .../StandardControllerServiceReference.java     | 62 ++++++++------------
 .../nifi/web/StandardNiFiServiceFacade.java     | 13 +---
 3 files changed, 27 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/35bfc939/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java
index 319c18c..2e97c10 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/ServiceStateTransition.java
@@ -19,6 +19,7 @@ package org.apache.nifi.controller.service;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 
 import org.apache.nifi.controller.ComponentNode;
@@ -58,12 +59,9 @@ public class ServiceStateTransition {
     }
 
     private void validateReferences(final ControllerServiceNode service) {
-        for (final ComponentNode component : service.getReferences().getReferencingComponents()) {
+        final List<ComponentNode> referencingComponents = service.getReferences().findRecursiveReferences(ComponentNode.class);
+        for (final ComponentNode component : referencingComponents) {
             component.performValidation();
-
-            if (component instanceof ControllerServiceNode) {
-                validateReferences((ControllerServiceNode) component);
-            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/nifi/blob/35bfc939/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceReference.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceReference.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceReference.java
index 4cb5239..e18e383 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceReference.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceReference.java
@@ -31,8 +31,7 @@ public class StandardControllerServiceReference implements ControllerServiceRefe
     private final ControllerServiceNode referenced;
     private final Set<ComponentNode> components;
 
-    public StandardControllerServiceReference(final ControllerServiceNode referencedService,
-            final Set<ComponentNode> referencingComponents) {
+    public StandardControllerServiceReference(final ControllerServiceNode referencedService, final Set<ComponentNode> referencingComponents) {
         this.referenced = referencedService;
         this.components = new HashSet<>(referencingComponents);
     }
@@ -56,52 +55,30 @@ public class StandardControllerServiceReference implements ControllerServiceRefe
             return ((ProcessorNode) component).isRunning();
         }
 
+        if (component instanceof ControllerServiceNode) {
+            return ((ControllerServiceNode) component).isActive();
+        }
+
         return false;
     }
 
     @Override
     public Set<ComponentNode> getActiveReferences() {
         final Set<ComponentNode> activeReferences = new HashSet<>();
-        final Set<ControllerServiceNode> serviceNodes = new HashSet<>();
 
         for (final ComponentNode component : components) {
-            if (component instanceof ControllerServiceNode) {
-                serviceNodes.add((ControllerServiceNode) component);
-
-                if (((ControllerServiceNode) component).isActive()) {
-                    activeReferences.add(component);
-                }
-            } else if (isRunning(component)) {
+            if (isRunning(component)) {
                 activeReferences.add(component);
             }
         }
 
-        activeReferences.addAll(getActiveIndirectReferences(serviceNodes));
-        return activeReferences;
-    }
-
-    private Set<ComponentNode> getActiveIndirectReferences(final Set<ControllerServiceNode> referencingServices) {
-        if (referencingServices.isEmpty()) {
-            return Collections.emptySet();
-        }
-
-        final Set<ComponentNode> references = new HashSet<>();
-        for (final ControllerServiceNode referencingService : referencingServices) {
-            final Set<ControllerServiceNode> serviceNodes = new HashSet<>();
-            final ControllerServiceReference ref = referencingService.getReferences();
-
-            for (final ComponentNode component : ref.getReferencingComponents()) {
-                if (component instanceof ControllerServiceNode) {
-                    serviceNodes.add((ControllerServiceNode) component);
-                } else if (isRunning(component)) {
-                    references.add(component);
-                }
+        for (final ComponentNode component : findRecursiveReferences(ComponentNode.class)) {
+            if (isRunning(component)) {
+                activeReferences.add(component);
             }
-
-            references.addAll(getActiveIndirectReferences(serviceNodes));
         }
 
-        return references;
+        return activeReferences;
     }
 
 
@@ -111,6 +88,10 @@ public class StandardControllerServiceReference implements ControllerServiceRefe
     }
 
     private <T> List<T> findRecursiveReferences(final ControllerServiceNode referencedNode, final Class<T> componentType) {
+        return findRecursiveReferences(referencedNode, componentType, new HashSet<>());
+    }
+
+    private <T> List<T> findRecursiveReferences(final ControllerServiceNode referencedNode, final Class<T> componentType, final Set<ControllerServiceNode> servicesVisited) {
         final List<T> references = new ArrayList<>();
 
         for (final ComponentNode referencingComponent : referencedNode.getReferences().getReferencingComponents()) {
@@ -122,12 +103,15 @@ public class StandardControllerServiceReference implements ControllerServiceRefe
                 final ControllerServiceNode referencingNode = (ControllerServiceNode) referencingComponent;
 
                 // find components recursively that depend on referencingNode.
-                final List<T> recursive = findRecursiveReferences(referencingNode, componentType);
-
-                // For anything that depends on referencing node, we want to add it to the list, but we know
-                // that it must come after the referencing node, so we first remove any existing occurrence.
-                references.removeAll(recursive);
-                references.addAll(recursive);
+                final boolean added = servicesVisited.add(referencingNode);
+                if (added) {
+                    final List<T> recursive = findRecursiveReferences(referencingNode, componentType, servicesVisited);
+
+                    // For anything that depends on referencing node, we want to add it to the list, but we know
+                    // that it must come after the referencing node, so we first remove any existing occurrence.
+                    references.removeAll(recursive);
+                    references.addAll(recursive);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/nifi/blob/35bfc939/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index 1c96861..700185c 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -2222,17 +2222,6 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
         return entityFactory.createControllerServiceEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
     }
 
-    private Set<ComponentNode> findAllReferencingComponents(final ControllerServiceReference reference) {
-        final Set<ComponentNode> referencingComponents = new HashSet<>(reference.getReferencingComponents());
-
-        for (final ComponentNode referencingComponent : reference.getReferencingComponents()) {
-            if (referencingComponent instanceof ControllerServiceNode) {
-                referencingComponents.addAll(findAllReferencingComponents(((ControllerServiceNode) referencingComponent).getReferences()));
-            }
-        }
-
-        return referencingComponents;
-    }
 
     @Override
     public ControllerServiceReferencingComponentsEntity updateControllerServiceReferencingComponents(
@@ -2257,7 +2246,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
                         }
 
                         // ensure the revision for all referencing components is included regardless of whether they were updated in this request
-                        for (final ComponentNode component : findAllReferencingComponents(updatedReference)) {
+                        for (final ComponentNode component : updatedReference.findRecursiveReferences(ComponentNode.class)) {
                             updatedRevisions.putIfAbsent(component.getIdentifier(), revisionManager.getRevision(component.getIdentifier()));
                         }
 


[2/2] nifi git commit: NIFI-5377 prevent infinite loop if a controller service circular reference exists

Posted by mc...@apache.org.
NIFI-5377 prevent infinite loop if a controller service circular reference exists


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

Branch: refs/heads/master
Commit: 0d07bc495118889aaf28a8d4bcb7e32796c99b99
Parents: 3ef8b4a
Author: Mark Bean <ma...@gmail.com>
Authored: Fri Jul 6 12:29:00 2018 +0000
Committer: Matt Gilman <ma...@gmail.com>
Committed: Tue Jul 10 09:57:13 2018 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/0d07bc49/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index a781442..1c96861 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -2282,9 +2282,9 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
             if (component instanceof ControllerServiceNode) {
                 final ControllerServiceNode node = (ControllerServiceNode) component;
                 if (!visited.contains(node)) {
+                    visited.add(node);
                     findControllerServiceReferencingComponentIdentifiers(node.getReferences(), visited);
                 }
-                visited.add(node);
             }
         }
     }