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); }
public ObjectIntHashMap<String> nodesPerAttributesCounts(String attributeName) { ObjectIntHashMap<String> nodesPerAttributesCounts = nodesPerAttributeNames.get(attributeName); if (nodesPerAttributesCounts != null) { return nodesPerAttributesCounts; } nodesPerAttributesCounts = new ObjectIntHashMap<>(); for (RoutingNode routingNode : this) { String attrValue = routingNode.node().getAttributes().get(attributeName); nodesPerAttributesCounts.addTo(attrValue, 1); } nodesPerAttributeNames.put(attributeName, nodesPerAttributesCounts); return nodesPerAttributesCounts; }
static Predicate<DiscoveryNode> getNodePredicate(Settings settings) { if (REMOTE_NODE_ATTRIBUTE.exists(settings)) { // nodes can be tagged with node.attr.remote_gateway: true to allow a node to be a gateway node for cross cluster search String attribute = REMOTE_NODE_ATTRIBUTE.get(settings); return DEFAULT_NODE_PREDICATE.and((node) -> Booleans.parseBoolean(node.getAttributes().getOrDefault(attribute, "false"))); } return DEFAULT_NODE_PREDICATE; }
/** * Generates X-Content for a {@link DiscoveryNode} that leaves off some of the non-critical fields. */ public static XContentBuilder discoveryNodeToXContent(DiscoveryNode node, boolean outerObjectWritten, XContentBuilder builder) throws IOException { builder.field(outerObjectWritten ? "id" : "node_id", node.getId()); builder.field(outerObjectWritten ? "name" : "node_name", node.getName()); builder.field("transport_address", node.getAddress().toString()); if (node.getAttributes().isEmpty() == false) { builder.startObject(outerObjectWritten ? "attributes" : "node_attributes"); for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) { builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); } return builder; }
if (!node.getAttributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry<String, String> attrEntry : node.getAttributes().entrySet()) { builder.field(attrEntry.getKey(), attrEntry.getValue());
private static DiscoveryNode maybeAddProxyAddress(String proxyAddress, DiscoveryNode node) { if (proxyAddress == null || proxyAddress.isEmpty()) { return node; } else { // resovle proxy address lazy here InetSocketAddress proxyInetAddress = RemoteClusterAware.parseSeedAddress(proxyAddress); return new DiscoveryNode(node.getName(), node.getId(), node.getEphemeralId(), node.getHostName(), node .getHostAddress(), new TransportAddress(proxyInetAddress), node.getAttributes(), node.getRoles(), node.getVersion()); } }
String nodeAttributeValue = node.getAttributes().get(attr); if (nodeAttributeValue == null) { if (opType == OpType.AND) {
for (String awarenessAttribute : awarenessAttributes) { if (!node.node().getAttributes().containsKey(awarenessAttribute)) { return allocation.decision(Decision.NO, NAME, "node does not contain the awareness attribute [%s]; required attributes cluster setting [%s=%s]", shardPerAttribute.addTo(routingNode.node().getAttributes().get(awarenessAttribute), 1); if (!node.nodeId().equals(nodeId)) { shardPerAttribute.putOrAdd(allocation.routingNodes().node(nodeId).node().getAttributes().get(awarenessAttribute), 0, -1); shardPerAttribute.addTo(node.node().getAttributes().get(awarenessAttribute), 1); shardPerAttribute.addTo(node.node().getAttributes().get(awarenessAttribute), 1); int currentNodeCount = shardPerAttribute.get(node.node().getAttributes().get(awarenessAttribute));
newNodes.add(new DiscoveryNode(nodeWithInfo.getName(), nodeWithInfo.getId(), nodeWithInfo.getEphemeralId(), nodeWithInfo.getHostName(), nodeWithInfo.getHostAddress(), listedNode.getAddress(), nodeWithInfo.getAttributes(), nodeWithInfo.getRoles(), nodeWithInfo.getVersion()));
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo) { boolean fullId = req.paramAsBoolean("full_id", false); DiscoveryNodes nodes = state.getState().nodes(); Table table = getTableWithHeader(req); for (DiscoveryNode node : nodes) { NodeInfo info = nodesInfo.getNodesMap().get(node.getId()); for (Map.Entry<String, String> attrEntry : node.getAttributes().entrySet()) { table.startRow(); table.addCell(node.getName()); table.addCell(fullId ? node.getId() : Strings.substring(node.getId(), 0, 4)); table.addCell(info == null ? null : info.getProcess().getId()); table.addCell(node.getHostName()); table.addCell(node.getHostAddress()); table.addCell(node.getAddress().address().getPort()); table.addCell(attrEntry.getKey()); table.addCell(attrEntry.getValue()); table.endRow(); } } return table; } }
for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) { String attrName = entry.getKey(); String attrValue = entry.getValue();
if (!nodeInfo.getNode().getAttributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry<String, String> entry : nodeInfo.getNode().getAttributes().entrySet()) { builder.field(entry.getKey(), entry.getValue());
if (!getNode().getAttributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry<String, String> attrEntry : getNode().getAttributes().entrySet()) { builder.field(attrEntry.getKey(), attrEntry.getValue());
public ObjectIntHashMap<String> nodesPerAttributesCounts(String attributeName) { ObjectIntHashMap<String> nodesPerAttributesCounts = nodesPerAttributeNames.get(attributeName); if (nodesPerAttributesCounts != null) { return nodesPerAttributesCounts; } nodesPerAttributesCounts = new ObjectIntHashMap<>(); for (RoutingNode routingNode : this) { String attrValue = routingNode.node().getAttributes().get(attributeName); nodesPerAttributesCounts.addTo(attrValue, 1); } nodesPerAttributeNames.put(attributeName, nodesPerAttributesCounts); return nodesPerAttributesCounts; }
public ObjectIntHashMap<String> nodesPerAttributesCounts(String attributeName) { ObjectIntHashMap<String> nodesPerAttributesCounts = nodesPerAttributeNames.get(attributeName); if (nodesPerAttributesCounts != null) { return nodesPerAttributesCounts; } nodesPerAttributesCounts = new ObjectIntHashMap<>(); for (RoutingNode routingNode : this) { String attrValue = routingNode.node().getAttributes().get(attributeName); nodesPerAttributesCounts.addTo(attrValue, 1); } nodesPerAttributeNames.put(attributeName, nodesPerAttributesCounts); return nodesPerAttributesCounts; }
public ObjectIntHashMap<String> nodesPerAttributesCounts(String attributeName) { ObjectIntHashMap<String> nodesPerAttributesCounts = nodesPerAttributeNames.get(attributeName); if (nodesPerAttributesCounts != null) { return nodesPerAttributesCounts; } nodesPerAttributesCounts = new ObjectIntHashMap<>(); for (RoutingNode routingNode : this) { String attrValue = routingNode.node().getAttributes().get(attributeName); nodesPerAttributesCounts.addTo(attrValue, 1); } nodesPerAttributeNames.put(attributeName, nodesPerAttributesCounts); return nodesPerAttributesCounts; }
static Predicate<DiscoveryNode> getNodePredicate(Settings settings) { if (REMOTE_NODE_ATTRIBUTE.exists(settings)) { // nodes can be tagged with node.attr.remote_gateway: true to allow a node to be a gateway node for cross cluster search String attribute = REMOTE_NODE_ATTRIBUTE.get(settings); return DEFAULT_NODE_PREDICATE.and((node) -> Booleans.parseBoolean(node.getAttributes().getOrDefault(attribute, "false"))); } return DEFAULT_NODE_PREDICATE; }
static Predicate<DiscoveryNode> getNodePredicate(Settings settings) { if (REMOTE_NODE_ATTRIBUTE.exists(settings)) { // nodes can be tagged with node.attr.remote_gateway: true to allow a node to be a gateway node for cross cluster search String attribute = REMOTE_NODE_ATTRIBUTE.get(settings); return DEFAULT_NODE_PREDICATE.and((node) -> Booleans.parseBoolean(node.getAttributes().getOrDefault(attribute, "false"))); } return DEFAULT_NODE_PREDICATE; }
/** * Generates X-Content for a {@link DiscoveryNode} that leaves off some of the non-critical fields. */ public static XContentBuilder discoveryNodeToXContent(DiscoveryNode node, boolean outerObjectWritten, XContentBuilder builder) throws IOException { builder.field(outerObjectWritten ? "id" : "node_id", node.getId()); builder.field(outerObjectWritten ? "name" : "node_name", node.getName()); builder.field("transport_address", node.getAddress().toString()); if (node.getAttributes().isEmpty() == false) { builder.startObject(outerObjectWritten ? "attributes" : "node_attributes"); for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) { builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); } return builder; }
private static DiscoveryNode maybeAddProxyAddress(String proxyAddress, DiscoveryNode node) { if (proxyAddress == null || proxyAddress.isEmpty()) { return node; } else { // resovle proxy address lazy here InetSocketAddress proxyInetAddress = RemoteClusterAware.parseSeedAddress(proxyAddress); return new DiscoveryNode(node.getName(), node.getId(), node.getEphemeralId(), node.getHostName(), node .getHostAddress(), new TransportAddress(proxyInetAddress), node.getAttributes(), node.getRoles(), node.getVersion()); } }