From f702f808a70929980f862ef62c2359b73f5e6b6b Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Wed, 3 Jan 2018 15:29:39 -0500 Subject: [PATCH] NIFI-4436: Fixed bug that caused a Process Group to be 'dirty' if a processor that was referencing a non-existent controller service is updated to reference an externally available controller service Signed-off-by: Matt Gilman --- .../nifi/controller/StandardFlowSynchronizer.java | 2 +- .../org/apache/nifi/groups/StandardProcessGroup.java | 12 +++++++++++- .../apache/nifi/web/StandardNiFiServiceFacade.java | 12 +++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java index 9bb3d2f565..425110c527 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java @@ -240,7 +240,7 @@ public class StandardFlowSynchronizer implements FlowSynchronizer { existingFlowEmpty = taskElements.isEmpty() && unrootedControllerServiceElements.isEmpty() && isEmpty(rootGroupDto) - && registriesPresent; + && !registriesPresent; logger.debug("Existing Flow Empty = {}", existingFlowEmpty); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java index 870804d52a..9418f40852 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java @@ -3316,7 +3316,17 @@ public final class StandardProcessGroup implements ProcessGroup { ancestorServiceIds = Collections.emptySet(); } else { ancestorServiceIds = parentGroup.getControllerServices(true).stream() - .map(ControllerServiceNode::getIdentifier) + .map(cs -> { + // We want to map the Controller Service to its Versioned Component ID, if it has one. + // If it does not have one, we want to generate it in the same way that our Flow Mapper does + // because this allows us to find the Controller Service when doing a Flow Diff. + final Optional versionedId = cs.getVersionedComponentId(); + if (versionedId.isPresent()) { + return versionedId.get(); + } + + return UUID.nameUUIDFromBytes(cs.getIdentifier().getBytes(StandardCharsets.UTF_8)).toString(); + }) .collect(Collectors.toSet()); } 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 b7559ec573..1ccced2f1e 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 @@ -3824,7 +3824,17 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { ancestorServiceIds = Collections.emptySet(); } else { ancestorServiceIds = parentGroup.getControllerServices(true).stream() - .map(ControllerServiceNode::getIdentifier) + .map(cs -> { + // We want to map the Controller Service to its Versioned Component ID, if it has one. + // If it does not have one, we want to generate it in the same way that our Flow Mapper does + // because this allows us to find the Controller Service when doing a Flow Diff. + final Optional versionedId = cs.getVersionedComponentId(); + if (versionedId.isPresent()) { + return versionedId.get(); + } + + return UUID.nameUUIDFromBytes(cs.getIdentifier().getBytes(StandardCharsets.UTF_8)).toString(); + }) .collect(Collectors.toSet()); }