Search in sources :

Example 1 with NodeStatsResponse

use of io.crate.executor.transport.NodeStatsResponse in project crate by crate.

the class NodeStatsIterator method getNodeStatsContextFromRemoteState.

private CompletableFuture<List<NodeStatsContext>> getNodeStatsContextFromRemoteState(Set<ColumnIdent> toCollect) {
    final CompletableFuture<List<NodeStatsContext>> nodeStatsContextsFuture = new CompletableFuture<>();
    final List<NodeStatsContext> rows = Collections.synchronizedList(new ArrayList<NodeStatsContext>(nodes.size()));
    final AtomicInteger remainingNodesToCollect = new AtomicInteger(nodes.size());
    for (final DiscoveryNode node : nodes) {
        final String nodeId = node.getId();
        final NodeStatsRequest request = new NodeStatsRequest(toCollect);
        transportStatTablesAction.execute(nodeId, request, new ActionListener<NodeStatsResponse>() {

            @Override
            public void onResponse(NodeStatsResponse response) {
                rows.add(response.nodeStatsContext());
                if (remainingNodesToCollect.decrementAndGet() == 0) {
                    nodeStatsContextsFuture.complete(rows);
                }
            }

            @Override
            public void onFailure(Throwable t) {
                if (t instanceof ReceiveTimeoutTransportException) {
                    rows.add(new NodeStatsContext(nodeId, node.name()));
                    if (remainingNodesToCollect.decrementAndGet() == 0) {
                        nodeStatsContextsFuture.complete(rows);
                    }
                } else {
                    nodeStatsContextsFuture.completeExceptionally(t);
                }
            }
        }, TimeValue.timeValueMillis(3000L));
    }
    return nodeStatsContextsFuture;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NodeStatsResponse(io.crate.executor.transport.NodeStatsResponse) ReceiveTimeoutTransportException(org.elasticsearch.transport.ReceiveTimeoutTransportException) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeStatsRequest(io.crate.executor.transport.NodeStatsRequest) NodeStatsContext(io.crate.operation.reference.sys.node.NodeStatsContext)

Aggregations

NodeStatsRequest (io.crate.executor.transport.NodeStatsRequest)1 NodeStatsResponse (io.crate.executor.transport.NodeStatsResponse)1 NodeStatsContext (io.crate.operation.reference.sys.node.NodeStatsContext)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 ReceiveTimeoutTransportException (org.elasticsearch.transport.ReceiveTimeoutTransportException)1