koding/kite — pull request #51 by fatih (2014-08-01 09:16:57+00:00)
Title: kontrol: implement ID based query and bug fixes

This PR started with implementing ID based queries but also contains several bug fixes that I've encounter during the implementation. First let me describe the ID based query:

1. If a kite registers we set the full path with a value. Such as `/kites/user/env/name/ver/region/hostname/id` and value `localhost:4444`. This is the current approach
2. Now we also add another key with the path `/kites/id` that contains the full path as value: `/user/env/name/ver/region/hostname/id`.
3. If a query comes with a single ID, we first check if this is a single ID lookup. That is decided if all other fields are empty expect ID.
4. If yes we go and get the full path from the `/kites/id` path and get the node from the that full path value
5. The rest is the same as we do query based on multiple fields.

There were several bugs that is fixed:

1. A version query with the string "0.0.1" was also considered a constraint. Therefore it was always searching paths until `/user/env/name` and not beyond that. Because of this even if you would send all the query fields it would always go and get the three path structure.
2. If you send a query with all fields set it would return an `event` from the etcd store which had a node with value. There wasn't any `nodes` that we could traverse or flatten. This was causing kontrol to return a zero list of kites and kite would say `no kites available`.

I've fixed this bugs together with the new feature above by refactoring some of the functionality and creating three new files called `etcd.go`, `node.go` and `kites.go`. This simplifies also some of our code and organizes them so we maintain it better in the future.