public class ZKUtils extends Object
Users of this class should call register(java.lang.Object)
to obtain the singleton. This will ensure that we're
properly connected and ready to go with ZooKeeper. When the user is done (i.e. on shutdown), it should call
unregister(java.lang.Object)
to let this class know; once there are no more users, this class will automatically
remove itself from ZooKeeper.
Each Oozie Server provides metadata that can be shared with the other Oozie Servers. To keep things simple and to make it easy
to add additional metadata in the future, we share a Map. They keys are defined in ZKUtils.ZKMetadataKeys
.
For the service discovery, the structure in ZooKeeper is /oozie.zookeeper.namespace/ZK_BASE_SERVICES_PATH/ (default is /oozie/services/). ZKUtils has a service named "servers" under which each Oozie server creates a ZNode named ${OOZIE_SERVICE_INSTANCE} (default is the hostname) that contains the metadata payload. For example, with the default settings, an Oozie server named "foo" would create a ZNode at /oozie/services/servers/foo where the foo ZNode contains the metadata.
If oozie.zookeeper.secure is set to true, then Oozie will (a) use jaas to connect to ZooKeeper using SASL/Kerberos based on Oozie's existing security configuration parameters (b) use/convert every znode under the namespace (including the namespace itself) to have ACLs such that only Oozie servers have access (i.e. if "service/host@REALM" is the Kerberos principal, then "service" will be used for the ACLs).
Oozie server will shutdown itself if ZK connection is lost for ${ZK_CONNECTION_TIMEOUT}.
Modifier and Type | Class and Description |
---|---|
class |
ZKUtils.SASLOwnerACLProvider
Simple implementation of an
ACLProvider that simply returns saslACL . |
class |
ZKUtils.ZKMetadataKeys
Keys used in the metadata provided by each Oozie Server to ZooKeeper and other Oozie Servers
|
Modifier and Type | Field and Description |
---|---|
static String |
OOZIE_INSTANCE_ID
oozie-env environment variable for specifying the Oozie instance ID
|
static String |
ZK_BASE_SERVICES_PATH
Services that need to put a node in zookeeper should go under here.
|
static String |
ZK_CONNECTION_STRING
oozie-site property for specifying the ZooKeeper connection string.
|
static String |
ZK_CONNECTION_TIMEOUT
Default ZK connection timeout ( in sec).
|
static String |
ZK_MAX_RETRIES
Maximum number of times to retry.
|
static String |
ZK_NAMESPACE
oozie-site property for specifying the ZooKeeper namespace to use (e.g.
|
static String |
ZK_SECURE
oozie-site property for specifying that ZooKeeper is secure.
|
static String |
ZK_SESSION_TIMEOUT
Default ZK session timeout ( in sec).
|
Modifier and Type | Method and Description |
---|---|
List<org.apache.curator.x.discovery.ServiceInstance<Map>> |
getAllMetaData()
Returns a list of the metadata provided by all of the Oozie Servers.
|
org.apache.curator.framework.CuratorFramework |
getClient()
Returns the
CuratorFramework used for managing the ZooKeeper connection; it can be used by calling classes to perform
more direct operations on ZooKeeper. |
static org.apache.curator.RetryPolicy |
getRetryPolicy()
Returns retry policy
|
static Set<Object> |
getUsers()
Useful for tests to get the registered classes
|
String |
getZKId()
Returns the ID of this Oozie Server as seen by ZooKeeper and other Oozie Servers
|
int |
getZKIdIndex(List<org.apache.curator.x.discovery.ServiceInstance<Map>> oozies)
Returns the index of this Oozie Server in ZooKeeper's list of Oozie Servers (ordered by registration time)
|
static String |
getZKNameSpace()
Returns configured zk namesapces
|
static ZKUtils |
register(Object user)
Classes that want to use ZooKeeper should call this method to get the ZKUtils singleton.
|
void |
unregister(Object user)
Classes should call this when they are done (i.e.
|
public static final String ZK_CONNECTION_STRING
public static final String ZK_NAMESPACE
public static final String ZK_CONNECTION_TIMEOUT
public static final String ZK_SESSION_TIMEOUT
public static final String ZK_MAX_RETRIES
public static final String OOZIE_INSTANCE_ID
public static final String ZK_SECURE
public static final String ZK_BASE_SERVICES_PATH
public static ZKUtils register(Object user) throws Exception
user
- The calling classException
- if there is an issue when connecting to ZooKeeperpublic void unregister(Object user)
user
- The calling classpublic List<org.apache.curator.x.discovery.ServiceInstance<Map>> getAllMetaData()
public String getZKId()
public org.apache.curator.framework.CuratorFramework getClient()
CuratorFramework
used for managing the ZooKeeper connection; it can be used by calling classes to perform
more direct operations on ZooKeeper. Most of the time, this shouldn't be needed.
Be careful not to close the connection.
public int getZKIdIndex(List<org.apache.curator.x.discovery.ServiceInstance<Map>> oozies)
oozies
- The collection of metadata provided by all of the Oozie Servers (from calling getAllMetaData()
public static Set<Object> getUsers()
public static org.apache.curator.RetryPolicy getRetryPolicy()
public static String getZKNameSpace()
Copyright © 2018 Apache Software Foundation. All rights reserved.