Skip to content

Commit

Permalink
Merge pull request #275 from pneerincx/master
Browse files Browse the repository at this point in the history
Updated templates for local and slurm backends and rewrote tests to produce output in a test specific subdir.
  • Loading branch information
dennishendriksen authored Aug 10, 2017
2 parents 94d7932 + 196e0a4 commit 2d0ecc6
Show file tree
Hide file tree
Showing 329 changed files with 15,101 additions and 11,619 deletions.
2 changes: 1 addition & 1 deletion molgenis-compute-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<molgenis.version>1.2.0</molgenis.version>
<compute.version>16.11.1</compute.version>
<compute.version>17.08.1</compute.version>
</properties>
<parent>
<groupId>org.molgenis</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ private void updateWorkflowParameterDefaultsCSV()
else
{
File workflowFile = new File(this.workFlow);
String workflowFilePath = workflowFile.getParent(); // get workflow
// path
String workflowFilePath = workflowFile.getParent(); // get workflow path
String workflowName = workflowFile.getName(); // strip workflow name
workflowName = workflowName.substring(0, workflowName.indexOf('.')); // strip
// extension
workflowName = workflowName.substring(0, workflowName.indexOf('.')); // strip extension

File defaultsFileTest = new File(
workflowFilePath + File.separator + workflowName + "." + Parameters.DEFAULTS_DEFAULT);
Expand Down Expand Up @@ -226,6 +224,9 @@ public void parseCommandLine(String[] args)

if (batchOption != null)
{
LOG.error("Batching is currently disabled pending re-implementation of this feature.");
System.exit(1);

String nameValue[] = batchOption.split("=");
if (nameValue.length != 2) LOG.warn("BATCH specification is wrong; usage example sample=2");
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<#noparse>#
## Start of footer for backend 'local'.
#
## General footer
#

# Show that we successfully finished. If the .finished file exists, then this step will be skipped when you resubmit your workflow
touch $ENVIRONMENT_DIR/${taskId}.sh.finished
if [ -d "${MC_tmpFolder:-}" ]; then
echo -n "INFO: Removing MC_tmpFolder ${MC_tmpFolder} ..."
rm -rf "${MC_tmpFolder}"
echo 'done.'
fi

tS=${SECONDS:-0}
tM=$((SECONDS / 60 ))
tH=$((SECONDS / 3600))
echo "On $(date +"%Y-%m-%d %T") ${MC_jobScript} finished successfully after ${tM} minutes." >> molgenis.bookkeeping.log
printf '%s:\t%d seconds\t%d minutes\t%d hours\n' "${MC_jobScript}" "${tS}" "${tM}" "${tH}" >> molgenis.bookkeeping.walltime

mv "${MC_jobScript}".{started,finished}

trap - EXIT
exit 0

# Also do bookkeeping
echo "On $(date +"%Y-%m-%d %T"), after $(( ($(date +%s) - $MOLGENIS_START) / 60 )) minutes, task ${taskId}.sh finished successfully" >> $ENVIRONMENT_DIR/molgenis.bookkeeping.log
</#noparse>

This file was deleted.

182 changes: 100 additions & 82 deletions molgenis-compute-core/src/main/resources/templates/localhost/header.ftl
Original file line number Diff line number Diff line change
@@ -1,101 +1,119 @@
#!/bin/bash
#
## Header for 'local' backend
# This is job <#if project??>${project}_</#if>${taskId}
#

#highly recommended to use
#set -e # exit if any subcommand or pipeline returns a non-zero status
#set -u # exit if any uninitialised variable is used

# Set location of *.env and *.log files
ENVIRONMENT_DIR="."
#
## Start of header for backend 'local'.
#

# If you detect an error, then exit your script by calling this function
exitWithError(){
errorCode=$1
errorMessage=$2
echo "$errorCode: $errorMessage --- TASK '${taskId}.sh' --- ON $(date +"%Y-%m-%d %T"), AFTER RUNNING $(( ($(date +%s) - $MOLGENIS_START) / 60 )) MINUTES" >> $ENVIRONMENT_DIR/molgenis.error.log
exit $errorCode
}
set -e
set -u

# For bookkeeping how long your task takes
MOLGENIS_START=$(date +%s)
ENVIRONMENT_DIR='.'

# Show that the task has started
touch $ENVIRONMENT_DIR/${taskId}.sh.started
#
# Variables declared in MOLGENIS Compute headers/footers always start with an MC_ prefix.
#
declare MC_jobScript="${taskId}.sh"
declare MC_jobScriptSTDERR="${taskId}.err"
declare MC_jobScriptSTDOUT="${taskId}.out"
declare MC_failedFile="molgenis.pipeline.failed"

<#noparse>
getFile()
{
ARGS=($@)
NUMBER="${#ARGS[@]}";
if [ "$NUMBER" -eq "1" ]
then
myFile=${ARGS[0]}

if test ! -e $myFile;
then
echo "WARNING in getFile/putFile: $myFile is missing" 1>&2
fi
declare MC_singleSeperatorLine=$(head -c 120 /dev/zero | tr '\0' '-')
declare MC_doubleSeperatorLine=$(head -c 120 /dev/zero | tr '\0' '=')
declare MC_tmpFolder='tmpFolder'
declare MC_tmpFile='tmpFile'
declare MC_tmpFolderCreated=0

else
echo "Example usage: getData \"\$TMPDIR/datadir/myfile.txt\""
fi
}
#
##
### Header functions.
##
#

putFile()
{
`getFile $@`
function errorExitAndCleanUp() {
local _signal="${1}"
local _problematicLine="${2}"
local _exitStatus="${3:-$?}"
local _executionHost="$(hostname)"
local _format='INFO: Last 50 lines or less of %s:\n'
local _errorMessage="FATAL: Trapped ${_signal} signal in ${MC_jobScript} running on ${_executionHost}. Exit status code was ${_exitStatus}."
if [ "${_signal}" == 'ERR' ]; then
_errorMessage="FATAL: Trapped ${_signal} signal on line ${_problematicLine} in ${MC_jobScript} running on ${_executionHost}. Exit status code was ${_exitStatus}."
fi
_errorMessage=${4:-"${_errorMessage}"} # Optionally use custom error message as 4th argument.
echo "${_errorMessage}"
echo "${MC_doubleSeperatorLine}" > "${MC_failedFile}"
echo "${_errorMessage}" >> "${MC_failedFile}"
if [ -f "${MC_jobScriptSTDERR}" ]; then
echo "${MC_singleSeperatorLine}" >> "${MC_failedFile}"
printf "${_format}" "${MC_jobScriptSTDERR}" >> "${MC_failedFile}"
echo "${MC_singleSeperatorLine}" >> "${MC_failedFile}"
tail -50 "${MC_jobScriptSTDERR}" >> "${MC_failedFile}"
fi
if [ -f "${MC_jobScriptSTDOUT}" ]; then
echo "${MC_singleSeperatorLine}" >> "${MC_failedFile}"
printf "${_format}" "${MC_jobScriptSTDOUT}" >> "${MC_failedFile}"
echo "${MC_singleSeperatorLine}" >> "${MC_failedFile}"
tail -50 "${MC_jobScriptSTDOUT}" >> "${MC_failedFile}"
fi
echo "${MC_doubleSeperatorLine}" >> "${MC_failedFile}"
}

inputs()
{
for name in $@
do
if test ! -e $name;
then
echo "$name is missing" 1>&2
exit 1;
fi
done
#
# Create tmp dir per script/job.
# To be called with with either a file or folder as first and only argument.
# Defines two globally set variables:
# 1. MC_tmpFolder: a tmp dir for this job/script. When function is called multiple times MC_tmpFolder will always be the same.
# 2. MC_tmpFile: when the first argument was a folder, MC_tmpFile == MC_tmpFolder
# when the first argument was a file, MC_tmpFile will be a path to a tmp file inside MC_tmpFolder.
#
function makeTmpDir {
#
# Compile paths.
#
local _originalPath="${1}"
local _myMD5="$(md5sum ${MC_jobScript} | cut -d ' ' -f 1)"
local _tmpSubFolder="tmp_${MC_jobScript}_${_myMD5}"
local _dir
local _base
if [[ -d "${_originalPath}" ]]; then
_dir="${_originalPath}"
_base=''
else
_base=$(basename "${_originalPath}")
_dir=$(dirname "${_originalPath}")
fi
MC_tmpFolder="${_dir}/${_tmpSubFolder}/"
MC_tmpFile="${MC_tmpFolder}/${_base}"
echo "DEBUG ${MC_jobScript}::makeTmpDir: dir='${_dir}';base='${_base}';MC_tmpFile='${MC_tmpFile}'"
#
# Cleanup the previously created tmpFolder first if this script was resubmitted.
#
if [[ ${MC_tmpFolderCreated} -eq 0 && -d "${MC_tmpFolder}" ]]; then
rm -rf "${MC_tmpFolder}"
fi
#
# (Re-)create tmpFolder.
#
mkdir -p "${MC_tmpFolder}"
MC_tmpFolderCreated=1
}

outputs()
{
for name in $@
do
if test -e $name;
then
echo "skipped"
echo "skipped" 1>&2
exit 0;
else
return;
fi
done
}
trap 'errorExitAndCleanUp HUP NA $?' HUP
trap 'errorExitAndCleanUp INT NA $?' INT
trap 'errorExitAndCleanUp QUIT NA $?' QUIT
trap 'errorExitAndCleanUp TERM NA $?' TERM
trap 'errorExitAndCleanUp EXIT NA $?' EXIT
trap 'errorExitAndCleanUp ERR $LINENO $?' ERR

alloutputsexist()
{
all_exist=true
for name in $@
do
if test ! -e $name;
then
all_exist=false
fi
done
if $all_exist;
then
echo "skipped"
echo "skipped" 1>&2
sleep 30
exit 0;
else
return 0;
fi
}
</#noparse>
touch "${MC_jobScript}.started"

#
## End of header for 'local' backend
## End of header for backend 'local'
#

</#noparse>

This file was deleted.

Loading

0 comments on commit 2d0ecc6

Please sign in to comment.