phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajeshb...@apache.org
Subject phoenix git commit: PHOENIX-2254 zookeeper.znode.parent value is not taking affect in MR integration job(Rajeshbabu)
Date Wed, 07 Oct 2015 09:24:55 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master bf3b7d3ec -> ce37e1205


PHOENIX-2254 zookeeper.znode.parent value is not taking affect in MR integration job(Rajeshbabu)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/ce37e120
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ce37e120
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ce37e120

Branch: refs/heads/master
Commit: ce37e12058f5f2a52ad3a6a24acb9f615dc296bc
Parents: bf3b7d3
Author: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Authored: Wed Oct 7 14:59:28 2015 +0530
Committer: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Committed: Wed Oct 7 14:59:28 2015 +0530

----------------------------------------------------------------------
 .../phoenix/end2end/ConnectionUtilIT.java       | 71 ++++++++++++++++++++
 .../phoenix/mapreduce/util/ConnectionUtil.java  | 17 +++--
 .../util/PhoenixConfigurationUtil.java          | 14 +++-
 3 files changed, 93 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ce37e120/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionUtilIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionUtilIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionUtilIT.java
new file mode 100644
index 0000000..e502fac
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionUtilIT.java
@@ -0,0 +1,71 @@
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.query.BaseTest.setUpConfigForMiniCluster;
+import static org.junit.Assert.*;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.phoenix.jdbc.PhoenixDriver;
+import org.apache.phoenix.mapreduce.util.ConnectionUtil;
+import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(NeedsOwnMiniClusterTest.class)
+public class ConnectionUtilIT {
+
+    private static HBaseTestingUtility hbaseTestUtil;
+    private static Configuration conf;
+  
+    @BeforeClass
+    public static void setUp() throws Exception {
+        hbaseTestUtil = new HBaseTestingUtility();
+        conf = hbaseTestUtil.getConfiguration();
+        setUpConfigForMiniCluster(conf);
+        conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/hbase-test");
+        hbaseTestUtil.startMiniCluster();
+        Class.forName(PhoenixDriver.class.getName());
+    }
+    
+	@Test
+	public void testInputAndOutputConnections() throws SQLException {
+		Connection inputConnection = ConnectionUtil.getInputConnection(conf);
+		Statement stmt = inputConnection.createStatement();
+		stmt.execute("create table t(a integer primary key,b varchar)");
+		stmt.execute("upsert into t values(1,'foo')");
+		inputConnection.commit();
+		ResultSet rs = stmt.executeQuery("select count(*) from t");
+		rs.next();
+		assertEquals(1, rs.getInt(1));
+		Connection outputConnection = ConnectionUtil.getOutputConnection(conf);
+		stmt = outputConnection.createStatement();
+		stmt.execute("create table t1(a integer primary key,b varchar)");
+		stmt.execute("upsert into t1 values(1,'foo')");
+		outputConnection.commit();
+		rs = stmt.executeQuery("select count(*) from t1");
+		rs.next();
+		assertEquals(1, rs.getInt(1));
+	}
+
+	@AfterClass
+	public static void tearDownAfterClass() throws Exception {
+		try {
+			PhoenixDriver.INSTANCE.close();
+		} finally {
+			try {
+				DriverManager.deregisterDriver(PhoenixDriver.INSTANCE);
+			} finally {
+				hbaseTestUtil.shutdownMiniCluster();
+			}
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ce37e120/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 b4724d8..4ba33e8 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
@@ -54,8 +54,10 @@ public class ConnectionUtil {
      */
     public static Connection getInputConnection(final Configuration conf , final Properties
props) throws SQLException {
         Preconditions.checkNotNull(conf);
-        return getConnection(PhoenixConfigurationUtil.getInputCluster(conf), PhoenixConfigurationUtil.getClientPort(conf),
-                PropertiesUtil.extractProperties(props, conf));
+		return getConnection(PhoenixConfigurationUtil.getInputCluster(conf),
+				PhoenixConfigurationUtil.getClientPort(conf),
+				PhoenixConfigurationUtil.getZNodeParent(conf),
+				PropertiesUtil.extractProperties(props, conf));
     }
 
     /**
@@ -77,8 +79,10 @@ public class ConnectionUtil {
      */
     public static Connection getOutputConnection(final Configuration conf, Properties props)
throws SQLException {
         Preconditions.checkNotNull(conf);
-        return getConnection(PhoenixConfigurationUtil.getOutputCluster(conf), PhoenixConfigurationUtil.getClientPort(conf),
-                PropertiesUtil.extractProperties(props, conf));
+		return getConnection(PhoenixConfigurationUtil.getOutputCluster(conf),
+				PhoenixConfigurationUtil.getClientPort(conf),
+				PhoenixConfigurationUtil.getZNodeParent(conf),
+				PropertiesUtil.extractProperties(props, conf));
     }
 
     /**
@@ -86,11 +90,12 @@ public class ConnectionUtil {
      *
      * @param quorum a ZooKeeper quorum connection string
      * @param clientPort a ZooKeeper client port
+     * @param znodeParent a zookeeper znode parent
      * @return a Phoenix connection to the given connection string
      */
-    private static Connection getConnection(final String quorum, final Integer clientPort,
Properties props) throws SQLException {
+    private static Connection getConnection(final String quorum, final Integer clientPort,
final String znodeParent, Properties props) throws SQLException {
         Preconditions.checkNotNull(quorum);
-        return DriverManager.getConnection(clientPort!=null? QueryUtil.getUrl(quorum, clientPort)
:  QueryUtil.getUrl(quorum), props);
+        return DriverManager.getConnection(QueryUtil.getUrl(quorum, clientPort, znodeParent),
props);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ce37e120/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
index 9b27523..8bf786b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
@@ -96,8 +96,6 @@ public final class PhoenixConfigurationUtil {
     public static final String MAPREDUCE_INPUT_CLUSTER_QUORUM = "phoenix.mapreduce.input.cluster.quorum";
     
     public static final String MAPREDUCE_OUTPUT_CLUSTER_QUORUM = "phoneix.mapreduce.output.cluster.quorum";
-    
-    public static final String HBASE_ZOOKEEPER_CLIENT_PORT = "hbase.zookeeper.property.clientPort";
 
     public enum SchemaType {
         TABLE,
@@ -391,10 +389,20 @@ public final class PhoenixConfigurationUtil {
      */
     public static Integer getClientPort(final Configuration configuration) {
         Preconditions.checkNotNull(configuration);
-        String clientPortString = configuration.get(HBASE_ZOOKEEPER_CLIENT_PORT);
+        String clientPortString = configuration.get(HConstants.ZOOKEEPER_CLIENT_PORT);
         return clientPortString==null ? null : Integer.parseInt(clientPortString);
     }
 
+    /**
+     * Returns the HBase zookeeper znode parent
+     * @param configuration
+     * @return
+     */
+    public static String getZNodeParent(final Configuration configuration) {
+        Preconditions.checkNotNull(configuration);
+        return configuration.get(HConstants.ZOOKEEPER_ZNODE_PARENT);
+    }
+
     public static void loadHBaseConfiguration(Job job) throws IOException {
         // load hbase-site.xml
         Configuration hbaseConf = HBaseConfiguration.create();


Mime
View raw message