You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "pvillard31 (via GitHub)" <gi...@apache.org> on 2026/07/07 08:33:08 UTC

[PR] NIFI-16082 - Connection update is incorrectly rejected when the current destination is running [nifi]

pvillard31 opened a new pull request, #11400:
URL: https://github.com/apache/nifi/pull/11400

   # Summary
   
   NIFI-16082 - Connection update is incorrectly rejected when the current destination is running
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   - Pull request contains [commits signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) with a registered key indicating `Verified` status
   
   ### Pull Request Formatting
   
   - Pull Request based on current revision of the `main` branch
   - Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `./mvnw clean install -P contrib-check`
     - [ ] JDK 21
     - [ ] JDK 25
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-16082 - Connection update is incorrectly rejected when the current destination is running [nifi]

Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on PR #11400:
URL: https://github.com/apache/nifi/pull/11400#issuecomment-5291216535

   Done, thanks for the review @exceptionfactory 


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-16082 - Connection update is incorrectly rejected when the current destination is running [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #11400:
URL: https://github.com/apache/nifi/pull/11400


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-16082 - Connection update is incorrectly rejected when the current destination is running [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #11400:
URL: https://github.com/apache/nifi/pull/11400#discussion_r3777784951


##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/dao/impl/StandardConnectionDAOTest.java:
##########
@@ -199,4 +210,124 @@ void testGetConnectionWithMultipleConnectors() {
 
         assertEquals(connectionInSecondConnector, result);
     }
+
+    private ConnectionDTO connectionDtoWithNameOnly() {
+        final ConnectionDTO dto = new ConnectionDTO();
+        dto.setId(ROOT_CONNECTION_ID);
+        dto.setName("renamed-connection");
+        return dto;
+    }
+
+    private ConnectionDTO connectionDtoChangingDestination(final String newDestinationId) {
+        final ConnectionDTO dto = new ConnectionDTO();
+        dto.setId(ROOT_CONNECTION_ID);
+        final ConnectableDTO newDestination = new ConnectableDTO();
+        newDestination.setId(newDestinationId);
+        newDestination.setType(ConnectableType.PROCESSOR.name());
+        dto.setDestination(newDestination);
+        return dto;
+    }
+
+    private void stubRootConnectionDestination(final String destinationId) {
+        final ProcessGroup group = mock(ProcessGroup.class);
+        when(group.getIdentifier()).thenReturn("group-id");
+        when(rootConnection.getProcessGroup()).thenReturn(group);
+
+        final Connectable currentDestination = mock(Connectable.class);
+        when(currentDestination.getIdentifier()).thenReturn(destinationId);
+        when(currentDestination.isRunning()).thenReturn(true);
+        when(currentDestination.getConnectableType()).thenReturn(ConnectableType.PROCESSOR);
+        when(rootConnection.getDestination()).thenReturn(currentDestination);
+    }
+
+    @Test
+    void testVerifyUpdateDoesNotCheckDestinationForNonDestinationEdit() {
+        stubRootConnectionDestination("current-destination-id");
+
+        assertDoesNotThrow(() -> connectionDAO.verifyUpdate(connectionDtoWithNameOnly()));
+        verify(rootConnection, never()).verifyCanUpdateDestination();
+    }
+
+    @Test
+    void testVerifyUpdateWrapsIllegalStateFromDestinationGuardAsValidationException() {
+        stubRootConnectionDestination("current-destination-id");
+        final String guardMessage = "Cannot change destination of Connection because the current destination ([proc]) is running";
+        org.mockito.Mockito.doThrow(new IllegalStateException(guardMessage))
+                .when(rootConnection).verifyCanUpdateDestination();
+
+        final ValidationException thrown = assertThrows(ValidationException.class,
+                () -> connectionDAO.verifyUpdate(connectionDtoChangingDestination("new-destination-id")));
+        assertTrue(thrown.getValidationErrors().contains(guardMessage),
+                "ValidationException should carry the guard's message; was: " + thrown.getValidationErrors());
+    }
+
+    @Test
+    void testVerifyUpdateChecksDestinationGuardWhenDestinationChanges() {
+        stubRootConnectionDestination("current-destination-id");
+
+        assertDoesNotThrow(() -> connectionDAO.verifyUpdate(connectionDtoChangingDestination("new-destination-id")));
+        verify(rootConnection).verifyCanUpdateDestination();
+    }
+
+    @Test
+    void testIsDestinationChangingReturnsFalseForSameDestinationId() {
+        final Connectable currentDestination = mock(Connectable.class);
+        when(currentDestination.getIdentifier()).thenReturn("dest-1");

Review Comment:
   Many of these methods reuse Strings for identifiers, so it would be helpful to declare these as static variables for reuse.



##########
nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/connectable/Connection.java:
##########
@@ -68,6 +68,16 @@ public interface Connection extends Authorizable, VersionedComponent {
 
     void setDestination(final Connectable newDestination);
 
+    /**
+     * Verifies that this Connection's destination may be changed, based solely on the current (existing) destination
+     * and the FlowFiles the Connection is holding. This applies the same guards as {@link #setDestination(Connectable)}
+     * so that a pre-check (e.g. the two-phase cluster verify) rejects exactly what the subsequent mutation would reject.
+     *
+     * @throws IllegalStateException if the current destination is running and is not exempt, or FlowFiles from this
+     * Connection are currently held by the destination
+     */
+    void verifyCanUpdateDestination() throws IllegalStateException;

Review Comment:
   Declaring a `RuntimeException` type in `throws` is generally unnecessary, and also implies a particular implementation. I recommend removing the declaration and instead documenting it on the implementation method



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org