HBASE-25841 Add basic jshell support

Signed-off-by: Bharath Vissapragada <bharathv@apache.org>
Signed-off-by: Pankaj Kumar <pankajkumar@apache.org>
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Nick Dimiduk 2021-05-03 12:28:15 -07:00 committed by Nick Dimiduk
parent aab6e1d0ff
commit d19e0587fa
4 changed files with 47 additions and 2 deletions

View File

@ -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

20
bin/hbase_startup.jsh Normal file
View File

@ -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.*;

View File

@ -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"

View File

@ -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