Class DiscoveryNodes

java.lang.Object
org.elasticsearch.cluster.node.DiscoveryNodes
All Implemented Interfaces:
Iterable<DiscoveryNode>, Diffable<DiscoveryNodes>, SimpleDiffable<DiscoveryNodes>, Writeable

public class DiscoveryNodes extends Object implements Iterable<DiscoveryNode>, SimpleDiffable<DiscoveryNodes>
This class holds all DiscoveryNode in the cluster and provides convenience methods to access, modify merge / diff discovery nodes.
  • Field Details

  • Method Details

    • withMasterNodeId

      public DiscoveryNodes withMasterNodeId(@Nullable String masterNodeId)
    • iterator

      public Iterator<DiscoveryNode> iterator()
      Specified by:
      iterator in interface Iterable<DiscoveryNode>
    • stream

      public Stream<DiscoveryNode> stream()
    • getAllNodes

      public Collection<DiscoveryNode> getAllNodes()
    • size

      public int size()
    • isLocalNodeElectedMaster

      public boolean isLocalNodeElectedMaster()
      Returns true if the local node is the elected master node.
    • getTiersToNodeIds

      public Map<String,Set<String>> getTiersToNodeIds()
      Gets a Map of node roles to node IDs which have those roles.
      Returns:
      Map of node roles to node IDs which have those roles.
    • getSize

      public int getSize()
      Get the number of known nodes
      Returns:
      number of nodes
    • getNodes

      public Map<String,DiscoveryNode> getNodes()
      Get a Map of the discovered nodes arranged by their ids
      Returns:
      Map of the discovered nodes arranged by their ids
    • getDataNodes

      public Map<String,DiscoveryNode> getDataNodes()
      Get a Map of the discovered data nodes arranged by their ids
      Returns:
      Map of the discovered data nodes arranged by their ids
    • getMasterNodes

      public Map<String,DiscoveryNode> getMasterNodes()
      Get a Map of the discovered master nodes arranged by their ids
      Returns:
      Map of the discovered master nodes arranged by their ids
    • getIngestNodes

      public Map<String,DiscoveryNode> getIngestNodes()
      Returns:
      All the ingest nodes arranged by their ids
    • getMasterAndDataNodes

      public Map<String,DiscoveryNode> getMasterAndDataNodes()
      Get a Map of the discovered master and data nodes arranged by their ids
      Returns:
      Map of the discovered master and data nodes arranged by their ids
    • getCoordinatingOnlyNodes

      public Map<String,DiscoveryNode> getCoordinatingOnlyNodes()
      Get a Map of the coordinating only nodes (nodes which are neither master, nor data, nor ingest nodes) arranged by their ids
      Returns:
      Map of the coordinating only nodes arranged by their ids
    • mastersFirstStream

      public Stream<DiscoveryNode> mastersFirstStream()
      Returns a stream of all nodes, with master nodes at the front
    • get

      public DiscoveryNode get(String nodeId)
      Get a node by its id
      Parameters:
      nodeId - id of the wanted node
      Returns:
      wanted node if it exists. Otherwise null
    • nodeExists

      public boolean nodeExists(String nodeId)
      Determine if a given node id exists
      Parameters:
      nodeId - id of the node which existence should be verified
      Returns:
      true if the node exists. Otherwise false
    • nodeExists

      public boolean nodeExists(DiscoveryNode node)
      Determine if a given node exists
      Parameters:
      node - of the node which existence should be verified
      Returns:
      true if the node exists. Otherwise false
    • nodeExistsWithSameRoles

      public boolean nodeExistsWithSameRoles(DiscoveryNode discoveryNode)
      Determine if the given node exists and has the right roles. Supported roles vary by version, and our local cluster state might have come via an older master, so the roles may differ even if the node is otherwise identical.
    • getMasterNodeId

      public String getMasterNodeId()
      Get the id of the master node
      Returns:
      id of the master
    • getLocalNodeId

      public String getLocalNodeId()
      Get the id of the local node
      Returns:
      id of the local node
    • getLocalNode

      public DiscoveryNode getLocalNode()
      Get the local node
      Returns:
      local node
    • getMasterNode

      @Nullable public DiscoveryNode getMasterNode()
      Returns the master node, or null if there is no master node
    • findByAddress

      public DiscoveryNode findByAddress(TransportAddress address)
      Get a node by its address
      Parameters:
      address - TransportAddress of the wanted node
      Returns:
      node identified by the given address or null if no such node exists
    • hasByName

      public boolean hasByName(String name)
      Check if a node with provided name exists
      Returns:
      true node identified with provided name exists or false otherwise
    • getSmallestNonClientNodeVersion

      public Version getSmallestNonClientNodeVersion()
      Returns the version of the node with the oldest version in the cluster that is not a client node If there are no non-client nodes, Version.CURRENT will be returned.
      Returns:
      the oldest version in the cluster
    • getMaxDataNodeCompatibleIndexVersion

      public IndexVersion getMaxDataNodeCompatibleIndexVersion()
      Returns the highest index version supported by all data nodes in the cluster
    • getMinNodeVersion

      public Version getMinNodeVersion()
      Returns the version of the node with the oldest version in the cluster.
      Returns:
      the oldest version in the cluster
    • getMaxNodeVersion

      public Version getMaxNodeVersion()
      Returns the version of the node with the youngest version in the cluster
      Returns:
      the youngest version in the cluster
    • getMinSupportedIndexVersion

      public IndexVersion getMinSupportedIndexVersion()
      Returns the minimum index version supported by all nodes in the cluster
    • getNodeLeftGeneration

      public long getNodeLeftGeneration()
      Return the node-left generation, which is the number of times the cluster membership has been updated by removing one or more nodes.

      Since node-left events are rare, nodes can use the fact that this value has not changed to very efficiently verify that they have not been removed from the cluster. If the node-left generation changes then that indicates some node has left the cluster, which triggers some more expensive checks to determine the new cluster membership.

      Not tracked if the cluster has any nodes older than v8.9.0, in which case this method returns zero.

    • resolveNode

      public DiscoveryNode resolveNode(String node)
      Resolve a node with a given id
      Parameters:
      node - id of the node to discover
      Returns:
      discovered node matching the given id
      Throws:
      IllegalArgumentException - if more than one node matches the request or no nodes have been resolved
    • resolveNodes

      public String[] resolveNodes(String... nodes)
      Resolves a set of nodes according to the given sequence of node specifications. Implements the logic in various APIs that allow the user to run the action on a subset of the nodes in the cluster. See [Node specification] in the reference manual for full details. Works by tracking the current set of nodes and applying each node specification in sequence. The set starts out empty and each node specification may either add or remove nodes. For instance: - _local, _master and _all respectively add to the subset the local node, the currently-elected master, and all the nodes - node IDs, names, hostnames and IP addresses all add to the subset any nodes which match - a wildcard-based pattern of the form "attr*:value*" adds to the subset all nodes with a matching attribute with a matching value - role:true adds to the subset all nodes with a matching role - role:false removes from the subset all nodes with a matching role. An empty sequence of node specifications returns all nodes, since the corresponding actions run on all nodes by default.
    • delta

      public DiscoveryNodes.Delta delta(DiscoveryNodes other)
      Returns the changes comparing this nodes to the provided nodes.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • readFrom

      public static DiscoveryNodes readFrom(StreamInput in, DiscoveryNode localNode) throws IOException
      Throws:
      IOException
    • readDiffFrom

      public static Diff<DiscoveryNodes> readDiffFrom(StreamInput in, DiscoveryNode localNode) throws IOException
      Throws:
      IOException
    • builder

      public static DiscoveryNodes.Builder builder()
    • builder

      public static DiscoveryNodes.Builder builder(DiscoveryNodes nodes)
    • addCommaSeparatedNodesWithoutAttributes

      public static void addCommaSeparatedNodesWithoutAttributes(Iterator<DiscoveryNode> iterator, StringBuilder stringBuilder)