2010-03-26 18:45:48 -04:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2008-06-13 01:50:00 -04:00
|
|
|
# File passed to org.jruby.Main by bin/hbase. Pollutes jirb with hbase imports
|
|
|
|
# and hbase commands and then loads jirb. Outputs a banner that tells user
|
|
|
|
# where to find help, shell version, and loads up a custom hirb.
|
2014-08-08 16:54:53 -04:00
|
|
|
#
|
|
|
|
# In noninteractive mode, runs commands from stdin until completion or an error.
|
|
|
|
# On success will exit with status 0, on any problem will exit non-zero. Callers
|
|
|
|
# should only rely on "not equal to 0", because the current error exit code of 1
|
|
|
|
# will likely be updated to diffentiate e.g. invalid commands, incorrect args,
|
|
|
|
# permissions, etc.
|
2008-05-30 15:19:46 -04:00
|
|
|
|
2008-06-13 01:50:00 -04:00
|
|
|
# TODO: Interrupt a table creation or a connection to a bad master. Currently
|
2008-06-18 18:24:34 -04:00
|
|
|
# has to time out. Below we've set down the retries for rpc and hbase but
|
|
|
|
# still can be annoying (And there seem to be times when we'll retry for
|
|
|
|
# ever regardless)
|
2008-06-13 01:50:00 -04:00
|
|
|
# TODO: Add support for listing and manipulating catalog tables, etc.
|
2008-06-17 19:58:05 -04:00
|
|
|
# TODO: Encoding; need to know how to go from ruby String to UTF-8 bytes
|
2008-05-30 01:13:58 -04:00
|
|
|
|
2008-06-12 02:00:35 -04:00
|
|
|
# Run the java magic include and import basic HBase types that will help ease
|
|
|
|
# hbase hacking.
|
2008-05-30 01:13:58 -04:00
|
|
|
include Java
|
|
|
|
|
2008-05-30 15:19:46 -04:00
|
|
|
# Some goodies for hirb. Should these be left up to the user's discretion?
|
|
|
|
require 'irb/completion'
|
2012-05-26 01:56:04 -04:00
|
|
|
require 'pathname'
|
2008-05-30 15:19:46 -04:00
|
|
|
|
2012-05-26 01:56:04 -04:00
|
|
|
# Add the directory names in hbase.jruby.sources commandline option
|
2010-03-11 20:36:04 -05:00
|
|
|
# to the ruby load path so I can load up my HBase ruby modules
|
2012-05-26 01:56:04 -04:00
|
|
|
sources = java.lang.System.getProperty('hbase.ruby.sources')
|
|
|
|
$LOAD_PATH.unshift Pathname.new(sources)
|
2008-06-12 02:00:35 -04:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
#
|
|
|
|
# FIXME: Switch args processing to getopt
|
|
|
|
#
|
2008-06-13 01:50:00 -04:00
|
|
|
# See if there are args for this shell. If any, read and then strip from ARGV
|
|
|
|
# so they don't go through to irb. Output shell 'usage' if user types '--help'
|
|
|
|
cmdline_help = <<HERE # HERE document output as shell usage
|
2011-12-28 17:57:30 -05:00
|
|
|
Usage: shell [OPTIONS] [SCRIPTFILE [ARGUMENTS]]
|
|
|
|
|
2018-12-07 02:05:21 -05:00
|
|
|
-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.
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
--top-level-defs Compatibility flag to export HBase shell commands onto
|
|
|
|
Ruby's main object
|
2018-12-07 02:05:21 -05:00
|
|
|
-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
|
2008-06-12 02:00:35 -04:00
|
|
|
HERE
|
2018-12-07 02:05:21 -05:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2008-06-12 02:00:35 -04:00
|
|
|
found = []
|
2009-06-25 19:53:04 -04:00
|
|
|
script2run = nil
|
2010-03-11 20:36:04 -05:00
|
|
|
log_level = org.apache.log4j.Level::ERROR
|
2012-10-27 21:37:04 -04:00
|
|
|
@shell_debug = false
|
2014-08-08 16:54:53 -04:00
|
|
|
interactive = true
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
top_level_definitions = false
|
2018-12-07 02:05:21 -05:00
|
|
|
_configuration = nil
|
2019-02-01 14:21:49 -05:00
|
|
|
D_ARG = '-D'.freeze
|
2018-12-07 02:05:21 -05:00
|
|
|
while (arg = ARGV.shift)
|
2017-11-09 18:03:13 -05:00
|
|
|
if arg == '-h' || arg == '--help'
|
2008-06-13 01:50:00 -04:00
|
|
|
puts cmdline_help
|
2008-06-12 02:00:35 -04:00
|
|
|
exit
|
2018-12-07 02:05:21 -05:00
|
|
|
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)
|
2009-12-07 15:54:58 -05:00
|
|
|
elsif arg == '-d' || arg == '--debug'
|
2010-03-11 20:36:04 -05:00
|
|
|
log_level = org.apache.log4j.Level::DEBUG
|
2009-12-07 15:54:58 -05:00
|
|
|
$fullBackTrace = true
|
2012-10-27 21:37:04 -04:00
|
|
|
@shell_debug = true
|
2014-08-04 15:47:54 -04:00
|
|
|
found.push(arg)
|
2017-07-19 13:05:26 -04:00
|
|
|
puts 'Setting DEBUG log level...'
|
2014-08-08 16:54:53 -04:00
|
|
|
elsif arg == '-n' || arg == '--noninteractive'
|
|
|
|
interactive = false
|
|
|
|
found.push(arg)
|
2018-01-11 14:47:13 -05:00
|
|
|
elsif arg == '-r' || arg == '--return-values'
|
2018-04-04 10:37:27 -04:00
|
|
|
warn '[INFO] the -r | --return-values option is ignored. we always behave '\
|
|
|
|
'as though it was given.'
|
2018-01-11 14:47:13 -05:00
|
|
|
found.push(arg)
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
elsif arg == '--top-level-defs'
|
|
|
|
top_level_definitions = true
|
2008-10-08 20:03:50 -04:00
|
|
|
else
|
2009-06-25 19:53:04 -04:00
|
|
|
# Presume it a script. Save it off for running later below
|
|
|
|
# after we've set up some environment.
|
|
|
|
script2run = arg
|
|
|
|
found.push(arg)
|
2009-07-10 00:20:48 -04:00
|
|
|
# Presume that any other args are meant for the script.
|
|
|
|
break
|
2008-06-12 02:00:35 -04:00
|
|
|
end
|
|
|
|
end
|
2009-12-07 15:54:58 -05:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Delete all processed args
|
|
|
|
found.each { |arg| ARGV.delete(arg) }
|
2014-08-04 15:47:54 -04:00
|
|
|
# Make sure debug flag gets back to IRB
|
2017-07-19 13:05:26 -04:00
|
|
|
ARGV.unshift('-d') if @shell_debug
|
2008-06-12 02:00:35 -04:00
|
|
|
|
2009-12-07 15:54:58 -05:00
|
|
|
# Set logging level to avoid verboseness
|
2017-07-19 13:05:26 -04:00
|
|
|
org.apache.log4j.Logger.getLogger('org.apache.zookeeper').setLevel(log_level)
|
|
|
|
org.apache.log4j.Logger.getLogger('org.apache.hadoop.hbase').setLevel(log_level)
|
2009-01-29 11:51:26 -05:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Require HBase now after setting log levels
|
2015-12-28 17:50:50 -05:00
|
|
|
require 'hbase_constants'
|
2009-06-16 23:46:12 -04:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Load hbase shell
|
|
|
|
require 'shell'
|
2008-06-01 01:19:08 -04:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Require formatter
|
|
|
|
require 'shell/formatter'
|
2008-06-17 19:58:05 -04:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Setup the HBase module. Create a configuration.
|
2018-12-07 02:05:21 -05:00
|
|
|
@hbase = _configuration.nil? ? Hbase::Hbase.new : Hbase::Hbase.new(_configuration)
|
2008-08-12 14:30:33 -04:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Setup console
|
2018-04-04 10:37:27 -04:00
|
|
|
@shell = Shell::Shell.new(@hbase, interactive)
|
2013-08-21 16:21:14 -04:00
|
|
|
@shell.debug = @shell_debug
|
2009-01-05 20:12:36 -05:00
|
|
|
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
##
|
|
|
|
# Toggle shell debugging
|
|
|
|
#
|
|
|
|
# @return [Boolean] true if debug is turned on after updating the flag
|
2010-03-16 13:43:09 -04:00
|
|
|
def debug
|
2012-10-27 21:37:04 -04:00
|
|
|
if @shell_debug
|
|
|
|
@shell_debug = false
|
2010-03-16 13:43:09 -04:00
|
|
|
conf.back_trace_limit = 0
|
2012-10-27 21:37:04 -04:00
|
|
|
log_level = org.apache.log4j.Level::ERROR
|
2010-03-16 13:43:09 -04:00
|
|
|
else
|
2012-10-27 21:37:04 -04:00
|
|
|
@shell_debug = true
|
2010-03-16 13:43:09 -04:00
|
|
|
conf.back_trace_limit = 100
|
2012-10-27 21:37:04 -04:00
|
|
|
log_level = org.apache.log4j.Level::DEBUG
|
2010-03-16 13:43:09 -04:00
|
|
|
end
|
2017-07-19 13:05:26 -04:00
|
|
|
org.apache.log4j.Logger.getLogger('org.apache.zookeeper').setLevel(log_level)
|
|
|
|
org.apache.log4j.Logger.getLogger('org.apache.hadoop.hbase').setLevel(log_level)
|
2010-03-16 13:43:09 -04:00
|
|
|
debug?
|
|
|
|
end
|
|
|
|
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
##
|
|
|
|
# Print whether debug is on or off
|
2010-03-16 13:43:09 -04:00
|
|
|
def debug?
|
2012-10-27 21:37:04 -04:00
|
|
|
puts "Debug mode is #{@shell_debug ? 'ON' : 'OFF'}\n\n"
|
2010-03-16 13:43:09 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2020-08-18 16:14:34 -04:00
|
|
|
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
# For backwards compatibility, this will export all the HBase shell commands, constants, and
|
|
|
|
# instance variables (@hbase and @shell) onto Ruby's top-level receiver object known as "main".
|
|
|
|
@shell.export_all(self) if top_level_definitions
|
2009-09-22 23:10:49 -04:00
|
|
|
|
2014-08-08 16:54:53 -04:00
|
|
|
# If script2run, try running it. If we're in interactive mode, will go on to run the shell unless
|
2009-09-22 23:10:49 -04:00
|
|
|
# script calls 'exit' or 'exit 0' or 'exit errcode'.
|
2020-08-18 16:14:34 -04:00
|
|
|
require 'shell/hbase_loader'
|
|
|
|
if script2run
|
|
|
|
::Shell::Shell.exception_handler(!$fullBackTrace) { @shell.eval_io(Hbase::Loader.file_for_load(script2run), filename = script2run) }
|
|
|
|
end
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
|
|
|
|
# If we are not running interactively, evaluate standard input
|
2020-08-18 16:14:34 -04:00
|
|
|
::Shell::Shell.exception_handler(!$fullBackTrace) { @shell.eval_io(STDIN) } unless interactive
|
2009-09-22 23:10:49 -04:00
|
|
|
|
2014-08-08 16:54:53 -04:00
|
|
|
if interactive
|
|
|
|
# Output a banner message that tells users where to go for help
|
|
|
|
@shell.print_banner
|
2008-06-01 01:19:08 -04:00
|
|
|
|
2017-07-19 13:05:26 -04:00
|
|
|
require 'irb'
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
require 'irb/ext/change-ws'
|
2014-08-08 16:54:53 -04:00
|
|
|
require 'irb/hirb'
|
2008-06-01 01:19:08 -04:00
|
|
|
|
2014-08-08 16:54:53 -04:00
|
|
|
module IRB
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
# Override of the default IRB.start
|
2014-08-08 16:54:53 -04:00
|
|
|
def self.start(ap_path = nil)
|
2017-07-19 13:05:26 -04:00
|
|
|
$0 = File.basename(ap_path, '.rb') if ap_path
|
2008-06-01 01:19:08 -04:00
|
|
|
|
2014-08-08 16:54:53 -04:00
|
|
|
IRB.setup(ap_path)
|
|
|
|
@CONF[:IRB_NAME] = 'hbase'
|
|
|
|
@CONF[:AP_NAME] = 'hbase'
|
|
|
|
@CONF[:BACK_TRACE_LIMIT] = 0 unless $fullBackTrace
|
2010-03-11 20:36:04 -05:00
|
|
|
|
2017-07-19 13:05:26 -04:00
|
|
|
hirb = if @CONF[:SCRIPT]
|
|
|
|
HIRB.new(nil, @CONF[:SCRIPT])
|
|
|
|
else
|
|
|
|
HIRB.new
|
|
|
|
end
|
2008-06-01 01:19:08 -04:00
|
|
|
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
shl = TOPLEVEL_BINDING.receiver.instance_variable_get :'@shell'
|
|
|
|
hirb.context.change_workspace shl.get_workspace
|
|
|
|
|
2014-08-08 16:54:53 -04:00
|
|
|
@CONF[:IRB_RC].call(hirb.context) if @CONF[:IRB_RC]
|
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace (#2141)
* HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace
- Refactor Shell.export_commands to define commands using ruby lambdas.
Additionally, this change stores a reference to shell_inst in scope so that
we no longer need to assume the existance of the variable @shell.
- Add logic to Shell class for constructing an IRB workspace with its own
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
- Create new method on Shell for evaluating input from an arbitrary IO instance
within the created IRB workspace. This is based on work by Hsieh that was
previously in bin/hirb.rb. This method is more generic and more testable.
This single pattern can be used for both executing files and reading from
stdin, therefore reducing complexity.
- Move special 'help' and 'tools' command definitions to shell.rb. These
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
- Remove all global includes of HBaseConstants from ruby test files. Before
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
- Try to reduce the number of places that constants are included. I think it's
best to reference each ruby constant's full name, but where that would cause
a big diff I instead moved the include to the innermost Module or Class.
- Update docs and comments
- Remove unneccessary includes
- Add shell --top-level-cmds compatibility flag. Since this PR removes all the
HBase symbols from the top-level receiver (ie. main Object), it is possible
(albeit unlikely) that this will break operator scripts. This flag will
export all the commands at the top-level like the shell previously did.
* HBASE-11686 Light refactoring with added unit tests
- Fixes some constants references by admin test 2
- Install HBase commands as singleton methods on recevier instances so that
multiple receivers may exist.
- Rename new flag from --top-level-cmds to --top-level-defs to be more
semantically accurate.
- Create new helper method Shell::Shell#export_all to install @hbase, @shell,
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.
- Add unit tests for Shell::Shell#eval_io and Shell::Shell#export_all
- Add @hbase and @shell to hbase-shell IRB workspace
- Fix robocop issues within patch
* Typo s/is/if/
2020-07-27 23:56:09 -04:00
|
|
|
# Storing our current HBase IRB Context as the main context is imperative for several reasons,
|
|
|
|
# including auto-completion.
|
2014-08-08 16:54:53 -04:00
|
|
|
@CONF[:MAIN_CONTEXT] = hirb.context
|
2008-06-01 01:19:08 -04:00
|
|
|
|
2014-08-08 16:54:53 -04:00
|
|
|
catch(:IRB_EXIT) do
|
|
|
|
hirb.eval_input
|
|
|
|
end
|
2008-06-01 01:19:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-08 16:54:53 -04:00
|
|
|
IRB.start
|
|
|
|
end
|