Skip to content

Commit f8bd228

Browse files
authored
HBASE-24620 : Add a ClusterManager which submits command to ZooKeeper and its Agent which picks and execute those Commands (#2299)
Signed-off-by: Aman Poonia <apoonia@salesforce.com> Signed-off-by: Viraj Jasani <vjasani@apache.org>
1 parent 904b555 commit f8bd228

File tree

8 files changed

+1447
-0
lines changed

8 files changed

+1447
-0
lines changed

bin/chaos-daemon.sh

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/usr/bin/env bash
2+
#
3+
#/**
4+
# * Licensed to the Apache Software Foundation (ASF) under one
5+
# * or more contributor license agreements. See the NOTICE file
6+
# * distributed with this work for additional information
7+
# * regarding copyright ownership. The ASF licenses this file
8+
# * to you under the Apache License, Version 2.0 (the
9+
# * "License"); you may not use this file except in compliance
10+
# * with the License. You may obtain a copy of the License at
11+
# *
12+
# * http://www.apache.org/licenses/LICENSE-2.0
13+
# *
14+
# * Unless required by applicable law or agreed to in writing, software
15+
# * distributed under the License is distributed on an "AS IS" BASIS,
16+
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# * See the License for the specific language governing permissions and
18+
# * limitations under the License.
19+
# */
20+
#
21+
22+
usage="Usage: chaos-daemon.sh (start|stop) chaosagent"
23+
24+
# if no args specified, show usage
25+
if [ $# -le 1 ]; then
26+
echo "$usage"
27+
exit 1
28+
fi
29+
30+
# get arguments
31+
startStop=$1
32+
shift
33+
34+
command=$1
35+
shift
36+
37+
check_before_start(){
38+
#ckeck if the process is not running
39+
mkdir -p "$HBASE_PID_DIR"
40+
if [ -f "$CHAOS_PID" ]; then
41+
if kill -0 "$(cat "$CHAOS_PID")" > /dev/null 2>&1; then
42+
echo "$command" running as process "$(cat "$CHAOS_PID")". Stop it first.
43+
exit 1
44+
fi
45+
fi
46+
}
47+
48+
bin=`dirname "${BASH_SOURCE-$0}"`
49+
bin=$(cd "$bin">/dev/null || exit; pwd)
50+
51+
. "$bin"/hbase-config.sh
52+
. "$bin"/hbase-common.sh
53+
54+
CLASSPATH=$HBASE_CONF_DIR
55+
for f in ../lib/*.jar; do
56+
CLASSPATH=${CLASSPATH}:$f
57+
done
58+
59+
# get log directory
60+
if [ "$HBASE_LOG_DIR" = "" ]; then
61+
export HBASE_LOG_DIR="$HBASE_HOME/logs"
62+
fi
63+
64+
if [ "$HBASE_PID_DIR" = "" ]; then
65+
HBASE_PID_DIR=/tmp
66+
fi
67+
68+
if [ "$HBASE_IDENT_STRING" = "" ]; then
69+
export HBASE_IDENT_STRING="$USER"
70+
fi
71+
72+
if [ "$JAVA_HOME" != "" ]; then
73+
#echo "run java in $JAVA_HOME"
74+
JAVA_HOME=$JAVA_HOME
75+
fi
76+
if [ "$JAVA_HOME" = "" ]; then
77+
echo "Error: JAVA_HOME is not set."
78+
exit 1
79+
fi
80+
81+
export HBASE_LOG_PREFIX=hbase-$HBASE_IDENT_STRING-$command-$HOSTNAME
82+
export CHAOS_LOGFILE=$HBASE_LOG_PREFIX.log
83+
84+
if [ -z "${HBASE_ROOT_LOGGER}" ]; then
85+
export HBASE_ROOT_LOGGER=${HBASE_ROOT_LOGGER:-"INFO,RFA"}
86+
fi
87+
88+
if [ -z "${HBASE_SECURITY_LOGGER}" ]; then
89+
export HBASE_SECURITY_LOGGER=${HBASE_SECURITY_LOGGER:-"INFO,RFAS"}
90+
fi
91+
92+
CHAOS_LOGLOG=${CHAOS_LOGLOG:-"${HBASE_LOG_DIR}/${CHAOS_LOGFILE}"}
93+
CHAOS_PID=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.pid
94+
95+
if [ -z "$CHAOS_JAVA_OPTS" ]; then
96+
CHAOS_JAVA_OPTS="-Xms1024m -Xmx4096m"
97+
fi
98+
99+
case $startStop in
100+
101+
(start)
102+
check_before_start
103+
echo running $command
104+
CMD="${JAVA_HOME}/bin/java -Dapp.home=${HBASE_CONF_DIR}/../ ${CHAOS_JAVA_OPTS} -cp ${CLASSPATH} org.apache.hadoop.hbase.chaos.ChaosService -$command start &>> ${CHAOS_LOGLOG} &"
105+
106+
eval $CMD
107+
PID=$(echo $!)
108+
echo ${PID} >${CHAOS_PID}
109+
110+
echo "Chaos ${1} process Started with ${PID} !"
111+
now=$(date)
112+
echo "${now} Chaos ${1} process Started with ${PID} !" >>${CHAOS_LOGLOG}
113+
;;
114+
115+
(stop)
116+
echo stopping $command
117+
if [ -f $CHAOS_PID ]; then
118+
pidToKill=`cat $CHAOS_PID`
119+
# kill -0 == see if the PID exists
120+
if kill -0 $pidToKill > /dev/null 2>&1; then
121+
echo -n stopping $command
122+
echo "`date` Terminating $command" >> $CHAOS_LOGLOG
123+
kill $pidToKill > /dev/null 2>&1
124+
waitForProcessEnd $pidToKill $command
125+
else
126+
retval=$?
127+
echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval
128+
fi
129+
else
130+
echo no $command to stop because no pid file $CHAOS_PID
131+
fi
132+
rm -f $CHAOS_PID
133+
;;
134+
135+
(*)
136+
echo $usage
137+
exit 1
138+
;;
139+
140+
esac

0 commit comments

Comments
 (0)