From 91756d7f796311269154110ca6967eea32d7bab0 Mon Sep 17 00:00:00 2001 From: Enis Soztutar Date: Fri, 11 May 2018 14:32:13 +0200 Subject: [PATCH] HBASE-16191 Add stop_regionserver and stop_master to shell Amending-Author: Peter Somogyi --- hbase-shell/src/main/ruby/.rubocop.yml | 5 +++ hbase-shell/src/main/ruby/hbase/admin.rb | 10 +++++ hbase-shell/src/main/ruby/shell.rb | 2 + .../main/ruby/shell/commands/stop_master.rb | 38 ++++++++++++++++++ .../ruby/shell/commands/stop_regionserver.rb | 40 +++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 hbase-shell/src/main/ruby/.rubocop.yml create mode 100644 hbase-shell/src/main/ruby/shell/commands/stop_master.rb create mode 100644 hbase-shell/src/main/ruby/shell/commands/stop_regionserver.rb diff --git a/hbase-shell/src/main/ruby/.rubocop.yml b/hbase-shell/src/main/ruby/.rubocop.yml new file mode 100644 index 00000000000..7b041387170 --- /dev/null +++ b/hbase-shell/src/main/ruby/.rubocop.yml @@ -0,0 +1,5 @@ +Naming/HeredocDelimiterNaming: + Enabled: false + +Layout/IndentHeredoc: + Enabled: false \ No newline at end of file diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index cb57c4cf97c..c385d3dabf6 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -1309,6 +1309,16 @@ module Hbase TableName.valueOf(new_table_name), preserve_splits) end + + # Stop the active Master + def stop_master + @admin.stopMaster + end + + # Stop the given RegionServer + def stop_regionserver(hostport) + @admin.stopRegionServer(hostport) + end end # rubocop:enable Metrics/ClassLength end diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index ab07a79b985..9a796587b6b 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -357,6 +357,8 @@ Shell.load_command_group( list_deadservers clear_deadservers clear_block_cache + stop_master + stop_regionserver ], # TODO: remove older hlog_roll command aliases: { diff --git a/hbase-shell/src/main/ruby/shell/commands/stop_master.rb b/hbase-shell/src/main/ruby/shell/commands/stop_master.rb new file mode 100644 index 00000000000..45a2b1121a6 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/stop_master.rb @@ -0,0 +1,38 @@ +# +# +# 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 + # Stop active Master + class StopMaster < Command + def help + <<-EOF +Stop active Master. For experts only. +Examples: + + hbase> stop_master +EOF + end + + def command + admin.stop_master + end + end + end +end diff --git a/hbase-shell/src/main/ruby/shell/commands/stop_regionserver.rb b/hbase-shell/src/main/ruby/shell/commands/stop_regionserver.rb new file mode 100644 index 00000000000..127088d4365 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/stop_regionserver.rb @@ -0,0 +1,40 @@ +# +# +# 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 + # Stop a RegionServer + class StopRegionserver < Command + def help + <<-EOF +Stop a RegionServer. For experts only. +Consider using graceful_stop.sh script instead! + +Examples: + + hbase> stop_regionserver 'hostname:port' +EOF + end + + def command(hostport) + admin.stop_regionserver(hostport) + end + end + end +end