org.apache.hadoop.hbase.zookeeper
Class ZKConfig

java.lang.Object
  extended by org.apache.hadoop.hbase.zookeeper.ZKConfig

@InterfaceAudience.Private
public final class ZKConfig
extends Object

Utility methods for reading, and building the ZooKeeper configuration.


Nested Class Summary
static class ZKConfig.ZKClusterKey
           
 
Method Summary
static String buildZKQuorumServerString(String[] serverHosts, String clientPort)
          Build the ZK quorum server string with "server:clientport" list, separated by ','
static String getZKQuorumServersString(org.apache.hadoop.conf.Configuration conf)
          Return the ZK Quorum servers string given the specified configuration.
static String getZKQuorumServersString(Properties properties)
          Return the ZK Quorum servers string given zk properties returned by makeZKProps
static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf)
          Get the key to the ZK ensemble for this configuration without adding a name at the end
static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf, String name)
          Get the key to the ZK ensemble for this configuration and append a name at the end
static Properties makeZKProps(org.apache.hadoop.conf.Configuration conf)
          Make a Properties object holding ZooKeeper config.
static Properties parseZooCfg(org.apache.hadoop.conf.Configuration conf, InputStream inputStream)
          Deprecated. in 0.96 onwards. HBase will no longer rely on zoo.cfg availability.
static String standardizeZKQuorumServerString(String quorumStringInput, String clientPort)
          Standardize the ZK quorum string: make it a "server:clientport" list, separated by ','
static ZKConfig.ZKClusterKey transformClusterKey(String key)
          Separate the given key into the three configurations it should contain: hbase.zookeeper.quorum, hbase.zookeeper.client.port and zookeeper.znode.parent
static void validateClusterKey(String key)
          Verifies that the given key matches the expected format for a ZooKeeper cluster key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeZKProps

public static Properties makeZKProps(org.apache.hadoop.conf.Configuration conf)
Make a Properties object holding ZooKeeper config. Parses the corresponding config options from the HBase XML configs and generates the appropriate ZooKeeper properties.

Parameters:
conf - Configuration to read from.
Returns:
Properties holding mappings representing ZooKeeper config file.

parseZooCfg

@Deprecated
public static Properties parseZooCfg(org.apache.hadoop.conf.Configuration conf,
                                                InputStream inputStream)
                              throws IOException
Deprecated. in 0.96 onwards. HBase will no longer rely on zoo.cfg availability.

Parse ZooKeeper's zoo.cfg, injecting HBase Configuration variables in. This method is used for testing so we can pass our own InputStream.

Parameters:
conf - HBaseConfiguration to use for injecting variables.
inputStream - InputStream to read from.
Returns:
Properties parsed from config stream with variables substituted.
Throws:
IOException - if anything goes wrong parsing config

getZKQuorumServersString

public static String getZKQuorumServersString(Properties properties)
Return the ZK Quorum servers string given zk properties returned by makeZKProps

Parameters:
properties -
Returns:
Quorum servers String

getZKQuorumServersString

public static String getZKQuorumServersString(org.apache.hadoop.conf.Configuration conf)
Return the ZK Quorum servers string given the specified configuration.

Parameters:
conf -
Returns:
Quorum servers

buildZKQuorumServerString

public static String buildZKQuorumServerString(String[] serverHosts,
                                               String clientPort)
Build the ZK quorum server string with "server:clientport" list, separated by ','

Parameters:
serverHosts - a list of servers for ZK quorum
clientPort - the default client port
Returns:
the string for a list of "server:port" separated by ","

validateClusterKey

public static void validateClusterKey(String key)
                               throws IOException
Verifies that the given key matches the expected format for a ZooKeeper cluster key. The Quorum for the ZK cluster can have one the following formats (see examples below):
  1. s1,s2,s3 (no client port in the list, the client port could be obtained from clientPort)
  2. s1:p1,s2:p2,s3:p3 (with client port, which could be same or different for each server, in this case, the clientPort would be ignored)
  3. s1:p1,s2,s3:p3 (mix of (1) and (2) - if port is not specified in a server, it would use the clientPort; otherwise, it would use the specified port)

Parameters:
key - the cluster key to validate
Throws:
IOException - if the key could not be parsed

transformClusterKey

public static ZKConfig.ZKClusterKey transformClusterKey(String key)
                                                 throws IOException
Separate the given key into the three configurations it should contain: hbase.zookeeper.quorum, hbase.zookeeper.client.port and zookeeper.znode.parent

Parameters:
key -
Returns:
the three configuration in the described order
Throws:
IOException

getZooKeeperClusterKey

public static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf)
Get the key to the ZK ensemble for this configuration without adding a name at the end

Parameters:
conf - Configuration to use to build the key
Returns:
ensemble key without a name

getZooKeeperClusterKey

public static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf,
                                            String name)
Get the key to the ZK ensemble for this configuration and append a name at the end

Parameters:
conf - Configuration to use to build the key
name - Name that should be appended at the end if not empty or null
Returns:
ensemble key with a name (if any)

standardizeZKQuorumServerString

public static String standardizeZKQuorumServerString(String quorumStringInput,
                                                     String clientPort)
Standardize the ZK quorum string: make it a "server:clientport" list, separated by ','

Parameters:
quorumStringInput - a string contains a list of servers for ZK quorum
clientPort - the default client port
Returns:
the string for a list of "server:port" separated by ","


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.