sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shreepa...@apache.org
Subject git commit: SENTRY-12: Write the policy file to hdfs when using UnmanagedHiveServer (Sravya Tirukkovalur via Shreepadma Venugopalan)
Date Thu, 03 Oct 2013 23:53:24 GMT
Updated Branches:
  refs/heads/master 6407c6a24 -> 9c7cd3731


SENTRY-12: Write the policy file to hdfs when using UnmanagedHiveServer (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/9c7cd373
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/9c7cd373
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/9c7cd373

Branch: refs/heads/master
Commit: 9c7cd3731b8341d79b00d2c68a1bdf9bbe1e0b27
Parents: 6407c6a
Author: Shreepadma Venugopalan <shreepadma@apache.org>
Authored: Thu Oct 3 16:52:51 2013 -0700
Committer: Shreepadma Venugopalan <shreepadma@apache.org>
Committed: Thu Oct 3 16:52:51 2013 -0700

----------------------------------------------------------------------
 .../apache/sentry/provider/file/PolicyFile.java | 52 +++++++++++++++++++-
 1 file changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/9c7cd373/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
index 3f2283e..32984dd 100644
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.base.Preconditions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -118,7 +119,7 @@ public class PolicyFile {
     return other;
   }
 
-  public void write(File file) throws IOException {
+  public void write(File file) throws Exception {
     if(file.exists() && !file.delete()) {
       throw new IllegalStateException("Unable to delete " + file);
     }
@@ -130,7 +131,54 @@ public class PolicyFile {
             "");
     LOGGER.info("Writing policy file to " + file + ":\n" + contents);
     Files.write(contents, file, Charsets.UTF_8);
+
+    String hiveServer2 = System.getProperty("sentry.e2etest.hiveServer2Type", "InternalHiveServer2");
+    if(hiveServer2.equals("UnmanagedHiveServer2")){
+
+      String policyLocation = System.getProperty("sentry.e2etest.policyLocation", "/user/hive/sentry/sentry-provider.ini");
+      String policyOnHDFS = System.getProperty("sentry.e2etest.policyOnHDFS", "true");
+      LOGGER.info("Moving policy file to " + policyLocation);
+
+      if( policyOnHDFS.trim().equalsIgnoreCase("true")){
+        String userKeytab = System.getProperty("sentry.e2etest.policyOwnerKeytab");
+        String userPrincipal = System.getProperty("sentry.e2etest.policyOwnerPrincipal");
+        Preconditions.checkNotNull(userKeytab);
+        Preconditions.checkNotNull(userPrincipal);
+        hdfsPut(file, policyLocation, userKeytab, userPrincipal);
+      }else{
+        Files.copy(file,new File(policyLocation));
+      }
+    }
   }
+
+  private void hdfsPut(File file, String hdfsPath, String userKeytab, String userPrincipal)
throws Exception {
+    String command, status;
+    Process p;
+
+    command = "kinit -kt " + userKeytab +  " " + userPrincipal;
+    p = Runtime.getRuntime().exec(command);
+    if(p.waitFor()!=0) {
+      throw new Exception("Setup incomplete. " + command + " FAILED");
+    }
+    else {
+      LOGGER.info("Command:" + command + " PASSED");
+    }
+
+    command = "hdfs dfs -rm " + hdfsPath;
+    p = Runtime.getRuntime().exec(command);
+    status = (p.waitFor()==0)?"PASSED":"FAILED";
+    LOGGER.warn("Command:" + command + " " + status);
+
+    command = "hdfs dfs -put " + file.getAbsolutePath() + " " + hdfsPath;
+    p = Runtime.getRuntime().exec(command);
+    if(p.waitFor()!=0) {
+      throw new Exception("Setup incomplete. " + command + " FAILED");
+    }
+    else {
+      LOGGER.info("Command:" + command + " PASSED");
+    }
+  }
+
   private String getSection(String name, Map<String, String> mapping) {
     if(mapping.isEmpty()) {
       return "";
@@ -181,4 +229,4 @@ public class PolicyFile {
       .addRolesToGroup(admin, "admin_role")
       .addPermissionsToRole("admin_role", "server=server1");
   }
-}
\ No newline at end of file
+}


Mime
View raw message