Repository: phoenix Updated Branches: refs/heads/master d223f2c39 -> 1fa09dc5c
PHOENIX-1880 Connections from QueryUtil.getConnection don't work on secure clusters (Geoffrey Jacoby) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1fa09dc5 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1fa09dc5 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1fa09dc5 Branch: refs/heads/master Commit: 1fa09dc5c84ca92f57f6904bf88628133eb65995 Parents: d223f2c Author: James Taylor <jtay...@salesforce.com> Authored: Thu Apr 30 13:39:23 2015 -0700 Committer: James Taylor <jtay...@salesforce.com> Committed: Thu Apr 30 13:39:23 2015 -0700 ---------------------------------------------------------------------- .../phoenix/mapreduce/util/ConnectionUtil.java | 23 +++----------------- .../org/apache/phoenix/util/PropertiesUtil.java | 22 +++++++++++++++++++ .../java/org/apache/phoenix/util/QueryUtil.java | 4 ++++ .../apache/phoenix/util/PropertiesUtilTest.java | 23 +++++++++++++++++++- 4 files changed, 51 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/1fa09dc5/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/ConnectionUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/ConnectionUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/ConnectionUtil.java index e677104..294d4e9 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/ConnectionUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/ConnectionUtil.java @@ -26,6 +26,7 @@ import java.util.Properties; import com.google.common.base.Preconditions; import org.apache.hadoop.conf.Configuration; +import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.QueryUtil; /** @@ -54,7 +55,7 @@ public class ConnectionUtil { public static Connection getInputConnection(final Configuration conf , final Properties props) throws SQLException { Preconditions.checkNotNull(conf); return getConnection(PhoenixConfigurationUtil.getInputCluster(conf), - extractProperties(props, conf)); + PropertiesUtil.extractProperties(props, conf)); } /** @@ -77,7 +78,7 @@ public class ConnectionUtil { public static Connection getOutputConnection(final Configuration conf, Properties props) throws SQLException { Preconditions.checkNotNull(conf); return getConnection(PhoenixConfigurationUtil.getOutputCluster(conf), - extractProperties(props, conf)); + PropertiesUtil.extractProperties(props, conf)); } /** @@ -91,22 +92,4 @@ public class ConnectionUtil { return DriverManager.getConnection(QueryUtil.getUrl(quorum), props); } - /** - * Add properties from the given Configuration to the provided Properties. - * - * @param props properties to which connection information from the Configuration will be added - * @param conf configuration containing connection information - * @return the input Properties value, with additional connection information from the - * given Configuration - */ - private static Properties extractProperties(Properties props, final Configuration conf) { - Iterator<Map.Entry<String, String>> iterator = conf.iterator(); - if(iterator != null) { - while (iterator.hasNext()) { - Map.Entry<String, String> entry = iterator.next(); - props.setProperty(entry.getKey(), entry.getValue()); - } - } - return props; - } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/1fa09dc5/phoenix-core/src/main/java/org/apache/phoenix/util/PropertiesUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PropertiesUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PropertiesUtil.java index d894e58..bcb9aa4 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/PropertiesUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PropertiesUtil.java @@ -17,7 +17,10 @@ */ package org.apache.phoenix.util; +import java.util.Iterator; +import java.util.Map; import java.util.Properties; +import org.apache.hadoop.conf.Configuration; public class PropertiesUtil { @@ -36,4 +39,23 @@ public class PropertiesUtil { } return newProperties; } + + /** + * Add properties from the given Configuration to the provided Properties. + * + * @param props properties to which connection information from the Configuration will be added + * @param conf configuration containing connection information + * @return the input Properties value, with additional connection information from the + * given Configuration + */ + public static Properties extractProperties(Properties props, final Configuration conf) { + Iterator<Map.Entry<String, String>> iterator = conf.iterator(); + if(iterator != null) { + while (iterator.hasNext()) { + Map.Entry<String, String> entry = iterator.next(); + props.setProperty(entry.getKey(), entry.getValue()); + } + } + return props; + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/1fa09dc5/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java index 993016a..d63a68f 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java @@ -49,6 +49,8 @@ import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import java.util.Iterator; +import java.util.Map; public final class QueryUtil { @@ -266,6 +268,7 @@ public final class QueryUtil { SQLException { String url = getConnectionUrl(props, conf); LOG.info("Creating connection with the jdbc url:" + url); + PropertiesUtil.extractProperties(props, conf); return DriverManager.getConnection(url, props); } @@ -316,4 +319,5 @@ public final class QueryUtil { ("\"" + tableName + "\" ") + (WHERE + " " + where); } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/phoenix/blob/1fa09dc5/phoenix-core/src/test/java/org/apache/phoenix/util/PropertiesUtilTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/PropertiesUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/PropertiesUtilTest.java index b4608a2..17adfcb 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/util/PropertiesUtilTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/util/PropertiesUtilTest.java @@ -21,13 +21,18 @@ import static org.junit.Assert.assertEquals; import java.sql.SQLException; import java.util.Properties; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; import org.junit.Test; public class PropertiesUtilTest { private static final String SOME_TENANT_ID = "00Dxx0000001234"; - + private static final String SOME_OTHER_PROPERTY_KEY = "some_other_property"; + private static final String SOME_OTHER_PROPERTY_VALUE = "some_other_value"; + @Test public void testCopy() throws Exception{ final Properties propsWithTenant = new Properties(); @@ -44,6 +49,22 @@ public class PropertiesUtilTest { verifyValidCopy(new Properties(propsWithTenant)); } + @Test + public void testCopyFromConfiguration() throws Exception{ + //make sure that we don't only copy the ZK quorum, but all + //properties + final Configuration conf = HBaseConfiguration.create(); + final Properties props = new Properties(); + + conf.set(HConstants.ZOOKEEPER_QUORUM, HConstants.LOCALHOST); + conf.set(PropertiesUtilTest.SOME_OTHER_PROPERTY_KEY, + PropertiesUtilTest.SOME_OTHER_PROPERTY_VALUE); + PropertiesUtil.extractProperties(props, conf); + assertEquals(props.getProperty(HConstants.ZOOKEEPER_QUORUM), + conf.get(HConstants.ZOOKEEPER_QUORUM)); + assertEquals(props.getProperty(PropertiesUtilTest.SOME_OTHER_PROPERTY_KEY), + conf.get(PropertiesUtilTest.SOME_OTHER_PROPERTY_KEY)); + } private void verifyValidCopy(Properties props) throws SQLException { Properties copy = PropertiesUtil.deepCopy(props);