2021-09-10 15:40:17 +00:00
|
|
|
function test_mgr() {
|
|
|
|
if curl -s https://${1}/confluent-api/ > /dev/null; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2021-05-03 16:48:08 +00:00
|
|
|
function set_confluent_vars() {
|
2021-07-23 23:08:06 +00:00
|
|
|
if [ -z "$nodename" ]; then
|
|
|
|
nodename=$(grep ^NODENAME: /etc/confluent/confluent.info | awk '{print $2}')
|
|
|
|
fi
|
2021-09-10 15:40:17 +00:00
|
|
|
if [[ "$confluent_mgr" == *"%"* ]]; then
|
|
|
|
confluent_mgr=""
|
|
|
|
fi
|
2021-05-03 16:48:08 +00:00
|
|
|
if [ -z "$confluent_mgr" ]; then
|
|
|
|
confluent_mgr=$(grep ^deploy_server: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //')
|
2021-09-10 15:40:17 +00:00
|
|
|
if ! test_mgr $confluent_mgr; then
|
|
|
|
confluent_mgr=$(grep ^deploy_server_v6: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //')
|
|
|
|
if [[ "$confluent_mgr" = *":"* ]]; then
|
|
|
|
confluent_mgr="[$confluent_mgr]"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! test_mgr $confluent_mgr; then
|
|
|
|
BESTMGRS=$(grep ^EXTMGRINFO: /etc/confluent/confluent.info | grep '|1$' | sed -e 's/EXTMGRINFO: //' -e 's/|.*//')
|
|
|
|
OKMGRS=$(grep ^EXTMGRINFO: /etc/confluent/confluent.info | grep '|0$' | sed -e 's/EXTMGRINFO: //' -e 's/|.*//')
|
|
|
|
for confluent_mgr in $BESTMGRS $OKMGRS; do
|
|
|
|
if [[ $confluent_mgr == *":"* ]]; then
|
|
|
|
confluent_mgr="[$confluent_mgr]"
|
|
|
|
fi
|
|
|
|
if test_mgr $confluent_mgr; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2021-05-03 16:48:08 +00:00
|
|
|
fi
|
|
|
|
if [ -z "$confluent_profile" ]; then
|
|
|
|
confluent_profile=$(grep ^profile: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //')
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-01 20:01:26 +00:00
|
|
|
run_remote() {
|
2021-05-03 16:48:08 +00:00
|
|
|
set_confluent_vars
|
2020-08-21 14:33:56 +00:00
|
|
|
requestedcmd="'$*'"
|
2020-08-21 21:03:12 +00:00
|
|
|
echo
|
|
|
|
echo '---------------------------------------------------------------------------'
|
2021-05-03 16:48:08 +00:00
|
|
|
echo Running $requestedcmd from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/
|
2020-08-21 21:42:02 +00:00
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
echo Executing in $tmpdir
|
|
|
|
cd $tmpdir
|
2021-05-03 19:36:27 +00:00
|
|
|
mkdir -p $(dirname $1)
|
2021-05-03 16:48:08 +00:00
|
|
|
curl -f -sS https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/$1 > $1
|
2020-08-21 21:42:02 +00:00
|
|
|
if [ $? != 0 ]; then echo $requestedcmd failed to download; return 1; fi
|
2020-06-01 20:01:26 +00:00
|
|
|
chmod +x $1
|
2020-07-15 19:22:27 +00:00
|
|
|
cmd=$1
|
|
|
|
shift
|
2020-07-13 21:08:38 +00:00
|
|
|
./$cmd $*
|
2020-08-21 21:42:02 +00:00
|
|
|
retcode=$?
|
|
|
|
echo "$requestedcmd exited with code $retcode"
|
|
|
|
cd - > /dev/null
|
|
|
|
return $retcode
|
2020-06-01 20:01:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 16:48:08 +00:00
|
|
|
source_remote_parts() {
|
|
|
|
confluentscripttmpdir=$(mktemp -d)
|
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
|
|
|
scriptlist=$(/usr/bin/python3 $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //')
|
|
|
|
for script in $scriptlist; do
|
|
|
|
source_remote $1/$script
|
|
|
|
done
|
|
|
|
unset confluentscripttmpdir
|
|
|
|
}
|
|
|
|
|
|
|
|
run_remote_parts() {
|
|
|
|
confluentscripttmpdir=$(mktemp -d)
|
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
|
|
|
scriptlist=$(/usr/bin/python3 $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //')
|
|
|
|
for script in $scriptlist; do
|
|
|
|
run_remote $1/$script
|
|
|
|
done
|
|
|
|
unset confluentscripttmpdir
|
|
|
|
}
|
|
|
|
|
2020-06-01 20:01:26 +00:00
|
|
|
run_remote_python() {
|
2020-08-21 21:03:12 +00:00
|
|
|
echo
|
|
|
|
echo '---------------------------------------------------------------------------'
|
2021-05-03 16:48:08 +00:00
|
|
|
echo Running python script "'$*'" from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/
|
2020-08-21 21:42:02 +00:00
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
echo Executing in $tmpdir
|
|
|
|
cd $tmpdir
|
2021-05-03 19:36:27 +00:00
|
|
|
mkdir -p $(dirname $1)
|
2021-05-03 16:48:08 +00:00
|
|
|
curl -f -sS https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/$1 > $1
|
2020-08-21 21:42:02 +00:00
|
|
|
if [ $? != 0 ]; then echo "'$*'" failed to download; return 1; fi
|
2020-07-13 21:08:38 +00:00
|
|
|
python3 $*
|
2020-08-21 21:42:02 +00:00
|
|
|
retcode=$?
|
|
|
|
echo "'$*' exited with code $retcode"
|
|
|
|
cd - > /dev/null
|
|
|
|
return $retcode
|
2020-06-01 20:01:26 +00:00
|
|
|
}
|
2021-03-18 18:37:54 +00:00
|
|
|
|
|
|
|
run_remote_config() {
|
|
|
|
echo
|
|
|
|
set_confluent_vars
|
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
|
|
|
echo '---------------------------------------------------------------------------'
|
2021-05-03 16:48:08 +00:00
|
|
|
echo Requesting to run remote configuration for "'$*'" from $confluent_mgr under profile $confluent_profile
|
2021-03-19 20:07:59 +00:00
|
|
|
python3 $apiclient /confluent-api/self/remoteconfig/"$*" -d {}
|
|
|
|
python3 $apiclient /confluent-api/self/remoteconfig/status -w 204
|
2021-03-18 18:37:54 +00:00
|
|
|
echo
|
2021-03-18 18:58:53 +00:00
|
|
|
echo 'Completed remote configuration'
|
2021-03-18 18:37:54 +00:00
|
|
|
echo '---------------------------------------------------------------------------'
|
|
|
|
return
|
|
|
|
}
|