Package org.apache.hadoop.util.curator
Class ZKCuratorManager
java.lang.Object
org.apache.hadoop.util.curator.ZKCuratorManager
Helper class that provides utility methods specific to ZK operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classclassUse curator transactions to ensure zk-operations are performed in an all or nothing fashion. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the connection with ZooKeeper.booleanCreate a ZNode.booleanCreate a ZNode.voidUtility function to ensure that the configured base znode exists.voidcreateRootDirRecursively(String path, List<org.apache.zookeeper.data.ACL> zkAcl) Utility function to ensure that the configured base znode exists.createTransaction(List<org.apache.zookeeper.data.ACL> fencingACL, String fencingNodePath) booleanDelete a ZNode.booleanCheck if a ZNode exists.List<org.apache.zookeeper.data.ACL>Get ACLs for a ZNode.getChildren(String path) Get children of a ZNode.org.apache.curator.framework.CuratorFrameworkGet the curator framework managing the ZooKeeper connection.byte[]Get the data in a ZNode.byte[]Get the data in a ZNode.static StringgetNodePath(String root, String nodeName) Get the path for a ZNode.getStringData(String path) Get the data in a ZNode.getStringData(String path, org.apache.zookeeper.data.Stat stat) Get the data in a ZNode.static List<org.apache.zookeeper.data.ACL>getZKAcls(Configuration conf) Utility method to fetch the ZK ACLs from the configuration.static List<ZKUtil.ZKAuthInfo>getZKAuths(Configuration conf) Utility method to fetch ZK auth info from the configuration.voidsafeCreate(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) voidsafeDelete(String path, List<org.apache.zookeeper.data.ACL> fencingACL, String fencingNodePath) Deletes the path.voidsafeSetData(String path, byte[] data, int version, List<org.apache.zookeeper.data.ACL> fencingACL, String fencingNodePath) voidSet data into a ZNode.voidSet data into a ZNode.voidstart()Start the connection to the ZooKeeper ensemble.voidStart the connection to the ZooKeeper ensemble.voidStart the connection to the ZooKeeper ensemble.voidStart the connection to the ZooKeeper ensemble.voidStart the connection to the ZooKeeper ensemble.
-
Constructor Details
-
ZKCuratorManager
- Throws:
IOException
-
-
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
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
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 readZKUtil.BadAuthFormatException- if the auth format is invalid
-
start
Start the connection to the ZooKeeper ensemble.- Throws:
IOException- If the connection cannot be started.
-
start
Start the connection to the ZooKeeper ensemble.- Parameters:
authInfos- List of authentication keys.- Throws:
IOException- If the connection cannot be started.
-
start
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
Get ACLs for a ZNode.- Parameters:
path- Path of the ZNode.- Returns:
- The list of ACLs.
- Throws:
Exception- If it cannot contact Zookeeper.
-
getData
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
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
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
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
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
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
Get children of a ZNode.- Parameters:
path- Path of the ZNode.- Returns:
- The list of children.
- Throws:
Exception- If it cannot contact Zookeeper.
-
exists
Check if a ZNode exists.- Parameters:
path- Path of the ZNode.- Returns:
- If the ZNode exists.
- Throws:
Exception- If it cannot contact Zookeeper.
-
create
Create a ZNode.- Parameters:
path- Path of the ZNode.- Returns:
- If the ZNode was created.
- Throws:
Exception- If it cannot contact Zookeeper.
-
create
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
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
Delete a ZNode.- Parameters:
path- Path of the ZNode.- Returns:
- If the znode was deleted.
- Throws:
Exception- If it cannot contact ZooKeeper.
-
getNodePath
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
-