Skip to content

Commit d925754

Browse files
authored
HBASE-28340. Use all Zk client properties that is found in HBase conf (#5669)
Signed-off-by: Balazs Meszaros <meszibali@apache.org>
1 parent 9656006 commit d925754

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121
import java.util.List;
2222
import java.util.Map.Entry;
2323
import java.util.Properties;
24-
import java.util.Set;
2524
import org.apache.commons.validator.routines.InetAddressValidator;
2625
import org.apache.hadoop.conf.Configuration;
2726
import org.apache.hadoop.hbase.HConstants;
2827
import org.apache.hadoop.util.StringUtils;
2928
import org.apache.yetus.audience.InterfaceAudience;
3029

3130
import org.apache.hbase.thirdparty.com.google.common.base.Splitter;
32-
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet;
3331

3432
/**
3533
* Utility methods for reading, and building the ZooKeeper configuration. The order and priority for
@@ -42,12 +40,6 @@ public final class ZKConfig {
4240
private static final String VARIABLE_START = "${";
4341
private static final String ZOOKEEPER_JAVA_PROPERTY_PREFIX = "zookeeper.";
4442

45-
/** Supported ZooKeeper client TLS properties */
46-
static final Set<String> ZOOKEEPER_CLIENT_TLS_PROPERTIES =
47-
ImmutableSet.of("client.secure", "clientCnxnSocket", "ssl.keyStore.location",
48-
"ssl.keyStore.password", "ssl.keyStore.passwordPath", "ssl.trustStore.location",
49-
"ssl.trustStore.password", "ssl.trustStore.passwordPath");
50-
5143
private ZKConfig() {
5244
}
5345

@@ -62,16 +54,12 @@ public static Properties makeZKProps(Configuration conf) {
6254
}
6355

6456
/**
65-
* Make a Properties object holding ZooKeeper config. Parses the corresponding config options from
66-
* the HBase XML configs and generates the appropriate ZooKeeper properties.
67-
* @param conf Configuration to read from.
68-
* @return Properties holding mappings representing ZooKeeper config file.
57+
* Directly map all the hbase.zookeeper.property.KEY properties. Synchronize on conf so no loading
58+
* of configs while we iterate
6959
*/
70-
private static Properties makeZKPropsFromHbaseConfig(Configuration conf) {
60+
private static Properties extractZKPropsFromHBaseConfig(final Configuration conf) {
7161
Properties zkProperties = new Properties();
7262

73-
// Directly map all of the hbase.zookeeper.property.KEY properties.
74-
// Synchronize on conf so no loading of configs while we iterate
7563
synchronized (conf) {
7664
for (Entry<String, String> entry : conf) {
7765
String key = entry.getKey();
@@ -87,6 +75,18 @@ private static Properties makeZKPropsFromHbaseConfig(Configuration conf) {
8775
}
8876
}
8977

78+
return zkProperties;
79+
}
80+
81+
/**
82+
* Make a Properties object holding ZooKeeper config. Parses the corresponding config options from
83+
* the HBase XML configs and generates the appropriate ZooKeeper properties.
84+
* @param conf Configuration to read from.
85+
* @return Properties holding mappings representing ZooKeeper config file.
86+
*/
87+
private static Properties makeZKPropsFromHbaseConfig(Configuration conf) {
88+
Properties zkProperties = extractZKPropsFromHBaseConfig(conf);
89+
9090
// If clientPort is not set, assign the default.
9191
if (zkProperties.getProperty(HConstants.CLIENT_PORT_STR) == null) {
9292
zkProperties.put(HConstants.CLIENT_PORT_STR, HConstants.DEFAULT_ZOOKEEPER_CLIENT_PORT);
@@ -343,24 +343,12 @@ public static String getClientZKQuorumServersString(Configuration conf) {
343343
}
344344

345345
private static void setZooKeeperClientSystemProperties(String prefix, Configuration conf) {
346-
synchronized (conf) {
347-
for (Entry<String, String> entry : conf) {
348-
String key = entry.getKey();
349-
if (!key.startsWith(prefix)) {
350-
continue;
351-
}
352-
String zkKey = key.substring(prefix.length());
353-
if (!ZOOKEEPER_CLIENT_TLS_PROPERTIES.contains(zkKey)) {
354-
continue;
355-
}
356-
String value = entry.getValue();
357-
// If the value has variables substitutions, need to do a get.
358-
if (value.contains(VARIABLE_START)) {
359-
value = conf.get(key);
360-
}
361-
if (System.getProperty(ZOOKEEPER_JAVA_PROPERTY_PREFIX + zkKey) == null) {
362-
System.setProperty(ZOOKEEPER_JAVA_PROPERTY_PREFIX + zkKey, value);
363-
}
346+
Properties zkProperties = extractZKPropsFromHBaseConfig(conf);
347+
for (Entry<Object, Object> entry : zkProperties.entrySet()) {
348+
String key = entry.getKey().toString().trim();
349+
String value = entry.getValue().toString().trim();
350+
if (System.getProperty(ZOOKEEPER_JAVA_PROPERTY_PREFIX + key) == null) {
351+
System.setProperty(ZOOKEEPER_JAVA_PROPERTY_PREFIX + key, value);
364352
}
365353
}
366354
}

hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
*/
1818
package org.apache.hadoop.hbase.zookeeper;
1919

20-
import static org.apache.hadoop.hbase.zookeeper.ZKConfig.ZOOKEEPER_CLIENT_TLS_PROPERTIES;
2120
import static org.junit.Assert.assertEquals;
2221
import static org.junit.Assert.assertTrue;
2322

2423
import java.io.IOException;
2524
import java.util.Properties;
25+
import java.util.Set;
2626
import org.apache.hadoop.conf.Configuration;
2727
import org.apache.hadoop.hbase.HBaseClassTestRule;
2828
import org.apache.hadoop.hbase.HBaseConfiguration;
@@ -33,13 +33,21 @@
3333
import org.junit.Test;
3434
import org.junit.experimental.categories.Category;
3535

36+
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet;
37+
3638
@Category({ MiscTests.class, SmallTests.class })
3739
public class TestZKConfig {
3840

3941
@ClassRule
4042
public static final HBaseClassTestRule CLASS_RULE =
4143
HBaseClassTestRule.forClass(TestZKConfig.class);
4244

45+
/** Supported ZooKeeper client TLS properties */
46+
private static final Set<String> ZOOKEEPER_CLIENT_TLS_PROPERTIES = ImmutableSet.of(
47+
"client.secure", "clientCnxnSocket", "ssl.keyStore.location", "ssl.keyStore.password",
48+
"ssl.keyStore.passwordPath", "ssl.keyStore.type", "ssl.trustStore.location",
49+
"ssl.trustStore.password", "ssl.trustStore.passwordPath", "ssl.trustStore.type");
50+
4351
@Test
4452
public void testZKConfigLoading() throws Exception {
4553
Configuration conf = HBaseConfiguration.create();
@@ -133,6 +141,21 @@ public void testZooKeeperTlsPropertiesServer() {
133141
}
134142
}
135143

144+
@Test
145+
public void testZooKeeperPropertiesDoesntOverwriteSystem() {
146+
// Arrange
147+
System.setProperty("zookeeper.a.b.c", "foo");
148+
Configuration conf = HBaseConfiguration.create();
149+
conf.set(HConstants.ZK_CFG_PROPERTY_PREFIX + "a.b.c", "bar");
150+
151+
// Act
152+
ZKConfig.getZKQuorumServersString(conf);
153+
154+
// Assert
155+
assertEquals("foo", System.getProperty("zookeeper.a.b.c"));
156+
System.clearProperty("zookeeper.a.b.c");
157+
}
158+
136159
private void testKey(String ensemble, int port, String znode) throws IOException {
137160
testKey(ensemble, port, znode, false); // not support multiple client ports
138161
}

0 commit comments

Comments
 (0)