From a18a1fa7afce4a248e9c209c06f75772562f2449 Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Mon, 3 Aug 2026 15:57:44 +0200 Subject: [PATCH 1/3] NIFI-16165 - Expose Node Connection State through NodeTypeProvider --- .../node/NodeConnectionState.java | 68 +++++++++++++++++++ .../nifi/controller/NodeTypeProvider.java | 13 ++++ .../nifi/controller/NodeTypeProviderTest.java | 42 ++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java create mode 100644 src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java diff --git a/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java b/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java new file mode 100644 index 0000000..95c89a4 --- /dev/null +++ b/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nifi.cluster.coordination.node; + +public enum NodeConnectionState { + /** + * A node has issued a connection request to the cluster, but has not yet + * sent a heartbeat. A connecting node can transition to DISCONNECTED or CONNECTED. The cluster + * will not accept any external requests to change the flow while any node is in + * this state. + */ + CONNECTING, + + /** + * A node that is connected to the cluster. A connecting node transitions + * to connected after the cluster receives the node's first heartbeat. A + * connected node can transition to disconnecting. + */ + CONNECTED, + + /** + * A node that is in the process of offloading its FlowFiles from the node. + */ + OFFLOADING, + + /** + * A node that is in the process of disconnecting from the cluster. + * A DISCONNECTING node will always transition to DISCONNECTED. + */ + DISCONNECTING, + + /** + * A node that has offloaded its FlowFiles from the node. + */ + OFFLOADED, + + /** + * A node that is not connected to the cluster. + * A DISCONNECTED node can transition to CONNECTING. + */ + DISCONNECTED, + + /** + * A NodeConnectionState of REMOVED indicates that the node was removed from the cluster + * and is used in order to notify other nodes in the cluster. + */ + REMOVED, + + /** + * A NiFi instance that is not configured to participate in a cluster. + */ + STANDALONE +} \ No newline at end of file diff --git a/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java b/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java index 1552282..41d6e74 100644 --- a/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java +++ b/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java @@ -17,6 +17,8 @@ package org.apache.nifi.controller; +import org.apache.nifi.cluster.coordination.node.NodeConnectionState; + import java.util.Collections; import java.util.Optional; import java.util.Set; @@ -47,6 +49,17 @@ default boolean isConnected() { return false; } + /** + * Returns the current node connection state and never null. The compatibility default is + * {@link NodeConnectionState#STANDALONE}. Providers for clustered NiFi should override this + * method with the current node lifecycle state. + * + * @return current node connection state + */ + default NodeConnectionState getNodeConnectionState() { + return NodeConnectionState.STANDALONE; + } + /** * @return true if this instance is the primary node in the cluster; false otherwise */ diff --git a/src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java b/src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java new file mode 100644 index 0000000..2d84719 --- /dev/null +++ b/src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.controller; + +import org.apache.nifi.cluster.coordination.node.NodeConnectionState; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class NodeTypeProviderTest { + + @Test + void getNodeConnectionStateReturnsStandaloneForLegacyImplementations() { + final NodeTypeProvider nodeTypeProvider = new NodeTypeProvider() { + @Override + public boolean isClustered() { + return false; + } + + @Override + public boolean isPrimary() { + return false; + } + }; + + assertEquals(NodeConnectionState.STANDALONE, nodeTypeProvider.getNodeConnectionState()); + } +} \ No newline at end of file From 3680c17f931f7eba976968761400bda7f915507a Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Mon, 3 Aug 2026 18:33:22 +0200 Subject: [PATCH 2/3] review --- .../node/NodeConnectionState.java | 68 ------------------- .../nifi/controller/NodeTypeProvider.java | 2 - .../nifi/controller/NodeTypeProviderTest.java | 6 +- 3 files changed, 2 insertions(+), 74 deletions(-) delete mode 100644 src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java diff --git a/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java b/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java deleted file mode 100644 index 95c89a4..0000000 --- a/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.cluster.coordination.node; - -public enum NodeConnectionState { - /** - * A node has issued a connection request to the cluster, but has not yet - * sent a heartbeat. A connecting node can transition to DISCONNECTED or CONNECTED. The cluster - * will not accept any external requests to change the flow while any node is in - * this state. - */ - CONNECTING, - - /** - * A node that is connected to the cluster. A connecting node transitions - * to connected after the cluster receives the node's first heartbeat. A - * connected node can transition to disconnecting. - */ - CONNECTED, - - /** - * A node that is in the process of offloading its FlowFiles from the node. - */ - OFFLOADING, - - /** - * A node that is in the process of disconnecting from the cluster. - * A DISCONNECTING node will always transition to DISCONNECTED. - */ - DISCONNECTING, - - /** - * A node that has offloaded its FlowFiles from the node. - */ - OFFLOADED, - - /** - * A node that is not connected to the cluster. - * A DISCONNECTED node can transition to CONNECTING. - */ - DISCONNECTED, - - /** - * A NodeConnectionState of REMOVED indicates that the node was removed from the cluster - * and is used in order to notify other nodes in the cluster. - */ - REMOVED, - - /** - * A NiFi instance that is not configured to participate in a cluster. - */ - STANDALONE -} \ No newline at end of file diff --git a/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java b/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java index 41d6e74..641bca0 100644 --- a/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java +++ b/src/main/java/org/apache/nifi/controller/NodeTypeProvider.java @@ -17,8 +17,6 @@ package org.apache.nifi.controller; -import org.apache.nifi.cluster.coordination.node.NodeConnectionState; - import java.util.Collections; import java.util.Optional; import java.util.Set; diff --git a/src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java b/src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java index 2d84719..05bdb4f 100644 --- a/src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java +++ b/src/test/java/org/apache/nifi/controller/NodeTypeProviderTest.java @@ -15,13 +15,11 @@ * limitations under the License. */ package org.apache.nifi.controller; - -import org.apache.nifi.cluster.coordination.node.NodeConnectionState; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -public class NodeTypeProviderTest { +class NodeTypeProviderTest { @Test void getNodeConnectionStateReturnsStandaloneForLegacyImplementations() { @@ -39,4 +37,4 @@ public boolean isPrimary() { assertEquals(NodeConnectionState.STANDALONE, nodeTypeProvider.getNodeConnectionState()); } -} \ No newline at end of file +} From 7d3a16e2b39b4ecacd3e23ceefe169696b600942 Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Mon, 3 Aug 2026 18:33:33 +0200 Subject: [PATCH 3/3] review --- .../nifi/controller/NodeConnectionState.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/main/java/org/apache/nifi/controller/NodeConnectionState.java diff --git a/src/main/java/org/apache/nifi/controller/NodeConnectionState.java b/src/main/java/org/apache/nifi/controller/NodeConnectionState.java new file mode 100644 index 0000000..5789772 --- /dev/null +++ b/src/main/java/org/apache/nifi/controller/NodeConnectionState.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nifi.controller; + +public enum NodeConnectionState { + /** + * A node has issued a connection request to the cluster, but has not yet + * sent a heartbeat. A connecting node can transition to DISCONNECTED or CONNECTED. The cluster + * will not accept any external requests to change the flow while any node is in + * this state. + */ + CONNECTING, + + /** + * A node that is connected to the cluster. A connecting node transitions + * to connected after the cluster receives the node's first heartbeat. A + * connected node can transition to disconnecting. + */ + CONNECTED, + + /** + * A node that is in the process of offloading its FlowFiles from the node. + */ + OFFLOADING, + + /** + * A node that is in the process of disconnecting from the cluster. + * A DISCONNECTING node will always transition to DISCONNECTED. + */ + DISCONNECTING, + + /** + * A node that has offloaded its FlowFiles from the node. + */ + OFFLOADED, + + /** + * A node that is not connected to the cluster. + * A DISCONNECTED node can transition to CONNECTING. + */ + DISCONNECTED, + + /** + * A NodeConnectionState of REMOVED indicates that the node was removed from the cluster + * and is used in order to notify other nodes in the cluster. + */ + REMOVED, + + /** + * A NiFi instance that is not configured to participate in a cluster. + */ + STANDALONE +}