本文整理汇总了Java中org.elasticsearch.cluster.node.DiscoveryNodes.get方法的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryNodes.get方法的具体用法?Java DiscoveryNodes.get怎么用?Java DiscoveryNodes.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.cluster.node.DiscoveryNodes
的用法示例。
在下文中一共展示了DiscoveryNodes.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nodesInclude
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
/**
* Returns a set of nodes that have at least one shard of the given index.
*/
public synchronized Set<String> nodesInclude(String index) {
if (clusterService().state().routingTable().hasIndex(index)) {
List<ShardRouting> allShards = clusterService().state().routingTable().allShards(index);
DiscoveryNodes discoveryNodes = clusterService().state().getNodes();
Set<String> nodes = new HashSet<>();
for (ShardRouting shardRouting : allShards) {
if (shardRouting.assignedToNode()) {
DiscoveryNode discoveryNode = discoveryNodes.get(shardRouting.currentNodeId());
nodes.add(discoveryNode.getName());
}
}
return nodes;
}
return Collections.emptySet();
}
示例2: buildTable
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
private Table buildTable(RestRequest request, ClusterStateResponse state) {
Table table = getTableWithHeader(request);
DiscoveryNodes nodes = state.getState().nodes();
table.startRow();
DiscoveryNode master = nodes.get(nodes.getMasterNodeId());
if (master == null) {
table.addCell("-");
table.addCell("-");
table.addCell("-");
table.addCell("-");
} else {
table.addCell(master.getId());
table.addCell(master.getHostName());
table.addCell(master.getHostAddress());
table.addCell(master.getName());
}
table.endRow();
return table;
}
示例3: collectAttributeShards
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
private static List<ShardRouting> collectAttributeShards(AttributesKey key, DiscoveryNodes nodes, ArrayList<ShardRouting> from) {
final ArrayList<ShardRouting> to = new ArrayList<>();
for (final String attribute : key.attributes) {
final String localAttributeValue = nodes.getLocalNode().getAttributes().get(attribute);
if (localAttributeValue != null) {
for (Iterator<ShardRouting> iterator = from.iterator(); iterator.hasNext(); ) {
ShardRouting fromShard = iterator.next();
final DiscoveryNode discoveryNode = nodes.get(fromShard.currentNodeId());
if (discoveryNode == null) {
iterator.remove(); // node is not present anymore - ignore shard
} else if (localAttributeValue.equals(discoveryNode.getAttributes().get(attribute))) {
iterator.remove();
to.add(fromShard);
}
}
}
}
return Collections.unmodifiableList(to);
}
示例4: buildTable
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
private Table buildTable(RestRequest request, ClusterStateResponse state) {
Table table = getTableWithHeader(request);
DiscoveryNodes nodes = state.getState().nodes();
table.startRow();
DiscoveryNode master = nodes.get(nodes.masterNodeId());
if (master == null) {
table.addCell("-");
table.addCell("-");
table.addCell("-");
table.addCell("-");
} else {
table.addCell(master.getId());
table.addCell(master.getHostName());
table.addCell(master.getHostAddress());
table.addCell(master.getName());
}
table.endRow();
return table;
}
示例5: collectAttributeShards
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
private static List<ShardRouting> collectAttributeShards(AttributesKey key, DiscoveryNodes nodes, ArrayList<ShardRouting> from) {
final ArrayList<ShardRouting> to = new ArrayList<>();
for (final String attribute : key.attributes) {
final String localAttributeValue = nodes.localNode().attributes().get(attribute);
if (localAttributeValue != null) {
for (Iterator<ShardRouting> iterator = from.iterator(); iterator.hasNext(); ) {
ShardRouting fromShard = iterator.next();
final DiscoveryNode discoveryNode = nodes.get(fromShard.currentNodeId());
if (discoveryNode == null) {
iterator.remove(); // node is not present anymore - ignore shard
} else if (localAttributeValue.equals(discoveryNode.attributes().get(attribute))) {
iterator.remove();
to.add(fromShard);
}
}
}
}
return Collections.unmodifiableList(to);
}
示例6: buildRow
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
private void buildRow(Table table, boolean fullId, boolean detailed, DiscoveryNodes discoveryNodes, TaskInfo taskInfo) {
table.startRow();
String nodeId = taskInfo.getTaskId().getNodeId();
DiscoveryNode node = discoveryNodes.get(nodeId);
table.addCell(taskInfo.getId());
table.addCell(taskInfo.getAction());
table.addCell(taskInfo.getTaskId().toString());
if (taskInfo.getParentTaskId().isSet()) {
table.addCell(taskInfo.getParentTaskId().toString());
} else {
table.addCell("-");
}
table.addCell(taskInfo.getType());
table.addCell(taskInfo.getStartTime());
table.addCell(dateFormat.print(taskInfo.getStartTime()));
table.addCell(taskInfo.getRunningTimeNanos());
table.addCell(TimeValue.timeValueNanos(taskInfo.getRunningTimeNanos()).toString());
// Node information. Note that the node may be null because it has left the cluster between when we got this response and now.
table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4));
table.addCell(node == null ? "-" : node.getHostAddress());
table.addCell(node.getAddress().address().getPort());
table.addCell(node == null ? "-" : node.getName());
table.addCell(node == null ? "-" : node.getVersion().toString());
if (detailed) {
table.addCell(taskInfo.getDescription());
}
table.endRow();
}
示例7: findSourceNodeForPeerRecovery
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
/**
* Finds the routing source node for peer recovery, return null if its not found. Note, this method expects the shard
* routing to *require* peer recovery, use {@link #isPeerRecovery(org.elasticsearch.cluster.routing.ShardRouting)} to
* check if its needed or not.
*/
private DiscoveryNode findSourceNodeForPeerRecovery(RoutingTable routingTable, DiscoveryNodes nodes, ShardRouting shardRouting) {
DiscoveryNode sourceNode = null;
if (!shardRouting.primary()) {
IndexShardRoutingTable shardRoutingTable = routingTable.index(shardRouting.index()).shard(shardRouting.id());
for (ShardRouting entry : shardRoutingTable) {
if (entry.primary() && entry.active()) {
// only recover from started primary, if we can't find one, we will do it next round
sourceNode = nodes.get(entry.currentNodeId());
if (sourceNode == null) {
logger.trace("can't find replica source node because primary shard {} is assigned to an unknown node.", entry);
return null;
}
break;
}
}
if (sourceNode == null) {
logger.trace("can't find replica source node for {} because a primary shard can not be found.", shardRouting.shardId());
}
} else if (shardRouting.relocatingNodeId() != null) {
sourceNode = nodes.get(shardRouting.relocatingNodeId());
if (sourceNode == null) {
logger.trace("can't find relocation source node for shard {} because it is assigned to an unknown node [{}].", shardRouting.shardId(), shardRouting.relocatingNodeId());
}
} else {
throw new IllegalStateException("trying to find source node for peer recovery when routing state means no peer recovery: " + shardRouting);
}
return sourceNode;
}
示例8: filterNodeIds
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
protected String[] filterNodeIds(DiscoveryNodes nodes, String[] nodesIds) {
// Filter out all old nodes that don't support task management API
List<String> supportedNodes = new ArrayList<>(nodesIds.length);
for (String nodeId : nodesIds) {
DiscoveryNode node = nodes.get(nodeId);
if(node != null && node.version().onOrAfter(Version.V_2_3_0)) {
supportedNodes.add(nodeId);
}
}
return supportedNodes.toArray(new String[supportedNodes.size()]);
}
示例9: toXContentGroupedByNode
import org.elasticsearch.cluster.node.DiscoveryNodes; //导入方法依赖的package包/类
/**
* Convert this task response to XContent grouping by executing nodes.
*/
public XContentBuilder toXContentGroupedByNode(XContentBuilder builder, Params params, DiscoveryNodes discoveryNodes)
throws IOException {
toXContentCommon(builder, params);
builder.startObject("nodes");
for (Map.Entry<String, List<TaskInfo>> entry : getPerNodeTasks().entrySet()) {
DiscoveryNode node = discoveryNodes.get(entry.getKey());
builder.startObject(entry.getKey());
if (node != null) {
// If the node is no longer part of the cluster, oh well, we'll just skip it's useful information.
builder.field("name", node.getName());
builder.field("transport_address", node.getAddress().toString());
builder.field("host", node.getHostName());
builder.field("ip", node.getAddress());
builder.startArray("roles");
for (DiscoveryNode.Role role : node.getRoles()) {
builder.value(role.getRoleName());
}
builder.endArray();
if (!node.getAttributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> attrEntry : node.getAttributes().entrySet()) {
builder.field(attrEntry.getKey(), attrEntry.getValue());
}
builder.endObject();
}
}
builder.startObject("tasks");
for(TaskInfo task : entry.getValue()) {
builder.startObject(task.getTaskId().toString());
task.toXContent(builder, params);
builder.endObject();
}
builder.endObject();
builder.endObject();
}
builder.endObject();
return builder;
}