2010-03-26 18:45:48 -04:00
|
|
|
#
|
|
|
|
# Copyright 2009 The Apache Software Foundation
|
|
|
|
#
|
|
|
|
# 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.
|
2008-05-30 15:19:46 -04:00
|
|
|
|
2008-06-13 01:50:00 -04:00
|
|
|
# TODO: Add 'debug' support (client-side logs show in shell). Add it as
|
|
|
|
# command-line option and as command.
|
|
|
|
# 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]]
|
|
|
|
|
|
|
|
--format=OPTION Formatter for outputting results.
|
|
|
|
Valid options are: console, html.
|
|
|
|
(Default: console)
|
|
|
|
|
|
|
|
-d | --debug Set DEBUG log levels.
|
|
|
|
-h | --help This help.
|
2008-06-12 02:00:35 -04:00
|
|
|
HERE
|
|
|
|
found = []
|
2008-06-18 18:24:34 -04:00
|
|
|
format = 'console'
|
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
|
2008-06-12 02:00:35 -04:00
|
|
|
for arg in ARGV
|
2009-06-03 01:11:48 -04:00
|
|
|
if arg =~ /^--format=(.+)/i
|
2008-06-12 02:00:35 -04:00
|
|
|
format = $1
|
|
|
|
if format =~ /^html$/i
|
2008-06-18 18:24:34 -04:00
|
|
|
raise NoMethodError.new("Not yet implemented")
|
2008-06-12 02:00:35 -04:00
|
|
|
elsif format =~ /^console$/i
|
|
|
|
# This is default
|
|
|
|
else
|
|
|
|
raise ArgumentError.new("Unsupported format " + arg)
|
|
|
|
end
|
2008-06-18 18:24:34 -04:00
|
|
|
found.push(arg)
|
2008-06-12 02:00:35 -04:00
|
|
|
elsif arg == '-h' || arg == '--help'
|
2008-06-13 01:50:00 -04:00
|
|
|
puts cmdline_help
|
2008-06-12 02:00:35 -04:00
|
|
|
exit
|
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
|
2010-03-11 20:36:04 -05:00
|
|
|
puts "Setting DEBUG log level..."
|
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) }
|
2008-06-12 02:00:35 -04:00
|
|
|
|
2009-12-07 15:54:58 -05:00
|
|
|
# Set logging level to avoid verboseness
|
2010-03-11 20:36:04 -05: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
|
|
|
|
require 'hbase'
|
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
|
|
|
# Presume console format.
|
|
|
|
# Formatter takes an :output_stream parameter, if you don't want STDOUT.
|
2010-05-31 12:49:50 -04:00
|
|
|
@formatter = Shell::Formatter::Console.new
|
2008-06-17 19:58:05 -04:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Setup the HBase module. Create a configuration.
|
|
|
|
@hbase = Hbase::Hbase.new
|
2008-08-12 14:30:33 -04:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Setup console
|
|
|
|
@shell = Shell::Shell.new(@hbase, @formatter)
|
2009-01-05 20:12:36 -05:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Add commands to this namespace
|
|
|
|
@shell.export_commands(self)
|
2009-01-05 20:12:36 -05:00
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Add help command
|
|
|
|
def help(command = nil)
|
|
|
|
@shell.help(command)
|
2009-01-05 20:12:36 -05:00
|
|
|
end
|
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Backwards compatibility method
|
|
|
|
def tools
|
|
|
|
@shell.help_group('tools')
|
2009-01-05 20:12:36 -05:00
|
|
|
end
|
|
|
|
|
2010-03-16 13:43:09 -04:00
|
|
|
# Debugging method
|
|
|
|
def debug
|
|
|
|
if @shell.debug
|
|
|
|
@shell.debug = false
|
|
|
|
conf.back_trace_limit = 0
|
|
|
|
else
|
|
|
|
@shell.debug = true
|
|
|
|
conf.back_trace_limit = 100
|
|
|
|
end
|
|
|
|
debug?
|
|
|
|
end
|
|
|
|
|
|
|
|
def debug?
|
|
|
|
puts "Debug mode is #{@shell.debug ? 'ON' : 'OFF'}\n\n"
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2010-03-11 20:36:04 -05:00
|
|
|
# Include hbase constants
|
|
|
|
include HBaseConstants
|
2009-09-22 23:10:49 -04:00
|
|
|
|
|
|
|
# If script2run, try running it. Will go on to run the shell unless
|
|
|
|
# script calls 'exit' or 'exit 0' or 'exit errcode'.
|
|
|
|
load(script2run) if script2run
|
|
|
|
|
2008-05-30 15:19:46 -04:00
|
|
|
# Output a banner message that tells users where to go for help
|
2010-03-11 20:36:04 -05:00
|
|
|
@shell.print_banner
|
2008-06-01 01:19:08 -04:00
|
|
|
|
|
|
|
require "irb"
|
2010-03-11 20:36:04 -05:00
|
|
|
require 'irb/hirb'
|
2008-06-01 01:19:08 -04:00
|
|
|
|
|
|
|
module IRB
|
2010-03-11 20:36:04 -05:00
|
|
|
def self.start(ap_path = nil)
|
2008-06-01 01:19:08 -04:00
|
|
|
$0 = File::basename(ap_path, ".rb") if ap_path
|
|
|
|
|
|
|
|
IRB.setup(ap_path)
|
2008-06-18 18:24:34 -04:00
|
|
|
@CONF[:IRB_NAME] = 'hbase'
|
|
|
|
@CONF[:AP_NAME] = 'hbase'
|
2009-12-07 15:54:58 -05:00
|
|
|
@CONF[:BACK_TRACE_LIMIT] = 0 unless $fullBackTrace
|
2010-03-11 20:36:04 -05:00
|
|
|
|
2008-06-01 01:19:08 -04:00
|
|
|
if @CONF[:SCRIPT]
|
2008-06-12 02:00:35 -04:00
|
|
|
hirb = HIRB.new(nil, @CONF[:SCRIPT])
|
2008-06-01 01:19:08 -04:00
|
|
|
else
|
2008-06-12 02:00:35 -04:00
|
|
|
hirb = HIRB.new
|
2008-06-01 01:19:08 -04:00
|
|
|
end
|
|
|
|
|
2008-06-12 02:00:35 -04:00
|
|
|
@CONF[:IRB_RC].call(hirb.context) if @CONF[:IRB_RC]
|
|
|
|
@CONF[:MAIN_CONTEXT] = hirb.context
|
2008-06-01 01:19:08 -04:00
|
|
|
|
|
|
|
catch(:IRB_EXIT) do
|
2008-06-12 02:00:35 -04:00
|
|
|
hirb.eval_input
|
2008-06-01 01:19:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
IRB.start
|