Repository: hadoop Updated Branches: refs/heads/HADOOP-13341 38812645a -> ef55eb952
HADOOP-13554. Add an equivalent of hadoop_subcmd_opts for secure opts (aw) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ef55eb95 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ef55eb95 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ef55eb95 Branch: refs/heads/HADOOP-13341 Commit: ef55eb9521851fc3c99cd642f9682777c12078d1 Parents: 3881264 Author: Allen Wittenauer <[email protected]> Authored: Tue Aug 30 08:16:23 2016 -0700 Committer: Allen Wittenauer <[email protected]> Committed: Tue Aug 30 08:16:23 2016 -0700 ---------------------------------------------------------------------- .../src/main/bin/hadoop-functions.sh | 45 +++++++++++++++++ .../scripts/hadoop_subcommand_secure_opts.bats | 52 ++++++++++++++++++++ 2 files changed, 97 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/ef55eb95/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 9003913..dd82347 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 @@ -2057,6 +2057,51 @@ function hadoop_subcommand_opts fi } +## @description Add custom (program)_(command)_SECURE_EXTRA_OPTS to HADOOP_OPTS. +## @description This *does not* handle the pre-3.x deprecated cases +## @audience public +## @stability stable +## @replaceable yes +## @param program +## @param subcommand +## @return will exit on failure conditions +function hadoop_subcommand_secure_opts +{ + declare program=$1 + declare command=$2 + 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_DATANODE_SECURE_EXTRA_OPTS + # HDFS_NFS3_SECURE_EXTRA_OPTS + # ... + uvar="${uprogram}_${ucommand}_SECURE_EXTRA_OPTS" + + if [[ -n ${!uvar} ]]; then + hadoop_debug "Appending ${!uvar} onto HADOOP_OPTS" + HADOOP_OPTS="${HADOOP_OPTS} ${!uvar}" + 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/ef55eb95/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_secure_opts.bats ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_secure_opts.bats b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_secure_opts.bats new file mode 100644 index 0000000..1b3506c --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommand_secure_opts.bats @@ -0,0 +1,52 @@ +# 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_secure_opts (missing param)" { + HADOOP_OPTS="x" + run hadoop_subcommand_secure_opts testvar + [ "${status}" = "1" ] +} + +@test "hadoop_subcommand_secure_opts (simple not exist)" { + HADOOP_OPTS="x" + hadoop_subcommand_secure_opts hadoop subcommand + [ "${HADOOP_OPTS}" = "x" ] +} + +@test "hadoop_subcommand_secure_opts (hadoop simple exist)" { + HADOOP_OPTS="x" + HADOOP_TEST_SECURE_EXTRA_OPTS="y" + hadoop_subcommand_secure_opts hadoop test + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y" ] +} + +@test "hadoop_subcommand_secure_opts (hadoop complex exist)" { + HADOOP_OPTS="x" + HADOOP_TEST_SECURE_EXTRA_OPTS="y z" + hadoop_subcommand_secure_opts hadoop test + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y z" ] +} + +@test "hadoop_subcommand_secure_opts (hdfs simple exist)" { + HADOOP_OPTS="x" + HDFS_TEST_SECURE_EXTRA_OPTS="y" + hadoop_subcommand_secure_opts hdfs test + echo "${HADOOP_OPTS}" + [ "${HADOOP_OPTS}" = "x y" ] +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
