sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pras...@apache.org
Subject git commit: SENTRY-175: sentry script throws error for the dbstore service invocation. (Sravya Tirukkovalur via Prasad Mujumdar)
Date Thu, 08 May 2014 02:02:41 GMT
Repository: incubator-sentry
Updated Branches:
  refs/heads/master 0fea11ab3 -> 1a72f6197


SENTRY-175: sentry script throws error for the dbstore service invocation. (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/1a72f619
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/1a72f619
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/1a72f619

Branch: refs/heads/master
Commit: 1a72f619712ee24e0bfb3e5c97856024f3c82a2c
Parents: 0fea11a
Author: Prasad Mujumdar <prasadm@cloudera.com>
Authored: Wed May 7 19:02:20 2014 -0700
Committer: Prasad Mujumdar <prasadm@cloudera.com>
Committed: Wed May 7 19:02:20 2014 -0700

----------------------------------------------------------------------
 bin/sentry                                      |  4 +-
 .../binding/hive/authz/SentryConfigTool.java    | 19 ++++----
 .../main/java/org/apache/sentry/SentryMain.java | 26 +++++++----
 .../sentry/service/thrift/SentryService.java    | 48 ++++++++++----------
 .../sentry/service/thrift/ServiceConstants.java | 14 +++---
 5 files changed, 59 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/1a72f619/bin/sentry
----------------------------------------------------------------------
diff --git a/bin/sentry b/bin/sentry
index 81b4382..0bd37e8 100755
--- a/bin/sentry
+++ b/bin/sentry
@@ -43,7 +43,7 @@ while [ $# -gt 0 ]; do    # Until you run out of parameters . . .
       echo Using hive-home $HIVE_HOME
       ;;
     *)
-      args+=($1)
+      args+=" $1"
       shift
       ;;
   esac
@@ -61,4 +61,4 @@ for f in ${SENTRY_HOME}/lib/*.jar; do
   HADOOP_CLASSPATH=${HADOOP_CLASSPATH}:${f}
 done
 export HADOOP_CLASSPATH
-${_HIVE_CMD} --service jar ${SENTRY_HOME}/lib/${_CMD_JAR} org.apache.sentry.SentryMain "${args[@]}"
+${_HIVE_CMD} --service jar ${SENTRY_HOME}/lib/${_CMD_JAR} org.apache.sentry.SentryMain ${args[@]}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/1a72f619/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
index bc739ad..370c00d 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
@@ -17,14 +17,6 @@
 
 package org.apache.sentry.binding.hive.authz;
 
-import java.security.CodeSource;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Set;
-
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.HelpFormatter;
@@ -51,6 +43,14 @@ import org.apache.sentry.core.common.Subject;
 import org.apache.sentry.core.model.db.Server;
 import org.apache.sentry.provider.common.AuthorizationProvider;
 
+import java.security.CodeSource;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Set;
+
 public class SentryConfigTool {
   private String sentrySiteFile = null;
   private String policyFile = null;
@@ -354,7 +354,7 @@ public class SentryConfigTool {
   // print usage
   private void usage(Options sentryOptions) {
     HelpFormatter formatter = new HelpFormatter();
-    formatter.printHelp("Sentry", sentryOptions);
+    formatter.printHelp("sentry --command config-tool", sentryOptions);
     System.exit(-1);
   }
 
@@ -469,7 +469,6 @@ public class SentryConfigTool {
         throw new ParseException("Must use -u with -e ");
       }
     } catch (ParseException e1) {
-      System.out.println("Argument parsing error: " + e1.getMessage());
       usage(sentryOptions);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/1a72f619/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
index eb3482b..bf028a2 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
@@ -40,16 +40,20 @@ public class SentryMain {
     Options options = new Options();
     options.addOption(HELP_SHORT, HELP_LONG, false, "Print this help text");
     options.addOption(null, COMMAND, true, "Command to run. Options: " + COMMANDS.keySet());
-    CommandLine commandLine = parser.parse(options, args);
+    //Ignore unrecognized options: service and config-tool options
+    CommandLine commandLine = parser.parse(options, args, true);
+
+    //Print sentry help only if commandName was not given,
+    // otherwise we assume the help is for the sub command
     String commandName = commandLine.getOptionValue(COMMAND);
-    if (commandName == null || commandLine.hasOption(HELP_SHORT) ||
-        commandLine.hasOption(HELP_LONG)) {
-      printHelp(options);
+    if (commandName == null && (commandLine.hasOption(HELP_SHORT) ||
+        commandLine.hasOption(HELP_LONG))) {
+      printHelp(options, null);
     }
+
     String commandClazz = COMMANDS.get(commandName);
     if (commandClazz == null) {
-      String msg = "Unknown command '" + commandName + "', options are: " + COMMANDS.keySet();
-      throw new IllegalArgumentException(msg);
+      printHelp(options, "Unknown command " + commandName + "\n");
     }
     Object command;
     try {
@@ -65,9 +69,11 @@ public class SentryMain {
     }
     ((Command)command).run(commandLine.getArgs());
   }
-  private static void printHelp(Options options) {
-    (new HelpFormatter()).printHelp("sentry --" + COMMAND + "=" + COMMANDS.keySet(),
-        options);
+  private static void printHelp(Options options, String msg) {
+    String sentry = "sentry";
+    if(msg != null)
+      sentry = msg + sentry;
+    (new HelpFormatter()).printHelp(sentry, options);
     System.exit(1);
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/1a72f619/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
index bebaf0d..107636a 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
@@ -18,25 +18,12 @@
 
 package org.apache.sentry.service.thrift;
 
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.security.PrivilegedExceptionAction;
-import java.util.HashSet;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-import javax.security.auth.Subject;
-import javax.security.auth.kerberos.KerberosPrincipal;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Options;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.net.NetUtils;
@@ -56,8 +43,20 @@ import org.apache.thrift.transport.TTransportFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
+import javax.security.auth.Subject;
+import javax.security.auth.kerberos.KerberosPrincipal;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 
 public class SentryService implements Runnable {
 
@@ -264,15 +263,18 @@ public class SentryService implements Runnable {
     public void run(String[] args) throws Exception {
       CommandLineParser parser = new GnuParser();
       Options options = new Options();
-      options.addOption(null, ServiceConstants.ServiceArgs.CONFIG_FILE,
+      options.addOption(ServiceConstants.ServiceArgs.CONFIG_FILE_SHORT,
+          ServiceConstants.ServiceArgs.CONFIG_FILE_LONG,
           true, "Sentry Service configuration file");
       CommandLine commandLine = parser.parse(options, args);
       String configFileName = commandLine.getOptionValue(ServiceConstants.
-          ServiceArgs.CONFIG_FILE);
+          ServiceArgs.CONFIG_FILE_LONG);
       File configFile = null;
-      if (configFileName == null) {
-        throw new IllegalArgumentException("Usage: " + ServiceConstants.ServiceArgs.CONFIG_FILE
+
-            " path/to/sentry-service.xml");
+      if (configFileName == null || commandLine.hasOption("h") || commandLine.hasOption("help"))
{
+        // print usage
+          HelpFormatter formatter = new HelpFormatter();
+          formatter.printHelp("sentry --command service", options);
+          System.exit(-1);
       } else if(!((configFile = new File(configFileName)).isFile() && configFile.canRead()))
{
         throw new IllegalArgumentException("Cannot read configuration file " + configFile);
       }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/1a72f619/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
index 6258471..76b3ebe 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
@@ -17,14 +17,13 @@
  */
 package org.apache.sentry.service.thrift;
 
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.security.sasl.Sasl;
-
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableMap;
 
+import javax.security.sasl.Sasl;
+import java.util.HashMap;
+import java.util.Map;
+
 public class ServiceConstants {
 
   private static final ImmutableMap<String, String> SASL_PROPERTIES;
@@ -41,7 +40,8 @@ public class ServiceConstants {
         .trimResults().omitEmptyStrings();
   }
   public static class ServiceArgs {
-    public static final String CONFIG_FILE = "--conf-file";
+    public static final String CONFIG_FILE_SHORT = "c";
+    public static final String CONFIG_FILE_LONG = "conffile";
   }
   public static class ServerConfig {
     public static final ImmutableMap<String, String> SASL_PROPERTIES = ServiceConstants.SASL_PROPERTIES;
@@ -131,4 +131,4 @@ public class ServiceConstants {
     TABLE,
     COLUMN
   }
-}
+}
\ No newline at end of file


Mime
View raw message