Search in sources :

Example 1 with NodeStatusChangeMessage

use of org.apache.nifi.cluster.protocol.message.NodeStatusChangeMessage in project nifi by apache.

the class NodeClusterCoordinator method notifyOthersOfNodeStatusChange.

/**
 * Notifies other nodes that the status of a node changed
 *
 * @param updatedStatus the updated status for a node in the cluster
 * @param notifyAllNodes if <code>true</code> will notify all nodes. If
 * <code>false</code>, will notify only the cluster coordinator
 */
void notifyOthersOfNodeStatusChange(final NodeConnectionStatus updatedStatus, final boolean notifyAllNodes, final boolean waitForCoordinator) {
    // If this node is the active cluster coordinator, then we are going to replicate to all nodes.
    // Otherwise, get the active coordinator (or wait for one to become active) and then notify the coordinator.
    final Set<NodeIdentifier> nodesToNotify;
    if (notifyAllNodes) {
        nodesToNotify = getNodeIdentifiers(NodeConnectionState.CONNECTED, NodeConnectionState.CONNECTING);
        // Do not notify ourselves because we already know about the status update.
        nodesToNotify.remove(getLocalNodeIdentifier());
    } else if (waitForCoordinator) {
        nodesToNotify = Collections.singleton(waitForElectedClusterCoordinator());
    } else {
        final NodeIdentifier nodeId = getElectedActiveCoordinatorNode();
        if (nodeId == null) {
            return;
        }
        nodesToNotify = Collections.singleton(nodeId);
    }
    final NodeStatusChangeMessage message = new NodeStatusChangeMessage();
    message.setNodeId(updatedStatus.getNodeIdentifier());
    message.setNodeConnectionStatus(updatedStatus);
    senderListener.notifyNodeStatusChange(nodesToNotify, message);
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeStatusChangeMessage(org.apache.nifi.cluster.protocol.message.NodeStatusChangeMessage)

Example 2 with NodeStatusChangeMessage

use of org.apache.nifi.cluster.protocol.message.NodeStatusChangeMessage in project nifi by apache.

the class TestNodeClusterCoordinator method testUpdateNodeStatusOutOfOrder.

@Test(timeout = 5000)
public void testUpdateNodeStatusOutOfOrder() 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.size() < 2) {
        Thread.sleep(10L);
    }
    nodeStatuses.clear();
    final NodeConnectionStatus oldStatus = new NodeConnectionStatus(-1L, nodeId1, NodeConnectionState.DISCONNECTED, DisconnectionCode.BLOCKED_BY_FIREWALL, null, 0L);
    final NodeStatusChangeMessage msg = new NodeStatusChangeMessage();
    msg.setNodeId(nodeId1);
    msg.setNodeConnectionStatus(oldStatus);
    coordinator.handle(msg);
    // Ensure that no status change message was send
    Thread.sleep(1000);
    assertTrue(nodeStatuses.isEmpty());
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeStatusChangeMessage(org.apache.nifi.cluster.protocol.message.NodeStatusChangeMessage) Test(org.junit.Test)

Aggregations

NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)2 NodeStatusChangeMessage (org.apache.nifi.cluster.protocol.message.NodeStatusChangeMessage)2 Test (org.junit.Test)1