sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pras...@apache.org
Subject git commit: SENTRY-260: Add support to use DB2 as database for sentry metastore (Ruiming Zhou via Prasad Mujumdar)
Date Tue, 08 Jul 2014 01:16:08 GMT
Repository: incubator-sentry
Updated Branches:
  refs/heads/master d1727c512 -> 56d4f563b


SENTRY-260: Add support to use DB2 as database for sentry metastore (Ruiming Zhou 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/56d4f563
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/56d4f563
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/56d4f563

Branch: refs/heads/master
Commit: 56d4f563bc251e22cc1ee529b265f5b2b52b0258
Parents: d1727c5
Author: Prasad Mujumdar <prasadm@cloudera.com>
Authored: Mon Jul 7 18:15:36 2014 -0700
Committer: Prasad Mujumdar <prasadm@cloudera.com>
Committed: Mon Jul 7 18:15:36 2014 -0700

----------------------------------------------------------------------
 .../provider/db/tools/SentrySchemaHelper.java   |  21 +++-
 .../provider/db/tools/SentrySchemaTool.java     |   8 +-
 .../src/main/resources/sentry-db2-1.4.0.sql     | 112 +++++++++++++++++++
 .../src/main/resources/upgrade.order.db2        |   0
 4 files changed, 137 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/56d4f563/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaHelper.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaHelper.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaHelper.java
index 24fe980..e3e04f1 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaHelper.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/SentrySchemaHelper.java
@@ -24,6 +24,7 @@ public class SentrySchemaHelper {
   public static final String DB_MYSQL = "mysql";
   public static final String DB_POSTGRACE = "postgres";
   public static final String DB_ORACLE = "oracle";
+  public static final String DB_DB2 = "db2";
 
   public interface NestedScriptParser {
 
@@ -281,6 +282,22 @@ public class SentrySchemaHelper {
     }
   }
 
+  // DB2 commandline parser
+  public static class DB2CommandParser extends AbstractCommandParser {
+
+    @Override
+    public String getScriptName(String dbCommand) throws IllegalArgumentException {
+        //DB2 does not support nesting script
+        throw new IllegalArgumentException("DB2 does not support nesting script " + dbCommand);
+    }
+
+    @Override
+    public boolean isNestedScript(String dbCommand) {
+        //DB2 does not support nesting script
+     return false;
+    }
+  }
+
   public static NestedScriptParser getDbCommandParser(String dbName) {
     if (dbName.equalsIgnoreCase(DB_DERBY)) {
       return new DerbyCommandParser();
@@ -289,7 +306,9 @@ public class SentrySchemaHelper {
     } else if (dbName.equalsIgnoreCase(DB_POSTGRACE)) {
       return new PostgresCommandParser();
     } else if (dbName.equalsIgnoreCase(DB_ORACLE)) {
-      return new OracleCommandParser();
+        return new OracleCommandParser();
+    } else if (dbName.equalsIgnoreCase(DB_DB2)) {
+      return new DB2CommandParser();
     } else {
       throw new IllegalArgumentException("Unknown dbType " + dbName);
     }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/56d4f563/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 164876d..69086d2 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
@@ -457,7 +457,8 @@ public class SentrySchemaTool {
                 SentrySchemaHelper.DB_DERBY + "," +
                 SentrySchemaHelper.DB_MYSQL + "," +
                 SentrySchemaHelper.DB_ORACLE + "," +
-                SentrySchemaHelper.DB_POSTGRACE + "]")
+                SentrySchemaHelper.DB_POSTGRACE + "," +
+                SentrySchemaHelper.DB_DB2 + "]")
                 .create("dbType");
     Option dbOpts = OptionBuilder.withArgName("databaseOpts")
                 .hasArgs().withDescription("Backend DB specific options")
@@ -511,8 +512,9 @@ public class SentrySchemaTool {
         dbType = line.getOptionValue("dbType");
         if ((!dbType.equalsIgnoreCase(SentrySchemaHelper.DB_DERBY)
             && !dbType.equalsIgnoreCase(SentrySchemaHelper.DB_MYSQL)
-            && !dbType.equalsIgnoreCase(SentrySchemaHelper.DB_POSTGRACE) &&
!dbType
-              .equalsIgnoreCase(SentrySchemaHelper.DB_ORACLE))) {
+            && !dbType.equalsIgnoreCase(SentrySchemaHelper.DB_POSTGRACE)
+            && !dbType.equalsIgnoreCase(SentrySchemaHelper.DB_ORACLE)
+            && !dbType.equalsIgnoreCase(SentrySchemaHelper.DB_DB2))) {
           System.err.println("Unsupported dbType " + dbType);
           printAndExit(cmdLineOptions);
         }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/56d4f563/sentry-provider/sentry-provider-db/src/main/resources/sentry-db2-1.4.0.sql
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/resources/sentry-db2-1.4.0.sql b/sentry-provider/sentry-provider-db/src/main/resources/sentry-db2-1.4.0.sql
new file mode 100644
index 0000000..f2a62d2
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/main/resources/sentry-db2-1.4.0.sql
@@ -0,0 +1,112 @@
+--Licensed to the Apache Software Foundation (ASF) under one or more
+--contributor license agreements.  See the NOTICE file distributed with
+--this work for additional information regarding copyright ownership.
+--The ASF licenses this file to You under the Apache License, Version 2.0
+--(the "License"); you may not use this file except in compliance with
+--the License.  You may obtain a copy of the License at
+--
+--    http://www.apache.org/licenses/LICENSE-2.0
+--
+--Unless required by applicable law or agreed to in writing, software
+--distributed under the License is distributed on an "AS IS" BASIS,
+--WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+--See the License for the specific language governing permissions and
+--limitations under the License.
+
+-- Table SENTRY_DB_PRIVILEGE for classes [org.apache.sentry.provider.db.service.model.MSentryPrivilege]
+CREATE TABLE SENTRY_DB_PRIVILEGE
+(
+    DB_PRIVILEGE_ID BIGINT NOT NULL generated always as identity (start with 1),
+    URI VARCHAR(4000),
+    "ACTION" VARCHAR(40),
+    CREATE_TIME BIGINT NOT NULL,
+    DB_NAME VARCHAR(4000),
+    GRANTOR_PRINCIPAL VARCHAR(4000),
+    PRIVILEGE_NAME VARCHAR(4000),
+    PRIVILEGE_SCOPE VARCHAR(40),
+    "SERVER_NAME" VARCHAR(4000),
+    "TABLE_NAME" VARCHAR(4000)
+);
+
+ALTER TABLE SENTRY_DB_PRIVILEGE ADD CONSTRAINT SENTRY_DB_PRIVILEGE_PK PRIMARY KEY (DB_PRIVILEGE_ID);
+
+-- Table SENTRY_ROLE for classes [org.apache.sentry.provider.db.service.model.MSentryRole]
+CREATE TABLE SENTRY_ROLE
+(
+    ROLE_ID BIGINT NOT NULL generated always as identity (start with 1),
+    CREATE_TIME BIGINT NOT NULL,
+    GRANTOR_PRINCIPAL VARCHAR(4000),
+    ROLE_NAME VARCHAR(128)
+);
+
+ALTER TABLE SENTRY_ROLE ADD CONSTRAINT SENTRY_ROLE_PK PRIMARY KEY (ROLE_ID);
+
+-- Table SENTRY_GROUP for classes [org.apache.sentry.provider.db.service.model.MSentryGroup]
+CREATE TABLE SENTRY_GROUP
+(
+    GROUP_ID BIGINT NOT NULL generated always as identity (start with 1),
+    CREATE_TIME BIGINT NOT NULL,
+    GRANTOR_PRINCIPAL VARCHAR(4000),
+    GROUP_NAME VARCHAR(128)
+);
+
+ALTER TABLE SENTRY_GROUP ADD CONSTRAINT SENTRY_GROUP_PK PRIMARY KEY (GROUP_ID);
+
+-- Table SENTRY_ROLE_GROUP_MAP for join relationship
+CREATE TABLE SENTRY_ROLE_GROUP_MAP
+(
+    GROUP_ID BIGINT NOT NULL,
+    ROLE_ID BIGINT NOT NULL
+);
+
+ALTER TABLE SENTRY_ROLE_GROUP_MAP ADD CONSTRAINT SENTRY_ROLE_GROUP_MAP_PK PRIMARY KEY (GROUP_ID,ROLE_ID);
+
+-- Table SENTRY_ROLE_DB_PRIVILEGE_MAP for join relationship
+CREATE TABLE SENTRY_ROLE_DB_PRIVILEGE_MAP
+(
+    ROLE_ID BIGINT NOT NULL,
+    DB_PRIVILEGE_ID BIGINT NOT NULL
+);
+
+ALTER TABLE SENTRY_ROLE_DB_PRIVILEGE_MAP ADD CONSTRAINT SENTRY_ROLE_DB_PRIVILEGE_MAP_PK PRIMARY
KEY (ROLE_ID,DB_PRIVILEGE_ID);
+
+CREATE TABLE "SENTRY_VERSION" (
+  VER_ID BIGINT NOT NULL,
+  SCHEMA_VERSION VARCHAR(127),
+  VERSION_COMMENT VARCHAR(255)
+);
+
+ALTER TABLE SENTRY_VERSION ADD CONSTRAINT SENTRY_VERSION_PK PRIMARY KEY (VER_ID);
+
+-- Constraints for table SENTRY_DB_PRIVILEGE for class(es) [org.apache.sentry.provider.db.service.model.MSentryPrivilege]
+CREATE UNIQUE INDEX SENTRYPRIVILEGENAME ON SENTRY_DB_PRIVILEGE (PRIVILEGE_NAME);
+
+
+-- Constraints for table SENTRY_ROLE for class(es) [org.apache.sentry.provider.db.service.model.MSentryRole]
+CREATE UNIQUE INDEX SENTRYROLENAME ON SENTRY_ROLE (ROLE_NAME);
+
+
+-- Constraints for table SENTRY_GROUP for class(es) [org.apache.sentry.provider.db.service.model.MSentryGroup]
+CREATE UNIQUE INDEX SENTRYGROUPNAME ON SENTRY_GROUP (GROUP_NAME);
+
+
+-- Constraints for table SENTRY_ROLE_GROUP_MAP
+CREATE INDEX SENTRY_ROLE_GROUP_MAP_N49 ON SENTRY_ROLE_GROUP_MAP (GROUP_ID);
+
+CREATE INDEX SENTRY_ROLE_GROUP_MAP_N50 ON SENTRY_ROLE_GROUP_MAP (ROLE_ID);
+
+ALTER TABLE SENTRY_ROLE_GROUP_MAP ADD CONSTRAINT SENTRY_ROLE_GROUP_MAP_FK2 FOREIGN KEY (ROLE_ID)
REFERENCES SENTRY_ROLE (ROLE_ID) ;
+
+ALTER TABLE SENTRY_ROLE_GROUP_MAP ADD CONSTRAINT SENTRY_ROLE_GROUP_MAP_FK1 FOREIGN KEY (GROUP_ID)
REFERENCES SENTRY_GROUP (GROUP_ID) ;
+
+
+-- Constraints for table SENTRY_ROLE_DB_PRIVILEGE_MAP
+CREATE INDEX SENTRY_ROLE_DB_PRIVILEGE_MAP_N50 ON SENTRY_ROLE_DB_PRIVILEGE_MAP (ROLE_ID);
+
+CREATE INDEX SENTRY_ROLE_DB_PRIVILEGE_MAP_N49 ON SENTRY_ROLE_DB_PRIVILEGE_MAP (DB_PRIVILEGE_ID);
+
+ALTER TABLE SENTRY_ROLE_DB_PRIVILEGE_MAP ADD CONSTRAINT SENTRY_ROLE_DB_PRIVILEGE_MAP_FK2
FOREIGN KEY (DB_PRIVILEGE_ID) REFERENCES SENTRY_DB_PRIVILEGE (DB_PRIVILEGE_ID) ;
+
+ALTER TABLE SENTRY_ROLE_DB_PRIVILEGE_MAP ADD CONSTRAINT SENTRY_ROLE_DB_PRIVILEGE_MAP_FK1
FOREIGN KEY (ROLE_ID) REFERENCES SENTRY_ROLE (ROLE_ID) ;
+
+INSERT INTO SENTRY_VERSION (VER_ID, SCHEMA_VERSION, VERSION_COMMENT) VALUES (1, '1.4.0',
'Sentry release version 1.4.0');

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/56d4f563/sentry-provider/sentry-provider-db/src/main/resources/upgrade.order.db2
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/resources/upgrade.order.db2 b/sentry-provider/sentry-provider-db/src/main/resources/upgrade.order.db2
new file mode 100644
index 0000000..e69de29


Mime
View raw message