You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by bb...@apache.org on 2017/05/03 15:04:26 UTC

nifi git commit: NIFI-3782: - Ensuring referenced Controller Services are not included in copy/paste requests when the Processor is located in a sub group.

Repository: nifi
Updated Branches:
  refs/heads/master 54d47c7f7 -> ce233bdbb


NIFI-3782: - Ensuring referenced Controller Services are not included in copy/paste requests when the Processor is located in a sub group.

This closes #1740.

Signed-off-by: Bryan Bende <bb...@apache.org>


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

Branch: refs/heads/master
Commit: ce233bdbbb78f55ff2c41681bdb709c3e3ec0bf9
Parents: 54d47c7
Author: Matt Gilman <ma...@gmail.com>
Authored: Wed May 3 10:32:07 2017 -0400
Committer: Bryan Bende <bb...@apache.org>
Committed: Wed May 3 11:04:08 2017 -0400

----------------------------------------------------------------------
 .../org/apache/nifi/web/util/SnippetUtils.java  | 45 ++++++++++++--------
 1 file changed, 27 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/ce233bdb/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java
index 83a2861..ff8b566 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java
@@ -18,21 +18,6 @@ package org.apache.nifi.web.util;
 
 
 
-import java.nio.charset.StandardCharsets;
-import java.security.SecureRandom;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
 import org.apache.commons.lang3.StringUtils;
 import org.apache.nifi.authorization.AccessPolicy;
 import org.apache.nifi.authorization.RequestAction;
@@ -77,6 +62,21 @@ import org.apache.nifi.web.dao.AccessPolicyDAO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.nio.charset.StandardCharsets;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
 /**
  * Template utilities.
  */
@@ -247,7 +247,12 @@ public final class SnippetUtils {
                 final ProcessGroupDTO childGroupDto = dtoFactory.createProcessGroupDto(childGroup, recurse);
                 processGroups.add(childGroupDto);
 
-                addControllerServices(childGroup, childGroupDto, allServicesReferenced, contentsByGroup, processGroup.getIdentifier());
+                // maintain a listing of visited groups starting with each group in the snippet. this is used to determine
+                // whether a referenced controller service should be included in the resulting snippet. if the service is
+                // defined at groupId or one of it's ancestors, its considered outside of this snippet and will only be included
+                // when the includeControllerServices is set to true. this happens above when considering the processors in this snippet
+                final Set<String> visitedGroupIds = new HashSet<>();
+                addControllerServices(childGroup, childGroupDto, allServicesReferenced, includeControllerServices, visitedGroupIds, contentsByGroup, processGroup.getIdentifier());
             }
         }
 
@@ -306,7 +311,7 @@ public final class SnippetUtils {
      * @param highestGroupId the UUID of the 'highest' process group in the snippet
      */
     private void addControllerServices(final ProcessGroup group, final ProcessGroupDTO dto, final Set<ControllerServiceDTO> allServicesReferenced,
-        final Map<String, FlowSnippetDTO> contentsByGroup, final String highestGroupId) {
+        final boolean includeControllerServices, final Set<String> visitedGroupIds, final Map<String, FlowSnippetDTO> contentsByGroup, final String highestGroupId) {
 
         final FlowSnippetDTO contents = dto.getContents();
         contentsByGroup.put(dto.getId(), contents);
@@ -314,11 +319,15 @@ public final class SnippetUtils {
             return;
         }
 
+        // include this group in the ancestry for this snippet, services only get included if the includeControllerServices
+        // flag is set or if the service is defined within this groups hierarchy within the snippet
+        visitedGroupIds.add(group.getIdentifier());
 
         for (final ProcessorNode procNode : group.getProcessors()) {
             // Include all referenced services that are not already included in this snippet.
             getControllerServices(procNode.getProperties()).stream()
                 .filter(svc -> allServicesReferenced.add(svc))
+                .filter(svc -> includeControllerServices || visitedGroupIds.contains(svc.getParentGroupId()))
                 .forEach(svc -> {
                     final String svcGroupId = svc.getParentGroupId();
                     final String destinationGroupId = contentsByGroup.containsKey(svcGroupId) ? svcGroupId : highestGroupId;
@@ -346,7 +355,7 @@ public final class SnippetUtils {
                 continue;
             }
 
-            addControllerServices(childGroup, childDto, allServicesReferenced, contentsByGroup, highestGroupId);
+            addControllerServices(childGroup, childDto, allServicesReferenced, includeControllerServices, visitedGroupIds, contentsByGroup, highestGroupId);
         }
     }