]> Creatis software - vip-workflow-creaphase.git/blob - bin/CreaPhase.sh
CreaPhase circle workflow v0.1
[vip-workflow-creaphase.git] / bin / CreaPhase.sh
1 #!/bin/bash
2
3 #     Functions     #
4
5 function info {
6   local D=`date`
7   echo [ INFO - $D ] $*
8 }
9
10 function warning {
11   local D=`date`
12   echo [ WARN - $D ] $*
13 }
14
15 function error {
16   local D=`date`
17   echo [ ERROR - $D ] $* >&2
18 }
19
20 function downloadLFN {
21
22   local LFN=$1
23   local LOCAL=${PWD}/`basename ${LFN}`
24
25   info "getting file size and computing sendReceiveTimeout"
26   size=`lfc-ls -l ${LFN} | awk -F' ' '{print $5}'`
27   sendReceiveTimeout=`echo $[${size}/150/1024]`
28   if [ "$sendReceiveTimeout" = "" ] || [ $sendReceiveTimeout -le 900 ]; then echo "sendReceiveTimeout empty or too small, setting it to 900s"; sendReceiveTimeout=900; else echo "sendReceiveTimeout is $sendReceiveTimeout"; fi;
29   info "Removing file ${LOCAL} in case it is already here"
30   \rm -f ${LOCAL}
31
32   info "Checking if the file is on local SE ${VO_BIOMED_DEFAULT_SE}"
33   local closeSURL=`lcg-lr lfn:${LFN} | grep ${VO_BIOMED_DEFAULT_SE}`
34   if [ "${closeSURL}" != "" ]
35   then
36     info "It is. Trying to download the file from there"
37     LINE="lcg-cp -v --connect-timeout 10 --sendreceive-timeout $sendReceiveTimeout --bdii-timeout 10 --srm-timeout 30 ${closeSURL} file:${LOCAL}"
38     info ${LINE}
39     ${LINE} &> lcg-log
40     if [ $? = 0 ]
41     then
42       info "lcg-cp worked fine"
43       lcg_source=`cat lcg-log | awk -F"://" '/Trying SURL srm/ {print $2}' | awk -F"/" '{print $1}'|awk -F":" '{print $1}'`;
44       lcg_destination=`hostname`;
45       lcg_time=`cat lcg-log | awk '/Transfer took/ {print $3$4}'`;
46       info "DownloadCommand=lcg-cp Source=$lcg_source Destination=$lcg_destination Size=$size Time=$lcg_time";
47       return 0
48     else
49       error "It failed, falling back on regular lcg-cp"
50     fi
51   else
52     info "It's not, falling back on regular lcg-cp"
53   fi
54
55 info "Downloading file ${LFN}..."
56 LINE="lcg-cp -v --connect-timeout 10 --sendreceive-timeout $sendReceiveTimeout --bdii-timeout 10 --srm-timeout 30 lfn:${LFN} file:${LOCAL}"
57 info ${LINE}
58 ${LINE} &> lcg-log
59 if [ $? = 0 ]
60 then
61   info "lcg-cp worked fine"
62   lcg_source=`cat lcg-log | awk -F"://" '/Trying SURL srm/ {print $2}' | awk -F"/" '{print $1}'|awk -F":" '{print $1}'`;
63   lcg_destination=`hostname`;
64   lcg_time=`cat lcg-log | awk '/Transfer took/ {print $3$4}'`;
65   info "DownloadCommand=lcg-cp Source=$lcg_source Destination=$lcg_destination Size=$size Time=$lcg_time";
66 else
67   error "lcg-cp failed"
68   error "`cat lcg-log`"
69   return 1
70 fi
71 \rm lcg-log 
72 }
73
74 # Arguments parsing #
75 RES=$1
76 COMM_LINE=`echo "${@:2:$(($#-2))}"`
77 # Command-line construction #
78
79 #echo "COMM line is $COMM_LINE"
80 #remove flags starting with --
81 #BOUTIQUES_ARGS="$(echo ${COMM_LINE} | sed 's/[--][[:alpha:]]*/,/g')"
82 BOUTIQUES_ARGS="$(echo ${COMM_LINE} | sed 's/ , /, /g')"
83 #remove leading ,,
84 #BOUTIQUES_ARGS="$(echo ${BOUTIQUES_ARGS} | sed 's/^,, //g')"
85 BOUTIQUES_COMMAND_LINE="octave --silent --eval \"SimuPBI_circle_func(${BOUTIQUES_ARGS})\""
86 echo "Boutiques COMM line is $BOUTIQUES_COMMAND_LINE"
87
88
89 #WARNING Cheating here : we know that outputs are written in dirOut
90 DIROUT="dirOut"
91 # Command-line execution #
92
93 cat << DOCKERJOB > .dockerjob.sh
94 #!/bin/bash -l
95 cd /CreaPhase
96 ${BOUTIQUES_COMMAND_LINE}
97 DOCKERJOB
98
99 mkdir $DIROUT
100 chmod 755 .dockerjob.sh
101 #.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
102 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
103
104 if [ $? != 0 ]
105 then
106     echo "CreaPhase execution failed!"
107     exit 1
108 fi
109
110 tar -czvf result.tgz $DIROUT
111
112
113 echo "Execution of CreaPhase completed."
114