Skip to content

Instantly share code, notes, and snippets.

@arkadijs
Created November 23, 2014 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkadijs/4d4280d7d1bdc7b50ef9 to your computer and use it in GitHub Desktop.
Save arkadijs/4d4280d7d1bdc7b50ef9 to your computer and use it in GitHub Desktop.
def zookeeper: Future[Map[String, String]] = async {
val writeback = ZooKeeper.WritebackPathPrefix.split("/").filterNot(_.isEmpty).toSeq
def join(l: Seq[String]) = l.mkString("/")
def nodes(parent: Seq[String], node: String): Seq[Seq[String]] = {
(parent :+ node) match {
case `writeback` => Seq()
case path => path +: ZooKeeper.getChildren(join(path)).flatMap(node => nodes(path, node))
}
}
nodes(Seq(), services.ZooKeeperService.BasePath.stripPrefix("/"))
.map(join).map { node => (node, ZooKeeper.get(node)) }.filter(_._2.isDefined).toMap.mapValues(_.get)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment