-
Notifications
You must be signed in to change notification settings - Fork 16
/
flush_all_tables.sh
executable file
·115 lines (85 loc) · 1.83 KB
/
flush_all_tables.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#-------------------------------------------------------------------------------#
# SCRIPT TO FLUSH ALL HBASE TABLES.
#-------------------------------------------------------------------------------#
LIST_OF_TABLES=/tmp/tables.txt
HBASE_SCRIPT=/tmp/hbase_script.txt
TARGET_HOST=$1
usage ()
{
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]
then
cat << ...
Usage:
$0 [hostname]
Note: Providing hostname is optional and not required when script
is executed within HDInsight cluster with access to 'hbase shell'.
However host name should be provided when executing the script as
script-action from HDInsight portal.
For Example:
1. Executing script inside HDInsight cluster (where 'hbase shell' is
accessible):
$0
[No need to provide hostname]
2. Executing script from HDinsight Azure portal:
Provide Script URL.
Provide hostname as a parameter (i.e. hn0, hn1 or wn2 etc.).
...
exit
fi
}
validate_machine ()
{
THIS_HOST=`hostname`
if [[ ! -z "$TARGET_HOST" ]] && [[ $THIS_HOST != $TARGET_HOST* ]]
then
echo "[INFO] This machine '$THIS_HOST' is not the right machine ($TARGET_HOST) to execute the script."
exit 0
fi
}
get_tables_list ()
{
hbase shell << ... > $LIST_OF_TABLES 2> /dev/null
list
exit
...
}
add_table_for_flush ()
{
TABLE_NAME=$1
echo "[INFO] Adding table '$TABLE_NAME' to flush list..."
cat << ... >> $HBASE_SCRIPT
flush '$TABLE_NAME'
...
}
clean_up ()
{
rm -f $LIST_OF_TABLES
rm -f $HBASE_SCRIPT
}
########
# MAIN #
########
usage $1
validate_machine
clean_up
get_tables_list
START=false
while read LINE
do
if [[ $LINE == TABLE ]]
then
START=true
continue
elif [[ $LINE == *row*in*seconds ]]
then
break
elif [[ $START == true ]]
then
add_table_for_flush $LINE
fi
done < $LIST_OF_TABLES
cat $HBASE_SCRIPT
hbase shell $HBASE_SCRIPT << ... 2> /dev/null
exit
...