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;
}
Aggregations