HBASE-6025 Expose Hadoop Dynamic Metrics through JSON Rest interface; REVERT -- OVERCOMMIT

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1390239 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-09-26 00:34:18 +00:00
parent 9a69eb3fc9
commit 3e30f1ecbf
11 changed files with 37 additions and 73 deletions

View File

@ -81,7 +81,6 @@ org.apache.hadoop.hbase.HBaseConfiguration;
<li><a href="/logs/">Local logs</a></li> <li><a href="/logs/">Local logs</a></li>
<li><a href="/logLevel">Log Level</a></li> <li><a href="/logLevel">Log Level</a></li>
<li><a href="/dump">Debug dump</a></li> <li><a href="/dump">Debug dump</a></li>
<li><a href="/jmx">Metrics Dump</a></li>
<%if HBaseConfiguration.isShowConfInServlet()%> <%if HBaseConfiguration.isShowConfInServlet()%>
<li><a href="/conf">HBase Configuration</a></li> <li><a href="/conf">HBase Configuration</a></li>
</%if> </%if>

View File

@ -77,7 +77,6 @@ org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionLoad;
<li><a href="/logs/">Local logs</a></li> <li><a href="/logs/">Local logs</a></li>
<li><a href="/logLevel">Log Level</a></li> <li><a href="/logLevel">Log Level</a></li>
<li><a href="/dump">Debug dump</a></li> <li><a href="/dump">Debug dump</a></li>
<li><a href="/jmx">Metrics Dump</a></li>
<%if HBaseConfiguration.isShowConfInServlet()%> <%if HBaseConfiguration.isShowConfInServlet()%>
<li><a href="/conf">HBase Configuration</a></li> <li><a href="/conf">HBase Configuration</a></li>
</%if> </%if>

View File

@ -97,7 +97,6 @@
<li><a href="/logs/">Local logs</a></li> <li><a href="/logs/">Local logs</a></li>
<li><a href="/logLevel">Log Level</a></li> <li><a href="/logLevel">Log Level</a></li>
<li><a href="/dump">Debug dump</a></li> <li><a href="/dump">Debug dump</a></li>
<li><a href="/jmx">Metrics Dump</a></li>
</ul> </ul>
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
</div> </div>

View File

@ -63,7 +63,6 @@
<li><a href="/logs/">Local logs</a></li> <li><a href="/logs/">Local logs</a></li>
<li><a href="/logLevel">Log Level</a></li> <li><a href="/logLevel">Log Level</a></li>
<li><a href="/dump">Debug dump</a></li> <li><a href="/dump">Debug dump</a></li>
<li><a href="/jmx">Metrics Dump</a></li>
</ul> </ul>
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
</div> </div>

View File

@ -68,7 +68,6 @@
<li><a href="/logs/">Local logs</a></li> <li><a href="/logs/">Local logs</a></li>
<li><a href="/logLevel">Log Level</a></li> <li><a href="/logLevel">Log Level</a></li>
<li><a href="/dump">Debug dump</a></li> <li><a href="/dump">Debug dump</a></li>
<li><a href="/jmx">Metrics Dump</a></li>
</ul> </ul>
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
</div> </div>

View File

@ -26,13 +26,14 @@ module Hbase
class Admin class Admin
include HBaseConstants include HBaseConstants
def initialize(configuration) def initialize(configuration, formatter)
@admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration) @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration)
connection = @admin.getConnection() connection = @admin.getConnection()
@conf = configuration @conf = configuration
@zk_wrapper = connection.getZooKeeperWatcher() @zk_wrapper = connection.getZooKeeperWatcher()
zk = @zk_wrapper.getRecoverableZooKeeper().getZooKeeper() zk = @zk_wrapper.getRecoverableZooKeeper().getZooKeeper()
@zk_main = org.apache.zookeeper.ZooKeeperMain.new(zk) @zk_main = org.apache.zookeeper.ZooKeeperMain.new(zk)
@formatter = formatter
end end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------

View File

@ -39,8 +39,8 @@ module Hbase
end end
end end
def admin def admin(formatter)
::Hbase::Admin.new(configuration) ::Hbase::Admin.new(configuration, formatter)
end end
# Create new one each time # Create new one each time

View File

@ -129,8 +129,6 @@ EOF
p.add(family, qualifier, value.to_s.to_java_bytes) p.add(family, qualifier, value.to_s.to_java_bytes)
end end
@table.put(p) @table.put(p)
#return number of rows added/updated.
return p.size()
end end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
@ -148,8 +146,6 @@ EOF
d.deleteColumns(family, qualifier, timestamp) d.deleteColumns(family, qualifier, timestamp)
end end
@table.delete(d) @table.delete(d)
#return number of rows deleted.
return d.size()
end end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------

View File

@ -19,9 +19,7 @@
# Shell commands module # Shell commands module
module Shell module Shell
require 'shell/formatter'
@@commands = {} @@commands = {}
@@formatters={}
def self.commands def self.commands
@@commands @@commands
end end
@ -31,17 +29,7 @@ module Shell
@@command_groups @@command_groups
end end
def self.getFormatter (type = :RowFormatter) def self.load_command(name, group)
type ||= :RowFormatter
format = @@formatters[type]
unless format
@@formatters[type] = eval("::Shell::Formatter::#{type}").new
return getFormatter type
end
return format
end
def self.load_command(name, group,formatter)
return if commands[name] return if commands[name]
# Register command in the group # Register command in the group
@ -52,7 +40,7 @@ module Shell
begin begin
require "shell/commands/#{name}" require "shell/commands/#{name}"
klass_name = name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } # camelize klass_name = name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } # camelize
commands[name] = {:command => eval("Commands::#{klass_name}"), :formatter => formatter} commands[name] = eval("Commands::#{klass_name}")
rescue => e rescue => e
raise "Can't load hbase shell command: #{name}. Error: #{e}\n#{e.backtrace.join("\n")}" raise "Can't load hbase shell command: #{name}. Error: #{e}\n#{e.backtrace.join("\n")}"
end end
@ -68,11 +56,8 @@ module Shell
:comment => opts[:comment] :comment => opts[:comment]
} }
formatterType = opts[:formatterType]
formatter = getFormatter formatterType
opts[:commands].each do |command| opts[:commands].each do |command|
load_command(command, group, formatter) load_command(command, group)
end end
end end
@ -84,12 +69,13 @@ module Shell
@debug = false @debug = false
attr_accessor :debug attr_accessor :debug
def initialize(hbase) def initialize(hbase, formatter)
self.hbase = hbase self.hbase = hbase
self.formatter = formatter
end end
def hbase_admin def hbase_admin
@hbase_admin ||= hbase.admin @hbase_admin ||= hbase.admin(formatter)
end end
def hbase_table(name) def hbase_table(name)
@ -121,8 +107,7 @@ module Shell
end end
def command_instance(command) def command_instance(command)
commandObj = ::Shell.commands[command.to_s] ::Shell.commands[command.to_s].new(self)
commandObj[:command].new(self, commandObj[:formatter])
end end
#call the method 'command' on the specified command #call the method 'command' on the specified command
@ -265,8 +250,7 @@ Shell.load_command_group(
alter_status alter_status
alter_async alter_async
get_table get_table
], ]
:formatterType => 'AdminFormatter'
) )
Shell.load_command_group( Shell.load_command_group(
@ -282,8 +266,7 @@ Shell.load_command_group(
put put
scan scan
truncate truncate
], ]
:formatterType => 'RowFormatter'
) )
Shell.load_command_group( Shell.load_command_group(

View File

@ -20,10 +20,9 @@
module Shell module Shell
module Commands module Commands
class Command class Command
attr_reader :formatter
def initialize(shell, formatter) def initialize(shell)
@shell = shell @shell = shell
@formatter = formatter
end end
#wrap an execution of cmd to catch hbase exceptions #wrap an execution of cmd to catch hbase exceptions
@ -61,18 +60,22 @@ module Shell
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def formatter
@shell.formatter
end
def format_simple_command def format_simple_command
now = Time.now now = Time.now
ret = yield yield
@formatter.header formatter.header
@formatter.footer(now, ret) formatter.footer(now)
end end
def format_and_return_simple_command def format_and_return_simple_command
now = Time.now now = Time.now
ret = yield ret = yield
@formatter.header formatter.header
@formatter.footer(now, ret) formatter.footer(now)
return ret return ret
end end

View File

@ -146,39 +146,25 @@ module Shell
end end
end end
def calculateRunTime(start_time = nil)
return unless start_time
return (Time.now - start_time)
end
end
#RowFormatter formats the return response with number of rows altered.
#Use this for operations (command groups) for which row count makes sense, eg: delete, add etc.
#Formatter is now defined at command group level.
class RowFormatter < Base
def footer(start_time = nil, row_count = nil) def footer(start_time = nil, row_count = nil)
timeSpent = calculateRunTime(start_time) return unless start_time
unless(row_count.is_a?(Integer))
row_count = nil
end
row_count ||= @row_count row_count ||= @row_count
# Only output elapsed time and row count if startTime passed # Only output elapsed time and row count if startTime passed
@out.puts("%d row(s) in %.4f seconds" % [row_count, timeSpent]) @out.puts("%d row(s) in %.4f seconds" % [row_count, Time.now - start_time])
end end
end end
#AdminFormatter is used for all non row specific operations (command groups) such as version, status etc.
#Formatter is now defined at command group level. class Console < Base
class AdminFormatter < Base end
def footer(start_time = nil, msg = "")
timeSpent = calculateRunTime(start_time) class XHTMLFormatter < Base
if(msg.is_a?(Integer)) # http://www.germane-software.com/software/rexml/doc/classes/REXML/Document.html
msg = msg, " rows" # http://www.crummy.com/writing/RubyCookbook/test_results/75942.html
end end
@out.puts("Succeeded in %.4f seconds.\n%s" % [timeSpent, msg])
end class JSON < Base
end end
end end
end end