From d9174359e607c2d0c65ffe04780ccd3b9e303ab9 Mon Sep 17 00:00:00 2001 From: Karan Mehta Date: Wed, 8 Mar 2017 15:15:43 -0800 Subject: [PATCH] HBASE-14925 Develop HBase shell command/tool to list table's region info through command line --- hbase-shell/src/main/ruby/shell.rb | 1 + .../src/main/ruby/shell/commands/list_regions.rb | 60 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 hbase-shell/src/main/ruby/shell/commands/list_regions.rb diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index b112b21..8b9ce9a 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -285,6 +285,7 @@ Shell.load_command_group( alter_async get_table locate_region + list_regions ], :aliases => { 'describe' => ['desc'] diff --git a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb new file mode 100644 index 0000000..836e7d7 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb @@ -0,0 +1,60 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module Shell + module Commands + class ListRegions < Command + def help + + return< list_regions 'table_name' + +EOF + return + end + + def command(tgtTable) + admin_instance = admin.instance_variable_get("@admin") + cluster_status = admin_instance.getClusterStatus(); + results = Array.new + for server_name in cluster_status.getServers() + for name, region in cluster_status.getLoad(server_name).getRegionsLoad() + region_name = region.getNameAsString() + regionStoreFileSize = region.getStorefileSizeMB() + regionRequests = region.getRequestsCount() + if region_name.start_with? tgtTable + results << { "server" => server_name, "name" => region_name, "size" => regionStoreFileSize, "requests" => regionRequests } + end + end + end + + formatter.header(["SERVER_NAME", "REGION_NAME", "SIZE", "REQUESTS"]) + for result in results + formatter.row([ result["server"], result["name"], result["size"], result["requests"]]) + end + formatter.footer(results.size) + @end_time = Time.now + + end + end + end +end -- 2.10.1 (Apple Git-78)