From 3dc28e2052dd3a8e4cd5888fc4f9e7e37f8bc062 Mon Sep 17 00:00:00 2001 From: Allen Wittenauer Date: Tue, 23 Sep 2014 12:24:23 -0700 Subject: [PATCH] HADOOP-11092. hadoop shell commands should print usage if not given a class (aw) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../hadoop-common/src/main/bin/hadoop | 6 +++--- .../hadoop-common/src/main/bin/hadoop-functions.sh | 11 +++++++++++ hadoop-hdfs-project/hadoop-hdfs/src/main/bin/hdfs | 6 +++--- hadoop-mapreduce-project/bin/mapred | 7 +++++-- hadoop-yarn-project/hadoop-yarn/bin/yarn | 6 +++--- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index e99a19d9e3..5f4ae1ac10 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -126,6 +126,9 @@ Trunk (Unreleased) HADOOP-11041. VersionInfo specifies subversion (Tsuyoshi OZAWA via aw) + HADOOP-11092. hadoop shell commands should print usage if not given a + a class (aw) + BUG FIXES HADOOP-9451. Fault single-layer config if node group topology is enabled. diff --git a/hadoop-common-project/hadoop-common/src/main/bin/hadoop b/hadoop-common-project/hadoop-common/src/main/bin/hadoop index 64c67587dc..ad6e4ee3d4 100755 --- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop +++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop @@ -162,11 +162,11 @@ case ${COMMAND} in version) CLASS=org.apache.hadoop.util.VersionInfo ;; - -*|hdfs) - hadoop_exit_with_usage 1 - ;; *) CLASS="${COMMAND}" + if ! hadoop_validate_classname "${CLASS}"; then + hadoop_exit_with_usage 1 + fi ;; esac diff --git a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh index dfdb101663..efa42f6522 100644 --- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh +++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh @@ -279,6 +279,17 @@ function hadoop_connect_to_hosts fi } +function hadoop_validate_classname +{ + local class=$1 + shift 1 + + if [[ ! ${class} =~ \. ]]; then + return 1 + fi + return 0 +} + function hadoop_add_param { # diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/bin/hdfs b/hadoop-hdfs-project/hadoop-hdfs/src/main/bin/hdfs index 22a0f0f8c0..087c67472a 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/bin/hdfs +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/bin/hdfs @@ -222,11 +222,11 @@ case ${COMMAND} in hadoop_debug "Appending HADOOP_ZKFC_OPTS onto HADOOP_OPTS" HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_ZKFC_OPTS}" ;; - -*) - hadoop_exit_with_usage 1 - ;; *) CLASS="${COMMAND}" + if ! hadoop_validate_classname "${CLASS}"; then + hadoop_exit_with_usage 1 + fi ;; esac diff --git a/hadoop-mapreduce-project/bin/mapred b/hadoop-mapreduce-project/bin/mapred index 8f3063774f..2163cada29 100755 --- a/hadoop-mapreduce-project/bin/mapred +++ b/hadoop-mapreduce-project/bin/mapred @@ -118,8 +118,11 @@ case ${COMMAND} in hadoop_debug "Appending HADOOP_CLIENT_OPTS onto HADOOP_OPTS" HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_CLIENT_OPTS}" ;; - -*|*) - hadoop_exit_with_usage 1 + *) + CLASS="${COMMAND}" + if ! hadoop_validate_classname "${CLASS}"; then + hadoop_exit_with_usage 1 + fi ;; esac diff --git a/hadoop-yarn-project/hadoop-yarn/bin/yarn b/hadoop-yarn-project/hadoop-yarn/bin/yarn index 12f7bb501b..207fb4a41f 100644 --- a/hadoop-yarn-project/hadoop-yarn/bin/yarn +++ b/hadoop-yarn-project/hadoop-yarn/bin/yarn @@ -154,11 +154,11 @@ case "${COMMAND}" in hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS" YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}" ;; - -*) - hadoop_exit_with_usage 1 - ;; *) CLASS="${COMMAND}" + if ! hadoop_validate_classname "${CLASS}"; then + hadoop_exit_with_usage 1 + fi ;; esac