HBASE-21567 Allow overriding configs starting up the shell
Adds support for -D as option to 'hbase shell'
This commit is contained in:
parent
e80cc3286c
commit
19c3663119
40
bin/hirb.rb
40
bin/hirb.rb
|
@ -54,21 +54,47 @@ $LOAD_PATH.unshift Pathname.new(sources)
|
|||
cmdline_help = <<HERE # HERE document output as shell usage
|
||||
Usage: shell [OPTIONS] [SCRIPTFILE [ARGUMENTS]]
|
||||
|
||||
-d | --debug Set DEBUG log levels.
|
||||
-h | --help This help.
|
||||
-n | --noninteractive Do not run within an IRB session
|
||||
and exit with non-zero status on
|
||||
first error.
|
||||
-d | --debug Set DEBUG log levels.
|
||||
-h | --help This help.
|
||||
-n | --noninteractive Do not run within an IRB session and exit with non-zero
|
||||
status on first error.
|
||||
-Dkey=value Pass hbase-*.xml Configuration overrides. For example, to
|
||||
use an alternate zookeeper ensemble, pass:
|
||||
-Dhbase.zookeeper.quorum=zookeeper.example.org
|
||||
For faster fail, pass the below and vary the values:
|
||||
-Dhbase.client.retries.number=7
|
||||
-Dhbase.ipc.client.connect.max.retries=3
|
||||
HERE
|
||||
|
||||
# Takes configuration and an arg that is expected to be key=value format.
|
||||
# If c is empty, creates one and returns it
|
||||
def add_to_configuration(c, arg)
|
||||
kv = arg.split('=')
|
||||
kv.length == 2 || (raise "Expected parameter #{kv} in key=value format")
|
||||
c = org.apache.hadoop.hbase.HBaseConfiguration.create if c.nil?
|
||||
c.set(kv[0], kv[1])
|
||||
c
|
||||
end
|
||||
|
||||
found = []
|
||||
script2run = nil
|
||||
log_level = org.apache.log4j.Level::ERROR
|
||||
@shell_debug = false
|
||||
interactive = true
|
||||
for arg in ARGV
|
||||
_configuration = nil
|
||||
D_ARG = '-D'
|
||||
while (arg = ARGV.shift)
|
||||
if arg == '-h' || arg == '--help'
|
||||
puts cmdline_help
|
||||
exit
|
||||
elsif arg == D_ARG
|
||||
argValue = ARGV.shift || (raise "#{D_ARG} takes a 'key=value' parameter")
|
||||
_configuration = add_to_configuration(_configuration, argValue)
|
||||
found.push(arg)
|
||||
found.push(argValue)
|
||||
elsif arg.start_with? D_ARG
|
||||
_configuration = add_to_configuration(_configuration, arg[2..-1])
|
||||
found.push(arg)
|
||||
elsif arg == '-d' || arg == '--debug'
|
||||
log_level = org.apache.log4j.Level::DEBUG
|
||||
$fullBackTrace = true
|
||||
|
@ -113,7 +139,7 @@ require 'shell'
|
|||
require 'shell/formatter'
|
||||
|
||||
# Setup the HBase module. Create a configuration.
|
||||
@hbase = Hbase::Hbase.new
|
||||
@hbase = _configuration.nil? ? Hbase::Hbase.new : Hbase::Hbase.new(_configuration)
|
||||
|
||||
# Setup console
|
||||
@shell = Shell::Shell.new(@hbase, interactive)
|
||||
|
|
|
@ -58,6 +58,7 @@ To run one of these files, do as follows:
|
|||
$ ./bin/hbase org.jruby.Main PATH_TO_SCRIPT
|
||||
----
|
||||
|
||||
|
||||
== Running the Shell in Non-Interactive Mode
|
||||
|
||||
A new non-interactive mode has been added to the HBase Shell (link:https://issues.apache.org/jira/browse/HBASE-11658[HBASE-11658)].
|
||||
|
@ -215,6 +216,21 @@ $ HBASE_SHELL_OPTS="-verbose:gc -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCD
|
|||
-XX:+PrintGCDetails -Xloggc:$HBASE_HOME/logs/gc-hbase.log" ./bin/hbase shell
|
||||
----
|
||||
|
||||
== Overriding configuration starting the HBase Shell
|
||||
|
||||
As of hbase-2.0.5/hbase-2.1.3/hbase-2.2.0/hbase-1.4.10/hbase-1.5.0, you can
|
||||
pass or override hbase configuration as specified in `hbase-*.xml` by passing
|
||||
your key/values prefixed with `-D` on the command-line as follows:
|
||||
[source,bash]
|
||||
----
|
||||
$ ./bin/hbase shell -Dhbase.zookeeper.quorum=ZK0.remote.cluster.example.org,ZK1.remote.cluster.example.org,ZK2.remote.cluster.example.org -Draining=false
|
||||
...
|
||||
hbase(main):001:0> @shell.hbase.configuration.get("hbase.zookeeper.quorum")
|
||||
=> "ZK0.remote.cluster.example.org,ZK1.remote.cluster.example.org,ZK2.remote.cluster.example.org"
|
||||
hbase(main):002:0> @shell.hbase.configuration.get("raining")
|
||||
=> "false"
|
||||
----
|
||||
|
||||
== Shell Tricks
|
||||
|
||||
=== Table variables
|
||||
|
|
Loading…
Reference in New Issue