bobpaulin commented on code in PR #11872:
URL: https://github.com/apache/nifi/pull/11872#discussion_r4556171915


##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/components/connector/StandardFlowContext.java:
##########
@@ -105,23 +113,55 @@ public void updateFlow(final VersionedExternalFlow 
versionedExternalFlow, final
         parameterContext = 
parameterContextFacadeFactory.create(managedProcessGroup);
     }
 
+    /**
+     * Restores a persisted flow into the managed process group, keeping 
component identifiers so queued FlowFiles
+     * reattach. When {@code parameterContext} is non-null its values are 
applied to the managed parameter context.
+     * Components resume according to the Process Group's auto-resume setting.
+     */
+    @Override
+    public void restorePersistedFlow(final VersionedProcessGroup 
persistedFlow, final VersionedParameterContext parameterContext) {
+        final VersionedExternalFlow externalFlow = 
toExternalFlow(persistedFlow, parameterContext);
+        managedProcessGroup.restoreFlowPreservingIdentifiers(externalFlow);
+        finishRestorePersistedFlow(externalFlow, parameterContext);
+    }
+
+    /**
+     * Restores a persisted flow into the managed process group, keeping 
component identifiers so queued FlowFiles
+     * reattach. When {@code resumeComponentState} is false, components are 
left stopped.
+     */
     @Override
-    public void restoreTroubleshootingFlow(final VersionedProcessGroup 
troubleshootingProcessGroup) {
+    public void restorePersistedFlow(final VersionedProcessGroup 
persistedFlow, final VersionedParameterContext parameterContext, final boolean 
resumeComponentState) {
+        final VersionedExternalFlow externalFlow = 
toExternalFlow(persistedFlow, parameterContext);
+        managedProcessGroup.restoreFlowPreservingIdentifiers(externalFlow, 
resumeComponentState);
+        finishRestorePersistedFlow(externalFlow, parameterContext);
+    }
+
+    private VersionedExternalFlow toExternalFlow(final VersionedProcessGroup 
persistedFlow, final VersionedParameterContext parameterContext) {
         final VersionedExternalFlow externalFlow = new VersionedExternalFlow();
-        externalFlow.setFlowContents(troubleshootingProcessGroup);
-        externalFlow.setParameterContexts(Map.of());
+        externalFlow.setFlowContents(persistedFlow);
+        if (parameterContext == null) {
+            externalFlow.setParameterContexts(Map.of());
+        } else {
+            
externalFlow.setParameterContexts(Map.of(parameterContext.getIdentifier(), 
parameterContext));
+        }
 
         final ParameterContext managedGroupParameterContext = 
managedProcessGroup.getParameterContext();
         if (managedGroupParameterContext != null) {
-            updateParameterContextNames(troubleshootingProcessGroup, 
managedGroupParameterContext.getName());
+            updateParameterContextNames(persistedFlow, 
managedGroupParameterContext.getName());
         }
+        return externalFlow;
+    }
 
-        managedProcessGroup.restoreFlowPreservingIdentifiers(externalFlow);
-
+    private void finishRestorePersistedFlow(final VersionedExternalFlow 
externalFlow, final VersionedParameterContext parameterContext) {
         final ReloadableState currentState = reloadableState;
         final ProcessGroupFacade rootGroup = 
groupFacadeFactory.create(managedProcessGroup, currentState.connectorLog());
         reloadableState = new 
ReloadableState(currentState.configurationContext(), 
currentState.connectorLog(), currentState.bundle(), rootGroup);
-        parameterContext = 
parameterContextFacadeFactory.create(managedProcessGroup);
+        this.parameterContext = 
parameterContextFacadeFactory.create(managedProcessGroup);
+
+        if (parameterContext != null && parameterContext.getParameters() != 
null) {
+            final ConnectorParameterLookup parameterLookup = new 
ConnectorParameterLookup(externalFlow.getParameterContexts().values(), 
assetManager);
+            
getParameterContext().updateParameters(parameterLookup.getParameterValues());

Review Comment:
   [Claude Opus 5.5] Addressed along with the restorePersistedManagedFlow 
comment. This call no longer runs on a normal restart. On the ghost and 
interrupted-upgrade paths, sensitive values are now saved encrypted and 
restored with real values. A null reaches updateParameters only when a bound 
secret can't be resolved or a persisted value can't be decrypted. Both cases 
are logged and leave components stopped.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to