Enhanced refresh monasca transform script

refresh_monasca_script.sh is useful for
development in a devstack environment.

Enhanced the script to
* start and stop monasca-transform process
  running in a screen session
* added more hardening to catch for errors
  and exit if any command fails.
* added debugging statements help track
  down any errors when the script is run.

Change-Id: Idab02d555eed192d8242c870017955b935532c3d
This commit is contained in:
Ashwin Agate 2017-04-18 19:14:02 -07:00
parent 699103e345
commit 5c15a99a5c
6 changed files with 173 additions and 33 deletions

View File

@ -87,7 +87,10 @@ Once the deploy is up use the following commands to set up tox.
To regenerate the environment for development purposes a script is provided To regenerate the environment for development purposes a script is provided
on the devstack instance at on the devstack instance at
/opt/stack/monasca-transform/tools/vagrant/refresh_monasca_transform.sh
To run the refresh_monasca_transform.sh script on devstack instance
cd /opt/stack/monasca-transform
tools/vagrant/refresh_monasca_transform.sh tools/vagrant/refresh_monasca_transform.sh
(note: to use/run tox after running this script, the (note: to use/run tox after running this script, the
@ -95,10 +98,18 @@ on the devstack instance at
This mostly re-does the work of the devstack plugin, updating the code from the This mostly re-does the work of the devstack plugin, updating the code from the
shared directory, regenerating the venv and the zip that is passed to spark shared directory, regenerating the venv and the zip that is passed to spark
during the spark-submit call. The configuration and the contents of the during the spark-submit call. The configuration and the transform and
database are updated with fresh copies also though the start scripts, driver and pre transform specs in the database are updated with fresh copies, along
service python code are left as they are (because I'm not envisaging much change with driver and service python code.
in those).
If refresh_monasca_transform.sh script completes successfully you should see
a message like the following in the console.
***********************************************
* *
* SUCCESS!! refresh monasca transform done. *
* *
***********************************************
### Development workflow ### Development workflow
@ -157,6 +168,19 @@ For example:
Reference: https://wiki.openstack.org/wiki/Testr Reference: https://wiki.openstack.org/wiki/Testr
## Access Spark Streaming and Spark Master/Worker User Interface
In a devstack environment ports on which Spark Streaming UI (4040), Spark Master(18080)
and Spark Worker (18081) UI are available are forwarded to the host and are
accessible from the host machine.
http://<host_machine_ip>:4040/ (Note: Spark Streaming UI,
is available only when
monasca-transform application
is running)
http://<host_machine_ip>:18080/ (Spark Master UI)
http://<host_machine_ip>:18081/ (Spark Worker UI)
## To run monasca-transform using a different deployment technology ## To run monasca-transform using a different deployment technology
Monasca-transform requires supporting services, such as Kafka and Monasca-transform requires supporting services, such as Kafka and

View File

@ -73,6 +73,9 @@ class Transform(os_service.Service):
'Shutting down all threads and exiting') 'Shutting down all threads and exiting')
shutdown_all_threads_and_die() shutdown_all_threads_and_die()
def stop(self, graceful):
shutdown_all_threads_and_die()
class TransformService(threading.Thread): class TransformService(threading.Thread):

View File

@ -3,6 +3,13 @@
SCRIPT_HOME=$(dirname $(readlink -f $BASH_SOURCE)) SCRIPT_HOME=$(dirname $(readlink -f $BASH_SOURCE))
pushd $SCRIPT_HOME pushd $SCRIPT_HOME
echo "create_zip.py: creating a zip file at ../monasca_transform/monasca-transform.zip..."
python create_zip.py python create_zip.py
rc=$?
popd if [[ $rc == 0 ]]; then
echo "created zip file at ../monasca_transfom/monasca-transform.zip sucessfully"
else
echo "error creating zip file at ../monasca_transform/monasca-transform.zip, bailing out"
exit 1
fi
popd

View File

@ -3,7 +3,29 @@
SCRIPT_HOME=$(dirname $(readlink -f $BASH_SOURCE)) SCRIPT_HOME=$(dirname $(readlink -f $BASH_SOURCE))
pushd $SCRIPT_HOME pushd $SCRIPT_HOME
python ddl/generate_ddl.py -t pre_transform_spec -i ddl/pre_transform_specs_template.sql -s ../monasca_transform/data_driven_specs/pre_transform_specs/pre_transform_specs.json -o ddl/pre_transform_specs.sql PRE_TRANSFORM_SPECS_JSON="../monasca_transform/data_driven_specs/pre_transform_specs/pre_transform_specs.json"
python ddl/generate_ddl.py -t transform_spec -i ddl/transform_specs_template.sql -s ../monasca_transform/data_driven_specs/transform_specs/transform_specs.json -o ddl/transform_specs.sql PRE_TRANSFORM_SPECS_SQL="ddl/pre_transform_specs.sql"
popd TRANSFORM_SPECS_JSON="../monasca_transform/data_driven_specs/transform_specs/transform_specs.json"
TRANSFORM_SPECS_SQL="ddl/transform_specs.sql"
echo "converting {$PRE_TRANSFORM_SPECS_JSON} to {$PRE_TRANSFORM_SPECS_SQL} ..."
python ddl/generate_ddl.py -t pre_transform_spec -i ddl/pre_transform_specs_template.sql -s "$PRE_TRANSFORM_SPECS_JSON" -o "$PRE_TRANSFORM_SPECS_SQL"
rc=$?
if [[ $rc == 0 ]]; then
echo "converting {$PRE_TRANSFORM_SPECS_JSON} to {$PRE_TRANSFORM_SPECS_SQL} sucessfully..."
else
echo "error in converting {$PRE_TRANSFORM_SPECS_JSON} to {$PRE_TRANSFORM_SPECS_SQL}, bailing out"
exit 1
fi
echo "converting {$TRANSFORM_SPECS_JSON} to {$TRANSFORM_SPECS_SQL}..."
python ddl/generate_ddl.py -t transform_spec -i ddl/transform_specs_template.sql -s "$TRANSFORM_SPECS_JSON" -o "$TRANSFORM_SPECS_SQL"
rc=$?
if [[ $rc == 0 ]]; then
echo "converting {$TRANSFORM_SPECS_JSON} to {$TRANSFORM_SPECS_SQL} sucessfully..."
else
echo "error in converting {$TRANSFORM_SPECS_JSON} to {$TRANSFORM_SPECS_SQL}, bailing out"
exit 1
fi
popd

View File

@ -1,40 +1,73 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# for debugging
#
## turn on display command
## set -x
if grep -q devstack <<<`hostname`; then if grep -q devstack <<<`hostname`; then
echo Refreshing monasca-transform echo Refreshing monasca-transform
else else
echo Yikes, no - this is not devstack! echo Yikes, no - this is not devstack!
exit 1 exit 1
fi fi
if [ -d "/home/vagrant/devstack" ] ; then
. /home/vagrant/devstack/.stackenv if [ -d ~/devstack ] ; then
. ~/devstack/.stackenv
fi fi
SCRIPT_HOME=$(dirname $(readlink -f $BASH_SOURCE)) SCRIPT_HOME=$(dirname $(readlink -f $BASH_SOURCE))
pushd $SCRIPT_HOME pushd $SCRIPT_HOME
# TODO not sure how to stop monasca-transform from here now that # stop monasca-transform process running in screen session
# the control for it in DevStack is via screen -x stack STOP_SLEEP=10
if grep -q running <<<`sudo service monasca-transform status`; then if [[ -r /opt/stack/status/stack/monasca-transform.pid ]]; then
sudo service monasca-transform stop echo "going to shutdown $service running in screen session..."
else pkill -g $(cat /opt/stack/status/stack/monasca-transform.pid)
echo "monasca-transform service not running" rc=$?
if [[ $rc == 0 ]]; then
echo "waiting $STOP_SLEEP seconds for monasca-transform to exit..."
sleep $STOP_SLEEP
screen -S stack -p monasca-transform -X stuff "\015"
echo "monasca-transform process stopped sucessfully"
else
echo "monasca-transform process wasnt running, proceeding"
fi
fi fi
#
# turn on exit immediately if command fails
#
set -e
sudo rm -rf /home/vagrant/monasca-transform-source /home/vagrant/monasca-transform sudo rm -rf /home/vagrant/monasca-transform-source /home/vagrant/monasca-transform
echo "calling setup_local_repos.sh ..."
sudo ./setup_local_repos.sh sudo ./setup_local_repos.sh
rc=$?
if [[ $rc == 0 ]]; then
echo "setup_local_repos.sh completed sucessfully..."
else
echo "Error in setup_local_repos.sh, bailing out"
exit 1
fi
# update the database with configuration # update the database with configuration
echo "populating monasca-transform db tables with pre_transform_specs and transform_specs..."
sudo cp /home/vagrant/monasca-transform/scripts/ddl/pre_transform_specs.sql /opt/monasca/transform/lib/pre_transform_specs.sql sudo cp /home/vagrant/monasca-transform/scripts/ddl/pre_transform_specs.sql /opt/monasca/transform/lib/pre_transform_specs.sql
sudo cp /home/vagrant/monasca-transform/scripts/ddl/transform_specs.sql /opt/monasca/transform/lib/transform_specs.sql sudo cp /home/vagrant/monasca-transform/scripts/ddl/transform_specs.sql /opt/monasca/transform/lib/transform_specs.sql
sudo mysql -h "127.0.0.1" -um-transform -ppassword < /opt/monasca/transform/lib/pre_transform_specs.sql sudo mysql -h "127.0.0.1" -um-transform -ppassword < /opt/monasca/transform/lib/pre_transform_specs.sql
sudo mysql -h "127.0.0.1" -um-transform -ppassword < /opt/monasca/transform/lib/transform_specs.sql sudo mysql -h "127.0.0.1" -um-transform -ppassword < /opt/monasca/transform/lib/transform_specs.sql
echo "populating monasca-transform db tables with pre_transform_specs and transform_specs done."
# update the zip file used for spark submit # update the zip file used for spark submit
echo "copying new monasca-transform.zip to /opt/monasca/transform/lib/ ..."
sudo cp /home/vagrant/monasca-transform/scripts/monasca-transform.zip /opt/monasca/transform/lib/. sudo cp /home/vagrant/monasca-transform/scripts/monasca-transform.zip /opt/monasca/transform/lib/.
echo "copying new monasca-transform.zip to /opt/monasca/transform/lib/ done."
# update the configuration file # update the configuration file
sudo cp /home/vagrant/monasca-transform/devstack/files/monasca-transform/monasca-transform.conf /etc/. sudo cp /home/vagrant/monasca-transform/devstack/files/monasca-transform/monasca-transform.conf /etc/.
@ -42,18 +75,31 @@ if [ -n "$SERVICE_HOST" ]; then
sudo sudo sed -i "s/brokers=192\.168\.15\.6:9092/brokers=${SERVICE_HOST}:9092/g" /etc/monasca-transform.conf sudo sudo sed -i "s/brokers=192\.168\.15\.6:9092/brokers=${SERVICE_HOST}:9092/g" /etc/monasca-transform.conf
fi fi
# delete the venv
sudo rm -rf /opt/monasca/transform/venv
# refresh the monasca-transform code to /opt/stack MONASCA_TRANSFORM_VENV="/opt/monasca/transform/venv"
sudo rm -rf /opt/stack/monasca-transform MONASCA_TRANSFORM_DIR="/opt/stack/monasca-transform"
echo "refreshing $MONASCA_TRANSFORM_DIR..."
# turn on display command
set -x
# delete the venv
sudo rm -rf $MONASCA_TRANSFORM_VENV
# refresh the monasca-transform code at /opt/stack
sudo rm -rf "$MONASCA_TRANSFORM_DIR"
pushd /opt/stack pushd /opt/stack
sudo git clone /home/vagrant/monasca-transform sudo git clone /home/vagrant/monasca-transform
sudo chown -R vagrant:vagrant /opt/stack/monasca-transform sudo chown -R vagrant:vagrant "$MONASCA_TRANSFORM_DIR"
virtualenv /opt/monasca/transform/venv virtualenv "$MONASCA_TRANSFORM_VENV"
. /opt/monasca/transform/venv/bin/activate . "$MONASCA_TRANSFORM_VENV"/bin/activate
pip install -e /opt/stack/monasca-transform/ pip install -e "$MONASCA_TRANSFORM_DIR"
deactivate deactivate
# turn off display command
set +x
echo "refreshing $MONASCA_TRANSFORM_DIR done."
popd popd
function get_id () { function get_id () {
@ -62,10 +108,26 @@ function get_id () {
source ~/devstack/openrc admin admin source ~/devstack/openrc admin admin
export ADMIN_PROJECT_ID=$(get_id openstack project show admin) export ADMIN_PROJECT_ID=$(get_id openstack project show admin)
echo "updating publish_kafka_project_id to $ADMIN_PROJECT_ID in /etc/monasca-transform.conf..."
sudo sed -i "s/publish_kafka_project_id=d2cb21079930415a9f2a33588b9f2bb6/publish_kafka_project_id=${ADMIN_PROJECT_ID}/g" /etc/monasca-transform.conf sudo sed -i "s/publish_kafka_project_id=d2cb21079930415a9f2a33588b9f2bb6/publish_kafka_project_id=${ADMIN_PROJECT_ID}/g" /etc/monasca-transform.conf
echo "updating publish_kafka_project_id to $ADMIN_PROJECT_ID in /etc/monasca-transform.conf done."
# TODO not sure how to start monasca-transform from here now that # start monasca-transform in screen session
# the control for it in DevStack is via screen -x stack start_command="/etc/monasca/transform/init/start-monasca-transform.sh"
sudo service monasca-transform start screen -S stack -p monasca-transform -X stuff "$start_command & echo \$! >/opt/stack/status/stack/monasca-transform.pid; fg || echo \"monasca-transform failed to start\""
screen -S stack -p monasca-transform -X stuff "\015"
rc=$?
if [[ $rc == 0 ]]; then
echo "monasca-transform process started sucessfully"
else
echo "Error: monasca-transfrom process was not started. Please check screen session for error messages"
exit 1
fi
echo "***********************************************"
echo "* *"
echo "* SUCCESS!! refresh monasca transform done. *"
echo "* *"
echo "***********************************************"
popd popd

View File

@ -1,24 +1,47 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo "going to copy /monasca-transform-source to /home/vagrant ..."
rsync -a --exclude='tools/vagrant/.vagrant' /monasca-transform-source /home/vagrant/ rsync -a --exclude='tools/vagrant/.vagrant' /monasca-transform-source /home/vagrant/
echo "going to move /home/vagrant/monasca-transform-source /home/vagrant/monasca-transform..."
mv /home/vagrant/monasca-transform-source /home/vagrant/monasca-transform mv /home/vagrant/monasca-transform-source /home/vagrant/monasca-transform
pushd /home/vagrant/monasca-transform pushd /home/vagrant/monasca-transform
# prepare the codebase # prepare the codebase
# #
# generate the sql scripts to populate the database # generate the sql scripts which will populate the database
# with the pre_transform and transform specs
scripts/generate_ddl.sh scripts/generate_ddl.sh
# build the zip rc=$?
scripts/create_zip.sh if [[ $rc == 0 ]]; then
echo "scripts/generate_ddl.sh completed sucessfully..."
else
echo "Error in scripts/generate_ddl.sh, bailing out"
exit 1
fi
# build the zip (to be submitted with spark application)
scripts/create_zip.sh
rc=$?
if [[ $rc == 0 ]]; then
echo "scripts/create_zip.sh completed sucessfully..."
else
echo "Error in scripts/create_zip.sh, bailing out"
exit 1
fi
echo "creating a local commit..."
git config --global user.email "local.devstack.committer@hpe.com" git config --global user.email "local.devstack.committer@hpe.com"
git config --global user.name "Local devstack committer" git config --global user.name "Local devstack committer"
git add --all git add --all
git commit -m "Local commit" git commit -m "Local commit"
echo "creating a local commit done."
CURRENT_BRANCH=`git status | grep 'On branch' | sed 's/On branch //'` CURRENT_BRANCH=`git status | grep 'On branch' | sed 's/On branch //'`
if [ ${CURRENT_BRANCH} != 'master' ] if [ ${CURRENT_BRANCH} != 'master' ]
then then
echo Maintaining current branch ${CURRENT_BRANCH} echo "Maintaining current branch ${CURRENT_BRANCH}"
# set the branch to what we're using in local.conf # set the branch to what we're using in local.conf
if [[ -z `grep ${CURRENT_BRANCH} /home/vagrant/devstack/local.conf` ]]; then if [[ -z `grep ${CURRENT_BRANCH} /home/vagrant/devstack/local.conf` ]]; then
sed -i "s/enable_plugin monasca-transform \/home\/vagrant\/monasca-transform//g" /home/vagrant/devstack/local.conf sed -i "s/enable_plugin monasca-transform \/home\/vagrant\/monasca-transform//g" /home/vagrant/devstack/local.conf
@ -27,5 +50,4 @@ then
printf "# END DEVSTACK LOCAL.CONF CONTENTS" >> /home/vagrant/devstack/local.conf printf "# END DEVSTACK LOCAL.CONF CONTENTS" >> /home/vagrant/devstack/local.conf
fi fi
fi fi
popd popd