-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-12453, NIFI-12454: Allow easily determining cluster state of a n…
…ode by running nifi.sh cluster-status and allow decommissioning of nodes without shutting down
- Loading branch information
Showing
11 changed files
with
279 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
nifi-framework-api/src/main/java/org/apache/nifi/cluster/ClusterDetailsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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; | ||
|
||
public interface ClusterDetailsFactory { | ||
|
||
/** | ||
* @return the current Connection State of this NiFi instance | ||
*/ | ||
ConnectionState getConnectionState(); | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
nifi-framework-api/src/main/java/org/apache/nifi/cluster/ConnectionState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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; | ||
|
||
public enum ConnectionState { | ||
|
||
/** | ||
* This NiFi instance is not part of a cluster | ||
*/ | ||
NOT_CLUSTERED, | ||
|
||
/** | ||
* Instance is in the process of connecting to the cluster | ||
*/ | ||
CONNECTING, | ||
|
||
/** | ||
* Instance is connected to the cluster | ||
*/ | ||
CONNECTED, | ||
|
||
/** | ||
* Instance is in the process of disconnecting from the cluster | ||
*/ | ||
DISCONNECTING, | ||
|
||
/** | ||
* Instance is disconnected from the cluster | ||
*/ | ||
DISCONNECTED, | ||
|
||
/** | ||
* Instance is offloading | ||
*/ | ||
OFFLOADING, | ||
|
||
/** | ||
* Instances has completed offloading | ||
*/ | ||
OFFLOADED, | ||
|
||
/** | ||
* Instance has been removed from the cluster | ||
*/ | ||
REMOVED, | ||
|
||
/** | ||
* The state is not currently known | ||
*/ | ||
UNKNOWN; | ||
} |
68 changes: 68 additions & 0 deletions
68
...ramework-cluster/src/main/java/org/apache/nifi/cluster/StandardClusterDetailsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
import org.apache.nifi.cluster.coordination.ClusterCoordinator; | ||
import org.apache.nifi.cluster.coordination.node.NodeConnectionStatus; | ||
import org.apache.nifi.cluster.protocol.NodeIdentifier; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
public class StandardClusterDetailsFactory implements ClusterDetailsFactory { | ||
private static final Logger logger = LoggerFactory.getLogger(StandardClusterDetailsFactory.class); | ||
|
||
private final ClusterCoordinator clusterCoordinator; | ||
|
||
/** | ||
* Constructor marked as never used because it is constructed via Spring | ||
*/ | ||
public StandardClusterDetailsFactory(final ClusterCoordinator clusterCoordinator) { | ||
this.clusterCoordinator = clusterCoordinator; | ||
} | ||
|
||
@Override | ||
public ConnectionState getConnectionState() { | ||
if (clusterCoordinator == null) { | ||
logger.debug("No Cluster Coordinator has been configured; returning Connection State of NOT_CLUSTERED"); | ||
return ConnectionState.NOT_CLUSTERED; | ||
} | ||
|
||
final NodeIdentifier nodeIdentifier = clusterCoordinator.getLocalNodeIdentifier(); | ||
if (nodeIdentifier == null) { | ||
logger.info("Local Node Identifier has not yet been established; returning Connection State of UNKNOWN"); | ||
return ConnectionState.UNKNOWN; | ||
} | ||
|
||
final NodeConnectionStatus connectionStatus = clusterCoordinator.getConnectionStatus(nodeIdentifier); | ||
if (connectionStatus == null) { | ||
logger.info("Cluster connection status is not currently known for Node Identifier {}; returning Connection State of UNKNOWN", nodeIdentifier.getId()); | ||
return ConnectionState.UNKNOWN; | ||
} | ||
|
||
final String stateName = connectionStatus.getState().name(); | ||
try { | ||
final ConnectionState connectionState = ConnectionState.valueOf(stateName); | ||
logger.debug("Returning Connection State of {}", connectionState); | ||
return connectionState; | ||
} catch (final IllegalArgumentException iae) { | ||
logger.warn("Cluster Coordinator reports Connection State of {}, which is not a known state; returning UNKNOWN", stateName); | ||
return ConnectionState.UNKNOWN; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.