|
| 1 | +From ec247bbf5e8b607267abaa2b302dc4a355e9767e Mon Sep 17 00:00:00 2001 |
| 2 | +From: Andrew Kenworthy <andrew.kenworthy@stackable.tech> |
| 3 | +Date: Tue, 5 May 2026 17:44:42 +0200 |
| 4 | +Subject: NIFI-15801 Stop processors in synchronizeProcessors before updating |
| 5 | + |
| 6 | +--- |
| 7 | + ...tandardVersionedComponentSynchronizer.java | 61 ++++++++++++------- |
| 8 | + 1 file changed, 40 insertions(+), 21 deletions(-) |
| 9 | + |
| 10 | +diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java |
| 11 | +index b79ee4d6e8..c3e059171e 100644 |
| 12 | +--- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java |
| 13 | ++++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java |
| 14 | +@@ -269,8 +269,8 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen |
| 15 | + final ProcessGroup newProcessGroup = addProcessGroup(group, processGroup, options.getComponentIdGenerator(), |
| 16 | + additions.getParameterContexts(), additions.getParameterProviders(), group); |
| 17 | + additionsBuilder.addProcessGroup(newProcessGroup); |
| 18 | +- } catch (final ProcessorInstantiationException pie) { |
| 19 | +- throw new RuntimeException(pie); |
| 20 | ++ } catch (final ProcessorInstantiationException | FlowSynchronizationException e) { |
| 21 | ++ throw new RuntimeException(e); |
| 22 | + } |
| 23 | + }); |
| 24 | + |
| 25 | +@@ -392,8 +392,8 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen |
| 26 | + final ProcessGroup topLevelGroup = syncOptions.getTopLevelGroupId() == null ? group : context.getFlowManager().getGroup(syncOptions.getTopLevelGroupId()); |
| 27 | + synchronize(group, versionedExternalFlow.getFlowContents(), versionedExternalFlow.getParameterContexts(), |
| 28 | + parameterProviderReferences, topLevelGroup, syncOptions.isUpdateSettings()); |
| 29 | +- } catch (final ProcessorInstantiationException pie) { |
| 30 | +- throw new RuntimeException(pie); |
| 31 | ++ } catch (final ProcessorInstantiationException | FlowSynchronizationException e) { |
| 32 | ++ throw new RuntimeException(e); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | +@@ -422,7 +422,7 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen |
| 37 | + |
| 38 | + private void synchronize(final ProcessGroup group, final VersionedProcessGroup proposed, final Map<String, VersionedParameterContext> versionedParameterContexts, |
| 39 | + final Map<String, ParameterProviderReference> parameterProviderReferences, final ProcessGroup topLevelGroup, final boolean updateGroupSettings) |
| 40 | +- throws ProcessorInstantiationException { |
| 41 | ++ throws ProcessorInstantiationException, FlowSynchronizationException { |
| 42 | + |
| 43 | + // Some components, such as Processors, may have a Scheduled State of RUNNING in the proposed flow. However, if we |
| 44 | + // transition the service into the RUNNING state, and then we need to update a Connection that is connected to it, |
| 45 | +@@ -687,7 +687,7 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen |
| 46 | + |
| 47 | + private void synchronizeChildGroups(final ProcessGroup group, final VersionedProcessGroup proposed, final Map<String, VersionedParameterContext> versionedParameterContexts, |
| 48 | + final Map<String, ProcessGroup> childGroupsByVersionedId, final Map<String, ParameterProviderReference> parameterProviderReferences, |
| 49 | +- final ProcessGroup topLevelGroup) throws ProcessorInstantiationException { |
| 50 | ++ final ProcessGroup topLevelGroup) throws ProcessorInstantiationException, FlowSynchronizationException { |
| 51 | + |
| 52 | + for (final VersionedProcessGroup proposedChildGroup : proposed.getProcessGroups()) { |
| 53 | + final ProcessGroup childGroup = childGroupsByVersionedId.get(proposedChildGroup.getIdentifier()); |
| 54 | +@@ -1189,21 +1189,39 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen |
| 55 | + |
| 56 | + private void synchronizeProcessors(final ProcessGroup group, final VersionedProcessGroup proposed, final Map<String, ProcessorNode> processorsByVersionedId, |
| 57 | + final ProcessGroup topLevelGroup) |
| 58 | +- throws ProcessorInstantiationException { |
| 59 | ++ throws ProcessorInstantiationException, FlowSynchronizationException { |
| 60 | + |
| 61 | +- for (final VersionedProcessor proposedProcessor : proposed.getProcessors()) { |
| 62 | +- final ProcessorNode processor = processorsByVersionedId.get(proposedProcessor.getIdentifier()); |
| 63 | +- if (processor == null) { |
| 64 | +- final ProcessorNode added = addProcessor(group, proposedProcessor, context.getComponentIdGenerator(), topLevelGroup); |
| 65 | +- LOG.info("Added {} to {}", added, group); |
| 66 | +- } else if (updatedVersionedComponentIds.contains(proposedProcessor.getIdentifier())) { |
| 67 | +- updateProcessor(processor, proposedProcessor, topLevelGroup); |
| 68 | +- // Any existing component that is modified during synchronization may have its properties reverted to a pre-migration state, |
| 69 | +- // so we then add it to the set to allow migrateProperties to be called again to get it back to the migrated state |
| 70 | +- createdAndModifiedExtensions.add(new CreatedOrModifiedExtension(processor, getPropertyValues(processor))); |
| 71 | +- LOG.info("Updated {}", processor); |
| 72 | +- } else { |
| 73 | +- processor.setPosition(new Position(proposedProcessor.getPosition().getX(), proposedProcessor.getPosition().getY())); |
| 74 | ++ final Set<ProcessorNode> processorsToRestart = new HashSet<>(); |
| 75 | ++ |
| 76 | ++ try { |
| 77 | ++ for (final VersionedProcessor proposedProcessor : proposed.getProcessors()) { |
| 78 | ++ final ProcessorNode processor = processorsByVersionedId.get(proposedProcessor.getIdentifier()); |
| 79 | ++ if (processor == null) { |
| 80 | ++ final ProcessorNode added = addProcessor(group, proposedProcessor, context.getComponentIdGenerator(), topLevelGroup); |
| 81 | ++ LOG.info("Added {} to {}", added, group); |
| 82 | ++ } else if (updatedVersionedComponentIds.contains(proposedProcessor.getIdentifier())) { |
| 83 | ++ final long processorStopDeadline = System.currentTimeMillis() + syncOptions.getComponentStopTimeout().toMillis(); |
| 84 | ++ try { |
| 85 | ++ final boolean stopped = stopOrTerminate(processor, processorStopDeadline, syncOptions); |
| 86 | ++ if (stopped && proposedProcessor.getScheduledState() == org.apache.nifi.flow.ScheduledState.RUNNING) { |
| 87 | ++ processorsToRestart.add(processor); |
| 88 | ++ } |
| 89 | ++ } catch (final TimeoutException e) { |
| 90 | ++ throw new FlowSynchronizationException("Failed to stop processor " + processor + " in preparation for update", e); |
| 91 | ++ } |
| 92 | ++ updateProcessor(processor, proposedProcessor, topLevelGroup); |
| 93 | ++ // Any existing component that is modified during synchronization may have its properties reverted to a pre-migration state, |
| 94 | ++ // so we then add it to the set to allow migrateProperties to be called again to get it back to the migrated state |
| 95 | ++ createdAndModifiedExtensions.add(new CreatedOrModifiedExtension(processor, getPropertyValues(processor))); |
| 96 | ++ LOG.info("Updated {}", processor); |
| 97 | ++ } else { |
| 98 | ++ processor.setPosition(new Position(proposedProcessor.getPosition().getX(), proposedProcessor.getPosition().getY())); |
| 99 | ++ } |
| 100 | ++ } |
| 101 | ++ } finally { |
| 102 | ++ for (final ProcessorNode processor : processorsToRestart) { |
| 103 | ++ processor.getProcessGroup().startProcessor(processor, false); |
| 104 | ++ notifyScheduledStateChange((ComponentNode) processor, syncOptions, org.apache.nifi.flow.ScheduledState.RUNNING); |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | +@@ -1375,7 +1393,8 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen |
| 109 | + |
| 110 | + private ProcessGroup addProcessGroup(final ProcessGroup destination, final VersionedProcessGroup proposed, final ComponentIdGenerator componentIdGenerator, |
| 111 | + final Map<String, VersionedParameterContext> versionedParameterContexts, |
| 112 | +- final Map<String, ParameterProviderReference> parameterProviderReferences, ProcessGroup topLevelGroup) throws ProcessorInstantiationException { |
| 113 | ++ final Map<String, ParameterProviderReference> parameterProviderReferences, ProcessGroup topLevelGroup) |
| 114 | ++ throws ProcessorInstantiationException, FlowSynchronizationException { |
| 115 | + final String id = componentIdGenerator.generateUuid(proposed.getIdentifier(), proposed.getInstanceIdentifier(), destination.getIdentifier()); |
| 116 | + final ProcessGroup group = context.getFlowManager().createProcessGroup(id); |
| 117 | + group.setVersionedComponentId(proposed.getIdentifier()); |
0 commit comments