diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java index 1e04948eb12..2ad1f33e257 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java @@ -50,8 +50,8 @@ import org.apache.zookeeper.server.quorum.QuorumPeerMain; * HBase's version of ZooKeeper's QuorumPeer. When HBase is set to manage * ZooKeeper, this class is used to start up QuorumPeer instances. By doing * things in here rather than directly calling to ZooKeeper, we have more - * control over the process. This class uses {@link ZKConfig} to parse the - * zoo.cfg and inject variables from HBase's site.xml configuration in. + * control over the process. This class uses {@link ZKConfig} to get settings + * from the hbase-site.xml file. */ @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS) @InterfaceStability.Evolving diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java index 7cf4b8d8a71..a8f1182498c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java @@ -18,15 +18,9 @@ */ package org.apache.hadoop.hbase.zookeeper; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; import java.util.Map.Entry; import java.util.Properties; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.classification.InterfaceAudience; @@ -35,18 +29,13 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience; * Utility methods for reading, and building the ZooKeeper configuration. * * The order and priority for reading the config are as follows: - * (1). zoo.cfg if ""hbase.config.read.zookeeper.config" is true - * (2). Property with "hbase.zookeeper.property." prefix from HBase XML - * (3). other zookeeper related properties in HBASE XML + * (1). Property with "hbase.zookeeper.property." prefix from HBase XML + * (2). other zookeeper related properties in HBASE XML */ @InterfaceAudience.Private public class ZKConfig { - private static final Log LOG = LogFactory.getLog(ZKConfig.class); private static final String VARIABLE_START = "${"; - private static final int VARIABLE_START_LENGTH = VARIABLE_START.length(); - private static final String VARIABLE_END = "}"; - private static final int VARIABLE_END_LENGTH = VARIABLE_END.length(); /** * Make a Properties object holding ZooKeeper config. @@ -56,54 +45,7 @@ public class ZKConfig { * @return Properties holding mappings representing ZooKeeper config file. */ public static Properties makeZKProps(Configuration conf) { - Properties zkProperties = makeZKPropsFromZooCfg(conf); - - if (zkProperties == null) { - // Otherwise, use the configuration options from HBase's XML files. - zkProperties = makeZKPropsFromHbaseConfig(conf); - } - return zkProperties; - } - - /** - * Parses the corresponding config options from the zoo.cfg file - * and make a Properties object holding the Zookeeper config. - * - * @param conf Configuration to read from. - * @return Properties holding mappings representing the ZooKeeper config file or null if - * the HBASE_CONFIG_READ_ZOOKEEPER_CONFIG is false or the file does not exist. - */ - private static Properties makeZKPropsFromZooCfg(Configuration conf) { - if (conf.getBoolean(HConstants.HBASE_CONFIG_READ_ZOOKEEPER_CONFIG, false)) { - LOG.warn( - "Parsing ZooKeeper's " + HConstants.ZOOKEEPER_CONFIG_NAME + - " file for ZK properties " + - "has been deprecated. Please instead place all ZK related HBase " + - "configuration under the hbase-site.xml, using prefixes " + - "of the form '" + HConstants.ZK_CFG_PROPERTY_PREFIX + "', and " + - "set property '" + HConstants.HBASE_CONFIG_READ_ZOOKEEPER_CONFIG + - "' to false"); - // First check if there is a zoo.cfg in the CLASSPATH. If so, simply read - // it and grab its configuration properties. - ClassLoader cl = HQuorumPeer.class.getClassLoader(); - final InputStream inputStream = - cl.getResourceAsStream(HConstants.ZOOKEEPER_CONFIG_NAME); - if (inputStream != null) { - try { - return parseZooCfg(conf, inputStream); - } catch (IOException e) { - LOG.warn("Cannot read " + HConstants.ZOOKEEPER_CONFIG_NAME + - ", loading from XML files", e); - } - } - } else { - if (LOG.isTraceEnabled()) { - LOG.trace("Skipped reading ZK properties file '" + HConstants.ZOOKEEPER_CONFIG_NAME + - "' since '" + HConstants.HBASE_CONFIG_READ_ZOOKEEPER_CONFIG + "' was not set to true"); - } - } - - return null; + return makeZKPropsFromHbaseConfig(conf); } /** @@ -129,7 +71,7 @@ public class ZKConfig { if (value.contains(VARIABLE_START)) { value = conf.get(key); } - zkProperties.put(zkKey, value); + zkProperties.setProperty(zkKey, value); } } } @@ -163,135 +105,6 @@ public class ZKConfig { return zkProperties; } - /** - * Parse ZooKeeper's zoo.cfg, injecting HBase Configuration variables in. - * This method is used for testing so we can pass our own InputStream. - * @param conf HBaseConfiguration to use for injecting variables. - * @param inputStream InputStream to read from. - * @return Properties parsed from config stream with variables substituted. - * @throws IOException if anything goes wrong parsing config - * @deprecated in 0.96 onwards. HBase will no longer rely on zoo.cfg - * availability. - */ - @Deprecated - public static Properties parseZooCfg(Configuration conf, - InputStream inputStream) throws IOException { - Properties properties = new Properties(); - try { - properties.load(inputStream); - } catch (IOException e) { - final String msg = "fail to read properties from " - + HConstants.ZOOKEEPER_CONFIG_NAME; - LOG.fatal(msg); - throw new IOException(msg, e); - } - for (Entry entry : properties.entrySet()) { - String value = entry.getValue().toString().trim(); - String key = entry.getKey().toString().trim(); - StringBuilder newValue = new StringBuilder(); - int varStart = value.indexOf(VARIABLE_START); - int varEnd = 0; - while (varStart != -1) { - varEnd = value.indexOf(VARIABLE_END, varStart); - if (varEnd == -1) { - String msg = "variable at " + varStart + " has no end marker"; - LOG.fatal(msg); - throw new IOException(msg); - } - String variable = value.substring(varStart + VARIABLE_START_LENGTH, varEnd); - - String substituteValue = System.getProperty(variable); - if (substituteValue == null) { - substituteValue = conf.get(variable); - } - if (substituteValue == null) { - String msg = "variable " + variable + " not set in system property " - + "or hbase configs"; - LOG.fatal(msg); - throw new IOException(msg); - } - - newValue.append(substituteValue); - - varEnd += VARIABLE_END_LENGTH; - varStart = value.indexOf(VARIABLE_START, varEnd); - } - // Special case for 'hbase.cluster.distributed' property being 'true' - if (key.startsWith("server.")) { - boolean mode = - conf.getBoolean(HConstants.CLUSTER_DISTRIBUTED, HConstants.DEFAULT_CLUSTER_DISTRIBUTED); - if (mode == HConstants.CLUSTER_IS_DISTRIBUTED && value.startsWith(HConstants.LOCALHOST)) { - String msg = "The server in zoo.cfg cannot be set to localhost " + - "in a fully-distributed setup because it won't be reachable. " + - "See \"Getting Started\" for more information."; - LOG.fatal(msg); - throw new IOException(msg); - } - } - newValue.append(value.substring(varEnd)); - properties.setProperty(key, newValue.toString()); - } - return properties; - } - - /** - * Return the ZK Quorum servers string given zk properties returned by - * makeZKProps - * @param properties - * @return Quorum servers String - */ - private static String getZKQuorumServersString(Properties properties) { - String clientPort = null; - List servers = new ArrayList(); - - // The clientPort option may come after the server.X hosts, so we need to - // grab everything and then create the final host:port comma separated list. - boolean anyValid = false; - for (Entry property : properties.entrySet()) { - String key = property.getKey().toString().trim(); - String value = property.getValue().toString().trim(); - if (key.equals("clientPort")) { - clientPort = value; - } - else if (key.startsWith("server.")) { - String host = value.substring(0, value.indexOf(':')); - servers.add(host); - anyValid = true; - } - } - - if (!anyValid) { - LOG.error("no valid quorum servers found in " + HConstants.ZOOKEEPER_CONFIG_NAME); - return null; - } - - if (clientPort == null) { - LOG.error("no clientPort found in " + HConstants.ZOOKEEPER_CONFIG_NAME); - return null; - } - - if (servers.isEmpty()) { - LOG.fatal("No servers were found in provided ZooKeeper configuration. " + - "HBase must have a ZooKeeper cluster configured for its " + - "operation. Ensure that you've configured '" + - HConstants.ZOOKEEPER_QUORUM + "' properly."); - return null; - } - - StringBuilder hostPortBuilder = new StringBuilder(); - for (int i = 0; i < servers.size(); ++i) { - String host = servers.get(i); - if (i > 0) { - hostPortBuilder.append(','); - } - hostPortBuilder.append(host); - hostPortBuilder.append(':'); - hostPortBuilder.append(clientPort); - } - - return hostPortBuilder.toString(); - } - /** * Return the ZK Quorum servers string given the specified configuration * @@ -334,17 +147,9 @@ public class ZKConfig { /** * Return the ZK Quorum servers string given the specified configuration. - * @param conf * @return Quorum servers */ public static String getZKQuorumServersString(Configuration conf) { - // First try zoo.cfg; if not applicable, then try config XML. - Properties zkProperties = makeZKPropsFromZooCfg(conf); - - if (zkProperties != null) { - return getZKQuorumServersString(zkProperties); - } - return getZKQuorumServersStringFromHbaseConfig(conf); } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index fdd9e92c9ff..2fe8fd7c21c 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -158,9 +158,6 @@ public final class HConstants { /** Name of ZooKeeper quorum configuration parameter. */ public static final String ZOOKEEPER_QUORUM = "hbase.zookeeper.quorum"; - /** Name of ZooKeeper config file in conf/ directory. */ - public static final String ZOOKEEPER_CONFIG_NAME = "zoo.cfg"; - /** Common prefix of ZooKeeper configuration properties */ public static final String ZK_CFG_PROPERTY_PREFIX = "hbase.zookeeper.property."; @@ -977,10 +974,6 @@ public final class HConstants { public static final Cell NO_NEXT_INDEXED_KEY = new KeyValue(); /** delimiter used between portions of a region name */ public static final int DELIMITER = ','; - public static final String HBASE_CONFIG_READ_ZOOKEEPER_CONFIG = - "hbase.config.read.zookeeper.config"; - public static final boolean DEFAULT_HBASE_CONFIG_READ_ZOOKEEPER_CONFIG = - false; /** * QOS attributes: these attributes are used to demarcate RPC call processing diff --git a/hbase-common/src/main/resources/hbase-default.xml b/hbase-common/src/main/resources/hbase-default.xml index fbaff1c5632..49dd9eb5dcb 100644 --- a/hbase-common/src/main/resources/hbase-default.xml +++ b/hbase-common/src/main/resources/hbase-default.xml @@ -432,15 +432,7 @@ possible configurations would overwhelm and obscure the important. and will not be downgraded. ZooKeeper versions before 3.4 do not support multi-update and will not fail gracefully if multi-update is invoked (see ZOOKEEPER-1495). - - hbase.config.read.zookeeper.config - false - - Set to true to allow HBaseConfiguration to read the - zoo.cfg file for ZooKeeper properties. Switching this to true - is not recommended, since the functionality of reading ZK - properties from a zoo.cfg file has been deprecated. - +