hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r922110 [1/2] - in /hadoop/hbase/trunk: ./ bin/ core/src/main/ruby/ core/src/main/ruby/hbase/ core/src/main/ruby/irb/ core/src/main/ruby/shell/ core/src/main/ruby/shell/commands/ core/src/test/java/org/apache/hadoop/hbase/client/ core/src/t...
Date Fri, 12 Mar 2010 01:36:05 GMT
Author: stack
Date: Fri Mar 12 01:36:04 2010
New Revision: 922110

URL: http://svn.apache.org/viewvc?rev=922110&view=rev
Log:
HBASE-2279 Hbase Shell does not have any tests

Added:
    hadoop/hbase/trunk/core/src/main/ruby/
    hadoop/hbase/trunk/core/src/main/ruby/hbase/
    hadoop/hbase/trunk/core/src/main/ruby/hbase.rb
    hadoop/hbase/trunk/core/src/main/ruby/hbase/admin.rb
    hadoop/hbase/trunk/core/src/main/ruby/hbase/hbase.rb
    hadoop/hbase/trunk/core/src/main/ruby/hbase/table.rb
    hadoop/hbase/trunk/core/src/main/ruby/irb/
    hadoop/hbase/trunk/core/src/main/ruby/irb/hirb.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/
    hadoop/hbase/trunk/core/src/main/ruby/shell.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/alter.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/close_region.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/compact.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/count.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/create.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/delete.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/deleteall.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/describe.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable_region.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/drop.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable_region.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/exists.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/flush.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/get.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/incr.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/list.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/major_compact.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/put.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/scan.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/shutdown.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/split.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/status.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/truncate.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/version.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk_dump.rb
    hadoop/hbase/trunk/core/src/main/ruby/shell/formatter.rb
    hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestShell.java
    hadoop/hbase/trunk/core/src/test/ruby/
    hadoop/hbase/trunk/core/src/test/ruby/hbase/
    hadoop/hbase/trunk/core/src/test/ruby/hbase/admin_test.rb
    hadoop/hbase/trunk/core/src/test/ruby/hbase/hbase_test.rb
    hadoop/hbase/trunk/core/src/test/ruby/hbase/table_test.rb
    hadoop/hbase/trunk/core/src/test/ruby/shell/
    hadoop/hbase/trunk/core/src/test/ruby/shell/commands_test.rb
    hadoop/hbase/trunk/core/src/test/ruby/shell/formatter_test.rb
    hadoop/hbase/trunk/core/src/test/ruby/shell/shell_test.rb
    hadoop/hbase/trunk/core/src/test/ruby/test_helper.rb
    hadoop/hbase/trunk/core/src/test/ruby/tests_runner.rb
Removed:
    hadoop/hbase/trunk/bin/Formatter.rb
    hadoop/hbase/trunk/bin/HBase.rb
Modified:
    hadoop/hbase/trunk/.gitignore
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/bin/hirb.rb
    hadoop/hbase/trunk/src/assembly/bin.xml

Modified: hadoop/hbase/trunk/.gitignore
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/.gitignore?rev=922110&r1=922109&r2=922110&view=diff
==============================================================================
--- hadoop/hbase/trunk/.gitignore (original)
+++ hadoop/hbase/trunk/.gitignore Fri Mar 12 01:36:04 2010
@@ -9,4 +9,6 @@
 /contrib/stargate/target/
 /contrib/transactional/target/
 /core/target/
+/core/build/
+/core/test/
 *.iml

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=922110&r1=922109&r2=922110&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Fri Mar 12 01:36:04 2010
@@ -427,6 +427,7 @@ Release 0.21.0 - Unreleased
                of the table (Kay Kay via Stack) 
    HBASE-2309  Add apache releases to pom (list of ) repositories
                (Kay Kay via Stack)
+   HBASE-2279  Hbase Shell does not have any tests (Alexey Kovyrin via Stack)
 
   NEW FEATURES
    HBASE-1961  HBase EC2 scripts

Modified: hadoop/hbase/trunk/bin/hirb.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/hirb.rb?rev=922110&r1=922109&r2=922110&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/hirb.rb (original)
+++ hadoop/hbase/trunk/bin/hirb.rb Fri Mar 12 01:36:04 2010
@@ -18,12 +18,17 @@ include Java
 # Some goodies for hirb. Should these be left up to the user's discretion?
 require 'irb/completion'
 
-# Add the $HBASE_HOME/bin directory, the location of this script, to the ruby
-# load path so I can load up my HBase ruby modules
-$LOAD_PATH.unshift File.dirname($PROGRAM_NAME)
-# Require formatter
-require 'Formatter'
+# Add the $HBASE_HOME/lib/ruby OR $HBASE_HOME/core/src/main/ruby/lib directory
+# to the ruby load path so I can load up my HBase ruby modules
+if File.exists?(File.join(File.dirname(__FILE__), "..", "lib", "ruby", "hbase.rb"))
+  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib", "ruby")
+else
+  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "core", "src", "main", "ruby")
+end
 
+#
+# 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 = <<HERE # HERE document output as shell usage
@@ -36,7 +41,7 @@ found = []
 format = 'console'
 format_width = 110
 script2run = nil
-logLevel = org.apache.log4j.Level::ERROR  
+log_level = org.apache.log4j.Level::ERROR
 for arg in ARGV
   if arg =~ /^--format=(.+)/i
     format = $1
@@ -55,9 +60,9 @@ for arg in ARGV
     puts cmdline_help
     exit
   elsif arg == '-d' || arg == '--debug'
-    logLevel = org.apache.log4j.Level::DEBUG
+    log_level = org.apache.log4j.Level::DEBUG
     $fullBackTrace = true
-    puts "Setting DEBUG log level..."  
+    puts "Setting DEBUG log level..."
   else
     # Presume it a script. Save it off for running later below
     # after we've set up some environment.
@@ -67,439 +72,68 @@ for arg in ARGV
     break
   end
 end
-for arg in found
-  ARGV.delete(arg)
-end
 
-# Presume console format.
-# Formatter takes an :output_stream parameter, if you don't want STDOUT.
-@formatter = Formatter::Console.new(:format_width => format_width)
-# TODO, etc.  @formatter = Formatter::XHTML.new(STDOUT)
+# Delete all processed args
+found.each { |arg| ARGV.delete(arg) }
 
 # Set logging level to avoid verboseness
-logger = org.apache.log4j.Logger.getLogger("org.apache.zookeeper")
-logger.setLevel(logLevel);
-logger = org.apache.log4j.Logger.getLogger("org.apache.hadoop.hbase")
-logger.setLevel(logLevel);
-# Require HBase now after setting log levels
-require 'HBase'
-
-# Setup the HBase module.  Create a configuration.
-# Turn off retries in hbase and ipc.  Human doesn't want to wait on N retries.
-@configuration = org.apache.hadoop.hbase.HBaseConfiguration.new()
-@configuration.setInt("hbase.client.retries.number", 7)
-@configuration.setInt("ipc.client.connect.max.retries", 3)
-
-# Do lazy create of admin because if we are pointed at bad master, it will hang
-# shell on startup trying to connect.
-@admin = nil
-
-# Promote hbase constants to be constants of this module so can
-# be used bare as keys in 'create', 'alter', etc. To see constants
-# in IRB, type 'Object.constants'. Don't promote defaults because
-# flattens all types to String.  Can be confusing.
-def promoteConstants(constants)
-  # The constants to import are all in uppercase
-  for c in constants
-    if c == c.upcase
-      eval("%s = \"%s\"" % [c, c]) unless c =~ /DEFAULT_.*/
-    end
-  end
-end
-promoteConstants(org.apache.hadoop.hbase.HColumnDescriptor.constants)
-promoteConstants(org.apache.hadoop.hbase.HTableDescriptor.constants)
-promoteConstants(HBase.constants)
-
-
-# Start of the hbase shell commands.
-
-# General shell methods
-
-def tools
-  # Help for hbase shell surgery tools
-  h  = <<HERE
-HBASE SURGERY TOOLS:
- close_region    Close a single region. Optionally specify regionserver.
-                 Examples:
-                 
-                 hbase> close_region 'REGIONNAME'
-                 hbase> close_region 'REGIONNAME', 'REGIONSERVER_IP:PORT'
-
- compact         Compact all regions in passed table or pass a region row
-                 to compact an individual region
-
- disable_region  Disable a single region
-
- enable_region   Enable a single region. For example:
-  
-                 hbase> enable_region 'REGIONNAME'
- 
- flush           Flush all regions in passed table or pass a region row to
-                 flush an individual region.  For example:
-
-                 hbase> flush 'TABLENAME'
-                 hbase> flush 'REGIONNAME'
-
- major_compact   Run major compaction on passed table or pass a region row
-                 to major compact an individual region
-
- split           Split table or pass a region row to split individual region
-
- zk              Low level ZooKeeper surgery tools. Type "zk 'help'" for more
-                 information (Yes, you must quote 'help').
-
- zk_dump         Dump status of HBase cluster as seen by ZooKeeper.
-
-Above commands are for 'experts'-only as misuse can damage an install
-HERE
-  puts h
-end
-
-def help
-  # Output help.  Help used to be a dictionary of name to short and long
-  # descriptions emitted using Formatters but awkward getting it to show
-  # nicely on console; instead use a HERE document.  Means we can't
-  # output help other than on console but not an issue at the moment.
-  # TODO: Add help to the commands themselves rather than keep it distinct
-  h  = <<HERE
-HBASE SHELL COMMANDS:
- alter     Alter column family schema;  pass table name and a dictionary
-           specifying new column family schema. Dictionaries are described
-           below in the GENERAL NOTES section.  Dictionary must include name
-           of column family to alter.  For example, 
-           
-           To change or add the 'f1' column family in table 't1' from defaults
-           to instead keep a maximum of 5 cell VERSIONS, do:
-           hbase> alter 't1', {NAME => 'f1', VERSIONS => 5}
-           
-           To delete the 'f1' column family in table 't1', do:
-           hbase> alter 't1', {NAME => 'f1', METHOD => 'delete'}
-
-           You can also change table-scope attributes like MAX_FILESIZE
-           MEMSTORE_FLUSHSIZE, READONLY, and DEFERRED_LOG_FLUSH.
-
-           For example, to change the max size of a family to 128MB, do:
-           hbase> alter 't1', {METHOD => 'table_att', MAX_FILESIZE => '134217728'}
-           
- count     Count the number of rows in a table. This operation may take a LONG
-           time (Run '$HADOOP_HOME/bin/hadoop jar hbase.jar rowcount' to run a
-           counting mapreduce job). Current count is shown every 1000 rows by
-           default. Count interval may be optionally specified. Examples:
-           
-           hbase> count 't1'
-           hbase> count 't1', 100000
-
- create    Create table; pass table name, a dictionary of specifications per
-           column family, and optionally a dictionary of table configuration.
-           Dictionaries are described below in the GENERAL NOTES section.
-           Examples:
-
-           hbase> create 't1', {NAME => 'f1', VERSIONS => 5}
-           hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
-           hbase> # The above in shorthand would be the following:
-           hbase> create 't1', 'f1', 'f2', 'f3'
-           hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, \\
-             BLOCKCACHE => true}
-
- describe  Describe the named table: e.g. "hbase> describe 't1'"
-
- delete    Put a delete cell value at specified table/row/column and optionally
-           timestamp coordinates.  Deletes must match the deleted cell's
-           coordinates exactly.  When scanning, a delete cell suppresses older
-           versions. Takes arguments like the 'put' command described below
- 
- deleteall Delete all cells in a given row; pass a table name, row, and optionally 
-           a column and timestamp
-
- disable   Disable the named table: e.g. "hbase> disable 't1'"
- 
- drop      Drop the named table. Table must first be disabled. If table has
-           more than one region, run a major compaction on .META.:
-
-           hbase> major_compact ".META."
-
- enable    Enable the named table
-
- exists    Does the named table exist? e.g. "hbase> exists 't1'"
-
- exit      Type "hbase> exit" to leave the HBase Shell
-
- get       Get row or cell contents; pass table name, row, and optionally
-           a dictionary of column(s), timestamp and versions.  Examples:
-
-           hbase> get 't1', 'r1'
-           hbase> get 't1', 'r1', {COLUMN => 'c1'}
-           hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}
-           hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
-           hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, \\
-             VERSIONS => 4}
-
- incr      Increments a cell 'value' at specified table/row/column coordinates.
-           To increment a cell value in table 't1' at row 'r1' under column
-           'c1' by 1 (can be omitted) or 10 do:
-
-           hbase> incr 't1', 'r1', 'c1'
-           hbase> incr 't1', 'r1', 'c1', 1
-           hbase> incr 't1', 'r1', 'c1', 10
-
- list      List all tables in hbase
-
- put       Put a cell 'value' at specified table/row/column and optionally
-           timestamp coordinates.  To put a cell value into table 't1' at
-           row 'r1' under column 'c1' marked with the time 'ts1', do:
-
-           hbase> put 't1', 'r1', 'c1', 'value', ts1
-
- tools     Listing of hbase surgery tools
-
- scan      Scan a table; pass table name and optionally a dictionary of scanner 
-           specifications.  Scanner specifications may include one or more of 
-           the following: LIMIT, STARTROW, STOPROW, TIMESTAMP, or COLUMNS.  If 
-           no columns are specified, all columns will be scanned.  To scan all 
-           members of a column family, leave the qualifier empty as in 
-           'col_family:'.  Examples:
-           
-           hbase> scan '.META.'
-           hbase> scan '.META.', {COLUMNS => 'info:regioninfo'}
-           hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, \\
-             STARTROW => 'xyz'}
-           
-           For experts, there is an additional option -- CACHE_BLOCKS -- which
-           switches block caching for the scanner on (true) or off (false).  By
-           default it is enabled.  Examples:
-           
-           hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}
-
- status    Show cluster status. Can be 'summary', 'simple', or 'detailed'. The
-           default is 'summary'. Examples:
-           
-           hbase> status
-           hbase> status 'simple'
-           hbase> status 'summary'
-           hbase> status 'detailed'
-
- shutdown  Shut down the cluster.
-
- truncate  Disables, drops and recreates the specified table.
-           
- version   Output this HBase version
-
-GENERAL NOTES:
-Quote all names in the hbase shell such as table and column names.  Don't
-forget commas delimit command parameters.  Type <RETURN> after entering a
-command to run it.  Dictionaries of configuration used in the creation and
-alteration of tables are ruby Hashes. They look like this:
-
-  {'key1' => 'value1', 'key2' => 'value2', ...}
-
-They are opened and closed with curley-braces.  Key/values are delimited by
-the '=>' character combination.  Usually keys are predefined constants such as
-NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type
-'Object.constants' to see a (messy) list of all constants in the environment.
-
-In case you are using binary keys or values and need to enter them into the 
-shell then use double-quotes to make use of hexadecimal for example:
-
-  hbase> get 't1', "key\\x03\\x3f\\xcd"
-  hbase> get 't1', "key\\003\\023\\011"
-  hbase> put 't1', "test\\xef\\xff", 'f1:', "\\x01\\x33\\x40"
-
-Using the double-quote notation you can directly use the values output by the
-shell for example during a "scan" call.
-
-This HBase shell is the JRuby IRB with the above HBase-specific commands added.
-For more on the HBase Shell, see http://wiki.apache.org/hadoop/Hbase/Shell
-HERE
-  puts h
-end
-
-def version
-  # Output version.
-  puts "Version: #{org.apache.hadoop.hbase.util.VersionInfo.getVersion()},\
- r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision()},\
- #{org.apache.hadoop.hbase.util.VersionInfo.getDate()}"
-end
-
-def shutdown
-  admin().shutdown()
-end 
-
-# DDL
-
-def admin()
-  @admin = HBase::Admin.new(@configuration, @formatter) unless @admin
-  @admin
-end
-
-def table(table)
-  # Create new one each time
-  HBase::Table.new(@configuration, table, @formatter)
-end
-
-def create(table, *args)
-  admin().create(table, args)
-end
-
-def drop(table)
-  admin().drop(table)
-end
-
-def alter(table, args)
-  admin().alter(table, args) 
-end
-
-# Administration
+org.apache.log4j.Logger.getLogger("org.apache.zookeeper").setLevel(log_level)
+org.apache.log4j.Logger.getLogger("org.apache.hadoop.hbase").setLevel(log_level)
 
-def list
-  admin().list()
-end
-
-def describe(table)
-  admin().describe(table)
-end
-  
-def enable(table)
-  admin().enable(table)
-end
-
-def disable(table)
-  admin().disable(table)
-end
-
-def enable_region(regionName)
-  admin().enable_region(regionName)
-end
-
-def disable_region(regionName)
-  admin().disable_region(regionName)
-end
-
-def exists(table)
-  admin().exists(table)
-end
-
-def truncate(table)
-  admin().truncate(table)
-end
-
-def close_region(regionName, server = nil)
-  admin().close_region(regionName, server)
-end
-
-def status(format = 'summary')
-  admin().status(format)
-end
-
-def zk(*args)
-  admin().zk(args)
-end
-
-def zk_dump
-  admin().zk_dump
-end
-
-# CRUD
-  
-def get(table, row, args = {})
-  table(table).get(row, args)
-end
+# Require HBase now after setting log levels
+require 'hbase'
 
-def put(table, row, column, value, timestamp = nil)
-  table(table).put(row, column, value, timestamp)
-end
-  
-def incr(table, row, column, value = nil)
-  table(table).incr(row, column, value)
-end
+# Load hbase shell
+require 'shell'
 
-def scan(table, args = {})
-  table(table).scan(args)
-end
-  
-def delete(table, row, column,
-    timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
-  table(table).delete(row, column, timestamp)
-end
+# Require formatter
+require 'shell/formatter'
 
-def deleteall(table, row, column = nil,
-    timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
-  table(table).deleteall(row, column, timestamp)
-end
+# Presume console format.
+# Formatter takes an :output_stream parameter, if you don't want STDOUT.
+@formatter = Shell::Formatter::Console.new(:format_width => format_width)
 
-def count(table, interval = 1000)
-  table(table).count(interval)
-end
+# Setup the HBase module.  Create a configuration.
+@hbase = Hbase::Hbase.new
 
-def flush(tableNameOrRegionName)
-  admin().flush(tableNameOrRegionName)
-end
+# Setup console
+@shell = Shell::Shell.new(@hbase, @formatter)
 
-def compact(tableNameOrRegionName)
-  admin().compact(tableNameOrRegionName)
-end
+# Add commands to this namespace
+@shell.export_commands(self)
 
-def major_compact(tableNameOrRegionName)
-  admin().major_compact(tableNameOrRegionName)
+# Add help command
+def help(command = nil)
+  @shell.help(command)
 end
 
-def split(tableNameOrRegionName)
-  admin().split(tableNameOrRegionName)
+# Backwards compatibility method
+def tools
+  @shell.help_group('tools')
 end
 
+# Include hbase constants
+include HBaseConstants
 
 # 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
 
-
 # Output a banner message that tells users where to go for help
-puts <<HERE
-HBase Shell; enter 'help<RETURN>' for list of supported commands.
-HERE
-version
+@shell.print_banner
 
 require "irb"
+require 'irb/hirb'
 
 module IRB
-  # Subclass of IRB so can intercept methods
-  class HIRB < Irb
-    def initialize
-      # This is ugly.  Our 'help' method above provokes the following message
-      # on irb construction: 'irb: warn: can't alias help from irb_help.'
-      # Below, we reset the output so its pointed at /dev/null during irb
-      # construction just so this message does not come out after we emit
-      # the banner.  Other attempts at playing with the hash of methods
-      # down in IRB didn't seem to work. I think the worst thing that can
-      # happen is the shell exiting because of failed IRB construction with
-      # no error (though we're not blanking STDERR)
-      begin
-        f = File.open("/dev/null", "w")
-        $stdout = f
-        super
-      ensure
-        f.close()
-        $stdout = STDOUT
-      end
-    end 
-    
-    def output_value
-      # Suppress output if last_value is 'nil'
-      # Otherwise, when user types help, get ugly 'nil'
-      # after all output.
-      if @context.last_value != nil
-        super
-      end
-    end
-  end
-
-  def IRB.start(ap_path = nil)
+  def self.start(ap_path = nil)
     $0 = File::basename(ap_path, ".rb") if ap_path
 
     IRB.setup(ap_path)
     @CONF[:IRB_NAME] = 'hbase'
     @CONF[:AP_NAME] = 'hbase'
     @CONF[:BACK_TRACE_LIMIT] = 0 unless $fullBackTrace
-    
+
     if @CONF[:SCRIPT]
       hirb = HIRB.new(nil, @CONF[:SCRIPT])
     else

Added: hadoop/hbase/trunk/core/src/main/ruby/hbase.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/hbase.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/hbase.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/hbase.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,52 @@
+# HBase ruby classes.
+# Has wrapper classes for org.apache.hadoop.hbase.client.HBaseAdmin
+# and for org.apache.hadoop.hbase.client.HTable.  Classes take
+# Formatters on construction and outputs any results using
+# Formatter methods.  These classes are only really for use by
+# the hirb.rb HBase Shell script; they don't make much sense elsewhere.
+# For example, the exists method on Admin class prints to the formatter
+# whether the table exists and returns nil regardless.
+include Java
+
+java_import org.apache.hadoop.hbase.HConstants
+java_import org.apache.hadoop.hbase.HColumnDescriptor
+java_import org.apache.hadoop.hbase.HTableDescriptor
+
+include_class('java.lang.Integer') {|package,name| "J#{name}" }
+include_class('java.lang.Long') {|package,name| "J#{name}" }
+include_class('java.lang.Boolean') {|package,name| "J#{name}" }
+
+module HBaseConstants
+  COLUMN = "COLUMN"
+  COLUMNS = "COLUMNS"
+  TIMESTAMP = "TIMESTAMP"
+  NAME = HConstants::NAME
+  VERSIONS = HConstants::VERSIONS
+  IN_MEMORY = HConstants::IN_MEMORY
+  STOPROW = "STOPROW"
+  STARTROW = "STARTROW"
+  ENDROW = STOPROW
+  LIMIT = "LIMIT"
+  METHOD = "METHOD"
+  MAXLENGTH = "MAXLENGTH"
+  CACHE_BLOCKS = "CACHE_BLOCKS"
+  REPLICATION_SCOPE = "REPLICATION_SCOPE"
+
+  # Load constants from hbase java API
+  def self.promote_constants(constants)
+    # The constants to import are all in uppercase
+    constants.each do |c|
+      next if c =~ /DEFAULT_.*/ || c != c.upcase
+      next if eval("defined?(#{c})")
+      eval("#{c} = '#{c}'")
+    end
+  end
+
+  promote_constants(HColumnDescriptor.constants)
+  promote_constants(HTableDescriptor.constants)
+end
+
+# Include classes definition
+require 'hbase/hbase'
+require 'hbase/admin'
+require 'hbase/table'

Added: hadoop/hbase/trunk/core/src/main/ruby/hbase/admin.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/hbase/admin.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/hbase/admin.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/hbase/admin.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,351 @@
+include Java
+
+java_import org.apache.hadoop.hbase.client.HBaseAdmin
+java_import org.apache.zookeeper.ZooKeeperMain
+java_import org.apache.hadoop.hbase.HColumnDescriptor
+java_import org.apache.hadoop.hbase.HTableDescriptor
+java_import org.apache.hadoop.hbase.HRegionInfo
+java_import org.apache.zookeeper.ZooKeeper
+
+# Wrapper for org.apache.hadoop.hbase.client.HBaseAdmin
+
+module Hbase
+  class Admin
+    include HBaseConstants
+
+    def initialize(configuration, formatter)
+      @admin = HBaseAdmin.new(configuration)
+      connection = @admin.getConnection()
+      @zk_wrapper = connection.getZooKeeperWrapper()
+      zk = @zk_wrapper.getZooKeeper()
+      @zk_main = ZooKeeperMain.new(zk)
+      @formatter = formatter
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Returns a list of tables in hbase
+    def list
+      @admin.listTables.map { |t| t.getNameAsString }
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Requests a table or region flush
+    def flush(table_or_region_name)
+      @admin.flush(table_or_region_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Requests a table or region compaction
+    def compact(table_or_region_name)
+      @admin.compact(table_or_region_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Requests a table or region major compaction
+    def major_compact(table_or_region_name)
+      @admin.majorCompact(table_or_region_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Requests a table or region split
+    def split(table_or_region_name)
+      @admin.split(table_or_region_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Enables a table
+    def enable(table_name)
+      return if enabled?(table_name)
+      @admin.enableTable(table_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Disables a table
+    def disable(table_name)
+      return unless enabled?(table_name)
+      @admin.disableTable(table_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Drops a table
+    def drop(table_name)
+      raise ArgumentError, "Table #{table_name} does not exist.'" unless exists?(table_name)
+      raise ArgumentError, "Table #{table_name} is enabled. Disable it first.'" if enabled?(table_name)
+
+      @admin.deleteTable(table_name)
+      flush(HConstants::META_TABLE_NAME)
+      major_compact(HConstants::META_TABLE_NAME)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Shuts hbase down
+    def shutdown
+      @admin.shutdown
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Returns ZooKeeper status dump
+    def zk_dump
+      @zk_wrapper.dump
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Creates a table
+    def create(table_name, *args)
+      # Fail if table name is not a string
+      raise(ArgumentError, "Table name must be of type String") unless table_name.kind_of?(String)
+
+      # Flatten params array
+      args = args.flatten.compact
+
+      # Fail if no column families defined
+      raise(ArgumentError, "Table must have at least one column family") if args.empty?
+
+      # Start defining the table
+      htd = HTableDescriptor.new(table_name)
+
+      # All args are columns, add them to the table definition
+      # TODO: add table options support
+      args.each do |arg|
+        unless arg.kind_of?(String) || arg.kind_of?(Hash)
+          raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash or String type")
+        end
+
+        # Add column to the table
+        htd.addFamily(hcd(arg))
+      end
+
+      # Perform the create table call
+      @admin.createTable(htd)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Closes a region
+    def close_region(region_name, server = nil)
+      @admin.closeRegion(region_name, server ? [server].to_java : nil)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Enables a region
+    def enable_region(region_name)
+      online(region_name, false)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Disables a region
+    def disable_region(region_name)
+      online(region_name, true)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Returns table's structure description
+    def describe(table_name)
+      tables = @admin.listTables.to_a
+      tables << HTableDescriptor::META_TABLEDESC
+      tables << HTableDescriptor::ROOT_TABLEDESC
+
+      tables.each do |t|
+        # Found the table
+        return t.to_s if t.getNameAsString == table_name
+      end
+
+      raise(ArgumentError, "Failed to find table named #{table_name}")
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Truncates table (deletes all records by recreating the table)
+    def truncate(table_name)
+      h_table = HTable.new(table_name)
+      table_description = h_table.getTableDescriptor()
+      yield 'Disabling table...' if block_given?
+      disable(table_name)
+
+      yield 'Dropping table...' if block_given?
+      drop(table_name)
+
+      yield 'Creating table...' if block_given?
+      @admin.createTable(table_description)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Change table structure or table options
+    def alter(table_name, *args)
+      # Table name should be a string
+      raise(ArgumentError, "Table name must be of type String") unless table_name.kind_of?(String)
+
+      # Table should exist
+      raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)
+
+      # Table should be disabled
+      raise(ArgumentError, "Table #{table_name} is enabled. Disable it first before altering.") if enabled?(table_name)
+
+      # There should be at least one argument
+      raise(ArgumentError, "There should be at least one argument but the table name") if args.empty?
+
+      # Get table descriptor
+      htd = @admin.getTableDescriptor(table_name.to_java_bytes)
+
+      # Process all args
+      args.each do |arg|
+        # Normalize args to support column name only alter specs
+        arg = { NAME => arg } if arg.kind_of?(String)
+
+        # Normalize args to support shortcut delete syntax
+        arg = { METHOD => 'delete', NAME => arg['delete'] } if arg['delete']
+
+        # No method parameter, try to use the args as a column definition
+        unless method = arg.delete(METHOD)
+          descriptor = hcd(arg)
+          column_name = descriptor.getNameAsString
+
+          # If column already exist, then try to alter it. Create otherwise.
+          if htd.hasFamily(column_name.to_java_bytes)
+            @admin.modifyColumn(table_name, column_name, descriptor)
+          else
+            @admin.addColumn(table_name, descriptor)
+          end
+          next
+        end
+
+        # Delete column family
+        if method == "delete"
+          raise(ArgumentError, "NAME parameter missing for delete method") unless arg[NAME]
+          @admin.deleteColumn(table_name, arg[NAME])
+          next
+        end
+
+        # Change table attributes
+        if method == "table_att"
+          htd.setMaxFileSize(JLong.valueOf(arg[MAX_FILESIZE])) if arg[MAX_FILESIZE]
+          htd.setReadOnly(JBoolean.valueOf(arg[READONLY])) if arg[READONLY]
+          htd.setMemStoreFlushSize(JLong.valueOf(arg[MEMSTORE_FLUSHSIZE])) if arg[MEMSTORE_FLUSHSIZE]
+          htd.setDeferredLogFlush(JBoolean.valueOf(arg[DEFERRED_LOG_FLUSH])) if arg[DEFERRED_LOG_FLUSH]
+          @admin.modifyTable(table_name.to_java_bytes, htd)
+          next
+        end
+
+        # Unknown method
+        raise ArgumentError, "Unknown method: #{method}"
+      end
+    end
+
+    def status(format)
+      status = @admin.getClusterStatus()
+      if format == "detailed"
+        puts("version %s" % [ status.getHBaseVersion() ])
+        # Put regions in transition first because usually empty
+        puts("%d regionsInTransition" % status.getRegionsInTransition().size())
+        for k, v in status.getRegionsInTransition()
+          puts("    %s" % [v])
+        end
+        puts("%d live servers" % [ status.getServers() ])
+        for server in status.getServerInfo()
+          puts("    %s:%d %d" % \
+            [ server.getServerAddress().getHostname(),  \
+              server.getServerAddress().getPort(), server.getStartCode() ])
+          puts("        %s" % [ server.getLoad().toString() ])
+          for region in server.getLoad().getRegionsLoad()
+            puts("        %s" % [ region.getNameAsString() ])
+            puts("            %s" % [ region.toString() ])
+          end
+        end
+        puts("%d dead servers" % [ status.getDeadServers() ])
+        for server in status.getDeadServerNames()
+          puts("    %s" % [ server ])
+        end
+      elsif format == "simple"
+        load = 0
+        regions = 0
+        puts("%d live servers" % [ status.getServers() ])
+        for server in status.getServerInfo()
+          puts("    %s:%d %d" % \
+            [ server.getServerAddress().getHostname(),  \
+              server.getServerAddress().getPort(), server.getStartCode() ])
+          puts("        %s" % [ server.getLoad().toString() ])
+          load += server.getLoad().getNumberOfRequests()
+          regions += server.getLoad().getNumberOfRegions()
+        end
+        puts("%d dead servers" % [ status.getDeadServers() ])
+        for server in status.getDeadServerNames()
+          puts("    %s" % [ server ])
+        end
+        puts("Aggregate load: %d, regions: %d" % [ load , regions ] )
+      else
+        puts "#{status.getServers} servers, #{status.getDeadServers} dead, #{'%.4f' % status.getAverageLoad} average load"
+      end
+    end
+
+    #----------------------------------------------------------------------------------------------
+    #
+    # Helper methods
+    #
+
+    # Does table exist?
+    def exists?(table_name)
+      @admin.tableExists(table_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Is table enabled
+    def enabled?(table_name)
+      @admin.isTableEnabled(table_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Return a new HColumnDescriptor made of passed args
+    def hcd(arg)
+      # String arg, single parameter constructor
+      return HColumnDescriptor.new(arg) if arg.kind_of?(String)
+
+      # TODO: This is brittle code.
+      # Here is current HCD constructor:
+      # public HColumnDescriptor(final byte [] familyName, final int maxVersions,
+      # final String compression, final boolean inMemory,
+      # final boolean blockCacheEnabled, final int blocksize,
+      # final int timeToLive, final boolean bloomFilter, final int scope) {
+      raise(ArgumentError, "Column family #{arg} must have a name") unless name = arg[NAME]
+
+      # TODO: What encoding are Strings in jruby?
+      return HColumnDescriptor.new(name.to_java_bytes,
+        # JRuby uses longs for ints. Need to convert.  Also constants are String
+        arg[VERSIONS]? JInteger.new(arg[VERSIONS]): HColumnDescriptor::DEFAULT_VERSIONS,
+        arg[HColumnDescriptor::COMPRESSION]? arg[HColumnDescriptor::COMPRESSION]: HColumnDescriptor::DEFAULT_COMPRESSION,
+        arg[IN_MEMORY]? JBoolean.valueOf(arg[IN_MEMORY]): HColumnDescriptor::DEFAULT_IN_MEMORY,
+        arg[HColumnDescriptor::BLOCKCACHE]? JBoolean.valueOf(arg[HColumnDescriptor::BLOCKCACHE]): HColumnDescriptor::DEFAULT_BLOCKCACHE,
+        arg[HColumnDescriptor::BLOCKSIZE]? JInteger.valueOf(arg[HColumnDescriptor::BLOCKSIZE]): HColumnDescriptor::DEFAULT_BLOCKSIZE,
+        arg[HColumnDescriptor::TTL]? JInteger.new(arg[HColumnDescriptor::TTL]): HColumnDescriptor::DEFAULT_TTL,
+        arg[HColumnDescriptor::BLOOMFILTER]? JBoolean.valueOf(arg[HColumnDescriptor::BLOOMFILTER]): HColumnDescriptor::DEFAULT_BLOOMFILTER,
+        arg[HColumnDescriptor::REPLICATION_SCOPE]? JInteger.new(arg[REPLICATION_SCOPE]): HColumnDescriptor::DEFAULT_REPLICATION_SCOPE)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Enables/disables a region by name
+    def online(region_name, on_off)
+      # Open meta table
+      meta = HTable.new(HConstants::META_TABLE_NAME)
+
+      # Read region info
+      # FIXME: fail gracefully if can't find the region
+      region_bytes = Bytes.toBytes(region_name)
+      g = Get.new(region_bytes)
+      g.addColumn(HConstants::CATALOG_FAMILY, HConstants::REGIONINFO_QUALIFIER)
+      hri_bytes = meta.get(g).value
+
+      # Change region status
+      hri = Writables.getWritable(hri_bytes, HRegionInfo.new)
+      hri.setOffline(on_off)
+
+      # Write it back
+      put = Put.new(region_bytes)
+      put.add(HConstants::CATALOG_FAMILY, HConstants::REGIONINFO_QUALIFIER, Writables.getBytes(hri))
+      meta.put(put)
+    end
+    #----------------------------------------------------------------------------------------------
+    # Invoke a ZooKeeper maintenance command
+    def zk(args)
+      line = args.join(' ')
+      line = 'help' if line.empty?
+      @zk_main.executeLine(line)
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/hbase/hbase.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/hbase/hbase.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/hbase/hbase.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/hbase/hbase.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,33 @@
+include Java
+
+import org.apache.hadoop.hbase.HBaseConfiguration
+
+require 'hbase/admin'
+require 'hbase/table'
+
+module Hbase
+  class Hbase
+    attr_accessor :configuration
+
+    def initialize(config = nil)
+      # Create configuration
+      if config
+        self.configuration = config
+      else
+        self.configuration = org.apache.hadoop.hbase.HBaseConfiguration.create
+        # Turn off retries in hbase and ipc.  Human doesn't want to wait on N retries.
+        configuration.setInt("hbase.client.retries.number", 7)
+        configuration.setInt("ipc.client.connect.max.retries", 3)
+      end
+    end
+
+    def admin(formatter)
+      ::Hbase::Admin.new(configuration, formatter)
+    end
+
+    # Create new one each time
+    def table(table, formatter)
+      ::Hbase::Table.new(configuration, table, formatter)
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/hbase/table.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/hbase/table.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/hbase/table.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/hbase/table.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,290 @@
+include Java
+
+java_import org.apache.hadoop.hbase.client.HTable
+
+java_import org.apache.hadoop.hbase.KeyValue
+java_import org.apache.hadoop.hbase.util.Bytes
+java_import org.apache.hadoop.hbase.util.Writables
+
+java_import org.apache.hadoop.hbase.client.Put
+java_import org.apache.hadoop.hbase.client.Get
+java_import org.apache.hadoop.hbase.client.Delete
+
+java_import org.apache.hadoop.hbase.client.Scan
+java_import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter
+
+# Wrapper for org.apache.hadoop.hbase.client.HTable
+
+module Hbase
+  class Table
+    include HBaseConstants
+
+    def initialize(configuration, table_name, formatter)
+      @table = HTable.new(configuration, table_name)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Put a cell 'value' at specified table/row/column
+    def put(row, column, value, timestamp = nil)
+      p = Put.new(row.to_s.to_java_bytes)
+      family, qualifier = parse_column_name(column)
+      if timestamp
+        p.add(family, qualifier, timestamp, value.to_s.to_java_bytes)
+      else
+        p.add(family, qualifier, value.to_s.to_java_bytes)
+      end
+      @table.put(p)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Delete a cell
+    def delete(row, column, timestamp = HConstants::LATEST_TIMESTAMP)
+      deleteall(row, column, timestamp)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Delete a row
+    def deleteall(row, column = nil, timestamp = HConstants::LATEST_TIMESTAMP)
+      d = Delete.new(row.to_s.to_java_bytes, timestamp, nil)
+      if column
+        family, qualifier = parse_column_name(column)
+        d.deleteColumns(family, qualifier, timestamp)
+      end
+      @table.delete(d)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Increment a counter atomically
+    def incr(row, column, value = nil)
+      value ||= 1
+      family, qualifier = parse_column_name(column)
+      @table.incrementColumnValue(row.to_s.to_java_bytes, family, qualifier, value)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Count rows in a table
+    def count(interval = 1000)
+      # We can safely set scanner caching with the first key only filter
+      scan = Scan.new
+      scan.cache_blocks = false
+      scan.caching = 10
+      scan.setFilter(FirstKeyOnlyFilter.new)
+
+      # Run the scanner
+      scanner = @table.getScanner(scan)
+      count = 0
+      iter = scanner.iterator
+
+      # Iterate results
+      while iter.hasNext
+        row = iter.next
+        count += 1
+        next unless (block_given? && count % interval == 0)
+        # Allow command modules to visualize counting process
+        yield(count, String.from_java_bytes(row.getRow))
+      end
+
+      # Return the counter
+      return count
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Get from table
+    def get(row, *args)
+      get = Get.new(row.to_s.to_java_bytes)
+      maxlength = -1
+
+      # Normalize args
+      args = args.first if args.first.kind_of?(Hash)
+      if args.kind_of?(String) || args.kind_of?(Array)
+        columns = [ args ].flatten.compact
+        args = { COLUMNS => columns }
+      end
+
+      #
+      # Parse arguments
+      #
+      unless args.kind_of?(Hash)
+        raise ArgumentError, "Failed parse of of #{args.inspect}, #{args.class}"
+      end
+
+      # Get maxlength parameter if passed
+      maxlength = args.delete(MAXLENGTH) if args[MAXLENGTH]
+
+      unless args.empty?
+        columns = args[COLUMN] || args[COLUMNS]
+        if columns
+          # Normalize types, convert string to an array of strings
+          columns = [ columns ] if columns.is_a?(String)
+
+          # At this point it is either an array or some unsupported stuff
+          unless columns.kind_of?(Array)
+            raise ArgumentError, "Failed parse column argument type #{args.inspect}, #{args.class}"
+          end
+
+          # Get each column name and add it to the filter
+          columns.each do |column|
+            family, qualifier = parse_column_name(column.to_s)
+            if qualifier
+              get.addColumn(family, qualifier)
+            else
+              get.addFamily(family)
+            end
+          end
+
+          # Additional params
+          get.setMaxVersions(args[VERSIONS] || 1)
+          get.setTimeStamp(args[TIMESTAMP]) if args[TIMESTAMP]
+        else
+          # May have passed TIMESTAMP and row only; wants all columns from ts.
+          unless ts = args[TIMESTAMP]
+            raise ArgumentError, "Failed parse of #{args.inspect}, #{args.class}"
+          end
+
+          # Set the timestamp
+          get.setTimeStamp(ts.to_i)
+        end
+      end
+
+      # Call hbase for the results
+      result = @table.get(get)
+      return nil if result.isEmpty
+
+      # Print out results.  Result can be Cell or RowResult.
+      res = {}
+      result.list.each do |kv|
+        family = String.from_java_bytes(kv.getFamily)
+        qualifier = Bytes::toStringBinary(kv.getQualifier)
+
+        column = "#{family}:#{qualifier}"
+        value = to_string(column, kv, maxlength)
+
+        if block_given?
+          yield(column, value)
+        else
+          res[column] = value
+        end
+      end
+
+      # If block given, we've yielded all the results, otherwise just return them
+      return ((block_given?) ? nil : res)
+    end
+
+    #----------------------------------------------------------------------------------------------
+    # Scans whole table or a range of keys and returns rows matching specific criterias
+    def scan(args = {})
+      unless args.kind_of?(Hash)
+        raise ArgumentError, "Arguments should be a hash. Failed to parse #{args.inspect}, #{args.class}"
+      end
+
+      limit = args.delete("LIMIT") || -1
+      maxlength = args.delete("MAXLENGTH") || -1
+
+      if args.any?
+        filter = args["FILTER"]
+        startrow = args["STARTROW"] || ''
+        stoprow = args["STOPROW"]
+        timestamp = args["TIMESTAMP"]
+        columns = args["COLUMNS"] || args["COLUMN"] || get_all_columns
+        cache = args["CACHE_BLOCKS"] || true
+        versions = args["VERSIONS"] || 1
+
+        # Normalize column names
+        columns = [columns] if columns.class == String
+        unless columns.kind_of?(Array)
+          raise ArgumentError.new("COLUMNS must be specified as a String or an Array")
+        end
+
+        scan = if stoprow
+          Scan.new(startrow.to_java_bytes, stoprow.to_java_bytes)
+        else
+          Scan.new(startrow.to_java_bytes)
+        end
+
+        columns.each { |c| scan.addColumns(c) }
+        scan.setFilter(filter) if filter
+        scan.setTimeStamp(timestamp) if timestamp
+        scan.setCacheBlocks(cache)
+        scan.setMaxVersions(versions) if versions > 1
+      else
+        scan = Scan.new
+      end
+
+      # Start the scanner
+      scanner = @table.getScanner(scan)
+      count = 0
+      res = {}
+      iter = scanner.iterator
+
+      # Iterate results
+      while iter.hasNext
+        if limit > 0 && count >= limit
+          break
+        end
+
+        row = iter.next
+        key = Bytes::toStringBinary(row.getRow)
+
+        row.list.each do |kv|
+          family = String.from_java_bytes(kv.getFamily)
+          qualifier = Bytes::toStringBinary(kv.getQualifier)
+
+          column = "#{family}:#{qualifier}"
+          cell = to_string(column, kv, maxlength)
+
+          if block_given?
+            yield(key, "column=#{column}, #{cell}")
+          else
+            res[key] ||= {}
+            res[key][column] = cell
+          end
+        end
+
+        # One more row processed
+        count += 1
+      end
+
+      return ((block_given?) ? count : res)
+    end
+
+    #----------------------------------------------------------------------------------------
+    # Helper methods
+
+    # Returns a list of column names in the table
+    def get_all_columns
+      @table.table_descriptor.getFamilies.map do |family|
+        "#{family.getNameAsString}:"
+      end
+    end
+
+    # Checks if current table is one of the 'meta' tables
+    def is_meta_table?
+      tn = @table.table_name
+      Bytes.equals(tn, HConstants::META_TABLE_NAME) || Bytes.equals(tn, HConstants::ROOT_TABLE_NAME)
+    end
+
+    # Returns family and (when has it) qualifier for a column name
+    def parse_column_name(column)
+      split = KeyValue.parseColumn(column.to_java_bytes)
+      return split[0], (split.length > 1) ? split[1] : nil
+    end
+
+    # Make a String of the passed kv
+    # Intercept cells whose format we know such as the info:regioninfo in .META.
+    def to_string(column, kv, maxlength = -1)
+      if is_meta_table?
+        if column == 'info:regioninfo'
+          hri = Writables.getHRegionInfoOrNull(kv.getValue)
+          return "timestamp=%d, value=%s" % [kv.getTimestamp, hri.toString]
+        end
+        if column == 'info:serverstartcode'
+          return "timestamp=%d, value=%s" % [kv.getTimestamp, Bytes.toLong(kv.getValue)]
+        end
+      end
+
+      val = "timestamp=#{kv.getTimestamp}, value=#{Bytes::toStringBinary(kv.getValue)}"
+      (maxlength != -1) ? val[0, maxlength] : val
+    end
+
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/irb/hirb.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/irb/hirb.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/irb/hirb.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/irb/hirb.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,32 @@
+module IRB
+  # Subclass of IRB so can intercept methods
+  class HIRB < Irb
+    def initialize
+      # This is ugly.  Our 'help' method above provokes the following message
+      # on irb construction: 'irb: warn: can't alias help from irb_help.'
+      # Below, we reset the output so its pointed at /dev/null during irb
+      # construction just so this message does not come out after we emit
+      # the banner.  Other attempts at playing with the hash of methods
+      # down in IRB didn't seem to work. I think the worst thing that can
+      # happen is the shell exiting because of failed IRB construction with
+      # no error (though we're not blanking STDERR)
+      begin
+        f = File.open("/dev/null", "w")
+        $stdout = f
+        super
+      ensure
+        f.close()
+        $stdout = STDOUT
+      end
+    end
+
+    def output_value
+      # Suppress output if last_value is 'nil'
+      # Otherwise, when user types help, get ugly 'nil'
+      # after all output.
+      if @context.last_value != nil
+        super
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,238 @@
+# Shell commands module
+module Shell
+  @@commands = {}
+  def self.commands
+    @@commands
+  end
+
+  @@command_groups = {}
+  def self.command_groups
+    @@command_groups
+  end
+
+  def self.load_command(name, group)
+    return if commands[name]
+
+    # Register command in the group
+    raise ArgumentError, "Unknown group: #{group}" unless command_groups[group]
+    command_groups[group][:commands] << name
+
+    # Load command
+    begin
+      require "shell/commands/#{name}"
+      klass_name = name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } # camelize
+      commands[name] = eval("Commands::#{klass_name}")
+    rescue => e
+      raise "Can't load hbase shell command: #{name}. Error: #{e}\n#{e.backtrace.join("\n")}"
+    end
+  end
+
+  def self.load_command_group(group, opts)
+    raise ArgumentError, "No :commands for group #{group}" unless opts[:commands]
+
+    command_groups[group] = {
+      :commands => [],
+      :command_names => opts[:commands],
+      :full_name => opts[:full_name] || group,
+      :comment => opts[:comment]
+    }
+
+    opts[:commands].each do |command|
+      load_command(command, group)
+    end
+  end
+
+  #----------------------------------------------------------------------
+  class Shell
+    attr_accessor :hbase
+    attr_accessor :formatter
+
+    def initialize(hbase, formatter)
+      self.hbase = hbase
+      self.formatter = formatter
+    end
+
+    def hbase_admin
+      @hbase_admin ||= hbase.admin(formatter)
+    end
+
+    def hbase_table(name)
+      hbase.table(name, formatter)
+    end
+
+    def export_commands(where)
+      ::Shell.commands.keys.each do |cmd|
+        where.send :instance_eval, <<-EOF
+          def #{cmd}(*args)
+            @shell.command('#{cmd}', *args)
+          end
+        EOF
+      end
+    end
+
+    def command_instance(command)
+      ::Shell.commands[command.to_s].new(self)
+    end
+
+    def command(command, *args)
+      command_instance(command).command_safe(*args)
+    end
+
+    def print_banner
+      puts "HBase Shell; enter 'help<RETURN>' for list of supported commands."
+      puts 'Type "exit<RETURN>" to leave the HBase Shell'
+      command('version')
+    end
+
+    def help_command(command)
+      puts "COMMAND: #{command}"
+      puts command_instance(command).help
+      puts
+      return nil
+    end
+
+    def help_group(group_name)
+      group = ::Shell.command_groups[group_name.to_s]
+      puts group[:full_name]
+      puts '-' * 80
+      group[:commands].sort.each { |cmd| help_command(cmd) }
+      if group[:comment]
+        puts '-' * 80
+        puts
+        puts group[:comment]
+        puts
+      end
+      return nil
+    end
+
+    def help(command = nil)
+      puts
+      if command
+        return help_command(command) if ::Shell.commands[command.to_s]
+        return help_group(command) if ::Shell.command_groups[command.to_s]
+        puts "ERROR: Invalid command or command group name: #{command}"
+        puts
+      end
+
+      puts help_header
+      puts
+      puts '-' * 80
+      puts
+      puts "Here is the list of groups with their commands:"
+      puts
+      ::Shell.command_groups.each do |name, group|
+        puts "  " + group[:full_name] + ": "
+        puts "    group name: " + name
+        puts "    commands: " + group[:command_names].sort.join(', ')
+        puts
+      end
+      puts
+      unless command
+        puts '-' * 80
+        puts
+        help_footer
+        puts
+      end
+      return nil
+    end
+
+    def help_header
+      return "There are few groups of commands in HBase\n\n" +
+             "Use help 'group_name' (e.g. help 'general') to get help on all commands in a group\n" +
+             "Use help 'command' (e.g. help 'get') to get help on a specific command"
+    end
+
+    def help_footer
+      puts "GENERAL NOTES:"
+      puts <<-HERE
+        Quote all names in the hbase shell such as table and column names.  Don't
+        forget commas delimit command parameters.  Type <RETURN> after entering a
+        command to run it.  Dictionaries of configuration used in the creation
+        and alteration of tables are ruby Hashes. They look like this:
+
+          {'key1' => 'value1', 'key2' => 'value2', ...}
+
+        They are opened and closed with curley-braces.  Key/values are delimited
+        by the '=>' character combination.  Usually keys are predefined constants
+        such as NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be
+        quoted.  Type 'Object.constants' to see a (messy) list of all constants
+        in the environment.
+
+        In case you are using binary keys or values and need to enter them into
+        the shell then use double-quotes to make use of hexadecimal for example:
+
+          hbase> get 't1', "key\\x03\\x3f\\xcd"
+          hbase> get 't1', "key\\003\\023\\011"
+          hbase> put 't1', "test\\xef\\xff", 'f1:', "\\x01\\x33\\x40"
+
+        Using the double-quote notation you can directly use the values output by
+        the shell for example during a "scan" call.
+
+        This HBase shell is the JRuby IRB with the above HBase-specific commands
+        added.  For more on the HBase Shell, see http://wiki.apache.org/hadoop/Hbase/Shell
+      HERE
+    end
+  end
+end
+
+# Load commands base class
+require 'shell/commands'
+
+# Load all commands
+Shell.load_command_group(
+  'general',
+  :full_name => 'GENERAL HBASE SHELL COMMANDS',
+  :commands => %w[
+    status
+    version
+  ]
+)
+
+Shell.load_command_group(
+  'ddl',
+  :full_name => 'TABLES MANAGEMENT COMMANDS',
+  :commands => %w[
+    alter
+    create
+    describe
+    disable
+    drop
+    enable
+    exists
+    list
+  ]
+)
+
+Shell.load_command_group(
+  'dml',
+  :full_name => 'DATA MANIPULATION COMMANDS',
+  :commands => %w[
+    count
+    delete
+    deleteall
+    get
+    incr
+    put
+    scan
+    truncate
+  ]
+)
+
+Shell.load_command_group(
+  'tools',
+  :full_name => 'HBASE SURGERY TOOLS',
+  :comment => "WARNING: Above commands are for 'experts'-only as misuse can damage an install",
+  :commands => %w[
+    close_region
+    compact
+    disable_region
+    enable_region
+    flush
+    major_compact
+    shutdown
+    split
+    zk
+    zk_dump
+  ]
+)
+

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,45 @@
+module Shell
+  module Commands
+    class Command
+      attr_accessor :shell
+
+      def initialize(shell)
+        self.shell = shell
+      end
+
+      def command_safe(*args)
+        command(*args)
+      rescue ArgumentError => e
+        puts
+        puts "ERROR: #{e}"
+        puts
+        puts "Here is some help for this command:"
+        puts help
+        puts
+      ensure
+        return nil
+      end
+
+      def admin
+        shell.hbase_admin
+      end
+
+      def table(name)
+        shell.hbase_table(name)
+      end
+
+      #----------------------------------------------------------------------
+
+      def formatter
+        shell.formatter
+      end
+
+      def format_simple_command
+        now = Time.now
+        yield
+        formatter.header
+        formatter.footer(now)
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/alter.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/alter.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/alter.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/alter.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,38 @@
+module Shell
+  module Commands
+    class Alter < Command
+      def help
+        return <<-EOF
+          Alter column family schema;  pass table name and a dictionary
+          specifying new column family schema. Dictionaries are described
+          on the main help command output. Dictionary must include name
+          of column family to alter. For example,
+
+          To change or add the 'f1' column family in table 't1' from defaults
+          to instead keep a maximum of 5 cell VERSIONS, do:
+          hbase> alter 't1', NAME => 'f1', VERSIONS => 5
+
+          To delete the 'f1' column family in table 't1', do:
+          hbase> alter 't1', NAME => 'f1', METHOD => 'delete'
+          or a shorter version:
+          hbase> alter 't1', 'delete' => 'f1'
+
+          You can also change table-scope attributes like MAX_FILESIZE
+          MEMSTORE_FLUSHSIZE, READONLY, and DEFERRED_LOG_FLUSH.
+
+          For example, to change the max size of a family to 128MB, do:
+          hbase> alter 't1', METHOD => 'table_att', MAX_FILESIZE => '134217728'
+
+          There could be more than one alteration in one command:
+          hbase> alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
+        EOF
+      end
+
+      def command(table, *args)
+        format_simple_command do
+          admin.alter(table, *args)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/close_region.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/close_region.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/close_region.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/close_region.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,20 @@
+module Shell
+  module Commands
+    class CloseRegion < Command
+      def help
+        return <<-EOF
+          Close a single region. Optionally specify regionserver.
+          Examples:
+            hbase> close_region 'REGIONNAME'
+            hbase> close_region 'REGIONNAME', 'REGIONSERVER_IP:PORT'
+        EOF
+      end
+
+      def command(region_name, server = nil)
+        format_simple_command do
+          admin.close_region(region_name, server)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/compact.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/compact.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/compact.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/compact.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,18 @@
+module Shell
+  module Commands
+    class Compact < Command
+      def help
+        return <<-EOF
+          Compact all regions in passed table or pass a region row
+          to compact an individual region
+        EOF
+      end
+
+      def command(table_or_region_name)
+        format_simple_command do
+          admin.compact(table_or_region_name)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/count.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/count.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/count.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/count.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,26 @@
+module Shell
+  module Commands
+    class Count < Command
+      def help
+        return <<-EOF
+          Count the number of rows in a table. This operation may take a LONG
+          time (Run '$HADOOP_HOME/bin/hadoop jar hbase.jar rowcount' to run a
+          counting mapreduce job). Current count is shown every 1000 rows by
+          default. Count interval may be optionally specified. Examples:
+
+          hbase> count 't1'
+          hbase> count 't1', 100000
+        EOF
+      end
+
+      def command(table, interval = 1000)
+        now = Time.now
+        formatter.header
+        count = table(table).count(interval) do |cnt, row|
+          formatter.row([ "Current count: #{cnt}, row: #{row}" ])
+        end
+        formatter.footer(now, count)
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/create.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/create.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/create.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/create.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,27 @@
+module Shell
+  module Commands
+    class Create < Command
+      def help
+        return <<-EOF
+          Create table; pass table name, a dictionary of specifications per
+          column family, and optionally a dictionary of table configuration.
+          Dictionaries are described below in the GENERAL NOTES section.
+          Examples:
+
+          hbase> create 't1', {NAME => 'f1', VERSIONS => 5}
+          hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
+          hbase> # The above in shorthand would be the following:
+          hbase> create 't1', 'f1', 'f2', 'f3'
+          hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000,
+                 BLOCKCACHE => true}
+        EOF
+      end
+
+      def command(table, *args)
+        format_simple_command do
+          admin.create(table, *args)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/delete.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/delete.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/delete.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/delete.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,23 @@
+module Shell
+  module Commands
+    class Delete < Command
+      def help
+        return <<-EOF
+          Put a delete cell value at specified table/row/column and optionally
+          timestamp coordinates.  Deletes must match the deleted cell's
+          coordinates exactly.  When scanning, a delete cell suppresses older
+          versions. To delete a cell from  't1' at row 'r1' under column 'c1'
+          marked with the time 'ts1', do:
+
+            hbase> delete 't1', 'r1', 'c1', ts1
+        EOF
+      end
+
+      def command(table, row, column, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
+        format_simple_command do
+          table(table).delete(row, column, timestamp)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/deleteall.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/deleteall.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/deleteall.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/deleteall.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,22 @@
+module Shell
+  module Commands
+    class Deleteall < Command
+      def help
+        return <<-EOF
+          Delete all cells in a given row; pass a table name, row, and optionally
+          a column and timestamp. Examples:
+
+            hbase> deleteall 't1', 'r1'
+            hbase> deleteall 't1', 'r1', 'c1'
+            hbase> deleteall 't1', 'r1', 'c1', ts1
+        EOF
+      end
+
+      def command(table, row, column = nil, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
+        format_simple_command do
+          table(table).deleteall(row, column, timestamp)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/describe.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/describe.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/describe.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/describe.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,22 @@
+module Shell
+  module Commands
+    class Describe < Command
+      def help
+        return <<-EOF
+          Describe the named table. For example:
+            hbase> describe 't1'
+        EOF
+      end
+
+      def command(table)
+        now = Time.now
+
+        desc = admin.describe(table)
+
+        formatter.header([ "DESCRIPTION", "ENABLED" ], [ 64 ])
+        formatter.row([ desc, admin.enabled?(table).to_s ], true, [ 64 ])
+        formatter.footer(now)
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,17 @@
+module Shell
+  module Commands
+    class Disable < Command
+      def help
+        return <<-EOF
+          Disable the named table: e.g. "hbase> disable 't1'"
+        EOF
+      end
+
+      def command(table)
+        format_simple_command do
+          admin.disable(table)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable_region.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable_region.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable_region.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/disable_region.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,19 @@
+module Shell
+  module Commands
+    class DisableRegion < Command
+      def help
+        return <<-EOF
+          Disable a single region. For example:
+
+            hbase> disable_region 'REGIONNAME'
+        EOF
+      end
+
+      def command(region_name)
+        format_simple_command do
+          admin.disable_region(region_name)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/drop.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/drop.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/drop.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/drop.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,20 @@
+module Shell
+  module Commands
+    class Drop < Command
+      def help
+        return <<-EOF
+          Drop the named table. Table must first be disabled. If table has
+          more than one region, run a major compaction on .META.:
+
+          hbase> major_compact ".META."
+        EOF
+      end
+
+      def command(table)
+        format_simple_command do
+          admin.drop(table)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,17 @@
+module Shell
+  module Commands
+    class Enable < Command
+      def help
+        return <<-EOF
+          Enable the named table: e.g. "hbase> enable 't1'"
+        EOF
+      end
+
+      def command(table)
+        format_simple_command do
+          admin.enable(table)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable_region.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable_region.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable_region.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/enable_region.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,19 @@
+module Shell
+  module Commands
+    class EnableRegion < Command
+      def help
+        return <<-EOF
+          Enable a single region. For example:
+
+            hbase> enable_region 'REGIONNAME'
+        EOF
+      end
+
+      def command(region_name)
+        format_simple_command do
+          admin.enable_region(region_name)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/exists.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/exists.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/exists.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/exists.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,19 @@
+module Shell
+  module Commands
+    class Exists < Command
+      def help
+        return <<-EOF
+          Does the named table exist? e.g. "hbase> exists 't1'"
+        EOF
+      end
+
+      def command(table)
+        format_simple_command do
+          formatter.row([
+            "Table #{table} " + (admin.exists?(table.to_s) ? "does exist" : "does not exist")
+          ])
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/flush.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/flush.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/flush.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/flush.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,21 @@
+module Shell
+  module Commands
+    class Flush < Command
+      def help
+        return <<-EOF
+          Flush all regions in passed table or pass a region row to
+          flush an individual region.  For example:
+
+            hbase> flush 'TABLENAME'
+            hbase> flush 'REGIONNAME'
+        EOF
+      end
+
+      def command(table_or_region_name)
+        format_simple_command do
+          admin.flush(table_or_region_name)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/get.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/get.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/get.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/get.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,32 @@
+module Shell
+  module Commands
+    class Get < Command
+      def help
+        return <<-EOF
+          Get row or cell contents; pass table name, row, and optionally
+          a dictionary of column(s), timestamp and versions. Examples:
+
+            hbase> get 't1', 'r1'
+            hbase> get 't1', 'r1', {COLUMN => 'c1'}
+            hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}
+            hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
+            hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
+            hbase> get 't1', 'r1', 'c1'
+            hbase> get 't1', 'r1', 'c1', 'c2'
+            hbase> get 't1', 'r1', ['c1', 'c2']
+        EOF
+      end
+
+      def command(table, row, *args)
+        now = Time.now
+        formatter.header(["COLUMN", "CELL"])
+
+        table(table).get(row, *args) do |column, value|
+          formatter.row([ column, value ])
+        end
+
+        formatter.footer(now)
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/incr.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/incr.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/incr.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/incr.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,23 @@
+module Shell
+  module Commands
+    class Incr < Command
+      def help
+        return <<-EOF
+          Increments a cell 'value' at specified table/row/column coordinates.
+          To increment a cell value in table 't1' at row 'r1' under column
+          'c1' by 1 (can be omitted) or 10 do:
+
+            hbase> incr 't1', 'r1', 'c1'
+            hbase> incr 't1', 'r1', 'c1', 1
+            hbase> incr 't1', 'r1', 'c1', 10
+        EOF
+      end
+
+      def command(table, row, column, value = nil)
+        format_simple_command do
+          table(table).incr(row, column, value)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/list.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/list.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/list.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/list.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,17 @@
+module Shell
+  module Commands
+    class List < Command
+      def help
+        return <<-EOF
+          List all tables in hbase
+        EOF
+      end
+
+      def command
+        format_simple_command do
+          admin.list
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/major_compact.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/major_compact.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/major_compact.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/major_compact.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,18 @@
+module Shell
+  module Commands
+    class MajorCompact < Command
+      def help
+        return <<-EOF
+          Run major compaction on passed table or pass a region row
+          to major compact an individual region
+        EOF
+      end
+
+      def command(table_or_region_name)
+        format_simple_command do
+          admin.major_compact(table_or_region_name)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/put.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/put.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/put.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/put.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,21 @@
+module Shell
+  module Commands
+    class Put < Command
+      def help
+        return <<-EOF
+          Put a cell 'value' at specified table/row/column and optionally
+          timestamp coordinates.  To put a cell value into table 't1' at
+          row 'r1' under column 'c1' marked with the time 'ts1', do:
+
+            hbase> put 't1', 'r1', 'c1', 'value', ts1
+        EOF
+      end
+
+      def command(table, row, column, value, timestamp = nil)
+        format_simple_command do
+          table(table).put(row, column, value, timestamp)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/scan.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/scan.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/scan.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/scan.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,37 @@
+module Shell
+  module Commands
+    class Scan < Command
+      def help
+        return <<-EOF
+          Scan a table; pass table name and optionally a dictionary of scanner
+          specifications.  Scanner specifications may include one or more of
+          the following: LIMIT, STARTROW, STOPROW, TIMESTAMP, or COLUMNS.  If
+          no columns are specified, all columns will be scanned.  To scan all
+          members of a column family, leave the qualifier empty as in
+          'col_family:'.  Examples:
+
+            hbase> scan '.META.'
+            hbase> scan '.META.', {COLUMNS => 'info:regioninfo'}
+            hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
+
+          For experts, there is an additional option -- CACHE_BLOCKS -- which
+          switches block caching for the scanner on (true) or off (false).  By
+          default it is enabled.  Examples:
+
+            hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}
+        EOF
+      end
+
+      def command(table, args = {})
+        now = Time.now
+        formatter.header(["ROW", "COLUMN+CELL"])
+
+        count = table(table).scan(args) do |row, cells|
+          formatter.row([ row, cells ])
+        end
+
+        formatter.footer(now, count)
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/shutdown.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/shutdown.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/shutdown.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/shutdown.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,15 @@
+module Shell
+  module Commands
+    class Shutdown < Command
+      def help
+        return <<-EOF
+          Shut down the cluster.
+        EOF
+      end
+
+      def command
+        admin.shutdown
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/split.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/split.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/split.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/split.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,17 @@
+module Shell
+  module Commands
+    class Split < Command
+      def help
+        return <<-EOF
+          Split table or pass a region row to split individual region
+        EOF
+      end
+
+      def command(table_or_region_name)
+        format_simple_command do
+          admin.split(table_or_region_name)
+        end
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/status.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/status.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/status.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/status.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,21 @@
+module Shell
+  module Commands
+    class Status < Command
+      def help
+        return <<-EOF
+          Show cluster status. Can be 'summary', 'simple', or 'detailed'. The
+          default is 'summary'. Examples:
+
+            hbase> status
+            hbase> status 'simple'
+            hbase> status 'summary'
+            hbase> status 'detailed'
+        EOF
+      end
+
+      def command(format = 'summary')
+        admin.status(format)
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/truncate.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/truncate.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/truncate.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/truncate.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,19 @@
+module Shell
+  module Commands
+    class Truncate < Command
+      def help
+        return <<-EOF
+          Disables, drops and recreates the specified table.
+        EOF
+      end
+
+      def command(table)
+        format_simple_command do
+          puts "Truncating '#{table}' table (it may take a while):"
+          admin.truncate(table) { |log| puts " - #{log}" }
+        end
+      end
+
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/version.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/version.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/version.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/version.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,18 @@
+module Shell
+  module Commands
+    class Version < Command
+      def help
+        return <<-EOF
+          Output this HBase version
+        EOF
+      end
+
+      def command
+        # Output version.
+        puts "Version: #{org.apache.hadoop.hbase.util.VersionInfo.getVersion()}, " +
+             "r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision()}, " +
+             "#{org.apache.hadoop.hbase.util.VersionInfo.getDate()}"
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,16 @@
+module Shell
+  module Commands
+    class Zk < Command
+      def help
+        return <<-EOF
+          Low level ZooKeeper surgery tools. Type "zk 'help'" for more
+          information (Yes, you must quote 'help').
+        EOF
+      end
+
+      def command(*args)
+        admin.zk(args)
+      end
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk_dump.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk_dump.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk_dump.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/commands/zk_dump.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,15 @@
+module Shell
+  module Commands
+    class ZkDump < Command
+      def help
+        return <<-EOF
+          Dump status of HBase cluster as seen by ZooKeeper.
+        EOF
+      end
+
+      def command
+        puts admin.zk_dump
+      end
+    end
+  end
+end



Mime
View raw message