Search in sources :

Example 16 with NodeConnectionStatus

use of org.apache.nifi.cluster.coordination.node.NodeConnectionStatus in project nifi by apache.

the class ClusterProtocolHeartbeatMonitor method getUpdatedStatuses.

private List<NodeConnectionStatus> getUpdatedStatuses(final List<NodeConnectionStatus> nodeStatusList) {
    // Map node's statuses by NodeIdentifier for quick & easy lookup
    final Map<NodeIdentifier, NodeConnectionStatus> nodeStatusMap = nodeStatusList.stream().collect(Collectors.toMap(status -> status.getNodeIdentifier(), Function.identity()));
    // Check if our connection status is the same for each Node Identifier and if not, add our version of the status
    // to a List of updated statuses.
    final List<NodeConnectionStatus> currentStatuses = clusterCoordinator.getConnectionStatuses();
    final List<NodeConnectionStatus> updatedStatuses = new ArrayList<>();
    for (final NodeConnectionStatus currentStatus : currentStatuses) {
        final NodeConnectionStatus nodeStatus = nodeStatusMap.get(currentStatus.getNodeIdentifier());
        if (!currentStatus.equals(nodeStatus)) {
            updatedStatuses.add(currentStatus);
        }
    }
    // If the node has any statuses that we do not have, add a REMOVED status to the update list
    final Set<NodeIdentifier> nodeIds = currentStatuses.stream().map(status -> status.getNodeIdentifier()).collect(Collectors.toSet());
    for (final NodeConnectionStatus nodeStatus : nodeStatusList) {
        if (!nodeIds.contains(nodeStatus.getNodeIdentifier())) {
            updatedStatuses.add(new NodeConnectionStatus(nodeStatus.getNodeIdentifier(), NodeConnectionState.REMOVED, null));
        }
    }
    logger.debug("\n\nCalculated diff between current cluster status and node cluster status as follows:\nNode: {}\nSelf: {}\nDifference: {}\n\n", nodeStatusList, currentStatuses, updatedStatuses);
    return updatedStatuses;
}
Also used : ClusterWorkloadResponseMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadResponseMessage) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) HeartbeatPayload(org.apache.nifi.cluster.protocol.HeartbeatPayload) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Function(java.util.function.Function) HeartbeatMessage(org.apache.nifi.cluster.protocol.message.HeartbeatMessage) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ClusterCoordinator(org.apache.nifi.cluster.coordination.ClusterCoordinator) MessageType(org.apache.nifi.cluster.protocol.message.ProtocolMessage.MessageType) NodeConnectionState(org.apache.nifi.cluster.coordination.node.NodeConnectionState) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) ProtocolHandler(org.apache.nifi.cluster.protocol.ProtocolHandler) HeartbeatResponseMessage(org.apache.nifi.cluster.protocol.message.HeartbeatResponseMessage) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Heartbeat(org.apache.nifi.cluster.protocol.Heartbeat) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ProtocolException(org.apache.nifi.cluster.protocol.ProtocolException) NiFiProperties(org.apache.nifi.util.NiFiProperties) ClusterWorkloadRequestMessage(org.apache.nifi.cluster.protocol.message.ClusterWorkloadRequestMessage) NodeWorkload(org.apache.nifi.cluster.coordination.node.NodeWorkload) ProtocolListener(org.apache.nifi.cluster.protocol.ProtocolListener) Collections(java.util.Collections) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ArrayList(java.util.ArrayList) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus)

Aggregations

NodeConnectionStatus (org.apache.nifi.cluster.coordination.node.NodeConnectionStatus)16 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)12 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ProtocolException (org.apache.nifi.cluster.protocol.ProtocolException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 List (java.util.List)3 NodeConnectionState (org.apache.nifi.cluster.coordination.node.NodeConnectionState)3 DataFlow (org.apache.nifi.cluster.protocol.DataFlow)3 HeartbeatPayload (org.apache.nifi.cluster.protocol.HeartbeatPayload)3 StandardDataFlow (org.apache.nifi.cluster.protocol.StandardDataFlow)3 HeartbeatMessage (org.apache.nifi.cluster.protocol.message.HeartbeatMessage)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2