You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by sh...@apache.org on 2013/09/20 23:27:42 UTC
git commit: SENTRY-13: Move createConnection to HiveServer
Implementation (from Context) (Sravya Tirukkovalur via Shreepadma
Venugopalan)
Updated Branches:
refs/heads/master 2dbf28a49 -> 3c232e191
SENTRY-13: Move createConnection to HiveServer Implementation (from Context) (Sravya Tirukkovalur via Shreepadma Venugopalan)
Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/3c232e19
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/3c232e19
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/3c232e19
Branch: refs/heads/master
Commit: 3c232e191ab0f18d00b503febc409da920382acc
Parents: 2dbf28a
Author: Shreepadma Venugopalan <sh...@apache.org>
Authored: Fri Sep 20 14:27:07 2013 -0700
Committer: Shreepadma Venugopalan <sh...@apache.org>
Committed: Fri Sep 20 14:27:07 2013 -0700
----------------------------------------------------------------------
.../org/apache/sentry/tests/e2e/Context.java | 3 +-
.../e2e/hiveserver/AbstractHiveServer.java | 6 ++
.../e2e/hiveserver/EmbeddedHiveServer.java | 9 +++
.../sentry/tests/e2e/hiveserver/HiveServer.java | 4 ++
.../tests/e2e/hiveserver/HiveServerFactory.java | 2 +-
.../e2e/hiveserver/UnmanagedHiveServer.java | 68 ++++++++++++++++++--
6 files changed, 85 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/3c232e19/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/Context.java
----------------------------------------------------------------------
diff --git a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/Context.java b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/Context.java
index 30d1aaa..45ec493 100644
--- a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/Context.java
+++ b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/Context.java
@@ -74,8 +74,7 @@ public class Context {
}
public Connection createConnection(String username, String password) throws Exception {
- String url = hiveServer.getURL();
- Connection connection = DriverManager.getConnection(url, username, password);
+ Connection connection = hiveServer.createConnection(username, password);
connections.add(connection);
assertNotNull("Connection is null", connection);
assertFalse("Connection should not be closed", connection.isClosed());
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/3c232e19/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/AbstractHiveServer.java
----------------------------------------------------------------------
diff --git a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/AbstractHiveServer.java b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/AbstractHiveServer.java
index 0c2fbc3..413ef52 100644
--- a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/AbstractHiveServer.java
+++ b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/AbstractHiveServer.java
@@ -52,6 +52,12 @@ public abstract class AbstractHiveServer implements HiveServer {
return "jdbc:hive2://" + hostname + ":" + port + "/default";
}
+ public Connection createConnection(String user, String password) throws Exception{
+ String url = getURL();
+ Connection connection = DriverManager.getConnection(url, user, password);
+ return connection;
+ }
+
protected static String getHostname(HiveConf hiveConf) {
return hiveConf.get(ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST.toString(), "localhost").trim();
}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/3c232e19/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/EmbeddedHiveServer.java
----------------------------------------------------------------------
diff --git a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/EmbeddedHiveServer.java b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/EmbeddedHiveServer.java
index 48c112c..ba9a913 100644
--- a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/EmbeddedHiveServer.java
+++ b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/EmbeddedHiveServer.java
@@ -20,6 +20,9 @@ package org.apache.sentry.tests.e2e.hiveserver;
import org.apache.hadoop.hive.metastore.HiveMetaStore;
import org.fest.reflect.core.Reflection;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
public class EmbeddedHiveServer implements HiveServer {
@Override
@@ -33,6 +36,12 @@ public class EmbeddedHiveServer implements HiveServer {
.set(false);
}
+ public Connection createConnection(String user, String password) throws Exception{
+ String url = getURL();
+ Connection connection = DriverManager.getConnection(url, user, password);
+ return connection;
+ }
+
@Override
public void shutdown() {
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/3c232e19/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServer.java
----------------------------------------------------------------------
diff --git a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServer.java b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServer.java
index ce4b3e8..8f519a4 100644
--- a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServer.java
+++ b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServer.java
@@ -17,6 +17,8 @@
package org.apache.sentry.tests.e2e.hiveserver;
+import java.sql.Connection;
+
public interface HiveServer {
public void start() throws Exception;
@@ -27,4 +29,6 @@ public interface HiveServer {
public String getProperty(String key);
+ public Connection createConnection(String user, String password) throws Exception;
+
}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/3c232e19/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServerFactory.java
----------------------------------------------------------------------
diff --git a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServerFactory.java b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServerFactory.java
index af3344e..628b247 100644
--- a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServerFactory.java
+++ b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/HiveServerFactory.java
@@ -189,7 +189,7 @@ public class HiveServerFactory {
return new ExternalHiveServer(hiveConf, confDir, logDir);
case UnmanagedHiveServer2:
LOGGER.info("Creating UnmanagedHiveServer");
- return new UnmanagedHiveServer(hiveConf);
+ return new UnmanagedHiveServer();
default:
throw new UnsupportedOperationException(type.name());
}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/3c232e19/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/UnmanagedHiveServer.java
----------------------------------------------------------------------
diff --git a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/UnmanagedHiveServer.java b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/UnmanagedHiveServer.java
index 288d2f7..7a92ba1 100644
--- a/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/UnmanagedHiveServer.java
+++ b/sentry-tests/src/test/java/org/apache/sentry/tests/e2e/hiveserver/UnmanagedHiveServer.java
@@ -16,21 +16,81 @@
*/
package org.apache.sentry.tests.e2e.hiveserver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
import org.apache.hadoop.hive.conf.HiveConf;
-public class UnmanagedHiveServer extends AbstractHiveServer {
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Properties;
+
+public class UnmanagedHiveServer implements HiveServer {
+ private static final Logger LOGGER = LoggerFactory.getLogger(UnmanagedHiveServer.class);
+ public static String hostname;
+ public static int port;
+ public static final String hs2Host = System.getProperty("hs2Host");
+ public static final int hs2Port = Integer.parseInt(System.getProperty("hivePort", "10000"));
+ public static final String auth = System.getProperty("auth", "kerberos");
+ public static final String hivePrincipal = System.getProperty("hivePrincipal");
+ public static final String kerbRealm = System.getProperty("kerberosRealm");
+ private HiveConf hiveConf;
- public UnmanagedHiveServer(HiveConf conf) {
- super(conf, getHostname(conf), getPort(conf));
+ public UnmanagedHiveServer() {
+ Preconditions.checkNotNull(hs2Host);
+ if(auth.equalsIgnoreCase("kerberos")){
+ Preconditions.checkNotNull(kerbRealm);
+ Preconditions.checkNotNull(hivePrincipal);
+ }
+ this.hostname = hs2Host;
+ this.port = hs2Port;
+ hiveConf = new HiveConf();
}
@Override
public void start() throws Exception {
- waitForStartup(this);
+ //For Unmanaged HiveServer, service need not be started within the test
}
@Override
public void shutdown() throws Exception {
+ //For Unmanaged HiveServer, service need not be stopped within the test
+ }
+
+ @Override
+ public String getURL() {
+ return "jdbc:hive2://" + hostname + ":" + port + "/default;";
+ }
+
+ @Override
+ public String getProperty(String key) {
+ return hiveConf.get(key);
+ }
+
+ @Override
+ public Connection createConnection(String user, String password) throws Exception{
+ String url = getURL();
+ Properties oProps = new Properties();
+
+ if(auth.equalsIgnoreCase("kerberos")){
+ String commandFormat = "kinit -kt /cdep/keytabs/%s.keytab %s@" + kerbRealm;
+ String command = String.format(commandFormat, user, user, user);
+ Process proc = Runtime.getRuntime().exec(command);
+ String status = (proc.waitFor()==0)?"passed":"failed";
+ LOGGER.info(command + ": " + status);
+
+ command = "kinit -R";
+ proc = Runtime.getRuntime().exec(command);
+ status = (proc.waitFor()==0)?"passed":"failed";
+ LOGGER.info(command + ": " + status);
+ url += "principal=" + hivePrincipal;
+ }else{
+ oProps.setProperty("user",user);
+ oProps.setProperty("password",password);
+ }
+ LOGGER.info("url: " + url);
+ return DriverManager.getConnection(url, oProps);
}
}