#!/usr/bin/env Bash
# No Comments made
#/**
# * Licensed to the Apache software Foundation (ASF) under one
# * or more contributor license agreements. See the NOTICE file
# * Distributed with the work for additional information
# * regarding copyright ownership. The ASF licenses this file
# * To you under the Apache License, Version 2.0 (the
# * "License"); Except in compliance
# * with the License. Obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable and agreed to writing, software
# * Distributed under the License is distributed on a "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.
# */
#
# Cleans HBase related data from zookeeper and HDFs if no hbase process is alive.--------------------------------------
#
# environment Variables
#
# hbase_regionservers File naming remote hosts.
# Default is ${hadoop_conf_dir}/regionservers
# Hadoop_conf_dir Alternate CONF DIR. Default is ${hadoop_home}/conf.
# hbase_conf_dir Alternate HBASE CONF DIR. Default is ${hbase_home}/conf.
# Hadoop_slave_sleep Seconds to SLEEP between spawning remote commands.
# hadoop_slave_timeout Seconds to wait for timing out a remote command.
# hadoop_ssh_opts Options passed to SSH when running remote commands.
#
If ["$distMode" = = ' false '];then
echo "Skipping hbase data clearing in standalone mode." 2>&1
Exit 1;
Fi
Zparent= ' $bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.parent '
If ["$zparent" = = "null"]; Then zparent= "/hbase"; Fi
Hrootdir= ' $bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool hbase.rootdir '
If ["$hrootdir" = = "null"]; Then hrootdir= "File:///tmp/hbase-${user}/hbase"; Fi
Check_for_znodes () {
command=$1;
Case $command in
Regionservers)
Zchild= ' $bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.rs '
If ["$zchild" = = "null"]; Then zchild= "RS"; Fi
;;
Backupmasters)
Zchild= ' $bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.backup.masters '
If ["$zchild" = = "null"]; Then zchild= "Backup-masters"; Fi
;;
Esac
znodes= ' $bin '/hbase zkcli ls $zparent/$zchild 2>&1 | Tail-1 | Sed "s/\[//" | sed "s/\]//"
If ["$znodes"! = ""]; Then
Echo-n "Znode (s) [${znodes}] of $command is not expired. Exiting without cleaning hbase data. "
Echo #force a newline
Exit 1;
Else
Echo-n "All Znode (s) of $command is expired."
Fi
Echo #force a newline
}
Check_znode_exists () {
Command=$1
"$bin"/hbase zkcli stat $command 2>&1 | grep "Node does not exist\| Connection refused "
}
Check_znode_exists $zparent
If [$?-ne 0]; Then
# Make sure the online region server (s) znode (s) has been deleted before continuing
Check_for_znodes regionservers
# Make sure the backup master (s) znode (s) have been deleted before continuing
Check_for_znodes backupmasters
# Make sure the master Znode have been deleted before continuing
Zmaster= ' $bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.master '
If ["$zmaster" = = "null"]; Then zmaster= "Master"; Fi
zmaster= $zparent/$zmaster
Check_znode_exists $zmaster
If [$?-ne 0]; Then
Echo-n "Master Znode is not expired. Exiting without cleaning hbase data. "
Echo #force a new line
Exit 1
Else
echo "Active Master Znode also expired."
Fi
Echo #force a newline
Else
echo "HBase parent Znode ${zparent} does not exist."
Fi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.