Spring Boot Yaml and ZooKeeper

Spring Boot supports the use of YAML files to externalize configuration. YAML is a superset of JSON, human-readable and very convenient for specifying hierarchical configuration data. This is an example of yaml

    - area: "marketing"
      - name: "Tom"
        email: "tom@mail.com"
      - name: "James"
      - name: "Mark"
    - area: "distribution"
      - name: "Steve"
      - name: "Richard"

You may also want to use Spring Cloud ZooKeeper Config and having your configuration distributed along your cluster. To get it you have to create a tree structure of nodes in ZooKeeper that is equivalent to the content of your yaml configuration files. It can be done through creation scripts for zkCli but is easier to use zookeeperdump. Zookeeperdump is a tool intended to help loading configurations for Spring Cloud ZooKeeper Config.

It can be downloaded with this maven command.

mvn -Dartifact=net.therore.zookeeperdump:therore-zookeeperdump:1.1.0:groovy -q -Ddest=zookeeperdump.groovy dependency:get

Zookeeperdump is a groovy script which requires that groovy binaries have been installed previously in your system. I recommend the use of gvm for managing groovy tools and versions.

To view all the tool options execute zookeeperdump.groovy without parameters:

usage: zookeeperdump.groovy [-s {ip:port}] [-x | -c] [-u scheme:id] [-a {scheme:id:perm,scheme:id:perm...}] zpath
 -a,--acls <arg>     set acls used for creation
 -c,--create         import tree in yaml format from stdin
 -s,--server <arg>   zookeeper server connection. By default localhost:2181
 -u,--auth <arg>     set session authentication
 -x,--extract        extract tree in yaml format to stdout
> zookeeperdump.groovy -x /config/application > dump.yml
> zookeeperdump.groovy -c /config/application < dump.yml
> zookeeperdump.groovy -x /config/application/scheduler/timeout
> echo 1000 | zookeeperdump.groovy -c /config/application/scheduler/timeout
> zookeeperdump.groovy -u digest:usr:pwd -a digest:usr:uPIxv8DxE/mT5RPGVrsDMJnQoTQ=:rw -c /config/application < dump.yml
> zookeeperdump.groovy -u digest:usr:pwd -a digest:usr:uPIxv8DxE/mT5RPGVrsDMJnQoTQ=:r -c /config/application < dump.yml
> zookeeperdump.groovy -u digest:super:secret  -c /config/myapplication < dump.yml
> zookeeperdump.groovy -u digest:super:secret  -x /config/myapplication > dump.yml

For example to import a yaml file into ZooKeeper is only needed this command.

zookeeperdump.groovy -c /config/application < dump.yml

To export is also quite simple

zookeeperdump.groovy -x /config/application > dump.yml

By the way I recommend you to read ZooKeeper Programmer's Guide to have a basic knowledge about ZooKeeper.