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


##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/components/connector/StandardConnectorNode.java:
##########
@@ -1619,6 +1773,240 @@ public boolean isExtensionMissing() {
         return extensionMissing;
     }
 
+    @Override
+    public boolean isPendingFlowEvolution() {
+        return flowEvolution.isPending();
+    }
+
+    @Override
+    public FlowEvolutionStatus getReportedFlowEvolutionStatus() {
+        return flowEvolution.getReportedStatus();
+    }
+
+    boolean hasFlowEvolutionFailed() {
+        return flowEvolution.hasFailed();
+    }
+
+    @Override
+    public ConnectorFlowSnapshot getAuthoritativeFlowSnapshot() {
+        return flowEvolution.getSnapshot();
+    }
+
+    @Override
+    public boolean restorePendingFlowEvolution(final VersionedConnector 
persisted, final List<VersionedConfigurationStep> activeConfiguration,
+            final List<VersionedConfigurationStep> workingConfiguration) 
throws FlowUpdateException {
+        final Bundle managedFlowBundle = resolveManagedFlowBundle(persisted);
+        final VersionedProcessGroup persistedManagedGroup = 
persisted.getManagedProcessGroup();
+        final Map<String, SecretReference> parameterSecretReferences = 
ParameterSecretReferences.convertManagedParameterSecretReferences(persisted);
+        // Components in the persisted group may name NAR versions that are no 
longer installed. A missing coordinate
+        // is rewritten only when exactly one compatible bundle is installed. 
A ghost has no initialization context,
+        // and its coordinates have to stay as persisted.
+        if (!extensionMissing) {
+            resolvePersistedBundles(persistedManagedGroup);
+        }
+
+        if (extensionMissing && persistedManagedGroup != null) {
+            // Adopt before inheritConfiguration. A flow save with no snapshot 
omits the managed group, and inherit
+            // rebuilds the live group before the persisted one is installed 
below.
+            adoptAuthoritativeSnapshot(persistedManagedGroup, 
persisted.getManagedParameterContext(), parameterSecretReferences, 
managedFlowBundle);
+            return false;
+        }
+
+        if (!extensionMissing && !sameManagedBundle(managedFlowBundle) && 
persistedManagedGroup != null) {
+            // Skip inheritConfiguration. Its applyUpdate would replace the 
pre-upgrade group with the new bundle's
+            // flow. The restored group keeps the previous bundle, so the next 
start evolves it. A failed restore still loads
+            // the configuration and adopts the persisted snapshot, so the 
next flow save keeps the pre-upgrade flow.
+            try {
+                restorePersistedFlow(persistedManagedGroup, 
persisted.getManagedParameterContext(), parameterSecretReferences, 
ResumeComponentState.RESUME_AS_PERSISTED);
+            } catch (final Exception e) {
+                logger.error("{} failed to restore the persisted pre-upgrade 
managed flow; the Connector cannot start until NiFi is restarted and the flow 
is restored", this, e);
+                markManagedFlowRestoreFailed();
+            }
+
+            loadConfigurationsWithoutRebuildingFlow(activeConfiguration, 
workingConfiguration);

Review Comment:
   [Claude Opus 5.5] Good catch. I went with the finally rather than adopting 
first. The snapshot records the active configuration at adoption, and flow 
saves write the active configuration from the snapshot, so adopting before the 
load would overwrite the persisted active configuration on the next save. The 
load is now in a try with the adoption in its finally, so a failed load still 
keeps the pre-upgrade flow saved and the evolution pending, and the exception 
still reaches syncConnector, which marks the Connector invalid. A partial load 
records the same active configuration a save would write without a snapshot, 
and Apply is rejected while the evolution is pending. I extended the 
restore-failure test to cover a working-configuration step that the new 
Connector version rejects.



-- 
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