public Optional<Node> nodeIfOnline(TopicPartition partition, int id) {
        Node node = nodeById(id);
        PartitionInfo partitionInfo = partition(partition);

        if (node != null && partitionInfo != null &&
            !Arrays.asList(partitionInfo.offlineReplicas()).contains(node) &&
            Arrays.asList(partitionInfo.replicas()).contains(node)) {

            return Optional.of(node);
        } else {
            return Optional.empty();
        }
    }
Get the node by node id if the replica for the given partition is online
@param partition The TopicPartition
@param id The node id
@return the node
clients/src/main/java/org/apache/kafka/common/Cluster.java