parameters: (addresses, path)
return_statement: return address
docstring: Resolve the leader using a znode path. ZooKeeper imposes a total
      order on the elements of the queue, guaranteeing that the
      oldest element of the queue is the first one. We can
      thus return the first address we get from ZooKeeper.
docstring_summary: Resolve the leader using a znode path. ZooKeeper imposes a total
      order on the elements of the queue, guaranteeing that the
      oldest element of the queue is the first one. We can
      thus return the first address we get from ZooKeeper.
docstring_tokens: Resolve the leader using a znode path . ZooKeeper imposes a total order on the elements of the queue guaranteeing that the oldest element of the queue is the first one . We can thus return the first address we get from ZooKeeper .
function: def zookeeper_resolve_leader(addresses, path):
      """
      Resolve the leader using a znode path. ZooKeeper imposes a total
      order on the elements of the queue, guaranteeing that the
      oldest element of the queue is the first one. We can
      thus return the first address we get from ZooKeeper.
      """
      hosts = ",".join(addresses)
  
      try:
          zk = KazooClient(hosts=hosts)
          zk.start()
      except Exception as exception:
          raise CLIException("Unable to initialize Zookeeper Client: {error}"
                             .format(error=exception))
  
      try:
          children = zk.get_children(path)
      except Exception as exception:
          raise CLIException("Unable to get children of {zk_path}: {error}"
                             .format(zk_path=path, error=exception))
  
      masters = sorted(
          # 'json.info' is the prefix for master nodes.
          child for child in children if child.startswith("json.info")
      )
  
      address = ""
      for master in masters:
          try:
              node_path = "{path}/{node}".format(path=path, node=master)
              json_data, _ = zk.get(node_path)
          except Exception as exception:
              raise CLIException("Unable to get the value of '{node}': {error}"
                                 .format(node=node_path, error=exception))
  
          try:
              data = json.loads(json_data)
          except Exception as exception:
              raise CLIException("Could not load JSON from '{data}': {error}"
                                 .format(data=data, error=str(exception)))
  
          if ("address" in data and "ip" in data["address"] and
                  "port" in data["address"]):
              address = "{ip}:{port}".format(ip=data["address"]["ip"],
                                             port=data["address"]["port"])
              break
  
      try:
          zk.stop()
      except Exception as exception:
          raise CLIException("Unable to stop Zookeeper Client: {error}"
                             .format(error=exception))
  
      if not address:
          raise CLIException("Unable to resolve the leading"
                             " master using ZooKeeper")
      return address
function_tokens: def zookeeper_resolve_leader ( addresses , path ) : hosts = "," . join ( addresses ) try : zk = KazooClient ( hosts = hosts ) zk . start ( ) except Exception as exception : raise CLIException ( "Unable to initialize Zookeeper Client: {error}" . format ( error = exception ) ) try : children = zk . get_children ( path ) except Exception as exception : raise CLIException ( "Unable to get children of {zk_path}: {error}" . format ( zk_path = path , error = exception ) ) masters = sorted ( # 'json.info' is the prefix for master nodes. child for child in children if child . startswith ( "json.info" ) ) address = "" for master in masters : try : node_path = "{path}/{node}" . format ( path = path , node = master ) json_data , _ = zk . get ( node_path ) except Exception as exception : raise CLIException ( "Unable to get the value of '{node}': {error}" . format ( node = node_path , error = exception ) ) try : data = json . loads ( json_data ) except Exception as exception : raise CLIException ( "Could not load JSON from '{data}': {error}" . format ( data = data , error = str ( exception ) ) ) if ( "address" in data and "ip" in data [ "address" ] and "port" in data [ "address" ] ) : address = "{ip}:{port}" . format ( ip = data [ "address" ] [ "ip" ] , port = data [ "address" ] [ "port" ] ) break try : zk . stop ( ) except Exception as exception : raise CLIException ( "Unable to stop Zookeeper Client: {error}" . format ( error = exception ) ) if not address : raise CLIException ( "Unable to resolve the leading" " master using ZooKeeper" ) return address