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


##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/components/connector/StandardConnectorNode.java:
##########
@@ -1619,6 +1775,691 @@ public boolean isExtensionMissing() {
         return extensionMissing;
     }
 
+    @Override
+    public boolean isPendingFlowEvolution() {
+        synchronized (flowEvolutionLock) {
+            if (extensionMissing) {
+                return false;
+            }
+
+            final ConnectorFlowSnapshot snapshot = authoritativeFlowSnapshot;
+            final Bundle snapshotBundle = snapshot == null ? null : 
snapshot.bundle();
+            return snapshotBundle != null && !sameBundle(snapshotBundle, 
bundleCoordinate);
+        }
+    }
+
+    @Override
+    public FlowEvolutionStatus getReportedFlowEvolutionStatus() {
+        return flowEvolutionProgress.get().reportedStatus();
+    }
+
+    private boolean isEvolveDrainComplete() {
+        return flowEvolutionProgress.get().isDrainComplete();
+    }
+
+    private boolean isApplyingEvolvedFlow() {
+        return getReportedFlowEvolutionStatus() == 
FlowEvolutionStatus.EVOLVE_DRAIN_COMPLETE;
+    }
+
+    boolean hasFlowEvolutionFailed() {
+        return flowEvolutionProgress.get().hasFailed();
+    }
+
+    private VersionedProcessGroup getAuthoritativeManagedProcessGroup() {
+        final ConnectorFlowSnapshot snapshot = authoritativeFlowSnapshot;
+        return snapshot == null ? null : snapshot.flow();
+    }
+
+    @Override
+    public ConnectorFlowSnapshot getAuthoritativeFlowSnapshot() {
+        return authoritativeFlowSnapshot;
+    }
+
+    @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.
+            restorePersistedFlow(persistedManagedGroup, 
persisted.getManagedParameterContext(), parameterSecretReferences, true);

Review Comment:
   [Claude Opus 5.5] Agreed, thanks for walking through it.
   
   I kept the restore before loading the configuration, because loading builds 
the working context by copying the active group, and that group has to be 
restored first. Instead the failure is now handled in two ways:
   
   Unreachable secrets provider: this now counts as unresolved secrets. The 
flow is restored with components stopped, so the queues reattach.
   Any other restore failure: it's caught and marks the restore as failed, 
which blocks START.
   In both cases the configuration is still loaded and the persisted snapshot 
is adopted, so the next flow save keeps the managed group and the active and 
working configurations. Tests: 
testRestorePersistedFlowKeepsComponentsStoppedWhenSecretUnavailable and 
testRestorePendingFlowEvolutionAdoptsSnapshotWhenRestoreFails.



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