Modify the algorithms updater script so that it can manage algorithms upgrades. See https://support.d4science.org/issues/9562

This commit is contained in:
Andrea Dell'Amico 2017-09-04 19:37:03 +02:00
parent 7258e12d3b
commit 0908b0bbd6
2 changed files with 36 additions and 3 deletions

View File

@ -21,6 +21,10 @@
subversion: repo={{ dataminer_wps_algorithms_svn }} dest={{ smartgears_user_home }}/wps_algorithms/algorithms checkout=yes force=yes update=yes subversion: repo={{ dataminer_wps_algorithms_svn }} dest={{ smartgears_user_home }}/wps_algorithms/algorithms checkout=yes force=yes update=yes
tags: [ 'tomcat', 'dataminer', 'wps', 'dataminer_algorithms', 'dataminer_algorithms_svn' ] tags: [ 'tomcat', 'dataminer', 'wps', 'dataminer_algorithms', 'dataminer_algorithms_svn' ]
- name: Create a directory where to install the algorithms updater logs and data
file: path={{ smartgears_user_home }}/wps_algorithms_install_log state=directory
tags: [ 'tomcat', 'dataminer', 'wps', 'dataminer_algorithms', 'dataminer_algorithms_script' ]
- name: Install a script that updates the algorithms repository and adds the missing algorithms configurations - name: Install a script that updates the algorithms repository and adds the missing algorithms configurations
become_user: "{{ d4science_ansible_become_user | default('root') }}" become_user: "{{ d4science_ansible_become_user | default('root') }}"
template: src=algorithms-updater.j2 dest=/usr/local/bin/algorithms-updater mode=0755 template: src=algorithms-updater.j2 dest=/usr/local/bin/algorithms-updater mode=0755

View File

@ -9,7 +9,7 @@ ADD_ALGORITHM_PATH={{ smartgears_user_home }}/algorithmInstaller/addAlgorithm.sh
ALGORITHMS_FILE={{ dataminer_wps_algorithms_dest }}/${INFRA_REFERENCE}/algorithms ALGORITHMS_FILE={{ dataminer_wps_algorithms_dest }}/${INFRA_REFERENCE}/algorithms
OUT_DIR=$( mktemp -d -t algorithms-updater.XXXXXXXXXX ) OUT_DIR=$( mktemp -d -t algorithms-updater.XXXXXXXXXX )
ALGORITHMS_TEMP_SCRIPT=$OUT_DIR/add_algorithms ALGORITHMS_TEMP_SCRIPT=$OUT_DIR/add_algorithms
LOG_DIR={{ smartgears_user_home }}/wps_algorithms_install_log/ LOG_DIR={{ smartgears_user_home }}/wps_algorithms_install_log
LOG_FILE=${LOG_DIR}/algorithms_updater.log LOG_FILE=${LOG_DIR}/algorithms_updater.log
ALGORITHMS_INSTALLED_FILE=${LOG_DIR}/already_installed_algorithms.txt ALGORITHMS_INSTALLED_FILE=${LOG_DIR}/already_installed_algorithms.txt
LOCK_FILE=${LOG_DIR}/.algorithms_updater.lock LOCK_FILE=${LOG_DIR}/.algorithms_updater.lock
@ -65,7 +65,7 @@ function algorithms_updater() {
echo "#!/bin/bash" > $ALGORITHMS_TEMP_SCRIPT.head echo "#!/bin/bash" > $ALGORITHMS_TEMP_SCRIPT.head
echo "cd $ADD_ALGORITHM_DIR" >> $ALGORITHMS_TEMP_SCRIPT.head echo "cd $ADD_ALGORITHM_DIR" >> $ALGORITHMS_TEMP_SCRIPT.head
echo "" >> $ALGORITHMS_TEMP_SCRIPT.head echo "" >> $ALGORITHMS_TEMP_SCRIPT.head
awk -F \| '{ print $2 "|" $6 }' $ALGORITHMS_FILE > $ALGORITHMS_TEMP_SCRIPT.algorithmslist awk -F \| '{ print $2 "|" $6 "|" $8 }' $ALGORITHMS_FILE > $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/<notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist sed -i -e 's/<notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/<\/notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist sed -i -e 's/<\/notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/\ N\ /\ Y\ /g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist sed -i -e 's/\ N\ /\ Y\ /g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
@ -78,6 +78,8 @@ function algorithms_updater() {
ALGO_PRESENT= ALGO_PRESENT=
ALGO_NAME=$( echo "$algo" | awk -F \| '{ print $1 }' ) ALGO_NAME=$( echo "$algo" | awk -F \| '{ print $1 }' )
ALGO_BODY=$( echo "$algo" | awk -F \| '{ print $2 }' ) ALGO_BODY=$( echo "$algo" | awk -F \| '{ print $2 }' )
ALGO_DATE=$( echo "$algo" | awk -F \| '{ print $3 }' )
ALGO_TIMESTAMP=$( date +%s -d "$ALGO_DATE" )
ALGO_LINE=$( egrep ^"$ALGO_NAME" $ALGORITHMS_INSTALLED_FILE ) ALGO_LINE=$( egrep ^"$ALGO_NAME" $ALGORITHMS_INSTALLED_FILE )
ALGO_PRESENT=$? ALGO_PRESENT=$?
if [ $ALGO_PRESENT -ne 0 ] ; then if [ $ALGO_PRESENT -ne 0 ] ; then
@ -97,9 +99,36 @@ function algorithms_updater() {
echo 'if [ $RETVAL -ne 0 ] ; then' >> $ALGORITHMS_TEMP_SCRIPT.body_ echo 'if [ $RETVAL -ne 0 ] ; then' >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME failed'" >> $ALGORITHMS_TEMP_SCRIPT.body_ echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME failed'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "else" >> $ALGORITHMS_TEMP_SCRIPT.body_ echo "else" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " echo '$ALGO_NAME' >> $ALGORITHMS_INSTALLED_FILE" >> $ALGORITHMS_TEMP_SCRIPT.body_ echo " echo '$ALGO_NAME | $ALGO_DATE' >> $ALGORITHMS_INSTALLED_FILE" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME succeeded'" >> $ALGORITHMS_TEMP_SCRIPT.body_ echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME succeeded'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "fi" >> $ALGORITHMS_TEMP_SCRIPT.body_ echo "fi" >> $ALGORITHMS_TEMP_SCRIPT.body_
else
ALGO_LOCAL_TIMESTAMP=0
ALGO_LOCAL_DATE=$( egrep ^"$ALGO_NAME" $ALGORITHMS_INSTALLED_FILE | awk -F \| '{ print $2 }' | grep -v \' )
ALGO_LOCAL_TIMESTAMP=$( date +%s -d "$ALGO_LOCAL_DATE" )
if [ $ALGO_LOCAL_TIMESTAMP -ne $ALGO_TIMESTAMP ] ; then
echo "logger 'algorithms-updater: running the add command of algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: the add command string is $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "RETVAL=" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo '-------------------------------------------'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Adding algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'With command $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "$ALGO_BODY" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo 'RETVAL=$?' >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Done.'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo 'if [ $RETVAL -ne 0 ] ; then' >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME failed'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "else" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " echo 'grep -v $ALGO_NAME $ALGORITHMS_INSTALLED_FILE > ${ALGORITHMS_INSTALLED_FILE}_ " >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " echo 'mv ${ALGORITHMS_INSTALLED_FILE}_ $ALGORITHMS_INSTALLED_FILE" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " echo '$ALGO_NAME | $ALGO_DATE' >> $ALGORITHMS_INSTALLED_FILE" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME succeeded'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "fi" >> $ALGORITHMS_TEMP_SCRIPT.body_
fi
fi fi
done < ${ALGORITHMS_TEMP_SCRIPT}.algorithmslist done < ${ALGORITHMS_TEMP_SCRIPT}.algorithmslist
set -o pipefail set -o pipefail