From 2f8f114b58f94a87ad3813a47227be0a89d6fca8 Mon Sep 17 00:00:00 2001 From: Sorina Pop Date: Fri, 24 Jun 2016 14:01:30 +0200 Subject: [PATCH 1/1] CreaPhase circle workflow v0.1 --- bin/CreaPhase.sh | 114 +++++++++++++++++++ gasw/CreaPhase.xml | 51 +++++++++ workflow/CreaPhase.gwendia | 223 +++++++++++++++++++++++++++++++++++++ 3 files changed, 388 insertions(+) create mode 100755 bin/CreaPhase.sh create mode 100644 gasw/CreaPhase.xml create mode 100644 workflow/CreaPhase.gwendia diff --git a/bin/CreaPhase.sh b/bin/CreaPhase.sh new file mode 100755 index 0000000..bf04443 --- /dev/null +++ b/bin/CreaPhase.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +# Functions # + +function info { + local D=`date` + echo [ INFO - $D ] $* +} + +function warning { + local D=`date` + echo [ WARN - $D ] $* +} + +function error { + local D=`date` + echo [ ERROR - $D ] $* >&2 +} + +function downloadLFN { + + local LFN=$1 + local LOCAL=${PWD}/`basename ${LFN}` + + info "getting file size and computing sendReceiveTimeout" + size=`lfc-ls -l ${LFN} | awk -F' ' '{print $5}'` + sendReceiveTimeout=`echo $[${size}/150/1024]` + if [ "$sendReceiveTimeout" = "" ] || [ $sendReceiveTimeout -le 900 ]; then echo "sendReceiveTimeout empty or too small, setting it to 900s"; sendReceiveTimeout=900; else echo "sendReceiveTimeout is $sendReceiveTimeout"; fi; + info "Removing file ${LOCAL} in case it is already here" + \rm -f ${LOCAL} + + info "Checking if the file is on local SE ${VO_BIOMED_DEFAULT_SE}" + local closeSURL=`lcg-lr lfn:${LFN} | grep ${VO_BIOMED_DEFAULT_SE}` + if [ "${closeSURL}" != "" ] + then + info "It is. Trying to download the file from there" + LINE="lcg-cp -v --connect-timeout 10 --sendreceive-timeout $sendReceiveTimeout --bdii-timeout 10 --srm-timeout 30 ${closeSURL} file:${LOCAL}" + info ${LINE} + ${LINE} &> lcg-log + if [ $? = 0 ] + then + info "lcg-cp worked fine" + lcg_source=`cat lcg-log | awk -F"://" '/Trying SURL srm/ {print $2}' | awk -F"/" '{print $1}'|awk -F":" '{print $1}'`; + lcg_destination=`hostname`; + lcg_time=`cat lcg-log | awk '/Transfer took/ {print $3$4}'`; + info "DownloadCommand=lcg-cp Source=$lcg_source Destination=$lcg_destination Size=$size Time=$lcg_time"; + return 0 + else + error "It failed, falling back on regular lcg-cp" + fi + else + info "It's not, falling back on regular lcg-cp" + fi + +info "Downloading file ${LFN}..." +LINE="lcg-cp -v --connect-timeout 10 --sendreceive-timeout $sendReceiveTimeout --bdii-timeout 10 --srm-timeout 30 lfn:${LFN} file:${LOCAL}" +info ${LINE} +${LINE} &> lcg-log +if [ $? = 0 ] +then + info "lcg-cp worked fine" + lcg_source=`cat lcg-log | awk -F"://" '/Trying SURL srm/ {print $2}' | awk -F"/" '{print $1}'|awk -F":" '{print $1}'`; + lcg_destination=`hostname`; + lcg_time=`cat lcg-log | awk '/Transfer took/ {print $3$4}'`; + info "DownloadCommand=lcg-cp Source=$lcg_source Destination=$lcg_destination Size=$size Time=$lcg_time"; +else + error "lcg-cp failed" + error "`cat lcg-log`" + return 1 +fi +\rm lcg-log +} + +# Arguments parsing # +RES=$1 +COMM_LINE=`echo "${@:2:$(($#-2))}"` +# Command-line construction # + +#echo "COMM line is $COMM_LINE" +#remove flags starting with -- +#BOUTIQUES_ARGS="$(echo ${COMM_LINE} | sed 's/[--][[:alpha:]]*/,/g')" +BOUTIQUES_ARGS="$(echo ${COMM_LINE} | sed 's/ , /, /g')" +#remove leading ,, +#BOUTIQUES_ARGS="$(echo ${BOUTIQUES_ARGS} | sed 's/^,, //g')" +BOUTIQUES_COMMAND_LINE="octave --silent --eval \"SimuPBI_circle_func(${BOUTIQUES_ARGS})\"" +echo "Boutiques COMM line is $BOUTIQUES_COMMAND_LINE" + + +#WARNING Cheating here : we know that outputs are written in dirOut +DIROUT="dirOut" +# Command-line execution # + +cat << DOCKERJOB > .dockerjob.sh +#!/bin/bash -l +cd /CreaPhase +${BOUTIQUES_COMMAND_LINE} +DOCKERJOB + +mkdir $DIROUT +chmod 755 .dockerjob.sh +#.dockerjob.sh script needs to be found in the workdir, ten we need to cd to /CreaPhase to be able to execute SimuPBI_circle_func +docker run --rm -v $PWD:/gasw-dir -v $PWD/$DIROUT:/CreaPhase/$DIROUT -v $PWD/../cache:$PWD/../cache -w /gasw-dir -u `id -u`:`id -g` camarasu/creaphase ./.dockerjob.sh + +if [ $? != 0 ] +then + echo "CreaPhase execution failed!" + exit 1 +fi + +tar -czvf result.tgz $DIROUT + + +echo "Execution of CreaPhase completed." + diff --git a/gasw/CreaPhase.xml b/gasw/CreaPhase.xml new file mode 100644 index 0000000..17cdc95 --- /dev/null +++ b/gasw/CreaPhase.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +