Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E48B1200B7D for ; Sat, 27 Aug 2016 02:17:35 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E30E6160AC7; Sat, 27 Aug 2016 00:17:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 17742160AB6 for ; Sat, 27 Aug 2016 02:17:34 +0200 (CEST) Received: (qmail 34387 invoked by uid 500); 27 Aug 2016 00:17:33 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 34162 invoked by uid 99); 27 Aug 2016 00:17:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2016 00:17:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BD1A8E69A3; Sat, 27 Aug 2016 00:17:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aw@apache.org To: common-commits@hadoop.apache.org Date: Sat, 27 Aug 2016 00:17:38 -0000 Message-Id: In-Reply-To: <03b73243222542148eec5981f8a47616@git.apache.org> References: <03b73243222542148eec5981f8a47616@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [7/8] hadoop git commit: HADOOP-13356. Add a function to handle command_subcommand_OPTS (aw) archived-at: Sat, 27 Aug 2016 00:17:36 -0000 HADOOP-13356. Add a function to handle command_subcommand_OPTS (aw) Signed-off-by: Allen Wittenauer Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/defe759b Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/defe759b Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/defe759b Branch: refs/heads/HADOOP-13341 Commit: defe759bc5a080d164ed218ae5953bcff9380bfa Parents: 19c743c Author: Allen Wittenauer Authored: Fri Jul 8 09:25:09 2016 -0700 Committer: Allen Wittenauer Committed: Fri Aug 26 17:17:29 2016 -0700 ---------------------------------------------------------------------- .../src/main/bin/hadoop-functions.sh | 62 ++++++++++++++++ .../test/scripts/hadoop_subcommand_opts.bats | 76 ++++++++++++++++++++ 2 files changed, 138 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/defe759b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh ---------------------------------------------------------------------- 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 75554f0..6e58dca 100755 --- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh +++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh @@ -1974,6 +1974,68 @@ function hadoop_verify_user fi } +## @description Add custom (program)_(command)_OPTS to HADOOP_OPTS. +## @description Also handles the deprecated cases from pre-3.x. +## @audience public +## @stability stable +## @replaceable yes +## @param program +## @param subcommand +## @return will exit on failure conditions +function hadoop_subcommand_opts +{ + declare program=$1 + declare command=$2 + declare var + declare uvar + declare uprogram + declare ucommand + + if [[ -z "${program}" || -z "${command}" ]]; then + return 1 + fi + + # bash 4 and up have built-in ways to upper and lower + # case the contents of vars. This is faster than + # calling tr. + + if [[ -z "${BASH_VERSINFO[0]}" ]] \ + || [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then + uprogram=$(echo "${program}" | tr '[:lower:]' '[:upper:]') + ucommand=$(echo "${command}" | tr '[:lower:]' '[:upper:]') + else + uprogram=${program^^} + ucommand=${command^^} + fi + + # HDFS_namenode_OPTS + # HADOOP_distcp_OPTS + # MAPRED_distcp_OPTS + # YARN_sharedcachemanger_OPTS + # ... + var="${uprogram}_${command}_OPTS" + + # Let's handle all of the deprecation cases early + # HADOOP_NAMENODE_OPTS -> HDFS_namenode_OPTS + # YARN_RESOURCEMANAGER_OPTS -> YARN_resourcemanager_OPTS + + uvar="${uprogram}_${ucommand}_OPTS" + if [[ -n ${!uvar} ]]; then + hadoop_deprecate_envvar "${uvar}" "${var}" + fi + + uvar="HADOOP_${ucommand}_OPTS" + if [[ -n ${!uvar} ]]; then + hadoop_deprecate_envvar "${uvar}" "${var}" + fi + + if [[ -n ${!var} ]]; then + hadoop_debug "Appending ${!var} onto HADOOP_OPTS" + HADOOP_OPTS="${HADOOP_OPTS} ${!var}" + return 0 + fi +} + ## @description Perform the 'hadoop classpath', etc subcommand with the given ## @description parameters ## @audience private http://git-wip-us.apache.org/repos/asf/hadoop/blob/defe759b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_opts.bats ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_opts.bats b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_opts.bats new file mode 100644 index 0000000..1fbf343 --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_opts.bats @@ -0,0 +1,76 @@ +# 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. + +load hadoop-functions_test_helper + +@test "hadoop_subcommand_opts (missing param)" { + HADOOP_OPTS="x" + run hadoop_subcommand_opts testvar + [ "${status}" = "1" ] +} + +@test "hadoop_subcommand_opts (simple not exist)" { + HADOOP_OPTS="x" + hadoop_subcommand_opts hadoop subcommand + [ "${HADOOP_OPTS}" = "x" ] +} + +@test "hadoop_subcommand_opts (hadoop simple exist)" { + HADOOP_OPTS="x" + HADOOP_test_OPTS="y" + hadoop_subcommand_opts hadoop test + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y" ] +} + +@test "hadoop_subcommand_opts (hadoop complex exist)" { + HADOOP_OPTS="x" + HADOOP_test_OPTS="y z" + hadoop_subcommand_opts hadoop test + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y z" ] +} + +@test "hadoop_subcommand_opts (hdfs simple exist)" { + HADOOP_OPTS="x" + HDFS_test_OPTS="y" + hadoop_subcommand_opts hdfs test + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y" ] +} + +@test "hadoop_subcommand_opts (yarn simple exist)" { + HADOOP_OPTS="x" + YARN_test_OPTS="y" + hadoop_subcommand_opts yarn test + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y" ] +} + +@test "hadoop_subcommand_opts (deprecation case #1)" { + HADOOP_OPTS="x" + HADOOP_NAMENODE_OPTS="y" + hadoop_subcommand_opts hdfs namenode + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y" ] +} + +@test "hadoop_subcommand_opts (deprecation case #2)" { + HADOOP_OPTS="x" + YARN_RESOURCEMANAGER_OPTS="y" + hadoop_subcommand_opts yarn resourcemanager + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y" ] +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org