Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(script): Script migrate_node.sh supports using specified config file when using shell config #1370

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [ "$CLUSTER" != "" ]; 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
49 changes: 38 additions & 11 deletions scripts/migrate_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,56 @@ set -e

PID=$$

if [ $# -ne 4 ]
then
function usage()
{
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
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

cluster=$1
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"
echo "USAGE: $0 <cluster-meta-list> <migrate-node> <app-name> <run|test>"
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 [ "$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
Expand All @@ -64,7 +83,11 @@ do
continue
fi

echo "app $app -d" | ./run.sh shell --cluster $cluster &>/tmp/$UID.$PID.pegasus.app.$app
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
Expand All @@ -79,7 +102,11 @@ do

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