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="/logLevel">Log Level</a></li>
<li><a href="/dump">Debug dump</a></li>
<li><a href="/jmx">Metrics Dump</a></li>
<%if HBaseConfiguration.isShowConfInServlet()%>
<li><a href="/conf">HBase Configuration</a></li>
</%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="/logLevel">Log Level</a></li>
<li><a href="/dump">Debug dump</a></li>
<li><a href="/jmx">Metrics Dump</a></li>
<%if HBaseConfiguration.isShowConfInServlet()%>
<li><a href="/conf">HBase Configuration</a></li>
</%if>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -146,39 +146,25 @@ module Shell
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)
timeSpent = calculateRunTime(start_time)
unless(row_count.is_a?(Integer))
row_count = nil
end
return unless start_time
row_count ||= @row_count
# 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
#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 AdminFormatter < Base
def footer(start_time = nil, msg = "")
timeSpent = calculateRunTime(start_time)
if(msg.is_a?(Integer))
msg = msg, " rows"
end
@out.puts("Succeeded in %.4f seconds.\n%s" % [timeSpent, msg])
end
class Console < Base
end
class XHTMLFormatter < Base
# http://www.germane-software.com/software/rexml/doc/classes/REXML/Document.html
# http://www.crummy.com/writing/RubyCookbook/test_results/75942.html
end
class JSON < Base
end
end
end