Class ZKCuratorManager

java.lang.Object
org.apache.hadoop.util.curator.ZKCuratorManager

@Private public final class ZKCuratorManager extends Object
Helper class that provides utility methods specific to ZK operations.
  • Constructor Details

  • Method Details

    • getCurator

      public org.apache.curator.framework.CuratorFramework getCurator()
      Get the curator framework managing the ZooKeeper connection.
      Returns:
      Curator framework.
    • close

      public void close()
      Close the connection with ZooKeeper.
    • getZKAcls

      public static List<org.apache.zookeeper.data.ACL> getZKAcls(Configuration conf) throws IOException
      Utility method to fetch the ZK ACLs from the configuration.
      Parameters:
      conf - configuration.
      Returns:
      acl list.
      Throws:
      IOException - if the Zookeeper ACLs configuration file cannot be read
    • getZKAuths

      public static List<ZKUtil.ZKAuthInfo> getZKAuths(Configuration conf) throws IOException
      Utility method to fetch ZK auth info from the configuration.
      Parameters:
      conf - configuration.
      Returns:
      ZKAuthInfo List.
      Throws:
      IOException - if the Zookeeper ACLs configuration file cannot be read
      ZKUtil.BadAuthFormatException - if the auth format is invalid
    • start

      public void start() throws IOException
      Start the connection to the ZooKeeper ensemble.
      Throws:
      IOException - If the connection cannot be started.
    • start

      public void start(List<org.apache.curator.framework.AuthInfo> authInfos) throws IOException
      Start the connection to the ZooKeeper ensemble.
      Parameters:
      authInfos - List of authentication keys.
      Throws:
      IOException - If the connection cannot be started.
    • start

      public void start(String zkHostPort) throws IOException
      Start the connection to the ZooKeeper ensemble.
      Parameters:
      zkHostPort - Host:Port of the ZooKeeper.
      Throws:
      IOException - If the connection cannot be started.
    • start

      public void start(List<org.apache.curator.framework.AuthInfo> authInfos, boolean sslEnabled) throws IOException
      Start the connection to the ZooKeeper ensemble.
      Parameters:
      authInfos - List of authentication keys.
      sslEnabled - If the connection should be SSL/TLS encrypted.
      Throws:
      IOException - If the connection cannot be started.
    • start

      public void start(List<org.apache.curator.framework.AuthInfo> authInfos, boolean sslEnabled, String zkHostPort) throws IOException
      Start the connection to the ZooKeeper ensemble.
      Parameters:
      authInfos - List of authentication keys.
      sslEnabled - If the connection should be SSL/TLS encrypted.
      zkHostPort - Host:Port of the ZooKeeper.
      Throws:
      IOException - If the connection cannot be started.
    • getACL

      public List<org.apache.zookeeper.data.ACL> getACL(String path) throws Exception
      Get ACLs for a ZNode.
      Parameters:
      path - Path of the ZNode.
      Returns:
      The list of ACLs.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • getData

      public byte[] getData(String path) throws Exception
      Get the data in a ZNode.
      Parameters:
      path - Path of the ZNode.
      Returns:
      The data in the ZNode.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • getData

      public byte[] getData(String path, org.apache.zookeeper.data.Stat stat) throws Exception
      Get the data in a ZNode.
      Parameters:
      path - Path of the ZNode.
      stat - stat.
      Returns:
      The data in the ZNode.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • getStringData

      public String getStringData(String path) throws Exception
      Get the data in a ZNode.
      Parameters:
      path - Path of the ZNode.
      Returns:
      The data in the ZNode.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • getStringData

      public String getStringData(String path, org.apache.zookeeper.data.Stat stat) throws Exception
      Get the data in a ZNode.
      Parameters:
      path - Path of the ZNode.
      stat - Output statistics of the ZNode.
      Returns:
      The data in the ZNode.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • setData

      public void setData(String path, byte[] data, int version) throws Exception
      Set data into a ZNode.
      Parameters:
      path - Path of the ZNode.
      data - Data to set.
      version - Version of the data to store.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • setData

      public void setData(String path, String data, int version) throws Exception
      Set data into a ZNode.
      Parameters:
      path - Path of the ZNode.
      data - Data to set as String.
      version - Version of the data to store.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • getChildren

      public List<String> getChildren(String path) throws Exception
      Get children of a ZNode.
      Parameters:
      path - Path of the ZNode.
      Returns:
      The list of children.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • exists

      public boolean exists(String path) throws Exception
      Check if a ZNode exists.
      Parameters:
      path - Path of the ZNode.
      Returns:
      If the ZNode exists.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • create

      public boolean create(String path) throws Exception
      Create a ZNode.
      Parameters:
      path - Path of the ZNode.
      Returns:
      If the ZNode was created.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • create

      public boolean create(String path, List<org.apache.zookeeper.data.ACL> zkAcl) throws Exception
      Create a ZNode.
      Parameters:
      path - Path of the ZNode.
      zkAcl - ACL for the node.
      Returns:
      If the ZNode was created.
      Throws:
      Exception - If it cannot contact Zookeeper.
    • createRootDirRecursively

      public void createRootDirRecursively(String path) throws Exception
      Utility function to ensure that the configured base znode exists. This recursively creates the znode as well as all of its parents.
      Parameters:
      path - Path of the znode to create.
      Throws:
      Exception - If it cannot create the file.
    • createRootDirRecursively

      public void createRootDirRecursively(String path, List<org.apache.zookeeper.data.ACL> zkAcl) throws Exception
      Utility function to ensure that the configured base znode exists. This recursively creates the znode as well as all of its parents.
      Parameters:
      path - Path of the znode to create.
      zkAcl - ACLs for ZooKeeper.
      Throws:
      Exception - If it cannot create the file.
    • delete

      public boolean delete(String path) throws Exception
      Delete a ZNode.
      Parameters:
      path - Path of the ZNode.
      Returns:
      If the znode was deleted.
      Throws:
      Exception - If it cannot contact ZooKeeper.
    • getNodePath

      public static String getNodePath(String root, String nodeName)
      Get the path for a ZNode.
      Parameters:
      root - Root of the ZNode.
      nodeName - Name of the ZNode.
      Returns:
      Path for the ZNode.
    • safeCreate

      public void safeCreate(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode mode, List<org.apache.zookeeper.data.ACL> fencingACL, String fencingNodePath) throws Exception
      Throws:
      Exception
    • safeDelete

      public void safeDelete(String path, List<org.apache.zookeeper.data.ACL> fencingACL, String fencingNodePath) throws Exception
      Deletes the path. Checks for existence of path as well.
      Parameters:
      path - Path to be deleted.
      fencingNodePath - fencingNodePath.
      fencingACL - fencingACL.
      Throws:
      Exception - if any problem occurs while performing deletion.
    • safeSetData

      public void safeSetData(String path, byte[] data, int version, List<org.apache.zookeeper.data.ACL> fencingACL, String fencingNodePath) throws Exception
      Throws:
      Exception
    • createTransaction

      public ZKCuratorManager.SafeTransaction createTransaction(List<org.apache.zookeeper.data.ACL> fencingACL, String fencingNodePath) throws Exception
      Throws:
      Exception