From d19e0587fa69876617ce47b9723e79280dc9fac3 Mon Sep 17 00:00:00 2001 From: Nick Dimiduk Date: Mon, 3 May 2021 12:28:15 -0700 Subject: [PATCH] HBASE-25841 Add basic jshell support Signed-off-by: Bharath Vissapragada Signed-off-by: Pankaj Kumar Signed-off-by: Duo Zhang --- bin/hbase | 25 ++++++++++++++++++++++-- bin/hbase_startup.jsh | 20 +++++++++++++++++++ conf/hbase-env.sh | 3 +++ src/main/asciidoc/_chapters/ops_mgt.adoc | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 bin/hbase_startup.jsh diff --git a/bin/hbase b/bin/hbase index 59c48712b67..16516083375 100755 --- a/bin/hbase +++ b/bin/hbase @@ -54,6 +54,9 @@ # HBASE_SHELL_OPTS Extra options passed to the hbase shell. # Empty by default. # +# HBASE_JSHELL_ARGS Additional arguments passed to the jshell. +# Defaults to `--startup DEFAULT --startup PRINTING --startup hbase_startup.jsh` +# bin=`dirname "$0"` bin=`cd "$bin">/dev/null; pwd` @@ -87,6 +90,7 @@ show_usage() { echo " thrift2 Run the HBase Thrift2 server" echo " clean Run the HBase clean up script" fi + echo " jshell Run a jshell with HBase on the classpath" echo " classpath Dump hbase CLASSPATH" echo " mapredcp Dump CLASSPATH entries required by mapreduce" echo " pe Run PerformanceEvaluation" @@ -506,6 +510,9 @@ if [[ $jruby_needed ]]; then fi fi +# set default values for HBASE_JSHELL_ARGS +read -r -a JSHELL_ARGS <<< "${HBASE_JSHELL_ARGS:-"--startup DEFAULT --startup PRINTING --startup ${HBASE_HOME}/bin/hbase_startup.jsh"}" + # figure out which class to run if [ "$COMMAND" = "shell" ] ; then #find the hbase ruby sources @@ -525,6 +532,14 @@ if [ "$COMMAND" = "shell" ] ; then CLASS="org.jruby.Main -X+O ${JRUBY_OPTS} ${HBASE_HOME}/hbase-shell/src/main/ruby/jar-bootstrap.rb" fi HBASE_OPTS="$HBASE_OPTS $HBASE_SHELL_OPTS" +elif [ "$COMMAND" = 'jshell' ] ; then + java_version="$(read_java_version)" + major_version_number="$(parse_java_major_version "${java_version}")" + if [ "${major_version_number}" -lt 9 ] ; then + echo "JShell is available only with JDK9 and lated. Detected JDK version is ${java_version}". + exit 1 + fi + CLASS='jdk.internal.jshell.tool.JShellToolProvider' elif [ "$COMMAND" = "hbck" ] ; then # Look for the -j /path/to/HBCK2.jar parameter. Else pass through to hbck. case "${1}" in @@ -778,9 +793,15 @@ if [ "${DEBUG}" = "true" ]; then HBASE_OPTS="${HBASE_OPTS} -Xdiag" fi +# resolve the command arguments +read -r -a CMD_ARGS <<< "$@" +if [ "${#JSHELL_ARGS[@]}" -gt 0 ] ; then + CMD_ARGS=("${JSHELL_ARGS[@]}" "${CMD_ARGS[@]}") +fi + if [ "${HBASE_NOEXEC}" != "" ]; then - "$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_OPTS $CLASS "$@" + "$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_OPTS $CLASS "${CMD_ARGS[@]}" else export JVM_PID="$$" - exec "$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_OPTS $CLASS "$@" + exec "$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_OPTS $CLASS "${CMD_ARGS[@]}" fi diff --git a/bin/hbase_startup.jsh b/bin/hbase_startup.jsh new file mode 100644 index 00000000000..0f5dd9c25bb --- /dev/null +++ b/bin/hbase_startup.jsh @@ -0,0 +1,20 @@ +/** + * 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. + */ + +import org.apache.hadoop.hbase.*; +import org.apache.hadoop.hbase.client.*; diff --git a/conf/hbase-env.sh b/conf/hbase-env.sh index f99373e653a..6cc16d8db49 100644 --- a/conf/hbase-env.sh +++ b/conf/hbase-env.sh @@ -141,3 +141,6 @@ # Override text processing tools for use by these launch scripts. # export GREP="${GREP-grep}" # export SED="${SED-sed}" + +# Additional argments passed to jshell invocation +# export HBASE_JSHELL_ARGS="--startup DEFAULT --startup PRINTING --startup hbase_startup.jsh" diff --git a/src/main/asciidoc/_chapters/ops_mgt.adoc b/src/main/asciidoc/_chapters/ops_mgt.adoc index d62e2345ab6..6458112e1c1 100644 --- a/src/main/asciidoc/_chapters/ops_mgt.adoc +++ b/src/main/asciidoc/_chapters/ops_mgt.adoc @@ -64,6 +64,7 @@ Some commands take arguments. Pass no args or -h for usage. thrift Run the HBase Thrift server thrift2 Run the HBase Thrift2 server clean Run the HBase clean up script + jshell Run a jshell with HBase on the classpath classpath Dump hbase CLASSPATH mapredcp Dump CLASSPATH entries required by mapreduce pe Run PerformanceEvaluation