Search in sources :

Example 1 with IllegalNodeDisconnectionException

use of org.apache.nifi.cluster.manager.exception.IllegalNodeDisconnectionException in project nifi by apache.

the class NodeClusterCoordinator method requestNodeDisconnect.

@Override
public void requestNodeDisconnect(final NodeIdentifier nodeId, final DisconnectionCode disconnectionCode, final String explanation) {
    final Set<NodeIdentifier> connectedNodeIds = getNodeIdentifiers(NodeConnectionState.CONNECTED);
    if (connectedNodeIds.size() == 1 && connectedNodeIds.contains(nodeId)) {
        throw new IllegalNodeDisconnectionException("Cannot disconnect node " + nodeId + " because it is the only node currently connected");
    }
    logger.info("Requesting that {} disconnect due to {}", nodeId, explanation == null ? disconnectionCode : explanation);
    updateNodeStatus(new NodeConnectionStatus(nodeId, disconnectionCode, explanation));
    // shutdown, as we will not be able to connect to the node anyway.
    if (disconnectionCode == DisconnectionCode.NODE_SHUTDOWN) {
        return;
    }
    final DisconnectMessage request = new DisconnectMessage();
    request.setNodeId(nodeId);
    request.setExplanation(explanation);
    addNodeEvent(nodeId, "Disconnection requested due to " + explanation);
    disconnectAsynchronously(request, 10, 5);
}
Also used : DisconnectMessage(org.apache.nifi.cluster.protocol.message.DisconnectMessage) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) IllegalNodeDisconnectionException(org.apache.nifi.cluster.manager.exception.IllegalNodeDisconnectionException)

Example 2 with IllegalNodeDisconnectionException

use of org.apache.nifi.cluster.manager.exception.IllegalNodeDisconnectionException in project nifi by apache.

the class TestNodeClusterCoordinator method testCannotDisconnectLastNode.

@Test(timeout = 5000)
public void testCannotDisconnectLastNode() throws InterruptedException {
    // Add a connected node
    final NodeIdentifier nodeId1 = createNodeId(1);
    final NodeIdentifier nodeId2 = createNodeId(2);
    coordinator.updateNodeStatus(new NodeConnectionStatus(nodeId1, NodeConnectionState.CONNECTED));
    coordinator.updateNodeStatus(new NodeConnectionStatus(nodeId2, NodeConnectionState.CONNECTED));
    // wait for the status change message and clear it
    while (nodeStatuses.isEmpty()) {
        Thread.sleep(10L);
    }
    nodeStatuses.clear();
    coordinator.requestNodeDisconnect(nodeId2, DisconnectionCode.USER_DISCONNECTED, "Unit Test");
    try {
        coordinator.requestNodeDisconnect(nodeId1, DisconnectionCode.USER_DISCONNECTED, "Unit Test");
        Assert.fail("Expected an IllegalNodeDisconnectionException when trying to disconnect last node but it wasn't thrown");
    } catch (final IllegalNodeDisconnectionException inde) {
    // expected
    }
    // Should still be able to request that node 2 disconnect, since it's not the node that is connected
    coordinator.requestNodeDisconnect(nodeId2, DisconnectionCode.USER_DISCONNECTED, "Unit Test");
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) IllegalNodeDisconnectionException(org.apache.nifi.cluster.manager.exception.IllegalNodeDisconnectionException) Test(org.junit.Test)

Aggregations

IllegalNodeDisconnectionException (org.apache.nifi.cluster.manager.exception.IllegalNodeDisconnectionException)2 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)2 DisconnectMessage (org.apache.nifi.cluster.protocol.message.DisconnectMessage)1 Test (org.junit.Test)1