Merge pull request #188 from d4mian/minor-changes
[voldemort/jeffpc.git] / bin / rebalance-zone-shrinkage.sh
blob7e7ca7b9bb320a89d30b4cc86f8b16f7bb96c7a0
1 #!/bin/bash -e
4 # Copyright 2013 LinkedIn, Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # This script generates a final cluster.xml and stores.xml after dropping a zone from the current
19 # cluster.xml and stores.xml, placing the output in output directory.
21 # Argument = -c <current_cluster.xml> -s <current_stores.xml> -d <drop_zoneid> -o <outputdir>
23 # This script steals partitions from other nodes in the zone that is being dropped
24 # and assigns them to the nodes in the surviving zones.
26 # This script uses getopts which means only single character switches are allowed.
27 # Using getopt would allow for multi character switch names but would come at a
28 # cost of not being cross compatible.
30 # Function to display usage
31 usage_and_exit() {
32 echo "ERROR: $1."
33 cat <<EOF
35 Usage: $0 options
36 OPTIONS:
37 -h Show this message
38 -c Current cluster that describes the cluster
39 -s Current stores.xml for the cluster
40 -d ZoneId that you want to drop
41 -o Output dir for final cluster.xml/stores.xml
42 EOF
43 exit 1
46 # initialize variables to an empty string
47 current_cluster=""
48 current_stores=""
49 drop_zoneid=""
50 output_dir=""
52 # Figure out voldemort home directory
53 dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
54 vold_home="$(dirname "$dir")"
56 # Parse options
57 while getopts “hc:s:d:o:” OPTION
59 case $OPTION in
61 usage_and_exit
62 exit 1
65 current_cluster=$OPTARG
66 echo "[rebalance-zone-shrinkage] Will rebalance on the cluster described in '$current_cluster'."
69 current_stores=$OPTARG
70 echo "[rebalance-zone-shrinkage] Will rebalance stores described in '$current_stores'."
71 ;;
73 drop_zoneid=$OPTARG
74 echo "[rebalance-zone-shrinkage] Will get rid of servers in zone '$drop_zoneid'."
77 output_dir=$OPTARG
78 mkdir -p $output_dir
79 echo "[rebalance-zone-shrinkage] Using '$output_dir' for final files generated."
82 usage_and_exit
84 esac
85 done
87 if [[ -z $current_cluster ]] || [[ -z $drop_zoneid ]] || [[ -z $output_dir ]] || [[ -z $current_stores ]]
88 then
89 printf "\n"
90 echo "[rebalance-zone-shrinkage] Missing argument. Check again."
91 usage_and_exit
92 exit 1
95 if [ ! -e $current_cluster ]; then
96 usage_and_exit "File '$current_cluster' does not exist."
99 if [ ! -e $current_stores ]; then
100 usage_and_exit "File '$current_stores' does not exist."
103 mkdir -p $output_dir
104 $vold_home/bin/run-class.sh voldemort.tools.ZoneClipperCLI \
105 --current-cluster $current_cluster \
106 --current-stores $current_stores \
107 --drop-zoneid $drop_zoneid \
108 --output-dir $output_dir/