Searches for the master node.

 @param [Array<Node>] nodes the nodes to search
 @return [Node] the found master node, nil if not found
505221
def guess_master(nodes)
      master_nodes = nodes.select { |node| node.master? }
      raise NoMasterError if master_nodes.empty?
      raise MultipleMastersError.new(master_nodes) if master_nodes.size > 1
      master_nodes.first
    end
1310861
def nodes_changed?(new_nodes)
      return true if address_for(@master) != new_nodes[:master]
      return true if different?(addresses_for(@slaves), new_nodes[:slaves])
      false
    end
1007683
private static Treenode search(Iterable<Treenode> root, String text, ITreenodeSearch search) {
        for (Treenode node : root) {
            if (search.isMatch(node, text)) {
                return node;
            }
        }
        return null;
    }
212213
def propfind(nodes)
      properties = { found: [], not_found: [] }

      find_properties_from_xml_elements nodes, properties

      properties[:found] = properties[:found].uniq.flatten if properties[:found]
      properties
    end
372177
def <<(node)
      @nodes << node
      @index_names.each { |name| add_to_index(name, value(node, name), node) }
      @contexts.each { |context| eval_context(context, node) }
      self
    end
203876
def master_for( key )
      return if @masters.empty?
      key = to_key(key)

      loop do
        break key if @masters.include? key
        break nil if :root == key

        if index = key.rindex(PATH_DELIMITER)
          key = key.slice(0, index)
        else
          key = :root
        end
      end
    end
149515
function MasterFinder (node) {
  let resolver = new EventEmitter()

  //  Debug
  const _debug = D('dnsmq-messagebus:masterfinder')
  const debug = (...args) => _debug(node.name, ...args)

  let _findingMaster = false

  /**
   * Connects to the coordination socket of all the reachable dnsNodes
   * to ask for the current master
   * Resolves as soon as it receives the first answer from a dnsNode
   * @alias resolve
   * @return {promise} An object containing the name and the pub/sub endpoints of the master node
   */
  function findMaster () {
    if (_findingMaster) return _findingMaster
    _findingMaster = new Promise((resolve, reject) => {
      let { host, coordinationPort } = node.settings
      debug(`seeking for master node at host '${host}'`)

      let resolveStart = Date.now()
      dns.resolve4(host, (err, addresses) => {
        if (err) {
          debug(`cannot resolve host '${host}'. Check DNS infrastructure.`)
          _findingMaster = false
          return reject(err)
        }
        debug(`resolved ${addresses.length} IP(s) for host '${host}' in ${Date.now() - resolveStart} ms`)

        let _resolved = false

        const onMasterFound = (master) => {
          if (_resolved) return
          _resolved = true

          _findingMaster = false

          debug(`discovered master node ${master.name}`)
          resolve(master)
        }
        const onTimeout = () => {
          if (_resolved) return
          _resolved = true

          _findingMaster = false

          debug(`failed to discover master node`)
          reject()
        }

        debug(`trying to get master coordinates from ${addresses.length} nodes`)
        addresses.forEach(address => {
          let messenger = zmq.socket('req')
          messenger.connect(`tcp://${address}:${coordinationPort}`)
          messenger.send(JSON.stringify({
            type: 'masterRequest',
            toAddress: address,
            from: node.name
          }))

          let _resolved = false
          const onEnd = (msgBuffer) => {
            if (_resolved) return
            _resolved = true
            messenger.removeListener('message', onEnd)
            messenger.close()

            let master = msgBuffer && JSON.parse(msgBuffer)
            if (master) onMasterFound(master)
          }
          messenger.once('message', onEnd)
          setTimeout(onEnd, HEARTBEAT_TIMEOUT)
        })

        setTimeout(onTimeout, HEARTBEAT_TIMEOUT)
      })
    })
    return _findingMaster
  }

  return Object.defineProperties(resolver, {
    isResolving: {get: () => !!_findingMaster},
    resolve: {value: findMaster}
  })
}
926160
def find_node(results, node_name)
      document = ::Nokogiri::XML(results.body)
      document.remove_namespaces!
      document.xpath("//#{node_name}").first
    end
399273
def find_servers
      # need a run_context to find anything in
      return nil unless run_context
      # If there are already servers in attribs use those
      return node[:etcd][:servers] if node.key?(:etcd) &&
                                      node[:etcd].key?(:servers)

      # if we have already searched in this run use those
      return node.run_state[:etcd_servers] if node.run_state.key? :etcd_servers

      # find nodes and build array of ip's
      etcd_nodes = search(:node, search_query)
      servers = etcd_nodes.map { |n| n[:ipaddress] }

      # store that in the run_state
      node.run_state[:etcd_servers] = servers
    end
809570
def gather_master_data(stackname)
      response = fetch_master_data(stackname)
      children = response.delete('children') || []
      result = { stackname => { stack_data: response } }
      children.each do |child|
        result.merge!(gather_master_data(child['name']))
      end
      result
    end
1223759
def traverse_subnodes(aParentNode)
      subnodes = aParentNode.subnodes
      broadcast(:before_subnodes, aParentNode, subnodes)

      # Let's proceed with the visit of subnodes
      subnodes.each { |a_node| a_node.accept(self) }

      broadcast(:after_subnodes, aParentNode, subnodes)
    end
812025
def __DepthFirstSearch(node, hashes):
        
        if node.LeftChild is None:
            hashes.add(node.Hash)
        else:
            MerkleTree.__DepthFirstSearch(node.LeftChild, hashes)
            MerkleTree.__DepthFirstSearch(node.RightChild, hashes)
159864
def node_ancestor(node, levels)
      while levels > 0
        node = node.node_parent
        return unless node
        levels -= 1
      end

      node
    end
678508
def parse(node)
      node.xpath('*').each do |node_children|
        case node_children.name
        when 'Relationship'
          @relationship << Relationship.new(parent: self).parse(node_children)
        end
      end
      self
    end
1276415
private DNode searchFrontendNode() {
        DNode result = DNode.NOT_FOUND;
        
        for (DNode node : nodes) {
            if (node.getFrontend()) {
                result = node;
                break;
            }
        }
        return result;
    }
51067
def manage_nodes
      # Re-discover nodes, since the state of the world may have been changed
      # by the time we've become the primary node manager.
      discover_nodes

      # ensure that slaves are correctly pointing to this master
      redirect_slaves_to(@master)

      # Periodically update master config state.
      while running? && master_manager?
        @zk_lock.assert!
        sleep(CHECK_INTERVAL)

        @lock.synchronize do
          snapshots = current_node_snapshots
          if ensure_sufficient_node_managers(snapshots)
            snapshots.each_key do |node|
              update_master_state(node, snapshots)
            end

            # flush current master state
            write_current_redis_nodes

            # check if we've exhausted our attempts to promote a master
            unless @master
              @master_promotion_attempts += 1
              raise NoMasterError if @master_promotion_attempts > MAX_PROMOTION_ATTEMPTS
            end
          end
        end
      end
    end
362092
@SuppressWarnings("unchecked")
    public static <T extends Node> void findNodes(List<Node> nodes, Class<T> cls, List<T> results) {
        for (Node n : nodes) {
            if (n instanceof ContainerNode) {
                findNodes(((ContainerNode) n).getNodes(), cls, results);
            }

            if (cls == n.getClass()) {
                results.add((T) n);
            }
        }
    }