# # # 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. # # 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. # # 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. # TODO: Interrupt a table creation or a connection to a bad master. Currently # 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) # TODO: Add support for listing and manipulating catalog tables, etc. # TODO: Encoding; need to know how to go from ruby String to UTF-8 bytes # Run the java magic include and import basic HBase types that will help ease # hbase hacking. include Java # Some goodies for hirb. Should these be left up to the user's discretion? require 'irb/completion' require 'pathname' # Add the directory names in hbase.jruby.sources commandline option # to the ruby load path so I can load up my HBase ruby modules sources = java.lang.System.getProperty('hbase.ruby.sources') $LOAD_PATH.unshift Pathname.new(sources) # # FIXME: Switch args processing to getopt # # 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 = < exception message = exception.to_s # exception unwrapping in shell means we'll have to handle Java exceptions # as a special case in order to format them properly. if exception.kind_of? java.lang.Exception $stderr.puts "java exception" message = exception.get_message end # Include the 'ERROR' string to try to make transition easier for scripts that # may have already been relying on grepping output. puts "ERROR #{exception.class}: #{message}" if $fullBacktrace # re-raising the will include a backtrace and exit. raise exception else exit 1 end end end