HBASE-21567 Allow overriding configs starting up the shell
Adds support for -D as option to 'hbase shell'
This commit is contained in:
parent
434bd0cd91
commit
3f34aed0a9
36
bin/hirb.rb
36
bin/hirb.rb
|
@ -56,19 +56,45 @@ 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.
|
||||
-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
|
||||
|
@ -111,7 +137,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)].
|
||||
|
@ -213,6 +214,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