curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Techy Teck <comptechge...@gmail.com>
Subject Re: Watch for events on descendant znodes using curator?
Date Sun, 17 Nov 2013 20:04:05 GMT
Any thoughts on this? Whether I am doing right way or not?


On Sat, Nov 16, 2013 at 6:45 PM, Techy Teck <comptechgeeky@gmail.com> wrote:

> I have tried doing the same thing as you have told me. Attached is my
> zookeeper schema diagram for which I am writing a watch and listener.
>
> I have a colo node, which will have atleast 3 nodes for now, but in future
> I can have more than three colos. So I have placed a watch on colo znode as
> well. Now each colo such as phx will have couple of hosts as well. Right
> now, I am having three hosts in each colo, but in future, it can be more
> than three. SO I have placed a watch on each colo node as well, meaning
> watch on phx, slc, lvs znodes.
>
> Now each hosts in all the colos will have some children nodes, so I need
> to make a watch on those host znodes in all the colos as well and keep on
> continuing like this for its children.
>
> Below are the requirements for me for the attached diagram-
>
>     1) Need to watch on colo node for any new colo being added
>     2) Need to watch on each individual colo to see any new machines
> getting added
>     3) Need to watch on each machine to see any workflow nodes getting
> added or not.
>     4) Need to watch on workflow node to see if there are any new steps
> being added or not and then watch on those steps node as well inside
> workflow node.
>
> Below is my full code, that I am able to came up with but not sure whether
> this is right or not? It doesn't keep a watch on all the child nodes as I
> was not able to understand fully how to do that but it keeps a watch on my
> first two use case as mentioned above. Is there any way to fulfill all my
> above requirements? As I recently started with curator so having some
> problem.
>
>     public class ZKWatchNode {
>
>         private static Map<String, List<String>> coloMachine = new
> LinkedHashMap<String, List<String>>();
>         private static final String COLO = "/colo";
>
>         public static void main(String[] args) {
>
>             try {
>                 CuratorFramework client =
> CuratorClient.createSimple("localhost:2181");
>                 client.start();
>
>                 // find number of colos we have and place a watch on the
> /colo node as well.
>                 List<String> numberOfColos = watchedGetChildren(client,
> COLO);
>                 System.out.println(numberOfColos);
>
>                 for(String colo : numberOfColos) {
>                     String coloNode = COLO+"/"+numberOfColos;
>                     List<String> childrenInEachColo =
> watchedGetChildren(client, coloNode);
>                     coloMachine.put(colo, childrenInEachColo);
>                 }
>
>                 handleWatchEvents(client);
>
>                 for(;;) {
>                     try {
>                         Thread.sleep(50000);
>                     } catch(InterruptedException e) {
>                     }
>                 }
>
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>         }
>
>
>         /**
>          * Watch the node on the path using Curator.
>          * @param client
>          * @param path
>          * @return
>          * @throws Exception
>          */
>         public static List<String> watchedGetChildren(CuratorFramework
> client, String path) throws Exception {
>
>             return client.getChildren().watched().forPath(path);
>         }
>
>         /**
>          * Handle the watch events
>          * @param client
>          * @throws Exception
>          */
>         public static void handleWatchEvents(CuratorFramework client)
> throws Exception {
>             CuratorListener listener = new CuratorListener() {
>                 public void eventReceived(CuratorFramework client,
> CuratorEvent event) throws Exception {
>
>                     // find number of colos we have and place a watch on
> the /colo node as well.
>                     List<String> numberOfColos =
> watchedGetChildren(client, COLO);
>                     System.out.println(numberOfColos);
>
>                     for(String colo : numberOfColos) {
>                         String coloNode = COLO+"/"+numberOfColos;
>                         List<String> childrenInEachColo =
> watchedGetChildren(client, coloNode);
>                         coloMachine.put(colo, childrenInEachColo);
>                     }
>                 }
>             };
>             client.getCuratorListenable().addListener(listener);
>         }
>     }
>
>
>
> If yes, any simple example will help me to understand better. Thanks..
>
>
>
>
> On Sat, Nov 16, 2013 at 6:05 PM, Techy Teck <comptechgeeky@gmail.com>wrote:
>
>> Thanks a lot John. I will try that out and once I have that code ready, I
>> will check with you whether this is the right way to do that or we can
>> improvise it slightly..
>>
>> Thanks a lot for the help..
>>
>>
>> On Sat, Nov 16, 2013 at 5:21 PM, John Vines <vines@apache.org> wrote:
>>
>>> Currently there is no existing mechanism. Curator-33 is for this
>>> feature. In the meantime, you can write a child listener that creates new
>>> listeners on create events and removes them on delete events.
>>>
>>> Sent from my phone, please pardon the typos and brevity.
>>> On Nov 16, 2013 8:02 PM, "Techy Teck" <comptechgeeky@gmail.com> wrote:
>>>
>>>> When using ZooKeeper is it possible to watch for all events happening
>>>> on descendant znodes?
>>>>
>>>> for example if I have below diagram as attached in this email.
>>>>
>>>> Is there a way to watch the poot node for any changes to /v1, /v2, /v3
>>>> and /host and other children nodes for v2,v3 and host as well?
>>>>
>>>
>>
>

Mime
View raw message