-
Notifications
You must be signed in to change notification settings - Fork 310
/
migrate_node.sh
executable file
·118 lines (104 loc) · 3.28 KB
/
migrate_node.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
115
116
117
118
#!/bin/bash
# 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.
set -e
PID=$$
function usage()
{
echo "This tool is for migrating primary replicas out of specified node."
echo
echo "USAGE1: $0 <cluster-meta-list> <migrate-node> <app-name> <run|test>"
echo "USAGE2: $0 <shell-config-path> <migrate-node> <app-name> <run|test> -f"
echo "app-name = * means migrate all apps"
}
if [ $# -ne 4 -a $# -ne 5 ]
then
usage
exit 1
fi
pwd="$( cd "$( dirname "$0" )" && pwd )"
shell_dir="$( cd $pwd/.. && pwd )"
cd $shell_dir
if [ $# -eq 4 ]; then
cluster=$1
elif [ "$5" == "-f" ]; then
config=$1
else
usage
echo "ERROR: invalid option: $5"
exit 1
fi
node=$2
app_name=$3
type=$4
if [ "$type" != "run" -a "$type" != "test" ]
then
usage
echo "ERROR: invalid type: $type"
exit 1
fi
echo "UID=$UID"
echo "PID=$PID"
echo
if [ "$cluster" != "" ]; then
echo "set_meta_level steady" | ./run.sh shell --cluster $cluster &>/tmp/$UID.$PID.pegasus.set_meta_level
echo ls | ./run.sh shell --cluster $cluster &>/tmp/$UID.$PID.pegasus.ls
else
echo "set_meta_level steady" | ./run.sh shell --config $config &>/tmp/$UID.$PID.pegasus.set_meta_level
echo ls | ./run.sh shell --config $config &>/tmp/$UID.$PID.pegasus.ls
fi
while read app_line
do
status=`echo $app_line | awk '{print $2}'`
if [ "$status" = "AVAILABLE" ]
then
gid=`echo $app_line | awk '{print $1}'`
app=`echo $app_line | awk '{print $3}'`
if [ "$app_name" != "*" -a "$app_name" != "$app" ]
then
continue
fi
if [ "$cluster" != "" ]; then
echo "app $app -d" | ./run.sh shell --cluster $cluster &>/tmp/$UID.$PID.pegasus.app.$app
else
echo "app $app -d" | ./run.sh shell --config $config &>/tmp/$UID.$PID.pegasus.app.$app
fi
while read line
do
pri=`echo $line | awk '{print $4}'`
if [ "$pri" = "$node" ]
then
pid=`echo $line | awk '{print $1}'`
to=`echo $line | awk '{print $5}' | grep -o '\[.*\]' | grep -o '[0-9.:,]*' | cut -d, -f$((RANDOM%2+1))`
echo "balance --gpid ${gid}.${pid} --type move_pri -f $node -t $to"
fi
done </tmp/$UID.$PID.pegasus.app.$app >/tmp/$UID.$PID.pegasus.cmd.$app
if [ "$type" = "run" ]
then
if [ "$cluster" != "" ]; then
cat /tmp/$UID.$PID.pegasus.cmd.$app | ./run.sh shell --cluster $cluster 2>/dev/null
else
cat /tmp/$UID.$PID.pegasus.cmd.$app | ./run.sh shell --config $config 2>/dev/null
fi
echo
echo
else
cat /tmp/$UID.$PID.pegasus.cmd.$app
fi
fi
done </tmp/$UID.$PID.pegasus.ls
rm -f /tmp/$UID.$PID.pegasus.* &>/dev/null