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 2014/03/07 21:04:38 UTC
git commit: SENTRY-130: Integrate sentry script (Brock via Shreepadma)
Repository: incubator-sentry
Updated Branches:
refs/heads/db_policy_store 62b22be9c -> bd511cdb2
SENTRY-130: Integrate sentry script (Brock via Shreepadma)
Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/bd511cdb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/bd511cdb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/bd511cdb
Branch: refs/heads/db_policy_store
Commit: bd511cdb284d8e8048bc85a5ea171c09535fe485
Parents: 62b22be
Author: Shreepadma Venugopalan <sh...@apache.org>
Authored: Fri Mar 7 12:04:12 2014 -0800
Committer: Shreepadma Venugopalan <sh...@apache.org>
Committed: Fri Mar 7 12:04:12 2014 -0800
----------------------------------------------------------------------
bin/config-tool.sh | 25 -----
bin/sentry | 60 +++++-----
bin/sentry.sh | 112 +++++++++++++++++++
.../binding/hive/authz/SentryConfigTool.java | 55 ++++-----
sentry-core/sentry-core-common/pom.xml | 4 +
.../main/java/org/apache/sentry/Command.java | 23 ++++
.../main/java/org/apache/sentry/SentryMain.java | 73 ++++++++++++
.../org/apache/sentry/SentryUserException.java | 28 +++++
.../main/java/org/apache/sentry/Command.java | 23 ----
.../main/java/org/apache/sentry/SentryMain.java | 59 ----------
.../org/apache/sentry/SentryUserException.java | 28 -----
11 files changed, 299 insertions(+), 191 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/bin/config-tool.sh
----------------------------------------------------------------------
diff --git a/bin/config-tool.sh b/bin/config-tool.sh
deleted file mode 100755
index b286421..0000000
--- a/bin/config-tool.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/env bash
-
-# 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.
-
-_CMD_JAR=sentry-binding-hive-*.jar
-_HIVE_CMD=${HIVE_HOME}/bin/hive
-for f in ${SENTRY_HOME}/lib/*.jar; do
- HADOOP_CLASSPATH=${HADOOP_CLASSPATH}:${f}
-done
-
-${_HIVE_CMD} --service jar ${SENTRY_HOME}/lib/${_CMD_JAR} org.apache.sentry.binding.hive.authz.SentryConfigTool "$@"
-
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/bin/sentry
----------------------------------------------------------------------
diff --git a/bin/sentry b/bin/sentry
index 6c40f68..81b4382 100755
--- a/bin/sentry
+++ b/bin/sentry
@@ -25,40 +25,40 @@ fi
_HIVE_CMD=hive
#check to see if the hive conf dir is given as an optional argument
+args=()
while [ $# -gt 0 ]; do # Until you run out of parameters . . .
case "$1" in
--hive-config)
- shift
- confdir=$1
- shift
- export HIVE_CONF_DIR=$confdir
- echo Using hive-conf-dir $HIVE_CONF_DIR
- ;;
+ shift
+ confdir=$1
+ shift
+ export HIVE_CONF_DIR=$confdir
+ echo Using hive-conf-dir $HIVE_CONF_DIR
+ ;;
--hive-home)
- shift
- homedir=$1
- shift
- export HIVE_HOME=$homedir
- echo Using hive-home $HIVE_HOME
- ;;
- --command)
- shift
- case "$1" in
- config-tool)
- shift
- $SENTRY_HOME/bin/config-tool.sh "$@"
- ;;
- *)
- echo Unknown option $1
- echo "Usage sentry --command <config-tool [config-tool-options]>"
- break
- ;;
- esac
- break
- ;;
+ shift
+ homedir=$1
+ shift
+ export HIVE_HOME=$homedir
+ echo Using hive-home $HIVE_HOME
+ ;;
*)
- echo "Usage sentry --command <config-tool [config-tool-options]>"
- break
- ;;
+ args+=($1)
+ shift
+ ;;
esac
done
+
+if [[ -z "$HIVE_HOME" ]]
+then
+ echo "HIVE_HOME must be defined either as an env variable or by the --hive-home argument"
+ exit 1
+fi
+
+_CMD_JAR=sentry-core-common-*.jar
+_HIVE_CMD=${HIVE_HOME}/bin/hive
+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[@]}"
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/bin/sentry.sh
----------------------------------------------------------------------
diff --git a/bin/sentry.sh b/bin/sentry.sh
new file mode 100644
index 0000000..76d550b
--- /dev/null
+++ b/bin/sentry.sh
@@ -0,0 +1,112 @@
+#!/bin/bash
+#
+#
+# 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.
+#
+
+################################
+# functions
+################################
+
+info() {
+ local msg=$1
+ echo "Info: $msg" >&2
+}
+
+warn() {
+ local msg=$1
+ echo "Warning: $msg" >&2
+}
+
+error() {
+ local msg=$1
+ local exit_code=$2
+
+ echo "Error: $msg" >&2
+
+ if [ -n "$exit_code" ] ; then
+ exit $exit_code
+ fi
+}
+
+################################
+# main
+################################
+
+# set default params
+SENTRY_CLASSPATH=""
+
+if [ -z "${SENTRY_HOME}" ]; then
+ SENTRY_HOME=$(cd $(dirname $0)/..; pwd)
+fi
+
+if [ -f ${SENTRY_HOME}/etc/sentry-env.sh ]
+then
+ . ${SENTRY_HOME}/etc/sentry-env.sh
+fi
+
+# prepend $SENTRY_HOME/lib jars to the specified classpath (if any)
+if [ -n "${SENTRY_CLASSPATH}" ] ; then
+ SENTRY_CLASSPATH="${SENTRY_HOME}/lib/*:$SENTRY_CLASSPATH"
+else
+ SENTRY_CLASSPATH="${SENTRY_HOME}/lib/*"
+fi
+
+# find java
+if [ -z "${JAVA_HOME}" ] ; then
+ warn "JAVA_HOME is not set!"
+ # Try to use Bigtop to autodetect JAVA_HOME if it's available
+ if [ -e /usr/libexec/bigtop-detect-javahome ] ; then
+ . /usr/libexec/bigtop-detect-javahome
+ elif [ -e /usr/lib/bigtop-utils/bigtop-detect-javahome ] ; then
+ . /usr/lib/bigtop-utils/bigtop-detect-javahome
+ fi
+
+ # Using java from path if bigtop is not installed or couldn't find it
+ if [ -z "${JAVA_HOME}" ] ; then
+ JAVA_DEFAULT=$(type -p java)
+ [ -n "$JAVA_DEFAULT" ] || error "Unable to find java executable. Is it in your PATH?" 1
+ JAVA_HOME=$(cd $(dirname $JAVA_DEFAULT)/..; pwd)
+ fi
+fi
+
+# look for hadoop libs
+HADOOP_IN_PATH=$(PATH="${HADOOP_HOME:-${HADOOP_PREFIX}}/bin:$PATH" \
+ which hadoop 2>/dev/null)
+if [ ! -f "${HADOOP_IN_PATH}" ]; then
+ error "Cannot find Hadoop command in path"
+fi
+
+info "Including Hadoop libraries found via ($HADOOP_IN_PATH)"
+
+# determine hadoop classpath
+HADOOP_CLASSPATH=$($HADOOP_IN_PATH classpath)
+
+# hack up and filter hadoop classpath
+ELEMENTS=$(sed -e 's/:/ /g' <<<${HADOOP_CLASSPATH})
+for ELEMENT in $ELEMENTS; do
+ for PIECE in $(echo $ELEMENT); do
+ if [[ $PIECE =~ slf4j-(api|log4j12).*\.jar ]]; then
+ info "Excluding $PIECE from classpath"
+ continue
+ else
+ SENTRY_CLASSPATH="$SENTRY_CLASSPATH:$PIECE"
+ fi
+ done
+done
+exec $JAVA_HOME/bin/java $SENTRY_OPTS -cp "$SENTRY_CLASSPATH" org.apache.sentry.SentryMain "$@"
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/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 e59b747..bc739ad 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
@@ -41,6 +41,7 @@ import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
+import org.apache.sentry.Command;
import org.apache.sentry.binding.hive.HiveAuthzBindingHook;
import org.apache.sentry.binding.hive.HiveAuthzBindingSessionHook;
import org.apache.sentry.binding.hive.conf.HiveAuthzConf;
@@ -478,39 +479,41 @@ public class SentryConfigTool {
}
}
- public static void main(String args[]) throws Exception {
- SentryConfigTool sentryTool = new SentryConfigTool();
+ public static class CommandImpl implements Command {
+ @Override
+ public void run(String[] args) throws Exception {
+ SentryConfigTool sentryTool = new SentryConfigTool();
- try {
- // parse arguments
- sentryTool.parseArgs(args);
+ try {
+ // parse arguments
+ sentryTool.parseArgs(args);
- // load configuration
- sentryTool.setupConfig();
+ // load configuration
+ sentryTool.setupConfig();
- // validate configuration
- if (sentryTool.isValidate()) {
- sentryTool.validatePolicy();
- }
+ // validate configuration
+ if (sentryTool.isValidate()) {
+ sentryTool.validatePolicy();
+ }
- // list permissions for give user
- if (sentryTool.isListPrivs()) {
- sentryTool.listPrivs();
- }
+ // list permissions for give user
+ if (sentryTool.isListPrivs()) {
+ sentryTool.listPrivs();
+ }
- // verify given query
- if (sentryTool.getQuery() != null) {
- if (sentryTool.getJdbcURL() != null) {
- sentryTool.verifyRemoteQuery(sentryTool.getQuery());
- } else {
- sentryTool.verifyLocalQuery(sentryTool.getQuery());
+ // verify given query
+ if (sentryTool.getQuery() != null) {
+ if (sentryTool.getJdbcURL() != null) {
+ sentryTool.verifyRemoteQuery(sentryTool.getQuery());
+ } else {
+ sentryTool.verifyLocalQuery(sentryTool.getQuery());
+ }
}
+ } catch (Exception e) {
+ System.out.println("Sentry tool reported Errors: " + e.getMessage());
+ e.printStackTrace(System.out);
+ System.exit(1);
}
- } catch (Exception e) {
- System.out.println("Sentry tool reported Errors: " + e.getMessage());
- e.printStackTrace(System.out);
- System.exit(1);
}
-
}
}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/sentry-core/sentry-core-common/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/pom.xml b/sentry-core/sentry-core-common/pom.xml
index d50963e..84ab359 100644
--- a/sentry-core/sentry-core-common/pom.xml
+++ b/sentry-core/sentry-core-common/pom.xml
@@ -29,6 +29,10 @@ limitations under the License.
<dependencies>
<dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/Command.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/Command.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/Command.java
new file mode 100644
index 0000000..528f7d7
--- /dev/null
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/Command.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+package org.apache.sentry;
+
+
+public interface Command {
+ public void run(String[] args) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/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
new file mode 100644
index 0000000..eb3482b
--- /dev/null
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+package org.apache.sentry;
+
+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 com.google.common.collect.ImmutableMap;
+
+public class SentryMain {
+ private static final String HELP_SHORT = "h";
+ private static final String HELP_LONG = "help";
+ private static final String COMMAND = "command";
+ private static final ImmutableMap<String, String> COMMANDS = ImmutableMap
+ .<String, String>builder()
+ .put("service", "org.apache.sentry.service.thrift.SentryService$CommandImpl")
+ .put("config-tool", "org.apache.sentry.binding.hive.authz.SentryConfigTool$CommandImpl")
+ .build();
+ public static void main(String[] args)
+ throws Exception {
+ CommandLineParser parser = new GnuParser();
+ 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);
+ String commandName = commandLine.getOptionValue(COMMAND);
+ if (commandName == null || commandLine.hasOption(HELP_SHORT) ||
+ commandLine.hasOption(HELP_LONG)) {
+ printHelp(options);
+ }
+ String commandClazz = COMMANDS.get(commandName);
+ if (commandClazz == null) {
+ String msg = "Unknown command '" + commandName + "', options are: " + COMMANDS.keySet();
+ throw new IllegalArgumentException(msg);
+ }
+ Object command;
+ try {
+ command = Class.forName(commandClazz.trim()).newInstance();
+ } catch (Exception e) {
+ String msg = "Could not create instance of " + commandClazz + " for command " + commandName;
+ throw new IllegalStateException(msg, e);
+ }
+ if (!(command instanceof Command)) {
+ String msg = "Command " + command.getClass().getName() + " is not an instance of "
+ + Command.class.getName();
+ throw new IllegalStateException(msg);
+ }
+ ((Command)command).run(commandLine.getArgs());
+ }
+ private static void printHelp(Options options) {
+ (new HelpFormatter()).printHelp("sentry --" + COMMAND + "=" + COMMANDS.keySet(),
+ options);
+ System.exit(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryUserException.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryUserException.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryUserException.java
new file mode 100644
index 0000000..2b24703
--- /dev/null
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryUserException.java
@@ -0,0 +1,28 @@
+/**
+ * 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.
+ */
+package org.apache.sentry;
+
+public class SentryUserException extends Exception{
+ private static final long serialVersionUID = 2329620558380655835L;
+ public SentryUserException(String msg) {
+ super(msg);
+ }
+ public SentryUserException(String msg, Throwable t) {
+ super(msg, t);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/Command.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/Command.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/Command.java
deleted file mode 100644
index 528f7d7..0000000
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/Command.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-package org.apache.sentry;
-
-
-public interface Command {
- public void run(String[] args) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryMain.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryMain.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryMain.java
deleted file mode 100644
index 3cb5e54..0000000
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryMain.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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.
- */
-package org.apache.sentry;
-
-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.sentry.service.thrift.SentryService;
-
-import com.google.common.collect.ImmutableMap;
-
-public class SentryMain {
- private static final String HELP_SHORT = "h";
- private static final String HELP_LONG = "help";
- private static final String COMMAND = "command";
- private static final ImmutableMap<String, Command> COMMANDS = ImmutableMap
- .<String, Command>builder()
- .put("service", new SentryService.CommandImpl())
- .build();
- public static void main(String[] args)
- throws Exception {
- CommandLineParser parser = new GnuParser();
- 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);
- String commandName = commandLine.getOptionValue(COMMAND);
- if (commandName == null || options.hasOption(HELP_SHORT) || options.hasOption(HELP_LONG)) {
- printHelp(options);
- }
- Command command = COMMANDS.get(commandName);
- if (command == null) {
- printHelp(options);
- }
- command.run(commandLine.getArgs());
- }
- private static void printHelp(Options options) {
- (new HelpFormatter()).printHelp("sentry.sh --" + COMMAND + "=" + COMMANDS.keySet(),
- options);
- System.exit(1);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/bd511cdb/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryUserException.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryUserException.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryUserException.java
deleted file mode 100644
index 2b24703..0000000
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/SentryUserException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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.
- */
-package org.apache.sentry;
-
-public class SentryUserException extends Exception{
- private static final long serialVersionUID = 2329620558380655835L;
- public SentryUserException(String msg) {
- super(msg);
- }
- public SentryUserException(String msg, Throwable t) {
- super(msg, t);
- }
-}