Zookeeper traversal and set ACLs

Source: Internet
Author: User
Tags zookeeper
Import java.io.IOException;
Import java.util.ArrayList;




Import java.util.List;
Import org.apache.hadoop.hbase.util.Bytes;
Import Org.apache.zookeeper.CreateMode;
Import org.apache.zookeeper.KeeperException;
Import Org.apache.zookeeper.Watcher;
Import Org.apache.zookeeper.ZooDefs;
Import Org.apache.zookeeper.ZooKeeper;
Import Org.apache.zookeeper.data.ACL;
Import Org.apache.zookeeper.data.Id;












Import Org.apache.zookeeper.data.Stat;




    




     public class Zkgetchild_setacl {//Session timeout, set to coincide with system default time private static final int session_timeout=30000;




    




     Create zookeeper instance zookeeper ZK; Create watcher Instance Watcher Wh=new watcher () {public void process (org.apache.zookeeper.WatchedEvent




            Event) {System.out.println (event.tostring ());




    




     }




     };   Initializes the zookeeper instance private void Createzkinstance () throws IOException {          




            Zk=new Zookeeper ("10.xxx.xxx.24:2181", ZKGETCHILD_SETACL.SESSION_TIMEOUT,THIS.WH); 
     
    private void Getchild (String path) throws Ioexception,interruptedexception,keeperexception {  
         ID ID = new ID ("IP", "10.XXX.XXX.23/27");  
         ACL ACL = new ACL (ZooDefs.Perms.ALL, id);  
         List<acl> ACLS = new arraylist<acl> ();  
         Acls.add (ACL);
         Zk.setacl (Path, ACLs,-1);




            System.out.println ("Set ACL succ:" +path);
           List<string> Child_list=zk.getchildren (path, false);
          for (String child:child_list) {System.out.println ("Child:" +child);
          if (Path.equals ("/")) {child=path+ "" +child;
          System.out.println ("A:" +child);
          }else{child=path+ "/" +child;
          System.out.println ("B:" +child);
          
          } System.out.println (New String (Zk.getdata (child,false,null));child=path+ "" +child;
          Stat Stat = Zk.exists (child, false);
          List<acl> Child_acl=zk.getacl (child, stat);
        for (ACL a:child_acl) {//system.out.println (a.getperms ());
        
        System.out.println (a);
          System.out.println ("**********");
           } getchild (child);
     
    } private void Confacl (String path) throws Keeperexception, Interruptedexception { ID ID = new ID ("World", "anyone"); Release permission id ID2 = new ID ("IP", "10.xxx.xxx.24"); 
         Qualify IP ACL ACL = new ACL (ZooDefs.Perms.ALL, id); 
         
         
         ACL Acl2 = new ACL (ZooDefs.Perms.ALL, ID2);  
         List<acl> ACLS = new arraylist<acl> ();  
         Acls.add (ACL);
        
         Acls.add (ACL2);
         Zk.setacl (Path, ACLs,-1);




        
     System.out.println ("Set ACL succ:" +path); private void Zkclose () throws Interruptedexception {
            Zk.close ();




            public static void Main (string[] args) throws Ioexception,interruptedexception,keeperexception {




            Zkgetchild_setacl dm=new Zkgetchild_setacl ();




            Dm.createzkinstance ();




            Dm.confacl ("/hbase/master"); Dm.




     Zkclose (); }




}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.