You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by pr...@apache.org on 2014/05/20 00:59:55 UTC
git commit: SENTRY-218: Use defaults for user,
password and driver in SchemaTool (Sravya Tirukkovalur via Prasad
Mujumdar)
Repository: incubator-sentry
Updated Branches:
refs/heads/master a27f633d2 -> 37d8e8457
SENTRY-218: Use defaults for user, password and driver in SchemaTool (Sravya Tirukkovalur via Prasad Mujumdar)
Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/37d8e845
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/37d8e845
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/37d8e845
Branch: refs/heads/master
Commit: 37d8e84572183b980663255ed0cdd8a89b06f963
Parents: a27f633
Author: Prasad Mujumdar <pr...@cloudera.com>
Authored: Mon May 19 07:34:52 2014 -0700
Committer: Prasad Mujumdar <pr...@cloudera.com>
Committed: Mon May 19 07:34:52 2014 -0700
----------------------------------------------------------------------
.../persistent/SentryStoreSchemaInfo.java | 2 +-
.../provider/db/tools/SentrySchemaTool.java | 84 +++++++++++---------
.../provider/db/tools/TestSentrySchemaTool.java | 24 ++++--
3 files changed, 65 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/37d8e845/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStoreSchemaInfo.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStoreSchemaInfo.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStoreSchemaInfo.java
index 0b5d1ca..d6f8cad 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStoreSchemaInfo.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStoreSchemaInfo.java
@@ -78,7 +78,7 @@ public class SentryStoreSchemaInfo {
* Target version. If it's null, then the current server version is
* used
* @return
- * @throws HiveMetaException
+ * @throws SentryUserException
*/
public String generateInitFileName(String toVersion)
throws SentryUserException {
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/37d8e845/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaTool.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaTool.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaTool.java
index 79977cf..1aa767e 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaTool.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaTool.java
@@ -58,9 +58,11 @@ public class SentrySchemaTool {
+ File.separatorChar + "sentrystore" + File.separatorChar + "upgrade";
private String userName = null;
private String passWord = null;
+ private String connectionURL = null;
+ private String driver = null;
private boolean dryRun = false;
- private boolean verbose = false;
private String dbOpts = null;
+ private boolean verbose = false;
private final Configuration sentryConf;
private final String dbType;
private final SentryStoreSchemaInfo SentryStoreSchemaInfo;
@@ -79,10 +81,25 @@ public class SentrySchemaTool {
this.dbType = dbType;
this.SentryStoreSchemaInfo = new SentryStoreSchemaInfo(sentryScripPath,
dbType);
- userName = sentryConf
- .get(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_USER);
- passWord = sentryConf
- .get(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_PASS);
+ userName = sentryConf.get(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_USER,
+ ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_USER_DEFAULT);
+ passWord = sentryConf.get(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_PASS,
+ ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_PASS_DEFAULT);
+ try {
+ connectionURL = getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_URL);
+ if(dbType == SentrySchemaHelper.DB_DERBY) {
+ driver = sentryConf.get(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER,
+ ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER_DEFAULT);
+ } else {
+ driver = getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER);
+ }
+ // load required JDBC driver
+ Class.forName(driver);
+ } catch (IOException e) {
+ throw new SentryUserException("Missing property", e);
+ } catch (ClassNotFoundException e) {
+ throw new SentryUserException("Failed to load driver", e);
+ }
}
public Configuration getConfiguration() {
@@ -121,7 +138,7 @@ public class SentrySchemaTool {
/***
* Print Hive version and schema version
- * @throws MetaException
+ * @throws SentryUserException
*/
public void showInfo() throws SentryUserException {
Connection sentryStoreConn = getConnectionToMetastore(true);
@@ -169,39 +186,29 @@ public class SentrySchemaTool {
*
* @param printInfo print connection parameters
* @return
- * @throws MetaException
+ * @throws SentryUserException
*/
private Connection getConnectionToMetastore(boolean printInfo)
throws SentryUserException {
+ if (printInfo) {
+ System.out.println("Sentry store connection URL:\t " + connectionURL);
+ System.out.println("Sentry store Connection Driver :\t " + driver);
+ System.out.println("Sentry store connection User:\t " + userName);
+ }
+ if ((userName == null) || userName.isEmpty()) {
+ throw new SentryUserException("UserName empty ");
+ }
try {
- String connectionURL = getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_URL);
- String driver = getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER);
- if (printInfo) {
- System.out.println("Metastore connection URL:\t " + connectionURL);
- System.out.println("Metastore Connection Driver :\t " + driver);
- System.out.println("Metastore connection User:\t " + userName);
- }
- if ((userName == null) || userName.isEmpty()) {
- throw new SentryUserException("UserName empty ");
- }
-
- // load required JDBC driver
- Class.forName(driver);
-
// Connect using the JDBC URL and user/pass from conf
return DriverManager.getConnection(connectionURL, userName, passWord);
- } catch (IOException e) {
- throw new SentryUserException("Failed to get schema version.", e);
} catch (SQLException e) {
- throw new SentryUserException("Failed to get schema version.", e);
- } catch (ClassNotFoundException e) {
- throw new SentryUserException("Failed to load driver", e);
+ throw new SentryUserException("Failed to make connection to Sentry store.", e);
}
}
/**
* check if the current schema version in sentry store matches the Hive version
- * @throws MetaException
+ * @throws SentryUserException
*/
public void verifySchemaVersion() throws SentryUserException {
// don't check version if its a dry run
@@ -220,7 +227,7 @@ public class SentrySchemaTool {
/**
* Perform sentry store schema upgrade. extract the current schema version from sentry store
- * @throws MetaException
+ * @throws SentryUserException
*/
public void doUpgrade() throws SentryUserException {
String fromVersion = getMetaStoreSchemaVersion(getConnectionToMetastore(false));
@@ -238,7 +245,7 @@ public class SentrySchemaTool {
*
* @param fromSchemaVer
* Existing version of the sentry store. If null, then read from the sentry store
- * @throws MetaException
+ * @throws SentryUserException
*/
public void doUpgrade(String fromSchemaVer) throws SentryUserException {
if (SentryStoreSchemaInfo.getSentrySchemaVersion().equals(fromSchemaVer)) {
@@ -273,7 +280,7 @@ public class SentrySchemaTool {
/**
* Initialize the sentry store schema to current version
*
- * @throws MetaException
+ * @throws SentryUserException
*/
public void doInit() throws SentryUserException {
doInit(SentryStoreSchemaInfo.getSentrySchemaVersion());
@@ -287,7 +294,7 @@ public class SentrySchemaTool {
*
* @param toVersion
* If null then current hive version is used
- * @throws MetaException
+ * @throws SentryUserException
*/
public void doInit(String toVersion) throws SentryUserException {
testConnectionToMetastore();
@@ -384,10 +391,10 @@ public class SentrySchemaTool {
public void runBeeLine(String sqlScriptFile) throws IOException {
List<String> argList = new ArrayList<String>();
argList.add("-u");
- argList.add(getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_URL));
+ argList.add(connectionURL);
argList.add("-d");
argList
- .add(getValidConfVar(ServiceConstants.ServerConfig.SENTRY_STORE_JDBC_DRIVER));
+ .add(driver);
argList.add("-n");
argList.add(userName);
argList.add("-p");
@@ -438,15 +445,19 @@ public class SentrySchemaTool {
optGroup.setRequired(true);
Option userNameOpt = OptionBuilder.withArgName("user")
- .hasArgs()
+ .hasArg()
.withDescription("Override config file user name")
.create("userName");
Option passwdOpt = OptionBuilder.withArgName("password")
- .hasArgs()
+ .hasArg()
.withDescription("Override config file password")
.create("passWord");
Option dbTypeOpt = OptionBuilder.withArgName("databaseType")
- .hasArgs().withDescription("Metastore database type")
+ .hasArg().withDescription("Metastore database type [" +
+ SentrySchemaHelper.DB_DERBY + "," +
+ SentrySchemaHelper.DB_MYSQL + "," +
+ SentrySchemaHelper.DB_ORACLE + "," +
+ SentrySchemaHelper.DB_POSTGRACE + "]")
.create("dbType");
Option dbOpts = OptionBuilder.withArgName("databaseOpts")
.hasArgs().withDescription("Backend DB specific options")
@@ -516,7 +527,6 @@ public class SentrySchemaTool {
System.err.println("no config file specified");
printAndExit(cmdLineOptions);
}
-
try {
SentrySchemaTool schemaTool = new SentrySchemaTool(
SentryService.loadConfig(configFileName), dbType);
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/37d8e845/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentrySchemaTool.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentrySchemaTool.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentrySchemaTool.java
index ce09f62..38a2e01 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentrySchemaTool.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/tools/TestSentrySchemaTool.java
@@ -34,21 +34,31 @@ public class TestSentrySchemaTool {
private SentrySchemaTool schemaTool;
@Before
- public void setup() throws Exception {
+ public void defaultSetup() throws Exception {
sentryConf = new Configuration();
File dbDir = new File(Files.createTempDir(), "sentry_policy_db");
sentryConf.set(ServerConfig.SENTRY_STORE_JDBC_URL,
"jdbc:derby:;databaseName=" + dbDir.getPath() + ";create=true");
- sentryConf.set(ServerConfig.SENTRY_STORE_JDBC_DRIVER,
- ServerConfig.SENTRY_STORE_JDBC_DRIVER_DEFAULT);
- sentryConf.set(ServerConfig.SENTRY_STORE_JDBC_USER,
- ServerConfig.SENTRY_STORE_JDBC_USER_DEFAULT);
- sentryConf.set(ServerConfig.SENTRY_STORE_JDBC_PASS,
- ServerConfig.SENTRY_STORE_JDBC_PASS_DEFAULT);
schemaTool = new SentrySchemaTool("./src/main/resources", sentryConf,
"derby");
}
+ private void nonDefaultsetup() throws Exception {
+ sentryConf = new Configuration();
+ File dbDir = new File(Files.createTempDir(), "sentry_policy_db");
+ sentryConf.set(ServerConfig.SENTRY_STORE_JDBC_URL,
+ "jdbc:derby:;databaseName=" + dbDir.getPath() + ";create=true");
+ schemaTool = new SentrySchemaTool("./src/main/resources", sentryConf,
+ "derby");
+ }
+
+ @Test
+ public void testInitNonDefault() throws Exception {
+ nonDefaultsetup();
+ schemaTool.doInit();
+ schemaTool.verifySchemaVersion();
+ }
+
@Test
public void testInit() throws Exception {
schemaTool.doInit();