Java Code Examples for org.elasticsearch.cluster.node.DiscoveryNode#getId()

The following examples show how to use org.elasticsearch.cluster.node.DiscoveryNode#getId() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: crate   File: CoordinatorTests.java    License: Apache License 2.0 6 votes vote down vote up
public static Runnable onNodeLog(DiscoveryNode node, Runnable runnable) {
    final String nodeId = "{" + node.getId() + "}{" + node.getEphemeralId() + "}";
    return new Runnable() {
        @Override
        public void run() {
            try (CloseableThreadContext.Instance ignored = CloseableThreadContext.put("nodeId", nodeId)) {
                runnable.run();
            }
        }

        @Override
        public String toString() {
            return nodeId + ": " + runnable.toString();
        }
    };
}
 
Example 2
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    String nodeId;
    DiscoveryNode node;
    builder.startObject(NODES_KEY);
    for (ADStatsNodeResponse adStats : getNodes()) {
        node = adStats.getNode();
        nodeId = node.getId();
        builder.startObject(nodeId);
        adStats.toXContent(builder, params);
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
 
Example 3
Source Project: Elasticsearch   File: TaskInfo.java    License: Apache License 2.0 5 votes vote down vote up
public TaskInfo(DiscoveryNode node, long id, String type, String action, String description, Task.Status status, long startTime,
                long runningTimeNanos, TaskId parentTaskId) {
    this.node = node;
    this.taskId = new TaskId(node.getId(), id);
    this.type = type;
    this.action = action;
    this.description = description;
    this.status = status;
    this.startTime = startTime;
    this.runningTimeNanos = runningTimeNanos;
    this.parentTaskId = parentTaskId;
}
 
Example 4
private void sendNodeRequest(final DiscoveryNode node, List<ShardRouting> shards, final int nodeIndex) {
    try {
        NodeRequest nodeRequest = new NodeRequest(node.getId(), request, shards);
        if (task != null) {
            nodeRequest.setParentTask(clusterService.localNode().id(), task.getId());
            taskManager.registerChildTask(task, node.getId());
        }
        transportService.sendRequest(node, transportNodeBroadcastAction, nodeRequest, new BaseTransportResponseHandler<NodeResponse>() {
            @Override
            public NodeResponse newInstance() {
                return new NodeResponse();
            }

            @Override
            public void handleResponse(NodeResponse response) {
                onNodeResponse(node, nodeIndex, response);
            }

            @Override
            public void handleException(TransportException exp) {
                onNodeFailure(node, nodeIndex, exp);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    } catch (Throwable e) {
        onNodeFailure(node, nodeIndex, e);
    }
}
 
Example 5
private void sendNodeRequest(final DiscoveryNode node, List<ShardRouting> shards, final int nodeIndex) {
    try {
        NodeRequest nodeRequest = new NodeRequest(node.getId(), request, shards);
        if (task != null) {
            nodeRequest.setParentTask(clusterService.localNode().getId(), task.getId());
        }
        transportService.sendRequest(node, transportNodeBroadcastAction, nodeRequest, new TransportResponseHandler<NodeResponse>() {

            @Override
            public NodeResponse read(StreamInput in) throws IOException {
                return new NodeResponse(in);
            }

            @Override
            public void handleResponse(NodeResponse response) {
                onNodeResponse(node, nodeIndex, response);
            }

            @Override
            public void handleException(TransportException exp) {
                onNodeFailure(node, nodeIndex, exp);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    } catch (Exception e) {
        onNodeFailure(node, nodeIndex, e);
    }
}
 
Example 6
protected void onNodeFailure(DiscoveryNode node, int nodeIndex, Throwable t) {
    String nodeId = node.getId();
    if (logger.isDebugEnabled() && !(t instanceof NodeShouldNotConnectException)) {
        logger.debug(new ParameterizedMessage("failed to execute [{}] on node [{}]", actionName, nodeId), t);
    }

    // this is defensive to protect against the possibility of double invocation
    // the current implementation of TransportService#sendRequest guards against this
    // but concurrency is hard, safety is important, and the small performance loss here does not matter
    if (responses.compareAndSet(nodeIndex, null, new FailedNodeException(nodeId, "Failed node [" + nodeId + "]", t))) {
        if (counter.incrementAndGet() == responses.length()) {
            onCompletion();
        }
    }
}
 
Example 7
Source Project: crate   File: NodeSelection.java    License: Apache License 2.0 5 votes vote down vote up
public static String resolveNodeId(DiscoveryNodes nodes, String nodeIdOrName) {
    if (nodes.nodeExists(nodeIdOrName)) {
        return nodeIdOrName;
    }
    for (DiscoveryNode node : nodes.get()) {
        if (nodeIdOrName.equalsIgnoreCase(node.getName())) {
            return node.getId();
        }
    }
    throw new IllegalArgumentException(
        String.format(Locale.ENGLISH, "Node: \'%s\' could not be found", nodeIdOrName)
    );
}
 
Example 8
Source Project: crate   File: NodeStatsCollectSource.java    License: Apache License 2.0 5 votes vote down vote up
static Collection<DiscoveryNode> filterNodes(Collection<DiscoveryNode> nodes, Symbol predicate, Functions functions) {
    var expressions = SysNodesTableInfo.create().expressions();
    var nameExpr = expressions.get(SysNodesTableInfo.Columns.NAME).create();
    var idExpr = expressions.get(SysNodesTableInfo.Columns.ID).create();
    MapBackedRefResolver referenceResolver = new MapBackedRefResolver(Map.of(
        SysNodesTableInfo.Columns.NAME, nameExpr,
        SysNodesTableInfo.Columns.ID, idExpr)
    );
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(
        functions,
        RowGranularity.DOC,
        referenceResolver,
        null
    );
    List<DiscoveryNode> newNodes = new ArrayList<>();
    for (DiscoveryNode node : nodes) {
        String nodeId = node.getId();
        NodeStatsContext statsContext = new NodeStatsContext(nodeId, node.getName());
        nameExpr.setNextRow(statsContext);
        idExpr.setNextRow(statsContext);
        Symbol normalized = normalizer.normalize(predicate, CoordinatorTxnCtx.systemTransactionContext());
        if (normalized.equals(predicate)) {
            return nodes; // No local available sys nodes columns in where clause
        }
        if (WhereClause.canMatch(normalized)) {
            newNodes.add(node);
        }
    }
    return newNodes;
}
 
Example 9
Source Project: crate   File: NodeStats.java    License: Apache License 2.0 5 votes vote down vote up
private CompletableFuture<List<NodeStatsContext>> getStatsFromRemote(Set<ColumnIdent> toCollect) {
    final CompletableFuture<List<NodeStatsContext>> nodeStatsContextsFuture = new CompletableFuture<>();
    final List<NodeStatsContext> rows = new ArrayList<>(nodes.size());
    final AtomicInteger remainingNodesToCollect = new AtomicInteger(nodes.size());
    for (final DiscoveryNode node : nodes) {
        final String nodeId = node.getId();
        NodeStatsRequest request = new NodeStatsRequest(toCollect);
        nodeStatsAction.execute(nodeId, request, new ActionListener<NodeStatsResponse>() {
            @Override
            public void onResponse(NodeStatsResponse response) {
                synchronized (rows) {
                    rows.add(response.nodeStatsContext());
                }
                if (remainingNodesToCollect.decrementAndGet() == 0) {
                    nodeStatsContextsFuture.complete(rows);
                }
            }

            @Override
            public void onFailure(Exception e) {
                Throwable t = SQLExceptions.unwrap(e);
                if (isTimeoutOrNodeNotReachable(t)) {
                    NodeStatsContext statsContext = new NodeStatsContext(nodeId, node.getName());
                    synchronized (rows) {
                        rows.add(statsContext);
                    }
                    if (remainingNodesToCollect.decrementAndGet() == 0) {
                        nodeStatsContextsFuture.complete(rows);
                    }
                } else {
                    nodeStatsContextsFuture.completeExceptionally(t);
                }
            }
        }, REQUEST_TIMEOUT);
    }
    return nodeStatsContextsFuture;
}
 
Example 10
Source Project: crate   File: DecommissioningService.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static Map<String, Object> getRemovedDecommissionedNodes(DiscoveryNodes.Delta nodesDelta, Settings transientSettings) {
    Map<String, Object> toRemove = null;
    for (DiscoveryNode discoveryNode : nodesDelta.removedNodes()) {
        Settings decommissionSettings = DECOMMISSION_INTERNAL_SETTING_GROUP.setting().get(transientSettings);
        String nodeId = discoveryNode.getId();
        if (decommissionSettings.hasValue(nodeId)) {
            if (toRemove == null) {
                toRemove = new HashMap<>();
            }
            toRemove.put(DECOMMISSION_PREFIX + nodeId, null);
        }
    }
    return toRemove;
}
 
Example 11
Source Project: crate   File: Coordinator.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean electionQuorumContains(ClusterState lastAcceptedState, DiscoveryNode node) {
    final String nodeId = node.getId();
    return lastAcceptedState.getLastCommittedConfiguration().getNodeIds().contains(nodeId)
        || lastAcceptedState.getLastAcceptedConfiguration().getNodeIds().contains(nodeId);
}
 
Example 12
Source Project: crate   File: CoordinationMetaData.java    License: Apache License 2.0 4 votes vote down vote up
public VotingConfigExclusion(DiscoveryNode node) {
    this(node.getId(), node.getName());
}
 
Example 13
Source Project: crate   File: TransportNodesAction.java    License: Apache License 2.0 4 votes vote down vote up
void start() {
    final DiscoveryNode[] nodes = request.concreteNodes();
    if (nodes.length == 0) {
        // nothing to notify
        threadPool.generic().execute(() -> listener.onResponse(newResponse(request, responses)));
        return;
    }
    TransportRequestOptions.Builder builder = TransportRequestOptions.builder();
    if (request.timeout() != null) {
        builder.withTimeout(request.timeout());
    }
    builder.withCompress(transportCompress());
    for (int i = 0; i < nodes.length; i++) {
        final int idx = i;
        final DiscoveryNode node = nodes[i];
        final String nodeId = node.getId();
        try {
            TransportRequest nodeRequest = newNodeRequest(nodeId, request);
            if (task != null) {
                nodeRequest.setParentTask(clusterService.localNode().getId(), task.getId());
            }
            transportService.sendRequest(
                node,
                transportNodeAction,
                nodeRequest,
                builder.build(),
                new TransportResponseHandler<NodeResponse>() {

                    @Override
                    public NodeResponse read(StreamInput in) throws IOException {
                        return TransportNodesAction.this.read(in);
                    }

                    @Override
                    public void handleResponse(NodeResponse response) {
                        onOperation(idx, response);
                    }

                    @Override
                    public void handleException(TransportException exp) {
                        onFailure(idx, node.getId(), exp);
                    }

                    @Override
                    public String executor() {
                        return ThreadPool.Names.SAME;
                    }
                }
            );
        } catch (Exception e) {
            onFailure(idx, nodeId, e);
        }
    }
}