Skip to content

Commit

Permalink
script migrate_node.sh supports using specified config file when usin…
Browse files Browse the repository at this point in the history
…g shell client
  • Loading branch information
wh002 committed Mar 10, 2023
1 parent ca6ee39 commit 73a8aef
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
20 changes: 17 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,7 @@ function usage_migrate_node()
echo "Options for subcommand 'migrate_node':"
echo " -h|--help print the help info"
echo " -c|--cluster <str> cluster meta lists"
echo " -f|--config <str> shell config path"
echo " -n|--node <str> the node to migrate primary replicas out, should be ip:port"
echo " -a|--app <str> the app to migrate primary replicas out, if not set, means migrate all apps"
echo " -t|--type <str> type: test or run, default is test"
Expand All @@ -1655,6 +1656,7 @@ function usage_migrate_node()
function run_migrate_node()
{
CLUSTER=""
CONFIG=""
NODE=""
APP="*"
TYPE="test"
Expand All @@ -1669,6 +1671,10 @@ function run_migrate_node()
CLUSTER="$2"
shift
;;
-f|--config)
CONFIG="$2"
shift
;;
-n|--node)
NODE="$2"
shift
Expand All @@ -1691,7 +1697,7 @@ function run_migrate_node()
shift
done

if [ "$CLUSTER" == "" ]; then
if [ "$CLUSTER" == "" -a "$CONFIG" == "" ]; then
echo "ERROR: no cluster specified"
echo
usage_migrate_node
Expand All @@ -1712,14 +1718,22 @@ function run_migrate_node()
exit 1
fi

echo "CLUSTER=$CLUSTER"
if [ "$CLUSTER" != "" ]; then
echo "CLUSTER=$CLUSTER"
else
echo "CONFIG=$CONFIG"
fi
echo "NODE=$NODE"
echo "APP=$APP"
echo "TYPE=$TYPE"
echo
cd ${ROOT}
echo "------------------------------"
./scripts/migrate_node.sh $CLUSTER $NODE "$APP" $TYPE
if [ ${CONFIG_SPECIFIED} -eq 0 ]; then
./scripts/migrate_node.sh $CLUSTER $NODE "$APP" $TYPE
else
./scripts/migrate_node.sh $CONFIG $NODE "$APP" $TYPE -f
fi
echo "------------------------------"
echo
if [ "$TYPE" == "test" ]; then
Expand Down
40 changes: 30 additions & 10 deletions scripts/migrate_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,49 @@ set -e

PID=$$

if [ $# -ne 4 ]
if [ $# -ne 4 -a $# -ne 5 ]
then
echo "This tool is for migrating primary replicas out of specified node."
echo "USAGE: $0 <cluster-meta-list> <migrate-node> <app-name> <run|test>"
echo " app-name = * means migrate all apps"
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"
exit 1
fi

pwd="$( cd "$( dirname "$0" )" && pwd )"
shell_dir="$( cd $pwd/.. && pwd )"
cd $shell_dir

cluster=$1
CONFIG_SPECIFIED=0
if [ $# -eq 4 ]; then
cluster=$1
else
CONFIG_SPECIFIED=1
config=$1
fi
node=$2
app_name=$3
type=$4

if [ "$type" != "run" -a "$type" != "test" ]
then
echo "ERROR: invalid type: $type"
echo "USAGE: $0 <cluster-meta-list> <migrate-node> <app-name> <run|test>"
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"
exit 1
fi

echo "UID=$UID"
echo "PID=$PID"
echo

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
if [ ${CONFIG_SPECIFIED} -eq 0 ]; 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
Expand All @@ -64,7 +76,11 @@ do
continue
fi

echo "app $app -d" | ./run.sh shell --cluster $cluster &>/tmp/$UID.$PID.pegasus.app.$app
if [ ${CONFIG_SPECIFIED} -eq 0 ]; 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
Expand All @@ -79,7 +95,11 @@ do

if [ "$type" = "run" ]
then
cat /tmp/$UID.$PID.pegasus.cmd.$app | ./run.sh shell --cluster $cluster 2>/dev/null
if [ ${CONFIG_SPECIFIED} -eq 0 ]; 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
Expand Down

0 comments on commit 73a8aef

Please sign in to comment.