diff --git a/smartgears/dataminer_app/tasks/dataminer-app.yml b/smartgears/dataminer_app/tasks/dataminer-app.yml index 4dd3504c..356fceed 100644 --- a/smartgears/dataminer_app/tasks/dataminer-app.yml +++ b/smartgears/dataminer_app/tasks/dataminer-app.yml @@ -21,6 +21,10 @@ 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' ] + - 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 become_user: "{{ d4science_ansible_become_user | default('root') }}" template: src=algorithms-updater.j2 dest=/usr/local/bin/algorithms-updater mode=0755 diff --git a/smartgears/dataminer_app/templates/algorithms-updater.j2 b/smartgears/dataminer_app/templates/algorithms-updater.j2 index 1c1099f4..1323199e 100644 --- a/smartgears/dataminer_app/templates/algorithms-updater.j2 +++ b/smartgears/dataminer_app/templates/algorithms-updater.j2 @@ -9,7 +9,7 @@ ADD_ALGORITHM_PATH={{ smartgears_user_home }}/algorithmInstaller/addAlgorithm.sh ALGORITHMS_FILE={{ dataminer_wps_algorithms_dest }}/${INFRA_REFERENCE}/algorithms OUT_DIR=$( mktemp -d -t algorithms-updater.XXXXXXXXXX ) 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 ALGORITHMS_INSTALLED_FILE=${LOG_DIR}/already_installed_algorithms.txt LOCK_FILE=${LOG_DIR}/.algorithms_updater.lock @@ -65,7 +65,7 @@ function algorithms_updater() { echo "#!/bin/bash" > $ALGORITHMS_TEMP_SCRIPT.head echo "cd $ADD_ALGORITHM_DIR" >> $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///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 @@ -78,6 +78,8 @@ function algorithms_updater() { ALGO_PRESENT= ALGO_NAME=$( echo "$algo" | awk -F \| '{ print $1 }' ) 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_PRESENT=$? if [ $ALGO_PRESENT -ne 0 ] ; then @@ -97,9 +99,36 @@ function algorithms_updater() { 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 '$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 "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 done < ${ALGORITHMS_TEMP_SCRIPT}.algorithmslist set -o pipefail