-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HBASE-11686 Shell code should create a binding / irb workspace instead of polluting the root namespace #2141
Conversation
…d 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.
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
- 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
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent
@busbey FYI
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
Failures are in the abandoned backup module. |
…d 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/ (cherry picked from commit 7eff07d)
…d of polluting the root namespace (apache#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/ (cherry picked from commit 7eff07d)
Resolves https://issues.apache.org/jira/browse/HBASE-11686
Goal
Stop defining HBase commands and constants on Ruby's main object. Instead, HBase commands and constants are defined within the scope of an Interactive Ruby (IRB) Workspace.
Consequences for Scripts
When using script via STDIN (
echo version | hbase shell
) or filename (hbase shell script.rb
), the code is evaluated by this PR within the created IRB Workspace. Code should work as before unless the script "breaks out" of the current binding (for example, this could be done using Ruby'sTOPLEVEL_BINDING
). For cases like this one, I added a flag--top-level-defs
that should be backwards compatible with all scripts.Changelog
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.
binding and non-global receiver. This workspace is loaded with all HBase and
IRB commands.
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.
commands are tightly linked with an instance of the shell, so it is easiest
to have them defined together.
this change, tests were loading these constants into the top level, which
could cause tests to pass that should really fail.
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.
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.
constants, and all hbase commands to a target receiver. As a result, the
HBaseReceiver became very simple and could be moved to shell.rb.